Skip to content

Commit

Permalink
In GlyphStore API, clarify function names to indicate whether byte or…
Browse files Browse the repository at this point in the history
… character indices are being iterated over.
  • Loading branch information
Brian J. Burg committed Nov 19, 2012
1 parent 0537e37 commit e838b17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/servo-gfx/font.rs
Expand Up @@ -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());

Expand Down Expand Up @@ -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),
Expand Down
18 changes: 10 additions & 8 deletions src/servo-gfx/text/glyph.rs
Expand Up @@ -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)
Expand All @@ -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;

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

Expand Down
6 changes: 3 additions & 3 deletions src/servo-gfx/text/harfbuzz/shaper.rs
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/servo/layout/box.rs
Expand Up @@ -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);
Expand Down

0 comments on commit e838b17

Please sign in to comment.