From e838b171b9d737844b289f1b730a20fe1022bbdb Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Mon, 19 Nov 2012 11:17:06 -0800 Subject: [PATCH] In GlyphStore API, clarify function names to indicate whether byte or character indices are being iterated over. --- src/servo-gfx/font.rs | 4 ++-- src/servo-gfx/text/glyph.rs | 18 ++++++++++-------- src/servo-gfx/text/harfbuzz/shaper.rs | 6 +++--- src/servo/layout/box.rs | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/servo-gfx/font.rs b/src/servo-gfx/font.rs index 6d40069343e..0fbf4972a2c 100644 --- a/src/servo-gfx/font.rs +++ b/src/servo-gfx/font.rs @@ -414,7 +414,7 @@ pub impl Font : FontMethods { let azglyphs = DVec(); azglyphs.reserve(range.length()); - for run.glyphs.iter_glyphs_for_range(range) |_i, glyph| { + for run.glyphs.iter_glyphs_for_byte_range(range) |_i, glyph| { let glyph_advance = glyph.advance(); let glyph_offset = glyph.offset().get_default(Au::zero_point()); @@ -453,7 +453,7 @@ pub impl Font : FontMethods { // TODO(Issue #199): alter advance direction for RTL // TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text let mut advance = Au(0); - for run.glyphs.iter_glyphs_for_range(range) |_i, glyph| { + for run.glyphs.iter_glyphs_for_byte_range(range) |_i, glyph| { advance += glyph.advance(); } let mut bounds = Rect(Point2D(Au(0), -self.metrics.ascent), diff --git a/src/servo-gfx/text/glyph.rs b/src/servo-gfx/text/glyph.rs index f9e34eaa75b..84d437916e5 100644 --- a/src/servo-gfx/text/glyph.rs +++ b/src/servo-gfx/text/glyph.rs @@ -498,7 +498,7 @@ fn GlyphStore(length: uint) -> GlyphStore { } impl GlyphStore { - fn add_glyph_for_index(i: uint, data: &GlyphData) { + fn add_glyph_for_char_index(i: uint, data: &GlyphData) { pure fn glyph_is_compressible(data: &GlyphData) -> bool { is_simple_glyph_id(data.index) @@ -523,7 +523,7 @@ impl GlyphStore { self.entry_buffer.set_elt(i, entry); } - fn add_glyphs_for_index(i: uint, data_for_glyphs: &[GlyphData]) { + fn add_glyphs_for_char_index(i: uint, data_for_glyphs: &[GlyphData]) { assert i < self.entry_buffer.len(); assert data_for_glyphs.len() > 0; @@ -552,7 +552,7 @@ impl GlyphStore { } // used when a character index has no associated glyph---for example, a ligature continuation. - fn add_nonglyph_for_index(&self, i: uint, cluster_start: bool, ligature_start: bool) { + fn add_nonglyph_for_char_index(&self, i: uint, cluster_start: bool, ligature_start: bool) { assert i < self.entry_buffer.len(); let entry = ComplexGlyphEntry(cluster_start, ligature_start, 0); @@ -561,7 +561,7 @@ impl GlyphStore { self.entry_buffer.set_elt(i, entry); } - fn iter_glyphs_for_index(&self, i: uint, cb: fn&(uint, GlyphInfo/&) -> bool) -> bool { + fn iter_glyphs_for_char_index(&self, i: uint, cb: fn&(uint, GlyphInfo/&) -> bool) -> bool { assert i < self.entry_buffer.len(); let entry = &self.entry_buffer[i]; @@ -582,7 +582,7 @@ impl GlyphStore { return true; } - fn iter_glyphs_for_range(&self, range: &const Range, cb: fn&(uint, GlyphInfo/&) -> bool) { + fn iter_glyphs_for_byte_range(&self, range: &const Range, cb: fn&(uint, GlyphInfo/&) -> bool) { if range.begin() >= self.entry_buffer.len() { error!("iter_glyphs_for_range: range.begin beyond length!"); return; @@ -592,14 +592,16 @@ impl GlyphStore { return; } - for range.eachi |i| { - if !self.iter_glyphs_for_index(i, cb) { break; } + // TODO: actually compute char indexes from byte indexes. + let char_range = copy *range; + for char_range.eachi |i| { + if !self.iter_glyphs_for_char_index(i, cb) { break; } } } fn iter_all_glyphs(cb: fn&(uint, GlyphInfo/&) -> bool) { for uint::range(0, self.entry_buffer.len()) |i| { - if !self.iter_glyphs_for_index(i, cb) { break; } + if !self.iter_glyphs_for_char_index(i, cb) { break; } } } diff --git a/src/servo-gfx/text/harfbuzz/shaper.rs b/src/servo-gfx/text/harfbuzz/shaper.rs index 58fe035014b..fe6ec997528 100644 --- a/src/servo-gfx/text/harfbuzz/shaper.rs +++ b/src/servo-gfx/text/harfbuzz/shaper.rs @@ -361,7 +361,7 @@ pub impl HarfbuzzShaper { // (i.e., pretend there are no combining character sequences) let shape = glyph_data.get_entry_for_glyph(glyph_span.begin(), &mut y_pos); let data = GlyphData(shape.codepoint, shape.advance, shape.offset, false, true, true); - glyphs.add_glyph_for_index(char_idx, &data); + glyphs.add_glyph_for_char_index(char_idx, &data); } else { // collect all glyphs to be assigned to the first character. let datas = DVec(); @@ -373,7 +373,7 @@ pub impl HarfbuzzShaper { } // now add the detailed glyph entry. - glyphs.add_glyphs_for_index(char_idx, dvec::unwrap(move datas)); + glyphs.add_glyphs_for_char_index(char_idx, dvec::unwrap(move datas)); // set the other chars, who have no glyphs let mut i = covered_byte_span.begin(); @@ -382,7 +382,7 @@ pub impl HarfbuzzShaper { i = next; if i >= covered_byte_span.end() { break; } char_idx += 1; - glyphs.add_nonglyph_for_index(char_idx, false, false); + glyphs.add_nonglyph_for_char_index(char_idx, false, false); } } diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index e96fda42839..f1462aa533b 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -292,7 +292,7 @@ impl RenderBox : RenderBoxMethods { let mut max_line_width: Au = Au(0); for d.run.iter_natural_lines_for_range(&const d.range) |line_range| { let mut line_width: Au = Au(0); - for d.run.glyphs.iter_glyphs_for_range(line_range) |_char_i, glyph| { + for d.run.glyphs.iter_glyphs_for_byte_range(line_range) |_char_i, glyph| { line_width += glyph.advance() } max_line_width = Au::max(max_line_width, line_width);