This commit is contained in:
Simon Sapin 2017-06-18 13:21:04 +02:00
parent 7af5a7fd54
commit 316cd35767
34 changed files with 261 additions and 264 deletions

View file

@ -88,9 +88,9 @@ impl FontContext {
font_variant_caps::T::normal => pt_size,
};
let handle = try!(FontHandle::new_from_template(&self.platform_handle,
let handle = FontHandle::new_from_template(&self.platform_handle,
template,
Some(actual_pt_size)));
Some(actual_pt_size))?;
Ok(Font::new(handle, variant, descriptor, pt_size, actual_pt_size, font_key))
}

View file

@ -80,7 +80,7 @@ impl Debug for FontTemplate {
impl FontTemplate {
pub fn new(identifier: Atom, maybe_bytes: Option<Vec<u8>>) -> Result<FontTemplate, IoError> {
let maybe_data = match maybe_bytes {
Some(_) => Some(try!(FontTemplateData::new(identifier.clone(), maybe_bytes))),
Some(_) => Some(FontTemplateData::new(identifier.clone(), maybe_bytes)?),
None => None,
};
@ -167,12 +167,12 @@ impl FontTemplate {
return Err(())
}
let data = try!(self.data().map_err(|_| ()));
let data = self.data().map_err(|_| ())?;
let handle: Result<FontHandle, ()> = FontHandleMethods::new_from_template(font_context,
data,
None);
self.is_valid = handle.is_ok();
let handle = try!(handle);
let handle = handle?;
self.descriptor = Some(FontTemplateDescriptor::new(handle.boldness(),
handle.stretchiness(),
handle.is_italic()));
@ -202,7 +202,7 @@ impl FontTemplate {
}
assert!(self.strong_ref.is_none());
let template_data = Arc::new(try!(FontTemplateData::new(self.identifier.clone(), None)));
let template_data = Arc::new(FontTemplateData::new(self.identifier.clone(), None)?);
self.weak_ref = Some(Arc::downgrade(&template_data));
Ok(template_data)
}

View file

@ -235,9 +235,9 @@ impl FontList {
fn load_file(path: &str) -> Result<String, io::Error> {
let mut file = try!(File::open(path));
let mut file = File::open(path)?;
let mut content = String::new();
try!(file.read_to_string(&mut content));
file.read_to_string(&mut content)?;
Ok(content)
}

View file

@ -99,7 +99,7 @@ impl FontHandleMethods for FontHandle {
return Err(());
}
if let Some(s) = pt_size {
try!(FontHandle::set_char_size(face, s).or(Err(())))
FontHandle::set_char_size(face, s).or(Err(()))?
}
Ok(face)
}

View file

@ -25,7 +25,7 @@ impl FontTemplateData {
},
None => {
// TODO: Handle file load failure!
let mut file = try!(File::open(&*identifier));
let mut file = File::open(&*identifier)?;
let mut buffer = vec![];
file.read_to_end(&mut buffer).unwrap();
buffer

View file

@ -47,7 +47,7 @@ fn make_tag(tag_bytes: &[u8]) -> FontTableTag {
unsafe { *(tag_bytes.as_ptr() as *const FontTableTag) }
}
macro_rules! try_lossy(($result:expr) => (try!($result.map_err(|_| (())))));
macro_rules! try_lossy(($result:expr) => ($result.map_err(|_| (()))?));
// Given a set of records, figure out the string indices for the family and face
// names. We want name_id 1 and 2, and we need to use platform_id == 1 and
@ -262,12 +262,12 @@ impl FontHandleMethods for FontHandle {
}
let face = font_file.unwrap().create_face(0, dwrote::DWRITE_FONT_SIMULATIONS_NONE);
let info = try!(FontInfo::new_from_face(&face));
let info = FontInfo::new_from_face(&face)?;
(info, face)
} else {
let font = font_from_atom(&template.identifier);
let face = font.create_font_face();
let info = try!(FontInfo::new_from_font(&font));
let info = FontInfo::new_from_font(&font)?;
(info, face)
};

View file

@ -665,27 +665,27 @@ impl<'a> GlyphStore {
impl fmt::Debug for GlyphStore {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
try!(write!(formatter, "GlyphStore:\n"));
write!(formatter, "GlyphStore:\n")?;
let mut detailed_buffer = self.detail_store.detail_buffer.iter();
for entry in self.entry_buffer.iter() {
if entry.is_simple() {
try!(write!(formatter,
write!(formatter,
" simple id={:?} advance={:?}\n",
entry.id(),
entry.advance()));
entry.advance())?;
continue
}
if entry.is_initial() {
continue
}
try!(write!(formatter, " complex..."));
write!(formatter, " complex...")?;
if detailed_buffer.next().is_none() {
continue
}
try!(write!(formatter,
write!(formatter,
" detailed id={:?} advance={:?}\n",
entry.id(),
entry.advance()));
entry.advance())?;
}
Ok(())
}