# Font Class

> Represents a font.

- Product: Adobe PDF Library 21
- Language: .NET Framework
- Version: APDFL21.0.0PlusP1e
- HTML page: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Font
- Version index: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/llms.txt

```csharp
class Font : SystemIDisposable
```

**Namespace:** `Datalogics::PDFL`

**Inherits from:** `SystemIDisposable`

## Description

Represents a font. Defines the typeface, size, style (bold, italic), Unicode values, and other details.

The Font class represents a font installed on the system.

**Referenced by:** [`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Font.md), [`Redaction`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Redaction.md), [`Text`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Text.md), [`TextRun`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/TextRun.md), [`WatermarkTextParams`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/WatermarkTextParams.md)

**Uses types:** [`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md), [`EncodingInfo`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/EncodingInfo.md), [`Font`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Font.md), [`FontCreateFlags`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/FontCreateFlags.md), [`FontFlags`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/FontFlags.md), [`PDFDict`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/PDFDict.md), [`Rect`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Rect.md), [`WritingMode`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/WritingMode.md)

## Constructors

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to find and create

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

• TrueTypes used as CID fonts must be embedded.

• All CID fonts that are embedded must be subsetted.

• CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

**Exceptions**

- `BadInput`: A font with the specified name could not be found.

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName, FontCreateFlags createFlags)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to create
- `createFlags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/FontCreateFlags.md)): flags specifying embedding and other options for the use of a font in the document

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

• TrueTypes used as CID fonts must be embedded.

• All CID fonts that are embedded must be subsetted.

• CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

**Exceptions**

- `BadInput`: A font with the specified name could not be found.

### Font

```csharp
Datalogics.PDFL.Font.Font(string fontName, FontCreateFlags createFlags, WritingMode wrMode)
```

*constructor*

**Parameters**

- `fontName` (`string`): the name of the font to create
- `createFlags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/FontCreateFlags.md)): flags specifying embedding and other options for the use of a font in the document
- `wrMode` ([`WritingMode`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/WritingMode.md)): determines whether text will be printed horizontally or vertically

Find a font with the specified name, and construct a Font object from it.

Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H or Identity-V encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

• TrueTypes used as CID fonts must be embedded.

• All CID fonts that are embedded must be subsetted.

• CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

**Exceptions**

- `BadInput`: A font with the specified name could not be found.

## Properties

### Ascent

```csharp
double Datalogics.PDFL.Font.Ascent { get; }
```

the Ascent value from the font descriptor. This is the maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.

### AvgWidth

```csharp
double Datalogics.PDFL.Font.AvgWidth { get; }
```

the AvgWidth value from the font descriptor. This is the average width of glyphs in the font, or 0 if the value is not defined in the font descriptor.

### BBox

```csharp
Rect Datalogics.PDFL.Font.BBox { get; }
```

The Bounding Box rectangle of the font.

### CapHeight

```csharp
double Datalogics.PDFL.Font.CapHeight { get; }
```

the CapHeight value from the font descriptor. This is the vertical coordinate of the top of flat capital letters, measured from the baseline, or 0 if the value is not defined in the font descriptor.

### CidFontType

```csharp
string Datalogics.PDFL.Font.CidFontType { get; }
```

Get the CID font type of the font.

### Descent

```csharp
double Datalogics.PDFL.Font.Descent { get; }
```

the Descent value from the font descriptor. This is the maximum depth below the baseline reached by glyphs in this font. The value is a negative number.

### Embedded

```csharp
bool Datalogics.PDFL.Font.Embedded { get; }
```

Tests whether the font is embedded in the document it was created for.

### Encoding

```csharp
string Datalogics.PDFL.Font.Encoding { get; }
```

Return the encoding of the font.

For a font created from a system font by name, this is the encoding PDFL gives the font when it is written to a document: WinAnsiEncoding on Windows and Linux, MacRomanEncoding on macOS, or Identity-H/V for a Type0 font. Symbolic fonts (Symbol, ZapfDingbats, Wingdings) use their own built-in encoding and return an empty string.

### EncodingInfo

```csharp
EncodingInfo Datalogics.PDFL.Font.EncodingInfo { get; }
```

Get the populated CEncodingInfo object.

### Flags

```csharp
FontFlags Datalogics.PDFL.Font.Flags { get; }
```

Get the font flags for a font.

### FontList

```csharp
static System.Collections.Generic.IList<Font> Datalogics.PDFL.Font.FontList { get; }
```

*static*

### FullName

```csharp
string Datalogics.PDFL.Font.FullName { get; }
```

Get the Full Name of the font.

### GlyphWidths

```csharp
System.Collections.Generic.IList<System.Double> Datalogics.PDFL.Font.GlyphWidths { get; }
```

Retrieve the glyph width table for the font's single-byte encoding.

Returns the 256-entry glyph advance table in character-space units (1000 units per em). For the user-space width of character code `c` at font sizes:`widths[c] * s / 1000.0`.

The returned vector always has 256 entries; positions outside the font's defined encoding are filled with whatever advance the font reports for unmapped codes (typically zero or the missing-glyph advance). This API is therefore only meaningful for simple single-byte fonts — Type 1, TrueType with a simple encoding, etc. CID / Type 0 fonts need per-glyph measurement via MeasureTextWidth instead.

### ItalicAngle

```csharp
double Datalogics.PDFL.Font.ItalicAngle { get; }
```

the ItalicAngle value from the font descriptor. This is the angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font, defined in the font descriptor.

### Leading

```csharp
double Datalogics.PDFL.Font.Leading { get; }
```

the Leading value from the font descriptor. This is the spacing between baselines of consecutive lines of text, or 0 if the value is not defined in the font descriptor.

### MaxWidth

```csharp
double Datalogics.PDFL.Font.MaxWidth { get; }
```

the MaxWidth value from the font descriptor. This is the maximum glyph width present in the font, or 0 if the value is not defined in the font descriptor.

### MissingWidth

```csharp
double Datalogics.PDFL.Font.MissingWidth { get; }
```

the MissingWidth value from the font descriptor. This is the width given to characters that do not have corresponding glyphs defined in the font, or 0 if the value is not defined in the font descriptor.

### Name

```csharp
string Datalogics.PDFL.Font.Name { get; }
```

Get the name of the font.

### PDFDict

```csharp
PDFDict Datalogics.PDFL.Font.PDFDict { get; }
```

Retrieve the PDFDict representation of this font.

### StemH

```csharp
double Datalogics.PDFL.Font.StemH { get; }
```

the StemH value from the font descriptor. This is the vertical thickness of the dominant horizontal stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

### StemV

```csharp
double Datalogics.PDFL.Font.StemV { get; }
```

the StemV value from the font descriptor. This is the horizontal thickness of the dominant vertical stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

### Type

```csharp
string Datalogics.PDFL.Font.Type { get; }
```

Get the type of the font.

### WritingMode

```csharp
WritingMode Datalogics.PDFL.Font.WritingMode { get; }
```

Get the writing mode of the font. The writing mode of the fontwhether it will place glyphs horizontally or vertically. Text written with this font will run in the direction of the writing mode

.

### XHeight

```csharp
double Datalogics.PDFL.Font.XHeight { get; }
```

the XHeight value from the font descriptor. This is the vertical coordinate of the top of flat nonascending lowercase letters in fonts that have Latin characters, as measured from the baseline, or 0 if the value is not defined in the font descriptor.

## Methods

### Dispose

```csharp
void Datalogics.PDFL.Font.Dispose()
```

**Returns:** `void`

### EmbedNow

```csharp
void Datalogics.PDFL.Font.EmbedNow(Document doc)
```

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md)): the Document the Font is embedded into

**Returns:** `void`

Embeds the Font.

### FindIndexOfFirstUnrepresentableChar

```csharp
uint Datalogics.PDFL.Font.FindIndexOfFirstUnrepresentableChar(string text)
```

**Parameters**

- `text` (`string`): the text to check

**Returns:** `uint`

The index of the first character that cannot be represented in this font.

Find the index of the first character that cannot be represented in this font. This will return the index of the first character in the string for which the font has no glyph. If all characters can be represented (i.e. if IsTextRepresentable() would return true), this will return the length of the string.

### IsFromDoc

```csharp
bool Datalogics.PDFL.Font.IsFromDoc()
```

**Returns:** `bool`

true if the font was loaded from a document, false if it was created from a system font.

Determine whether this font was obtained from an existing document rather than the system.

### IsTextRepresentable

```csharp
bool Datalogics.PDFL.Font.IsTextRepresentable(string text)
```

**Parameters**

- `text` (`string`): the text to check

**Returns:** `bool`

true if all characters in the text have corresponding glyphs in this font.

Is this text representable in this font?

### MeasureTextWidth

```csharp
double Datalogics.PDFL.Font.MeasureTextWidth(string text, double fontSize)
```

**Parameters**

- `text` (`string`): the Text to be measured
- `fontSize` (`double`): the Font size to be used

**Returns:** `double`

The width of the text in points.

Measures the width of the specified text in points, using the Font at the specified size.
