mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Simplify FontHandle::new_from_template
This commit is contained in:
parent
1a61273e1e
commit
477258f11b
1 changed files with 9 additions and 22 deletions
|
@ -73,22 +73,14 @@ impl FontHandleMethods for FontHandle {
|
|||
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
||||
if ft_ctx.is_null() { return Err(()); }
|
||||
|
||||
let face_result = create_face_from_buffer(ft_ctx, &template.bytes, pt_size);
|
||||
|
||||
// TODO: this could be more simply written as result::chain
|
||||
// and moving buf into the struct ctor, but cant' move out of
|
||||
// captured binding.
|
||||
return match face_result {
|
||||
Ok(face) => {
|
||||
return create_face_from_buffer(ft_ctx, &template.bytes, pt_size).map(|face| {
|
||||
let handle = FontHandle {
|
||||
face: face,
|
||||
font_data: template.clone(),
|
||||
handle: fctx.clone()
|
||||
};
|
||||
Ok(handle)
|
||||
}
|
||||
Err(()) => Err(())
|
||||
handle: fctx.clone(),
|
||||
};
|
||||
handle
|
||||
});
|
||||
|
||||
fn create_face_from_buffer(lib: FT_Library, buffer: &[u8], pt_size: Option<Au>)
|
||||
-> Result<FT_Face, ()> {
|
||||
|
@ -101,15 +93,10 @@ impl FontHandleMethods for FontHandle {
|
|||
if !result.succeeded() || face.is_null() {
|
||||
return Err(());
|
||||
}
|
||||
match pt_size {
|
||||
Some(s) => {
|
||||
match FontHandle::set_char_size(face, s) {
|
||||
Ok(_) => Ok(face),
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}
|
||||
None => Ok(face),
|
||||
if let Some(s) = pt_size {
|
||||
try!(FontHandle::set_char_size(face, s).or(Err(())))
|
||||
}
|
||||
Ok(face)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue