mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Refactor font-feature-settings and font-variation-settings.
This fixes all known issues with serialization and parsing of these two properties, and in particular calc handling and such: https://bugzilla.mozilla.org/show_bug.cgi?id=1434692 https://bugzilla.mozilla.org/show_bug.cgi?id=1434724 Also does a fair amount of cleanup and all that, which was needed.
This commit is contained in:
parent
09398d42af
commit
3b34d734e6
11 changed files with 270 additions and 261 deletions
|
@ -9,7 +9,7 @@
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
|
use computed_values::{font_stretch, font_style, font_weight};
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||||
use cssparser::{SourceLocation, CowRcStr};
|
use cssparser::{SourceLocation, CowRcStr};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||||
|
@ -25,6 +25,8 @@ use str::CssStringWriter;
|
||||||
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
||||||
use style_traits::{StyleParseErrorKind, ToCss};
|
use style_traits::{StyleParseErrorKind, ToCss};
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
use values::specified::font::SpecifiedFontFeatureSettings;
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A source for a font-face rule.
|
/// A source for a font-face rule.
|
||||||
|
@ -395,8 +397,8 @@ font_face_descriptors! {
|
||||||
],
|
],
|
||||||
|
|
||||||
/// The feature settings of this font face.
|
/// The feature settings of this font face.
|
||||||
"font-feature-settings" feature_settings / mFontFeatureSettings: font_feature_settings::T = {
|
"font-feature-settings" feature_settings / mFontFeatureSettings: SpecifiedFontFeatureSettings = {
|
||||||
font_feature_settings::T::Normal
|
font_feature_settings::SpecifiedValue::normal()
|
||||||
},
|
},
|
||||||
|
|
||||||
/// The language override of this font face.
|
/// The language override of this font face.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! Bindings for CSS Rule objects
|
//! Bindings for CSS Rule objects
|
||||||
|
|
||||||
use byteorder::{BigEndian, WriteBytesExt};
|
use byteorder::{BigEndian, WriteBytesExt};
|
||||||
use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
|
use computed_values::{font_stretch, font_style, font_weight};
|
||||||
use counter_style;
|
use counter_style;
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight};
|
use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight};
|
||||||
|
@ -21,7 +21,7 @@ use std::fmt::{self, Write};
|
||||||
use std::str;
|
use std::str;
|
||||||
use str::CssStringWriter;
|
use str::CssStringWriter;
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
use values::generics::font::FontSettings;
|
use values::specified::font::SpecifiedFontFeatureSettings;
|
||||||
|
|
||||||
/// A @font-face rule
|
/// A @font-face rule
|
||||||
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
||||||
|
@ -50,26 +50,26 @@ impl ToNsCssValue for FontWeight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNsCssValue for font_feature_settings::T {
|
impl ToNsCssValue for SpecifiedFontFeatureSettings {
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
match self {
|
if self.0.is_empty() {
|
||||||
FontSettings::Normal => nscssvalue.set_normal(),
|
nscssvalue.set_normal();
|
||||||
FontSettings::Tag(tags) => {
|
return;
|
||||||
nscssvalue.set_pair_list(tags.into_iter().map(|entry| {
|
}
|
||||||
|
|
||||||
|
nscssvalue.set_pair_list(self.0.into_iter().map(|entry| {
|
||||||
let mut feature = nsCSSValue::null();
|
let mut feature = nsCSSValue::null();
|
||||||
let mut raw = [0u8; 4];
|
let mut raw = [0u8; 4];
|
||||||
(&mut raw[..]).write_u32::<BigEndian>(entry.tag.0).unwrap();
|
(&mut raw[..]).write_u32::<BigEndian>(entry.tag.0).unwrap();
|
||||||
feature.set_string(str::from_utf8(&raw).unwrap());
|
feature.set_string(str::from_utf8(&raw).unwrap());
|
||||||
|
|
||||||
let mut index = nsCSSValue::null();
|
let mut index = nsCSSValue::null();
|
||||||
index.set_integer(entry.value.0 as i32);
|
index.set_integer(entry.value.value());
|
||||||
|
|
||||||
(feature, index)
|
(feature, index)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToNsCssValue for font_language_override::SpecifiedValue {
|
impl ToNsCssValue for font_language_override::SpecifiedValue {
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
|
|
|
@ -1426,30 +1426,22 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
}
|
}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_font_settings(ident, tag_type)">
|
<%def name="impl_font_settings(ident, tag_type, value_type, gecko_value_type)">
|
||||||
<%
|
<%
|
||||||
gecko_ffi_name = to_camel_case_lower(ident)
|
gecko_ffi_name = to_camel_case_lower(ident)
|
||||||
%>
|
%>
|
||||||
|
|
||||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
use values::generics::font::FontSettings;
|
|
||||||
|
|
||||||
let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
|
let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
|
||||||
current_settings.clear_pod();
|
current_settings.clear_pod();
|
||||||
|
|
||||||
match v {
|
unsafe { current_settings.set_len_pod(v.0.len() as u32) };
|
||||||
FontSettings::Normal => {}, // do nothing, length is already 0
|
|
||||||
|
|
||||||
FontSettings::Tag(other_settings) => {
|
for (current, other) in current_settings.iter_mut().zip(v.0.iter()) {
|
||||||
unsafe { current_settings.set_len_pod(other_settings.len() as u32) };
|
|
||||||
|
|
||||||
for (current, other) in current_settings.iter_mut().zip(other_settings) {
|
|
||||||
current.mTag = other.tag.0;
|
current.mTag = other.tag.0;
|
||||||
current.mValue = other.value.0;
|
current.mValue = other.value as ${gecko_value_type};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_${ident}_from(&mut self, other: &Self) {
|
pub fn copy_${ident}_from(&mut self, other: &Self) {
|
||||||
let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
|
let current_settings = &mut self.gecko.mFont.${gecko_ffi_name};
|
||||||
|
@ -1470,22 +1462,18 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||||
use values::generics::font::{FontSettings, FontSettingTag, ${tag_type}};
|
use values::generics::font::{FontSettings, ${tag_type}};
|
||||||
use values::specified::font::FontTag;
|
use values::specified::font::FontTag;
|
||||||
|
|
||||||
if self.gecko.mFont.${gecko_ffi_name}.len() == 0 {
|
FontSettings(
|
||||||
FontSettings::Normal
|
|
||||||
} else {
|
|
||||||
FontSettings::Tag(
|
|
||||||
self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| {
|
self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| {
|
||||||
FontSettingTag {
|
${tag_type} {
|
||||||
tag: FontTag(gecko_font_setting.mTag),
|
tag: FontTag(gecko_font_setting.mTag),
|
||||||
value: ${tag_type}(gecko_font_setting.mValue),
|
value: gecko_font_setting.mValue as ${value_type},
|
||||||
}
|
}
|
||||||
}).collect()
|
}).collect::<Vec<_>>().into_boxed_slice()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_trait(style_struct_name, skip_longhands='')">
|
<%def name="impl_trait(style_struct_name, skip_longhands='')">
|
||||||
|
@ -2338,8 +2326,10 @@ fn static_assert() {
|
||||||
<%self:impl_trait style_struct_name="Font"
|
<%self:impl_trait style_struct_name="Font"
|
||||||
skip_longhands="${skip_font_longhands}">
|
skip_longhands="${skip_font_longhands}">
|
||||||
|
|
||||||
<% impl_font_settings("font_feature_settings", "FontSettingTagInt") %>
|
// Negative numbers are invalid at parse time, but <integer> is still an
|
||||||
<% impl_font_settings("font_variation_settings", "FontSettingTagFloat") %>
|
// i32.
|
||||||
|
<% impl_font_settings("font_feature_settings", "FeatureTagValue", "i32", "u32") %>
|
||||||
|
<% impl_font_settings("font_variation_settings", "VariationValue", "f32", "f32") %>
|
||||||
|
|
||||||
pub fn fixup_none_generic(&mut self, device: &Device) {
|
pub fn fixup_none_generic(&mut self, device: &Device) {
|
||||||
self.gecko.mFont.systemFont = false;
|
self.gecko.mFont.systemFont = false;
|
||||||
|
|
|
@ -17,8 +17,6 @@ use properties::{CSSWideKeyword, PropertyDeclaration};
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
use properties::longhands::font_variation_settings::computed_value::T as FontVariationSettings;
|
|
||||||
use properties::longhands::visibility::computed_value::T as Visibility;
|
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties::PropertyId;
|
use properties::PropertyId;
|
||||||
|
@ -51,15 +49,15 @@ use values::computed::transform::Translate as ComputedTranslate;
|
||||||
use values::computed::transform::Scale as ComputedScale;
|
use values::computed::transform::Scale as ComputedScale;
|
||||||
use values::generics::transform::{self, Rotate, Translate, Scale, Transform, TransformOperation};
|
use values::generics::transform::{self, Rotate, Translate, Scale, Transform, TransformOperation};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
#[cfg(feature = "gecko")] use values::generics::font::FontSettings as GenericFontSettings;
|
use values::generics::font::FontSettings as GenericFontSettings;
|
||||||
#[cfg(feature = "gecko")] use values::generics::font::FontSettingTag as GenericFontSettingTag;
|
use values::computed::font::FontVariationSettings;
|
||||||
#[cfg(feature = "gecko")] use values::generics::font::FontSettingTagFloat;
|
use values::generics::font::VariationValue;
|
||||||
use values::generics::NonNegative;
|
use values::generics::NonNegative;
|
||||||
use values::generics::effects::Filter;
|
use values::generics::effects::Filter;
|
||||||
use values::generics::position as generic_position;
|
use values::generics::position as generic_position;
|
||||||
use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint};
|
use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint};
|
||||||
use values::generics::svg::{SVGPaintKind, SVGStrokeDashArray, SVGOpacity};
|
use values::generics::svg::{SVGPaintKind, SVGStrokeDashArray, SVGOpacity};
|
||||||
#[cfg(feature = "gecko")] use values::specified::font::FontTag;
|
use values::specified::font::FontTag;
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-transitions/#animtype-repeatable-list>
|
/// <https://drafts.csswg.org/css-transitions/#animtype-repeatable-list>
|
||||||
pub trait RepeatableListAnimatable: Animate {}
|
pub trait RepeatableListAnimatable: Animate {}
|
||||||
|
@ -817,18 +815,16 @@ impl Into<FontStretch> for f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def>
|
/// <https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def>
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl Animate for FontVariationSettings {
|
impl Animate for FontVariationSettings {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
FontSettingTagIter::new(self, other)?
|
FontSettingTagIter::new(self, other)?
|
||||||
.map(|r| r.and_then(|(st, ot)| st.animate(&ot, procedure)))
|
.map(|r| r.and_then(|(st, ot)| st.animate(&ot, procedure)))
|
||||||
.collect::<Result<Vec<FontSettingTag>, ()>>()
|
.collect::<Result<Vec<ComputedVariationValue>, ()>>()
|
||||||
.map(GenericFontSettings::Tag)
|
.map(|v| GenericFontSettings(v.into_boxed_slice()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl ComputeSquaredDistance for FontVariationSettings {
|
impl ComputeSquaredDistance for FontVariationSettings {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
|
@ -838,7 +834,6 @@ impl ComputeSquaredDistance for FontVariationSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl ToAnimatedZero for FontVariationSettings {
|
impl ToAnimatedZero for FontVariationSettings {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
|
@ -846,45 +841,17 @@ impl ToAnimatedZero for FontVariationSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
type ComputedVariationValue = VariationValue<Number>;
|
||||||
impl Animate for FontSettingTag {
|
|
||||||
#[inline]
|
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
|
||||||
if self.tag != other.tag {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
let value = self.value.animate(&other.value, procedure)?;
|
|
||||||
Ok(FontSettingTag {
|
|
||||||
tag: self.tag,
|
|
||||||
value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
// FIXME: Could do a rename, this is only used for font variations.
|
||||||
impl ComputeSquaredDistance for FontSettingTag {
|
|
||||||
#[inline]
|
|
||||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
|
||||||
if self.tag != other.tag {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
self.value.compute_squared_distance(&other.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
type FontSettingTag = GenericFontSettingTag<FontSettingTagFloat>;
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
struct FontSettingTagIterState<'a> {
|
struct FontSettingTagIterState<'a> {
|
||||||
tags: Vec<(&'a FontSettingTag)>,
|
tags: Vec<(&'a ComputedVariationValue)>,
|
||||||
index: usize,
|
index: usize,
|
||||||
prev_tag: FontTag,
|
prev_tag: FontTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl<'a> FontSettingTagIterState<'a> {
|
impl<'a> FontSettingTagIterState<'a> {
|
||||||
fn new(tags: Vec<(&'a FontSettingTag)>) -> FontSettingTagIterState<'a> {
|
fn new(tags: Vec<<&'a ComputedVariationValue>) -> FontSettingTagIterState<'a> {
|
||||||
FontSettingTagIterState {
|
FontSettingTagIterState {
|
||||||
index: tags.len(),
|
index: tags.len(),
|
||||||
tags,
|
tags,
|
||||||
|
@ -898,12 +865,13 @@ impl<'a> FontSettingTagIterState<'a> {
|
||||||
/// [CSS fonts level 4](https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-variation-settings)
|
/// [CSS fonts level 4](https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-variation-settings)
|
||||||
/// defines the animation of font-variation-settings as follows:
|
/// defines the animation of font-variation-settings as follows:
|
||||||
///
|
///
|
||||||
/// Two declarations of font-feature-settings[sic] can be animated between if they are "like".
|
/// Two declarations of font-feature-settings[sic] can be animated between if
|
||||||
/// "Like" declarations are ones where the same set of properties appear (in any order).
|
/// they are "like". "Like" declarations are ones where the same set of
|
||||||
/// Because succesive[sic] duplicate properties are applied instead of prior duplicate
|
/// properties appear (in any order). Because succesive[sic] duplicate
|
||||||
/// properties, two declarations can be "like" even if they have differing number of
|
/// properties are applied instead of prior duplicate properties, two
|
||||||
/// properties. If two declarations are "like" then animation occurs pairwise between
|
/// declarations can be "like" even if they have differing number of
|
||||||
/// corresponding values in the declarations.
|
/// properties. If two declarations are "like" then animation occurs pairwise
|
||||||
|
/// between corresponding values in the declarations.
|
||||||
///
|
///
|
||||||
/// In other words if we have the following lists:
|
/// In other words if we have the following lists:
|
||||||
///
|
///
|
||||||
|
@ -915,9 +883,10 @@ impl<'a> FontSettingTagIterState<'a> {
|
||||||
/// "wdth" 5, "wght" 2
|
/// "wdth" 5, "wght" 2
|
||||||
/// "wght" 4, "wdth" 10
|
/// "wght" 4, "wdth" 10
|
||||||
///
|
///
|
||||||
/// This iterator supports this by sorting the two lists, then iterating them in reverse,
|
/// This iterator supports this by sorting the two lists, then iterating them in
|
||||||
/// and skipping entries with repeated tag names. It will return Some(Err()) if it reaches the
|
/// reverse, and skipping entries with repeated tag names. It will return
|
||||||
/// end of one list before the other, or if the tag names do not match.
|
/// Some(Err()) if it reaches the end of one list before the other, or if the
|
||||||
|
/// tag names do not match.
|
||||||
///
|
///
|
||||||
/// For the above example, this iterator would return:
|
/// For the above example, this iterator would return:
|
||||||
///
|
///
|
||||||
|
@ -925,37 +894,33 @@ impl<'a> FontSettingTagIterState<'a> {
|
||||||
/// Some(Ok("wdth" 5, "wdth" 10))
|
/// Some(Ok("wdth" 5, "wdth" 10))
|
||||||
/// None
|
/// None
|
||||||
///
|
///
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
struct FontSettingTagIter<'a> {
|
struct FontSettingTagIter<'a> {
|
||||||
a_state: FontSettingTagIterState<'a>,
|
a_state: FontSettingTagIterState<'a>,
|
||||||
b_state: FontSettingTagIterState<'a>,
|
b_state: FontSettingTagIterState<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl<'a> FontSettingTagIter<'a> {
|
impl<'a> FontSettingTagIter<'a> {
|
||||||
fn new(
|
fn new(
|
||||||
a_settings: &'a FontVariationSettings,
|
a_settings: &'a FontVariationSettings,
|
||||||
b_settings: &'a FontVariationSettings,
|
b_settings: &'a FontVariationSettings,
|
||||||
) -> Result<FontSettingTagIter<'a>, ()> {
|
) -> Result<FontSettingTagIter<'a>, ()> {
|
||||||
if let (&GenericFontSettings::Tag(ref a_tags), &GenericFontSettings::Tag(ref b_tags)) = (a_settings, b_settings)
|
if a_settings.0.is_empty() || b_settings.0.is_empty() {
|
||||||
{
|
return Err(());
|
||||||
fn as_new_sorted_tags(tags: &Vec<FontSettingTag>) -> Vec<(&FontSettingTag)> {
|
}
|
||||||
|
fn as_new_sorted_tags(tags: &[ComputedVariationValue]) -> Vec<<&ComputedVariationValue> {
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
let mut sorted_tags: Vec<(&FontSettingTag)> = Vec::from_iter(tags.iter());
|
let mut sorted_tags = Vec::from_iter(tags.iter());
|
||||||
sorted_tags.sort_by_key(|k| k.tag.0);
|
sorted_tags.sort_by_key(|k| k.tag.0);
|
||||||
sorted_tags
|
sorted_tags
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(FontSettingTagIter {
|
Ok(FontSettingTagIter {
|
||||||
a_state: FontSettingTagIterState::new(as_new_sorted_tags(a_tags)),
|
a_state: FontSettingTagIterState::new(as_new_sorted_tags(&a_settings.0)),
|
||||||
b_state: FontSettingTagIterState::new(as_new_sorted_tags(b_tags)),
|
b_state: FontSettingTagIterState::new(as_new_sorted_tags(&b_settings.0)),
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_tag(state: &mut FontSettingTagIterState<'a>) -> Option<(&'a FontSettingTag)> {
|
fn next_tag(state: &mut FontSettingTagIterState<'a>) -> Option<<&'a ComputedVariationValue> {
|
||||||
if state.index == 0 {
|
if state.index == 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -971,11 +936,10 @@ impl<'a> FontSettingTagIter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl<'a> Iterator for FontSettingTagIter<'a> {
|
impl<'a> Iterator for FontSettingTagIter<'a> {
|
||||||
type Item = Result<(&'a FontSettingTag, &'a FontSettingTag), ()>;
|
type Item = Result<(&'a ComputedVariationValue, &'a ComputedVariationValue), ()>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Result<(&'a FontSettingTag, &'a FontSettingTag), ()>> {
|
fn next(&mut self) -> Option<Result<(&'a ComputedVariationValue, &'a ComputedVariationValue), ()>> {
|
||||||
match (
|
match (
|
||||||
FontSettingTagIter::next_tag(&mut self.a_state),
|
FontSettingTagIter::next_tag(&mut self.a_state),
|
||||||
FontSettingTagIter::next_tag(&mut self.b_state),
|
FontSettingTagIter::next_tag(&mut self.b_state),
|
||||||
|
|
|
@ -144,7 +144,6 @@ ${helpers.predefined_type("font-feature-settings",
|
||||||
initial_value="computed::FontFeatureSettings::normal()",
|
initial_value="computed::FontFeatureSettings::normal()",
|
||||||
initial_specified_value="specified::FontFeatureSettings::normal()",
|
initial_specified_value="specified::FontFeatureSettings::normal()",
|
||||||
extra_prefixes="moz",
|
extra_prefixes="moz",
|
||||||
boxed=True,
|
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings")}
|
spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings")}
|
||||||
|
@ -157,10 +156,10 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
|
||||||
%>
|
%>
|
||||||
|
|
||||||
${helpers.predefined_type("font-variation-settings",
|
${helpers.predefined_type("font-variation-settings",
|
||||||
"FontVariantSettings",
|
"FontVariationSettings",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
gecko_pref="layout.css.font-variations.enabled",
|
gecko_pref="layout.css.font-variations.enabled",
|
||||||
initial_value="specified::FontVariantSettings::normal()",
|
initial_value="computed::FontVariationSettings::normal()",
|
||||||
animation_value_type="ComputedValue",
|
animation_value_type="ComputedValue",
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
spec="${variation_spec}")}
|
spec="${variation_spec}")}
|
||||||
|
|
|
@ -22,13 +22,13 @@ use std::slice;
|
||||||
use style_traits::{CssWriter, ParseError, ToCss};
|
use style_traits::{CssWriter, ParseError, ToCss};
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||||
use values::computed::{Context, NonNegativeLength, ToComputedValue};
|
use values::computed::{Context, NonNegativeLength, ToComputedValue, Integer, Number};
|
||||||
use values::generics::font::{FontSettings, FontSettingTagInt};
|
use values::generics::font::{FontSettings, FeatureTagValue, VariationValue};
|
||||||
use values::specified::font as specified;
|
use values::specified::font as specified;
|
||||||
use values::specified::length::{FontBaseSize, NoCalcLength};
|
use values::specified::length::{FontBaseSize, NoCalcLength};
|
||||||
|
|
||||||
pub use values::computed::Length as MozScriptMinSize;
|
pub use values::computed::Length as MozScriptMinSize;
|
||||||
pub use values::specified::font::{XTextZoom, XLang, MozScriptSizeMultiplier, FontSynthesis, FontVariantSettings};
|
pub use values::specified::font::{XTextZoom, XLang, MozScriptSizeMultiplier, FontSynthesis};
|
||||||
|
|
||||||
/// As of CSS Fonts Module Level 3, only the following values are
|
/// As of CSS Fonts Module Level 3, only the following values are
|
||||||
/// valid: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
/// valid: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
||||||
|
@ -712,8 +712,11 @@ pub type FontVariantLigatures = specified::VariantLigatures;
|
||||||
/// Use VariantNumeric as computed type of FontVariantNumeric
|
/// Use VariantNumeric as computed type of FontVariantNumeric
|
||||||
pub type FontVariantNumeric = specified::VariantNumeric;
|
pub type FontVariantNumeric = specified::VariantNumeric;
|
||||||
|
|
||||||
/// Use FontSettings as computed type of FontFeatureSettings
|
/// Use FontSettings as computed type of FontFeatureSettings.
|
||||||
pub type FontFeatureSettings = FontSettings<FontSettingTagInt>;
|
pub type FontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
|
||||||
|
|
||||||
|
/// The computed value for font-variation-settings.
|
||||||
|
pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
|
||||||
|
|
||||||
/// font-language-override can only have a single three-letter
|
/// font-language-override can only have a single three-letter
|
||||||
/// OpenType "language system" tag, so we should be able to compute
|
/// OpenType "language system" tag, so we should be able to compute
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub use self::background::{BackgroundSize, BackgroundRepeat};
|
||||||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||||
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
||||||
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
|
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
|
||||||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
|
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
|
||||||
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
||||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
||||||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
||||||
|
|
|
@ -4,128 +4,116 @@
|
||||||
|
|
||||||
//! Generic types for font stuff.
|
//! Generic types for font stuff.
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
use num_traits::One;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError, ToCss, StyleParseErrorKind};
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, ParseError, ToCss};
|
||||||
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
use values::specified::font::FontTag;
|
use values::specified::font::FontTag;
|
||||||
|
|
||||||
/// A settings tag, defined by a four-character tag and a setting value
|
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
||||||
///
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
/// For font-feature-settings, this is a tag and an integer, for
|
pub struct FeatureTagValue<Integer> {
|
||||||
/// font-variation-settings this is a tag and a float.
|
/// A four-character tag, packed into a u32 (one byte per character).
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
|
||||||
pub struct FontSettingTag<T> {
|
|
||||||
/// A four-character tag, packed into a u32 (one byte per character)
|
|
||||||
pub tag: FontTag,
|
pub tag: FontTag,
|
||||||
/// The actual value.
|
/// The actual value.
|
||||||
pub value: T,
|
pub value: Integer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> OneOrMoreSeparated for FontSettingTag<T> {
|
impl<Integer> ToCss for FeatureTagValue<Integer>
|
||||||
type S = Comma;
|
where
|
||||||
}
|
Integer: One + ToCss + PartialEq,
|
||||||
|
{
|
||||||
impl<T: Parse> Parse for FontSettingTag<T> {
|
|
||||||
/// <https://www.w3.org/TR/css-fonts-3/#propdef-font-feature-settings>
|
|
||||||
/// <https://drafts.csswg.org/css-fonts-4/#low-level-font-variation->
|
|
||||||
/// settings-control-the-font-variation-settings-property
|
|
||||||
/// <string> [ on | off | <integer> ]
|
|
||||||
/// <string> <number>
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
let tag = FontTag::parse(context, input)?;
|
|
||||||
let value = T::parse(context, input)?;
|
|
||||||
|
|
||||||
Ok(Self { tag, value })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A font settings value for font-variation-settings or font-feature-settings
|
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
|
||||||
pub enum FontSettings<T> {
|
|
||||||
/// No settings (default)
|
|
||||||
Normal,
|
|
||||||
/// Set of settings
|
|
||||||
Tag(Vec<FontSettingTag<T>>)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl <T> FontSettings<T> {
|
|
||||||
#[inline]
|
|
||||||
/// Default value of font settings as `normal`
|
|
||||||
pub fn normal() -> Self {
|
|
||||||
FontSettings::Normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Parse> Parse for FontSettings<T> {
|
|
||||||
/// <https://www.w3.org/TR/css-fonts-3/#propdef-font-feature-settings>
|
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
|
||||||
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
|
||||||
return Ok(FontSettings::Normal);
|
|
||||||
}
|
|
||||||
Vec::parse(context, input).map(FontSettings::Tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An integer that can also parse "on" and "off",
|
|
||||||
/// for font-feature-settings
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
|
||||||
pub struct FontSettingTagInt(pub u32);
|
|
||||||
|
|
||||||
/// A number value to be used for font-variation-settings.
|
|
||||||
///
|
|
||||||
/// FIXME(emilio): The spec only says <integer>, so we should be able to reuse
|
|
||||||
/// the other code:
|
|
||||||
///
|
|
||||||
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-variation-settings
|
|
||||||
#[cfg_attr(feature = "gecko", derive(Animate, ComputeSquaredDistance))]
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
|
||||||
pub struct FontSettingTagFloat(pub f32);
|
|
||||||
|
|
||||||
impl ToCss for FontSettingTagInt {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
match self.0 {
|
self.tag.to_css(dest)?;
|
||||||
1 => Ok(()),
|
// Don't serialize the default value.
|
||||||
0 => dest.write_str("off"),
|
if self.value != Integer::one() {
|
||||||
x => x.to_css(dest),
|
dest.write_char(' ')?;
|
||||||
|
self.value.to_css(dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for FontSettingTagInt {
|
/// Variation setting for a single feature, see:
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
///
|
||||||
// FIXME(emilio): This doesn't handle calc properly.
|
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||||
if let Ok(value) = input.try(|input| input.expect_integer()) {
|
#[derive(Animate, Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
// handle integer, throw if it is negative
|
pub struct VariationValue<Number> {
|
||||||
if value >= 0 {
|
/// A four-character tag, packed into a u32 (one byte per character).
|
||||||
Ok(FontSettingTagInt(value as u32))
|
#[animation(constant)]
|
||||||
} else {
|
pub tag: FontTag,
|
||||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
/// The actual value.
|
||||||
|
pub value: Number,
|
||||||
}
|
}
|
||||||
} else if let Ok(_) = input.try(|input| input.expect_ident_matching("on")) {
|
|
||||||
// on is an alias for '1'
|
impl<Number> ComputeSquaredDistance for VariationValue<Number>
|
||||||
Ok(FontSettingTagInt(1))
|
where
|
||||||
} else if let Ok(_) = input.try(|input| input.expect_ident_matching("off")) {
|
Number: ComputeSquaredDistance,
|
||||||
// off is an alias for '0'
|
{
|
||||||
Ok(FontSettingTagInt(0))
|
#[inline]
|
||||||
} else {
|
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||||
// empty value is an alias for '1'
|
if self.tag != other.tag {
|
||||||
Ok(FontSettingTagInt(1))
|
return Err(());
|
||||||
}
|
}
|
||||||
|
self.value.compute_squared_distance(&other.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for FontSettingTagFloat {
|
/// A value both for font-variation-settings and font-feature-settings.
|
||||||
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
// FIXME(emilio): Should handle calc() using Number::parse.
|
pub struct FontSettings<T>(pub Box<[T]>);
|
||||||
//
|
|
||||||
// Also why is this not in font.rs?
|
impl<T> FontSettings<T> {
|
||||||
input.expect_number().map(FontSettingTagFloat).map_err(|e| e.into())
|
/// Default value of font settings as `normal`.
|
||||||
|
#[inline]
|
||||||
|
pub fn normal() -> Self {
|
||||||
|
FontSettings(vec![].into_boxed_slice())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Parse> Parse for FontSettings<T> {
|
||||||
|
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-feature-settings
|
||||||
|
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||||
|
return Ok(Self::normal());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(FontSettings(
|
||||||
|
input.parse_comma_separated(|i| T::parse(context, i))?.into_boxed_slice()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ToCss> ToCss for FontSettings<T> {
|
||||||
|
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-feature-settings
|
||||||
|
/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: Write,
|
||||||
|
{
|
||||||
|
if self.0.is_empty() {
|
||||||
|
return dest.write_str("normal");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut first = true;
|
||||||
|
for item in self.0.iter() {
|
||||||
|
if !first {
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
item.to_css(dest)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue};
|
use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue};
|
||||||
use values::computed::font::{SingleFontFamily, FontFamilyList, FamilyName};
|
use values::computed::font::{SingleFontFamily, FontFamilyList, FamilyName};
|
||||||
use values::generics::font::{FontSettings, FontSettingTagFloat};
|
use values::generics::font::{FontSettings, FeatureTagValue, VariationValue};
|
||||||
use values::specified::{AllowQuirks, LengthOrPercentage, NoCalcLength, Number};
|
use values::specified::{AllowQuirks, Integer, LengthOrPercentage, NoCalcLength, Number};
|
||||||
use values::specified::length::{AU_PER_PT, AU_PER_PX, FontBaseSize};
|
use values::specified::length::{AU_PER_PT, AU_PER_PX, FontBaseSize};
|
||||||
|
|
||||||
const DEFAULT_SCRIPT_MIN_SIZE_PT: u32 = 8;
|
const DEFAULT_SCRIPT_MIN_SIZE_PT: u32 = 8;
|
||||||
|
@ -164,8 +164,8 @@ impl From<LengthOrPercentage> for FontSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specifies a prioritized list of font family names or generic family names.
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
/// Specifies a prioritized list of font family names or generic family names
|
|
||||||
pub enum FontFamily {
|
pub enum FontFamily {
|
||||||
/// List of `font-family`
|
/// List of `font-family`
|
||||||
Values(FontFamilyList),
|
Values(FontFamilyList),
|
||||||
|
@ -1709,13 +1709,15 @@ impl Parse for FontVariantNumeric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
/// This property provides low-level control over OpenType or TrueType font variations.
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
pub type SpecifiedFontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
|
||||||
/// Define initial settings that apply when the font defined
|
|
||||||
/// by an @font-face rule is rendered.
|
/// Define initial settings that apply when the font defined by an @font-face
|
||||||
|
/// rule is rendered.
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum FontFeatureSettings {
|
pub enum FontFeatureSettings {
|
||||||
/// Value of `FontSettings`
|
/// Value of `FontSettings`
|
||||||
Value(computed::FontFeatureSettings),
|
Value(SpecifiedFontFeatureSettings),
|
||||||
/// System font
|
/// System font
|
||||||
System(SystemFont)
|
System(SystemFont)
|
||||||
}
|
}
|
||||||
|
@ -1724,7 +1726,7 @@ impl FontFeatureSettings {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get default value of `font-feature-settings` as normal
|
/// Get default value of `font-feature-settings` as normal
|
||||||
pub fn normal() -> FontFeatureSettings {
|
pub fn normal() -> FontFeatureSettings {
|
||||||
FontFeatureSettings::Value(FontSettings::Normal)
|
FontFeatureSettings::Value(FontSettings::normal())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get `font-feature-settings` with system font
|
/// Get `font-feature-settings` with system font
|
||||||
|
@ -1745,12 +1747,12 @@ impl FontFeatureSettings {
|
||||||
impl ToComputedValue for FontFeatureSettings {
|
impl ToComputedValue for FontFeatureSettings {
|
||||||
type ComputedValue = computed::FontFeatureSettings;
|
type ComputedValue = computed::FontFeatureSettings;
|
||||||
|
|
||||||
fn to_computed_value(&self, _context: &Context) -> computed::FontFeatureSettings {
|
fn to_computed_value(&self, context: &Context) -> computed::FontFeatureSettings {
|
||||||
match *self {
|
match *self {
|
||||||
FontFeatureSettings::Value(ref v) => v.clone(),
|
FontFeatureSettings::Value(ref v) => v.to_computed_value(context),
|
||||||
FontFeatureSettings::System(_) => {
|
FontFeatureSettings::System(_) => {
|
||||||
#[cfg(feature = "gecko")] {
|
#[cfg(feature = "gecko")] {
|
||||||
_context.cached_system_font.as_ref().unwrap().font_feature_settings.clone()
|
context.cached_system_font.as_ref().unwrap().font_feature_settings.clone()
|
||||||
}
|
}
|
||||||
#[cfg(feature = "servo")] {
|
#[cfg(feature = "servo")] {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
@ -1760,7 +1762,7 @@ impl ToComputedValue for FontFeatureSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_computed_value(other: &computed::FontFeatureSettings) -> Self {
|
fn from_computed_value(other: &computed::FontFeatureSettings) -> Self {
|
||||||
FontFeatureSettings::Value(other.clone())
|
FontFeatureSettings::Value(ToComputedValue::from_computed_value(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1770,7 +1772,7 @@ impl Parse for FontFeatureSettings {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>
|
input: &mut Parser<'i, 't>
|
||||||
) -> Result<FontFeatureSettings, ParseError<'i>> {
|
) -> Result<FontFeatureSettings, ParseError<'i>> {
|
||||||
computed::FontFeatureSettings::parse(context, input).map(FontFeatureSettings::Value)
|
SpecifiedFontFeatureSettings::parse(context, input).map(FontFeatureSettings::Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2006,9 +2008,51 @@ impl ToCss for FontTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This property provides low-level control over OpenType or TrueType font
|
||||||
|
/// variations.
|
||||||
|
pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
|
||||||
|
|
||||||
|
fn parse_one_feature_value<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Integer, ParseError<'i>> {
|
||||||
|
if let Ok(integer) = input.try(|i| Integer::parse_non_negative(context, i)) {
|
||||||
|
return Ok(integer)
|
||||||
|
}
|
||||||
|
|
||||||
|
try_match_ident_ignore_ascii_case! { input,
|
||||||
|
"on" => Ok(Integer::new(1)),
|
||||||
|
"off" => Ok(Integer::new(0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for FeatureTagValue<Integer> {
|
||||||
|
/// https://drafts.csswg.org/css-fonts-4/#feature-tag-value
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
let tag = FontTag::parse(context, input)?;
|
||||||
|
let value = input.try(|i| parse_one_feature_value(context, i))
|
||||||
|
.unwrap_or_else(|_| Integer::new(1));
|
||||||
|
|
||||||
|
Ok(Self { tag, value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for VariationValue<Number> {
|
||||||
|
/// This is the `<string> <number>` part of the font-variation-settings
|
||||||
|
/// syntax.
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
let tag = FontTag::parse(context, input)?;
|
||||||
|
let value = Number::parse(context, input)?;
|
||||||
|
Ok(Self { tag, value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This property provides low-level control over OpenType or TrueType font variations.
|
|
||||||
pub type FontVariantSettings = FontSettings<FontSettingTagFloat>;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
/// text-zoom. Enable if true, disable if false
|
/// text-zoom. Enable if true, disable if false
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
use Namespace;
|
use Namespace;
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{Parser, Token, serialize_identifier};
|
use cssparser::{Parser, Token, serialize_identifier};
|
||||||
|
use num_traits::One;
|
||||||
use parser::{ParserContext, Parse};
|
use parser::{ParserContext, Parse};
|
||||||
use self::url::SpecifiedUrl;
|
use self::url::SpecifiedUrl;
|
||||||
#[allow(unused_imports)] use std::ascii::AsciiExt;
|
#[allow(unused_imports)] use std::ascii::AsciiExt;
|
||||||
|
@ -33,7 +34,7 @@ pub use self::background::{BackgroundRepeat, BackgroundSize};
|
||||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
||||||
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
|
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
|
||||||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
|
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
|
||||||
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
||||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
||||||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
||||||
|
@ -382,12 +383,28 @@ impl ToComputedValue for Opacity {
|
||||||
/// An specified `<integer>`, optionally coming from a `calc()` expression.
|
/// An specified `<integer>`, optionally coming from a `calc()` expression.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-values/#integers>
|
/// <https://drafts.csswg.org/css-values/#integers>
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, PartialOrd)]
|
||||||
pub struct Integer {
|
pub struct Integer {
|
||||||
value: CSSInteger,
|
value: CSSInteger,
|
||||||
was_calc: bool,
|
was_calc: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl One for Integer {
|
||||||
|
#[inline]
|
||||||
|
fn one() -> Self {
|
||||||
|
Self::new(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is not great, because it loses calc-ness, but it's necessary for One.
|
||||||
|
impl ::std::ops::Mul<Integer> for Integer {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, other: Self) -> Self {
|
||||||
|
Self::new(self.value * other.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Integer {
|
impl Integer {
|
||||||
/// Trivially constructs a new `Integer` value.
|
/// Trivially constructs a new `Integer` value.
|
||||||
pub fn new(val: CSSInteger) -> Self {
|
pub fn new(val: CSSInteger) -> Self {
|
||||||
|
@ -435,7 +452,7 @@ impl Integer {
|
||||||
pub fn parse_with_minimum<'i, 't>(
|
pub fn parse_with_minimum<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
min: i32
|
min: i32,
|
||||||
) -> Result<Integer, ParseError<'i>> {
|
) -> Result<Integer, ParseError<'i>> {
|
||||||
match Integer::parse(context, input) {
|
match Integer::parse(context, input) {
|
||||||
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
|
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
|
||||||
|
@ -498,10 +515,11 @@ impl ToCss for Integer {
|
||||||
pub type IntegerOrAuto = Either<Integer, Auto>;
|
pub type IntegerOrAuto = Either<Integer, Auto>;
|
||||||
|
|
||||||
impl IntegerOrAuto {
|
impl IntegerOrAuto {
|
||||||
#[allow(missing_docs)]
|
/// Parse `auto` or a positive integer.
|
||||||
pub fn parse_positive<'i, 't>(context: &ParserContext,
|
pub fn parse_positive<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>)
|
context: &ParserContext,
|
||||||
-> Result<IntegerOrAuto, ParseError<'i>> {
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<IntegerOrAuto, ParseError<'i>> {
|
||||||
match IntegerOrAuto::parse(context, input) {
|
match IntegerOrAuto::parse(context, input) {
|
||||||
Ok(Either::First(integer)) if integer.value() <= 0 => {
|
Ok(Either::First(integer)) if integer.value() <= 0 => {
|
||||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
|
|
|
@ -4727,10 +4727,11 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
) -> bool {
|
) -> bool {
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use self::nsCSSFontDesc::*;
|
use self::nsCSSFontDesc::*;
|
||||||
use style::computed_values::{font_feature_settings, font_stretch, font_style};
|
use style::computed_values::{font_stretch, font_style};
|
||||||
use style::font_face::{FontDisplay, FontWeight, Source};
|
use style::font_face::{FontDisplay, FontWeight, Source};
|
||||||
use style::properties::longhands::font_language_override;
|
use style::properties::longhands::font_language_override;
|
||||||
use style::values::computed::font::FamilyName;
|
use style::values::computed::font::FamilyName;
|
||||||
|
use style::values::specified::font::SpecifiedFontFeatureSettings;
|
||||||
|
|
||||||
let string = unsafe { (*value).to_string() };
|
let string = unsafe { (*value).to_string() };
|
||||||
let mut input = ParserInput::new(&string);
|
let mut input = ParserInput::new(&string);
|
||||||
|
@ -4779,7 +4780,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
eCSSFontDesc_Stretch / font_stretch::T,
|
eCSSFontDesc_Stretch / font_stretch::T,
|
||||||
eCSSFontDesc_Src / Vec<Source>,
|
eCSSFontDesc_Src / Vec<Source>,
|
||||||
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
||||||
eCSSFontDesc_FontFeatureSettings / font_feature_settings::T,
|
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
|
||||||
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
||||||
eCSSFontDesc_Display / FontDisplay,
|
eCSSFontDesc_Display / FontDisplay,
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue