Make font template data load fallible. Fixes #12037.

This commit is contained in:
Josh Matthews 2016-07-01 11:26:32 -04:00
parent 0ae07e07e6
commit fb943ab54b
4 changed files with 29 additions and 25 deletions

View file

@ -12,7 +12,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::io::{Read, Error as IoError};
use std::ops::Deref;
use std::sync::Mutex;
use string_cache::Atom;
@ -41,12 +41,12 @@ unsafe impl Send for FontTemplateData {}
unsafe impl Sync for FontTemplateData {}
impl FontTemplateData {
pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> FontTemplateData {
FontTemplateData {
pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> Result<FontTemplateData, IoError> {
Ok(FontTemplateData {
ctfont: CachedCTFont(Mutex::new(HashMap::new())),
identifier: identifier.to_owned(),
font_data: font_data
}
})
}
/// Retrieves the Core Text font instance, instantiating it if necessary.