Retain buffer for CGDataProviderCreateWithData. Fixes #5084.

CGDataProviderCreateWithData just wraps the underlying buffer. The
underlying buffer needs to be kept around until the data provider is
freed. Adding the buffer to the FontTemplateData struct ensures it
sticks around.
This commit is contained in:
Connor Jennings 2015-03-15 14:02:27 -04:00
parent f30faeadd0
commit f298089f02

View file

@ -16,6 +16,7 @@ use std::borrow::ToOwned;
pub struct FontTemplateData { pub struct FontTemplateData {
pub ctfont: Option<CTFont>, pub ctfont: Option<CTFont>,
pub identifier: String, pub identifier: String,
pub font_data: Option<Vec<u8>>
} }
unsafe impl Send for FontTemplateData {} unsafe impl Send for FontTemplateData {}
@ -24,7 +25,7 @@ unsafe impl Sync for FontTemplateData {}
impl FontTemplateData { impl FontTemplateData {
pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData { pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData {
let ctfont = match font_data { let ctfont = match font_data {
Some(bytes) => { Some(ref bytes) => {
let fontprov = CGDataProvider::from_buffer(bytes.as_slice()); let fontprov = CGDataProvider::from_buffer(bytes.as_slice());
let cgfont_result = CGFont::from_data_provider(fontprov); let cgfont_result = CGFont::from_data_provider(fontprov);
match cgfont_result { match cgfont_result {
@ -40,6 +41,7 @@ impl FontTemplateData {
FontTemplateData { FontTemplateData {
ctfont: ctfont, ctfont: ctfont,
identifier: identifier.to_owned(), identifier: identifier.to_owned(),
font_data: font_data
} }
} }
} }