Remove unused FontShapingOptions field from Shaper

This commit is contained in:
Matt Brubeck 2016-05-23 10:51:46 -07:00
parent 3c1b8e10c4
commit 7bf6a41553
2 changed files with 12 additions and 35 deletions

View file

@ -172,7 +172,7 @@ struct ShapeCacheEntry {
impl Font {
pub fn shape_text(&mut self, text: &str, options: &ShapingOptions) -> Arc<GlyphStore> {
self.make_shaper(options);
self.make_shaper();
//FIXME: find the equivalent of Equiv and the old ShapeCacheEntryRef
let shaper = &self.shaper;
@ -198,16 +198,10 @@ impl Font {
})
}
fn make_shaper<'a>(&'a mut self, options: &ShapingOptions) -> &'a Shaper {
// fast path: already created a shaper
if let Some(ref mut shaper) = self.shaper {
shaper.set_options(options);
return shaper
fn make_shaper(&mut self) {
if self.shaper.is_none() {
self.shaper = Some(Shaper::new(self));
}
let shaper = Shaper::new(self, options);
self.shaper = Some(shaper);
self.shaper.as_ref().unwrap()
}
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {

View file

@ -126,17 +126,11 @@ impl ShapedGlyphData {
}
}
#[derive(Debug)]
struct FontAndShapingOptions {
font: *mut Font,
options: ShapingOptions,
}
#[derive(Debug)]
pub struct Shaper {
hb_face: *mut hb_face_t,
hb_font: *mut hb_font_t,
font_and_shaping_options: Box<FontAndShapingOptions>,
font: *mut Font,
}
impl Drop for Shaper {
@ -152,15 +146,11 @@ impl Drop for Shaper {
}
impl Shaper {
pub fn new(font: &mut Font, options: &ShapingOptions) -> Shaper {
pub fn new(font: &mut Font) -> Shaper {
unsafe {
let mut font_and_shaping_options = box FontAndShapingOptions {
font: font,
options: *options,
};
let hb_face: *mut hb_face_t =
hb_face_create_for_tables(Some(font_table_func),
&mut *font_and_shaping_options as *mut _ as *mut c_void,
font as *mut _ as *mut c_void,
None);
let hb_font: *mut hb_font_t = hb_font_create(hb_face);
@ -179,15 +169,11 @@ impl Shaper {
Shaper {
hb_face: hb_face,
hb_font: hb_font,
font_and_shaping_options: font_and_shaping_options,
font: font,
}
}
}
pub fn set_options(&mut self, options: &ShapingOptions) {
self.font_and_shaping_options.options = *options
}
fn float_to_fixed(f: f64) -> i32 {
float_to_fixed(16, f)
}
@ -409,8 +395,7 @@ impl Shaper {
//
// TODO: Proper tab stops.
const TAB_COLS: i32 = 8;
let font = self.font_and_shaping_options.font;
let (space_glyph_id, space_advance) = glyph_space_advance(font);
let (space_glyph_id, space_advance) = glyph_space_advance(self.font);
let advance = Au::from_f64_px(space_advance) * TAB_COLS;
let data = GlyphData::new(space_glyph_id,
advance,
@ -557,13 +542,11 @@ extern fn font_table_func(_: *mut hb_face_t,
-> *mut hb_blob_t {
unsafe {
// NB: These asserts have security implications.
let font_and_shaping_options: *const FontAndShapingOptions =
user_data as *const FontAndShapingOptions;
assert!(!font_and_shaping_options.is_null());
assert!(!(*font_and_shaping_options).font.is_null());
let font = user_data as *const Font;
assert!(!font.is_null());
// TODO(Issue #197): reuse font table data, which will change the unsound trickery here.
match (*(*font_and_shaping_options).font).table_for_tag(tag as FontTableTag) {
match (*font).table_for_tag(tag as FontTableTag) {
None => ptr::null_mut(),
Some(font_table) => {
// `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer