Upgrade to the new harfbuzz-sys crate

This commit is contained in:
Matt Brubeck 2015-09-25 16:52:06 -07:00
parent a72d7a4f52
commit 062493fac6
6 changed files with 64 additions and 71 deletions

View file

@ -12,7 +12,7 @@ path = "lib.rs"
bitflags = "0.3" bitflags = "0.3"
euclid = "0.2" euclid = "0.2"
fnv = "1.0" fnv = "1.0"
harfbuzz = "0.1" harfbuzz-sys = "0.1"
lazy_static = "0.1" lazy_static = "0.1"
libc = "0.1" libc = "0.1"
log = "0.3" log = "0.3"

View file

@ -52,7 +52,7 @@ extern crate gfx_traits;
// Eventually we would like the shaper to be pluggable, as many operating systems have their own // 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. // shapers. For now, however, this is a hard dependency.
extern crate harfbuzz; extern crate harfbuzz_sys as harfbuzz;
extern crate ipc_channel; extern crate ipc_channel;
extern crate layers; extern crate layers;

View file

@ -2,34 +2,32 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate harfbuzz;
use euclid::Point2D; use euclid::Point2D;
use font::{DISABLE_KERNING_SHAPING_FLAG, Font, FontHandleMethods, FontTableMethods, FontTableTag}; use font::{DISABLE_KERNING_SHAPING_FLAG, Font, FontHandleMethods, FontTableMethods, FontTableTag};
use font::{IGNORE_LIGATURES_SHAPING_FLAG, RTL_FLAG, ShapingOptions}; use font::{IGNORE_LIGATURES_SHAPING_FLAG, RTL_FLAG, ShapingOptions};
use harfbuzz::{HB_DIRECTION_LTR, HB_DIRECTION_RTL, HB_MEMORY_MODE_READONLY}; 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::{hb_blob_create, 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_t}; use harfbuzz::{hb_blob_t};
use harfbuzz::{hb_bool_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_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_face_t, hb_font_t};
use harfbuzz::{hb_feature_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_info_t};
use harfbuzz::{hb_glyph_position_t}; use harfbuzz::{hb_glyph_position_t};
use harfbuzz::{hb_position_t, hb_tag_t}; use harfbuzz::{hb_position_t, hb_tag_t};
@ -70,10 +68,10 @@ impl ShapedGlyphData {
pub fn new(buffer: *mut hb_buffer_t) -> ShapedGlyphData { pub fn new(buffer: *mut hb_buffer_t) -> ShapedGlyphData {
unsafe { unsafe {
let mut glyph_count = 0; 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()); assert!(!glyph_infos.is_null());
let mut pos_count = 0; 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!(!pos_infos.is_null());
assert!(glyph_count == pos_count); assert!(glyph_count == pos_count);
@ -151,10 +149,10 @@ impl Drop for Shaper {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
assert!(!self.hb_face.is_null()); 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()); 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, options: *options,
}; };
let hb_face: *mut hb_face_t = let hb_face: *mut hb_face_t =
RUST_hb_face_create_for_tables(font_table_func, hb_face_create_for_tables(Some(font_table_func),
(&mut *font_and_shaping_options) &mut *font_and_shaping_options as *mut _ as *mut c_void,
as *mut FontAndShapingOptions
as *mut c_void,
None); 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. // Set points-per-em. if zero, performs no hinting in that direction.
let pt_size = font.actual_pt_size.to_f64_px(); 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. // 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,
Shaper::float_to_fixed(pt_size) as c_int); Shaper::float_to_fixed(pt_size) as c_int);
// configure static function callbacks. // 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 { Shaper {
hb_face: hb_face, hb_face: hb_face,
@ -212,40 +208,40 @@ impl ShaperMethods for Shaper {
/// font. /// font.
fn shape_text(&self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore) { fn shape_text(&self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore) {
unsafe { unsafe {
let hb_buffer: *mut hb_buffer_t = RUST_hb_buffer_create(); let hb_buffer: *mut hb_buffer_t = hb_buffer_create();
RUST_hb_buffer_set_direction(hb_buffer, if options.flags.contains(RTL_FLAG) { hb_buffer_set_direction(hb_buffer, if options.flags.contains(RTL_FLAG) {
HB_DIRECTION_RTL HB_DIRECTION_RTL
} else { } else {
HB_DIRECTION_LTR HB_DIRECTION_LTR
}); });
RUST_hb_buffer_add_utf8(hb_buffer, hb_buffer_add_utf8(hb_buffer,
text.as_ptr() as *const c_char, text.as_ptr() as *const c_char,
text.len() as c_int, text.len() as c_int,
0, 0,
text.len() as c_int); text.len() as c_int);
let mut features = Vec::new(); let mut features = Vec::new();
if options.flags.contains(IGNORE_LIGATURES_SHAPING_FLAG) { if options.flags.contains(IGNORE_LIGATURES_SHAPING_FLAG) {
features.push(hb_feature_t { features.push(hb_feature_t {
_tag: LIGA, tag: LIGA,
_value: 0, value: 0,
_start: 0, start: 0,
_end: RUST_hb_buffer_get_length(hb_buffer), end: hb_buffer_get_length(hb_buffer),
}) })
} }
if options.flags.contains(DISABLE_KERNING_SHAPING_FLAG) { if options.flags.contains(DISABLE_KERNING_SHAPING_FLAG) {
features.push(hb_feature_t { features.push(hb_feature_t {
_tag: KERN, tag: KERN,
_value: 0, value: 0,
_start: 0, start: 0,
_end: RUST_hb_buffer_get_length(hb_buffer), 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); 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. // Callbacks from Harfbuzz when font map and glyph advance lookup needed.
lazy_static! { lazy_static! {
static ref HB_FONT_FUNCS: ptr::Unique<hb_font_funcs_t> = unsafe { static ref HB_FONT_FUNCS: ptr::Unique<hb_font_funcs_t> = unsafe {
let hb_funcs = RUST_hb_font_funcs_create(); let hb_funcs = hb_font_funcs_create();
RUST_hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, ptr::null_mut(), None); hb_font_funcs_set_glyph_func(hb_funcs, Some(glyph_func), ptr::null_mut(), None);
RUST_hb_font_funcs_set_glyph_h_advance_func( hb_font_funcs_set_glyph_h_advance_func(
hb_funcs, glyph_h_advance_func, ptr::null_mut(), None); hb_funcs, Some(glyph_h_advance_func), ptr::null_mut(), None);
RUST_hb_font_funcs_set_glyph_h_kerning_func( hb_font_funcs_set_glyph_h_kerning_func(
hb_funcs, glyph_h_kerning_func, ptr::null_mut(), ptr::null_mut()); hb_funcs, Some(glyph_h_kerning_func), ptr::null_mut(), None);
ptr::Unique::new(hb_funcs) 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(); let mut blob: *mut hb_blob_t = ptr::null_mut();
(*font_table_ptr).with_buffer(|buf: *const u8, len: usize| { (*font_table_ptr).with_buffer(|buf: *const u8, len: usize| {
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed. // 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, len as c_uint,
HB_MEMORY_MODE_READONLY, HB_MEMORY_MODE_READONLY,
font_table_ptr as *mut c_void, font_table_ptr as *mut c_void,
destroy_blob_func); Some(destroy_blob_func));
}); });
assert!(!blob.is_null()); assert!(!blob.is_null());

View file

@ -591,7 +591,7 @@ dependencies = [
"fontconfig 0.1.0 (git+https://github.com/servo/rust-fontconfig)", "fontconfig 0.1.0 (git+https://github.com/servo/rust-fontconfig)",
"freetype 0.1.0 (git+https://github.com/servo/rust-freetype)", "freetype 0.1.0 (git+https://github.com/servo/rust-freetype)",
"gfx_traits 0.0.1", "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)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
"layers 0.1.0 (git+https://github.com/servo/rust-layers)", "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)", "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
@ -734,11 +734,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "harfbuzz" name = "harfbuzz-sys"
version = "0.1.2" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]

View file

@ -1,4 +1,4 @@
[css-flexbox-column-reverse.htm] [css-flexbox-column-reverse.htm]
type: reftest type: reftest
expected: expected:
if os == "linux": FAIL FAIL

View file

@ -1,4 +0,0 @@
[bidi-glyph-mirroring-002.htm]
type: reftest
expected:
if os == "mac": FAIL