From 2db432663f30b24e563abcc9e2c8b2094728bc88 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 19:14:57 -0800 Subject: [PATCH] Add FontHandleMethods trait; add ctor and FontHandle member for FontEntry; add debug info for CTFont name key information. --- src/rust-core-text | 2 +- src/servo/gfx/font.rs | 23 ++++++++++++++++++++++- src/servo/gfx/native.rs | 6 +++--- src/servo/gfx/quartz/font.rs | 24 +++++++++++++++++++++++- src/servo/gfx/quartz/font_list.rs | 10 ++++++++-- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/rust-core-text b/src/rust-core-text index 29baa9c4e16..6fde7833913 160000 --- a/src/rust-core-text +++ b/src/rust-core-text @@ -1 +1 @@ -Subproject commit 29baa9c4e16f5b900570427cc7e01dd602c1dee4 +Subproject commit 6fde7833913c8152ac41f5584f4d7f2e59d0f59f diff --git a/src/servo/gfx/font.rs b/src/servo/gfx/font.rs index 34e93751d07..72326228e21 100644 --- a/src/servo/gfx/font.rs +++ b/src/servo/gfx/font.rs @@ -26,7 +26,17 @@ pub type FontHandle/& = quartz::font::QuartzFontHandle; #[cfg(target_os = "linux")] pub type FontHandle/& = freetype::font::FreeTypeFontHandle; -// TODO: `new` should be part of trait FontHandle +pub trait FontHandleMethods { + pure fn face_name() -> ~str; + pure fn is_italic() -> bool; + pure fn boldness() -> CSSFontWeight; + + fn glyph_index(codepoint: char) -> Option; + fn glyph_h_advance(GlyphIndex) -> Option; + fn get_metrics() -> FontMetrics; +} + +// TODO: `new` should be part of trait FontHandleMethods // TODO(Issue #163): this is a workaround for static methods and // typedefs not working well together. It should be removed. @@ -199,10 +209,21 @@ struct FontEntry { face_name: ~str, priv weight: CSSFontWeight, priv italic: bool, + handle: FontHandle, // TODO: array of OpenType features, etc. } impl FontEntry { + static fn new(family: @FontFamily, handle: FontHandle) -> FontEntry { + FontEntry { + family: family, + face_name: handle.face_name(), + weight: handle.boldness(), + italic: handle.is_italic(), + handle: move handle + } + } + pure fn is_bold() -> bool { match self.weight { FontWeight900 | FontWeight800 | FontWeight700 | FontWeight600 => true, diff --git a/src/servo/gfx/native.rs b/src/servo/gfx/native.rs index 50a7ee703eb..abcf8052944 100644 --- a/src/servo/gfx/native.rs +++ b/src/servo/gfx/native.rs @@ -4,6 +4,6 @@ Note that you still must define each of the files as a module in servo.rc. This is not ideal and may be changed in the future. */ -pub use font::FontHandle; -pub use font_context::FontContextHandle; -pub use font_list::FontListHandle; \ No newline at end of file +pub use gfx::font::FontHandle; +pub use gfx::font_context::FontContextHandle; +pub use gfx::font_list::FontListHandle; \ No newline at end of file diff --git a/src/servo/gfx/quartz/font.rs b/src/servo/gfx/quartz/font.rs index 4bd449cea98..b0c0fdae426 100644 --- a/src/servo/gfx/quartz/font.rs +++ b/src/servo/gfx/quartz/font.rs @@ -4,7 +4,13 @@ extern mod core_text; use font_context::QuartzFontContextHandle; use gfx::au; -use gfx::font::{FontMetrics, FractionalPixel}; +use gfx::font::{ + CSSFontWeight, + FontHandleMethods, + FontMetrics, + FontWeight500, + FractionalPixel +}; use text::glyph::GlyphIndex; use libc::size_t; @@ -74,6 +80,22 @@ pub impl QuartzFontHandle { return move result; } +} + +pub impl QuartzFontHandle : FontHandleMethods { + + pure fn face_name() -> ~str { + self.ctfont.face_name() + } + + pure fn is_italic() -> bool { + false // FIXME + } + + pure fn boldness() -> CSSFontWeight { + FontWeight500 // FIXME + } + fn glyph_index(codepoint: char) -> Option { let characters: ~[UniChar] = ~[codepoint as UniChar]; diff --git a/src/servo/gfx/quartz/font_list.rs b/src/servo/gfx/quartz/font_list.rs index 8c02bc64c77..86280a43b79 100644 --- a/src/servo/gfx/quartz/font_list.rs +++ b/src/servo/gfx/quartz/font_list.rs @@ -4,6 +4,10 @@ extern mod core_text; use cf = core_foundation; use cf::array::CFArray; use ct = core_text; +use ct::font::{ + CTFont, + debug_font_names, +}; use ct::font_collection::CTFontCollection; use ct::font_descriptor::{ CTFontDescriptor, @@ -24,13 +28,15 @@ pub impl QuartzFontListHandle { QuartzFontListHandle { collection: CTFontCollection::new() } } - fn get_available_families(_fctx: &native::FontContextHandle) -> ~[@FontFamily] { + fn get_available_families(fctx: &native::FontContextHandle) -> ~[@FontFamily] { // TODO: make a hashtable from family name to DVec let descriptors : CFArray; descriptors = self.collection.get_descriptors(); for descriptors.each |desc: &CTFontDescriptor| { - debug!("%?", { debug_descriptor(desc); () }); + //debug!("%?", { debug_descriptor(desc); () }); // TODO: for each descriptor, make a FontEntry. + let font = CTFont::new_from_descriptor(desc, 0.0); + debug!("%s", { debug_font_names(&font); ~"--- DEBUG CTFONT NAMES ---" }); // TODO: append FontEntry to hashtable value }