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;
|
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
||||||
if ft_ctx.is_null() { return Err(()); }
|
if ft_ctx.is_null() { return Err(()); }
|
||||||
|
|
||||||
let face_result = create_face_from_buffer(ft_ctx, &template.bytes, pt_size);
|
return create_face_from_buffer(ft_ctx, &template.bytes, pt_size).map(|face| {
|
||||||
|
let handle = FontHandle {
|
||||||
// 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) => {
|
|
||||||
let handle = FontHandle {
|
|
||||||
face: face,
|
face: face,
|
||||||
font_data: template.clone(),
|
font_data: template.clone(),
|
||||||
handle: fctx.clone()
|
handle: fctx.clone(),
|
||||||
};
|
};
|
||||||
Ok(handle)
|
handle
|
||||||
}
|
});
|
||||||
Err(()) => Err(())
|
|
||||||
};
|
|
||||||
|
|
||||||
fn create_face_from_buffer(lib: FT_Library, buffer: &[u8], pt_size: Option<Au>)
|
fn create_face_from_buffer(lib: FT_Library, buffer: &[u8], pt_size: Option<Au>)
|
||||||
-> Result<FT_Face, ()> {
|
-> Result<FT_Face, ()> {
|
||||||
|
@ -101,15 +93,10 @@ impl FontHandleMethods for FontHandle {
|
||||||
if !result.succeeded() || face.is_null() {
|
if !result.succeeded() || face.is_null() {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
match pt_size {
|
if let Some(s) = pt_size {
|
||||||
Some(s) => {
|
try!(FontHandle::set_char_size(face, s).or(Err(())))
|
||||||
match FontHandle::set_char_size(face, s) {
|
|
||||||
Ok(_) => Ok(face),
|
|
||||||
Err(_) => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => Ok(face),
|
|
||||||
}
|
}
|
||||||
|
Ok(face)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue