Skip to content

Commit

Permalink
Persist original character flag data (is space, is cluster, is breaka…
Browse files Browse the repository at this point in the history
…ble, etc) in the glyph store when setting glyph-related data.
  • Loading branch information
Brian J. Burg committed Nov 21, 2012
1 parent d460162 commit 42c6e45
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
32 changes: 26 additions & 6 deletions src/servo-gfx/text/glyph.rs
Expand Up @@ -38,15 +38,28 @@ enum BreakType {
BreakTypeHyphen
}

impl BreakType : Eq {
pure fn eq(other: &BreakType) -> bool {
match (self, *other) {
(BreakTypeNone, BreakTypeNone) => true,
(BreakTypeNormal, BreakTypeNormal) => true,
(BreakTypeHyphen, BreakTypeHyphen) => true,
(_,_) => false,
}
}
pure fn ne(other: &BreakType) -> bool {
!self.eq(other)
}
}

const BREAK_TYPE_NONE : u8 = 0x0u8;
const BREAK_TYPE_NORMAL : u8 = 0x1u8;
const BREAK_TYPE_HYPHEN : u8 = 0x2u8;

pure fn break_flag_to_enum(flag: u8) -> BreakType {
if (flag & BREAK_TYPE_NONE) as bool { return BreakTypeNone; }
if (flag & BREAK_TYPE_NORMAL) as bool { return BreakTypeNormal; }
if (flag & BREAK_TYPE_HYPHEN) as bool { return BreakTypeHyphen; }
fail ~"Unknown break setting"
if (flag & BREAK_TYPE_NORMAL) != 0 { return BreakTypeNormal; }
if (flag & BREAK_TYPE_HYPHEN) != 0 { return BreakTypeHyphen; }
BreakTypeNone
}

pure fn break_enum_to_flag(e: BreakType) -> u8 {
Expand Down Expand Up @@ -244,6 +257,11 @@ impl GlyphEntry {
/*priv*/ pure fn has_flag(flag: u32) -> bool {
(self.value & flag) != 0
}

#[inline(always)]
pure fn adapt_character_flags_of_entry(other: &GlyphEntry) -> GlyphEntry {
GlyphEntry { value: self.value | other.value }
}
}

// Stores data for a detailed glyph, in the case that several glyphs
Expand Down Expand Up @@ -504,8 +522,10 @@ impl GlyphStore {
is_simple_glyph_id(data.index)
&& is_simple_advance(data.advance)
&& data.offset == au::zero_point()
&& data.cluster_start // others are stored in detail buffer
}

assert data.ligature_start; // can't compress ligature continuation glyphs.
assert i < self.entry_buffer.len();

let entry = match (data.is_missing, glyph_is_compressible(data)) {
Expand All @@ -516,7 +536,7 @@ impl GlyphStore {
self.detail_store.add_detailed_glyphs_for_entry(i, glyph);
ComplexGlyphEntry(data.cluster_start, data.ligature_start, 1)
}
};
}.adapt_character_flags_of_entry(&self.entry_buffer[i]);

//debug!("Adding single glyph[idx=%u]: %?", i, entry);

Expand Down Expand Up @@ -544,7 +564,7 @@ impl GlyphStore {
first_glyph_data.ligature_start,
glyph_count)
}
};
}.adapt_character_flags_of_entry(&self.entry_buffer[i]);

debug!("Adding multiple glyphs[idx=%u, count=%u]: %?", i, glyph_count, entry);

Expand Down
14 changes: 10 additions & 4 deletions src/servo-gfx/text/harfbuzz/shaper.rs
Expand Up @@ -358,17 +358,23 @@ pub impl HarfbuzzShaper {
// TODO(Issue #214): cluster ranges need to be computed before
// shaping, and then consulted here.
// for now, just pretend that every character is a cluster start.
// (i.e., pretend there are no combining character sequences)
// (i.e., pretend there are no combining character sequences).
// 1-to-1 mapping of character to glyph also treated as ligature start.
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_char_index(char_idx, &data);
} else {
// collect all glyphs to be assigned to the first character.
let datas = DVec();

while glyph_span.length() > 0 {
let shape = glyph_data.get_entry_for_glyph(glyph_span.begin(), &mut y_pos);
datas.push(GlyphData(shape.codepoint, shape.advance, shape.offset, false, true, true));
for glyph_span.eachi |glyph_i| {
let shape = glyph_data.get_entry_for_glyph(glyph_i, &mut y_pos);
datas.push(GlyphData(shape.codepoint,
shape.advance,
shape.offset,
false, // not missing
true, // treat as cluster start
glyph_i > glyph_span.begin())); // all but first are ligature continuations
glyph_span.adjust_by(1,-1);
}

Expand Down

0 comments on commit 42c6e45

Please sign in to comment.