mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Fonts should keep their libraries alive
This commit is contained in:
parent
d937e3c2fe
commit
a475304754
2 changed files with 19 additions and 7 deletions
|
@ -12,6 +12,8 @@ A font handle. Layout can use this to calculate glyph metrics
|
|||
and the renderer can use it to render text.
|
||||
"]
|
||||
struct Font {
|
||||
// A back reference to keep the library alive
|
||||
lib: @FontLibrary,
|
||||
fontbuf: @~[u8],
|
||||
native_font: NativeFont,
|
||||
}
|
||||
|
@ -33,8 +35,9 @@ impl Font {
|
|||
}
|
||||
}
|
||||
|
||||
fn Font(fontbuf: @~[u8], +native_font: NativeFont) -> Font {
|
||||
fn Font(lib: @FontLibrary, fontbuf: @~[u8], +native_font: NativeFont) -> Font {
|
||||
Font {
|
||||
lib: lib,
|
||||
fontbuf : fontbuf,
|
||||
native_font : move native_font,
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ export FontLibrary, native;
|
|||
use font::{Font, test_font_bin};
|
||||
|
||||
struct FontLibrary {
|
||||
// FIXME: This is a hack to hold onto a boxed reference to
|
||||
// the self pointer until explicit self types work on methods.
|
||||
// This is a huge space leak.
|
||||
mut at_self: Option<@FontLibrary>,
|
||||
native_lib: native::NativeFontLibrary,
|
||||
|
||||
drop {
|
||||
|
@ -12,7 +16,8 @@ struct FontLibrary {
|
|||
|
||||
impl FontLibrary {
|
||||
fn get_font() -> @Font {
|
||||
match create_font(&self.native_lib) {
|
||||
assert self.at_self.is_some();
|
||||
match create_font(self.at_self.get(), &self.native_lib) {
|
||||
Ok(font) => font,
|
||||
Err(*) => /* FIXME */ fail
|
||||
}
|
||||
|
@ -23,13 +28,17 @@ impl FontLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
fn FontLibrary() -> FontLibrary {
|
||||
FontLibrary {
|
||||
fn FontLibrary() -> @FontLibrary {
|
||||
let lib = @FontLibrary {
|
||||
mut at_self: None,
|
||||
native_lib: native::create_native_lib()
|
||||
}
|
||||
};
|
||||
|
||||
lib.at_self = Some(lib);
|
||||
return lib;
|
||||
}
|
||||
|
||||
fn create_font(native_lib: &native::NativeFontLibrary) -> Result<@Font, ()> {
|
||||
fn create_font(lib: @FontLibrary, native_lib: &native::NativeFontLibrary) -> Result<@Font, ()> {
|
||||
let font_bin = @test_font_bin();
|
||||
let native_font = native_font::create(native_lib, font_bin);
|
||||
let native_font = if native_font.is_ok() {
|
||||
|
@ -37,7 +46,7 @@ fn create_font(native_lib: &native::NativeFontLibrary) -> Result<@Font, ()> {
|
|||
} else {
|
||||
return Err(native_font.get_err());
|
||||
};
|
||||
return Ok(@Font(font_bin, native_font));
|
||||
return Ok(@Font(lib, font_bin, native_font));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue