style: Move font-feature-settings outside of mako

This commit is contained in:
CYBAI 2017-11-20 11:26:09 +08:00
parent db5fb74a4d
commit 70033edccd
5 changed files with 91 additions and 75 deletions

View file

@ -11,6 +11,7 @@ use style_traits::ToCss;
use values::CSSFloat;
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::{Context, NonNegativeLength, ToComputedValue};
use values::generics::{FontSettings, FontSettingTagInt};
use values::specified::font as specified;
use values::specified::length::{FontBaseSize, NoCalcLength};
@ -286,6 +287,17 @@ pub type FontVariantLigatures = specified::VariantLigatures;
/// Use VariantNumeric as computed type of FontVariantNumeric
pub type FontVariantNumeric = specified::VariantNumeric;
/// Use FontSettings as computed type of FontFeatureSettings
pub type FontFeatureSettings = FontSettings<FontSettingTagInt>;
impl FontFeatureSettings {
#[inline]
/// Default value of `font-feature-settings` as `normal`
pub fn normal() -> FontFeatureSettings {
FontSettings::Normal
}
}
/// font-language-override can only have a single three-letter
/// OpenType "language system" tag, so we should be able to compute
/// it and store it as a 32-bit integer

View file

@ -38,7 +38,8 @@ pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};

View file

@ -1573,6 +1573,71 @@ impl Parse for FontVariantNumeric {
}
}
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
/// Define initial settings that apply when the font defined
/// by an @font-face rule is rendered.
pub enum FontFeatureSettings {
/// Value of `FontSettings`
Value(computed::FontFeatureSettings),
/// System font
System(SystemFont)
}
impl FontFeatureSettings {
#[inline]
/// Get default value of `font-feature-settings` as normal
pub fn normal() -> FontFeatureSettings {
FontFeatureSettings::Value(FontSettings::Normal)
}
/// Get `font-feature-settings` with system font
pub fn system_font(f: SystemFont) -> Self {
FontFeatureSettings::System(f)
}
/// Get system font
pub fn get_system(&self) -> Option<SystemFont> {
if let FontFeatureSettings::System(s) = *self {
Some(s)
} else {
None
}
}
}
impl ToComputedValue for FontFeatureSettings {
type ComputedValue = computed::FontFeatureSettings;
fn to_computed_value(&self, _context: &Context) -> computed::FontFeatureSettings {
match *self {
FontFeatureSettings::Value(ref v) => v.clone(),
FontFeatureSettings::System(_) => {
#[cfg(feature = "gecko")] {
_context.cached_system_font.as_ref().unwrap().font_feature_settings.clone()
}
#[cfg(feature = "servo")] {
unreachable!()
}
}
}
}
fn from_computed_value(other: &computed::FontFeatureSettings) -> Self {
FontFeatureSettings::Value(other.clone())
}
}
impl Parse for FontFeatureSettings {
/// normal | <feature-tag-value>#
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<FontFeatureSettings, ParseError<'i>> {
computed::FontFeatureSettings::parse(context, input).map(FontFeatureSettings::Value)
}
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
/// Whether user agents are allowed to synthesize bold or oblique font faces
/// when a font family lacks bold or italic faces

View file

@ -32,7 +32,8 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVariantAlternates};
pub use self::font::{FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, ScrollSnapType, VerticalAlign};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};