mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
Bug 1455358: Update font-style to css-fonts-4. r=xidorn
This patch is meant to be squashed with the following two. This is an initial strawman implementation that I wrote to unblock jwatt, cleanups and fixes follow. Note that this is style pretty much untested until jwatt's patches are ready, since Gecko doesn't understand the angle at all, but I expect the fixes to be minor. MozReview-Commit-ID: 1Nq5DyCjaZe
This commit is contained in:
parent
5403bc5d9c
commit
5aeef4886f
@ -6,10 +6,6 @@
|
||||
//!
|
||||
//! [ff]: https://drafts.csswg.org/css-fonts/#at-font-face-rule
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
use computed_values::font_style;
|
||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||
use cssparser::{CowRcStr, SourceLocation};
|
||||
#[cfg(feature = "gecko")]
|
||||
@ -30,6 +26,9 @@ use values::computed::font::FamilyName;
|
||||
use values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::font::FontStyle as SpecifiedFontStyle;
|
||||
use values::specified::Angle;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A source for a font-face rule.
|
||||
@ -130,6 +129,62 @@ impl Parse for FontStretch {
|
||||
}
|
||||
}
|
||||
|
||||
/// The font-style descriptor:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-style
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum FontStyle {
|
||||
Normal,
|
||||
Italic,
|
||||
Oblique(Angle, Angle),
|
||||
}
|
||||
|
||||
impl Parse for FontStyle {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let style = SpecifiedFontStyle::parse(context, input)?;
|
||||
Ok(match style {
|
||||
SpecifiedFontStyle::Normal => FontStyle::Normal,
|
||||
SpecifiedFontStyle::Italic => FontStyle::Italic,
|
||||
SpecifiedFontStyle::Oblique(angle) => {
|
||||
let second_angle = input.try(|input| {
|
||||
SpecifiedFontStyle::parse_angle(context, input)
|
||||
}).unwrap_or_else(|_| angle.clone());
|
||||
|
||||
FontStyle::Oblique(angle, second_angle)
|
||||
}
|
||||
SpecifiedFontStyle::System(..) => unreachable!(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for FontStyle {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
FontStyle::Normal => dest.write_str("normal"),
|
||||
FontStyle::Italic => dest.write_str("italic"),
|
||||
FontStyle::Oblique(ref first, ref second) => {
|
||||
dest.write_str("oblique")?;
|
||||
if *first != SpecifiedFontStyle::default_angle() || first != second {
|
||||
dest.write_char(' ')?;
|
||||
first.to_css(dest)?;
|
||||
}
|
||||
if first != second {
|
||||
dest.write_char(' ')?;
|
||||
second.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse the block inside a `@font-face` rule.
|
||||
///
|
||||
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
||||
@ -407,7 +462,7 @@ font_face_descriptors! {
|
||||
]
|
||||
optional descriptors = [
|
||||
/// The style of this font face.
|
||||
"font-style" style / mStyle: font_style::T,
|
||||
"font-style" style / mStyle: FontStyle,
|
||||
|
||||
/// The weight of this font face.
|
||||
"font-weight" weight / mWeight: FontWeight,
|
||||
|
@ -5,10 +5,9 @@
|
||||
//! Bindings for CSS Rule objects
|
||||
|
||||
use byteorder::{BigEndian, WriteBytesExt};
|
||||
use computed_values::font_style::T as ComputedFontStyle;
|
||||
use counter_style::{self, CounterBound};
|
||||
use cssparser::UnicodeRange;
|
||||
use font_face::{FontDisplay, FontWeight, FontStretch, Source};
|
||||
use font_face::{FontDisplay, FontWeight, FontStretch, FontStyle, Source};
|
||||
use gecko_bindings::structs::{self, nsCSSValue};
|
||||
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
|
||||
use properties::longhands::font_language_override;
|
||||
@ -17,6 +16,7 @@ use values::computed::font::FamilyName;
|
||||
use values::generics::font::FontTag;
|
||||
use values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
|
||||
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||
use values::specified::font::FontStyle as SpecifiedFontStyle;
|
||||
|
||||
impl<'a> ToNsCssValue for &'a FamilyName {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
@ -114,6 +114,24 @@ macro_rules! descriptor_range_conversion {
|
||||
descriptor_range_conversion!(FontWeight);
|
||||
descriptor_range_conversion!(FontStretch);
|
||||
|
||||
impl<'a> ToNsCssValue for &'a FontStyle {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
match *self {
|
||||
FontStyle::Normal => nscssvalue.set_normal(),
|
||||
FontStyle::Italic => nscssvalue.set_enum(structs::NS_FONT_STYLE_ITALIC as i32),
|
||||
FontStyle::Oblique(ref first, ref second) => {
|
||||
let mut a = nsCSSValue::null();
|
||||
let mut b = nsCSSValue::null();
|
||||
|
||||
a.set_angle(SpecifiedFontStyle::compute_angle(first));
|
||||
b.set_angle(SpecifiedFontStyle::compute_angle(second));
|
||||
|
||||
nscssvalue.set_pair(&a, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToNsCssValue for &'a font_language_override::SpecifiedValue {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
match *self {
|
||||
@ -127,34 +145,6 @@ impl<'a> ToNsCssValue for &'a font_language_override::SpecifiedValue {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! map_enum {
|
||||
(
|
||||
$(
|
||||
$ty:ident {
|
||||
$($servo:ident => $gecko:ident,)+
|
||||
}
|
||||
)+
|
||||
) => {
|
||||
$(
|
||||
impl<'a> ToNsCssValue for &'a $ty {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_enum(match *self {
|
||||
$( $ty::$servo => structs::$gecko as i32, )+
|
||||
})
|
||||
}
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
map_enum! {
|
||||
ComputedFontStyle {
|
||||
Normal => NS_FONT_STYLE_NORMAL,
|
||||
Italic => NS_FONT_STYLE_ITALIC,
|
||||
Oblique => NS_FONT_STYLE_OBLIQUE,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToNsCssValue for &'a Vec<Source> {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
let src_len = self.iter().fold(0, |acc, src| {
|
||||
|
@ -2614,7 +2614,6 @@ fn static_assert() {
|
||||
unsafe { bindings::Gecko_FontStretch_SetFloat(&mut self.gecko.mFont.stretch, (v.0).0) };
|
||||
}
|
||||
${impl_simple_copy('font_stretch', 'mFont.stretch')}
|
||||
|
||||
pub fn clone_font_stretch(&self) -> longhands::font_stretch::computed_value::T {
|
||||
use values::computed::Percentage;
|
||||
use values::generics::NonNegative;
|
||||
@ -2625,6 +2624,21 @@ fn static_assert() {
|
||||
NonNegative(Percentage(stretch))
|
||||
}
|
||||
|
||||
pub fn set_font_style(&mut self, v: longhands::font_style::computed_value::T) {
|
||||
use values::computed::font::FontStyle;
|
||||
self.gecko.mFont.style = match v {
|
||||
FontStyle::Normal => structs::NS_STYLE_FONT_STYLE_NORMAL,
|
||||
FontStyle::Italic => structs::NS_STYLE_FONT_STYLE_ITALIC,
|
||||
// FIXME(emilio): Honor the angle.
|
||||
FontStyle::Oblique(ref _angle) => structs::NS_STYLE_FONT_STYLE_OBLIQUE,
|
||||
} as u8;
|
||||
}
|
||||
${impl_simple_copy('font_style', 'mFont.style')}
|
||||
pub fn clone_font_style(&self) -> longhands::font_style::computed_value::T {
|
||||
use values::computed::font::FontStyle;
|
||||
FontStyle::from_gecko(self.gecko.mFont.style)
|
||||
}
|
||||
|
||||
${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}
|
||||
|
||||
pub fn set_font_size_adjust(&mut self, v: longhands::font_size_adjust::computed_value::T) {
|
||||
|
@ -15,15 +15,16 @@ ${helpers.predefined_type("font-family",
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-family",
|
||||
servo_restyle_damage="rebuild_and_reflow")}
|
||||
|
||||
${helpers.single_keyword_system(
|
||||
${helpers.predefined_type(
|
||||
"font-style",
|
||||
"normal italic oblique",
|
||||
gecko_constant_prefix="NS_FONT_STYLE",
|
||||
gecko_ffi_name="mFont.style",
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
|
||||
"FontStyle",
|
||||
initial_value="computed::FontStyle::Normal",
|
||||
initial_specified_value="specified::FontStyle::Normal",
|
||||
# FIXME(emilio): This won't handle clamping correctly.
|
||||
animation_value_type="ComputedValue",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
animation_value_type="discrete",
|
||||
servo_restyle_damage="rebuild_and_reflow"
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
|
||||
servo_restyle_damage="rebuild_and_reflow",
|
||||
)}
|
||||
|
||||
<% font_variant_caps_custom_consts= { "small-caps": "SMALLCAPS",
|
||||
@ -289,12 +290,11 @@ ${helpers.predefined_type("-x-text-zoom",
|
||||
-moz-window -moz-document -moz-workspace -moz-desktop
|
||||
-moz-info -moz-dialog -moz-button -moz-pull-down-menu
|
||||
-moz-list -moz-field""".split()
|
||||
kw_font_props = """font_style font_variant_caps
|
||||
kw_font_props = """font_variant_caps
|
||||
font_kerning font_variant_position font_variant_ligatures
|
||||
font_variant_east_asian font_variant_numeric
|
||||
font_optical_sizing""".split()
|
||||
kw_cast = """font_style font_variant_caps
|
||||
font_kerning font_variant_position
|
||||
kw_cast = """font_variant_caps font_kerning font_variant_position
|
||||
font_optical_sizing""".split()
|
||||
%>
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToCss)]
|
||||
@ -330,7 +330,7 @@ ${helpers.predefined_type("-x-text-zoom",
|
||||
use gecko_bindings::structs::{LookAndFeel_FontID, nsFont};
|
||||
use std::mem;
|
||||
use values::computed::Percentage;
|
||||
use values::computed::font::{FontSize, FontFamilyList};
|
||||
use values::computed::font::{FontSize, FontStyle, FontFamilyList};
|
||||
use values::generics::NonNegative;
|
||||
|
||||
let id = match *self {
|
||||
@ -352,6 +352,7 @@ ${helpers.predefined_type("-x-text-zoom",
|
||||
}
|
||||
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||
let font_stretch = NonNegative(Percentage(system.stretch as f32));
|
||||
let font_style = FontStyle::from_gecko(system.style);
|
||||
let ret = ComputedSystemFont {
|
||||
font_family: longhands::font_family::computed_value::T(
|
||||
FontFamilyList(
|
||||
@ -359,11 +360,12 @@ ${helpers.predefined_type("-x-text-zoom",
|
||||
)
|
||||
),
|
||||
font_size: FontSize {
|
||||
size: Au(system.size).into(),
|
||||
keyword_info: None
|
||||
size: Au(system.size).into(),
|
||||
keyword_info: None
|
||||
},
|
||||
font_weight,
|
||||
font_stretch,
|
||||
font_style,
|
||||
font_size_adjust: longhands::font_size_adjust::computed_value
|
||||
::T::from_gecko_adjust(system.sizeAdjust),
|
||||
% for kwprop in kw_font_props:
|
||||
|
@ -363,8 +363,6 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
if self.style.get_font().clone__moz_math_variant() != MozMathVariant::None {
|
||||
let font_style = self.style.mutate_font();
|
||||
// Sadly we don't have a nice name for the computed value
|
||||
// of "font-weight: normal".
|
||||
font_style.set_font_weight(FontWeight::normal());
|
||||
font_style.set_font_style(FontStyle::Normal);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use std::slice;
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
use values::CSSFloat;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::{Context, Integer, NonNegativeLength, Number, ToComputedValue};
|
||||
use values::computed::{Angle, Context, Integer, NonNegativeLength, Number, ToComputedValue};
|
||||
use values::generics::font::{FeatureTagValue, FontSettings};
|
||||
use values::generics::font::{KeywordInfo as GenericKeywordInfo, VariationValue};
|
||||
use values::specified::font::{self as specified, MIN_FONT_WEIGHT, MAX_FONT_WEIGHT};
|
||||
@ -829,3 +829,68 @@ impl ToComputedValue for specified::MozScriptLevel {
|
||||
specified::MozScriptLevel::MozAbsolute(*other as i32)
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of `font-style`.
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
|
||||
PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum FontStyle {
|
||||
#[animation(error)]
|
||||
Normal,
|
||||
#[animation(error)]
|
||||
Italic,
|
||||
// FIXME(emilio): This needs to clamp really.
|
||||
Oblique(Angle),
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FontStyle {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
use num_traits::Zero;
|
||||
Ok(FontStyle::Oblique(Angle::zero()))
|
||||
}
|
||||
}
|
||||
|
||||
impl FontStyle {
|
||||
/// The default angle for font-style: oblique. This is 20deg per spec:
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
|
||||
pub fn default_angle() -> Angle {
|
||||
Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES)
|
||||
}
|
||||
|
||||
|
||||
/// Get the font style from Gecko's nsFont struct.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn from_gecko(kw: u8) -> Self {
|
||||
use gecko_bindings::structs;
|
||||
|
||||
match kw as u32 {
|
||||
structs::NS_STYLE_FONT_STYLE_NORMAL => FontStyle::Normal,
|
||||
structs::NS_STYLE_FONT_STYLE_ITALIC => FontStyle::Italic,
|
||||
// FIXME(emilio): Grab the angle when we honor it :)
|
||||
structs::NS_STYLE_FONT_STYLE_OBLIQUE => FontStyle::Oblique(Self::default_angle()),
|
||||
_ => unreachable!("Unknown font style"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for FontStyle {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
FontStyle::Normal => dest.write_str("normal"),
|
||||
FontStyle::Italic => dest.write_str("italic"),
|
||||
FontStyle::Oblique(ref angle) => {
|
||||
dest.write_str("oblique")?;
|
||||
if *angle != Self::default_angle() {
|
||||
dest.write_char(' ')?;
|
||||
angle.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ pub use self::background::{BackgroundRepeat, BackgroundSize};
|
||||
pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
|
||||
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontVariantAlternates, FontWeight};
|
||||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle, FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
|
||||
|
@ -41,13 +41,19 @@ impl ToCss for Angle {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(emilio): Probably computed angles shouldn't preserve the unit and
|
||||
// should serialize to degrees per:
|
||||
//
|
||||
// https://drafts.csswg.org/css-values/#compat
|
||||
impl ToComputedValue for Angle {
|
||||
type ComputedValue = ComputedAngle;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue {
|
||||
self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
Angle {
|
||||
value: *computed,
|
||||
@ -89,6 +95,12 @@ impl Angle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this specified angle came from a `calc()` expression.
|
||||
#[inline]
|
||||
pub fn was_calc(&self) -> bool {
|
||||
self.was_calc
|
||||
}
|
||||
|
||||
/// Returns the amount of radians this angle represents.
|
||||
#[inline]
|
||||
pub fn radians(self) -> f32 {
|
||||
|
@ -17,13 +17,13 @@ use properties::longhands::system_font::SystemFont;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
use values::CustomIdent;
|
||||
use values::computed::Percentage as ComputedPercentage;
|
||||
use values::computed::{Angle as ComputedAngle, Percentage as ComputedPercentage};
|
||||
use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue};
|
||||
use values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily};
|
||||
use values::generics::NonNegative;
|
||||
use values::generics::font::{FeatureTagValue, FontSettings, FontTag};
|
||||
use values::generics::font::{KeywordInfo as GenericKeywordInfo, KeywordSize, VariationValue};
|
||||
use values::specified::{AllowQuirks, Integer, LengthOrPercentage, NoCalcLength, Number, Percentage};
|
||||
use values::specified::{AllowQuirks, Angle, Integer, LengthOrPercentage, NoCalcLength, Number, Percentage};
|
||||
use values::specified::length::{FontBaseSize, AU_PER_PT, AU_PER_PX};
|
||||
|
||||
const DEFAULT_SCRIPT_MIN_SIZE_PT: u32 = 8;
|
||||
@ -191,6 +191,166 @@ impl Parse for AbsoluteFontWeight {
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `font-style` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#font-style-prop
|
||||
///
|
||||
/// FIXME(emilio): It'd be nice to share more code with computed::FontStyle,
|
||||
/// except the system font stuff makes it kind of a pain.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum FontStyle {
|
||||
Normal,
|
||||
Italic,
|
||||
Oblique(Angle),
|
||||
System(SystemFont),
|
||||
}
|
||||
|
||||
impl ToComputedValue for FontStyle {
|
||||
type ComputedValue = computed::FontStyle;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
FontStyle::Normal => computed::FontStyle::Normal,
|
||||
FontStyle::Italic => computed::FontStyle::Italic,
|
||||
FontStyle::Oblique(ref angle) => {
|
||||
computed::FontStyle::Oblique(angle.to_computed_value(context))
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
FontStyle::System(..) => context
|
||||
.cached_system_font
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.font_style
|
||||
.clone(),
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
FontStyle::System(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
computed::FontStyle::Normal => FontStyle::Normal,
|
||||
computed::FontStyle::Italic => FontStyle::Italic,
|
||||
computed::FontStyle::Oblique(ref angle) => {
|
||||
FontStyle::Oblique(Angle::from_computed_value(angle))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The default angle for `font-style: oblique`.
|
||||
///
|
||||
/// NOTE(emilio): As of right now this diverges from the spec, which specifies
|
||||
/// 20, because it's not updated yet to account for the resolution in:
|
||||
///
|
||||
/// https://github.com/w3c/csswg-drafts/issues/2295
|
||||
pub const DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES: f32 = 14.;
|
||||
|
||||
/// From https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle:
|
||||
///
|
||||
/// Values less than -90deg or values greater than 90deg are
|
||||
/// invalid and are treated as parse errors.
|
||||
///
|
||||
/// The maximum angle value that `font-style: oblique` should compute to.
|
||||
pub const FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES: f32 = 90.;
|
||||
|
||||
/// The minimum angle value that `font-style: oblique` should compute to.
|
||||
pub const FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES: f32 = -90.;
|
||||
|
||||
impl FontStyle {
|
||||
/// More system font copy-pasta.
|
||||
pub fn system_font(f: SystemFont) -> Self {
|
||||
FontStyle::System(f)
|
||||
}
|
||||
|
||||
/// Retreive a SystemFont from FontStyle.
|
||||
pub fn get_system(&self) -> Option<SystemFont> {
|
||||
if let FontStyle::System(s) = *self {
|
||||
Some(s)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a clamped angle from a specified Angle.
|
||||
pub fn compute_angle(angle: &Angle) -> ComputedAngle {
|
||||
ComputedAngle::Deg(
|
||||
angle.degrees()
|
||||
.max(FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES)
|
||||
.min(FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES)
|
||||
)
|
||||
}
|
||||
|
||||
/// Parse a suitable angle for font-style: oblique.
|
||||
pub fn parse_angle<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Angle, ParseError<'i>> {
|
||||
let angle = Angle::parse(context, input)?;
|
||||
if angle.was_calc() {
|
||||
return Ok(angle);
|
||||
}
|
||||
|
||||
let degrees = angle.degrees();
|
||||
if degrees < FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES ||
|
||||
degrees > FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES
|
||||
{
|
||||
return Err(input.new_custom_error(
|
||||
StyleParseErrorKind::UnspecifiedError
|
||||
));
|
||||
}
|
||||
return Ok(angle)
|
||||
}
|
||||
|
||||
/// The default angle for `font-style: oblique`.
|
||||
pub fn default_angle() -> Angle {
|
||||
Angle::from_degrees(
|
||||
DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES,
|
||||
/* was_calc = */ false,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for FontStyle {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
FontStyle::Normal => dest.write_str("normal"),
|
||||
FontStyle::Italic => dest.write_str("italic"),
|
||||
FontStyle::Oblique(ref angle) => {
|
||||
dest.write_str("oblique")?;
|
||||
if *angle != Self::default_angle() {
|
||||
dest.write_char(' ')?;
|
||||
angle.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
FontStyle::System(ref s) => s.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for FontStyle {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(try_match_ident_ignore_ascii_case! { input,
|
||||
"normal" => FontStyle::Normal,
|
||||
"italic" => FontStyle::Italic,
|
||||
"oblique" => {
|
||||
let angle = input.try(|input| Self::parse_angle(context, input))
|
||||
.unwrap_or_else(|_| Self::default_angle());
|
||||
|
||||
FontStyle::Oblique(angle)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A value for the `font-stretch` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-fonts-4/#font-stretch-prop
|
||||
|
@ -35,7 +35,7 @@ pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing};
|
||||
pub use self::column::ColumnCount;
|
||||
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontVariantAlternates, FontWeight};
|
||||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle, FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
|
||||
|
@ -3820,7 +3820,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
|
||||
longhands::font_size::SpecifiedValue::from_html_size(value as u8)
|
||||
},
|
||||
FontStyle => {
|
||||
ToComputedValue::from_computed_value(&longhands::font_style::computed_value::T::from_gecko_keyword(value))
|
||||
ToComputedValue::from_computed_value(&longhands::font_style::computed_value::T::from_gecko(value as u8))
|
||||
},
|
||||
FontWeight => longhands::font_weight::SpecifiedValue::from_gecko_keyword(value),
|
||||
ListStyleType => Box::new(longhands::list_style_type::SpecifiedValue::from_gecko_keyword(value)),
|
||||
@ -5407,9 +5407,8 @@ pub extern "C" fn Servo_ParseFontShorthandForMatching(
|
||||
stretch: nsCSSValueBorrowedMut,
|
||||
weight: nsCSSValueBorrowedMut
|
||||
) -> bool {
|
||||
use style::properties::longhands::font_style;
|
||||
use style::properties::shorthands::font;
|
||||
use style::values::specified::font::{FontFamily, FontWeight};
|
||||
use style::values::specified::font::{FontFamily, FontWeight, FontStyle};
|
||||
|
||||
let string = unsafe { (*value).to_string() };
|
||||
let mut input = ParserInput::new(&string);
|
||||
@ -5434,10 +5433,14 @@ pub extern "C" fn Servo_ParseFontShorthandForMatching(
|
||||
FontFamily::Values(list) => family.set_move(list.0),
|
||||
FontFamily::System(_) => return false,
|
||||
}
|
||||
style.set_from(match font.font_style {
|
||||
font_style::SpecifiedValue::Keyword(ref kw) => kw,
|
||||
font_style::SpecifiedValue::System(_) => return false,
|
||||
});
|
||||
match font.font_style {
|
||||
FontStyle::Normal => style.set_normal(),
|
||||
FontStyle::Italic => style.set_enum(structs::NS_FONT_STYLE_ITALIC as i32),
|
||||
FontStyle::Oblique(ref angle) => {
|
||||
style.set_angle(FontStyle::compute_angle(angle))
|
||||
}
|
||||
FontStyle::System(_) => return false,
|
||||
};
|
||||
|
||||
if font.font_stretch.get_system().is_some() {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user