mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Work on implementing NativeFont
This commit is contained in:
parent
a6d9b123e4
commit
2967527abb
3 changed files with 73 additions and 15 deletions
|
@ -7,30 +7,32 @@ font resources needed by the graphics layer to draw glyphs.
|
|||
|
||||
"];
|
||||
|
||||
export NativeFont, create_test_native_font;
|
||||
export NativeFont;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
type NativeFont/& = quartz_native_font::NativeFont;
|
||||
type NativeFont/& = quartz_native_font::QuartzNativeFont;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
type NativeFont/& = ft_native_font::NativeFont;
|
||||
type NativeFont/& = ft_native_font::FreeTypeNativeFont;
|
||||
|
||||
fn create_test_native_font() -> NativeFont {
|
||||
fail;
|
||||
fn with_test_native_font(f: fn@(NativeFont)) {
|
||||
fail
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn should_get_glyph_indexes() {
|
||||
let font = create_test_native_font();
|
||||
let idx = font.glyph_index('w');
|
||||
assert idx == some(40u);
|
||||
with_test_native_font { |font|
|
||||
let idx = font.glyph_index('w');
|
||||
assert idx == some(40u);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn should_get_glyph_h_advance() {
|
||||
let font = create_test_native_font();
|
||||
let adv = font.glyph_h_advance(40u);
|
||||
assert adv == 15;
|
||||
with_test_native_font { |font|
|
||||
let adv = font.glyph_h_advance(40u);
|
||||
assert adv == 15;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,32 @@
|
|||
export FreeTypeNativeFont;
|
||||
|
||||
import vec_as_buf = vec::as_buf;
|
||||
import result::{result, ok, err};
|
||||
import ptr::{addr_of, null};
|
||||
import glyph::GlyphIndex;
|
||||
import azure::freetype;
|
||||
import freetype::{ FT_Error, FT_Library, FT_Face, FT_Long };
|
||||
import freetype::bindgen::{
|
||||
FT_Init_FreeType,
|
||||
FT_Done_FreeType,
|
||||
FT_New_Memory_Face,
|
||||
FT_Done_Face
|
||||
};
|
||||
|
||||
class NativeFont/& {
|
||||
let bogus: int;
|
||||
class FreeTypeNativeFont/& {
|
||||
let face: FT_Face;
|
||||
|
||||
new() { self.bogus = 0; }
|
||||
new(face: FT_Face) {
|
||||
assert face.is_not_null();
|
||||
self.face = face;
|
||||
}
|
||||
|
||||
drop {
|
||||
assert self.face.is_not_null();
|
||||
if !FT_Done_Face(self.face).succeeded() {
|
||||
fail "FT_Done_Face failed";
|
||||
}
|
||||
}
|
||||
|
||||
fn glyph_index(_codepoint: char) -> option<GlyphIndex> {
|
||||
fail;
|
||||
|
@ -14,3 +37,36 @@ class NativeFont/& {
|
|||
fail;
|
||||
}
|
||||
}
|
||||
|
||||
fn create(lib: FT_Library, buf: &[u8]) -> result<FreeTypeNativeFont, ()> {
|
||||
assert lib.is_not_null();
|
||||
let face: FT_Face = null();
|
||||
ret vec_as_buf(*buf) {|cbuf|
|
||||
if FT_New_Memory_Face(lib, cbuf, (*buf).len() as FT_Long,
|
||||
0 as FT_Long, addr_of(face)).succeeded() {
|
||||
ok(FreeTypeNativeFont(face))
|
||||
} else {
|
||||
err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl methods for FT_Error {
|
||||
fn succeeded() -> bool { self == 0 as FT_Error }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn with_lib(f: fn@(FT_Library)) {
|
||||
let lib: FT_Library = null();
|
||||
assert FT_Init_FreeType(addr_of(lib)).succeeded();
|
||||
f(lib);
|
||||
FT_Done_FreeType(lib);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_should_return_err_if_buf_is_bogus() {
|
||||
with_lib { |lib|
|
||||
let buf = &[];
|
||||
assert create(lib, buf).is_err();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import glyph::GlyphIndex;
|
||||
|
||||
class NativeFont/& {
|
||||
class QuartzNativeFont/& {
|
||||
let bogus: int;
|
||||
|
||||
new() { self.bogus = 0; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue