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

## Detailed Description

A set of glyphs, each with a position.

You can create a GlyphArrangement, text to it and then draw it onto a graphics context. It's used internally by the text methods in the Graphics class, but can be used directly if more control is needed.

See also
  Font, PositionedGlyph

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

- juce_graphics/fonts/juce_GlyphArrangement.h

## Public Types

using | Options = GlyphArrangementOptions

## Public Member Functions

| GlyphArrangement ()
| Creates an empty arrangement.
| GlyphArrangement (const GlyphArrangement &)=default
GlyphArrangement & | operator= (const GlyphArrangement &)=default
| GlyphArrangement (GlyphArrangement &&)=default
GlyphArrangement & | operator= (GlyphArrangement &&)=default
| ~GlyphArrangement ()=default
| Destructor.
int | getNumGlyphs () const noexcept
| Returns the total number of glyphs in the arrangement.
PositionedGlyph & | getGlyph (int index) noexcept
| Returns one of the glyphs from the arrangement.
const PositionedGlyph * | begin () const
const PositionedGlyph * | end () const
void | clear ()
| Clears all text from the arrangement and resets it.
void | addLineOfText (const Font &font, const String &text, float x, float y)
| Appends a line of text to the arrangement.
void | addCurtailedLineOfText (const Font &font, const String &text, float x, float y, float maxWidthPixels, bool useEllipsis)
| Adds a line of text, truncating it if it's wider than a specified size.
void | addJustifiedText (const Font &font, const String &text, float x, float y, float maxLineWidth, Justification horizontalLayout, float leading=0.0f)
| Adds some multi-line text, breaking lines at word-boundaries if they are too wide.
void | addFittedText (const Font &font, const String &text, float x, float y, float width, float height, Justification layout, int maximumLinesToUse, float minimumHorizontalScale=0.0f, GlyphArrangementOptions options={})
| Tries to fit some text within a given space.
void | addGlyphArrangement (const GlyphArrangement &)
| Appends another glyph arrangement to this one.
void | addGlyph (const PositionedGlyph &)
| Appends a custom glyph to the arrangement.
void | draw (const Graphics &) const
| Draws this glyph arrangement to a graphics context.
void | draw (const Graphics &, AffineTransform) const
| Draws this glyph arrangement to a graphics context.
void | createPath (Path &path) const
| Converts the set of glyphs into a path.
int | findGlyphIndexAt (float x, float y) const
| Looks for a glyph that contains the given coordinate.
Rectangle< float > | getBoundingBox (int startIndex, int numGlyphs, bool includeWhitespace) const
| Finds the smallest rectangle that will enclose a subset of the glyphs.
void | moveRangeOfGlyphs (int startIndex, int numGlyphs, float deltaX, float deltaY)
| Shifts a set of glyphs by a given amount.
void | removeRangeOfGlyphs (int startIndex, int numGlyphs)
| Removes a set of glyphs from the arrangement.
void | stretchRangeOfGlyphs (int startIndex, int numGlyphs, float horizontalScaleFactor)
| Expands or compresses a set of glyphs horizontally.
void | justifyGlyphs (int startIndex, int numGlyphs, float x, float y, float width, float height, Justification justification)
| Justifies a set of glyphs within a given space.

## Static Public Member Functions

static Rectangle< float > | getStringBounds (const Font &font, StringRef text)
| This convenience function adds text to a GlyphArrangement using the specified font 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 GlyphArrangement using the specified font and returns the width of the bounding box of the text after shaping.
static int | getStringWidthInt (const Font &font, StringRef text)
| This convenience function adds text to a GlyphArrangement using the specified font and returns the width of the bounding box of the text after shaping, rounded up to the next integer.

## Member Typedef Documentation

## Options

using juce::GlyphArrangement::Options = GlyphArrangementOptions

## Constructors and Destructors

## GlyphArrangement() [1/3]

juce::GlyphArrangement::GlyphArrangement | ( |  | ) |

Creates an empty arrangement.

Referenced by addGlyphArrangement(), getStringBounds(), GlyphArrangement(), GlyphArrangement(), operator=(), and operator=().

## GlyphArrangement() [2/3]

juce::GlyphArrangement::GlyphArrangement | ( | const GlyphArrangement & |  | ) |

default

References GlyphArrangement().

## GlyphArrangement() [3/3]

juce::GlyphArrangement::GlyphArrangement | ( | GlyphArrangement && |  | ) |

default

References GlyphArrangement().

## ~GlyphArrangement()

juce::GlyphArrangement::~GlyphArrangement | ( |  | ) |

default

Destructor.

## Member Functions

## operator=() [1/2]

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

default

References GlyphArrangement().

## operator=() [2/2]

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

default

References GlyphArrangement().

## getNumGlyphs()

int juce::GlyphArrangement::getNumGlyphs | ( |  | ) | const

inline noexcept

Returns the total number of glyphs in the arrangement.

Referenced by getStringBounds().

## getGlyph()

PositionedGlyph & juce::GlyphArrangement::getGlyph | ( | int | index | ) |

noexcept

Returns one of the glyphs from the arrangement.

Parameters

  index | the glyph's index, from 0 to (getNumGlyphs() - 1). Be careful not to pass an out-of-range index here, as it doesn't do any bounds-checking.

## begin()

const PositionedGlyph * juce::GlyphArrangement::begin | ( |  | ) | const

inline

## end()

const PositionedGlyph * juce::GlyphArrangement::end | ( |  | ) | const

inline

## clear()

void juce::GlyphArrangement::clear | ( |  | ) |

Clears all text from the arrangement and resets it.

## addLineOfText()

void juce::GlyphArrangement::addLineOfText | ( | const Font & | font,
|  | const String & | text,
|  | float | x,
|  | float | y )

Appends a line of text to the arrangement.

This will add the text as a single line, where x is the left-hand edge of the first character, and y is the position for the text's baseline.

If the text contains new-lines or carriage-returns, this will ignore them - use addJustifiedText() to add multi-line arrangements.

References x, and y.

Referenced by getStringBounds().

## addCurtailedLineOfText()

void juce::GlyphArrangement::addCurtailedLineOfText | ( | const Font & | font,
|  | const String & | text,
|  | float | x,
|  | float | y,
|  | float | maxWidthPixels,
|  | bool | useEllipsis )

Adds a line of text, truncating it if it's wider than a specified size.

This is the same as addLineOfText(), but if the line's width exceeds the value specified in maxWidthPixels, it will be truncated using either ellipsis (i.e. dots: "..."), if useEllipsis is true, or if this is false, it will just drop any subsequent characters.

References x, and y.

## addJustifiedText()

void juce::GlyphArrangement::addJustifiedText | ( | const Font & | font,
|  | const String & | text,
|  | float | x,
|  | float | y,
|  | float | maxLineWidth,
|  | Justification | horizontalLayout,
|  | float | leading = 0.0f )

Adds some multi-line text, breaking lines at word-boundaries if they are too wide.

This will add text to the arrangement, breaking it into new lines either where there is a new-line or carriage-return character in the text, or where a line's width exceeds the value set in maxLineWidth.

Each line that is added will be laid out using the flags set in horizontalLayout, so the lines can be left- or right-justified, or centred horizontally in the space between x and (x + maxLineWidth).

The y coordinate is the position of the baseline of the first line of text - subsequent lines will be placed below it, separated by a distance of font.getHeight() + leading.

References x, and y.

## addFittedText()

void juce::GlyphArrangement::addFittedText | ( | const Font & | font,
|  | const String & | text,
|  | float | x,
|  | float | y,
|  | float | width,
|  | float | height,
|  | Justification | layout,
|  | int | maximumLinesToUse,
|  | float | minimumHorizontalScale = 0.0f,
|  | GlyphArrangementOptions | options = {} )

Tries to fit some text within a given space.

This does its best to make the given text readable within the specified rectangle, so it's useful for labelling things.

If the text is too big, it'll be squashed horizontally or broken over multiple lines if the maximumLinesToUse value allows this. If the text just won't fit into the space, it'll cram as much as possible in there, and put some ellipsis at the end to show that it's been truncated.

A Justification parameter lets you specify how the text is laid out within the rectangle, both horizontally and vertically.

The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you can set this value to 1.0f. Pass 0 if you want it to use the default value.

See also
  Graphics::drawFittedText

References x, and y.

## addGlyphArrangement()

void juce::GlyphArrangement::addGlyphArrangement | ( | const GlyphArrangement & |  | ) |

