From 3ffbaaaa47d64e8e28310fe0cc9b1a943c6f9c69 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 21 Jun 2012 17:42:43 -0700 Subject: [PATCH] Introduce NativeFont --- src/servo/servo.rc | 11 ++++++ src/servo/text/native_font.rs | 36 +++++++++++++++++++ src/servo/text/native_font/ft_native_font.rs | 16 +++++++++ .../text/native_font/quartz_native_font.rs | 16 +++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/servo/text/native_font.rs create mode 100644 src/servo/text/native_font/ft_native_font.rs create mode 100644 src/servo/text/native_font/quartz_native_font.rs diff --git a/src/servo/servo.rc b/src/servo/servo.rc index 34947cd7325..4983a7edffd 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -62,10 +62,21 @@ mod platform { } mod text { + export glyph; + export text_run; + export font; + export shaper; + mod glyph; mod text_run; mod font; mod shaper; + mod native_font { + #[cfg(target_os = "macos")] + mod quartz_native_font; + #[cfg(target_os = "linux")] + mod ft_native_font; + } } mod util { diff --git a/src/servo/text/native_font.rs b/src/servo/text/native_font.rs new file mode 100644 index 00000000000..3789f4aeed3 --- /dev/null +++ b/src/servo/text/native_font.rs @@ -0,0 +1,36 @@ +#[doc = " + +NativeFont encapsulates access to the platform's font API, +e.g. quartz, FreeType. It provides access to metrics and tables +needed by the text shaper as well as access to the underlying +font resources needed by the graphics layer to draw glyphs. + +"]; + +export NativeFont, create_test_native_font; + +#[cfg(target_os = "macos")] +type NativeFont/& = quartz_native_font::NativeFont; + +#[cfg(target_os = "linux")] +type NativeFont/& = ft_native_font::NativeFont; + +fn create_test_native_font() -> 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); +} + +#[test] +#[ignore] +fn should_get_glyph_h_advance() { + let font = create_test_native_font(); + let adv = font.glyph_h_advance(40u); + assert adv == 15; +} diff --git a/src/servo/text/native_font/ft_native_font.rs b/src/servo/text/native_font/ft_native_font.rs new file mode 100644 index 00000000000..9a940eaa4b5 --- /dev/null +++ b/src/servo/text/native_font/ft_native_font.rs @@ -0,0 +1,16 @@ +import glyph::GlyphIndex; + +class NativeFont/& { + let bogus: int; + + new() { self.bogus = 0; } + + fn glyph_index(_codepoint: char) -> option { + fail; + } + + // FIXME: What unit is this returning? Let's have a custom type + fn glyph_h_advance(_glyph: GlyphIndex) -> int { + fail; + } +} diff --git a/src/servo/text/native_font/quartz_native_font.rs b/src/servo/text/native_font/quartz_native_font.rs new file mode 100644 index 00000000000..9a940eaa4b5 --- /dev/null +++ b/src/servo/text/native_font/quartz_native_font.rs @@ -0,0 +1,16 @@ +import glyph::GlyphIndex; + +class NativeFont/& { + let bogus: int; + + new() { self.bogus = 0; } + + fn glyph_index(_codepoint: char) -> option { + fail; + } + + // FIXME: What unit is this returning? Let's have a custom type + fn glyph_h_advance(_glyph: GlyphIndex) -> int { + fail; + } +}