# Font Class

> Represents a font.

- Product: Adobe PDF Library 21
- Language: Modern C++
- Version: 21.4.0
- HTML page: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font
- Version index: https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/llms.txt

```cpp
class Font
```

**Namespace:** `datalogics_interface`

## 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/ModernCPP/21.4.0/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md), [`TextRun`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextRun.md), [`WatermarkTextParams`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/WatermarkTextParams.md)

**Uses types:** [`EncodingInfo`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/EncodingInfo.md), [`Font`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md), [`FontCreateFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/FontCreateFlags.md), [`FontFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/FontFlags.md), [`PDFDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md), [`WritingMode`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/WritingMode.md)

## Constructors

### Font

```cpp
datalogics_interface::Font::Font(const std::string &font_name)
```

*constructor*

**Parameters**

- `font_name` (`const std::string &`)

Default constructor.

Direct construction is prohibited.

### Font

```cpp
datalogics_interface::Font::Font(const std::string &font_name, FontCreateFlags flags)
```

*constructor*

**Parameters**

- `font_name` (`const std::string &`)
- `flags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/FontCreateFlags.md))

Default constructor.

Direct construction is prohibited.

### Font

```cpp
datalogics_interface::Font::Font(const std::string &font_name, FontCreateFlags flags, WritingMode mode)
```

*constructor*

**Parameters**

- `font_name` (`const std::string &`)
- `flags` ([`FontCreateFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/FontCreateFlags.md))
- `mode` ([`WritingMode`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/WritingMode.md))

Default constructor.

Direct construction is prohibited.

### Font

```cpp
datalogics_interface::Font::Font(Font &&) noexcept
```

*constructor*

**Parameters**

- (unnamed) ([`Font &&`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md))

### ~Font

```cpp
datalogics_interface::Font::~Font()
```

*destructor*

## Methods

### embed_now

```cpp
void datalogics_interface::Font::embed_now(Document &doc) const
```

**Parameters**

- `doc` ([`Document &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Document.md)): the Document the Font is embedded into

**Returns:** `void`

Embeds the Font.

### find_index_of_first_unrepresentable_char

```cpp
unsigned int datalogics_interface::Font::find_index_of_first_unrepresentable_char(const std::string &text) const
```

**Parameters**

- `text` (`const std::string &`): the text to check

**Returns:** `unsigned int`

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.

### get_ascent

```cpp
double datalogics_interface::Font::get_ascent() const
```

**Returns:** `double`

The Ascent value of the font in glyph space units.

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.

### get_avg_width

```cpp
double datalogics_interface::Font::get_avg_width() const
```

**Returns:** `double`

The AvgWidth value of the font in glyph space units, or 0 if not defined.

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.

### get_bbox

```cpp
Rect datalogics_interface::Font::get_bbox() const
```

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)

The bounding box of the font as a Rect, in glyph space units.

The Bounding Box rectangle of the font.

### get_cap_height

```cpp
double datalogics_interface::Font::get_cap_height() const
```

**Returns:** `double`

The CapHeight value of the font in glyph space units, or 0 if not defined.

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.

### get_cid_font_type

```cpp
std::string datalogics_interface::Font::get_cid_font_type() const
```

**Returns:** `std::string`

The CID font type, or an empty string if not a CID font.

Get the CID font type of the font.

### get_descent

```cpp
double datalogics_interface::Font::get_descent() const
```

**Returns:** `double`

The descent value of the font.

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.

### get_embedded

```cpp
bool datalogics_interface::Font::get_embedded() const
```

**Returns:** `bool`

true if the font is embedded, false if it is not.

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

### get_encoding

```cpp
std::string datalogics_interface::Font::get_encoding() const
```

**Returns:** `std::string`

The encoding of the font, eg: WinAnsiEncoding MacRomanEncoding

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.

### get_encoding_info

```cpp
std::unique_ptr< EncodingInfo > datalogics_interface::Font::get_encoding_info() const
```

**Returns:** [`std::unique_ptr< EncodingInfo >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/EncodingInfo.md)

The EncodingInfo object containing encoding details for this font.

Get the populated CEncodingInfo object.

### get_flags

```cpp
FontFlags datalogics_interface::Font::get_flags() const
```

**Returns:** [`FontFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/FontFlags.md)

The font descriptor flags as a CFontFlags bitmask.

Get the font flags for a font.

### get_font_list

```cpp
static std::vector< Font > datalogics_interface::Font::get_font_list()
```

*static*

**Returns:** [`std::vector< Font >`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)

The list of available fonts.

Get a list of available fonts.

### get_full_name

```cpp
std::string datalogics_interface::Font::get_full_name() const
```

**Returns:** `std::string`

The Full Name of the font. Note: This method only returns a meaningful result for TrueType-based technology fonts.

Get the Full Name of the font.

### get_glyph_widths

```cpp
std::vector< double > datalogics_interface::Font::get_glyph_widths() const
```

**Returns:** `std::vector< double >`

256 glyph advances in 1000-em character-space units.

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

Retrieve the 256-entry glyph width table for this font's single-byte encoding. Values are in character-space units (1000 per em); for the user-space width of character code `c` at font size `s` use `widths[c] * s / 1000.0`. Only meaningful for simple single-byte fonts; CID/Type-0 fonts should use measure_text_width.

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 size s: 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.

### get_italic_angle

```cpp
double datalogics_interface::Font::get_italic_angle() const
```

**Returns:** `double`

The ItalicAngle value of the font in degrees.

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.

### get_leading

```cpp
double datalogics_interface::Font::get_leading() const
```

**Returns:** `double`

The leading value of the font, or 0 if not present.

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.

### get_max_width

```cpp
double datalogics_interface::Font::get_max_width() const
```

**Returns:** `double`

The MaxWidth value of the font in glyph space units, or 0 if not present.

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.

### get_missing_width

```cpp
double datalogics_interface::Font::get_missing_width() const
```

**Returns:** `double`

The MissingWidth value of the font in glyph space units, or 0 if not present.

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.

### get_name

```cpp
std::string datalogics_interface::Font::get_name() const
```

**Returns:** `std::string`

The name of the font.

Get the name of the font.

### get_pdf_dict

```cpp
PDFDict datalogics_interface::Font::get_pdf_dict() const
```

**Returns:** [`PDFDict`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/PDFDict.md)

The PDFDict for this font's COS dictionary object.

Retrieve the PDFDict representation of this font.

### get_stem_h

```cpp
double datalogics_interface::Font::get_stem_h() const
```

**Returns:** `double`

The StemH value of the font in glyph space units, or 0 if not present.

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.

### get_stem_v

```cpp
double datalogics_interface::Font::get_stem_v() const
```

**Returns:** `double`

The StemV value of the font in glyph space units, or 0 if not present.

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.

### get_type

```cpp
std::string datalogics_interface::Font::get_type() const
```

**Returns:** `std::string`

The type of the font. Type0 Type1 MMType1 TrueType

Get the type of the font.

### get_writing_mode

```cpp
WritingMode datalogics_interface::Font::get_writing_mode() const
```

**Returns:** [`WritingMode`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/WritingMode.md)

The WritingMode of the font.

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.

### get_x_height

```cpp
double datalogics_interface::Font::get_x_height() const
```

**Returns:** `double`

The XHeight value of the font in glyph space units, or 0 if not present.

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.

### is_from_doc

```cpp
bool datalogics_interface::Font::is_from_doc() const
```

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

### is_text_representable

```cpp
bool datalogics_interface::Font::is_text_representable(const std::string &text) const
```

**Parameters**

- `text` (`const std::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?

### measure_text_width

```cpp
double datalogics_interface::Font::measure_text_width(const std::string &text, double font_size) const
```

**Parameters**

- `text` (`const std::string &`): the Text to be measured
- `font_size` (`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.

### operator=

```cpp
Font & datalogics_interface::Font::operator=(Font &&) noexcept
```

**Parameters**

- (unnamed) ([`Font &&`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md))

**Returns:** [`Font &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)
