Add FontHandleMethods trait; add ctor and FontHandle member for FontEntry; add debug info for CTFont name key information.

This commit is contained in:
Brian J. Burg 2012-11-08 19:14:57 -08:00
parent bf4fedc420
commit 2db432663f
5 changed files with 57 additions and 8 deletions

@ -1 +1 @@
Subproject commit 29baa9c4e16f5b900570427cc7e01dd602c1dee4
Subproject commit 6fde7833913c8152ac41f5584f4d7f2e59d0f59f

View file

@ -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<GlyphIndex>;
fn glyph_h_advance(GlyphIndex) -> Option<FractionalPixel>;
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,

View file

@ -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;
pub use gfx::font::FontHandle;
pub use gfx::font_context::FontContextHandle;
pub use gfx::font_list::FontListHandle;

View file

@ -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<GlyphIndex> {
let characters: ~[UniChar] = ~[codepoint as UniChar];

View file

@ -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<FontEntry>
let descriptors : CFArray<CTFontDescriptorRef, CTFontDescriptor>;
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
}