mirror of
https://github.com/servo/servo.git
synced 2025-08-12 17:05:33 +01:00
style: Update font-stretch to css-fonts-4.
These won't "just work", pending changes from bug 1436048 to use a floating point representation for those. Bug: 1454883 Reviewed-by: xidorn MozReview-Commit-ID: Bi5iTdFreMA
This commit is contained in:
parent
91be6c31c3
commit
f7636e6662
11 changed files with 267 additions and 124 deletions
|
@ -2601,7 +2601,7 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
|
||||
unsafe { Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0 as f32) };
|
||||
unsafe { Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0) };
|
||||
}
|
||||
${impl_simple_copy('font_weight', 'mFont.weight')}
|
||||
|
||||
|
@ -2610,6 +2610,21 @@ fn static_assert() {
|
|||
longhands::font_weight::computed_value::T(weight)
|
||||
}
|
||||
|
||||
pub fn set_font_stretch(&mut self, v: longhands::font_stretch::computed_value::T) {
|
||||
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;
|
||||
|
||||
let stretch = self.gecko.mFont.stretch as f32 / 100.;
|
||||
debug_assert!(stretch >= 0.);
|
||||
|
||||
NonNegative(Percentage(stretch))
|
||||
}
|
||||
|
||||
${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) {
|
||||
|
|
|
@ -19,7 +19,6 @@ use num_traits::Zero;
|
|||
use properties::{CSSWideKeyword, PropertyDeclaration};
|
||||
use properties::longhands;
|
||||
use properties::longhands::font_weight::computed_value::T as FontWeight;
|
||||
use properties::longhands::font_stretch::computed_value::T as FontStretch;
|
||||
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||
use properties::PropertyId;
|
||||
use properties::{LonghandId, ShorthandId};
|
||||
|
@ -880,61 +879,6 @@ impl ToAnimatedZero for FontWeight {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-fonts/#font-stretch-prop>
|
||||
impl Animate for FontStretch {
|
||||
#[inline]
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
let from = f64::from(*self);
|
||||
let to = f64::from(*other);
|
||||
let normal = f64::from(FontStretch::Normal);
|
||||
let (this_weight, other_weight) = procedure.weights();
|
||||
let result = (from - normal) * this_weight + (to - normal) * other_weight + normal;
|
||||
Ok(result.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for FontStretch {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
f64::from(*self).compute_squared_distance(&(*other).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for FontStretch {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
/// We should treat font stretch as real number in order to interpolate this property.
|
||||
/// <https://drafts.csswg.org/css-fonts-3/#font-stretch-animation>
|
||||
impl From<FontStretch> for f64 {
|
||||
fn from(stretch: FontStretch) -> f64 {
|
||||
use self::FontStretch::*;
|
||||
match stretch {
|
||||
UltraCondensed => 1.0,
|
||||
ExtraCondensed => 2.0,
|
||||
Condensed => 3.0,
|
||||
SemiCondensed => 4.0,
|
||||
Normal => 5.0,
|
||||
SemiExpanded => 6.0,
|
||||
Expanded => 7.0,
|
||||
ExtraExpanded => 8.0,
|
||||
UltraExpanded => 9.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<FontStretch> for f64 {
|
||||
fn into(self) -> FontStretch {
|
||||
use properties::longhands::font_stretch::computed_value::T::*;
|
||||
let index = (self + 0.5).floor().min(9.0).max(1.0);
|
||||
static FONT_STRETCH_ENUM_MAP: [FontStretch; 9] =
|
||||
[ UltraCondensed, ExtraCondensed, Condensed, SemiCondensed, Normal,
|
||||
SemiExpanded, Expanded, ExtraExpanded, UltraExpanded ];
|
||||
FONT_STRETCH_ENUM_MAP[(index - 1.0) as usize]
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def>
|
||||
impl Animate for FontVariationSettings {
|
||||
#[inline]
|
||||
|
|
|
@ -81,17 +81,16 @@ ${helpers.predefined_type("font-synthesis",
|
|||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-synthesis")}
|
||||
|
||||
${helpers.single_keyword_system("font-stretch",
|
||||
"normal ultra-condensed extra-condensed condensed \
|
||||
semi-condensed semi-expanded expanded extra-expanded \
|
||||
ultra-expanded",
|
||||
gecko_ffi_name="mFont.stretch",
|
||||
gecko_constant_prefix="NS_FONT_STRETCH",
|
||||
cast_type='i16',
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-stretch",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
animation_value_type="ComputedValue",
|
||||
servo_restyle_damage="rebuild_and_reflow")}
|
||||
${helpers.predefined_type(
|
||||
"font-stretch",
|
||||
"FontStretch",
|
||||
initial_value="computed::NonNegativePercentage::hundred()",
|
||||
initial_specified_value="specified::FontStretch::normal()",
|
||||
animation_value_type="Percentage",
|
||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-stretch",
|
||||
servo_restyle_damage="rebuild_and_reflow",
|
||||
)}
|
||||
|
||||
${helpers.single_keyword_system("font-kerning",
|
||||
"auto none normal",
|
||||
|
@ -290,11 +289,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 font_stretch
|
||||
kw_font_props = """font_style 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_stretch
|
||||
kw_cast = """font_style font_variant_caps
|
||||
font_kerning font_variant_position
|
||||
font_optical_sizing""".split()
|
||||
%>
|
||||
|
@ -330,7 +329,9 @@ ${helpers.predefined_type("-x-text-zoom",
|
|||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs::{LookAndFeel_FontID, nsFont};
|
||||
use std::mem;
|
||||
use values::computed::Percentage;
|
||||
use values::computed::font::{FontSize, FontFamilyList};
|
||||
use values::generics::NonNegative;
|
||||
|
||||
let id = match *self {
|
||||
% for font in system_fonts:
|
||||
|
@ -349,7 +350,8 @@ ${helpers.predefined_type("-x-text-zoom",
|
|||
cx.device().pres_context()
|
||||
)
|
||||
}
|
||||
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||
let font_stretch = NonNegative(Percentage(system.stretch as f32));
|
||||
let ret = ComputedSystemFont {
|
||||
font_family: longhands::font_family::computed_value::T(
|
||||
FontFamilyList(
|
||||
|
@ -360,7 +362,8 @@ ${helpers.predefined_type("-x-text-zoom",
|
|||
size: Au(system.size).into(),
|
||||
keyword_info: None
|
||||
},
|
||||
font_weight: weight,
|
||||
font_weight,
|
||||
font_stretch,
|
||||
font_size_adjust: longhands::font_size_adjust::computed_value
|
||||
::T::from_gecko_adjust(system.sizeAdjust),
|
||||
% for kwprop in kw_font_props:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue