From 42c6e45d08d3f5b5c73667c653fa563079e60e8c Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Tue, 20 Nov 2012 18:17:34 -0800 Subject: [PATCH] Persist original character flag data (is space, is cluster, is breakable, etc) in the glyph store when setting glyph-related data. --- src/servo-gfx/text/glyph.rs | 32 ++++++++++++++++++++++----- src/servo-gfx/text/harfbuzz/shaper.rs | 14 ++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/servo-gfx/text/glyph.rs b/src/servo-gfx/text/glyph.rs index 84d437916e5..651c7dab275 100644 --- a/src/servo-gfx/text/glyph.rs +++ b/src/servo-gfx/text/glyph.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); diff --git a/src/servo-gfx/text/harfbuzz/shaper.rs b/src/servo-gfx/text/harfbuzz/shaper.rs index fe6ec997528..37d9708ef3a 100644 --- a/src/servo-gfx/text/harfbuzz/shaper.rs +++ b/src/servo-gfx/text/harfbuzz/shaper.rs @@ -358,7 +358,8 @@ 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); @@ -366,9 +367,14 @@ pub impl HarfbuzzShaper { // 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); }