зеркало из https://github.com/mozilla/gecko-dev.git
servo: Misc work on fonts
Source-Repo: https://github.com/servo/servo Source-Revision: e1d09aae96322a3aa30820e3809822f99a14350d
This commit is contained in:
Родитель
d39801bea6
Коммит
5f2e136e6d
|
@ -42,7 +42,7 @@ class font/& {
|
||||||
&self.fontbuf
|
&self.fontbuf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_glyph_idx(codepoint: char) -> option<uint> {
|
fn glyph_idx(codepoint: char) -> option<uint> {
|
||||||
#debug("getting glyph for codepoint %u", codepoint as uint);
|
#debug("getting glyph for codepoint %u", codepoint as uint);
|
||||||
let codepoint_str = str::from_char(codepoint);
|
let codepoint_str = str::from_char(codepoint);
|
||||||
|
|
||||||
|
@ -73,6 +73,10 @@ class font/& {
|
||||||
none
|
none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn glyph_advance(_glyph: uint) -> (int, int) {
|
||||||
|
(10, 10)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cairo_font(buf: &[u8]) -> (*cairo_scaled_font_t, fn@()) {
|
fn get_cairo_font(buf: &[u8]) -> (*cairo_scaled_font_t, fn@()) {
|
||||||
|
@ -190,11 +194,20 @@ fn should_get_glyph_indexes() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
||||||
let font = create_test_font();
|
let font = create_test_font();
|
||||||
let glyph_idx = font.get_glyph_idx('w');
|
let glyph_idx = font.glyph_idx('w');
|
||||||
assert glyph_idx == some(40u);
|
assert glyph_idx == some(40u);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_be_threadsafe() {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_be_able_to_create_instances_in_multiple_threads() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
||||||
iter::repeat(10u) {||
|
iter::repeat(10u) {||
|
||||||
|
|
|
@ -35,29 +35,7 @@ import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy,
|
||||||
Calculate the layout metrics associated with a some given text
|
Calculate the layout metrics associated with a some given text
|
||||||
when rendered in a specific font.
|
when rendered in a specific font.
|
||||||
"]
|
"]
|
||||||
fn shape_text(_font: &font, text: str) -> [glyph] {
|
fn shape_text(font: &font, text: str) -> [glyph] unsafe {
|
||||||
let mut glyphs = [];
|
|
||||||
let mut cur_x = 0u;
|
|
||||||
for text.each_char {
|
|
||||||
|ch|
|
|
||||||
// TODO: Use HarfBuzz!
|
|
||||||
let hb_pos = {
|
|
||||||
x_advance: 10 as int32_t,
|
|
||||||
y_advance: 0 as int32_t,
|
|
||||||
x_offset: cur_x as int32_t,
|
|
||||||
y_offset: 0 as int32_t,
|
|
||||||
var: 0 as hb_var_int_t
|
|
||||||
};
|
|
||||||
|
|
||||||
let pos = hb_glyph_pos_to_servo_glyph_pos(hb_pos);
|
|
||||||
vec::push(glyphs, glyph(ch as uint, pos));
|
|
||||||
cur_x += 10u;
|
|
||||||
};
|
|
||||||
|
|
||||||
ret glyphs;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
|
||||||
#debug("shaping text '%s'", text);
|
#debug("shaping text '%s'", text);
|
||||||
|
|
||||||
let face_blob = vec::as_buf(*(*font).buf()) { |buf|
|
let face_blob = vec::as_buf(*(*font).buf()) { |buf|
|
||||||
|
@ -100,14 +78,17 @@ fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
||||||
|
|
||||||
assert info_len == pos_len;
|
assert info_len == pos_len;
|
||||||
|
|
||||||
|
let mut glyphs = [];
|
||||||
|
|
||||||
for uint::range(0u, info_len as uint) { |i|
|
for uint::range(0u, info_len as uint) { |i|
|
||||||
let info_ = offset(info_, i);
|
let info_ = offset(info_, i);
|
||||||
let pos = offset(pos, i);
|
let pos = offset(pos, i);
|
||||||
#debug("glyph %?: codep %?, cluster %?,\
|
let codepoint = (*info_).codepoint as uint;
|
||||||
x_adv %?, y_adv %?, x_off %?, y_of %?",
|
let pos = hb_glyph_pos_to_servo_glyph_pos(&*pos);
|
||||||
i, (*info_).codepoint, (*info_).cluster,
|
#debug("glyph %?: codep %?, x_adv %?, y_adv %?, x_off %?, y_of %?",
|
||||||
(*pos).x_advance, (*pos).y_advance,
|
i, codepoint, pos.advance.x, pos.advance.y, pos.offset.x, pos.offset.y);
|
||||||
(*pos).x_offset, (*pos).y_offset);
|
|
||||||
|
glyphs += [glyph(codepoint, pos)];
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_buffer_destroy(buffer);
|
hb_buffer_destroy(buffer);
|
||||||
|
@ -116,7 +97,7 @@ fn shape_text2(font: &font, text: str) -> [glyph] unsafe {
|
||||||
hb_face_destroy(hbface);
|
hb_face_destroy(hbface);
|
||||||
hb_blob_destroy(face_blob);
|
hb_blob_destroy(face_blob);
|
||||||
|
|
||||||
ret [];
|
ret glyphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
crust fn glyph_func(_font: *hb_font_t,
|
crust fn glyph_func(_font: *hb_font_t,
|
||||||
|
@ -129,7 +110,7 @@ crust fn glyph_func(_font: *hb_font_t,
|
||||||
let font: *font = reinterpret_cast(font_data);
|
let font: *font = reinterpret_cast(font_data);
|
||||||
assert font.is_not_null();
|
assert font.is_not_null();
|
||||||
|
|
||||||
ret alt (*font).get_glyph_idx(unicode as char) {
|
ret alt (*font).glyph_idx(unicode as char) {
|
||||||
some(g) {
|
some(g) {
|
||||||
*glyph = g as hb_codepoint_t;
|
*glyph = g as hb_codepoint_t;
|
||||||
true
|
true
|
||||||
|
@ -140,15 +121,18 @@ crust fn glyph_func(_font: *hb_font_t,
|
||||||
} as hb_bool_t;
|
} 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 {
|
||||||
glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int),
|
glyph_pos(Point2D(px_to_au(hb_pos.x_advance as int),
|
||||||
px_to_au(hb_pos.y_advance as int)),
|
px_to_au(hb_pos.y_advance as int)),
|
||||||
Point2D(px_to_au(hb_pos.x_offset as int),
|
Point2D(px_to_au(hb_pos.x_offset as int),
|
||||||
px_to_au(hb_pos.y_offset as int)))
|
px_to_au(hb_pos.y_offset as int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn should_get_glyph_codepoints() {
|
||||||
fn test_shape_basic() {
|
#[test];
|
||||||
|
|
||||||
let font = font::create_test_font();
|
let font = font::create_test_font();
|
||||||
shape_text2(&font, "firecracker");
|
let glyphs = shape_text(&font, "firecracker");
|
||||||
|
let idxs = glyphs.map { |glyph| glyph.codepoint };
|
||||||
|
assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче