aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/style/font_face.rs9
-rw-r--r--components/style/gecko/rules.rs26
-rw-r--r--components/style/properties/longhand/font.mako.rs21
3 files changed, 44 insertions, 12 deletions
diff --git a/components/style/font_face.rs b/components/style/font_face.rs
index 3d81476fd12..4eb79690c91 100644
--- a/components/style/font_face.rs
+++ b/components/style/font_face.rs
@@ -9,7 +9,7 @@
#![deny(missing_docs)]
#[cfg(feature = "gecko")]
-use computed_values::{font_style, font_weight, font_stretch};
+use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use cssparser::SourceLocation;
@@ -337,7 +337,12 @@ font_face_descriptors! {
UnicodeRange { start: 0, end: 0x10FFFF }
],
- // FIXME: add font-feature-settings, font-language-override, and font-display
+ /// The feature settings of this font face.
+ "font-feature-settings" feature_settings / mFontFeatureSettings: font_feature_settings::T = {
+ font_feature_settings::T::Normal
+ },
+
+ // FIXME: add font-language-override, and font-display.
]
}
diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs
index f41fcb1e0b1..aceb4aec5e9 100644
--- a/components/style/gecko/rules.rs
+++ b/components/style/gecko/rules.rs
@@ -4,7 +4,8 @@
//! Bindings for CSS Rule objects
-use computed_values::{font_style, font_weight, font_stretch};
+use byteorder::{BigEndian, WriteBytesExt};
+use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
use computed_values::font_family::FamilyName;
use counter_style;
use cssparser::UnicodeRange;
@@ -15,7 +16,7 @@ use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
-use std::fmt;
+use std::{fmt, str};
/// A @font-face rule
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
@@ -32,6 +33,27 @@ impl ToNsCssValue for font_weight::T {
}
}
+impl ToNsCssValue for font_feature_settings::T {
+ fn convert(self, nscssvalue: &mut nsCSSValue) {
+ match self {
+ font_feature_settings::T::Normal => nscssvalue.set_normal(),
+ font_feature_settings::T::Tag(tags) => {
+ nscssvalue.set_pair_list(tags.into_iter().map(|entry| {
+ let mut feature = nsCSSValue::null();
+ let mut raw = [0u8; 4];
+ (&mut raw[..]).write_u32::<BigEndian>(entry.tag).unwrap();
+ feature.set_string(str::from_utf8(&raw).unwrap());
+
+ let mut index = nsCSSValue::null();
+ index.set_integer(entry.value as i32);
+
+ (feature, index)
+ }))
+ }
+ }
+ }
+}
+
macro_rules! map_enum {
(
$(
diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs
index aed5221e4b6..1faf2ded1c7 100644
--- a/components/style/properties/longhand/font.mako.rs
+++ b/components/style/properties/longhand/font.mako.rs
@@ -1804,14 +1804,14 @@ ${helpers.single_keyword_system("font-variant-position",
use std::fmt;
use style_traits::ToCss;
- #[derive(Debug, Clone, PartialEq)]
+ #[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
Normal,
Tag(Vec<FeatureTagValue>)
}
- #[derive(Debug, Clone, PartialEq)]
+ #[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct FeatureTagValue {
pub tag: u32,
@@ -1837,6 +1837,16 @@ ${helpers.single_keyword_system("font-variant-position",
}
}
+ impl Parse for T {
+ /// https://www.w3.org/TR/css-fonts-3/#propdef-font-feature-settings
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
+ return Ok(T::Normal);
+ }
+ input.parse_comma_separated(|i| FeatureTagValue::parse(context, i)).map(T::Tag)
+ }
+ }
+
impl ToCss for FeatureTagValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
use std::str;
@@ -1909,12 +1919,7 @@ ${helpers.single_keyword_system("font-variant-position",
/// normal | <feature-tag-value>#
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
- if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
- Ok(SpecifiedValue::Value(computed_value::T::Normal))
- } else {
- input.parse_comma_separated(|i| computed_value::FeatureTagValue::parse(context, i))
- .map(computed_value::T::Tag).map(SpecifiedValue::Value)
- }
+ computed_value::T::parse(context, input).map(SpecifiedValue::Value)
}
</%helpers:longhand>