# TextRun Class

> Represents one or more contiguous characters in a text object.

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

```cpp
class TextRun
```

**Namespace:** `datalogics_interface`

## Description

Represents one or more contiguous characters in a text object.

@structure PDEGraphicState @structure PDETextState @structure PDETextItem

All the characters contained within a text run have the same style, color, font, and size.

**Referenced by:** [`Text`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Text.md)

**Uses types:** [`Font`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md), [`GraphicState`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md), [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md), [`TextState`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextState.md)

## Constructors

### TextRun

```cpp
datalogics_interface::TextRun::TextRun(const std::string &text, Font &font, GraphicState &gstate, TextState &tstate, const Matrix &matrix)
```

*constructor*

**Parameters**

- `text` (`const std::string &`): The text content for this run.
- `font` ([`Font &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)): The font to use for rendering the text.
- `gstate` ([`GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): The graphic state (colors, line width, etc.) for this text run.
- `tstate` ([`TextState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextState.md)): The text state (character spacing, word spacing, font size, etc.) for this text run.
- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): The transformation matrix positioning this text run in user space.

Creates a new TextRun with the specified text, font, graphic state, text state, and matrix.

### TextRun

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

*constructor*

**Parameters**

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

### ~TextRun

```cpp
datalogics_interface::TextRun::~TextRun()
```

*destructor*

## Methods

### clear_graphic_state

```cpp
void datalogics_interface::TextRun::clear_graphic_state()
```

**Returns:** `void`

Removes the graphic state from this text run.

### get_advance

```cpp
double datalogics_interface::TextRun::get_advance() const
```

**Returns:** `double`

The advance width of this text run.

Deprecated, use Text.GetAdvanceForTextRun(int textRunIndex) instead. This version does not indicate the direction of the advance width.

The advance width of this run of text, in user space.

The advance width is the amount by which the current point advances when the text run is drawn.

### get_bounding_box

```cpp
Rect datalogics_interface::TextRun::get_bounding_box() const
```

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

Represents one or more contiguous characters in a text object.

@structure PDEGraphicState @structure PDETextState @structure PDETextItem

All the characters contained within a text run have the same style, color, font, and size.

### get_font

```cpp
Font datalogics_interface::TextRun::get_font() const
```

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

The font for this text run.

The font used to render this TextRun.

### get_graphic_state

```cpp
std::unique_ptr< GraphicState > datalogics_interface::TextRun::get_graphic_state()
```

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

The GraphicState for this text run, or null.

The graphic state (colors, line width, etc.) of the text run.

May return null if this element does not have a GraphicState.

### get_matrix

```cpp
Matrix datalogics_interface::TextRun::get_matrix() const
```

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

Represents one or more contiguous characters in a text object.

@structure PDEGraphicState @structure PDETextState @structure PDETextItem

All the characters contained within a text run have the same style, color, font, and size.

### get_text

```cpp
std::string datalogics_interface::TextRun::get_text() const
```

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

The text string for this run.

The Unicode text content of this TextRun.

### get_text_state

```cpp
TextState datalogics_interface::TextRun::get_text_state() const
```

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

The TextState for this text run.

The text state parameters (character spacing, word spacing, font size, etc.) of this TextRun.

### operator=

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

**Parameters**

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

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

### set_font

```cpp
void datalogics_interface::TextRun::set_font(Font &font)
```

**Parameters**

- `font` ([`Font &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)): The new font for this text run.

**Returns:** `void`

The font used to render this TextRun.

### set_graphic_state

```cpp
void datalogics_interface::TextRun::set_graphic_state(const GraphicState &gstate)
```

**Parameters**

- `gstate` ([`const GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): - the new/updated Graphic State for the text run.

**Returns:** `void`

Set the Graphic State of the text run.

### set_matrix

```cpp
void datalogics_interface::TextRun::set_matrix(const Matrix &matrix)
```

**Parameters**

- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md))

**Returns:** `void`

Represents one or more contiguous characters in a text object.

@structure PDEGraphicState @structure PDETextState @structure PDETextItem

All the characters contained within a text run have the same style, color, font, and size.

### set_text

```cpp
void datalogics_interface::TextRun::set_text(const std::string &text)
```

**Parameters**

- `text` (`const std::string &`): The new text content for this run.

**Returns:** `void`

The Unicode text content of this TextRun.
