diff --git a/src/servo/gfx.rs b/src/servo/gfx.rs index 71728311e86..2b9cdcd2975 100644 --- a/src/servo/gfx.rs +++ b/src/servo/gfx.rs @@ -17,7 +17,6 @@ pub use font::FontSelector; pub use font::FontStyle; pub use font::RunMetrics; pub use font_context::FontContext; -pub use font_matcher::FontMatcher; pub use geometry::Au; pub use render_context::RenderContext; diff --git a/src/servo/gfx/font.rs b/src/servo/gfx/font.rs index 9a20591eb0e..7f7c2e4a21f 100644 --- a/src/servo/gfx/font.rs +++ b/src/servo/gfx/font.rs @@ -15,7 +15,37 @@ use text::{ use core::dvec::DVec; -use native::FontHandle; +// FontHandle 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. + +#[cfg(target_os = "macos")] +pub type FontHandle/& = quartz::font::QuartzFontHandle; + +#[cfg(target_os = "linux")] +pub type FontHandle/& = freetype::font::FreeTypeFontHandle; + +// TODO: `new` should be part of trait FontHandle + +// TODO(Issue #163): this is a workaround for static methods and +// typedefs not working well together. It should be removed. + +// TODO(Rust #1723): #cfg doesn't work for impl methods, so we have +// to conditionally define the entire impl. +#[cfg(target_os = "macos")] +impl FontHandle { + static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result { + quartz::font::QuartzFontHandle::new(fctx, buf, pt_size) + } +} + +#[cfg(target_os = "linux")] +impl FontHandle { + static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result { + freetype::font::FreeTypeFontHandle::new(fctx, buf, pt_size) + } +} // Used to abstract over the shaper's choice of fixed int representation. type FractionalPixel = float; diff --git a/src/servo/gfx/font_context.rs b/src/servo/gfx/font_context.rs index 8a168790c36..bbc59122bd6 100644 --- a/src/servo/gfx/font_context.rs +++ b/src/servo/gfx/font_context.rs @@ -36,22 +36,22 @@ pub fn dummy_style() -> FontStyle { // to conditionally define the entire impl. #[cfg(target_os = "macos")] -type FontContextHandle/& = quartz::font_context::QuartzFontContext; +type FontContextHandle/& = quartz::font_context::QuartzFontContextHandle; #[cfg(target_os = "linux")] -type FontContextHandle/& = freetype::font_context::FreeTypeFontContext; +type FontContextHandle/& = freetype::font_context::FreeTypeFontContextHandle; #[cfg(target_os = "macos")] pub impl FontContextHandle { static pub fn new() -> FontContextHandle { - quartz::font_context::QuartzFontContext::new() + quartz::font_context::QuartzFontContextHandle::new() } } #[cfg(target_os = "linux")] pub impl FontContextHandle { static pub fn new() -> FontContextHandle { - freetype::font_context::FreeTypeFontContext::new() + freetype::font_context::FreeTypeFontContextHandle::new() } } diff --git a/src/servo/gfx/font_handle.rs b/src/servo/gfx/font_handle.rs deleted file mode 100644 index 9966f36975b..00000000000 --- a/src/servo/gfx/font_handle.rs +++ /dev/null @@ -1,33 +0,0 @@ -/** -FontHandle 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. -*/ - -#[cfg(target_os = "macos")] -pub type FontHandle/& = quartz::font_handle::QuartzFontHandle; - -#[cfg(target_os = "linux")] -pub type FontHandle/& = freetype::font_handle::FreeTypeFontHandle; - -// TODO: `new` should be part of trait FontHandle - -// TODO(Issue #163): this is a workaround for static methods and -// typedefs not working well together. It should be removed. - -// TODO(Rust #1723): #cfg doesn't work for impl methods, so we have -// to conditionally define the entire impl. -#[cfg(target_os = "macos")] -impl FontHandle { - static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result { - quartz::font_handle::QuartzFontHandle::new(fctx, buf, pt_size) - } -} - -#[cfg(target_os = "linux")] -impl FontHandle { - static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result { - freetype::font_handle::FreeTypeFontHandle::new(fctx, buf, pt_size) - } -} \ No newline at end of file diff --git a/src/servo/gfx/font_list.rs b/src/servo/gfx/font_list.rs new file mode 100644 index 00000000000..8ab29fb4338 --- /dev/null +++ b/src/servo/gfx/font_list.rs @@ -0,0 +1,19 @@ +#[cfg(target_os = "macos")] +type FontListHandle/& = quartz::font_list::QuartzFontListHandle; + +#[cfg(target_os = "linux")] +type FontListHandle/& = freetype::font_list::FreeTypeFontListHandle; + +#[cfg(target_os = "macos")] +pub impl FontListHandle { + static pub fn new() -> FontListHandle { + quartz::font_list::QuartzFontListHandle::new() + } +} + +#[cfg(target_os = "linux")] +pub impl FontListHandle { + static pub fn new() -> FontListHandle { + freetype::font_list::FreeTypeFontListHandle::new() + } +} diff --git a/src/servo/gfx/font_list_handle.rs b/src/servo/gfx/font_list_handle.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/servo/gfx/font_matcher.rs b/src/servo/gfx/font_matcher.rs deleted file mode 100644 index f819fc47bcf..00000000000 --- a/src/servo/gfx/font_matcher.rs +++ /dev/null @@ -1,14 +0,0 @@ -use font::{Font, FontStyle}; -use font_context::FontContext; - -struct FontMatcher { - fctx: @FontContext, -} - -impl FontMatcher { - static pub fn new(fctx: @FontContext) -> FontMatcher { - FontMatcher { - fctx: fctx, - } - } -} diff --git a/src/servo/gfx/fontconfig/font_list.rs b/src/servo/gfx/fontconfig/font_list.rs new file mode 100644 index 00000000000..109e8b65620 --- /dev/null +++ b/src/servo/gfx/fontconfig/font_list.rs @@ -0,0 +1,12 @@ +pub struct FontconfigFontContextHandle { + ctx: (), + + drop { } +} + +pub impl FontconfigFontContextHandle { + // this is a placeholder. + static pub fn new() -> FontconfigFontContextHandle { + FontconfigFontContextHandle { ctx: () } + } +} \ No newline at end of file diff --git a/src/servo/gfx/freetype/font_handle.rs b/src/servo/gfx/freetype/font.rs similarity index 100% rename from src/servo/gfx/freetype/font_handle.rs rename to src/servo/gfx/freetype/font.rs diff --git a/src/servo/gfx/freetype/font_context.rs b/src/servo/gfx/freetype/font_context.rs index c28c0f18cd4..18a168fd77d 100644 --- a/src/servo/gfx/freetype/font_context.rs +++ b/src/servo/gfx/freetype/font_context.rs @@ -10,7 +10,7 @@ use freetype::bindgen::{ }; -pub struct FreeTypeFontContext { +pub struct FreeTypeFontContextHandle { ctx: FT_Library, drop { @@ -19,8 +19,8 @@ pub struct FreeTypeFontContext { } } -pub impl FreeTypeFontContext { - static pub fn new() -> FreeTypeFontContext { +pub impl FreeTypeFontContextHandle { + static pub fn new() -> FreeTypeFontContextHandle { let lib: FT_Library = ptr::null(); let res = FT_Init_FreeType(ptr::addr_of(&lib)); // FIXME: error handling diff --git a/src/servo/gfx/native.rs b/src/servo/gfx/native.rs index 15e69e6de94..9218c8fab88 100644 --- a/src/servo/gfx/native.rs +++ b/src/servo/gfx/native.rs @@ -4,5 +4,5 @@ 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_handle::FontHandle; +pub use font::FontHandle; pub use font_context::FontContextHandle; \ No newline at end of file diff --git a/src/servo/gfx/quartz/font_handle.rs b/src/servo/gfx/quartz/font.rs similarity index 95% rename from src/servo/gfx/quartz/font_handle.rs rename to src/servo/gfx/quartz/font.rs index 4fc34ab6cca..961c1b912dd 100644 --- a/src/servo/gfx/quartz/font_handle.rs +++ b/src/servo/gfx/quartz/font.rs @@ -2,9 +2,9 @@ extern mod core_foundation; extern mod core_graphics; extern mod core_text; -use font::{FontMetrics, FractionalPixel}; -use font_context::QuartzFontContext; +use font_context::QuartzFontContextHandle; use gfx::au; +use gfx::font::{FontMetrics, FractionalPixel}; use text::glyph::GlyphIndex; use libc::size_t; @@ -68,7 +68,7 @@ pub struct QuartzFontHandle { } pub impl QuartzFontHandle { - static pub fn new(_fctx: &QuartzFontContext, buf: @~[u8], pt_size: float) -> Result { + static pub fn new(_fctx: &QuartzFontContextHandle, buf: @~[u8], pt_size: float) -> Result { let fontprov = vec::as_imm_buf(*buf, |cbuf, len| { CGDataProviderCreateWithData( ptr::null(), diff --git a/src/servo/gfx/quartz/font_context.rs b/src/servo/gfx/quartz/font_context.rs index b66cc499eba..2e227923a7b 100644 --- a/src/servo/gfx/quartz/font_context.rs +++ b/src/servo/gfx/quartz/font_context.rs @@ -1,12 +1,12 @@ -pub struct QuartzFontContext { - ctx: u8, +pub struct QuartzFontContextHandle { + ctx: (), drop { } } -pub impl QuartzFontContext { +pub impl QuartzFontContextHandle { // this is a placeholder until NSFontManager or whatever is bound in here. - static pub fn new() -> QuartzFontContext { - QuartzFontContext { ctx: 42 } + static pub fn new() -> QuartzFontContextHandle { + QuartzFontContextHandle { ctx: () } } } \ No newline at end of file diff --git a/src/servo/gfx/quartz/font_list.rs b/src/servo/gfx/quartz/font_list.rs new file mode 100644 index 00000000000..7a323b821eb --- /dev/null +++ b/src/servo/gfx/quartz/font_list.rs @@ -0,0 +1,12 @@ +pub struct QuartzFontListHandle { + ctx: (), + + drop { } +} + +pub impl QuartzFontListHandle { + // this is a placeholder until CTFontCollection is bound here. + static pub fn new() -> QuartzFontListHandle { + QuartzFontListHandle { ctx: () } + } +} \ No newline at end of file diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index 8f7e4f5eefe..289d5be1d44 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -2,7 +2,6 @@ use geom::{Rect, Size2D, Point2D}; -use css::node_style::{NodeStyle, StyledNode}; use dom::element::{ElementKind, HTMLDivElement, HTMLImageElement}; use dom::node::{Element, Node, NodeData, NodeKind, NodeTree}; use gfx::{au, dl}; @@ -18,6 +17,7 @@ use layout::display_list_builder::DisplayListBuilder; use layout::flow::FlowContext; use layout::text::TextBoxData; use newcss::color::{Color, rgba, rgb}; +use newcss::complete::CompleteStyle; use newcss::units::{BoxSizing, Length, Px}; use newcss::values::{CSSBorderColor, CSSPositionAbsolute}; use newcss::values::{CSSBorderWidthLength, CSSBorderWidthMedium}; diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index 8ff8357ffff..9eb615dac84 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -16,7 +16,6 @@ use gfx::{ Au, DisplayList, FontContext, - FontMatcher, RenderLayer, }; use gfx::render_task; @@ -81,7 +80,6 @@ struct Layout { from_content: comm::Port, font_ctx: @FontContext, - font_matcher: @FontMatcher, // This is used to root auxilliary RCU reader data layout_refs: DVec<@LayoutData>, css_select_ctx: Mut, @@ -98,7 +96,6 @@ fn Layout(render_task: RenderTask, image_cache_task: image_cache_task.clone(), local_image_cache: @LocalImageCache(move image_cache_task), from_content: from_content, - font_matcher: @FontMatcher::new(fctx), font_ctx: fctx, layout_refs: DVec(), css_select_ctx: Mut(new_css_select_ctx()) diff --git a/src/servo/servo.rc b/src/servo/servo.rc index eecec49f538..416b7b40c19 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -83,25 +83,29 @@ pub mod gfx { // fonts pub mod font; - pub mod font_cache; - pub mod font_matcher; + pub mod font_context; + pub mod font_list; - // Typedefs and pub-uses for multiple implementations. - // native contains redirects, so one can write native::FontHandle. + // Pub-uses for multiple implementations. Platform selection happens in + // font.rs, font_list.rs, font_context.rs pub mod native; - pub mod font_context; - pub mod font_handle; #[cfg(target_os = "macos")] pub mod quartz { + pub mod font; pub mod font_context; - pub mod font_handle; + pub mod font_list; } #[cfg(target_os = "linux")] pub mod freetype { + pub mod font; pub mod font_context; - pub mod font_handle; + } + + #[cfg(target_os = "linux")] + pub mod fontconfig { + pub mod font_list; } }