mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Hook up optional FontList instance to FontContext.
This commit is contained in:
parent
eacf27263e
commit
577303514d
10 changed files with 62 additions and 17 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 22ff767266abfeeab508da705a4a75c23a77a291
|
Subproject commit 925aad58aad897c8cf90377adc7c2fdbdb63d132
|
|
@ -1 +1 @@
|
||||||
Subproject commit 03050d5d816462582c4506e1fb6f507b5c6653bc
|
Subproject commit c1450887c2e21a4cddfa57c4d3fc4d4eb02da425
|
|
@ -12,11 +12,13 @@ pub use display_list::DisplayItem;
|
||||||
pub use display_list::DisplayList;
|
pub use display_list::DisplayList;
|
||||||
pub use font::Font;
|
pub use font::Font;
|
||||||
pub use font::FontDescriptor;
|
pub use font::FontDescriptor;
|
||||||
|
pub use font::FontFamily;
|
||||||
pub use font::FontGroup;
|
pub use font::FontGroup;
|
||||||
pub use font::FontSelector;
|
pub use font::FontSelector;
|
||||||
pub use font::FontStyle;
|
pub use font::FontStyle;
|
||||||
pub use font::RunMetrics;
|
pub use font::RunMetrics;
|
||||||
pub use font_context::FontContext;
|
pub use font_context::FontContext;
|
||||||
|
pub use font_list::FontList;
|
||||||
pub use geometry::Au;
|
pub use geometry::Au;
|
||||||
|
|
||||||
pub use render_context::RenderContext;
|
pub use render_context::RenderContext;
|
||||||
|
|
|
@ -148,9 +148,9 @@ pub enum FontSelector {
|
||||||
// TODO(Issue #181): use deriving for trivial cmp::Eq implementations
|
// TODO(Issue #181): use deriving for trivial cmp::Eq implementations
|
||||||
pub impl FontSelector : cmp::Eq {
|
pub impl FontSelector : cmp::Eq {
|
||||||
pure fn eq(other: &FontSelector) -> bool {
|
pure fn eq(other: &FontSelector) -> bool {
|
||||||
match (self, *other) {
|
match (&self, other) {
|
||||||
(SelectorStubDummy, SelectorStubDummy) => true,
|
(&SelectorStubDummy, &SelectorStubDummy) => true,
|
||||||
(SelectorPlatformName(a), SelectorPlatformName(b)) => a == b,
|
(&SelectorPlatformName(a), &SelectorPlatformName(b)) => a == b,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use dvec::DVec;
|
||||||
use util::cache;
|
use util::cache;
|
||||||
use gfx::{
|
use gfx::{
|
||||||
FontDescriptor,
|
FontDescriptor,
|
||||||
|
FontList,
|
||||||
FontSelector,
|
FontSelector,
|
||||||
FontStyle,
|
FontStyle,
|
||||||
};
|
};
|
||||||
|
@ -51,15 +52,19 @@ pub impl FontContextHandle {
|
||||||
|
|
||||||
pub struct FontContext {
|
pub struct FontContext {
|
||||||
instance_cache: cache::MonoCache<FontDescriptor, @Font>,
|
instance_cache: cache::MonoCache<FontDescriptor, @Font>,
|
||||||
|
font_list: Option<FontList>, // only needed by layout
|
||||||
handle: FontContextHandle,
|
handle: FontContextHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl FontContext {
|
pub impl FontContext {
|
||||||
static fn new() -> FontContext {
|
static fn new(needs_font_list: bool) -> FontContext {
|
||||||
|
let handle = FontContextHandle::new();
|
||||||
|
let font_list = if needs_font_list { Some(FontList::new(&handle)) } else { None };
|
||||||
FontContext {
|
FontContext {
|
||||||
// TODO(Rust #3902): remove extraneous type parameters once they are inferred correctly.
|
// TODO(Rust #3902): remove extraneous type parameters once they are inferred correctly.
|
||||||
instance_cache: cache::new::<FontDescriptor, @Font, cache::MonoCache<FontDescriptor, @Font>>(10),
|
instance_cache: cache::new::<FontDescriptor, @Font, cache::MonoCache<FontDescriptor, @Font>>(10),
|
||||||
handle: FontContextHandle::new()
|
font_list: move font_list,
|
||||||
|
handle: move handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
use gfx::{
|
||||||
|
FontFamily,
|
||||||
|
};
|
||||||
|
|
||||||
|
use dvec::DVec;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
type FontListHandle/& = quartz::font_list::QuartzFontListHandle;
|
type FontListHandle/& = quartz::font_list::QuartzFontListHandle;
|
||||||
|
|
||||||
|
@ -6,12 +12,38 @@ type FontListHandle/& = freetype::font_list::FreeTypeFontListHandle;
|
||||||
|
|
||||||
pub impl FontListHandle {
|
pub impl FontListHandle {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
static pub fn new() -> FontListHandle {
|
static pub fn new(fctx: &native::FontContextHandle) -> Result<FontListHandle, ()> {
|
||||||
quartz::font_list::QuartzFontListHandle::new()
|
Ok(quartz::font_list::QuartzFontListHandle::new(fctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
static pub fn new() -> FontListHandle {
|
static pub fn new(fctx: &native::FontContextHandle) -> Result<FontListHandle, ()> {
|
||||||
freetype::font_list::FreeTypeFontListHandle::new()
|
Ok(freetype::font_list::FreeTypeFontListHandle::new(fctx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FontList {
|
||||||
|
families: DVec<@FontFamily>,
|
||||||
|
handle: FontListHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub impl FontList {
|
||||||
|
static fn new(fctx: &native::FontContextHandle) -> FontList {
|
||||||
|
let handle = result::unwrap(FontListHandle::new(fctx));
|
||||||
|
let list = FontList {
|
||||||
|
handle: move handle,
|
||||||
|
families: DVec(),
|
||||||
|
};
|
||||||
|
list.refresh(fctx);
|
||||||
|
return move list;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv fn refresh(fctx: &native::FontContextHandle) {
|
||||||
|
// TODO: don't refresh unless something actually changed.
|
||||||
|
// Does OSX have a notification for this event?
|
||||||
|
// It would be better to do piecemeal.
|
||||||
|
do self.families.swap |_old_families: ~[@FontFamily]| {
|
||||||
|
self.handle.get_available_families(fctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,4 +5,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. */
|
servo.rc. This is not ideal and may be changed in the future. */
|
||||||
|
|
||||||
pub use font::FontHandle;
|
pub use font::FontHandle;
|
||||||
pub use font_context::FontContextHandle;
|
pub use font_context::FontContextHandle;
|
||||||
|
pub use font_list::FontListHandle;
|
|
@ -5,7 +5,11 @@ use cf = core_foundation;
|
||||||
use cf::array::CFArray;
|
use cf::array::CFArray;
|
||||||
use ct = core_text;
|
use ct = core_text;
|
||||||
use ct::font_collection::CTFontCollection;
|
use ct::font_collection::CTFontCollection;
|
||||||
use ct::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
|
use ct::font_descriptor::{
|
||||||
|
CTFontDescriptor,
|
||||||
|
CTFontDescriptorRef,
|
||||||
|
debug_descriptor,
|
||||||
|
};
|
||||||
|
|
||||||
use gfx::font::FontFamily;
|
use gfx::font::FontFamily;
|
||||||
|
|
||||||
|
@ -16,15 +20,16 @@ pub struct QuartzFontListHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl QuartzFontListHandle {
|
pub impl QuartzFontListHandle {
|
||||||
static pub fn new() -> QuartzFontListHandle {
|
static pub fn new(_fctx: &native::FontContextHandle) -> QuartzFontListHandle {
|
||||||
QuartzFontListHandle { collection: CTFontCollection::new() }
|
QuartzFontListHandle { collection: CTFontCollection::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_available_families(_fctx: FontContext) -> ~[@FontFamily] {
|
fn get_available_families(_fctx: &native::FontContextHandle) -> ~[@FontFamily] {
|
||||||
// TODO: make a hashtable from family name to DVec<FontEntry>
|
// TODO: make a hashtable from family name to DVec<FontEntry>
|
||||||
let descriptors : CFArray<CTFontDescriptorRef, CTFontDescriptor>;
|
let descriptors : CFArray<CTFontDescriptorRef, CTFontDescriptor>;
|
||||||
descriptors = self.collection.get_descriptors();
|
descriptors = self.collection.get_descriptors();
|
||||||
for descriptors.each |desc: &CTFontDescriptor| {
|
for descriptors.each |desc: &CTFontDescriptor| {
|
||||||
|
debug!("%?", { debug_descriptor(desc); () });
|
||||||
// TODO: for each descriptor, make a FontEntry.
|
// TODO: for each descriptor, make a FontEntry.
|
||||||
// TODO: append FontEntry to hashtable value
|
// TODO: append FontEntry to hashtable value
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub fn RenderTask<C: Compositor Send>(compositor: C) -> RenderTask {
|
||||||
port: po,
|
port: po,
|
||||||
compositor: move compositor,
|
compositor: move compositor,
|
||||||
mut layer_buffer_set_port: Cell(move layer_buffer_set_port),
|
mut layer_buffer_set_port: Cell(move layer_buffer_set_port),
|
||||||
font_ctx: @FontContext::new(),
|
font_ctx: @FontContext::new(false),
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ fn Layout(render_task: RenderTask,
|
||||||
image_cache_task: ImageCacheTask,
|
image_cache_task: ImageCacheTask,
|
||||||
from_content: comm::Port<Msg>) -> Layout {
|
from_content: comm::Port<Msg>) -> Layout {
|
||||||
|
|
||||||
let fctx = @FontContext::new();
|
let fctx = @FontContext::new(true);
|
||||||
|
|
||||||
Layout {
|
Layout {
|
||||||
render_task: render_task,
|
render_task: render_task,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue