Skip to content

Commit 096329e

Browse files
committed
Correctly parse font-weight and font-stretch ranges in @font-face rules
1 parent ef5cf63 commit 096329e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,6 +4450,10 @@ mod tests {
44504450
minify_test("@font-face {src: url(\"test.woff\") format(woff supports variations);}", "@font-face{src:url(test.woff)format(\"woff\" supports variations)}");
44514451
minify_test("@font-face {src: url(\"test.woff\") format(woff supports palettes);}", "@font-face{src:url(test.woff)format(\"woff\" supports palettes)}");
44524452
minify_test("@font-face {src: url(\"test.woff\") format(woff supports features(opentype) color(sbix));}", "@font-face{src:url(test.woff)format(\"woff\" supports features(opentype) color(sbix))}");
4453+
minify_test("@font-face {font-weight: 200 400}", "@font-face{font-weight:200 400}");
4454+
minify_test("@font-face {font-weight: 400 400}", "@font-face{font-weight:400}");
4455+
minify_test("@font-face {font-stretch: 50% 200%}", "@font-face{font-stretch:50% 200%}");
4456+
minify_test("@font-face {font-stretch: 50% 50%}", "@font-face{font-stretch:50%}");
44534457
}
44544458

44554459
#[test]

src/rules/font_face.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use cssparser::*;
22
use crate::traits::{Parse, ToCss};
33
use crate::printer::Printer;
44
use crate::properties::font::{FontFamily, FontStyle, FontWeight, FontStretch};
5+
use crate::values::size::Size2D;
56
use crate::properties::custom::CustomProperty;
67
use crate::macros::enum_property;
78

@@ -16,8 +17,8 @@ pub enum FontFaceProperty {
1617
Source(Vec<Source>),
1718
FontFamily(FontFamily),
1819
FontStyle(FontStyle),
19-
FontWeight(FontWeight),
20-
FontStretch(FontStretch),
20+
FontWeight(Size2D<FontWeight>),
21+
FontStretch(Size2D<FontStretch>),
2122
Custom(CustomProperty)
2223
}
2324

@@ -258,8 +259,8 @@ impl<'i> cssparser::DeclarationParser<'i> for FontFaceDeclarationParser {
258259
input: &mut cssparser::Parser<'i, 't>,
259260
) -> Result<Self::Declaration, cssparser::ParseError<'i, Self::Error>> {
260261
macro_rules! property {
261-
($property: ident, $type: ident) => {
262-
if let Ok(c) = $type::parse(input) {
262+
($property: ident, $type: ty) => {
263+
if let Ok(c) = <$type>::parse(input) {
263264
return Ok(FontFaceProperty::$property(c))
264265
}
265266
};
@@ -273,9 +274,9 @@ impl<'i> cssparser::DeclarationParser<'i> for FontFaceDeclarationParser {
273274
}
274275
},
275276
"font-family" => property!(FontFamily, FontFamily),
276-
"font-weight" => property!(FontWeight, FontWeight),
277+
"font-weight" => property!(FontWeight, Size2D<FontWeight>),
277278
"font-style" => property!(FontStyle, FontStyle),
278-
"font-stretch" => property!(FontStretch, FontStretch),
279+
"font-stretch" => property!(FontStretch, Size2D<FontStretch>),
279280
_ => {}
280281
}
281282

0 commit comments

Comments
 (0)