Final font rearrangement for a while. Remove _handle suffix, add dummy font_list, other cleanup.

This commit is contained in:
Brian J. Burg 2012-11-07 14:05:39 -08:00
parent 72c11b6fba
commit 65781484d8
17 changed files with 103 additions and 77 deletions

View file

@ -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;

View file

@ -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<FontHandle, ()> {
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<FontHandle, ()> {
freetype::font::FreeTypeFontHandle::new(fctx, buf, pt_size)
}
}
// Used to abstract over the shaper's choice of fixed int representation.
type FractionalPixel = float;

View file

@ -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()
}
}

View file

@ -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<FontHandle, ()> {
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<FontHandle, ()> {
freetype::font_handle::FreeTypeFontHandle::new(fctx, buf, pt_size)
}
}

View file

@ -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()
}
}

View file

View file

@ -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,
}
}
}

View file

@ -0,0 +1,12 @@
pub struct FontconfigFontContextHandle {
ctx: (),
drop { }
}
pub impl FontconfigFontContextHandle {
// this is a placeholder.
static pub fn new() -> FontconfigFontContextHandle {
FontconfigFontContextHandle { ctx: () }
}
}

View file

@ -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

View file

@ -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;

View file

@ -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<QuartzFontHandle, ()> {
static pub fn new(_fctx: &QuartzFontContextHandle, buf: @~[u8], pt_size: float) -> Result<QuartzFontHandle, ()> {
let fontprov = vec::as_imm_buf(*buf, |cbuf, len| {
CGDataProviderCreateWithData(
ptr::null(),

View file

@ -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: () }
}
}

View file

@ -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: () }
}
}

View file

@ -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};

View file

@ -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<Msg>,
font_ctx: @FontContext,
font_matcher: @FontMatcher,
// This is used to root auxilliary RCU reader data
layout_refs: DVec<@LayoutData>,
css_select_ctx: Mut<SelectCtx>,
@ -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())

View file

@ -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;
}
}