diff options
author | Glenn Watson <gw@intuitionlibrary.com> | 2014-07-21 13:32:04 +1000 |
---|---|---|
committer | Glenn Watson <gw@intuitionlibrary.com> | 2014-07-24 07:51:39 +1000 |
commit | 3a55c376f37be2af0875464fd8648f358c221e28 (patch) | |
tree | b5fc0dcd678d2ccbfc94074026a2f4e8f594e8ca /src | |
parent | 2ed7444624d58df9d6adc2dd64c837d0e58f8b30 (diff) | |
download | servo-3a55c376f37be2af0875464fd8648f358c221e28.tar.gz servo-3a55c376f37be2af0875464fd8648f358c221e28.zip |
Implement kerning support for linux/android. Improves some wikipedia issues (#2554).
Diffstat (limited to 'src')
-rw-r--r-- | src/components/gfx/font.rs | 5 | ||||
-rw-r--r-- | src/components/gfx/platform/android/font.rs | 16 | ||||
-rw-r--r-- | src/components/gfx/platform/linux/font.rs | 16 | ||||
-rw-r--r-- | src/components/gfx/platform/macos/font.rs | 6 | ||||
-rw-r--r-- | src/components/gfx/text/shaping/harfbuzz.rs | 17 | ||||
m--------- | src/support/harfbuzz/rust-harfbuzz | 0 |
6 files changed, 54 insertions, 6 deletions
diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index a17bf199979..2c902b8a2bb 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -36,6 +36,7 @@ pub trait FontHandleMethods { fn glyph_index(&self, codepoint: char) -> Option<GlyphId>; fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>; + fn glyph_h_kerning(&self, GlyphId, GlyphId) -> FractionalPixel; fn get_metrics(&self) -> FontMetrics; fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>; } @@ -148,6 +149,10 @@ impl Font { self.handle.glyph_index(codepoint) } + pub fn glyph_h_kerning(&mut self, first_glyph: GlyphId, second_glyph: GlyphId) -> FractionalPixel { + self.handle.glyph_h_kerning(first_glyph, second_glyph) + } + pub fn glyph_h_advance(&mut self, glyph: GlyphId) -> FractionalPixel { let handle = &self.handle; self.glyph_advance_cache.find_or_create(&glyph, |glyph| { diff --git a/src/components/gfx/platform/android/font.rs b/src/components/gfx/platform/android/font.rs index 9e393733c69..989dda4a718 100644 --- a/src/components/gfx/platform/android/font.rs +++ b/src/components/gfx/platform/android/font.rs @@ -16,12 +16,12 @@ use platform::font_template::FontTemplateData; use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name}; use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size}; -use freetype::freetype::{FT_Get_Sfnt_Table}; +use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table}; use freetype::freetype::{FT_New_Memory_Face, FT_Done_Face}; use freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec}; use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong}; -use freetype::freetype::{FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD}; -use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics}; +use freetype::freetype::{FT_KERNING_DEFAULT, FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD}; +use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics, struct_FT_Vector_}; use freetype::freetype::{ft_sfnt_os2}; use freetype::tt_os2::TT_OS2; @@ -171,6 +171,16 @@ impl FontHandleMethods for FontHandle { } } + fn glyph_h_kerning(&self, first_glyph: GlyphId, second_glyph: GlyphId) + -> FractionalPixel { + assert!(self.face.is_not_null()); + let delta = struct_FT_Vector_ { x: 0, y: 0 }; + unsafe { + FT_Get_Kerning(self.face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &delta); + } + fixed_to_float_ft(delta.x as i32) + } + fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> { assert!(self.face.is_not_null()); diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index 9e393733c69..989dda4a718 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -16,12 +16,12 @@ use platform::font_template::FontTemplateData; use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name}; use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size}; -use freetype::freetype::{FT_Get_Sfnt_Table}; +use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table}; use freetype::freetype::{FT_New_Memory_Face, FT_Done_Face}; use freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec}; use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong}; -use freetype::freetype::{FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD}; -use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics}; +use freetype::freetype::{FT_KERNING_DEFAULT, FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD}; +use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics, struct_FT_Vector_}; use freetype::freetype::{ft_sfnt_os2}; use freetype::tt_os2::TT_OS2; @@ -171,6 +171,16 @@ impl FontHandleMethods for FontHandle { } } + fn glyph_h_kerning(&self, first_glyph: GlyphId, second_glyph: GlyphId) + -> FractionalPixel { + assert!(self.face.is_not_null()); + let delta = struct_FT_Vector_ { x: 0, y: 0 }; + unsafe { + FT_Get_Kerning(self.face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &delta); + } + fixed_to_float_ft(delta.x as i32) + } + fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> { assert!(self.face.is_not_null()); diff --git a/src/components/gfx/platform/macos/font.rs b/src/components/gfx/platform/macos/font.rs index 26209abb9d9..9ff32f0dee9 100644 --- a/src/components/gfx/platform/macos/font.rs +++ b/src/components/gfx/platform/macos/font.rs @@ -124,6 +124,12 @@ impl FontHandleMethods for FontHandle { return Some(glyphs[0] as GlyphId); } + fn glyph_h_kerning(&self, _first_glyph: GlyphId, _second_glyph: GlyphId) + -> FractionalPixel { + // TODO: Implement on mac + 0.0 + } + fn glyph_h_advance(&self, glyph: GlyphId) -> Option<FractionalPixel> { let glyphs = [glyph as CGGlyph]; let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation, diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index e028ae8dac2..c495c3e26be 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -27,6 +27,7 @@ use harfbuzz::{hb_font_funcs_create}; use harfbuzz::{hb_font_funcs_destroy}; use harfbuzz::{hb_font_funcs_set_glyph_func}; use harfbuzz::{hb_font_funcs_set_glyph_h_advance_func}; +use harfbuzz::{hb_font_funcs_set_glyph_h_kerning_func}; use harfbuzz::{hb_font_funcs_t, hb_buffer_t, hb_codepoint_t}; use harfbuzz::{hb_font_set_funcs}; use harfbuzz::{hb_font_set_ppem}; @@ -176,6 +177,7 @@ impl Shaper { let hb_funcs: *hb_font_funcs_t = hb_font_funcs_create(); hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, null(), None); hb_font_funcs_set_glyph_h_advance_func(hb_funcs, glyph_h_advance_func, null(), None); + hb_font_funcs_set_glyph_h_kerning_func(hb_funcs, glyph_h_kerning_func, null(), null()); hb_font_set_funcs(hb_font, hb_funcs, font_ptr as *c_void, None); Shaper { @@ -487,6 +489,21 @@ extern fn glyph_h_advance_func(_: *hb_font_t, } } +extern fn glyph_h_kerning_func(_: *hb_font_t, + font_data: *c_void, + first_glyph: hb_codepoint_t, + second_glyph: hb_codepoint_t, + _: *c_void) + -> hb_position_t { + let font: *mut Font = font_data as *mut Font; + assert!(font.is_not_null()); + + unsafe { + let advance = (*font).glyph_h_kerning(first_glyph as GlyphId, second_glyph as GlyphId); + Shaper::float_to_fixed(advance) + } +} + // Callback to get a font table out of a font. extern fn get_font_table_func(_: *hb_face_t, tag: hb_tag_t, user_data: *c_void) -> *hb_blob_t { unsafe { diff --git a/src/support/harfbuzz/rust-harfbuzz b/src/support/harfbuzz/rust-harfbuzz -Subproject 3763b41bc060731b7644e83f923ec69ca7c0c20 +Subproject db93ee4a61154ded598e6560df78a9e0e164c81 |