mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Put 'use harfbuzz' in text::shaper, not at the crate level
This commit is contained in:
parent
5086fde828
commit
61a615fb4d
3 changed files with 19 additions and 14 deletions
|
@ -10,7 +10,6 @@ use std;
|
||||||
use sdl;
|
use sdl;
|
||||||
use azure;
|
use azure;
|
||||||
use js;
|
use js;
|
||||||
use harfbuzz;
|
|
||||||
use stb_image;
|
use stb_image;
|
||||||
|
|
||||||
mod dom {
|
mod dom {
|
||||||
|
|
|
@ -1,19 +1,12 @@
|
||||||
import gfx::geom::{au, point, px_to_au};
|
import gfx::geom::{au, point};
|
||||||
|
|
||||||
#[doc="The position of a glyph on the screen."]
|
#[doc="The position of a glyph on the screen."]
|
||||||
class glyph_pos {
|
class glyph_pos {
|
||||||
let advance: point<au>;
|
let advance: point<au>;
|
||||||
let offset: point<au>;
|
let offset: point<au>;
|
||||||
|
new(advance: point<au>, offset: point<au>) {
|
||||||
new(hb_pos: harfbuzz::hb_glyph_position_t) {
|
self.advance = advance;
|
||||||
self.advance = {
|
self.offset = offset;
|
||||||
x: px_to_au(hb_pos.x_advance as int),
|
|
||||||
y: px_to_au(hb_pos.y_advance as int)
|
|
||||||
};
|
|
||||||
self.offset = {
|
|
||||||
x: px_to_au(hb_pos.x_offset as int),
|
|
||||||
y: px_to_au(hb_pos.y_offset as int)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
|
use harfbuzz;
|
||||||
|
|
||||||
|
export shape_text;
|
||||||
|
|
||||||
import libc::types::common::c99::int32_t;
|
import libc::types::common::c99::int32_t;
|
||||||
import libc::{c_uint, c_int, c_void};
|
import libc::{c_uint, c_int, c_void};
|
||||||
import font::font;
|
import font::font;
|
||||||
import glyph::{glyph, glyph_pos};
|
import glyph::{glyph, glyph_pos};
|
||||||
import ptr::{null, addr_of, offset};
|
import ptr::{null, addr_of, offset};
|
||||||
|
import gfx::geom::{point, px_to_au};
|
||||||
|
|
||||||
import unsafe::reinterpret_cast;
|
import unsafe::reinterpret_cast;
|
||||||
import harfbuzz::{HB_MEMORY_MODE_READONLY,
|
import harfbuzz::{HB_MEMORY_MODE_READONLY,
|
||||||
HB_DIRECTION_LTR};
|
HB_DIRECTION_LTR};
|
||||||
import harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_buffer_t,
|
import harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_buffer_t,
|
||||||
hb_codepoint_t, hb_bool_t};
|
hb_codepoint_t, hb_bool_t, hb_glyph_position_t};
|
||||||
import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy,
|
import harfbuzz::bindgen::{hb_blob_create, hb_blob_destroy,
|
||||||
hb_face_create, hb_face_destroy,
|
hb_face_create, hb_face_destroy,
|
||||||
hb_font_create, hb_font_destroy,
|
hb_font_create, hb_font_destroy,
|
||||||
|
@ -42,7 +47,8 @@ fn shape_text(_font: &font, text: str) -> [glyph] {
|
||||||
var: 0i32
|
var: 0i32
|
||||||
};
|
};
|
||||||
|
|
||||||
vec::push(glyphs, glyph(ch as uint, glyph_pos(hb_pos)));
|
let pos = hb_glyph_pos_to_servo_glyph_pos(hb_pos);
|
||||||
|
vec::push(glyphs, glyph(ch as uint, pos));
|
||||||
cur_x += 10u;
|
cur_x += 10u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,6 +128,13 @@ crust fn glyph_func(_font: *hb_font_t,
|
||||||
ret true as hb_bool_t;
|
ret true as hb_bool_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hb_glyph_pos_to_servo_glyph_pos(hb_pos: hb_glyph_position_t) -> glyph_pos {
|
||||||
|
glyph_pos(point(px_to_au(hb_pos.x_advance as int),
|
||||||
|
px_to_au(hb_pos.y_advance as int)),
|
||||||
|
point(px_to_au(hb_pos.x_offset as int),
|
||||||
|
px_to_au(hb_pos.y_offset as int)))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shape_basic() {
|
fn test_shape_basic() {
|
||||||
let font = font::create();
|
let font = font::create();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue