Table of Contents

Class CssFontSource

Namespace
Egami.Css
Assembly
Egami.Css.dll

One source of an @font-face src descriptor: a URL with its format and technologies, or a local font.

public sealed record CssFontSource : IEquatable<CssFontSource>
Inheritance
CssFontSource
Implements
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

Constructors

CssFontSource(string?, string?, string?, IReadOnlyList<string>)

One source of an @font-face src descriptor: a URL with its format and technologies, or a local font.

public CssFontSource(string? Url, string? LocalName, string? Format, IReadOnlyList<string> Techs)

Parameters

Url string

The URL, unresolved, or null for a local font.

LocalName string

The full font name of local(), or null for a URL.

Format string

The format() hint in lowercase, such as woff2, or null.

Techs IReadOnlyList<string>

The tech() keywords in lowercase, such as variations; empty when not given.

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

Format

The format() hint in lowercase, such as woff2, or null.

public string? Format { get; init; }

Property Value

string

LocalName

The full font name of local(), or null for a URL.

public string? LocalName { get; init; }

Property Value

string

Techs

The tech() keywords in lowercase, such as variations; empty when not given.

public IReadOnlyList<string> Techs { get; init; }

Property Value

IReadOnlyList<string>

Url

The URL, unresolved, or null for a local font.

public string? Url { get; init; }

Property Value

string