Don't load all font faces sources

We stop at the first one we manage to load.
This commit is contained in:
Anthony Ramine 2016-06-10 12:41:24 +02:00
parent 04b682195d
commit b97c7a8c4d
4 changed files with 131 additions and 117 deletions

View file

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