Skip to content

Commit

Permalink
Use FamilyName instead of FontFamily in @font-face
Browse files Browse the repository at this point in the history
… to exclude generic families, per spec:
https://drafts.csswg.org/css-fonts/#font-family-desc
  • Loading branch information
SimonSapin committed Feb 2, 2017
1 parent 52aa243 commit 5405fb0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions components/gfx/font_cache_thread.rs
Expand Up @@ -25,7 +25,7 @@ use std::sync::{Arc, Mutex};
use std::thread;
use std::u32;
use style::font_face::{EffectiveSources, Source};
use style::properties::longhands::font_family::computed_value::FontFamily;
use style::properties::longhands::font_family::computed_value::{FontFamily, FamilyName};
use webrender_traits;

/// A list of font templates that make up a given font family.
Expand Down Expand Up @@ -269,7 +269,7 @@ impl FontCache {
});
}
Source::Local(ref font) => {
let font_face_name = LowercaseString::new(font.name());
let font_face_name = LowercaseString::new(&font.0);
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
let mut found = false;
for_each_variation(&font_face_name, |path| {
Expand Down Expand Up @@ -461,8 +461,8 @@ impl FontCacheThread {
}
}

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 add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.0), sources, sender)).unwrap();
}

pub fn exit(&self) {
Expand Down
12 changes: 6 additions & 6 deletions components/style/font_face.rs
Expand Up @@ -8,7 +8,7 @@

#![deny(missing_docs)]

use computed_values::font_family::FontFamily;
use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use parser::{ParserContext, log_css_error, Parse};
use std::fmt;
Expand All @@ -23,7 +23,7 @@ pub enum Source {
/// A `url()` source.
Url(UrlSource),
/// A `local()` source.
Local(FontFamily),
Local(FamilyName),
}

impl ToCss for Source {
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Parse for Source {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Source, ()> {
if input.try(|input| input.expect_function_matching("local")).is_ok() {
return input.parse_nested_block(|input| {
FontFamily::parse(context, input)
FamilyName::parse(context, input)
}).map(Source::Local)
}

Expand All @@ -177,10 +177,10 @@ impl Parse for Source {
macro_rules! font_face_descriptors {
(
mandatory descriptors = [
$( #[$m_doc: meta] $m_name: tt $m_ident: ident : $m_ty: ty = $m_initial: expr, )*
$( #[$m_doc: meta] $m_name: tt $m_ident: ident: $m_ty: ty = $m_initial: expr, )*
]
optional descriptors = [
$( #[$o_doc: meta] $o_name: tt $o_ident: ident : $o_ty: ty = $o_initial: expr, )*
$( #[$o_doc: meta] $o_name: tt $o_ident: ident: $o_ty: ty = $o_initial: expr, )*
]
) => {
/// A `@font-face` rule.
Expand Down Expand Up @@ -285,7 +285,7 @@ macro_rules! font_face_descriptors {
font_face_descriptors! {
mandatory descriptors = [
/// The specified url.
"font-family" family: FontFamily = FontFamily::Generic(atom!("")),
"font-family" family: FamilyName = FamilyName(atom!("")),

/// The format hints specified with the `format()` function.
"src" sources: Vec<Source> = Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/gfx/font_cache_thread.rs
Expand Up @@ -12,8 +12,8 @@ fn test_local_web_font() {
let (inp_chan, _) = ipc::channel().unwrap();
let (out_chan, out_receiver) = ipc::channel().unwrap();
let font_cache_thread = FontCacheThread::new(inp_chan, None);
let family_name = FontFamily::FamilyName(FamilyName(From::from("test family")));
let variant_name = FontFamily::FamilyName(FamilyName(From::from("test font face")));
let family_name = FamilyName(From::from("test family"));
let variant_name = FamilyName(From::from("test font face"));
let font_face_rule = FontFaceRule {
family: family_name.clone(),
sources: vec![Source::Local(variant_name)],
Expand Down

0 comments on commit 5405fb0

Please sign in to comment.