mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Refactor uses of text ranges in glyph storage iteration and display list.
This commit is contained in:
parent
0f050e7835
commit
7bfafa5bb8
5 changed files with 23 additions and 28 deletions
|
@ -8,7 +8,7 @@ use servo_text::text_run;
|
|||
use std::arc::ARC;
|
||||
use clone_arc = std::arc::clone;
|
||||
use dvec::DVec;
|
||||
use text::text_run::SendableTextRun;
|
||||
use text::text_run::{TextRange, SendableTextRun};
|
||||
|
||||
pub use layout::display_list_builder::DisplayListBuilder;
|
||||
|
||||
|
@ -24,7 +24,7 @@ pub enum DisplayItemData {
|
|||
// TODO: need to provide spacing data for text run.
|
||||
// (i.e, to support rendering of CSS 'word-spacing' and 'letter-spacing')
|
||||
// TODO: don't copy text runs, ever.
|
||||
TextData(~SendableTextRun, uint, uint),
|
||||
TextData(~SendableTextRun, TextRange),
|
||||
ImageData(ARC<~image::base::Image>),
|
||||
BorderData(au, u8, u8, u8)
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ fn draw_SolidColor(self: &DisplayItem, ctx: &RenderContext) {
|
|||
|
||||
fn draw_Text(self: &DisplayItem, ctx: &RenderContext) {
|
||||
match self.data {
|
||||
TextData(run, offset, len) => {
|
||||
TextData(run, range) => {
|
||||
let new_run = text_run::deserialize(ctx.font_cache, run);
|
||||
ctx.draw_text(self.bounds, new_run, offset, len)
|
||||
ctx.draw_text(self.bounds, new_run, range)
|
||||
},
|
||||
_ => fail
|
||||
}
|
||||
|
@ -76,11 +76,11 @@ pub fn Border(bounds: Rect<au>, width: au, r: u8, g: u8, b: u8) -> DisplayItem {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn Text(bounds: Rect<au>, run: ~SendableTextRun, offset: uint, length: uint) -> DisplayItem {
|
||||
pub fn Text(bounds: Rect<au>, run: ~SendableTextRun, range: TextRange) -> DisplayItem {
|
||||
DisplayItem {
|
||||
draw: |self, ctx| draw_Text(self, ctx),
|
||||
bounds: bounds,
|
||||
data: TextData(run, offset, length)
|
||||
data: TextData(run, range)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use mod au = geometry;
|
|||
|
||||
use compositor::LayerBuffer;
|
||||
use text::font::Font;
|
||||
use text::text_run::TextRun;
|
||||
use text::text_run::{TextRun, TextRange};
|
||||
use text::font_cache::FontCache;
|
||||
use image::base::Image;
|
||||
use au = au::au;
|
||||
|
@ -67,7 +67,7 @@ impl RenderContext {
|
|||
draw_options);
|
||||
}
|
||||
|
||||
pub fn draw_text(&self, bounds: Rect<au>, run: &TextRun, offset: uint, length: uint) {
|
||||
pub fn draw_text(&self, bounds: Rect<au>, run: &TextRun, range: TextRange) {
|
||||
use ptr::{null};
|
||||
use vec::raw::to_ptr;
|
||||
use libc::types::common::c99::{uint16_t, uint32_t};
|
||||
|
@ -109,9 +109,9 @@ impl RenderContext {
|
|||
|
||||
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(&bounds.size.height));
|
||||
let azglyphs = DVec();
|
||||
azglyphs.reserve(length);
|
||||
azglyphs.reserve(range.length());
|
||||
|
||||
do run.glyphs.iter_glyphs_for_range(offset, length) |_i, glyph| {
|
||||
do run.glyphs.iter_glyphs_for_range(range) |_i, glyph| {
|
||||
let glyph_advance = glyph.advance();
|
||||
let glyph_offset = glyph.offset().get_default(au::zero_point());
|
||||
|
||||
|
|
|
@ -294,13 +294,10 @@ impl RenderBox : RenderBoxMethods {
|
|||
TextBox(_,d) => {
|
||||
let mut max_line_width: au = au(0);
|
||||
for d.run.iter_natural_lines_for_range(d.range) |line_range| {
|
||||
// if the line is a single newline, then len will be zero
|
||||
if line_range.length() == 0 { loop }
|
||||
|
||||
let mut line_width: au = au(0);
|
||||
do d.run.glyphs.iter_glyphs_for_range(line_range.begin(), line_range.length()) |_char_i, glyph| {
|
||||
for d.run.glyphs.iter_glyphs_for_range(line_range) |_char_i, glyph| {
|
||||
line_width += glyph.advance()
|
||||
};
|
||||
}
|
||||
max_line_width = au::max(max_line_width, line_width);
|
||||
}
|
||||
|
||||
|
@ -442,7 +439,7 @@ impl RenderBox : RenderBoxMethods {
|
|||
UnscannedTextBox(*) => fail ~"Shouldn't see unscanned boxes here.",
|
||||
TextBox(_,d) => {
|
||||
list.append_item(~dl::Text(copy abs_box_bounds, text_run::serialize(builder.ctx.font_cache, d.run),
|
||||
d.range.begin(), d.range.length()))
|
||||
d.range))
|
||||
},
|
||||
// TODO: items for background, border, outline
|
||||
GenericBox(_) => {
|
||||
|
|
|
@ -57,10 +57,8 @@ pub impl Font : FontMethods {
|
|||
// TODO: alter advance direction for RTL
|
||||
// TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
|
||||
let mut advance = au(0);
|
||||
if range.length() > 0 {
|
||||
do run.glyphs.iter_glyphs_for_range(range.begin(), range.length()) |_i, glyph| {
|
||||
advance += glyph.advance();
|
||||
}
|
||||
for run.glyphs.iter_glyphs_for_range(range) |_i, glyph| {
|
||||
advance += glyph.advance();
|
||||
}
|
||||
let mut bounds = Rect(Point2D(au(0), -self.metrics.ascent),
|
||||
Size2D(advance, self.metrics.ascent + self.metrics.descent));
|
||||
|
|
|
@ -4,9 +4,11 @@ use core::cmp::{Ord, Eq};
|
|||
use core::dvec::DVec;
|
||||
use core::u16;
|
||||
use geom::point::Point2D;
|
||||
use std::sort;
|
||||
use servo_util::vec::*;
|
||||
use num::from_int;
|
||||
use std::sort;
|
||||
use servo_text::text_run::TextRange;
|
||||
use servo_util::vec::*;
|
||||
|
||||
|
||||
// GlyphEntry is a port of Gecko's CompressedGlyph scheme for storing
|
||||
// glyph data compactly.
|
||||
|
@ -543,13 +545,11 @@ impl GlyphStore {
|
|||
}
|
||||
}
|
||||
|
||||
fn iter_glyphs_for_range<T>(&self, offset: uint, len: uint, cb: fn&(uint, GlyphInfo/&) -> T) {
|
||||
assert offset < self.entry_buffer.len();
|
||||
assert len > 0 && len + offset <= self.entry_buffer.len();
|
||||
fn iter_glyphs_for_range<T>(&self, range: TextRange, cb: fn&(uint, GlyphInfo/&) -> T) {
|
||||
assert range.begin() < self.entry_buffer.len();
|
||||
assert range.end() <= self.entry_buffer.len();
|
||||
|
||||
for uint::range(offset, offset + len) |i| {
|
||||
self.iter_glyphs_for_index(i, cb);
|
||||
}
|
||||
for range.eachi |i| { self.iter_glyphs_for_index(i, cb); }
|
||||
}
|
||||
|
||||
fn iter_all_glyphs<T>(cb: fn&(uint, GlyphInfo/&) -> T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue