Loading...
Searching...
No Matches
juce::TextLayout Class Referencefinal

## Detailed Description

A Pre-formatted piece of text, which may contain multiple fonts and colours.

A TextLayout is created from an AttributedString, and once created can be quickly drawn into a Graphics context.

See also
  AttributedString

The documentation for this class was generated from the following file:

- juce_graphics/fonts/juce_TextLayout.h

## Classes

class | Glyph
| A positioned glyph. More...
class | Run
| A sequence of glyphs with a common font and colour. More...
class | Line
| A line containing a sequence of glyph-runs. More...

## Public Types

using | iterator = DereferencingIterator< Line* const*>
using | const_iterator = DereferencingIterator<const Line* const*>

## Public Member Functions

| TextLayout ()
| Creates an empty layout.
| TextLayout (const TextLayout &)
TextLayout & | operator= (const TextLayout &)
| TextLayout (TextLayout &&) noexcept
TextLayout & | operator= (TextLayout &&) noexcept
| ~TextLayout ()
| Destructor.
void | createLayout (const AttributedString &, float maxWidth)
| Creates a layout from the given attributed string.
void | createLayout (const AttributedString &, float maxWidth, float maxHeight)
| Creates a layout from the given attributed string, given some size constraints.
void | createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth)
| Creates a layout, attempting to choose a width which results in lines of a similar length.
void | createLayoutWithBalancedLineLengths (const AttributedString &, float maxWidth, float maxHeight)
| Creates a layout, attempting to choose a width which results in lines of a similar length.
void | draw (Graphics &, Rectangle< float > area) const
| Draws the layout within the specified area.
float | getWidth () const noexcept
| Returns the maximum width of the content.
float | getHeight () const noexcept
| Returns the maximum height of the content.
int | getNumLines () const noexcept
| Returns the number of lines in the layout.
Line & | getLine (int index) const noexcept
| Returns one of the lines.
void | addLine (std::unique_ptr< Line >)
| Adds a line to the layout.
void | ensureStorageAllocated (int numLinesNeeded)
| Pre-allocates space for the specified number of lines.
iterator | begin ()
| Returns an iterator over the lines of content.
const_iterator | begin () const
const_iterator | cbegin () const
iterator | end ()
| Returns an iterator over the lines of content.
const_iterator | end () const
const_iterator | cend () const
void | recalculateSize ()
| If you modify the TextLayout after creating it, call this to compute the new dimensions of the content.

## Static Public Member Functions

static Rectangle< float > | getStringBounds (const AttributedString &string)
| This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.
static Rectangle< float > | getStringBounds (const Font &font, StringRef text)
| This convenience function adds text to a TextLayout using the specified font and returns the bounding box of the text after shaping.
static float | getStringWidth (const AttributedString &string)
| This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.
static float | getStringWidth (const Font &font, StringRef text)
| This convenience function adds text to a TextLayout using the specified font and returns the width of the bounding box of the text after shaping.

## Member Typedef Documentation

## iterator

using juce::TextLayout::iterator = DereferencingIterator< Line* const*>

## const_iterator

using juce::TextLayout::const_iterator = DereferencingIterator<const Line* const*>

## Constructors and Destructors

## TextLayout() [1/3]

juce::TextLayout::TextLayout | ( |  | ) |

Creates an empty layout.

Having created a TextLayout, you can populate it using createLayout() or createLayoutWithBalancedLineLengths().

Referenced by getStringBounds(), operator=(), operator=(), TextLayout(), TextLayout(), and ~TextLayout().

## TextLayout() [2/3]

juce::TextLayout::TextLayout | ( | const TextLayout & |  | ) |

References TextLayout().

## TextLayout() [3/3]

juce::TextLayout::TextLayout | ( | TextLayout && |  | ) |

noexcept

References TextLayout().

## ~TextLayout()

juce::TextLayout::~TextLayout | ( |  | ) |

Destructor.

References TextLayout().

## Member Functions

## operator=() [1/2]

TextLayout & juce::TextLayout::operator= | ( | const TextLayout & |  | ) |

References TextLayout().

## operator=() [2/2]

TextLayout & juce::TextLayout::operator= | ( | TextLayout && |  | ) |

noexcept

References TextLayout().

## createLayout() [1/2]

void juce::TextLayout::createLayout | ( | const AttributedString & | ,
|  | float | maxWidth )

Creates a layout from the given attributed string.

This will replace any data that is currently stored in the layout.

References createLayout().

Referenced by createLayout(), createLayout(), and getStringBounds().

## createLayout() [2/2]

