From f1e268b1e8fa6265dbad472cd6e2f456ad393b2e Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 3 Aug 2015 11:21:43 -0700 Subject: [PATCH 1/2] Sort gfx crates.io dependencies and move to top --- components/gfx/Cargo.toml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index 9ec80d3e091..8f2f1b579bc 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -8,6 +8,21 @@ authors = ["The Servo Project Developers"] name = "gfx" path = "lib.rs" +[dependencies] +bitflags = "0.3" +euclid = "0.1" +fnv = "1.0" +harfbuzz = "0.1" +libc = "0.1" +log = "0.3" +rand = "0.3" +rustc-serialize = "0.3" +serde = "0.4" +serde_macros = "0.4" +smallvec = "0.1" +string_cache = "0.1" +time = "0.1.12" + [dependencies.plugins] path = "../plugins" @@ -51,21 +66,6 @@ git = "https://github.com/pcwalton/ipc-channel" version = "0.2" features = [ "serde_serialization" ] -[dependencies] -log = "0.3" -fnv = "1.0" -time = "0.1.12" -bitflags = "0.3" -rustc-serialize = "0.3" -libc = "0.1" -rand = "0.3" -harfbuzz = "0.1" -smallvec = "0.1" -string_cache = "0.1" -euclid = "0.1" -serde = "0.4" -serde_macros = "0.4" - [target.x86_64-apple-darwin.dependencies] core-foundation = "0.1" core-graphics = "0.1" From 47a0d494ec430298a1e1365496ad643de16ab53b Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 3 Aug 2015 14:56:11 -0700 Subject: [PATCH 2/2] Make Harfbuzz font_funcs static --- components/gfx/Cargo.toml | 1 + components/gfx/lib.rs | 3 +++ components/gfx/text/shaping/harfbuzz.rs | 28 +++++++++++++------------ components/servo/Cargo.lock | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index 8f2f1b579bc..a776bc2f709 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -13,6 +13,7 @@ bitflags = "0.3" euclid = "0.1" fnv = "1.0" harfbuzz = "0.1" +lazy_static = "0.1" libc = "0.1" log = "0.3" rand = "0.3" diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index d13251123ca..6ffbe36fb5b 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -12,6 +12,7 @@ #![feature(mpsc_select)] #![feature(plugin)] #![feature(str_char)] +#![feature(unique)] #![feature(vec_push_all)] #![plugin(plugins)] @@ -26,6 +27,8 @@ extern crate azure; extern crate fnv; extern crate euclid; extern crate ipc_channel; +#[macro_use] +extern crate lazy_static; extern crate layers; extern crate libc; #[macro_use] diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 74a3b4e6d25..735a5e6183b 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -149,7 +149,6 @@ struct FontAndShapingOptions { pub struct Shaper { hb_face: *mut hb_face_t, hb_font: *mut hb_font_t, - hb_funcs: *mut hb_font_funcs_t, font_and_shaping_options: Box, } @@ -161,9 +160,6 @@ impl Drop for Shaper { assert!(!self.hb_font.is_null()); RUST_hb_font_destroy(self.hb_font); - - assert!(!self.hb_funcs.is_null()); - RUST_hb_font_funcs_destroy(self.hb_funcs); } } } @@ -193,18 +189,11 @@ impl Shaper { Shaper::float_to_fixed(pt_size) as c_int); // configure static function callbacks. - // NB. This funcs structure could be reused globally, as it never changes. - let hb_funcs: *mut hb_font_funcs_t = 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()); - RUST_hb_font_set_funcs(hb_font, hb_funcs, font as *mut Font as *mut c_void, None); + RUST_hb_font_set_funcs(hb_font, **HB_FONT_FUNCS, font as *mut Font as *mut c_void, None); Shaper { hb_face: hb_face, hb_font: hb_font, - hb_funcs: hb_funcs, font_and_shaping_options: font_and_shaping_options, } } @@ -528,7 +517,20 @@ 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! { + static ref HB_FONT_FUNCS: ptr::Unique = 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()); + + ptr::Unique::new(hb_funcs) + }; +} + extern fn glyph_func(_: *mut hb_font_t, font_data: *mut c_void, unicode: hb_codepoint_t, diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 14f8284ed3e..8f166854de5 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -466,6 +466,7 @@ dependencies = [ "harfbuzz 0.1.1 (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.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1",