Skip to content

PdfOpenTypeFont class

View as Markdown

Namespace: PdfNetStack.Fonts
Assembly: PdfNetStack.dll
Package: PdfNetStack

A TrueType or OpenType font, embedded in the document as a subset of the glyphs actually drawn. Loads .ttf, .otf, collections (.ttc, .otc), WOFF and WOFF2 files. Text is searchable and copyable, and pairs are kerned from the font’s GPOS or kern table.

public sealed class PdfOpenTypeFont : PdfFont

Inheritance

object ← PdfFont ← PdfOpenTypeFont

The font program is embedded, so the PDF shows the same glyphs everywhere, including in PDF/A. A variable font draws its default instance; GetInstance and GetInstance give any other, embedded as a static font with the variations applied (TrueType and CFF2 outlines alike). Each location is made once and shared while it is in use, the default location being the font itself, so a document embeds one program per location drawn; instances nothing holds any more are freed. Fonts whose license forbids embedding (OS/2 fsType) are refused when first drawn.

True when the font’s license (OS/2 fsType) allows embedding it in a document.

public bool AllowsEmbedding { get; }

bool

Family name, such as “Helvetica”.

public override string FamilyName { get; }

string

Number of glyphs in the font.

public int GlyphCount { get; }

int

True for bold and heavier weights.

public override bool IsBold { get; }

bool

True when all glyphs have the same advance.

public bool IsFixedPitch { get; }

bool

True for italic and oblique styles.

public override bool IsItalic { get; }

bool

True for a variable font: one with design axes that GetInstance can set.

public bool IsVariable { get; }

bool

PostScript name, as written to /BaseFont.

public override string Name { get; }

string

The style names of a variable font’s named instances, such as “Bold” or “Condensed Light”; empty for a static font.

public IReadOnlyList<string> NamedInstances { get; }

IReadOnlyList<string>

Style name within the family, such as “Bold Italic”.

public string StyleName { get; }

string

The design axes of a variable font; empty for a static font.

public IReadOnlyList<PdfFontAxis> VariationAxes { get; }

IReadOnlyList<PdfFontAxis>

Weight from 1 to 1000: 400 is regular, 700 bold.

public int Weight { get; }

int

Number of fonts in a file’s bytes: more than one for a collection.

public static int CountFonts(byte[] data)

data byte[]

int

The variable font at one of its named instances, as a static font: outlines, advances and metrics follow the instance, and shaping applies its kerning and substitutions.

public PdfOpenTypeFont GetInstance(string name)

name string

A style name from NamedInstances, compared without regard to case.

PdfOpenTypeFont

InvalidOperationException

The font is not variable.

ArgumentException

The font has no instance of that name.

FontFormatException

The font’s variation data is damaged.

GetInstance(IReadOnlyDictionary<string, double>)

Section titled “ GetInstance(IReadOnlyDictionary<string, double>)”

The variable font at the given axis values, as a static font. Axes not named keep their default; values outside an axis’s range are clamped to it.

public PdfOpenTypeFont GetInstance(IReadOnlyDictionary<string, double> axisValues)

axisValues IReadOnlyDictionary<string, double>

Values by axis tag, in the axis’s own units, such as { [“wght”] = 650 }.

PdfOpenTypeFont

InvalidOperationException

The font is not variable.

ArgumentException

A tag is not one of the font’s axes, or a value is not a number.

FontFormatException

The font’s variation data is damaged.

Loads a font from a file: .ttf, .otf, .ttc, .otc, .woff or .woff2.

public static PdfOpenTypeFont Load(string path, int index = 0)

path string

The font file.

index int

For a collection, which of its fonts; see CountFonts.

PdfOpenTypeFont

FontFormatException

The file is not a supported font.

Loads a font from a stream, read to its end.

public static PdfOpenTypeFont Load(Stream stream, int index = 0)

stream Stream

index int

PdfOpenTypeFont

FontFormatException

The data is not a supported font.

Loads a font from its bytes. The array is used directly; do not change it afterwards.

public static PdfOpenTypeFont Load(byte[] data, int index = 0)

data byte[]

index int

PdfOpenTypeFont

FontFormatException

The data is not a supported font.