void juce::TextLayout::createLayout | ( | const AttributedString & | ,
|  | float | maxWidth,
|  | float | maxHeight )

Creates a layout from the given attributed string, given some size constraints.

This will replace any data that is currently stored in the layout.

References createLayout().

## createLayoutWithBalancedLineLengths() [1/2]

void juce::TextLayout::createLayoutWithBalancedLineLengths | ( | const AttributedString & | ,
|  | float | maxWidth )

Creates a layout, attempting to choose a width which results in lines of a similar length.

This will be slower than the normal createLayout method, but produces a tidier result.

References createLayoutWithBalancedLineLengths().

Referenced by createLayoutWithBalancedLineLengths(), and createLayoutWithBalancedLineLengths().

## createLayoutWithBalancedLineLengths() [2/2]

void juce::TextLayout::createLayoutWithBalancedLineLengths | ( | const AttributedString & | ,
|  | float | maxWidth,
|  | float | maxHeight )

Creates a layout, attempting to choose a width which results in lines of a similar length.

This will be slower than the normal createLayout method, but produces a tidier result.

References createLayoutWithBalancedLineLengths().

## draw()

void juce::TextLayout::draw | ( | Graphics & | ,
|  | Rectangle< float > | area ) const

Draws the layout within the specified area.

The position of the text within the rectangle is controlled by the justification flags set in the original AttributedString that was used to create this layout.

References draw().

Referenced by draw().

## getWidth()

float juce::TextLayout::getWidth | ( |  | ) | const

inline noexcept

Returns the maximum width of the content.

References getWidth().

Referenced by getWidth().

## getHeight()

float juce::TextLayout::getHeight | ( |  | ) | const

inline noexcept

Returns the maximum height of the content.

## getNumLines()

int juce::TextLayout::getNumLines | ( |  | ) | const

inline noexcept

Returns the number of lines in the layout.

Referenced by getStringBounds().

## getLine()

Line & juce::TextLayout::getLine | ( | int | index | ) | const

noexcept

Returns one of the lines.

Referenced by getStringBounds().

## addLine()

void juce::TextLayout::addLine | ( | std::unique_ptr< Line > |  | ) |

Adds a line to the layout.

The layout will take ownership of this line object and will delete it when it is no longer needed.

## ensureStorageAllocated()

void juce::TextLayout::ensureStorageAllocated | ( | int | numLinesNeeded | ) |

Pre-allocates space for the specified number of lines.

## begin() [1/2]

iterator juce::TextLayout::begin | ( |  | ) |

inline

Returns an iterator over the lines of content.

## begin() [2/2]

const_iterator juce::TextLayout::begin | ( |  | ) | const

inline

## cbegin()

const_iterator juce::TextLayout::cbegin | ( |  | ) | const

inline

## end() [1/2]

iterator juce::TextLayout::end | ( |  | ) |

inline

Returns an iterator over the lines of content.

## end() [2/2]

const_iterator juce::TextLayout::end | ( |  | ) | const

inline

## cend()

const_iterator juce::TextLayout::cend | ( |  | ) | const

inline

## recalculateSize()

void juce::TextLayout::recalculateSize | ( |  | ) |

If you modify the TextLayout after creating it, call this to compute the new dimensions of the content.

## getStringBounds() [1/2]

Rectangle< float > juce::TextLayout::getStringBounds | ( | const AttributedString & | string | ) |

inline static

This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.

The returned bounding box is positioned with its origin at the left end of the text's baseline.

References createLayout(), getLine(), juce::TextLayout::Line::getLineBounds(), getNumLines(), and TextLayout().

Referenced by getStringBounds(), getStringWidth(), and getStringWidth().

## getStringBounds() [2/2]

Rectangle< float > juce::TextLayout::getStringBounds | ( | const Font & | font,
|  | StringRef | text )

inline static

This convenience function adds text to a TextLayout using the specified font and returns the bounding box of the text after shaping.

The returned bounding box is positioned with its origin at the left end of the text's baseline.

References juce::AttributedString::append(), and getStringBounds().

## getStringWidth() [1/2]

float juce::TextLayout::getStringWidth | ( | const AttributedString & | string | ) |

inline static

This convenience function adds an AttributedString to a TextLayout and returns the bounding box of the text after shaping.

References getStringBounds().

## getStringWidth() [2/2]

float juce::TextLayout::getStringWidth | ( | const Font & | font,
|  | StringRef | text )

inline static

This convenience function adds text to a TextLayout using the specified font and returns the width of the bounding box of the text after shaping.

References getStringBounds().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited