> For the complete documentation index, see [llms.txt](https://docs.febucci.com/text-animator-unreal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.febucci.com/text-animator-unreal/integrations/how-to-perform-your-own-text-shaping-text-layout.md).

# How to perform your own Text Shaping/Text Layout

Shaping is the act of transforming a simple String into a series of important data which the system needs to draw that text. After shaping comes layout: a sequence of calculations which tell the text where/how to be rendered. Think of features like justification, word wrapping, overflow handling etc. Animating the text, shaping it and laying it out are three very distinctive operations, that's why the plugin heavily separates these 3 concerns. In particular, shaping and layout are demanded to "TextGenerators", classes that have an API designed to take care of those functionalities and return what the plugin needs to just animate.

### TextGenerator Base Class <a href="#actions-base-class" id="actions-base-class"></a>

When creating a new class, inherit from `UBaseTextGenerator` defined in "BaseTextGenerator.h".

```csharp
UCLASS()
class TEXTANIMATORFEBUCCI_API UYourTextGenerator : public UBaseTextGenerator
{
    //[...]
```

### TextGenerator Properties <a href="#actions-base-class" id="actions-base-class"></a>

At creation (or when layout changes), all TextGenerators by default get passed in these properties by the plugin:

* FText Text
* FSlateFontInfo Font
* ETextJustify::Type HorizontalJustification
* ETextOverflowMode TextOverflowMode
* bool WordWrapping
* float CharacterSpacing
* float WordSpacing
* float LineSpacing
* ETextJustifyVertical VerticalJustification

So remember you can use them in your custom implemented logic.

### ShapeText Method <a href="#doaction-method" id="doaction-method"></a>

This is where all the shaping takes place. The plugin will pass in an empty array where it expects the final shaped Glyphs that will be later used for layout.

```csharp
void UYourTextGenerator::ShapeText_Implementation(TArray<FAnimTextGlyph>& OutGlyphs)
{
    //Start from the already populated Text and Font properties
    //to shape your glyphs. Then store them in OutGlyphs
}
```

### LayoutGlyphs Method <a href="#doaction-method" id="doaction-method"></a>

This is where all the layout takes place. OutGlyphs is the same as in ShapeText: an empty array where the Glyphs resulting from the layout operations must be stored. InGlyphs are the current Glyphs cached by the plugin.

```csharp
void UDefaultTextGenerator::LayoutGlyphs_Implementation(
	const TArray<FAnimTextGlyph>& InGlyphs,
	TArray<FAnimTextGlyph>& OutGlyphs)
{
    //Perform any sort of modifications on Glyphs like moving them, marking
    //them as IsRendered = false, etc etc
}
```

### OnBeforeRenderingGlyphs Method <a href="#doaction-method" id="doaction-method"></a>

This hook was left for any non-layout dependant custom final logic to be executed just before rendering the glyphs. An example would be per-style rendering effects (drop shadows, outlines, glows, etc).

Passed arrays are the same as LayoutGlyphs.

```csharp
void UDefaultTextGenerator::OnBeforeRenderingGlyphs_Implementation(
    const TArray<FAnimTextGlyph>& InGlyphs, 
    TArray<FAnimTextGlyph>& OutGlyphs)
{
    //Perform any sort of modifications on Glyphs like moving them, marking
    //them as IsRendered = false, etc etc
}
```

### Creating and pluggin a TextGenerator <a href="#doaction-method" id="doaction-method"></a>

After creating a new class inheriting from UBaseTextGenerator, either via Blueprints or C++, that class will appear in the TextGenerator property dropdown in the plugin's widget details:

<figure><img src="/files/eWJZ1I5mZMcutuo9fQz5" alt="" width="496"><figcaption></figcaption></figure>

### DefaultTextGenerator Example <a href="#doaction-method" id="doaction-method"></a>

Remember we included a fully fledged `UDefaultTextGenerator` class where you can see how we implemented text shaping and layout from scratch.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.febucci.com/text-animator-unreal/integrations/how-to-perform-your-own-text-shaping-text-layout.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
