# Text Class

> A container that represents a series of text elements and characters.

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

```cpp
class Text : Element
```

**Namespace:** `datalogics_interface`

**Inherits from:** [`Element`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md)

## Description

A container that represents a series of text elements and characters.

A Text object is container that represents both a series of TextRun elements and a series of text characters. Operations can be performed on individual TextRuns within a Text or on individual characters within a Text by specifying the index of the individual TextRun or character. All indices start at 0.

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

**Uses types:** [`Clip`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md), [`Element`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Element.md), [`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md), [`ElementType`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementType.md), [`Matrix`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md), [`Point`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md), [`Rect`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md), [`Text`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Text.md), [`TextFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/TextFlags.md), [`TextRun`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextRun.md)

## Constructors

### Text

```cpp
datalogics_interface::Text::Text()
```

*constructor*

Create a new, empty Text object.

### Text

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

*constructor*

**Parameters**

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

### ~Text

```cpp
datalogics_interface::Text::~Text() override
```

*destructor*

## Methods

### add_glyphs

```cpp
void datalogics_interface::Text::add_glyphs(const std::vector< std::uint8_t > &glyph_ids, const std::vector< std::uint8_t > &uni_text, Font &font, GraphicState &gs, TextState &ts, const Matrix &matrix, TextFlags flags)
```

**Parameters**

- `glyph_ids` (`const std::vector< std::uint8_t > &`): Glyphs IDs in the specified font for adding to the page's content
- `uni_text` (`const std::vector< std::uint8_t > &`): Unicode codes for the specified glyph IDs
- `font` ([`Font &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)): - Font for wich GlyphIDs were specified
- `gs` ([`GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): - The GraphicsState for Text element
- `ts` ([`TextState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextState.md)): - TextState flags
- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): - matrix for the Text element
- `flags` ([`TextFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/TextFlags.md)): - TextFlags that specifies what kind of text to add

**Returns:** `void`

Adds Unicode text to a Text object

### add_glyphs

```cpp
void datalogics_interface::Text::add_glyphs(const std::vector< std::uint8_t > &glyph_ids, const std::vector< std::uint8_t > &uni_text, Font &font, GraphicState &gs, TextState &ts, const Matrix &matrix, TextFlags flags, int index)
```

**Parameters**

- `glyph_ids` (`const std::vector< std::uint8_t > &`): Glyphs IDs in the specified font for adding to the page's content
- `uni_text` (`const std::vector< std::uint8_t > &`): Unicode codes for the specified glyph IDs
- `font` ([`Font &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Font.md)): - Font for wich GlyphIDs were specified
- `gs` ([`GraphicState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/GraphicState.md)): - The GraphicsState for Text element
- `ts` ([`TextState &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextState.md)): - TextState flags
- `matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): - matrix for the Text element
- `flags` ([`TextFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/TextFlags.md)): - TextFlags that specifies what kind of text to add
- `index` (`int`)

**Returns:** `void`

Adds Unicode text to a Text object

### add_run

```cpp
void datalogics_interface::Text::add_run(TextRun &run)
```

**Parameters**

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

**Returns:** `void`

Adds a TextRun to the end of this text element.

### add_run

```cpp
void datalogics_interface::Text::add_run(TextRun &run, int index)
```

**Parameters**

- `run` ([`TextRun &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/TextRun.md)): The TextRun to append.
- `index` (`int`)

**Returns:** `void`

Adds a TextRun to the end of this text element.

### change_text_matrix_for_text_run

```cpp
void datalogics_interface::Text::change_text_matrix_for_text_run(const Matrix &new_matrix, int text_run_index)
```

**Parameters**

- `new_matrix` ([`const Matrix &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Matrix.md)): The new transformation matrix to use for the TextRun.
- `text_run_index` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

**Returns:** `void`

Changes the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

### clone

```cpp
std::unique_ptr< Element > datalogics_interface::Element::clone(ElementCloneFlags flags) const
```

**Parameters**

- `flags` ([`ElementCloneFlags`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/enum/ElementCloneFlags.md))

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

The copied element.

Makes a copy of the element.

Make a copy of an element to obtain a new element that has a distinct set of attributes.

Note: TextRun objects may not be cloned.

### clone

```cpp
std::unique_ptr< Text > datalogics_interface::Text::clone() const
```

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

Makes a copy of this Text object.

### find_text_run_index_for_character

```cpp
int datalogics_interface::Text::find_text_run_index_for_character(int char_index) const
```

**Parameters**

- `char_index` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

**Returns:** `int`

The index of the TextRun that contains the character specified by characterIndex.

Finds the index of the TextRun that contains the nth character in a Text object.

### get_advance_for_character

```cpp
Point datalogics_interface::Text::get_advance_for_character(int index) const
```

**Parameters**

- `index` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

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

A value specifying both the horizontal and vertical components of the advance width of a character in user space.

Gets the advance width of a character, in user space. The advance width is the amount by which the current point advances when the character is drawn.

Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

### get_advance_for_text_run

```cpp
Point datalogics_interface::Text::get_advance_for_text_run(int index) const
```

**Parameters**

- `index` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

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

A value specifying both the horizontal and vertical components of the advance width of a TextRun in user space.

Gets the advance width of a TextRun, in user space. The advance width is the amount by which the current point advances when the TextRun is drawn.

Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

### get_bounding_box

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

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

The bounding box for this element. The coordinates of the bounding box are specified in user space coordinates, relative to the element's Content. Note that user space coordinates correspond to unrotated pages; any rotation specified in the page dictionary is not taken into account.

The bounding box for this element.

The bounding box is a rectangle that is guaranteed to encompass the element, but it is not guaranteed to be the smallest box that could contain the element. For example, if the element is a Path that contains an arc, the bounding box encompasses the bezier control points, and not just the curve itself.

### get_bounding_box_for_character

```cpp
Rect datalogics_interface::Text::get_bounding_box_for_character(int index) const
```

**Parameters**

- `index` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0)

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

A Rect specifying the bounding box for the character.

The bounding box for a character in this text element.

### get_clip

```cpp
std::unique_ptr< Clip > datalogics_interface::Element::get_clip()
```

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

The current Clip for this Element, or NULL if no clip is set.

Gets the current Clip for an Element.

### get_element_type

```cpp
ElementType datalogics_interface::Element::get_element_type() const
```

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

Returns the runtime type of this element.

### get_matrix

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

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

The current transformation matrix applied to this element.

The transformation matrix for the element.

### get_number_of_characters

```cpp
int datalogics_interface::Text::get_number_of_characters() const
```

**Returns:** `int`

The number of characters in this text element.

### get_number_of_runs

```cpp
int datalogics_interface::Text::get_number_of_runs() const
```

**Returns:** `int`

The number of text runs in this text element.

### get_run

```cpp
std::unique_ptr< TextRun > datalogics_interface::Text::get_run(int index)
```

**Parameters**

- `index` (`int`): The zero-based index of the TextRun to retrieve.

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

The TextRun at the specified index.

Obtains the TextRun at the specified index.

### get_text_matrix_for_character

```cpp
Matrix datalogics_interface::Text::get_text_matrix_for_character(int index) const
```

**Parameters**

- `index` (`int`): The index of a character, relative to the Text object (the first character in the Text object is at index 0).

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

The transformation matrix for the character specified by characterIndex.

Gets the transformation matrix from user space to the current text space for the specified character. The H and V values of the matrix indicate the origin of the first character.

### get_text_matrix_for_text_run

```cpp
Matrix datalogics_interface::Text::get_text_matrix_for_text_run(int index) const
```

**Parameters**

- `index` (`int`): The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).

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

The transformation matrix for the TextRun specified by TextRunIndex.

Gets the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

### operator=

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

**Parameters**

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

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

### point_intersects_character

```cpp
bool datalogics_interface::Text::point_intersects_character(const Point &p, int index)
```

**Parameters**

- `p` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): The point to test, in user space coordinates.
- `index` (`int`): The index of the character. The first character in the Text has an index of 0.

**Returns:** `bool`

true if the point is on the character, false if the point is not on the character.

Tests whether a point is on a specified character within this Text object.

### point_intersects_text_run

```cpp
bool datalogics_interface::Text::point_intersects_text_run(const Point &p, int index)
```

**Parameters**

- `p` ([`const Point &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Point.md)): The point to test, in user space coordinates.
- `index` (`int`): The index of the TextRun. The first TextRun in the Text has an index of 0.

**Returns:** `bool`

true if the point is on the TextRun, false if the point is not on the TextRun.

Tests whether a point is on a specified TextRun within this Text object.

### rect_intersects_character

```cpp
bool datalogics_interface::Text::rect_intersects_character(const Rect &r, int index)
```

**Parameters**

- `r` ([`const Rect &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)): The rect to test, in user space coordinates.
- `index` (`int`): The index of the character. The first character in the Text has an index of 0.

**Returns:** `bool`

true if any part of the rectangle is on the character, false if no part of the rectangle is on the character.

Tests whether any part of a rectangle is on a specified character within this Text object.

### rect_intersects_text_run

```cpp
bool datalogics_interface::Text::rect_intersects_text_run(const Rect &r, int index)
```

**Parameters**

- `r` ([`const Rect &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/struct/Rect.md)): The rect to test, in user space coordinates.
- `index` (`int`): The index of the TextRun. The first TextRun in the Text has an index of 0.

**Returns:** `bool`

true if any part of the rectangle is on the TextRun, false if no part of the rectangle is on the TextRun.

Tests whether any part of a rectangle is on a specified TextRun within this Text object.

### remove_runs

```cpp
void datalogics_interface::Text::remove_runs(int index, int count)
```

**Parameters**

- `index` (`int`): Start position of range to delete
- `count` (`int`): Count of TextRuns to delete

**Returns:** `void`

Removes a count of TextRuns, starting from index

### rotate

```cpp
void datalogics_interface::Element::rotate(double theta)
```

**Parameters**

- `theta` (`double`): The rotation angle in degrees.

**Returns:** `void`

Rotate an element by theta degrees counterclockwise using the matrix [ cos T sin T -sin T cos T 0 0 ].

### scale

```cpp
void datalogics_interface::Element::scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): The horizontal scale factor.
- `sy` (`double`): The vertical scale factor.

**Returns:** `void`

Scale an element by (sx,sy) units using the matrix [ sx 0 0 sy 0 0 ].

### set_clip

```cpp
void datalogics_interface::Element::set_clip(Clip &clip)
```

**Parameters**

- `clip` ([`Clip &`](https://docs.datalogics.com/apdfl21/ModernCPP/21.4.0/class/Clip.md)): The clip to set as the current clip for this element, or NULL to remove clipping.

**Returns:** `void`

Sets the current Clip for an Element.

### set_matrix

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

**Parameters**

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

**Returns:** `void`

Set the transformation matrix for the element.

### split_text_run_at_character

```cpp
void datalogics_interface::Text::split_text_run_at_character(int split_location)
```

**Parameters**

- `split_location` (`int`): The split location, relative to the Text object.

**Returns:** `void`

Splits the TextRun containing the character at the specified location into two contiguous TextRuns. The character at the specified index will be part of the first TextRun.

### translate

```cpp
void datalogics_interface::Element::translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): The horizontal translation distance in user space units.
- `ty` (`double`): The vertical translation distance in user space units.

**Returns:** `void`

Translate an element by (tx,ty) units using the matrix [ 1 0 0 1 tx ty ].

### try_as

```cpp
T * datalogics_interface::Element::try_as()
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `T *`

Attempt to downcast this element to a derived type. Returns a pointer to the derived type, or nullptr if the type doesn't match.

### try_as

```cpp
const T * datalogics_interface::Element::try_as() const
```

**Parameters**

- (unnamed) (`typename T`)

**Returns:** `const T *`

Const overload of try_as(). Returns a const pointer, or nullptr.
