Skip to content

Commit

Permalink
Refactor uses of text ranges in glyph storage iteration and display l…
Browse files Browse the repository at this point in the history
…ist.
  • Loading branch information
Brian J. Burg committed Oct 18, 2012
1 parent 0f050e7 commit 7bfafa5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/servo/gfx/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/servo/gfx/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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());

Expand Down
9 changes: 3 additions & 6 deletions src/servo/layout/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(_) => {
Expand Down
6 changes: 2 additions & 4 deletions src/servo/text/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions src/servo/text/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use core::cmp::{Ord, Eq};
use core::dvec::DVec;
use core::u16;
use geom::point::Point2D;
use num::from_int;
use std::sort;
use servo_text::text_run::TextRange;
use servo_util::vec::*;
use num::from_int;


// GlyphEntry is a port of Gecko's CompressedGlyph scheme for storing
// glyph data compactly.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7bfafa5

Please sign in to comment.