Remove native.rs. It's no longer needed; just use platform::* directly.

This commit is contained in:
Patrick Walton 2013-04-05 16:57:24 -07:00
parent 9822f5d96b
commit b2f5ccfd5f
12 changed files with 104 additions and 176 deletions

View file

@ -3,11 +3,11 @@
use color::Color; use color::Color;
use font_context::FontContext; use font_context::FontContext;
use geometry::Au; use geometry::Au;
use platform; use platform::font_context::FontContextHandle;
use platform::font::{FontHandle, FontTable};
use render_context::RenderContext; use render_context::RenderContext;
use text::glyph::{GlyphStore, GlyphIndex}; use text::glyph::{GlyphStore, GlyphIndex};
use text::shaper::ShaperMethods; use text::shaper::ShaperMethods;
use text::shaper::ShaperMethods;
use text::{Shaper, TextRun}; use text::{Shaper, TextRun};
use util::range::Range; use util::range::Range;
@ -16,20 +16,15 @@ use azure::scaled_font::ScaledFont;
use azure::azure_hl::{BackendType, ColorPattern}; use azure::azure_hl::{BackendType, ColorPattern};
use geom::{Point2D, Rect, Size2D}; use geom::{Point2D, Rect, Size2D};
use native;
// FontHandle encapsulates access to the platform's font API, // FontHandle encapsulates access to the platform's font API,
// e.g. quartz, FreeType. It provides access to metrics and tables // e.g. quartz, FreeType. It provides access to metrics and tables
// needed by the text shaper as well as access to the underlying font // needed by the text shaper as well as access to the underlying font
// resources needed by the graphics layer to draw glyphs. // resources needed by the graphics layer to draw glyphs.
#[cfg(target_os = "macos")]
pub type FontHandle = platform::font::QuartzFontHandle;
#[cfg(target_os = "linux")]
pub type FontHandle = platform::font::FreeTypeFontHandle;
pub trait FontHandleMethods { pub trait FontHandleMethods {
fn new_from_buffer(fctx: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
-> Result<Self,()>;
// an identifier usable by FontContextHandle to recreate this FontHandle. // an identifier usable by FontContextHandle to recreate this FontHandle.
fn face_identifier(&self) -> ~str; fn face_identifier(&self) -> ~str;
fn family_name(&self) -> ~str; fn family_name(&self) -> ~str;
@ -37,36 +32,14 @@ pub trait FontHandleMethods {
fn is_italic(&self) -> bool; fn is_italic(&self) -> bool;
fn boldness(&self) -> CSSFontWeight; fn boldness(&self) -> CSSFontWeight;
fn clone_with_style(&self, fctx: &native::FontContextHandle, style: &UsedFontStyle) -> Result<FontHandle, ()>; fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
-> Result<FontHandle, ()>;
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>; fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>;
fn glyph_h_advance(&self, GlyphIndex) -> Option<FractionalPixel>; fn glyph_h_advance(&self, GlyphIndex) -> Option<FractionalPixel>;
fn get_metrics(&self) -> FontMetrics; fn get_metrics(&self) -> FontMetrics;
fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>; fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>;
} }
// TODO(Issue #163): this is a workaround for static methods and
// typedefs not working well together. It should be removed.
//
// `new` should be part of trait FontHandleMethods.
pub impl FontHandle {
#[cfg(target_os = "macos")]
pub fn new_from_buffer(fctx: &native::FontContextHandle,
buf: ~[u8],
style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
platform::font::QuartzFontHandle::new_from_buffer(fctx, buf, style)
}
#[cfg(target_os = "linux")]
pub fn new_from_buffer(fctx: &native::FontContextHandle,
buf: ~[u8],
style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
platform::font::FreeTypeFontHandle::new_from_buffer(fctx, @buf, style)
}
}
// Used to abstract over the shaper's choice of fixed int representation. // Used to abstract over the shaper's choice of fixed int representation.
pub type FractionalPixel = float; pub type FractionalPixel = float;
@ -88,12 +61,6 @@ impl FontTableTagConversions for FontTableTag {
} }
} }
#[cfg(target_os = "macos")]
pub type FontTable = platform::font::QuartzFontTable;
#[cfg(target_os = "linux")]
pub type FontTable = platform::font::FreeTypeFontTable;
pub trait FontTableMethods { pub trait FontTableMethods {
fn with_buffer(&self, &fn(*u8, uint)); fn with_buffer(&self, &fn(*u8, uint));
} }
@ -246,8 +213,8 @@ pub impl Font {
style: &SpecifiedFontStyle, style: &SpecifiedFontStyle,
backend: BackendType) backend: BackendType)
-> Result<@mut Font, ()> { -> Result<@mut Font, ()> {
let handle = FontHandle::new_from_buffer(&ctx.handle, buffer, style); let handle = FontHandleMethods::new_from_buffer(&ctx.handle, buffer, style);
let handle = if handle.is_ok() { let handle: FontHandle = if handle.is_ok() {
result::unwrap(handle) result::unwrap(handle)
} else { } else {
return Err(handle.get_err()); return Err(handle.get_err());

View file

@ -4,8 +4,8 @@ use font::{Font, FontDescriptor, FontGroup, FontStyle, SelectorPlatformIdentifie
use font::{SelectorStubDummy, SpecifiedFontStyle, UsedFontStyle}; use font::{SelectorStubDummy, SpecifiedFontStyle, UsedFontStyle};
use font_context; use font_context;
use font_list::FontList; use font_list::FontList;
use native::FontHandle; use platform::font::FontHandle;
use platform; use platform::font_context::FontContextHandle;
use util::cache::Cache; use util::cache::Cache;
use util::cache::MonoCache; use util::cache::MonoCache;
@ -32,31 +32,11 @@ pub fn dummy_style() -> FontStyle {
} }
} }
#[cfg(target_os = "macos")]
type FontContextHandle = platform::font_context::QuartzFontContextHandle;
#[cfg(target_os = "linux")]
type FontContextHandle = platform::font_context::FreeTypeFontContextHandle;
pub trait FontContextHandleMethods { pub trait FontContextHandleMethods {
fn clone(&self) -> FontContextHandle; fn clone(&self) -> FontContextHandle;
fn create_font_from_identifier(&self, ~str, UsedFontStyle) -> Result<FontHandle, ()>; fn create_font_from_identifier(&self, ~str, UsedFontStyle) -> Result<FontHandle, ()>;
} }
// TODO(Issue #163): this is a workaround for static methods, traits,
// and typedefs not working well together. It should be removed.
pub impl FontContextHandle {
#[cfg(target_os = "macos")]
pub fn new() -> FontContextHandle {
platform::font_context::QuartzFontContextHandle::new()
}
#[cfg(target_os = "linux")]
pub fn new() -> FontContextHandle {
platform::font_context::FreeTypeFontContextHandle::new()
}
}
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
pub struct FontContext { pub struct FontContext {
instance_cache: MonoCache<FontDescriptor, @mut Font>, instance_cache: MonoCache<FontDescriptor, @mut Font>,

View file

@ -2,36 +2,17 @@
use font::{CSSFontWeight, SpecifiedFontStyle}; use font::{CSSFontWeight, SpecifiedFontStyle};
use gfx_font::FontHandleMethods; use gfx_font::FontHandleMethods;
use gfx_font::FontHandleMethods; use platform::font::FontHandle;
use native::FontHandle; use platform::font_context::FontContextHandle;
use native; use platform::font_list::FontListHandle;
use platform;
use util::time::time; use util::time::time;
use core::hashmap::HashMap; use core::hashmap::HashMap;
#[cfg(target_os = "macos")]
type FontListHandle = platform::font_list::QuartzFontListHandle;
#[cfg(target_os = "linux")]
type FontListHandle = platform::font_list::FontconfigFontListHandle;
pub impl FontListHandle {
#[cfg(target_os = "macos")]
pub fn new(fctx: &native::FontContextHandle) -> Result<FontListHandle, ()> {
Ok(platform::font_list::QuartzFontListHandle::new(fctx))
}
#[cfg(target_os = "linux")]
pub fn new(fctx: &native::FontContextHandle) -> Result<FontListHandle, ()> {
Ok(platform::font_list::FontconfigFontListHandle::new(fctx))
}
}
pub type FontFamilyMap = HashMap<~str, @mut FontFamily>; pub type FontFamilyMap = HashMap<~str, @mut FontFamily>;
trait FontListHandleMethods { trait FontListHandleMethods {
fn get_available_families(&self, fctx: &native::FontContextHandle) -> FontFamilyMap; fn get_available_families(&self, fctx: &FontContextHandle) -> FontFamilyMap;
fn load_variations_for_family(&self, family: @mut FontFamily); fn load_variations_for_family(&self, family: @mut FontFamily);
} }
@ -41,8 +22,8 @@ pub struct FontList {
} }
pub impl FontList { pub impl FontList {
fn new(fctx: &native::FontContextHandle) -> FontList { fn new(fctx: &FontContextHandle) -> FontList {
let handle = result::unwrap(FontListHandle::new(fctx)); let handle = FontListHandle::new(fctx);
let mut list = FontList { let mut list = FontList {
handle: handle, handle: handle,
family_map: HashMap::new(), family_map: HashMap::new(),
@ -51,7 +32,7 @@ pub impl FontList {
return list; return list;
} }
priv fn refresh(&mut self, _fctx: &native::FontContextHandle) { priv fn refresh(&mut self, _: &FontContextHandle) {
// TODO(Issue #186): don't refresh unless something actually // TODO(Issue #186): don't refresh unless something actually
// changed. Does OSX have a notification for this event? // changed. Does OSX have a notification for this event?
// //
@ -106,15 +87,15 @@ pub impl FontFamily {
} }
} }
priv fn load_family_variations(@mut self, list: &native::FontListHandle) { priv fn load_family_variations(@mut self, list: &FontListHandle) {
let this : &mut FontFamily = self; // FIXME: borrow checker workaround let this : &mut FontFamily = self; // FIXME: borrow checker workaround
if this.entries.len() > 0 { return; } if this.entries.len() > 0 { return; }
list.load_variations_for_family(self); list.load_variations_for_family(self);
assert!(this.entries.len() > 0); assert!(this.entries.len() > 0);
} }
fn find_font_for_style(@mut self, list: &native::FontListHandle, style: &SpecifiedFontStyle) -> Option<@FontEntry> { fn find_font_for_style(@mut self, list: &FontListHandle, style: &SpecifiedFontStyle)
-> Option<@FontEntry> {
self.load_family_variations(list); self.load_family_variations(list);
// TODO(Issue #189): optimize lookup for // TODO(Issue #189): optimize lookup for
@ -165,5 +146,8 @@ pub impl FontEntry {
self.weight.is_bold() self.weight.is_bold()
} }
fn is_italic(&self) -> bool { self.italic } fn is_italic(&self) -> bool {
self.italic
}
} }

View file

@ -1,9 +0,0 @@
/* This file exists just to make it easier to import platform-specific
implementations.
Note that you still must define each of the files as a module in
servo_gfx.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;

View file

@ -8,8 +8,7 @@ use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTab
use gfx_font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100}; use gfx_font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use gfx_font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600}; use gfx_font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
use gfx_font::{FontWeight700, FontWeight800, FontWeight900}; use gfx_font::{FontWeight700, FontWeight800, FontWeight900};
use native; use platform::font_context::{FreeTypeFontContextHandle, FontContextHandle};
use platform::font_context::FreeTypeFontContextHandle;
use text::glyph::GlyphIndex; use text::glyph::GlyphIndex;
use text::util::{float_to_fixed, fixed_to_float}; use text::util::{float_to_fixed, fixed_to_float};
@ -24,6 +23,9 @@ use platform::font::freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics};
use platform::font::freetype::freetype::{ft_sfnt_os2}; use platform::font::freetype::freetype::{ft_sfnt_os2};
use platform::font::freetype::tt_os2::TT_OS2; use platform::font::freetype::tt_os2::TT_OS2;
pub use FontHandle = platform::linux::font::FreeTypeFontHandle;
pub use FontTable = platform::linux::font::FreeTypeFontTable;
fn float_to_fixed_ft(f: float) -> i32 { fn float_to_fixed_ft(f: float) -> i32 {
float_to_fixed(6, f) float_to_fixed(6, f)
} }
@ -113,9 +115,15 @@ pub impl FreeTypeFontHandle {
Ok(FreeTypeFontHandle { source: FontSourceFile(file), face: face }) Ok(FreeTypeFontHandle { source: FontSourceFile(file), face: face })
} }
}
impl FontHandleMethods for FreeTypeFontHandle {
pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle, pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle,
buf: @~[u8], style: &SpecifiedFontStyle) -> Result<FreeTypeFontHandle, ()> { buf: ~[u8],
style: &SpecifiedFontStyle)
-> Result<FreeTypeFontHandle, ()> {
let buf = @buf;
let ft_ctx: FT_Library = fctx.ctx.ctx; let ft_ctx: FT_Library = fctx.ctx.ctx;
if ft_ctx.is_null() { return Err(()); } if ft_ctx.is_null() { return Err(()); }
@ -150,9 +158,7 @@ pub impl FreeTypeFontHandle {
} }
} }
} }
}
impl FontHandleMethods for FreeTypeFontHandle {
// an identifier usable by FontContextHandle to recreate this FontHandle. // an identifier usable by FontContextHandle to recreate this FontHandle.
fn face_identifier(&self) -> ~str { fn face_identifier(&self) -> ~str {
/* FT_Get_Postscript_Name seems like a better choice here, but it /* FT_Get_Postscript_Name seems like a better choice here, but it
@ -196,7 +202,7 @@ impl FontHandleMethods for FreeTypeFontHandle {
} }
fn clone_with_style(&self, fn clone_with_style(&self,
fctx: &native::FontContextHandle, fctx: &FontContextHandle,
style: &UsedFontStyle) -> Result<FreeTypeFontHandle, ()> { style: &UsedFontStyle) -> Result<FreeTypeFontHandle, ()> {
match self.source { match self.source {
FontSourceMem(buf) => { FontSourceMem(buf) => {

View file

@ -9,6 +9,8 @@ use platform::font_list::path_from_identifier;
use platform::font_context::freetype::freetype::{FTErrorMethods, FT_Library}; use platform::font_context::freetype::freetype::{FTErrorMethods, FT_Library};
use platform::font_context::freetype::freetype::bindgen::{FT_Done_FreeType, FT_Init_FreeType}; use platform::font_context::freetype::freetype::bindgen::{FT_Done_FreeType, FT_Init_FreeType};
pub use FontContextHandle = platform::linux::FreeTypeFontContextHandle;
struct FreeTypeLibraryHandle { struct FreeTypeLibraryHandle {
ctx: FT_Library, ctx: FT_Library,
} }

View file

@ -6,9 +6,8 @@ extern mod fontconfig;
use gfx_font::FontHandleMethods; use gfx_font::FontHandleMethods;
use gfx_font_context::FontContextHandleMethods; use gfx_font_context::FontContextHandleMethods;
use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap};
use native;
use platform::font::FreeTypeFontHandle; use platform::font::FreeTypeFontHandle;
use platform::font_context::FreeTypeFontContextHandle; use platform::font_context::{FontContextHandle, FreeTypeFontContextHandle};
use core::hashmap::HashMap; use core::hashmap::HashMap;
use core::libc::c_int; use core::libc::c_int;
@ -35,7 +34,7 @@ pub struct FontconfigFontListHandle {
} }
pub impl FontconfigFontListHandle { pub impl FontconfigFontListHandle {
pub fn new(fctx: &native::FontContextHandle) -> FontconfigFontListHandle { pub fn new(fctx: &FontContextHandle) -> FontconfigFontListHandle {
FontconfigFontListHandle { fctx: fctx.clone() } FontconfigFontListHandle { fctx: fctx.clone() }
} }

View file

@ -5,7 +5,7 @@ extern mod core_graphics;
extern mod core_text; extern mod core_text;
use geometry::Au; use geometry::Au;
use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTableMethods}; use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use gfx_font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400}; use gfx_font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400};
use gfx_font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900}; use gfx_font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900};
use gfx_font::{FractionalPixel, SpecifiedFontStyle}; use gfx_font::{FractionalPixel, SpecifiedFontStyle};
@ -19,59 +19,39 @@ use platform::macos::font::core_text::font::{CTFont, CTFontMethods, CTFontMethod
use platform::macos::font::core_text::font_descriptor::{SymbolicTraitAccessors}; use platform::macos::font::core_text::font_descriptor::{SymbolicTraitAccessors};
use platform::macos::font::core_text::font_descriptor::{TraitAccessors}; use platform::macos::font::core_text::font_descriptor::{TraitAccessors};
use platform::macos::font::core_text::font_descriptor::{kCTFontDefaultOrientation}; use platform::macos::font::core_text::font_descriptor::{kCTFontDefaultOrientation};
use platform::macos::font_context::QuartzFontContextHandle; use platform::macos::font_context::FontContextHandle;
use platform; use platform;
use text::glyph::GlyphIndex; use text::glyph::GlyphIndex;
struct QuartzFontTable { pub struct FontTable {
data: CFData, data: CFData,
} }
// Noncopyable. // Noncopyable.
impl Drop for QuartzFontTable { fn finalize(&self) {} } impl Drop for FontTable {
fn finalize(&self) {}
}
pub impl QuartzFontTable { pub impl FontTable {
fn wrap(data: CFData) -> QuartzFontTable { fn wrap(data: CFData) -> FontTable {
QuartzFontTable { data: data } FontTable { data: data }
} }
} }
impl FontTableMethods for QuartzFontTable { impl FontTableMethods for FontTable {
fn with_buffer(&self, blk: &fn(*u8, uint)) { fn with_buffer(&self, blk: &fn(*u8, uint)) {
blk(self.data.bytes(), self.data.len()); blk(self.data.bytes(), self.data.len());
} }
} }
pub struct QuartzFontHandle { pub struct FontHandle {
priv cgfont: Option<CGFont>, priv cgfont: Option<CGFont>,
ctfont: CTFont, ctfont: CTFont,
} }
pub impl QuartzFontHandle { pub impl FontHandle {
fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: ~[u8], fn new_from_CTFont(_: &FontContextHandle, ctfont: CTFont) -> Result<FontHandle, ()> {
style: &SpecifiedFontStyle) -> Result<QuartzFontHandle, ()> { Ok(FontHandle {
let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| {
platform::macos::font::core_graphics::data_provider::new_from_buffer(cbuf, len)
});
let cgfont = platform::macos::font::core_graphics::font::create_with_data_provider(
&fontprov);
let ctfont = platform::macos::font::core_text::font::new_from_CGFont(&cgfont,
style.pt_size);
let result = Ok(QuartzFontHandle {
cgfont: Some(cgfont),
ctfont: ctfont,
});
return result;
}
fn new_from_CTFont(_: &QuartzFontContextHandle,
ctfont: CTFont)
-> Result<QuartzFontHandle, ()> {
Ok(QuartzFontHandle {
mut cgfont: None, mut cgfont: None,
ctfont: ctfont, ctfont: ctfont,
}) })
@ -89,7 +69,26 @@ pub impl QuartzFontHandle {
} }
} }
impl FontHandleMethods for QuartzFontHandle { impl FontHandleMethods for FontHandle {
fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| {
platform::macos::font::core_graphics::data_provider::new_from_buffer(cbuf, len)
});
let cgfont = platform::macos::font::core_graphics::font::create_with_data_provider(
&fontprov);
let ctfont = platform::macos::font::core_text::font::new_from_CGFont(&cgfont,
style.pt_size);
let result = Ok(FontHandle {
cgfont: Some(cgfont),
ctfont: ctfont,
});
return result;
}
fn family_name(&self) -> ~str { fn family_name(&self) -> ~str {
self.ctfont.family_name() self.ctfont.family_name()
} }
@ -118,11 +117,10 @@ impl FontHandleMethods for QuartzFontHandle {
return FontWeight900; return FontWeight900;
} }
fn clone_with_style(&self, fctx: &QuartzFontContextHandle, fn clone_with_style(&self, fctx: &FontContextHandle, style: &SpecifiedFontStyle)
style: &SpecifiedFontStyle) -> Result<FontHandle,()> {
-> Result<QuartzFontHandle,()> {
let new_font = self.ctfont.clone_with_font_size(style.pt_size); let new_font = self.ctfont.clone_with_font_size(style.pt_size);
return QuartzFontHandle::new_from_CTFont(fctx, new_font); return FontHandle::new_from_CTFont(fctx, new_font);
} }
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex> { fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex> {
@ -182,7 +180,7 @@ impl FontHandleMethods for QuartzFontHandle {
fn get_table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> { fn get_table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
let result: Option<CFData> = self.ctfont.get_font_table(tag); let result: Option<CFData> = self.ctfont.get_font_table(tag);
result.chain(|data| { result.chain(|data| {
Some(QuartzFontTable::wrap(data)) Some(FontTable::wrap(data))
}) })
} }

View file

@ -2,26 +2,28 @@ extern mod core_foundation;
extern mod core_graphics; extern mod core_graphics;
extern mod core_text; extern mod core_text;
use gfx_font::{FontHandle, UsedFontStyle}; use gfx_font::UsedFontStyle;
use gfx_font_context::FontContextHandleMethods; use gfx_font_context::FontContextHandleMethods;
use platform::macos::font::QuartzFontHandle; use platform::macos::font::FontHandle;
use platform; use platform;
pub struct QuartzFontContextHandle { pub struct FontContextHandle {
ctx: () ctx: ()
} }
pub impl QuartzFontContextHandle { pub impl FontContextHandle {
// this is a placeholder until NSFontManager or whatever is bound in here. // this is a placeholder until NSFontManager or whatever is bound in here.
pub fn new() -> QuartzFontContextHandle { pub fn new() -> FontContextHandle {
QuartzFontContextHandle { ctx: () } FontContextHandle { ctx: () }
} }
} }
impl FontContextHandleMethods for QuartzFontContextHandle { impl FontContextHandleMethods for FontContextHandle {
fn clone(&self) -> QuartzFontContextHandle { fn clone(&self) -> FontContextHandle {
QuartzFontContextHandle { ctx: self.ctx } FontContextHandle {
ctx: self.ctx
}
} }
fn create_font_from_identifier(&self, fn create_font_from_identifier(&self,
@ -32,7 +34,7 @@ impl FontContextHandleMethods for QuartzFontContextHandle {
name, name,
style.pt_size); style.pt_size);
do result::chain(ctfont_result) |ctfont| { do result::chain(ctfont_result) |ctfont| {
QuartzFontHandle::new_from_CTFont(self, ctfont) FontHandle::new_from_CTFont(self, ctfont)
} }
} }
} }

View file

@ -5,9 +5,8 @@ use gfx_font::FontHandleMethods;
use gfx_font_context::FontContextHandleMethods; use gfx_font_context::FontContextHandleMethods;
use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap};
use native; use platform::macos::font::FontHandle;
use platform::macos::font::QuartzFontHandle; use platform::macos::font_context::FontContextHandle;
use platform::macos::font_context::QuartzFontContextHandle;
use platform::macos::font_list::core_foundation::array::CFArray; use platform::macos::font_list::core_foundation::array::CFArray;
use platform::macos::font_list::core_foundation::base::CFWrapper; use platform::macos::font_list::core_foundation::base::CFWrapper;
use platform::macos::font_list::core_foundation::string::{CFString, CFStringRef}; use platform::macos::font_list::core_foundation::string::{CFString, CFStringRef};
@ -17,13 +16,15 @@ use platform;
use core::hashmap::HashMap; use core::hashmap::HashMap;
pub struct QuartzFontListHandle { pub struct FontListHandle {
fctx: QuartzFontContextHandle, fctx: FontContextHandle,
} }
pub impl QuartzFontListHandle { pub impl FontListHandle {
fn new(fctx: &native::FontContextHandle) -> QuartzFontListHandle { fn new(fctx: &FontContextHandle) -> FontListHandle {
QuartzFontListHandle { fctx: fctx.clone() } FontListHandle {
fctx: fctx.clone()
}
} }
fn get_available_families(&self) -> FontFamilyMap { fn get_available_families(&self) -> FontFamilyMap {
@ -52,7 +53,7 @@ pub impl QuartzFontListHandle {
let desc = CFWrapper::wrap_shared(*descref); let desc = CFWrapper::wrap_shared(*descref);
let font = platform::macos::font_list::core_text::font::new_from_descriptor(&desc, let font = platform::macos::font_list::core_text::font::new_from_descriptor(&desc,
0.0); 0.0);
let handle = result::unwrap(QuartzFontHandle::new_from_CTFont(&self.fctx, font)); let handle = result::unwrap(FontHandle::new_from_CTFont(&self.fctx, font));
debug!("Creating new FontEntry for face: %s", handle.face_name()); debug!("Creating new FontEntry for face: %s", handle.face_name());
let entry = @FontEntry::new(family, handle); let entry = @FontEntry::new(family, handle);

View file

@ -37,10 +37,7 @@ pub mod font_list;
// Misc. // Misc.
pub mod opts; pub mod opts;
// Pub-uses for multiple implementations. Platform selection happens in // Platform-specific implementations.
// font.rs, font_list.rs, font_context.rs
pub mod native;
#[path="platform/mod.rs"] #[path="platform/mod.rs"]
pub mod platform; pub mod platform;

View file

@ -4,7 +4,8 @@ use geom::Point2D;
use geometry::Au; use geometry::Au;
use font::{Font, FontTable, FontTableMethods, FontTableTag}; use font::{Font, FontTableMethods, FontTableTag};
use platform::font::FontTable;
use text::glyph::{GlyphStore, GlyphIndex, GlyphData}; use text::glyph::{GlyphStore, GlyphIndex, GlyphData};
use text::shaper::ShaperMethods; use text::shaper::ShaperMethods;