mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Give FontLibrary a handle to NativeFontLibrary
This commit is contained in:
parent
d4e37f0c82
commit
2b29512ef5
1 changed files with 40 additions and 3 deletions
|
@ -1,11 +1,17 @@
|
||||||
export FontLibrary;
|
export FontLibrary, native;
|
||||||
|
|
||||||
import font::Font;
|
import font::Font;
|
||||||
|
|
||||||
class FontLibrary {
|
class FontLibrary {
|
||||||
let bogus: int;
|
let native_lib: native::NativeFontLibrary;
|
||||||
|
|
||||||
new() { self.bogus = 0; }
|
new() {
|
||||||
|
self.native_lib = native::create_native_lib();
|
||||||
|
}
|
||||||
|
|
||||||
|
drop {
|
||||||
|
native::destroy_native_lib(&self.native_lib);
|
||||||
|
}
|
||||||
|
|
||||||
fn get_font() -> @Font {
|
fn get_font() -> @Font {
|
||||||
let f = Font(font::test_font_bin());
|
let f = Font(font::test_font_bin());
|
||||||
|
@ -17,6 +23,37 @@ class FontLibrary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
mod native {
|
||||||
|
import ptr::{null, addr_of};
|
||||||
|
import azure::freetype;
|
||||||
|
import freetype::{FT_Library, FT_Error};
|
||||||
|
import freetype::bindgen::{FT_Init_FreeType, FT_Done_FreeType};
|
||||||
|
|
||||||
|
type NativeFontLibrary = FT_Library;
|
||||||
|
|
||||||
|
fn create_native_lib() -> NativeFontLibrary {
|
||||||
|
let lib: FT_Library = null();
|
||||||
|
let res = FT_Init_FreeType(addr_of(lib));
|
||||||
|
// FIXME: error handling
|
||||||
|
assert res == 0 as FT_Error;
|
||||||
|
return lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn destroy_native_lib(native_lib: &NativeFontLibrary) {
|
||||||
|
assert native_lib.is_not_null();
|
||||||
|
FT_Done_FreeType(*native_lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod native {
|
||||||
|
type NativeFontLibrary = ();
|
||||||
|
|
||||||
|
fn create_native_lib() -> NativeFontLibrary { () }
|
||||||
|
fn destroy_native_lib(_native_lib: &NativeFontLibrary) { }
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_get_fonts() {
|
fn should_get_fonts() {
|
||||||
let lib = FontLibrary();
|
let lib = FontLibrary();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue