diff --git a/servo/src/servo/text/font.rs b/servo/src/servo/text/font.rs index b86eefd974dd..2690eb94d77e 100644 --- a/servo/src/servo/text/font.rs +++ b/servo/src/servo/text/font.rs @@ -74,8 +74,8 @@ class font/& { } } - fn glyph_advance(_glyph: uint) -> (int, int) { - (10, 10) + fn glyph_h_advance(_glyph: uint) -> int { + 10 } } @@ -202,9 +202,9 @@ fn should_get_glyph_advance() { #[test]; let font = create_test_font(); - let (x, y) = font.glyph_advance(40u); - // These are bogus numbers - assert x == 10 && y == 10; + let x = font.glyph_h_advance(40u); + // This number is bogus + assert x == 10; } fn should_be_able_to_create_instances_in_multiple_threads() { diff --git a/servo/src/servo/text/shaper.rs b/servo/src/servo/text/shaper.rs index 9450d96ac3e2..bb649d498a33 100644 --- a/servo/src/servo/text/shaper.rs +++ b/servo/src/servo/text/shaper.rs @@ -15,7 +15,7 @@ import harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR}; import harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_buffer_t, hb_codepoint_t, hb_bool_t, hb_glyph_position_t, - hb_var_int_t}; + hb_var_int_t, hb_position_t}; import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy, hb_face_create, hb_face_destroy, hb_font_create, hb_font_destroy, @@ -54,6 +54,7 @@ fn shape_text(font: &font, text: str) -> [glyph] unsafe { let funcs = hb_font_funcs_create(); hb_font_funcs_set_glyph_func(funcs, glyph_func, null(), null()); + hb_font_funcs_set_glyph_h_advance_func(funcs, glyph_h_advance_func, null(), null()); hb_font_set_funcs(hbfont, funcs, reinterpret_cast(addr_of(*font)), null()); let buffer = hb_buffer_create(); @@ -121,6 +122,18 @@ crust fn glyph_func(_font: *hb_font_t, } as hb_bool_t; } +crust fn glyph_h_advance_func(_font: *hb_font_t, + font_data: *c_void, + glyph: hb_codepoint_t, + _user_data: *c_void) -> hb_position_t unsafe { + let font: *font = reinterpret_cast(font_data); + assert font.is_not_null(); + + let h_advance = (*font).glyph_h_advance(glyph as uint); + #debug("h_advance for codepoint %? is %?", glyph, h_advance); + ret h_advance as hb_position_t; +} + fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: &hb_glyph_position_t) -> glyph_pos { glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int), px_to_au(hb_pos.y_advance as int)), @@ -136,3 +149,12 @@ fn should_get_glyph_codepoints() { let idxs = glyphs.map { |glyph| glyph.codepoint }; assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u]; } + +fn should_get_glyph_h_advance() { + #[test]; + + let font = font::create_test_font(); + let glyphs = shape_text(&font, "firecracker"); + // This number is just a placeholder and probably not correct + assert glyphs.all { |glyph| glyph.pos.advance.x == px_to_au(10) }; +}