Skip to content
Permalink
Browse files

Persist original character flag data (is space, is cluster, is breaka…

…ble, etc) in the glyph store when setting glyph-related data.
  • Loading branch information
Brian J. Burg
Brian J. Burg committed Nov 21, 2012
1 parent d460162 commit 42c6e45d08d3f5b5c73667c653fa563079e60e8c
Showing with 36 additions and 10 deletions.
  1. +26 −6 src/servo-gfx/text/glyph.rs
  2. +10 −4 src/servo-gfx/text/harfbuzz/shaper.rs
@@ -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 {
@@ -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
@@ -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)) {
@@ -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);

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

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

0 comments on commit 42c6e45

Please sign in to comment.
You can’t perform that action at this time.