Appends another glyph arrangement to this one.

References GlyphArrangement().

## addGlyph()

void juce::GlyphArrangement::addGlyph | ( | const PositionedGlyph & |  | ) |

Appends a custom glyph to the arrangement.

## draw() [1/2]

void juce::GlyphArrangement::draw | ( | const Graphics & |  | ) | const

Draws this glyph arrangement to a graphics context.

This uses cached bitmaps so is much faster than the draw (Graphics&, AffineTransform) method, which renders the glyphs as filled vectors.

## draw() [2/2]

void juce::GlyphArrangement::draw | ( | const Graphics & | ,
|  | AffineTransform | ) const

Draws this glyph arrangement to a graphics context.

This renders the paths as filled vectors, so is far slower than the draw (Graphics&) method for non-transformed arrangements.

## createPath()

void juce::GlyphArrangement::createPath | ( | Path & | path | ) | const

Converts the set of glyphs into a path.

Parameters

  path | the glyphs' outlines will be appended to this path

## findGlyphIndexAt()

int juce::GlyphArrangement::findGlyphIndexAt | ( | float | x,
|  | float | y ) const

Looks for a glyph that contains the given coordinate.

Returns
  the index of the glyph, or -1 if none were found.

References x, and y.

## getBoundingBox()

Rectangle< float > juce::GlyphArrangement::getBoundingBox | ( | int | startIndex,
|  | int | numGlyphs,
|  | bool | includeWhitespace ) const

Finds the smallest rectangle that will enclose a subset of the glyphs.

Parameters

  startIndex | the first glyph to test
  numGlyphs | the number of glyphs to include; if this is < 0, all glyphs after startIndex will be included
  includeWhitespace | if true, the extent of any whitespace characters will also be taken into account

Referenced by getStringBounds().

## moveRangeOfGlyphs()

void juce::GlyphArrangement::moveRangeOfGlyphs | ( | int | startIndex,
|  | int | numGlyphs,
|  | float | deltaX,
|  | float | deltaY )

Shifts a set of glyphs by a given amount.

Parameters

  startIndex | the first glyph to transform
  numGlyphs | the number of glyphs to move; if this is < 0, all glyphs after startIndex will be used
  deltaX | the amount to add to their x-positions
  deltaY | the amount to add to their y-positions

## removeRangeOfGlyphs()

void juce::GlyphArrangement::removeRangeOfGlyphs | ( | int | startIndex,
|  | int | numGlyphs )

Removes a set of glyphs from the arrangement.

Parameters

  startIndex | the first glyph to remove
  numGlyphs | the number of glyphs to remove; if this is < 0, all glyphs after startIndex will be deleted

## stretchRangeOfGlyphs()

void juce::GlyphArrangement::stretchRangeOfGlyphs | ( | int | startIndex,
|  | int | numGlyphs,
|  | float | horizontalScaleFactor )

Expands or compresses a set of glyphs horizontally.

Parameters

  startIndex | the first glyph to transform
  numGlyphs | the number of glyphs to stretch; if this is < 0, all glyphs after startIndex will be used
  horizontalScaleFactor | how much to scale their horizontal width by

## justifyGlyphs()

void juce::GlyphArrangement::justifyGlyphs | ( | int | startIndex,
|  | int | numGlyphs,
|  | float | x,
|  | float | y,
|  | float | width,
|  | float | height,
|  | Justification | justification )

Justifies a set of glyphs within a given space.

This moves the glyphs as a block so that the whole thing is located within the given rectangle with the specified layout.

If the Justification::horizontallyJustified flag is specified, each line will be stretched out to fill the specified width.

References x, and y.

## getStringBounds()

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

inline static

This convenience function adds text to a GlyphArrangement 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 addLineOfText(), getBoundingBox(), getNumGlyphs(), and GlyphArrangement().

Referenced by getStringWidth().

## getStringWidth()

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

inline static

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

References getStringBounds().

Referenced by getStringWidthInt().

## getStringWidthInt()

int juce::GlyphArrangement::getStringWidthInt | ( | const Font & | font,
|  | StringRef | text )

inline static

This convenience function adds text to a GlyphArrangement using the specified font and returns the width of the bounding box of the text after shaping, rounded up to the next integer.

References getStringWidth().

### 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