Table of Contents

Class CssFontFace

Namespace
Egami.Css
Assembly
Egami.Css.dll

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

string

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

string

FeatureSettings

Gets the font-feature-settings descriptor as CSS text, or null.

public string? FeatureSettings { get; }

Property Value

string

ObliqueAngle

Gets the oblique angle range in degrees for an oblique style (14 degrees when not given).

public CssRange? ObliqueAngle { get; }

Property Value

CssRange?

Sources

Gets the sources, in order of preference. Entries that do not parse are skipped.

public IReadOnlyList<CssFontSource> Sources { get; }

Property Value

IReadOnlyList<CssFontSource>

Stretch

Gets the width range as percentages (condensed is 75), or null for auto.

public CssRange? Stretch { get; }

Property Value

CssRange?

Style

Gets the style: normal, italic or oblique; null for auto.

public string? Style { get; }

Property Value

string

UnicodeRanges

Gets the code point ranges the face covers; all of Unicode when not given.

public IReadOnlyList<CssUnicodeRange> UnicodeRanges { get; }

Property Value

IReadOnlyList<CssUnicodeRange>

VariationSettings

Gets the font-variation-settings descriptor as CSS text, or null.

public string? VariationSettings { get; }

Property Value

string

Weight

Gets the weight range, or null for auto (the font's own).

public CssRange? Weight { get; }

Property Value

CssRange?

Methods

FromDeclarations(IEnumerable<CssDeclaration>)

Reads the descriptors of an @font-face rule.

public static CssFontFace FromDeclarations(IEnumerable<CssDeclaration> declarations)

Parameters

declarations IEnumerable<CssDeclaration>

The rule's declarations.

Returns

CssFontFace

The parsed descriptors.