Allow creation of unboxed FontTables

This commit is contained in:
Matt Brubeck 2016-05-18 11:58:06 -07:00
parent 0010b448b8
commit 7f6b1da85c
4 changed files with 7 additions and 7 deletions

View file

@ -53,7 +53,7 @@ pub trait FontHandleMethods: Sized {
fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>; fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
fn glyph_h_kerning(&self, GlyphId, GlyphId) -> FractionalPixel; fn glyph_h_kerning(&self, GlyphId, GlyphId) -> FractionalPixel;
fn metrics(&self) -> FontMetrics; fn metrics(&self) -> FontMetrics;
fn table_for_tag(&self, FontTableTag) -> Option<Box<FontTable>>; fn table_for_tag(&self, FontTableTag) -> Option<FontTable>;
} }
// Used to abstract over the shaper's choice of fixed int representation. // Used to abstract over the shaper's choice of fixed int representation.
@ -206,7 +206,7 @@ impl Font {
self.shaper.as_ref().unwrap() self.shaper.as_ref().unwrap()
} }
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> { pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
let result = self.handle.table_for_tag(tag); let result = self.handle.table_for_tag(tag);
let status = if result.is_some() { "Found" } else { "Didn't find" }; let status = if result.is_some() { "Found" } else { "Didn't find" };

View file

@ -260,7 +260,7 @@ impl FontHandleMethods for FontHandle {
metrics metrics
} }
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> { fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
let tag = tag as FT_ULong; let tag = tag as FT_ULong;
unsafe { unsafe {
@ -274,7 +274,7 @@ impl FontHandleMethods for FontHandle {
if !FT_Load_Sfnt_Table(self.face, tag, 0, buf.as_mut_ptr(), &mut len).succeeded() { if !FT_Load_Sfnt_Table(self.face, tag, 0, buf.as_mut_ptr(), &mut len).succeeded() {
return None return None
} }
Some(box FontTable { buffer: buf }) Some(FontTable { buffer: buf })
} }
} }
} }

View file

@ -209,10 +209,10 @@ impl FontHandleMethods for FontHandle {
metrics metrics
} }
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> { fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
let result: Option<CFData> = self.ctfont.get_font_table(tag); let result: Option<CFData> = self.ctfont.get_font_table(tag);
result.and_then(|data| { result.and_then(|data| {
Some(box FontTable::wrap(data)) Some(FontTable::wrap(data))
}) })
} }
} }

View file

@ -519,7 +519,7 @@ extern fn font_table_func(_: *mut hb_face_t,
// `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer // `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer
// while HarfBuzz is using it. When HarfBuzz is done with the buffer, it will pass // while HarfBuzz is using it. When HarfBuzz is done with the buffer, it will pass
// this raw pointer back to `destroy_blob_func` which will deallocate the Box. // this raw pointer back to `destroy_blob_func` which will deallocate the Box.
let font_table_ptr = Box::into_raw(font_table); let font_table_ptr = Box::into_raw(box font_table);
let buf = (*font_table_ptr).buffer(); let buf = (*font_table_ptr).buffer();
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed. // HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed.