In GlyphStore API, clarify function names to indicate whether byte or character indices are being iterated over.

This commit is contained in:
Brian J. Burg 2012-11-19 11:17:06 -08:00
parent 0537e3723f
commit e838b171b9
4 changed files with 16 additions and 14 deletions

View file

@ -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),

View file

@ -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; }
}
}

View file

@ -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);
}
}

View file

@ -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);