Class CssFontFace
The descriptors of an @font-face rule (CSS Fonts 4), parsed. Invalid descriptors keep their defaults.
public sealed class CssFontFace
- Inheritance
-
CssFontFace
- Inherited Members
Examples
bool isFont = CssFont.TryParse("italic bold 14px/1.4 \"Source Sans 3\", sans-serif", out CssFont? font);
CssFontWeight weight = font!.Weight; // 700
foreach (CssFontFamily family in font.Families!.Families)
{
Console.WriteLine($"{family.Name} (generic: {family.IsGeneric})");
}
bool isFamilyList = CssFontFamilyList.TryParse("Georgia, serif", out CssFontFamilyList? families);
bool isWeight = CssFontWeight.TryParse("bolder", out CssFontWeight bolder);
double resolved = bolder.Kind == CssFontWeightKind.Bolder ? bolder.Resolve(400) : bolder.Value; // 700
// @font-face descriptors.
CssStyleSheet sheet = CssStyleSheet.Parse("""
@font-face {
font-family: "Inter";
src: local("Inter"), url(inter.woff2) format("woff2") tech(variations);
font-weight: 100 900;
unicode-range: U+0000-00FF, U+20AC;
}
""");
CssFontFace face = ((CssFontFaceRule)sheet.Rules[0]).FontFace;
CssFontSource source = face.Sources[1]; // inter.woff2, format woff2, tech variations
CssRange weights = face.Weight!.Value; // 100 to 900
CssUnicodeRange latin = face.UnicodeRanges[0]; // U+0-FF
Properties
Display
Gets the font-display keyword: auto (the default), block, swap, fallback or optional.
public string Display { get; }
Property Value
Family
Gets the family name the face is known by, or null when missing (the rule is then unusable).
public string? Family { get; }
Property Value
FeatureSettings
Gets the font-feature-settings descriptor as CSS text, or null.
public string? FeatureSettings { get; }
Property Value
ObliqueAngle
Gets the oblique angle range in degrees for an oblique style (14 degrees when not given).
public CssRange? ObliqueAngle { get; }
Property Value
Sources
Gets the sources, in order of preference. Entries that do not parse are skipped.
public IReadOnlyList<CssFontSource> Sources { get; }
Property Value
Stretch
Gets the width range as percentages (condensed is 75), or null for auto.
public CssRange? Stretch { get; }
Property Value
Style
Gets the style: normal, italic or oblique; null for auto.
public string? Style { get; }
Property Value
UnicodeRanges
Gets the code point ranges the face covers; all of Unicode when not given.
public IReadOnlyList<CssUnicodeRange> UnicodeRanges { get; }
Property Value
VariationSettings
Gets the font-variation-settings descriptor as CSS text, or null.
public string? VariationSettings { get; }
Property Value
Weight
Gets the weight range, or null for auto (the font's own).
public CssRange? Weight { get; }
Property Value
Methods
FromDeclarations(IEnumerable<CssDeclaration>)
Reads the descriptors of an @font-face rule.
public static CssFontFace FromDeclarations(IEnumerable<CssDeclaration> declarations)
Parameters
declarationsIEnumerable<CssDeclaration>The rule's declarations.
Returns
- CssFontFace
The parsed descriptors.