Fonts must be created from a FontLibrary

This commit is contained in:
Brian Anderson 2012-06-22 16:44:59 -07:00
parent de59f7ef86
commit 776be8cf31
6 changed files with 27 additions and 13 deletions

View file

@ -159,7 +159,8 @@ fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: Tex
import vec::unsafe::to_ptr; import vec::unsafe::to_ptr;
import libc::types::common::c99::{uint16_t, uint32_t}; import libc::types::common::c99::{uint16_t, uint32_t};
import geom::point::Point2D; import geom::point::Point2D;
import text::font::{Font, create_test_font}; import text::font_library::FontLibrary;
import text::font::Font;
import azure::{AzNativeFont, AzFloat, AZ_NATIVE_FONT_CAIRO_FONT_FACE}; import azure::{AzNativeFont, AzFloat, AZ_NATIVE_FONT_CAIRO_FONT_FACE};
import azure::bindgen::{AzCreateScaledFontWithCairo, import azure::bindgen::{AzCreateScaledFontWithCairo,
AzReleaseScaledFont, AzReleaseScaledFont,
@ -167,7 +168,9 @@ fn draw_text(draw_target: AzDrawTargetRef, item: dl::display_item, text_run: Tex
AzReleaseColorPattern}; AzReleaseColorPattern};
let bounds = copy (*item).bounds; let bounds = copy (*item).bounds;
let font = create_test_font(); // FIXME: The font library should not be created here
let flib = FontLibrary();
let font = flib.get_test_font();
let nfont: AzNativeFont = { let nfont: AzNativeFont = {
mType: AZ_NATIVE_FONT_CAIRO_FONT_FACE, mType: AZ_NATIVE_FONT_CAIRO_FONT_FACE,

View file

@ -4,7 +4,7 @@ import geom::size::Size2D;
import gfx::geometry::au; import gfx::geometry::au;
import layout::base::*; // FIXME: Can't get around import *; resolve bug. import layout::base::*; // FIXME: Can't get around import *; resolve bug.
import servo_text::text_run::TextRun; import servo_text::text_run::TextRun;
import servo_text::font::create_test_font; import servo_text::font_library::FontLibrary;
class text_box { class text_box {
let text: str; let text: str;
@ -24,8 +24,10 @@ impl text_layout_methods for @Box {
_ { fail "expected text box in reflow_text!" } _ { fail "expected text box in reflow_text!" }
}; };
let font = create_test_font(); // FIXME: The font library should not be initialized here
let run = TextRun(&font, subbox.text); let flib = FontLibrary();
let font = flib.get_test_font();
let run = TextRun(font, subbox.text);
self.bounds.size = run.size(); self.bounds.size = run.size();
subbox.run = some(run); subbox.run = some(run);
} }

View file

@ -1,4 +1,4 @@
export Font, create_test_font, test_font_bin; export Font, test_font_bin, create_test_font;
import glyph::GlyphIndex; import glyph::GlyphIndex;
import vec_to_ptr = vec::unsafe::to_ptr; import vec_to_ptr = vec::unsafe::to_ptr;
@ -267,8 +267,11 @@ fn get_cairo_face(buf: &[u8]) -> (*cairo_font_face_t, fn@()) {
(cface, dtor) (cface, dtor)
} }
fn create_test_font() -> Font { fn create_test_font() -> @Font {
Font(test_font_bin()) import font_library::FontLibrary;
let flib = FontLibrary();
ret flib.get_test_font();
} }
fn test_font_bin() -> [u8] { #include_bin("JosefinSans-SemiBold.ttf") } fn test_font_bin() -> [u8] { #include_bin("JosefinSans-SemiBold.ttf") }

View file

@ -11,6 +11,10 @@ class FontLibrary {
let f = Font(font::test_font_bin()); let f = Font(font::test_font_bin());
ret @f; ret @f;
} }
fn get_test_font() -> @Font {
self.get_font()
}
} }
#[test] #[test]

View file

@ -146,7 +146,7 @@ fn should_get_glyph_indexes() {
#[ignore(reason = "random failures")]; #[ignore(reason = "random failures")];
let font = font::create_test_font(); let font = font::create_test_font();
let glyphs = shape_text(&font, "firecracker"); let glyphs = shape_text(font, "firecracker");
let idxs = glyphs.map { |glyph| glyph.index }; let idxs = glyphs.map { |glyph| glyph.index };
assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u]; assert idxs == [32u, 8u, 13u, 14u, 10u, 13u, 201u, 10u, 37u, 14u, 13u];
} }
@ -156,7 +156,7 @@ fn should_get_glyph_h_advance() {
#[ignore(reason = "random failures")]; #[ignore(reason = "random failures")];
let font = font::create_test_font(); let font = font::create_test_font();
let glyphs = shape_text(&font, "firecracker"); let glyphs = shape_text(font, "firecracker");
let actual = glyphs.map { |g| g.pos.advance.x }; let actual = glyphs.map { |g| g.pos.advance.x };
let expected = [6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7].map { |a| px_to_au(a) }; let expected = [6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7].map { |a| px_to_au(a) };
assert expected == actual; assert expected == actual;

View file

@ -2,7 +2,8 @@ import geom::point::Point2D;
import geom::size::Size2D; import geom::size::Size2D;
import gfx::geometry::{au, px_to_au}; import gfx::geometry::{au, px_to_au};
import libc::{c_void}; import libc::{c_void};
import font::{Font, create_test_font}; import font_library::FontLibrary;
import font::Font;
import glyph::Glyph; import glyph::Glyph;
import shaper::shape_text; import shaper::shape_text;
@ -31,8 +32,9 @@ fn should_calculate_the_total_size() {
#[test]; #[test];
#[ignore(reason = "random failures")]; #[ignore(reason = "random failures")];
let font = create_test_font(); let flib = FontLibrary();
let run = TextRun(&font, "firecracker"); let font = flib.get_test_font();
let run = TextRun(font, "firecracker");
let expected = Size2D(px_to_au(84), px_to_au(20)); let expected = Size2D(px_to_au(84), px_to_au(20));
assert run.size() == expected; assert run.size() == expected;
} }