Rename GlyphIndex->GlyphId

This will allow us to use the GlyphIndex identifier to refer to glyph indexes into text runs in the future.
This commit is contained in:
Brendan Zabarauskas 2014-05-07 16:06:07 -07:00
parent b036bee532
commit 68f9aad883
6 changed files with 49 additions and 49 deletions

View file

@ -23,7 +23,7 @@ use servo_util::geometry::Au;
use platform::font_context::FontContextHandle; use platform::font_context::FontContextHandle;
use platform::font::{FontHandle, FontTable}; use platform::font::{FontHandle, FontTable};
use render_context::RenderContext; use render_context::RenderContext;
use text::glyph::{GlyphStore, GlyphIndex}; use text::glyph::{GlyphStore, GlyphId};
use text::shaping::ShaperMethods; use text::shaping::ShaperMethods;
use text::{Shaper, TextRun}; use text::{Shaper, TextRun};
@ -45,8 +45,8 @@ pub trait FontHandleMethods {
fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle) fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
-> Result<FontHandle, ()>; -> Result<FontHandle, ()>;
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>; fn glyph_index(&self, codepoint: char) -> Option<GlyphId>;
fn glyph_h_advance(&self, GlyphIndex) -> Option<FractionalPixel>; fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
fn get_metrics(&self) -> FontMetrics; fn get_metrics(&self) -> FontMetrics;
fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>; fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>;
} }
@ -361,7 +361,7 @@ impl Font {
let glyph_offset = glyph.offset().unwrap_or(Zero::zero()); let glyph_offset = glyph.offset().unwrap_or(Zero::zero());
let azglyph = struct__AzGlyph { let azglyph = struct__AzGlyph {
mIndex: glyph.index() as uint32_t, mIndex: glyph.id() as uint32_t,
mPosition: struct__AzPoint { mPosition: struct__AzPoint {
x: (origin.x + glyph_offset.x).to_nearest_px() as AzFloat, x: (origin.x + glyph_offset.x).to_nearest_px() as AzFloat,
y: (origin.y + glyph_offset.y).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())) FontDescriptor::new(self.style.clone(), SelectorPlatformIdentifier(self.handle.face_identifier()))
} }
pub fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex> { pub fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
self.handle.glyph_index(codepoint) 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; let handle = &self.handle;
self.glyph_advance_cache.find_or_create(&glyph, |glyph| { self.glyph_advance_cache.find_or_create(&glyph, |glyph| {
match handle.glyph_h_advance(*glyph) { match handle.glyph_h_advance(*glyph) {

View file

@ -9,7 +9,7 @@ use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};
use servo_util::geometry::Au; use servo_util::geometry::Au;
use servo_util::geometry; use servo_util::geometry;
use platform::font_context::FontContextHandle; use platform::font_context::FontContextHandle;
use text::glyph::GlyphIndex; use text::glyph::GlyphId;
use text::util::{float_to_fixed, fixed_to_float}; use text::util::{float_to_fixed, fixed_to_float};
use style::computed_values::font_weight; use style::computed_values::font_weight;
@ -174,12 +174,12 @@ impl FontHandleMethods for FontHandle {
} }
fn glyph_index(&self, fn glyph_index(&self,
codepoint: char) -> Option<GlyphIndex> { codepoint: char) -> Option<GlyphId> {
assert!(self.face.is_not_null()); assert!(self.face.is_not_null());
unsafe { unsafe {
let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong); let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong);
return if idx != 0 as FT_UInt { return if idx != 0 as FT_UInt {
Some(idx as GlyphIndex) Some(idx as GlyphId)
} else { } else {
debug!("Invalid codepoint: {}", codepoint); debug!("Invalid codepoint: {}", codepoint);
None None
@ -188,7 +188,7 @@ impl FontHandleMethods for FontHandle {
} }
fn glyph_h_advance(&self, fn glyph_h_advance(&self,
glyph: GlyphIndex) -> Option<FractionalPixel> { glyph: GlyphId) -> Option<FractionalPixel> {
assert!(self.face.is_not_null()); assert!(self.face.is_not_null());
unsafe { unsafe {
let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0); let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0);

View file

@ -9,7 +9,7 @@ use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle};
use servo_util::geometry::Au; use servo_util::geometry::Au;
use servo_util::geometry; use servo_util::geometry;
use platform::font_context::FontContextHandle; use platform::font_context::FontContextHandle;
use text::glyph::GlyphIndex; use text::glyph::GlyphId;
use text::util::{float_to_fixed, fixed_to_float}; use text::util::{float_to_fixed, fixed_to_float};
use style::computed_values::font_weight; use style::computed_values::font_weight;
@ -174,12 +174,12 @@ impl FontHandleMethods for FontHandle {
} }
fn glyph_index(&self, fn glyph_index(&self,
codepoint: char) -> Option<GlyphIndex> { codepoint: char) -> Option<GlyphId> {
assert!(self.face.is_not_null()); assert!(self.face.is_not_null());
unsafe { unsafe {
let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong); let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong);
return if idx != 0 as FT_UInt { return if idx != 0 as FT_UInt {
Some(idx as GlyphIndex) Some(idx as GlyphId)
} else { } else {
debug!("Invalid codepoint: {}", codepoint); debug!("Invalid codepoint: {}", codepoint);
None None
@ -188,7 +188,7 @@ impl FontHandleMethods for FontHandle {
} }
fn glyph_h_advance(&self, fn glyph_h_advance(&self,
glyph: GlyphIndex) -> Option<FractionalPixel> { glyph: GlyphId) -> Option<FractionalPixel> {
assert!(self.face.is_not_null()); assert!(self.face.is_not_null());
unsafe { unsafe {
let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0); let res = FT_Load_Glyph(self.face, glyph as FT_UInt, 0);

View file

@ -14,7 +14,7 @@ use font::{FractionalPixel, SpecifiedFontStyle};
use servo_util::geometry::{Au, px_to_pt}; use servo_util::geometry::{Au, px_to_pt};
use servo_util::geometry; use servo_util::geometry;
use platform::macos::font_context::FontContextHandle; use platform::macos::font_context::FontContextHandle;
use text::glyph::GlyphIndex; use text::glyph::GlyphId;
use style::computed_values::font_weight; use style::computed_values::font_weight;
use core_foundation::base::CFIndex; use core_foundation::base::CFIndex;
@ -125,7 +125,7 @@ impl FontHandleMethods for FontHandle {
return FontHandle::new_from_CTFont(fctx, new_font); return FontHandle::new_from_CTFont(fctx, new_font);
} }
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex> { fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
let characters: [UniChar, ..1] = [codepoint as UniChar]; let characters: [UniChar, ..1] = [codepoint as UniChar];
let glyphs: [CGGlyph, ..1] = [0 as CGGlyph]; let glyphs: [CGGlyph, ..1] = [0 as CGGlyph];
let count: CFIndex = 1; let count: CFIndex = 1;
@ -140,10 +140,10 @@ impl FontHandleMethods for FontHandle {
} }
assert!(glyphs[0] != 0); // FIXME: error handling 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<FractionalPixel> { fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> {
let glyphs = [glyph as CGGlyph]; let glyphs = [glyph as CGGlyph];
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation, let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
&glyphs[0], &glyphs[0],

View file

@ -39,15 +39,15 @@ impl GlyphEntry {
} }
// Creates a GlyphEntry for the common case // Creates a GlyphEntry for the common case
fn simple(index: GlyphIndex, advance: Au) -> GlyphEntry { fn simple(id: GlyphId, advance: Au) -> GlyphEntry {
assert!(is_simple_glyph_id(index)); assert!(is_simple_glyph_id(id));
assert!(is_simple_advance(advance)); assert!(is_simple_advance(advance));
let index_mask = index as u32; let id_mask = id as u32;
let Au(advance) = advance; let Au(advance) = advance;
let advance_mask = (advance as u32) << GLYPH_ADVANCE_SHIFT; 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 // 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 /// The id of a particular glyph within a font
pub type GlyphIndex = u32; pub type GlyphId = u32;
// TODO: unify with bit flags? // TODO: unify with bit flags?
#[deriving(Eq)] #[deriving(Eq)]
@ -100,12 +100,12 @@ static BREAK_TYPE_HYPHEN: u8 = 0x2;
fn break_flag_to_enum(flag: u8) -> BreakType { fn break_flag_to_enum(flag: u8) -> BreakType {
if (flag & BREAK_TYPE_NORMAL) != 0 { 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 { 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 FLAG_CHAR_IS_LOW_SURROGATE: u32 = 0x00000020;
//static CHAR_IDENTITY_FLAGS_MASK: u32 = 0x00000038; //static CHAR_IDENTITY_FLAGS_MASK: u32 = 0x00000038;
fn is_simple_glyph_id(glyphId: GlyphIndex) -> bool { fn is_simple_glyph_id(id: GlyphId) -> bool {
((glyphId as u32) & GLYPH_ID_MASK) == glyphId ((id as u32) & GLYPH_ID_MASK) == id
} }
fn is_simple_advance(advance: Au) -> bool { fn is_simple_advance(advance: Au) -> bool {
@ -171,7 +171,7 @@ impl GlyphEntry {
NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT).unwrap() NumCast::from((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT).unwrap()
} }
fn index(&self) -> GlyphIndex { fn id(&self) -> GlyphId {
self.value & GLYPH_ID_MASK self.value & GLYPH_ID_MASK
} }
@ -253,7 +253,7 @@ impl GlyphEntry {
// correspond to one character, or the glyph's data couldn't be packed. // correspond to one character, or the glyph's data couldn't be packed.
#[deriving(Clone)] #[deriving(Clone)]
struct DetailedGlyph { struct DetailedGlyph {
index: GlyphIndex, id: GlyphId,
// glyph's advance, in the text's direction (RTL or RTL) // glyph's advance, in the text's direction (RTL or RTL)
advance: Au, advance: Au,
// glyph's offset from the font's em-box (from top-left) // glyph's offset from the font's em-box (from top-left)
@ -261,9 +261,9 @@ struct DetailedGlyph {
} }
impl DetailedGlyph { impl DetailedGlyph {
fn new(index: GlyphIndex, advance: Au, offset: Point2D<Au>) -> DetailedGlyph { fn new(id: GlyphId, advance: Au, offset: Point2D<Au>) -> DetailedGlyph {
DetailedGlyph { DetailedGlyph {
index: index, id: id,
advance: advance, advance: advance,
offset: offset offset: offset
} }
@ -423,7 +423,7 @@ impl<'a> DetailedGlyphStore {
// This struct is used by GlyphStore clients to provide new glyph data. // 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. // It should be allocated on the stack and passed by reference to GlyphStore.
pub struct GlyphData { pub struct GlyphData {
index: GlyphIndex, id: GlyphId,
advance: Au, advance: Au,
offset: Point2D<Au>, offset: Point2D<Au>,
is_missing: bool, is_missing: bool,
@ -432,7 +432,7 @@ pub struct GlyphData {
} }
impl GlyphData { impl GlyphData {
pub fn new(index: GlyphIndex, pub fn new(id: GlyphId,
advance: Au, advance: Au,
offset: Option<Point2D<Au>>, offset: Option<Point2D<Au>>,
is_missing: bool, is_missing: bool,
@ -445,7 +445,7 @@ impl GlyphData {
}; };
GlyphData { GlyphData {
index: index, id: id,
advance: advance, advance: advance,
offset: offset, offset: offset,
is_missing: is_missing, is_missing: is_missing,
@ -465,11 +465,11 @@ pub enum GlyphInfo<'a> {
} }
impl<'a> GlyphInfo<'a> { impl<'a> GlyphInfo<'a> {
pub fn index(self) -> GlyphIndex { pub fn id(self) -> GlyphId {
match self { 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) => { 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) { pub fn add_glyph_for_char_index(&mut self, i: int, data: &GlyphData) {
fn glyph_is_compressible(data: &GlyphData) -> bool { fn glyph_is_compressible(data: &GlyphData) -> bool {
is_simple_glyph_id(data.index) is_simple_glyph_id(data.id)
&& is_simple_advance(data.advance) && is_simple_advance(data.advance)
&& data.offset.is_zero() && data.offset.is_zero()
&& data.cluster_start // others are stored in detail buffer && 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)) { let entry = match (data.is_missing, glyph_is_compressible(data)) {
(true, _) => GlyphEntry::missing(1), (true, _) => GlyphEntry::missing(1),
(false, true) => GlyphEntry::simple(data.index, data.advance), (false, true) => GlyphEntry::simple(data.id, data.advance),
(false, false) => { (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); self.detail_store.add_detailed_glyphs_for_entry(i, glyph);
GlyphEntry::complex(data.cluster_start, data.ligature_start, 1) GlyphEntry::complex(data.cluster_start, data.ligature_start, 1)
} }
@ -566,7 +566,7 @@ impl<'a> GlyphStore {
true => GlyphEntry::missing(glyph_count), true => GlyphEntry::missing(glyph_count),
false => { false => {
let glyphs_vec = slice::from_fn(glyph_count as uint, |i| { 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].advance,
data_for_glyphs[i].offset) data_for_glyphs[i].offset)
}); });

View file

@ -6,7 +6,7 @@ extern crate harfbuzz;
use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag}; use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag};
use platform::font::FontTable; use platform::font::FontTable;
use text::glyph::{GlyphStore, GlyphIndex, GlyphData}; use text::glyph::{GlyphStore, GlyphId, GlyphData};
use text::shaping::ShaperMethods; use text::shaping::ShaperMethods;
use text::util::{float_to_fixed, fixed_to_float}; use text::util::{float_to_fixed, fixed_to_float};
@ -55,7 +55,7 @@ pub struct ShapedGlyphData {
pub struct ShapedGlyphEntry { pub struct ShapedGlyphEntry {
cluster: int, cluster: int,
codepoint: GlyphIndex, codepoint: GlyphId,
advance: Au, advance: Au,
offset: Option<Point2D<Au>>, offset: Option<Point2D<Au>>,
} }
@ -125,7 +125,7 @@ impl ShapedGlyphData {
ShapedGlyphEntry { ShapedGlyphEntry {
cluster: (*glyph_info_i).cluster as int, cluster: (*glyph_info_i).cluster as int,
codepoint: (*glyph_info_i).codepoint as GlyphIndex, codepoint: (*glyph_info_i).codepoint as GlyphId,
advance: x_advance, advance: x_advance,
offset: offset, offset: offset,
} }
@ -485,7 +485,7 @@ extern fn glyph_h_advance_func(_: *hb_font_t,
assert!(font.is_not_null()); assert!(font.is_not_null());
unsafe { unsafe {
let advance = (*font).glyph_h_advance(glyph as GlyphIndex); let advance = (*font).glyph_h_advance(glyph as GlyphId);
Shaper::float_to_fixed(advance) Shaper::float_to_fixed(advance)
} }
} }