1+ //! The `@font-face` rule.
2+
13use super :: Location ;
24use crate :: error:: { ParserError , PrinterError } ;
35use crate :: macros:: enum_property;
@@ -11,27 +13,43 @@ use crate::values::url::Url;
1113use cssparser:: * ;
1214use std:: fmt:: Write ;
1315
16+ /// A [@font-face](https://drafts.csswg.org/css-fonts/#font-face-rule) rule.
1417#[ derive( Debug , PartialEq , Clone ) ]
1518pub struct FontFaceRule < ' i > {
19+ /// Declarations in the `@font-face` rule.
1620 pub properties : Vec < FontFaceProperty < ' i > > ,
21+ /// The location of the rule in the source file.
1722 pub loc : Location ,
1823}
1924
25+ /// A property within an `@font-face` rule.
26+ ///
27+ /// See [FontFaceRule](FontFaceRule).
2028#[ derive( Debug , Clone , PartialEq ) ]
2129pub enum FontFaceProperty < ' i > {
30+ /// The `src` property.
2231 Source ( Vec < Source < ' i > > ) ,
32+ /// The `font-family` property.
2333 FontFamily ( FontFamily < ' i > ) ,
34+ /// The `font-style` property.
2435 FontStyle ( FontStyle ) ,
36+ /// The `font-weight` property.
2537 FontWeight ( Size2D < FontWeight > ) ,
38+ /// The `font-stretch` property.
2639 FontStretch ( Size2D < FontStretch > ) ,
40+ /// The `unicode-range` property.
2741 UnicodeRange ( Vec < UnicodeRange > ) ,
42+ /// An unknown or unsupported property.
2843 Custom ( CustomProperty < ' i > ) ,
2944}
3045
31- /// https://www.w3.org/TR/2021/WD-css-fonts-4-20210729/#font-face-src-parsing
46+ /// A value for the [src](https://drafts.csswg.org/css-fonts/#src-desc)
47+ /// property in an `@font-face` rule.
3248#[ derive( Debug , Clone , PartialEq ) ]
3349pub enum Source < ' i > {
50+ /// A `url()` with optional format metadata.
3451 Url ( UrlSource < ' i > ) ,
52+ /// The `local()` function.
3553 Local ( FontFamily < ' i > ) ,
3654}
3755
@@ -63,9 +81,13 @@ impl<'i> ToCss for Source<'i> {
6381 }
6482}
6583
84+ /// A `url()` value for the [src](https://drafts.csswg.org/css-fonts/#src-desc)
85+ /// property in an `@font-face` rule.
6686#[ derive( Debug , Clone , PartialEq ) ]
6787pub struct UrlSource < ' i > {
88+ /// The URL.
6889 pub url : Url < ' i > ,
90+ /// Optional `format()` function.
6991 pub format : Option < Format < ' i > > ,
7092}
7193
@@ -99,9 +121,14 @@ impl<'i> ToCss for UrlSource<'i> {
99121 }
100122}
101123
124+ /// The `format()` function within the [src](https://drafts.csswg.org/css-fonts/#src-desc)
125+ /// property of an `@font-face` rule.
102126#[ derive( Debug , Clone , PartialEq ) ]
103127pub struct Format < ' i > {
128+ /// A font format name.
104129 pub format : FontFormat < ' i > ,
130+ /// The `supports()` function.
131+ // TODO: did this get renamed to `tech()`?
105132 pub supports : Vec < FontTechnology > ,
106133}
107134
@@ -144,15 +171,26 @@ impl<'i> ToCss for Format<'i> {
144171 }
145172}
146173
174+ /// A font format keyword in the `format()` function of the the
175+ /// [src](https://drafts.csswg.org/css-fonts/#src-desc)
176+ /// property of an `@font-face` rule.
147177#[ derive( Debug , Clone , PartialEq ) ]
148178pub enum FontFormat < ' i > {
179+ /// A WOFF font.
149180 WOFF ,
181+ /// A WOFF v2 font.
150182 WOFF2 ,
183+ /// A TrueType font.
151184 TrueType ,
185+ /// An OpenType font.
152186 OpenType ,
187+ /// An Embedded OpenType (.eot) font.
153188 EmbeddedOpenType ,
189+ /// A font collection.
154190 Collection ,
191+ /// An SVG font.
155192 SVG ,
193+ /// An unknown format.
156194 String ( CowArcStr < ' i > ) ,
157195}
158196
@@ -196,28 +234,49 @@ impl<'i> ToCss for FontFormat<'i> {
196234}
197235
198236enum_property ! {
237+ /// A font feature tech descriptor in the `supports()`function of the
238+ /// [src](https://drafts.csswg.org/css-fonts/#src-desc)
239+ /// property of an `@font-face` rule.
199240 pub enum FontFeatureTechnology {
241+ /// Supports OpenType features.
200242 OpenType ,
243+ /// Supports Apple Advanced Typography features.
201244 AAT ,
245+ /// Supports Graphite features.
202246 Graphite ,
203247 }
204248}
205249
206250enum_property ! {
251+ /// A color font tech descriptor in the `supports()`function of the
252+ /// [src](https://drafts.csswg.org/css-fonts/#src-desc)
253+ /// property of an `@font-face` rule.
207254 pub enum ColorFontTechnology {
255+ /// Supports the `COLR` v0 table.
208256 COLRv0 ,
257+ /// Supports the `COLR` v1 table.
209258 COLRv1 ,
259+ /// Supports SVG glyphs.
210260 SVG ,
261+ /// Supports the `sbix` table.
211262 SBIX ,
263+ /// Supports the `CBDT` table.
212264 CBDT ,
213265 }
214266}
215267
268+ /// A font technology descriptor in the `supports()`function of the
269+ /// [src](https://drafts.csswg.org/css-fonts/#src-desc)
270+ /// property of an `@font-face` rule.
216271#[ derive( Debug , Clone , PartialEq ) ]
217272pub enum FontTechnology {
273+ /// Supports font features.
218274 Features ( FontFeatureTechnology ) ,
275+ /// Supports variations.
219276 Variations ,
277+ /// Supports color glyphs.
220278 Color ( ColorFontTechnology ) ,
279+ /// Supports color palettes.
221280 Palettes ,
222281}
223282
0 commit comments