mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Implement kerning support for linux/android. Improves some wikipedia issues (#2554).
This commit is contained in:
parent
2ed7444624
commit
3a55c376f3
6 changed files with 55 additions and 7 deletions
|
@ -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| {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3763b41bc060731b7644e83f923ec69ca7c0c20c
|
||||
Subproject commit db93ee4a61154ded598e6560df78a9e0e164c815
|
Loading…
Add table
Add a link
Reference in a new issue