mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Teach text::shaper how to find a glyph index from the font
This commit is contained in:
parent
c1af1b833c
commit
902605c690
1 changed files with 22 additions and 12 deletions
|
@ -68,15 +68,15 @@ fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
||||||
null())
|
null())
|
||||||
};
|
};
|
||||||
|
|
||||||
let face = hb_face_create(face_blob, 0 as c_uint);
|
let hbface = hb_face_create(face_blob, 0 as c_uint);
|
||||||
let font = hb_font_create(face);
|
let hbfont = hb_font_create(hbface);
|
||||||
|
|
||||||
hb_font_set_ppem(font, 10 as c_uint, 10 as c_uint);
|
hb_font_set_ppem(hbfont, 10 as c_uint, 10 as c_uint);
|
||||||
hb_font_set_scale(font, 10 as c_int, 10 as c_int);
|
hb_font_set_scale(hbfont, 10 as c_int, 10 as c_int);
|
||||||
|
|
||||||
let funcs = hb_font_funcs_create();
|
let funcs = hb_font_funcs_create();
|
||||||
hb_font_funcs_set_glyph_func(funcs, glyph_func, null(), null());
|
hb_font_funcs_set_glyph_func(funcs, glyph_func, null(), null());
|
||||||
hb_font_set_funcs(font, funcs, addr_of(*font), null());
|
hb_font_set_funcs(hbfont, funcs, reinterpret_cast(addr_of(*font)), null());
|
||||||
|
|
||||||
let buffer = hb_buffer_create();
|
let buffer = hb_buffer_create();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
||||||
text.len() as c_int);
|
text.len() as c_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_shape(font, buffer, null(), 0 as c_uint);
|
hb_shape(hbfont, buffer, null(), 0 as c_uint);
|
||||||
|
|
||||||
let info_len = 0 as c_uint;
|
let info_len = 0 as c_uint;
|
||||||
let info_ = hb_buffer_get_glyph_infos(buffer, addr_of(info_len));
|
let info_ = hb_buffer_get_glyph_infos(buffer, addr_of(info_len));
|
||||||
|
@ -112,22 +112,32 @@ fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
||||||
|
|
||||||
hb_buffer_destroy(buffer);
|
hb_buffer_destroy(buffer);
|
||||||
hb_font_funcs_destroy(funcs);
|
hb_font_funcs_destroy(funcs);
|
||||||
hb_font_destroy(font);
|
hb_font_destroy(hbfont);
|
||||||
hb_face_destroy(face);
|
hb_face_destroy(hbface);
|
||||||
hb_blob_destroy(face_blob);
|
hb_blob_destroy(face_blob);
|
||||||
|
|
||||||
ret [];
|
ret [];
|
||||||
}
|
}
|
||||||
|
|
||||||
crust fn glyph_func(_font: *hb_font_t,
|
crust fn glyph_func(_font: *hb_font_t,
|
||||||
_font_data: *c_void,
|
font_data: *c_void,
|
||||||
_unicode: hb_codepoint_t,
|
unicode: hb_codepoint_t,
|
||||||
_variant_selector: hb_codepoint_t,
|
_variant_selector: hb_codepoint_t,
|
||||||
glyph: *mut hb_codepoint_t,
|
glyph: *mut hb_codepoint_t,
|
||||||
_user_data: *c_void) -> hb_bool_t unsafe {
|
_user_data: *c_void) -> hb_bool_t unsafe {
|
||||||
|
|
||||||
*glyph = 40 as hb_codepoint_t;
|
let font: *font = reinterpret_cast(font_data);
|
||||||
ret true as hb_bool_t;
|
assert font.is_not_null();
|
||||||
|
|
||||||
|
ret alt (*font).get_glyph_idx(unicode as char) {
|
||||||
|
some(g) {
|
||||||
|
*glyph = g as hb_codepoint_t;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
none {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} as hb_bool_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: hb_glyph_position_t) -> glyph_pos {
|
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: hb_glyph_position_t) -> glyph_pos {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue