mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Only parse font-stretch keywords in the font shorthand.
Bug: 1454883 Reviewed-by: xidorn MozReview-Commit-ID: 4BqnOSz83w4
This commit is contained in:
parent
36cef8ec68
commit
b1fbb28b8a
2 changed files with 57 additions and 5 deletions
|
@ -27,6 +27,7 @@
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
use values::specified::text::LineHeight;
|
use values::specified::text::LineHeight;
|
||||||
use values::specified::FontSize;
|
use values::specified::FontSize;
|
||||||
|
use values::specified::font::{FontStretch, FontStretchKeyword};
|
||||||
|
|
||||||
<%
|
<%
|
||||||
gecko_sub_properties = "kerning language_override size_adjust \
|
gecko_sub_properties = "kerning language_override size_adjust \
|
||||||
|
@ -94,8 +95,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if stretch.is_none() {
|
if stretch.is_none() {
|
||||||
if let Ok(value) = input.try(|input| font_stretch::parse(context, input)) {
|
if let Ok(value) = input.try(FontStretchKeyword::parse) {
|
||||||
stretch = Some(value);
|
stretch = Some(FontStretch::Keyword(value));
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,15 +181,31 @@
|
||||||
% endfor
|
% endfor
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
// In case of serialization for canvas font, we need to drop
|
// Only font-stretch keywords are allowed as part as the font
|
||||||
// initial values of properties other than size and family.
|
// shorthand.
|
||||||
% for name in "style variant_caps weight stretch".split():
|
let font_stretch = match *self.font_stretch {
|
||||||
|
FontStretch::Keyword(kw) => kw,
|
||||||
|
FontStretch::Stretch(percentage) => {
|
||||||
|
match FontStretchKeyword::from_percentage(percentage.get()) {
|
||||||
|
Some(kw) => kw,
|
||||||
|
None => return Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FontStretch::System(..) => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
% for name in "style variant_caps weight".split():
|
||||||
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
||||||
self.font_${name}.to_css(dest)?;
|
self.font_${name}.to_css(dest)?;
|
||||||
dest.write_str(" ")?;
|
dest.write_str(" ")?;
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
if font_stretch != FontStretchKeyword::Normal {
|
||||||
|
font_stretch.to_css(dest)?;
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
}
|
||||||
|
|
||||||
self.font_size.to_css(dest)?;
|
self.font_size.to_css(dest)?;
|
||||||
|
|
||||||
if *self.line_height != LineHeight::normal() {
|
if *self.line_height != LineHeight::normal() {
|
||||||
|
|
|
@ -418,6 +418,41 @@ impl FontStretchKeyword {
|
||||||
UltraExpanded => 2.,
|
UltraExpanded => 2.,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Does the opposite operation to `compute`, in order to serialize keywords
|
||||||
|
/// if possible.
|
||||||
|
pub fn from_percentage(percentage: f32) -> Option<Self> {
|
||||||
|
use self::FontStretchKeyword::*;
|
||||||
|
// NOTE(emilio): Can't use `match` because of rust-lang/rust#41620.
|
||||||
|
if percentage == 0.5 {
|
||||||
|
return Some(UltraCondensed);
|
||||||
|
}
|
||||||
|
if percentage == 0.625 {
|
||||||
|
return Some(ExtraCondensed);
|
||||||
|
}
|
||||||
|
if percentage == 0.75 {
|
||||||
|
return Some(Condensed);
|
||||||
|
}
|
||||||
|
if percentage == 0.875 {
|
||||||
|
return Some(SemiCondensed);
|
||||||
|
}
|
||||||
|
if percentage == 1. {
|
||||||
|
return Some(Normal);
|
||||||
|
}
|
||||||
|
if percentage == 1.125 {
|
||||||
|
return Some(SemiExpanded);
|
||||||
|
}
|
||||||
|
if percentage == 1.25 {
|
||||||
|
return Some(Expanded);
|
||||||
|
}
|
||||||
|
if percentage == 1.5 {
|
||||||
|
return Some(ExtraExpanded);
|
||||||
|
}
|
||||||
|
if percentage == 2. {
|
||||||
|
return Some(UltraExpanded);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontStretch {
|
impl FontStretch {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue