mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use the actual horizontal advance
This commit is contained in:
parent
d9c59e3adf
commit
632c781206
5 changed files with 36 additions and 11 deletions
|
@ -156,7 +156,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
|
|||
|
||||
let expected = Rect(
|
||||
Point2D(px_to_au(0), px_to_au(0)),
|
||||
Size2D(px_to_au(220), px_to_au(20))
|
||||
Size2D(px_to_au(84), px_to_au(20))
|
||||
);
|
||||
|
||||
assert di[0].bounds == expected;
|
||||
|
@ -174,7 +174,7 @@ fn should_calculate_the_bounds_of_the_text_items() {
|
|||
|
||||
let expected = Rect(
|
||||
Point2D(px_to_au(0), px_to_au(0)),
|
||||
Size2D(px_to_au(220), px_to_au(20))
|
||||
Size2D(px_to_au(84), px_to_au(20))
|
||||
);
|
||||
|
||||
assert di[1].bounds == expected;
|
||||
|
|
|
@ -46,6 +46,6 @@ fn should_calculate_the_size_of_the_text_box() {
|
|||
|
||||
let subbox = alt check b.kind { TextBox(subbox) { subbox } };
|
||||
b.reflow_text(px_to_au(800), subbox);
|
||||
let expected = Size2D(px_to_au(220), px_to_au(20));
|
||||
let expected = Size2D(px_to_au(84), px_to_au(20));
|
||||
assert b.bounds.size == expected;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
export font, create_test_font, test_font_bin;
|
||||
|
||||
import libc::{ c_int, c_double };
|
||||
import vec_to_ptr = vec::unsafe::to_ptr;
|
||||
import libc::{ c_int, c_double, c_ulong };
|
||||
import ptr::{ null, addr_of };
|
||||
import azure::cairo::{
|
||||
cairo_font_face_t,
|
||||
cairo_scaled_font_t,
|
||||
cairo_glyph_t,
|
||||
cairo_text_extents_t,
|
||||
CAIRO_STATUS_SUCCESS,
|
||||
};
|
||||
import azure::cairo::bindgen::{
|
||||
cairo_font_face_destroy,
|
||||
cairo_scaled_font_destroy,
|
||||
cairo_scaled_font_text_to_glyphs,
|
||||
cairo_scaled_font_glyph_extents,
|
||||
cairo_glyph_free,
|
||||
};
|
||||
|
||||
|
@ -74,8 +77,30 @@ class font/& {
|
|||
}
|
||||
}
|
||||
|
||||
fn glyph_h_advance(_glyph: uint) -> int {
|
||||
20
|
||||
fn glyph_h_advance(glyph: uint) -> int {
|
||||
|
||||
let glyphs: [cairo_glyph_t] = [{
|
||||
index: glyph as c_ulong,
|
||||
x: 0 as c_double,
|
||||
y: 0 as c_double,
|
||||
}];
|
||||
let extents: cairo_text_extents_t = {
|
||||
x_bearing: 0 as c_double,
|
||||
y_bearing: 0 as c_double,
|
||||
width: 0 as c_double,
|
||||
height: 0 as c_double,
|
||||
x_advance: 0 as c_double,
|
||||
y_advance: 0 as c_double,
|
||||
};
|
||||
|
||||
cairo_scaled_font_glyph_extents(
|
||||
self.cairo_font, unsafe { vec_to_ptr(glyphs) },
|
||||
1 as c_int, addr_of(extents));
|
||||
|
||||
#debug("x_advance: %?", extents.x_advance);
|
||||
#debug("y_advance: %?", extents.y_advance);
|
||||
|
||||
ret extents.x_advance as int;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,8 +266,7 @@ fn should_get_glyph_advance() {
|
|||
|
||||
let font = create_test_font();
|
||||
let x = font.glyph_h_advance(40u);
|
||||
// This number is bogus
|
||||
assert x == 20;
|
||||
assert x == 15;
|
||||
}
|
||||
|
||||
fn should_be_able_to_create_instances_in_multiple_threads() {
|
||||
|
|
|
@ -155,6 +155,7 @@ fn should_get_glyph_h_advance() {
|
|||
|
||||
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(20) };
|
||||
let actual = glyphs.map { |g| g.pos.advance.x };
|
||||
let expected = [6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7].map { |a| px_to_au(a) };
|
||||
assert expected == actual;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,6 @@ fn should_calculate_the_total_size() {
|
|||
|
||||
let font = create_test_font();
|
||||
let run = text_run(&font, "firecracker");
|
||||
let expected = Size2D(px_to_au(220), px_to_au(20));
|
||||
let expected = Size2D(px_to_au(84), px_to_au(20));
|
||||
assert run.size() == expected;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue