Skip to content

PDFFont

Namespace: O2S.Components.PDF4NET.Graphics

Defines the base class for PDF fonts.

public abstract class PDFFont

Inheritance ObjectPDFFont

Properties

Bold

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

public bool Bold { get; set; }

Property Value

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


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


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
If true, then the font has an italic appearance.


Metrics

Gets the font metrics.

public PDFFontMetrics Metrics { get; }

Property Value

PDFFontMetrics
A PDFFontMetrics that represents the metrics of the font.


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 float 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.