mirror of
https://github.com/servo/servo.git
synced 2025-07-10 17:03:40 +01:00
Auto merge of #15134 - seankao31:font-stretch-shorthand, r=canaltinova
add font-stretch to font shorthand sub-property <!-- Please describe your changes on the following line: --> Add `font-stretch` sub-property to font shorthand --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15027 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15134) <!-- Reviewable:end -->
This commit is contained in:
commit
c3c4805c82
1 changed files with 18 additions and 5 deletions
|
@ -4,21 +4,22 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<%helpers:shorthand name="font" sub_properties="font-style font-variant font-weight
|
<%helpers:shorthand name="font" sub_properties="font-style font-variant font-weight font-stretch
|
||||||
font-size line-height font-family"
|
font-size line-height font-family"
|
||||||
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
||||||
use properties::longhands::{font_style, font_variant, font_weight, font_size,
|
use properties::longhands::{font_style, font_variant, font_weight, font_stretch};
|
||||||
line_height, font_family};
|
use properties::longhands::{font_size, line_height, font_family};
|
||||||
|
|
||||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||||
let mut nb_normals = 0;
|
let mut nb_normals = 0;
|
||||||
let mut style = None;
|
let mut style = None;
|
||||||
let mut variant = None;
|
let mut variant = None;
|
||||||
let mut weight = None;
|
let mut weight = None;
|
||||||
|
let mut stretch = None;
|
||||||
let size;
|
let size;
|
||||||
loop {
|
loop {
|
||||||
// Special-case 'normal' because it is valid in each of
|
// Special-case 'normal' because it is valid in each of
|
||||||
// font-style, font-weight and font-variant.
|
// font-style, font-weight, font-variant and font-stretch.
|
||||||
// Leaves the values to None, 'normal' is the initial value for each of them.
|
// Leaves the values to None, 'normal' is the initial value for each of them.
|
||||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||||
nb_normals += 1;
|
nb_normals += 1;
|
||||||
|
@ -42,6 +43,12 @@
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if stretch.is_none() {
|
||||||
|
if let Ok(value) = input.try(|input| font_stretch::parse(context, input)) {
|
||||||
|
stretch = Some(value);
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
size = Some(try!(font_size::parse(context, input)));
|
size = Some(try!(font_size::parse(context, input)));
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -49,7 +56,7 @@
|
||||||
fn count<T>(opt: &Option<T>) -> u8 {
|
fn count<T>(opt: &Option<T>) -> u8 {
|
||||||
if opt.is_some() { 1 } else { 0 }
|
if opt.is_some() { 1 } else { 0 }
|
||||||
}
|
}
|
||||||
if size.is_none() || (count(&style) + count(&weight) + count(&variant) + nb_normals) > 3 {
|
if size.is_none() || (count(&style) + count(&weight) + count(&variant) + count(&stretch) + nb_normals) > 4 {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
let line_height = if input.try(|input| input.expect_delim('/')).is_ok() {
|
let line_height = if input.try(|input| input.expect_delim('/')).is_ok() {
|
||||||
|
@ -62,6 +69,7 @@
|
||||||
font_style: style,
|
font_style: style,
|
||||||
font_variant: variant,
|
font_variant: variant,
|
||||||
font_weight: weight,
|
font_weight: weight,
|
||||||
|
font_stretch: stretch,
|
||||||
font_size: size,
|
font_size: size,
|
||||||
line_height: line_height,
|
line_height: line_height,
|
||||||
font_family: Some(font_family::SpecifiedValue(family))
|
font_family: Some(font_family::SpecifiedValue(family))
|
||||||
|
@ -86,6 +94,11 @@
|
||||||
try!(write!(dest, " "));
|
try!(write!(dest, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let DeclaredValue::Value(ref stretch) = *self.font_stretch {
|
||||||
|
try!(stretch.to_css(dest));
|
||||||
|
try!(write!(dest, " "));
|
||||||
|
}
|
||||||
|
|
||||||
try!(self.font_size.to_css(dest));
|
try!(self.font_size.to_css(dest));
|
||||||
if let DeclaredValue::Value(ref height) = *self.line_height {
|
if let DeclaredValue::Value(ref height) = *self.line_height {
|
||||||
match *height {
|
match *height {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue