mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Cache the one Font we support
This commit is contained in:
parent
03732b0cce
commit
88645b67a1
1 changed files with 12 additions and 4 deletions
|
@ -3,6 +3,7 @@ use font::{Font, test_font_bin};
|
|||
|
||||
struct FontCache {
|
||||
native_lib: native::NativeFontCache,
|
||||
mut cached_font: Option<@Font>,
|
||||
|
||||
drop {
|
||||
native::destroy_native_lib(&self.native_lib);
|
||||
|
@ -11,11 +12,17 @@ struct FontCache {
|
|||
|
||||
impl FontCache {
|
||||
fn get_font(@self) -> @Font {
|
||||
match create_font(self, &self.native_lib) {
|
||||
Ok(font) => font,
|
||||
match self.cached_font {
|
||||
Some(font) => font,
|
||||
None => match create_font(self, &self.native_lib) {
|
||||
Ok(font) => {
|
||||
self.cached_font = Some(font);
|
||||
font
|
||||
}
|
||||
Err(*) => /* FIXME */ fail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_test_font(@self) -> @Font {
|
||||
self.get_font()
|
||||
|
@ -24,7 +31,8 @@ impl FontCache {
|
|||
|
||||
fn FontCache() -> @FontCache {
|
||||
@FontCache {
|
||||
native_lib: native::create_native_lib()
|
||||
native_lib: native::create_native_lib(),
|
||||
cached_font: None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue