mirror of
https://github.com/servo/servo.git
synced 2025-06-28 11:03:39 +01:00
Upgrade to the new harfbuzz-sys crate
This commit is contained in:
parent
a72d7a4f52
commit
062493fac6
6 changed files with 64 additions and 71 deletions
|
@ -12,7 +12,7 @@ path = "lib.rs"
|
|||
bitflags = "0.3"
|
||||
euclid = "0.2"
|
||||
fnv = "1.0"
|
||||
harfbuzz = "0.1"
|
||||
harfbuzz-sys = "0.1"
|
||||
lazy_static = "0.1"
|
||||
libc = "0.1"
|
||||
log = "0.3"
|
||||
|
|
|
@ -52,7 +52,7 @@ extern crate gfx_traits;
|
|||
|
||||
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
|
||||
// shapers. For now, however, this is a hard dependency.
|
||||
extern crate harfbuzz;
|
||||
extern crate harfbuzz_sys as harfbuzz;
|
||||
|
||||
extern crate ipc_channel;
|
||||
extern crate layers;
|
||||
|
|
|
@ -2,34 +2,32 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate harfbuzz;
|
||||
|
||||
use euclid::Point2D;
|
||||
use font::{DISABLE_KERNING_SHAPING_FLAG, Font, FontHandleMethods, FontTableMethods, FontTableTag};
|
||||
use font::{IGNORE_LIGATURES_SHAPING_FLAG, RTL_FLAG, ShapingOptions};
|
||||
use harfbuzz::{HB_DIRECTION_LTR, HB_DIRECTION_RTL, HB_MEMORY_MODE_READONLY};
|
||||
use harfbuzz::{RUST_hb_blob_create, RUST_hb_face_create_for_tables};
|
||||
use harfbuzz::{RUST_hb_buffer_add_utf8};
|
||||
use harfbuzz::{RUST_hb_buffer_create, RUST_hb_font_destroy};
|
||||
use harfbuzz::{RUST_hb_buffer_destroy};
|
||||
use harfbuzz::{RUST_hb_buffer_get_glyph_infos, RUST_hb_shape};
|
||||
use harfbuzz::{RUST_hb_buffer_get_glyph_positions};
|
||||
use harfbuzz::{RUST_hb_buffer_get_length};
|
||||
use harfbuzz::{RUST_hb_buffer_set_direction};
|
||||
use harfbuzz::{RUST_hb_face_destroy};
|
||||
use harfbuzz::{RUST_hb_font_create};
|
||||
use harfbuzz::{RUST_hb_font_funcs_create};
|
||||
use harfbuzz::{RUST_hb_font_funcs_set_glyph_func};
|
||||
use harfbuzz::{RUST_hb_font_funcs_set_glyph_h_advance_func};
|
||||
use harfbuzz::{RUST_hb_font_funcs_set_glyph_h_kerning_func};
|
||||
use harfbuzz::{RUST_hb_font_set_funcs};
|
||||
use harfbuzz::{RUST_hb_font_set_ppem};
|
||||
use harfbuzz::{RUST_hb_font_set_scale};
|
||||
use harfbuzz::{hb_blob_create, hb_face_create_for_tables};
|
||||
use harfbuzz::{hb_blob_t};
|
||||
use harfbuzz::{hb_bool_t};
|
||||
use harfbuzz::{hb_buffer_add_utf8};
|
||||
use harfbuzz::{hb_buffer_create, hb_font_destroy};
|
||||
use harfbuzz::{hb_buffer_destroy};
|
||||
use harfbuzz::{hb_buffer_get_glyph_infos, hb_shape};
|
||||
use harfbuzz::{hb_buffer_get_glyph_positions};
|
||||
use harfbuzz::{hb_buffer_get_length};
|
||||
use harfbuzz::{hb_buffer_set_direction, hb_buffer_set_script};
|
||||
use harfbuzz::{hb_buffer_t, hb_codepoint_t, hb_font_funcs_t};
|
||||
use harfbuzz::{hb_face_destroy};
|
||||
use harfbuzz::{hb_face_t, hb_font_t};
|
||||
use harfbuzz::{hb_feature_t};
|
||||
use harfbuzz::{hb_font_create};
|
||||
use harfbuzz::{hb_font_funcs_create};
|
||||
use harfbuzz::{hb_font_funcs_set_glyph_func};
|
||||
use harfbuzz::{hb_font_funcs_set_glyph_h_advance_func};
|
||||
use harfbuzz::{hb_font_funcs_set_glyph_h_kerning_func};
|
||||
use harfbuzz::{hb_font_set_funcs};
|
||||
use harfbuzz::{hb_font_set_ppem};
|
||||
use harfbuzz::{hb_font_set_scale};
|
||||
use harfbuzz::{hb_glyph_info_t};
|
||||
use harfbuzz::{hb_glyph_position_t};
|
||||
use harfbuzz::{hb_position_t, hb_tag_t};
|
||||
|
@ -70,10 +68,10 @@ impl ShapedGlyphData {
|
|||
pub fn new(buffer: *mut hb_buffer_t) -> ShapedGlyphData {
|
||||
unsafe {
|
||||
let mut glyph_count = 0;
|
||||
let glyph_infos = RUST_hb_buffer_get_glyph_infos(buffer, &mut glyph_count);
|
||||
let glyph_infos = hb_buffer_get_glyph_infos(buffer, &mut glyph_count);
|
||||
assert!(!glyph_infos.is_null());
|
||||
let mut pos_count = 0;
|
||||
let pos_infos = RUST_hb_buffer_get_glyph_positions(buffer, &mut pos_count);
|
||||
let pos_infos = hb_buffer_get_glyph_positions(buffer, &mut pos_count);
|
||||
assert!(!pos_infos.is_null());
|
||||
assert!(glyph_count == pos_count);
|
||||
|
||||
|
@ -151,10 +149,10 @@ impl Drop for Shaper {
|
|||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
assert!(!self.hb_face.is_null());
|
||||
RUST_hb_face_destroy(self.hb_face);
|
||||
hb_face_destroy(self.hb_face);
|
||||
|
||||
assert!(!self.hb_font.is_null());
|
||||
RUST_hb_font_destroy(self.hb_font);
|
||||
hb_font_destroy(self.hb_font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,24 +165,22 @@ impl Shaper {
|
|||
options: *options,
|
||||
};
|
||||
let hb_face: *mut hb_face_t =
|
||||
RUST_hb_face_create_for_tables(font_table_func,
|
||||
(&mut *font_and_shaping_options)
|
||||
as *mut FontAndShapingOptions
|
||||
as *mut c_void,
|
||||
hb_face_create_for_tables(Some(font_table_func),
|
||||
&mut *font_and_shaping_options as *mut _ as *mut c_void,
|
||||
None);
|
||||
let hb_font: *mut hb_font_t = RUST_hb_font_create(hb_face);
|
||||
let hb_font: *mut hb_font_t = hb_font_create(hb_face);
|
||||
|
||||
// Set points-per-em. if zero, performs no hinting in that direction.
|
||||
let pt_size = font.actual_pt_size.to_f64_px();
|
||||
RUST_hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
||||
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
||||
|
||||
// Set scaling. Note that this takes 16.16 fixed point.
|
||||
RUST_hb_font_set_scale(hb_font,
|
||||
hb_font_set_scale(hb_font,
|
||||
Shaper::float_to_fixed(pt_size) as c_int,
|
||||
Shaper::float_to_fixed(pt_size) as c_int);
|
||||
|
||||
// configure static function callbacks.
|
||||
RUST_hb_font_set_funcs(hb_font, **HB_FONT_FUNCS, font as *mut Font as *mut c_void, None);
|
||||
hb_font_set_funcs(hb_font, **HB_FONT_FUNCS, font as *mut Font as *mut c_void, None);
|
||||
|
||||
Shaper {
|
||||
hb_face: hb_face,
|
||||
|
@ -212,14 +208,14 @@ impl ShaperMethods for Shaper {
|
|||
/// font.
|
||||
fn shape_text(&self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore) {
|
||||
unsafe {
|
||||
let hb_buffer: *mut hb_buffer_t = RUST_hb_buffer_create();
|
||||
RUST_hb_buffer_set_direction(hb_buffer, if options.flags.contains(RTL_FLAG) {
|
||||
let hb_buffer: *mut hb_buffer_t = hb_buffer_create();
|
||||
hb_buffer_set_direction(hb_buffer, if options.flags.contains(RTL_FLAG) {
|
||||
HB_DIRECTION_RTL
|
||||
} else {
|
||||
HB_DIRECTION_LTR
|
||||
});
|
||||
|
||||
RUST_hb_buffer_add_utf8(hb_buffer,
|
||||
hb_buffer_add_utf8(hb_buffer,
|
||||
text.as_ptr() as *const c_char,
|
||||
text.len() as c_int,
|
||||
0,
|
||||
|
@ -228,24 +224,24 @@ impl ShaperMethods for Shaper {
|
|||
let mut features = Vec::new();
|
||||
if options.flags.contains(IGNORE_LIGATURES_SHAPING_FLAG) {
|
||||
features.push(hb_feature_t {
|
||||
_tag: LIGA,
|
||||
_value: 0,
|
||||
_start: 0,
|
||||
_end: RUST_hb_buffer_get_length(hb_buffer),
|
||||
tag: LIGA,
|
||||
value: 0,
|
||||
start: 0,
|
||||
end: hb_buffer_get_length(hb_buffer),
|
||||
})
|
||||
}
|
||||
if options.flags.contains(DISABLE_KERNING_SHAPING_FLAG) {
|
||||
features.push(hb_feature_t {
|
||||
_tag: KERN,
|
||||
_value: 0,
|
||||
_start: 0,
|
||||
_end: RUST_hb_buffer_get_length(hb_buffer),
|
||||
tag: KERN,
|
||||
value: 0,
|
||||
start: 0,
|
||||
end: hb_buffer_get_length(hb_buffer),
|
||||
})
|
||||
}
|
||||
|
||||
RUST_hb_shape(self.hb_font, hb_buffer, features.as_mut_ptr(), features.len() as u32);
|
||||
hb_shape(self.hb_font, hb_buffer, features.as_mut_ptr(), features.len() as u32);
|
||||
self.save_glyph_results(text, options, glyphs, hb_buffer);
|
||||
RUST_hb_buffer_destroy(hb_buffer);
|
||||
hb_buffer_destroy(hb_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -522,12 +518,12 @@ impl Shaper {
|
|||
// Callbacks from Harfbuzz when font map and glyph advance lookup needed.
|
||||
lazy_static! {
|
||||
static ref HB_FONT_FUNCS: ptr::Unique<hb_font_funcs_t> = unsafe {
|
||||
let hb_funcs = RUST_hb_font_funcs_create();
|
||||
RUST_hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, ptr::null_mut(), None);
|
||||
RUST_hb_font_funcs_set_glyph_h_advance_func(
|
||||
hb_funcs, glyph_h_advance_func, ptr::null_mut(), None);
|
||||
RUST_hb_font_funcs_set_glyph_h_kerning_func(
|
||||
hb_funcs, glyph_h_kerning_func, ptr::null_mut(), ptr::null_mut());
|
||||
let hb_funcs = hb_font_funcs_create();
|
||||
hb_font_funcs_set_glyph_func(hb_funcs, Some(glyph_func), ptr::null_mut(), None);
|
||||
hb_font_funcs_set_glyph_h_advance_func(
|
||||
hb_funcs, Some(glyph_h_advance_func), ptr::null_mut(), None);
|
||||
hb_font_funcs_set_glyph_h_kerning_func(
|
||||
hb_funcs, Some(glyph_h_kerning_func), ptr::null_mut(), None);
|
||||
|
||||
ptr::Unique::new(hb_funcs)
|
||||
};
|
||||
|
@ -620,11 +616,11 @@ extern fn font_table_func(_: *mut hb_face_t,
|
|||
let mut blob: *mut hb_blob_t = ptr::null_mut();
|
||||
(*font_table_ptr).with_buffer(|buf: *const u8, len: usize| {
|
||||
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed.
|
||||
blob = RUST_hb_blob_create(buf as *const c_char,
|
||||
blob = hb_blob_create(buf as *const c_char,
|
||||
len as c_uint,
|
||||
HB_MEMORY_MODE_READONLY,
|
||||
font_table_ptr as *mut c_void,
|
||||
destroy_blob_func);
|
||||
Some(destroy_blob_func));
|
||||
});
|
||||
|
||||
assert!(!blob.is_null());
|
||||
|
|
7
components/servo/Cargo.lock
generated
7
components/servo/Cargo.lock
generated
|
@ -591,7 +591,7 @@ dependencies = [
|
|||
"fontconfig 0.1.0 (git+https://github.com/servo/rust-fontconfig)",
|
||||
"freetype 0.1.0 (git+https://github.com/servo/rust-freetype)",
|
||||
"gfx_traits 0.0.1",
|
||||
"harfbuzz 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"harfbuzz-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
|
||||
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
|
||||
"lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -734,11 +734,12 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "harfbuzz"
|
||||
version = "0.1.2"
|
||||
name = "harfbuzz-sys"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[css-flexbox-column-reverse.htm]
|
||||
type: reftest
|
||||
expected:
|
||||
if os == "linux": FAIL
|
||||
FAIL
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
[bidi-glyph-mirroring-002.htm]
|
||||
type: reftest
|
||||
expected:
|
||||
if os == "mac": FAIL
|
Loading…
Add table
Add a link
Reference in a new issue