PdfOpenTypeFont class
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 : PdfFontInheritance
object ← PdfFont ← PdfOpenTypeFont
Remarks
Section titled “Remarks”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.
Properties
Section titled “Properties”AllowsEmbedding
Section titled “ AllowsEmbedding”True when the font’s license (OS/2 fsType) allows embedding it in a document.
public bool AllowsEmbedding { get; }Property Value
Section titled “Property Value”FamilyName
Section titled “ FamilyName”Family name, such as “Helvetica”.
public override string FamilyName { get; }Property Value
Section titled “Property Value”GlyphCount
Section titled “ GlyphCount”Number of glyphs in the font.
public int GlyphCount { get; }Property Value
Section titled “Property Value”IsBold
Section titled “ IsBold”True for bold and heavier weights.
public override bool IsBold { get; }Property Value
Section titled “Property Value”IsFixedPitch
Section titled “ IsFixedPitch”True when all glyphs have the same advance.
public bool IsFixedPitch { get; }Property Value
Section titled “Property Value”IsItalic
Section titled “ IsItalic”True for italic and oblique styles.
public override bool IsItalic { get; }Property Value
Section titled “Property Value”IsVariable
Section titled “ IsVariable”True for a variable font: one with design axes that GetInstance can set.
public bool IsVariable { get; }Property Value
Section titled “Property Value”PostScript name, as written to /BaseFont.
public override string Name { get; }Property Value
Section titled “Property Value”NamedInstances
Section titled “ NamedInstances”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; }Property Value
Section titled “Property Value”StyleName
Section titled “ StyleName”Style name within the family, such as “Bold Italic”.
public string StyleName { get; }Property Value
Section titled “Property Value”VariationAxes
Section titled “ VariationAxes”The design axes of a variable font; empty for a static font.
public IReadOnlyList<PdfFontAxis> VariationAxes { get; }Property Value
Section titled “Property Value”Weight
Section titled “ Weight”Weight from 1 to 1000: 400 is regular, 700 bold.
public int Weight { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”CountFonts(byte[])
Section titled “ CountFonts(byte[])”Number of fonts in a file’s bytes: more than one for a collection.
public static int CountFonts(byte[] data)Parameters
Section titled “Parameters”data byte[]
Returns
Section titled “Returns”GetInstance(string)
Section titled “ GetInstance(string)”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)Parameters
Section titled “Parameters”name string
A style name from NamedInstances, compared without regard to case.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The font is not variable.
The font has no instance of that name.
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)Parameters
Section titled “Parameters”axisValues IReadOnlyDictionary<string, double>
Values by axis tag, in the axis’s own units, such as { [“wght”] = 650 }.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The font is not variable.
A tag is not one of the font’s axes, or a value is not a number.
The font’s variation data is damaged.
Load(string, int)
Section titled “ Load(string, int)”Loads a font from a file: .ttf, .otf, .ttc, .otc, .woff or .woff2.
public static PdfOpenTypeFont Load(string path, int index = 0)Parameters
Section titled “Parameters”path string
The font file.
index int
For a collection, which of its fonts; see CountFonts.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The file is not a supported font.
Load(Stream, int)
Section titled “ Load(Stream, int)”Loads a font from a stream, read to its end.
public static PdfOpenTypeFont Load(Stream stream, int index = 0)Parameters
Section titled “Parameters”stream Stream
index int
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported font.
Load(byte[], int)
Section titled “ Load(byte[], int)”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)Parameters
Section titled “Parameters”data byte[]
index int
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported font.