Table of Contents

Class CssFont

Namespace
Egami.Css
Assembly
Egami.Css.dll

The font shorthand (CSS Fonts 4), parsed.

public sealed class CssFont
Inheritance
CssFont
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

Families

Gets the font families, or null for a system font.

public CssFontFamilyList? Families { get; }

Property Value

CssFontFamilyList

LineHeight

Gets the line height, or null when not given (normal).

public IReadOnlyList<CssComponentValue>? LineHeight { get; }

Property Value

IReadOnlyList<CssComponentValue>

ObliqueAngle

Gets the angle of oblique <angle> in degrees, or null.

public double? ObliqueAngle { get; }

Property Value

double?

Size

Gets the size: a keyword such as medium, a length, a percentage or a math function. Empty for a system font.

public IReadOnlyList<CssComponentValue> Size { get; }

Property Value

IReadOnlyList<CssComponentValue>

Stretch

Gets the width keyword, such as condensed, or normal.

public string Stretch { get; }

Property Value

string

Style

Gets the font style: normal, italic or oblique.

public string Style { get; }

Property Value

string

SystemFont

Gets the system font keyword (caption, icon, menu, message-box, small-caption or status-bar), or null.

public string? SystemFont { get; }

Property Value

string

VariantCaps

Gets the variant: normal or small-caps.

public string VariantCaps { get; }

Property Value

string

Weight

Gets the weight.

public CssFontWeight Weight { get; }

Property Value

CssFontWeight

Methods

ToString()

Formats the font as CSS text.

public override string ToString()

Returns

string

The text.

TryParse(IReadOnlyList<CssComponentValue>, out CssFont?)

Parses component values as a font shorthand value.

public static bool TryParse(IReadOnlyList<CssComponentValue> values, out CssFont? font)

Parameters

values IReadOnlyList<CssComponentValue>

The component values.

font CssFont

The font.

Returns

bool

True when valid.

TryParse(string, out CssFont?)

Parses a font shorthand value, such as italic bold 12px/1.5 "Open Sans", sans-serif.

public static bool TryParse(string text, out CssFont? font)

Parameters

text string

The CSS text.

font CssFont

The font.

Returns

bool

True when valid.