Class TrueTypeFont

Namespace
SoftZenPdf
Assembly
SoftZenPdf.dll

A TrueType font embedded in the document. Only the glyphs actually used are embedded (subsetting), and a ToUnicode map is added so text can be copied and searched. Use it for any text beyond Western European characters.

public sealed class TrueTypeFont : PdfFont
Inheritance
TrueTypeFont
Inherited Members

Examples

var noto = TrueTypeFont.FromFile("NotoSans-Regular.ttf");
page.Content.DrawText("Ωμέγα — Привет — €5", 72, 700, noto, 16);

Remarks

Supports fonts with TrueType (glyf) outlines in .ttf files, .otf files with TrueType outlines, and TrueType collections (.ttc, see FromFile(string, int)). CFF-flavoured OpenType fonts are not supported. The font's embedding permissions (OS/2 fsType) are respected.

Text is laid out with the Unicode Bidirectional Algorithm, so Hebrew, Arabic and mixed-direction lines are ordered correctly, and with the font's OpenType substitutions: joined forms of Arabic letters (and other cursive scripts), required ligatures such as lam-alef, glyph composition, contextual alternates and standard ligatures (Ligatures). Pair kerning (Kerning) and mark attachment (placing dots and vowel marks on their letters) are applied; the reordering and conjuncts of Indic scripts are not. Load a font once and reuse the instance: each instance is embedded separately.

Properties

FamilyName

The font family name from the font's name table, such as Noto Sans.

GlyphCount

The number of glyphs in the font.

IsBold

Whether the font is bold (from its OS/2 weight and style flags).

IsItalic

Whether the font is italic or oblique (from its style flags or italic angle).

Kerning

Whether pair kerning from the font's GPOS 'kern' feature (or its legacy 'kern' table) is applied. Defaults to true. Set it before drawing; it also affects MeasureText(string, double).

Ligatures

Whether the font's standard and contextual ligatures (GSUB 'liga' and 'clig' features, such as fi and fl) are applied. Defaults to true. Required ligatures ('rlig', such as Arabic lam-alef) and joined letter forms are always applied. Copied and extracted text still reads as the original letters. Set it before drawing.

PostScriptName

The PostScript name used in the PDF, with characters that are invalid in PDF names removed.

SubfamilyName

The subfamily (style) name, such as Regular or Bold Italic.

UnitsPerEm

The number of font design units per em, the scale of GetAdvanceWidth(ushort).

Methods

CountFonts(byte[])

The number of fonts in a TrueType collection (.ttc), or 1 for a single font file.

FromBytes(byte[])

Loads a TrueType font from memory; for a collection, the first font in it.

FromBytes(byte[], int)

Loads one font of a TrueType collection from memory.

FromFile(string)

Loads a TrueType font from a file; for a collection (.ttc), the first font in it.

FromFile(string, int)

Loads one font of a TrueType collection (.ttc) file.

GetAdvanceWidth(ushort)

The advance width of a glyph, in font design units (see UnitsPerEm).

ToString()

Returns PostScriptName.

TryGetGlyphId(int, out ushort)

Looks up the glyph for a Unicode code point, to check whether the font can show a character.