mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add test for FontContext/FontGroup functionality
Unfortunately, this required quite a bit of changes to the non-test code. That's because FontContext depends on a FontCacheThread, which in turn depends on a CoreResourceThread and therefore lots of other data structures. It seemed like it would be very difficult to instantiate a FontContext as it was, and even if we could it seems like overkill to have all these data structures present for a relatively focused test. Therefore, I created a FontSource trait which represents the interface which FontContext uses to talk to FontCacheThread. FontCacheThread then implements FontSource. Then, in the test, we can create a dummy implementation of FontSource rather than using FontCacheThread. This actually has the advantage that we can make our dummy implementation behave in certain specific way which are useful for testing, for example it can count the number of times find_font_template() is called, which helps us verify that caching/lazy-loading is working as intended.
This commit is contained in:
parent
f22e5ef3bd
commit
e4acb3f77f
61 changed files with 381 additions and 62 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use app_units::Au;
|
||||
use euclid::{Point2D, Rect, Size2D};
|
||||
use font_context::FontContext;
|
||||
use font_context::{FontContext, FontSource};
|
||||
use font_template::FontTemplateDescriptor;
|
||||
use ordered_float::NotNaN;
|
||||
use platform::font::{FontHandle, FontTable};
|
||||
|
@ -341,23 +341,33 @@ impl FontGroup {
|
|||
/// `codepoint`. If no such font is found, returns the first available font or fallback font
|
||||
/// (which will cause a "glyph not found" character to be rendered). If no font at all can be
|
||||
/// found, returns None.
|
||||
pub fn find_by_codepoint(&mut self, mut font_context: &mut FontContext, codepoint: char) -> Option<FontRef> {
|
||||
pub fn find_by_codepoint<S: FontSource>(
|
||||
&mut self,
|
||||
mut font_context: &mut FontContext<S>,
|
||||
codepoint: char
|
||||
) -> Option<FontRef> {
|
||||
self.find(&mut font_context, |font| font.borrow().has_glyph_for(codepoint))
|
||||
.or_else(|| self.first(&mut font_context))
|
||||
}
|
||||
|
||||
pub fn first(&mut self, mut font_context: &mut FontContext) -> Option<FontRef> {
|
||||
pub fn first<S: FontSource>(
|
||||
&mut self,
|
||||
mut font_context: &mut FontContext<S>
|
||||
) -> Option<FontRef> {
|
||||
self.find(&mut font_context, |_| true)
|
||||
}
|
||||
|
||||
/// Find a font which returns true for `predicate`. This method mutates because we may need to
|
||||
/// load new font data in the process of finding a suitable font.
|
||||
fn find<P>(
|
||||
fn find<S, P>(
|
||||
&mut self,
|
||||
mut font_context: &mut FontContext,
|
||||
mut font_context: &mut FontContext<S>,
|
||||
mut predicate: P
|
||||
) -> Option<FontRef>
|
||||
where P: FnMut(&FontRef) -> bool {
|
||||
where
|
||||
S: FontSource,
|
||||
P: FnMut(&FontRef) -> bool
|
||||
{
|
||||
self.families.iter_mut()
|
||||
.filter_map(|family| family.font(&mut font_context))
|
||||
.find(|f| predicate(f))
|
||||
|
@ -392,7 +402,7 @@ impl FontGroupFamily {
|
|||
/// Returns the font within this family which matches the style. We'll fetch the data from the
|
||||
/// `FontContext` the first time this method is called, and return a cached reference on
|
||||
/// subsequent calls.
|
||||
fn font(&mut self, font_context: &mut FontContext) -> Option<FontRef> {
|
||||
fn font<S: FontSource>(&mut self, font_context: &mut FontContext<S>) -> Option<FontRef> {
|
||||
if !self.loaded {
|
||||
self.font = font_context.font(&self.descriptor, &self.family);
|
||||
self.loaded = true;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use font_context::FontSource;
|
||||
use font_template::{FontTemplate, FontTemplateDescriptor};
|
||||
use fontsan;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
|
@ -30,7 +31,7 @@ use style::values::computed::font::{SingleFontFamily, FamilyName};
|
|||
use webrender_api;
|
||||
|
||||
/// A list of font templates that make up a given font family.
|
||||
struct FontTemplates {
|
||||
pub struct FontTemplates {
|
||||
templates: Vec<FontTemplate>,
|
||||
}
|
||||
|
||||
|
@ -41,14 +42,14 @@ pub struct FontTemplateInfo {
|
|||
}
|
||||
|
||||
impl FontTemplates {
|
||||
fn new() -> FontTemplates {
|
||||
pub fn new() -> FontTemplates {
|
||||
FontTemplates {
|
||||
templates: vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Find a font in this family that matches a given descriptor.
|
||||
fn find_font_for_style(&mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
|
||||
pub fn find_font_for_style(&mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
|
||||
-> Option<Arc<FontTemplateData>> {
|
||||
// TODO(Issue #189): optimize lookup for
|
||||
// regular/bold/italic/bolditalic with fixed offsets and a
|
||||
|
@ -89,7 +90,7 @@ impl FontTemplates {
|
|||
None
|
||||
}
|
||||
|
||||
fn add_template(&mut self, identifier: Atom, maybe_data: Option<Vec<u8>>) {
|
||||
pub fn add_template(&mut self, identifier: Atom, maybe_data: Option<Vec<u8>>) {
|
||||
for template in &self.templates {
|
||||
if *template.identifier() == identifier {
|
||||
return;
|
||||
|
@ -414,8 +415,8 @@ impl FontCache {
|
|||
}
|
||||
}
|
||||
|
||||
/// The public interface to the font cache thread, used exclusively by
|
||||
/// the per-thread/thread FontContext structures.
|
||||
/// The public interface to the font cache thread, used by per-thread `FontContext` instances (via
|
||||
/// the `FontSource` trait), and also by layout.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct FontCacheThread {
|
||||
chan: IpcSender<Command>,
|
||||
|
@ -453,7 +454,31 @@ impl FontCacheThread {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn find_font_template(&self, family: SingleFontFamily, desc: FontTemplateDescriptor)
|
||||
pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
|
||||
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.name), sources, sender)).unwrap();
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
let (response_chan, response_port) = ipc::channel().unwrap();
|
||||
self.chan.send(Command::Exit(response_chan)).expect("Couldn't send FontCacheThread exit message");
|
||||
response_port.recv().expect("Couldn't receive FontCacheThread reply");
|
||||
}
|
||||
}
|
||||
|
||||
impl FontSource for FontCacheThread {
|
||||
fn get_font_instance(&mut self, key: webrender_api::FontKey, size: Au) -> webrender_api::FontInstanceKey {
|
||||
let (response_chan, response_port) =
|
||||
ipc::channel().expect("failed to create IPC channel");
|
||||
self.chan.send(Command::GetFontInstance(key, size, response_chan))
|
||||
.expect("failed to send message to font cache thread");
|
||||
|
||||
let instance_key = response_port.recv()
|
||||
.expect("failed to receive response to font request");
|
||||
|
||||
instance_key
|
||||
}
|
||||
|
||||
fn find_font_template(&mut self, family: SingleFontFamily, desc: FontTemplateDescriptor)
|
||||
-> Option<FontTemplateInfo> {
|
||||
let (response_chan, response_port) =
|
||||
ipc::channel().expect("failed to create IPC channel");
|
||||
|
@ -470,7 +495,7 @@ impl FontCacheThread {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn last_resort_font_template(&self, desc: FontTemplateDescriptor)
|
||||
fn last_resort_font_template(&mut self, desc: FontTemplateDescriptor)
|
||||
-> FontTemplateInfo {
|
||||
let (response_chan, response_port) =
|
||||
ipc::channel().expect("failed to create IPC channel");
|
||||
|
@ -486,31 +511,8 @@ impl FontCacheThread {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
|
||||
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.name), sources, sender)).unwrap();
|
||||
}
|
||||
|
||||
pub fn get_font_instance(&self, key: webrender_api::FontKey, size: Au) -> webrender_api::FontInstanceKey {
|
||||
let (response_chan, response_port) =
|
||||
ipc::channel().expect("failed to create IPC channel");
|
||||
self.chan.send(Command::GetFontInstance(key, size, response_chan))
|
||||
.expect("failed to send message to font cache thread");
|
||||
|
||||
let instance_key = response_port.recv()
|
||||
.expect("failed to receive response to font request");
|
||||
|
||||
instance_key
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
let (response_chan, response_port) = ipc::channel().unwrap();
|
||||
self.chan.send(Command::Exit(response_chan)).expect("Couldn't send FontCacheThread exit message");
|
||||
response_port.recv().expect("Couldn't receive FontCacheThread reply");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct LowercaseString {
|
||||
inner: String,
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
use app_units::Au;
|
||||
use fnv::FnvHasher;
|
||||
use font::{Font, FontDescriptor, FontGroup, FontHandleMethods, FontRef};
|
||||
use font_cache_thread::{FontCacheThread, FontTemplateInfo};
|
||||
use font_cache_thread::FontTemplateInfo;
|
||||
use font_template::FontTemplateDescriptor;
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use platform::font::FontHandle;
|
||||
pub use platform::font_context::FontContextHandle;
|
||||
|
@ -20,6 +21,7 @@ use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
|
|||
use style::computed_values::font_variant_caps::T as FontVariantCaps;
|
||||
use style::properties::style_structs::Font as FontStyleStruct;
|
||||
use style::values::computed::font::SingleFontFamily;
|
||||
use webrender_api;
|
||||
|
||||
static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h)
|
||||
|
||||
|
@ -58,14 +60,26 @@ impl FallbackFontCacheEntry {
|
|||
/// this one.
|
||||
static FONT_CACHE_EPOCH: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
pub trait FontSource {
|
||||
fn get_font_instance(&mut self, key: webrender_api::FontKey, size: Au) -> webrender_api::FontInstanceKey;
|
||||
|
||||
fn find_font_template(
|
||||
&mut self,
|
||||
family: SingleFontFamily,
|
||||
desc: FontTemplateDescriptor
|
||||
) -> Option<FontTemplateInfo>;
|
||||
|
||||
fn last_resort_font_template(&mut self, desc: FontTemplateDescriptor) -> FontTemplateInfo;
|
||||
}
|
||||
|
||||
/// The FontContext represents the per-thread/thread state necessary for
|
||||
/// working with fonts. It is the public API used by the layout and
|
||||
/// paint code. It talks directly to the font cache thread where
|
||||
/// required.
|
||||
#[derive(Debug)]
|
||||
pub struct FontContext {
|
||||
pub struct FontContext<S: FontSource> {
|
||||
platform_handle: FontContextHandle,
|
||||
font_cache_thread: FontCacheThread,
|
||||
font_source: S,
|
||||
|
||||
// TODO: The font context holds a strong ref to the cached fonts
|
||||
// so they will never be released. Find out a good time to drop them.
|
||||
|
@ -81,12 +95,12 @@ pub struct FontContext {
|
|||
epoch: usize,
|
||||
}
|
||||
|
||||
impl FontContext {
|
||||
pub fn new(font_cache_thread: FontCacheThread) -> FontContext {
|
||||
impl<S: FontSource> FontContext<S> {
|
||||
pub fn new(font_source: S) -> FontContext<S> {
|
||||
let handle = FontContextHandle::new();
|
||||
FontContext {
|
||||
platform_handle: handle,
|
||||
font_cache_thread: font_cache_thread,
|
||||
font_source,
|
||||
font_cache: vec!(),
|
||||
fallback_font_cache: vec!(),
|
||||
font_group_cache: HashMap::with_hasher(Default::default()),
|
||||
|
@ -97,7 +111,7 @@ impl FontContext {
|
|||
/// Create a `Font` for use in layout calculations, from a `FontTemplateInfo` returned by the
|
||||
/// cache thread (which contains the underlying font data) and a `FontDescriptor` which
|
||||
/// contains the styling parameters.
|
||||
fn create_font(&self, info: FontTemplateInfo, descriptor: FontDescriptor) -> Result<Font, ()> {
|
||||
fn create_font(&mut self, info: FontTemplateInfo, descriptor: FontDescriptor) -> Result<Font, ()> {
|
||||
// TODO: (Bug #3463): Currently we only support fake small-caps
|
||||
// painting. We should also support true small-caps (where the
|
||||
// font supports it) in the future.
|
||||
|
@ -110,8 +124,7 @@ impl FontContext {
|
|||
info.font_template,
|
||||
Some(actual_pt_size))?;
|
||||
|
||||
let font_instance_key = self.font_cache_thread
|
||||
.get_font_instance(info.font_key, actual_pt_size);
|
||||
let font_instance_key = self.font_source.get_font_instance(info.font_key, actual_pt_size);
|
||||
Ok(Font::new(handle, descriptor.to_owned(), actual_pt_size, font_instance_key))
|
||||
}
|
||||
|
||||
|
@ -155,9 +168,9 @@ impl FontContext {
|
|||
}
|
||||
|
||||
/// Creates a new font cache entry matching `descriptor` and `family`.
|
||||
fn create_font_cache_entry(&self, descriptor: &FontDescriptor, family: &SingleFontFamily) -> FontCacheEntry {
|
||||
fn create_font_cache_entry(&mut self, descriptor: &FontDescriptor, family: &SingleFontFamily) -> FontCacheEntry {
|
||||
let font =
|
||||
self.font_cache_thread.find_font_template(family.clone(), descriptor.template_descriptor.clone())
|
||||
self.font_source.find_font_template(family.clone(), descriptor.template_descriptor.clone())
|
||||
.and_then(|template_info|
|
||||
self.create_font(template_info, descriptor.to_owned()).ok()
|
||||
)
|
||||
|
@ -187,8 +200,8 @@ impl FontContext {
|
|||
}
|
||||
|
||||
/// Creates a new fallback font cache entry matching `descriptor`.
|
||||
fn create_fallback_font_cache_entry(&self, descriptor: &FontDescriptor) -> Option<FallbackFontCacheEntry> {
|
||||
let template_info = self.font_cache_thread.last_resort_font_template(descriptor.template_descriptor.clone());
|
||||
fn create_fallback_font_cache_entry(&mut self, descriptor: &FontDescriptor) -> Option<FallbackFontCacheEntry> {
|
||||
let template_info = self.font_source.last_resort_font_template(descriptor.template_descriptor.clone());
|
||||
|
||||
match self.create_font(template_info, descriptor.to_owned()) {
|
||||
Ok(font) =>
|
||||
|
@ -220,7 +233,7 @@ impl FontContext {
|
|||
}
|
||||
}
|
||||
|
||||
impl MallocSizeOf for FontContext {
|
||||
impl<S: FontSource> MallocSizeOf for FontContext<S> {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
// FIXME(njn): Measure other fields eventually.
|
||||
self.platform_handle.size_of(ops)
|
||||
|
|
174
components/gfx/tests/font_context.rs
Normal file
174
components/gfx/tests/font_context.rs
Normal file
|
@ -0,0 +1,174 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate app_units;
|
||||
extern crate gfx;
|
||||
extern crate servo_arc;
|
||||
extern crate servo_atoms;
|
||||
extern crate style;
|
||||
extern crate webrender_api;
|
||||
|
||||
use app_units::Au;
|
||||
use gfx::font::FontHandleMethods;
|
||||
use gfx::font_cache_thread::{FontTemplates, FontTemplateInfo};
|
||||
use gfx::font_context::{FontContext, FontContextHandle, FontSource};
|
||||
use gfx::font_template::FontTemplateDescriptor;
|
||||
use servo_arc::Arc;
|
||||
use servo_atoms::Atom;
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use style::properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
use style::properties::longhands::font_style::computed_value::T as FontStyle;
|
||||
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
|
||||
use style::properties::style_structs::Font as FontStyleStruct;
|
||||
use style::values::computed::font::{FamilyName, FamilyNameSyntax, FontFamily, FontFamilyList, FontSize};
|
||||
use style::values::computed::font::{FontWeight, SingleFontFamily};
|
||||
|
||||
struct TestFontSource {
|
||||
handle: FontContextHandle,
|
||||
families: HashMap<Atom, FontTemplates>,
|
||||
find_font_count: Rc<Cell<isize>>,
|
||||
}
|
||||
|
||||
impl TestFontSource {
|
||||
fn new() -> TestFontSource {
|
||||
let mut csstest_ascii = FontTemplates::new();
|
||||
Self::add_face(&mut csstest_ascii, "csstest-ascii");
|
||||
|
||||
let mut csstest_basic = FontTemplates::new();
|
||||
Self::add_face(&mut csstest_basic, "csstest-basic-regular");
|
||||
|
||||
let mut families = HashMap::new();
|
||||
families.insert(Atom::from("CSSTest ASCII"), csstest_ascii);
|
||||
families.insert(Atom::from("CSSTest Basic"), csstest_basic);
|
||||
|
||||
TestFontSource {
|
||||
handle: FontContextHandle::new(),
|
||||
families,
|
||||
find_font_count: Rc::new(Cell::new(0)),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_face(family: &mut FontTemplates, name: &str) {
|
||||
let mut path: PathBuf = [
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"tests",
|
||||
"support",
|
||||
"CSSTest",
|
||||
].iter().collect();
|
||||
path.push(format!("{}.ttf", name));
|
||||
|
||||
let file = File::open(path).unwrap();
|
||||
|
||||
family.add_template(
|
||||
Atom::from(name),
|
||||
Some(file.bytes().map(|b| b.unwrap()).collect())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl FontSource for TestFontSource {
|
||||
fn get_font_instance(&mut self, _key: webrender_api::FontKey, _size: Au) -> webrender_api::FontInstanceKey {
|
||||
webrender_api::FontInstanceKey(webrender_api::IdNamespace(0), 0)
|
||||
}
|
||||
|
||||
fn find_font_template(
|
||||
&mut self,
|
||||
family: SingleFontFamily,
|
||||
desc: FontTemplateDescriptor
|
||||
) -> Option<FontTemplateInfo> {
|
||||
let handle = &self.handle;
|
||||
|
||||
self.find_font_count.set(self.find_font_count.get() + 1);
|
||||
self.families
|
||||
.get_mut(family.atom())
|
||||
.and_then(|family| family.find_font_for_style(&desc, handle))
|
||||
.map(|template| {
|
||||
FontTemplateInfo {
|
||||
font_template: template,
|
||||
font_key: webrender_api::FontKey(webrender_api::IdNamespace(0), 0),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn last_resort_font_template(&mut self, _desc: FontTemplateDescriptor) -> FontTemplateInfo {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
fn style() -> FontStyleStruct {
|
||||
let mut style = FontStyleStruct {
|
||||
font_family: FontFamily::serif(),
|
||||
font_style: FontStyle::Normal,
|
||||
font_variant_caps: FontVariantCaps::Normal,
|
||||
font_weight: FontWeight::normal(),
|
||||
font_size: FontSize::medium(),
|
||||
font_stretch: FontStretch::Normal,
|
||||
hash: 0,
|
||||
};
|
||||
style.compute_font_hash();
|
||||
style
|
||||
}
|
||||
|
||||
fn font_family(names: Vec<&str>) -> FontFamily {
|
||||
let names: Vec<SingleFontFamily> = names.into_iter().map(|name|
|
||||
SingleFontFamily::FamilyName(FamilyName {
|
||||
name: Atom::from(name),
|
||||
syntax: FamilyNameSyntax::Quoted,
|
||||
})
|
||||
).collect();
|
||||
|
||||
FontFamily(FontFamilyList::new(names.into_boxed_slice()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_font_group_is_cached_by_style() {
|
||||
let source = TestFontSource::new();
|
||||
let mut context = FontContext::new(source);
|
||||
|
||||
let style1 = style();
|
||||
|
||||
let mut style2 = style();
|
||||
style2.set_font_style(FontStyle::Italic);
|
||||
|
||||
assert_eq!(
|
||||
context.font_group(Arc::new(style1.clone())).as_ptr(),
|
||||
context.font_group(Arc::new(style1.clone())).as_ptr(),
|
||||
"the same font group should be returned for two styles with the same hash"
|
||||
);
|
||||
|
||||
assert_ne!(
|
||||
context.font_group(Arc::new(style1.clone())).as_ptr(),
|
||||
context.font_group(Arc::new(style2.clone())).as_ptr(),
|
||||
"different font groups should be returned for two styles with different hashes"
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_font_group_find_by_codepoint() {
|
||||
let source = TestFontSource::new();
|
||||
let count = source.find_font_count.clone();
|
||||
let mut context = FontContext::new(source);
|
||||
|
||||
let mut style = style();
|
||||
style.set_font_family(font_family(vec!("CSSTest ASCII", "CSSTest Basic")));
|
||||
|
||||
let group = context.font_group(Arc::new(style));
|
||||
|
||||
let font = group.borrow_mut().find_by_codepoint(&mut context, 'a').unwrap();
|
||||
assert_eq!(font.borrow().handle.family_name(), "CSSTest ASCII");
|
||||
assert_eq!(count.get(), 1, "only the first font in the list should have been loaded");
|
||||
|
||||
let font = group.borrow_mut().find_by_codepoint(&mut context, 'a').unwrap();
|
||||
assert_eq!(font.borrow().handle.family_name(), "CSSTest ASCII");
|
||||
assert_eq!(count.get(), 1, "we shouldn't load the same font a second time");
|
||||
|
||||
let font = group.borrow_mut().find_by_codepoint(&mut context, 'á').unwrap();
|
||||
assert_eq!(font.borrow().handle.family_name(), "CSSTest Basic");
|
||||
assert_eq!(count.get(), 2, "both fonts should now have been loaded");
|
||||
}
|
94
components/gfx/tests/support/CSSTest/LICENSE
Normal file
94
components/gfx/tests/support/CSSTest/LICENSE
Normal file
|
@ -0,0 +1,94 @@
|
|||
Copyright (c) 2003-2008 SIL International (http://www.sil.org/),
|
||||
with Reserved Font Names "Gentium" and "SIL".
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 1 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that the font
|
||||
names of derivative works are changed. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
25
components/gfx/tests/support/CSSTest/README
Normal file
25
components/gfx/tests/support/CSSTest/README
Normal file
|
@ -0,0 +1,25 @@
|
|||
These fonts are a copy of the CSSTest fonts in web-platform-tests, so that we
|
||||
can use them for unit-testing our font code. Here is the README from
|
||||
web-platform-tests:
|
||||
|
||||
-----
|
||||
|
||||
These fonts were created to support the testing of the font features
|
||||
in CSS, and are required to run some of the tests for those features.
|
||||
|
||||
The fonts are modified versions of Gentium Basic, licensed by SIL under
|
||||
the Open Font License which allows modifications as long as the terms
|
||||
of the license are met.
|
||||
|
||||
The original fonts were used to create the family 'CSSTest Basic'. This
|
||||
family has four faces and can be used for testing bold / italics.
|
||||
A subsetted version of this font with only glyphs for basic ASCII
|
||||
characters is 'CSSTest ASCII'. This was used to make the other
|
||||
variations. Most of the modications are to the name table and character
|
||||
maps, for the most part glyphs were not modified.
|
||||
|
||||
The fonts are available for download both individually and as a
|
||||
ZIP package below.
|
||||
|
||||
The files test.html and test.xhtml test that the fonts have been
|
||||
correctly installed.
|
BIN
components/gfx/tests/support/CSSTest/csstest-ascii.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-ascii.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-basic-bold.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-basic-bold.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-basic-italic.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-basic-italic.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-basic-regular.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-basic-regular.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-fallback.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-fallback.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-familyname-bold.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-familyname-bold.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-familyname.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-familyname.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-verify.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-verify.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-100.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-100.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w1.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w1.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w4.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w4.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w7.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w7.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w9.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-1479-w9.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-15-w1.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-15-w1.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-15-w5.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-15-w5.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-200.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-200.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-24-w2.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-24-w2.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-24-w4.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-24-w4.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w2.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w2.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w5.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w5.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w6.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w6.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w9.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-2569-w9.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w2.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w2.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w5.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w5.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w8.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-258-w8.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-300.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-300.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w3.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w3.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w5.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w5.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w8.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w8.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w9.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-3589-w9.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-400.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-400.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-47-w4.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-47-w4.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-47-w7.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-47-w7.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-500.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-500.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-600.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-600.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-700.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-700.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-800.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-800.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-900.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-900.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w1.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w1.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w2.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w2.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w3.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w3.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w4.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w4.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w5.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w5.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w6.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w6.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w7.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w7.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w8.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w8.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w9.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights-full-w9.ttf
Normal file
Binary file not shown.
BIN
components/gfx/tests/support/CSSTest/csstest-weights.ttf
Normal file
BIN
components/gfx/tests/support/CSSTest/csstest-weights.ttf
Normal file
Binary file not shown.
|
@ -27,10 +27,12 @@ use std::thread;
|
|||
use style::context::RegisteredSpeculativePainter;
|
||||
use style::context::SharedStyleContext;
|
||||
|
||||
thread_local!(static FONT_CONTEXT_KEY: RefCell<Option<FontContext>> = RefCell::new(None));
|
||||
pub type LayoutFontContext = FontContext<FontCacheThread>;
|
||||
|
||||
thread_local!(static FONT_CONTEXT_KEY: RefCell<Option<LayoutFontContext>> = RefCell::new(None));
|
||||
|
||||
pub fn with_thread_local_font_context<F, R>(layout_context: &LayoutContext, f: F) -> R
|
||||
where F: FnOnce(&mut FontContext) -> R
|
||||
where F: FnOnce(&mut LayoutFontContext) -> R
|
||||
{
|
||||
FONT_CONTEXT_KEY.with(|k| {
|
||||
let mut font_context = k.borrow_mut();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use ServoArc;
|
||||
use app_units::{Au, MIN_AU};
|
||||
use block::AbsoluteAssignBSizesTraversal;
|
||||
use context::LayoutContext;
|
||||
use context::{LayoutContext, LayoutFontContext};
|
||||
use display_list::{DisplayListBuildState, InlineFlowDisplayListBuilding};
|
||||
use display_list::StackingContextCollectionState;
|
||||
use euclid::{Point2D, Size2D};
|
||||
|
@ -20,7 +20,6 @@ use fragment::FragmentFlags;
|
|||
use fragment::SpecificFragmentInfo;
|
||||
use gfx::display_list::OpaqueNode;
|
||||
use gfx::font::FontMetrics;
|
||||
use gfx::font_context::FontContext;
|
||||
use gfx_traits::print_tree::PrintTree;
|
||||
use layout_debug;
|
||||
use model::IntrinsicISizesContribution;
|
||||
|
@ -1132,7 +1131,7 @@ impl InlineFlow {
|
|||
/// Computes the minimum metrics for each line. This is done during flow construction.
|
||||
///
|
||||
/// `style` is the style of the block.
|
||||
pub fn minimum_line_metrics(&self, font_context: &mut FontContext, style: &ComputedValues)
|
||||
pub fn minimum_line_metrics(&self, font_context: &mut LayoutFontContext, style: &ComputedValues)
|
||||
-> LineMetrics {
|
||||
InlineFlow::minimum_line_metrics_for_fragments(&self.fragments.fragments,
|
||||
font_context,
|
||||
|
@ -1144,7 +1143,7 @@ impl InlineFlow {
|
|||
///
|
||||
/// `style` is the style of the block that these fragments belong to.
|
||||
pub fn minimum_line_metrics_for_fragments(fragments: &[Fragment],
|
||||
font_context: &mut FontContext,
|
||||
font_context: &mut LayoutFontContext,
|
||||
style: &ComputedValues)
|
||||
-> LineMetrics {
|
||||
// As a special case, if this flow contains only hypothetical fragments, then the entire
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
#![deny(unsafe_code)]
|
||||
|
||||
use app_units::Au;
|
||||
use context::LayoutFontContext;
|
||||
use fragment::{Fragment, ScannedTextFlags};
|
||||
use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo};
|
||||
use gfx::font::{FontRef, FontMetrics, RunMetrics, ShapingFlags, ShapingOptions};
|
||||
use gfx::font_context::FontContext;
|
||||
use gfx::text::glyph::ByteIndex;
|
||||
use gfx::text::text_run::TextRun;
|
||||
use gfx::text::util::{self, CompressionMode};
|
||||
|
@ -69,7 +69,7 @@ impl TextRunScanner {
|
|||
}
|
||||
|
||||
pub fn scan_for_runs(&mut self,
|
||||
font_context: &mut FontContext,
|
||||
font_context: &mut LayoutFontContext,
|
||||
mut fragments: LinkedList<Fragment>)
|
||||
-> InlineFragments {
|
||||
debug!("TextRunScanner: scanning {} fragments for text runs...", fragments.len());
|
||||
|
@ -137,7 +137,7 @@ impl TextRunScanner {
|
|||
/// for correct painting order. Since we compress several leaf fragments here, the mapping must
|
||||
/// be adjusted.
|
||||
fn flush_clump_to_list(&mut self,
|
||||
mut font_context: &mut FontContext,
|
||||
mut font_context: &mut LayoutFontContext,
|
||||
out_fragments: &mut Vec<Fragment>,
|
||||
paragraph_bytes_processed: &mut usize,
|
||||
bidi_levels: Option<&[bidi::Level]>,
|
||||
|
@ -463,7 +463,7 @@ fn bounding_box_for_run_metrics(metrics: &RunMetrics, writing_mode: WritingMode)
|
|||
///
|
||||
/// Panics if no font can be found for the given font style.
|
||||
#[inline]
|
||||
pub fn font_metrics_for_style(mut font_context: &mut FontContext, style: ::ServoArc<FontStyleStruct>)
|
||||
pub fn font_metrics_for_style(mut font_context: &mut LayoutFontContext, style: ::ServoArc<FontStyleStruct>)
|
||||
-> FontMetrics {
|
||||
let font_group = font_context.font_group(style);
|
||||
let font = font_group.borrow_mut().first(&mut font_context);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue