From 68f9aad883fb7335b9e2dddb24e96fb61c5653bc Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 7 May 2014 16:06:07 -0700 Subject: [PATCH] Rename GlyphIndex->GlyphId This will allow us to use the GlyphIndex identifier to refer to glyph indexes into text runs in the future. --- src/components/gfx/font.rs | 12 ++--- src/components/gfx/platform/android/font.rs | 8 +-- src/components/gfx/platform/linux/font.rs | 8 +-- src/components/gfx/platform/macos/font.rs | 8 +-- src/components/gfx/text/glyph.rs | 54 ++++++++++----------- src/components/gfx/text/shaping/harfbuzz.rs | 8 +-- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index c5628e079d2..a90ad0ec822 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -23,7 +23,7 @@ use servo_util::geometry::Au; use platform::font_context::FontContextHandle; use platform::font::{FontHandle, FontTable}; use render_context::RenderContext; -use text::glyph::{GlyphStore, GlyphIndex}; +use text::glyph::{GlyphStore, GlyphId}; use text::shaping::ShaperMethods; use text::{Shaper, TextRun}; @@ -45,8 +45,8 @@ pub trait FontHandleMethods { fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle) -> Result; - fn glyph_index(&self, codepoint: char) -> Option; - fn glyph_h_advance(&self, GlyphIndex) -> Option; + fn glyph_index(&self, codepoint: char) -> Option; + fn glyph_h_advance(&self, GlyphId) -> Option; fn get_metrics(&self) -> FontMetrics; fn get_table_for_tag(&self, FontTableTag) -> Option; } @@ -361,7 +361,7 @@ impl Font { let glyph_offset = glyph.offset().unwrap_or(Zero::zero()); let azglyph = struct__AzGlyph { - mIndex: glyph.index() as uint32_t, + mIndex: glyph.id() as uint32_t, mPosition: struct__AzPoint { x: (origin.x + glyph_offset.x).to_nearest_px() as AzFloat, y: (origin.y + glyph_offset.y).to_nearest_px() as AzFloat @@ -430,11 +430,11 @@ impl Font { FontDescriptor::new(self.style.clone(), SelectorPlatformIdentifier(self.handle.face_identifier())) } - pub fn glyph_index(&self, codepoint: char) -> Option { + pub fn glyph_index(&self, codepoint: char) -> Option { self.handle.glyph_index(codepoint) } - pub fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> FractionalPixel { + pub fn glyph_h_advance(&mut self, glyph: GlyphId) -> FractionalPixel { let handle = &self.handle; self.glyph_advance_cache.find_or_create(&glyph, |glyph| { match handle.glyph_h_advance(*glyph) { diff --git a/src/components/gfx/platform/android/font.rs b/src/components/gfx/platform/android/font.rs index b8a4f110cc4..4c5f5245384 100644 --- a/src/components/gfx/platform/android/font.rs +++ b/src/components/gfx/platform/android/font.rs @@ -9,7 +9,7 @@ use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle}; use servo_util::geometry::Au; use servo_util::geometry; use platform::font_context::FontContextHandle; -use text::glyph::GlyphIndex; +use text::glyph::GlyphId; use text::util::{float_to_fixed, fixed_to_float}; use style::computed_values::font_weight; @@ -174,12 +174,12 @@ impl FontHandleMethods for FontHandle { } fn glyph_index(&self, - codepoint: char) -> Option { + codepoint: char) -> Option { assert!(self.face.is_not_null()); unsafe { let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong); return if idx != 0 as FT_UInt { - Some(idx as GlyphIndex) + Some(idx as GlyphId) } else { debug!("Invalid codepoint: {}", codepoint); None @@ -188,7 +188,7 @@ impl FontHandleMethods for FontHandle { } fn glyph_h_advance(&self, - glyph: GlyphIndex) -> Option { + glyph: GlyphId) -> Option { assert!(self.face.is_not_null()); unsafe { let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0); diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index 94527b3b35d..c5b704ac9bb 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -9,7 +9,7 @@ use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle}; use servo_util::geometry::Au; use servo_util::geometry; use platform::font_context::FontContextHandle; -use text::glyph::GlyphIndex; +use text::glyph::GlyphId; use text::util::{float_to_fixed, fixed_to_float}; use style::computed_values::font_weight; @@ -174,12 +174,12 @@ impl FontHandleMethods for FontHandle { } fn glyph_index(&self, - codepoint: char) -> Option { + codepoint: char) -> Option { assert!(self.face.is_not_null()); unsafe { let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong); return if idx != 0 as FT_UInt { - Some(idx as GlyphIndex) + Some(idx as GlyphId) } else { debug!("Invalid codepoint: {}", codepoint); None @@ -188,7 +188,7 @@ impl FontHandleMethods for FontHandle { } fn glyph_h_advance(&self, - glyph: GlyphIndex) -> Option { + glyph: GlyphId) -> Option { assert!(self.face.is_not_null()); unsafe { let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0); diff --git a/src/components/gfx/platform/macos/font.rs b/src/components/gfx/platform/macos/font.rs index 5441415b653..48f0d318b2c 100644 --- a/src/components/gfx/platform/macos/font.rs +++ b/src/components/gfx/platform/macos/font.rs @@ -14,7 +14,7 @@ use font::{FractionalPixel, SpecifiedFontStyle}; use servo_util::geometry::{Au, px_to_pt}; use servo_util::geometry; use platform::macos::font_context::FontContextHandle; -use text::glyph::GlyphIndex; +use text::glyph::GlyphId; use style::computed_values::font_weight; use core_foundation::base::CFIndex; @@ -125,7 +125,7 @@ impl FontHandleMethods for FontHandle { return FontHandle::new_from_CTFont(fctx, new_font); } - fn glyph_index(&self, codepoint: char) -> Option { + fn glyph_index(&self, codepoint: char) -> Option { let characters: [UniChar, ..1] = [codepoint as UniChar]; let glyphs: [CGGlyph, ..1] = [0 as CGGlyph]; let count: CFIndex = 1; @@ -140,10 +140,10 @@ impl FontHandleMethods for FontHandle { } assert!(glyphs[0] != 0); // FIXME: error handling - return Some(glyphs[0] as GlyphIndex); + return Some(glyphs[0] as GlyphId); } - fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option { + fn glyph_h_advance(&self, glyph: GlyphId) -> Option { let glyphs = [glyph as CGGlyph]; let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation, &glyphs[0], diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs index 1eb04c81b36..f762e4a0c99 100644 --- a/src/components/gfx/text/glyph.rs +++ b/src/components/gfx/text/glyph.rs @@ -39,15 +39,15 @@ impl GlyphEntry { } // Creates a GlyphEntry for the common case - fn simple(index: GlyphIndex, advance: Au) -> GlyphEntry { - assert!(is_simple_glyph_id(index)); + fn simple(id: GlyphId, advance: Au) -> GlyphEntry { + assert!(is_simple_glyph_id(id)); assert!(is_simple_advance(advance)); - let index_mask = index as u32; + let id_mask = id as u32; let Au(advance) = advance; let advance_mask = (advance as u32) << GLYPH_ADVANCE_SHIFT; - GlyphEntry::new(index_mask | advance_mask | FLAG_IS_SIMPLE_GLYPH) + GlyphEntry::new(id_mask | advance_mask | FLAG_IS_SIMPLE_GLYPH) } // Create a GlyphEntry for uncommon case; should be accompanied by @@ -83,8 +83,8 @@ impl GlyphEntry { } } -/// The index of a particular glyph within a font -pub type GlyphIndex = u32; +/// The id of a particular glyph within a font +pub type GlyphId = u32; // TODO: unify with bit flags? #[deriving(Eq)] @@ -100,12 +100,12 @@ static BREAK_TYPE_HYPHEN: u8 = 0x2; fn break_flag_to_enum(flag: u8) -> BreakType { if (flag & BREAK_TYPE_NORMAL) != 0 { - return BreakTypeNormal; + BreakTypeNormal + } else if (flag & BREAK_TYPE_HYPHEN) != 0 { + BreakTypeHyphen + } else { + BreakTypeNone } - if (flag & BREAK_TYPE_HYPHEN) != 0 { - return BreakTypeHyphen; - } - BreakTypeNone } fn break_enum_to_flag(e: BreakType) -> u8 { @@ -151,8 +151,8 @@ static FLAG_CHAR_IS_NEWLINE: u32 = 0x00000010; //static FLAG_CHAR_IS_LOW_SURROGATE: u32 = 0x00000020; //static CHAR_IDENTITY_FLAGS_MASK: u32 = 0x00000038; -fn is_simple_glyph_id(glyphId: GlyphIndex) -> bool { - ((glyphId as u32) & GLYPH_ID_MASK) == glyphId +fn is_simple_glyph_id(id: GlyphId) -> bool { + ((id as u32) & GLYPH_ID_MASK) == id } fn is_simple_advance(advance: Au) -> bool { @@ -171,7 +171,7 @@ impl GlyphEntry { NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT).unwrap() } - fn index(&self) -> GlyphIndex { + fn id(&self) -> GlyphId { self.value & GLYPH_ID_MASK } @@ -253,7 +253,7 @@ impl GlyphEntry { // correspond to one character, or the glyph's data couldn't be packed. #[deriving(Clone)] struct DetailedGlyph { - index: GlyphIndex, + id: GlyphId, // glyph's advance, in the text's direction (RTL or RTL) advance: Au, // glyph's offset from the font's em-box (from top-left) @@ -261,9 +261,9 @@ struct DetailedGlyph { } impl DetailedGlyph { - fn new(index: GlyphIndex, advance: Au, offset: Point2D) -> DetailedGlyph { + fn new(id: GlyphId, advance: Au, offset: Point2D) -> DetailedGlyph { DetailedGlyph { - index: index, + id: id, advance: advance, offset: offset } @@ -423,7 +423,7 @@ impl<'a> DetailedGlyphStore { // This struct is used by GlyphStore clients to provide new glyph data. // It should be allocated on the stack and passed by reference to GlyphStore. pub struct GlyphData { - index: GlyphIndex, + id: GlyphId, advance: Au, offset: Point2D, is_missing: bool, @@ -432,7 +432,7 @@ pub struct GlyphData { } impl GlyphData { - pub fn new(index: GlyphIndex, + pub fn new(id: GlyphId, advance: Au, offset: Option>, is_missing: bool, @@ -445,7 +445,7 @@ impl GlyphData { }; GlyphData { - index: index, + id: id, advance: advance, offset: offset, is_missing: is_missing, @@ -465,11 +465,11 @@ pub enum GlyphInfo<'a> { } impl<'a> GlyphInfo<'a> { - pub fn index(self) -> GlyphIndex { + pub fn id(self) -> GlyphId { match self { - SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i as uint).index(), + SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i as uint).id(), DetailGlyphInfo(store, entry_i, detail_j) => { - store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).index + store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).id } } } @@ -533,7 +533,7 @@ impl<'a> GlyphStore { pub fn add_glyph_for_char_index(&mut self, i: int, data: &GlyphData) { fn glyph_is_compressible(data: &GlyphData) -> bool { - is_simple_glyph_id(data.index) + is_simple_glyph_id(data.id) && is_simple_advance(data.advance) && data.offset.is_zero() && data.cluster_start // others are stored in detail buffer @@ -544,9 +544,9 @@ impl<'a> GlyphStore { let entry = match (data.is_missing, glyph_is_compressible(data)) { (true, _) => GlyphEntry::missing(1), - (false, true) => GlyphEntry::simple(data.index, data.advance), + (false, true) => GlyphEntry::simple(data.id, data.advance), (false, false) => { - let glyph = [DetailedGlyph::new(data.index, data.advance, data.offset)]; + let glyph = [DetailedGlyph::new(data.id, data.advance, data.offset)]; self.detail_store.add_detailed_glyphs_for_entry(i, glyph); GlyphEntry::complex(data.cluster_start, data.ligature_start, 1) } @@ -566,7 +566,7 @@ impl<'a> GlyphStore { true => GlyphEntry::missing(glyph_count), false => { let glyphs_vec = slice::from_fn(glyph_count as uint, |i| { - DetailedGlyph::new(data_for_glyphs[i].index, + DetailedGlyph::new(data_for_glyphs[i].id, data_for_glyphs[i].advance, data_for_glyphs[i].offset) }); diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index fc07de9422d..7fcfca35426 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -6,7 +6,7 @@ extern crate harfbuzz; use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag}; use platform::font::FontTable; -use text::glyph::{GlyphStore, GlyphIndex, GlyphData}; +use text::glyph::{GlyphStore, GlyphId, GlyphData}; use text::shaping::ShaperMethods; use text::util::{float_to_fixed, fixed_to_float}; @@ -55,7 +55,7 @@ pub struct ShapedGlyphData { pub struct ShapedGlyphEntry { cluster: int, - codepoint: GlyphIndex, + codepoint: GlyphId, advance: Au, offset: Option>, } @@ -125,7 +125,7 @@ impl ShapedGlyphData { ShapedGlyphEntry { cluster: (*glyph_info_i).cluster as int, - codepoint: (*glyph_info_i).codepoint as GlyphIndex, + codepoint: (*glyph_info_i).codepoint as GlyphId, advance: x_advance, offset: offset, } @@ -485,7 +485,7 @@ extern fn glyph_h_advance_func(_: *hb_font_t, assert!(font.is_not_null()); unsafe { - let advance = (*font).glyph_h_advance(glyph as GlyphIndex); + let advance = (*font).glyph_h_advance(glyph as GlyphId); Shaper::float_to_fixed(advance) } }