mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Don't load all font faces sources
We stop at the first one we manage to load.
This commit is contained in:
parent
04b682195d
commit
b97c7a8c4d
4 changed files with 131 additions and 117 deletions
|
@ -21,7 +21,7 @@ use std::ops::Deref;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::u32;
|
||||
use string_cache::Atom;
|
||||
use style::font_face::Source;
|
||||
use style::font_face::{EffectiveSources, Source};
|
||||
use style::properties::longhands::font_family::computed_value::FontFamily;
|
||||
use url::Url;
|
||||
use util::prefs;
|
||||
|
@ -105,8 +105,8 @@ impl FontTemplates {
|
|||
pub enum Command {
|
||||
GetFontTemplate(FontFamily, FontTemplateDescriptor, IpcSender<Reply>),
|
||||
GetLastResortFontTemplate(FontTemplateDescriptor, IpcSender<Reply>),
|
||||
AddWebFont(FontFamily, Source, IpcSender<()>),
|
||||
AddDownloadedWebFont(FontFamily, Url, Vec<u8>, IpcSender<()>),
|
||||
AddWebFont(LowercaseString, EffectiveSources, IpcSender<()>),
|
||||
AddDownloadedWebFont(LowercaseString, Url, Vec<u8>, IpcSender<()>),
|
||||
Exit(IpcSender<()>),
|
||||
}
|
||||
|
||||
|
@ -171,8 +171,33 @@ impl FontCache {
|
|||
let font_template = self.last_resort_font_template(&descriptor);
|
||||
result.send(Reply::GetFontTemplateReply(Some(font_template))).unwrap();
|
||||
}
|
||||
Command::AddWebFont(family, src, result) => {
|
||||
let family_name = LowercaseString::new(family.name());
|
||||
Command::AddWebFont(family_name, sources, result) => {
|
||||
self.handle_add_web_font(family_name, sources, result);
|
||||
}
|
||||
Command::AddDownloadedWebFont(family_name, url, bytes, result) => {
|
||||
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
|
||||
templates.add_template(Atom::from(url.to_string()), Some(bytes));
|
||||
drop(result.send(()));
|
||||
}
|
||||
Command::Exit(result) => {
|
||||
result.send(()).unwrap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_add_web_font(&mut self,
|
||||
family_name: LowercaseString,
|
||||
mut sources: EffectiveSources,
|
||||
sender: IpcSender<()>) {
|
||||
let src = if let Some(src) = sources.next() {
|
||||
src
|
||||
} else {
|
||||
sender.send(()).unwrap();
|
||||
return;
|
||||
};
|
||||
|
||||
if !self.web_families.contains_key(&family_name) {
|
||||
let templates = FontTemplates::new();
|
||||
self.web_families.insert(family_name.clone(), templates);
|
||||
|
@ -224,16 +249,17 @@ impl FontCache {
|
|||
}
|
||||
ResponseAction::ResponseComplete(response) => {
|
||||
if response.is_err() || !*response_valid.lock().unwrap() {
|
||||
drop(result.send(()));
|
||||
let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone());
|
||||
channel_to_self.send(msg).unwrap();
|
||||
return;
|
||||
}
|
||||
let mut bytes = bytes.lock().unwrap();
|
||||
let bytes = mem::replace(&mut *bytes, Vec::new());
|
||||
let command =
|
||||
Command::AddDownloadedWebFont(family.clone(),
|
||||
Command::AddDownloadedWebFont(family_name.clone(),
|
||||
url.clone(),
|
||||
bytes,
|
||||
result.clone());
|
||||
sender.clone());
|
||||
channel_to_self.send(command).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -245,21 +271,7 @@ impl FontCache {
|
|||
for_each_variation(&font_face_name, |path| {
|
||||
templates.add_template(Atom::from(&*path), None);
|
||||
});
|
||||
result.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::AddDownloadedWebFont(family, url, bytes, result) => {
|
||||
let family_name = LowercaseString::new(family.name());
|
||||
|
||||
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
|
||||
templates.add_template(Atom::from(url.to_string()), Some(bytes));
|
||||
drop(result.send(()));
|
||||
}
|
||||
Command::Exit(result) => {
|
||||
result.send(()).unwrap();
|
||||
break;
|
||||
}
|
||||
sender.send(()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,8 +443,8 @@ impl FontCacheThread {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_web_font(&self, family: FontFamily, src: Source, sender: IpcSender<()>) {
|
||||
self.chan.send(Command::AddWebFont(family, src, sender)).unwrap();
|
||||
pub fn add_web_font(&self, family: FontFamily, sources: EffectiveSources, sender: IpcSender<()>) {
|
||||
self.chan.send(Command::AddWebFont(LowercaseString::new(family.name()), sources, sender)).unwrap();
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
|
|
|
@ -358,23 +358,21 @@ fn add_font_face_rules(stylesheet: &Stylesheet,
|
|||
if opts::get().load_webfonts_synchronously {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
for font_face in stylesheet.effective_rules(&device).font_face() {
|
||||
for source in font_face.effective_sources() {
|
||||
let effective_sources = font_face.effective_sources();
|
||||
font_cache_thread.add_web_font(font_face.family.clone(),
|
||||
(*source).clone(),
|
||||
effective_sources,
|
||||
sender.clone());
|
||||
receiver.recv().unwrap();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for font_face in stylesheet.effective_rules(&device).font_face() {
|
||||
for source in font_face.effective_sources() {
|
||||
let effective_sources = font_face.effective_sources();
|
||||
outstanding_web_fonts_counter.fetch_add(1, Ordering::SeqCst);
|
||||
font_cache_thread.add_web_font(font_face.family.clone(),
|
||||
(*source).clone(),
|
||||
effective_sources,
|
||||
(*font_cache_sender).clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LayoutThread {
|
||||
|
|
|
@ -7,7 +7,6 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
|||
use parser::{ParserContext, log_css_error};
|
||||
use properties::longhands::font_family::parse_one_family;
|
||||
use std::iter;
|
||||
use std::slice;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug, HeapSizeOf, PartialEq, Eq, Deserialize, Serialize)]
|
||||
|
@ -60,21 +59,15 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
}
|
||||
|
||||
pub struct EffectiveSourcesIter<'a>(slice::Iter<'a, Source>);
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct EffectiveSources(Vec<Source>);
|
||||
|
||||
impl FontFaceRule {
|
||||
/// Returns the list of effective sources for that font-face, that is the
|
||||
/// sources which don't list any format hint, or the ones which list at
|
||||
/// least "truetype" or "opentype".
|
||||
pub fn effective_sources(&self) -> EffectiveSourcesIter {
|
||||
EffectiveSourcesIter(self.sources.iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> iter::Iterator for EffectiveSourcesIter<'a> {
|
||||
type Item = &'a Source;
|
||||
fn next(&mut self) -> Option<&'a Source> {
|
||||
self.0.find(|source| {
|
||||
pub fn effective_sources(&self) -> EffectiveSources {
|
||||
EffectiveSources(self.sources.iter().rev().filter(|source| {
|
||||
if let Source::Url(ref url_source) = **source {
|
||||
let hints = &url_source.format_hints;
|
||||
// We support only opentype fonts and truetype is an alias for
|
||||
|
@ -86,7 +79,14 @@ impl<'a> iter::Iterator for EffectiveSourcesIter<'a> {
|
|||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
}).cloned().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl iter::Iterator for EffectiveSources {
|
||||
type Item = Source;
|
||||
fn next(&mut self) -> Option<Source> {
|
||||
self.0.pop()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use gfx::font_cache_thread::FontCacheThread;
|
||||
use ipc_channel::ipc;
|
||||
use style::computed_values::font_family::FontFamily;
|
||||
use style::font_face::Source;
|
||||
use style::font_face::{FontFaceRule, Source};
|
||||
|
||||
#[test]
|
||||
fn test_local_web_font() {
|
||||
|
@ -14,8 +14,12 @@ fn test_local_web_font() {
|
|||
let font_cache_thread = FontCacheThread::new(inp_chan, None);
|
||||
let family_name = FontFamily::FamilyName(From::from("test family"));
|
||||
let variant_name = FontFamily::FamilyName(From::from("test font face"));
|
||||
let font_face_rule = FontFaceRule {
|
||||
family: family_name.clone(),
|
||||
sources: vec![Source::Local(variant_name)],
|
||||
};
|
||||
|
||||
font_cache_thread.add_web_font(family_name, Source::Local(variant_name), out_chan);
|
||||
font_cache_thread.add_web_font(family_name, font_face_rule.effective_sources(), out_chan);
|
||||
|
||||
assert_eq!(out_receiver.recv().unwrap(), ());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue