Skip to content

PDFTrueTypeFont

Namespace: O2S.Components.PDF4NET.Graphics

Defines the base class for TrueType fonts.

public class PDFTrueTypeFont : PDFFont

Inheritance ObjectPDFFontPDFTrueTypeFont

Properties

Bold

Gets or sets a value indicating whether the font is bold.

public bool Bold { get; set; }

Property Value

Boolean
True if the font has a bold appearance.

Remarks

This property has no effect if the font is embedded.


CharacterSpacing

Gets or sets the character spacing to be used by this font.

public double CharacterSpacing { get; set; }

Property Value

Double
Character spacing in unscaled text units.


CosFont

Gets the COS font dictionary.

public PDFCosDictionary CosFont { get; }

Property Value

PDFCosDictionary


EnableFontSubset

Gets or sets a value indicating whether this font must be subset or not.

public bool EnableFontSubset { get; set; }

Property Value

Boolean
True if the font data should be subset in order to reduce the final font size, false if the whole font file should be embedded in the PDF file. Default is true.


HorizontalScaling

Gets or sets the text horizontal scaling to be used by this font.

public double HorizontalScaling { get; set; }

Property Value

Double
Percentage of the normal width of the glyphs, with 100 being the normal width.

Remarks

The horizontal scaling property adjusts the width of glyphs by stretching or compressing them in the horizontal direction.


Italic

Gets or sets a value indicating whether the font is italic.

public bool Italic { get; set; }

Property Value

Boolean
True if the font has an italic appearance.

Remarks

This property has no effect if the font is embedded.


Metrics

Gets the font metrics.

public PDFFontMetrics Metrics { get; }

Property Value

PDFFontMetrics
A PDFFontMetrics that represents the metrics of the font.


Name

Gets the name of this font.

public string Name { get; }

Property Value

String
The name of the font as it appears in the font file.


Size

Gets or sets the font size.

public double Size { get; set; }

Property Value

Double
The font size in PDF points.


Strikethrough

Gets or sets a value indicating whether the font is strikethrough.

public bool Strikethrough { get; set; }

Property Value

Boolean
If true, then the font has a strikethrough appearance.


StrikethroughOffset

Gets or sets the strikethrough offset.

public double StrikethroughOffset { get; set; }

Property Value

Double
Offset from text baseline for drawing the strikethrough.

Remarks

The offset is given in PDF points. 0 means default strikethrough offset.


TextRenderingMode

Gets or sets the text rendering mode.

public PDFTextRenderingMode TextRenderingMode { get; set; }

Property Value

PDFTextRenderingMode
A PDFTextRenderingMode specifying how the text is rendered using this font.


Underline

Gets or sets a value indicating whether the font is underlined.

public bool Underline { get; set; }

Property Value

Boolean
If true, then the font has an underlined appearance.


Methods

EncodeString(String)

Encodes the given text to a byte array based on font's encoding.

public Byte[] EncodeString(string text)

Parameters

text String
String to convert.

Returns

Byte[]
An array of bytes representing the string according to font encoding.


GetCharWidth(Char)

Gets the width of the given character when drawn with this font object.

public double GetCharWidth(char charCode)

Parameters

charCode Char
the char to get its width

Returns

Double
This method returns a double value that represents the width, in unscaled glyph units, of the given character.

Remarks

To scale this value to font's current size, divide it by 1000 and multiply it by font size. For example, if font size is 20pt, then the width, in points, of a character for this font is 20 * GetCharWidth( charCode ) / 1000.


GetGlyphEmWidth(Int32)

Gets the Em width of the given glyph when drawn with this font object.

public int GetGlyphEmWidth(int glyph)

Parameters

glyph Int32
the index of the glyph to get its width

Returns

Int32
The width of the glyph in Em units.

Remarks

To scale this value to font's current size, divide it by 2048 and multiply it by font size. For example, if font size is 20pt, then the width, in points, of a character for this font is 20 * GetGlyphEmWidth(glyph) / 2048.


GetGlyphOutline(Int32)

Gets the outline of the specified character, given as a Unicode code point.

public PDFPath GetGlyphOutline(int codePoint)

Parameters

codePoint Int32
The Unicode code point of the character for which the glyph outline should be retrieved

Returns

PDFPath
The glyph outline as a PDFPath object


UpdateCharsSubset(Char[])

Updates the set of characters that must be subset in the final font data.

public void UpdateCharsSubset(Char[] chars)

Parameters

chars Char[]
Array of characters to be included in the subset.

Remarks

This method is called automatically when using the DrawString methods in the PDFCanvas class but when the low level methods in PDFContentStream class are used then the characters to be subset must be added manually.


UpdateGlyphsSubset(Int32[])

Updates the set of glyphs that must be subset in the final font data.

public void UpdateGlyphsSubset(Int32[] glyphs)

Parameters

glyphs Int32[]
Array of glyph indexes to be included in the subset.

Remarks

This method is called automatically when using the DrawString methods in the PDFCanvas class but when the low level methods in PDFContentStream class are used then the glyphs to be subset must be added manually.