HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields
tt::shaped_text Class Reference

#include <ttauri/text/shaped_text.hpp>

Public Types

using iterator = recursive_iterator<std::vector<attributed_glyph_line>::iterator>
 
using const_iterator = recursive_iterator<std::vector<attributed_glyph_line>::const_iterator>
 

Public Member Functions

 shaped_text (shaped_text const &other)=default
 
 shaped_text (shaped_text &&other) noexcept=default
 
shaped_textoperator= (shaped_text const &other)=default
 
shaped_textoperator= (shaped_text &&other) noexcept=default
 
 shaped_text (std::vector< attributed_grapheme > const &text, float width, tt::alignment const alignment=alignment::middle_center, bool wrap=true) noexcept
 Create shaped text from attributed text.
 
 shaped_text (gstring const &text, text_style const &style, float width, tt::alignment const alignment=alignment::middle_center, bool wrap=true) noexcept
 Create shaped text from a string.
 
 shaped_text (std::u8string_view text, text_style const &style, float width, tt::alignment const alignment=alignment::middle_center, bool wrap=true) noexcept
 Create shaped text from a string.
 
size_t size () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
float topAccender () const noexcept
 
float bottomDescender () const noexcept
 
float topCapHeight () const noexcept
 
float bottomCapHeight () const noexcept
 
float middleCapHeight () const noexcept
 Get the capHeight of the middle line(s).
 
float baselineOffset (float height) noexcept
 Get the offset of the baseline The offset of the baseline when the text needs to be rendered inside a box of the given height.
 
float middleOffset (float height) const noexcept
 Get the offset of the middle of a line.
 
translate2 translate_base_line (point2 position) noexcept
 Get the translation for where to place the text.
 
const_iterator find (ssize_t position) const noexcept
 Find a glyph that corresponds to position.
 
aarectangle rectangleOfgrapheme (ssize_t index) const noexcept
 Get a rectangle for the grapheme.
 
aarectangle leftToRightCaret (ssize_t index, bool overwrite) const noexcept
 Return the cursor-carets.
 
std::vector< aarectangleselectionRectangles (ssize_t first, ssize_t last) const noexcept
 Return a list of merged rectangles to display for the selection.
 
std::optional< ssize_tindexOfCharAtCoordinate (point2 coordinate) const noexcept
 Get the character close to a coordinate.
 
std::optional< ssize_tindexOfCharOnTheLeft (ssize_t logical_index) const noexcept
 Get the character left of the given character.
 
std::optional< ssize_tindexOfCharOnTheRight (ssize_t logical_index) const noexcept
 Get the character right of the given character.
 
std::pair< ssize_t, ssize_tindicesOfWord (ssize_t logical_index) const noexcept
 Get the word with the given character.
 
std::pair< ssize_t, ssize_tindicesOfParagraph (ssize_t logical_index) const noexcept
 Get the character right of the given character.
 
ssize_t indexAtRightSideOfWord (ssize_t logical_index) const noexcept
 Get the character right of the given character.
 
std::optional< ssize_tindexOfWordOnTheLeft (ssize_t logical_index) const noexcept
 Get the first character of the word on the left.
 
std::optional< ssize_tindexOfWordOnTheRight (ssize_t logical_index) const noexcept
 Get the last character of the word on the right.
 
graphic_path get_path () const noexcept
 Convert the whole shaped text into a layered path.
 
int indexFromCoordinate (point2 coordinate) const noexcept
 Get the index into the text from a coordinate.
 
std::vector< int > indicesFromCoordinates (point2 start, point2 current) const noexcept
 Get the index into the text from a coordinate.
 

Data Fields

alignment alignment
 
aarectangle boundingBox
 
float width
 
extent2 preferred_extent
 

Detailed Description

shaped_text represent a piece of text shaped to be displayed.

Constructor & Destructor Documentation

◆ shaped_text() [1/3]

tt::shaped_text::shaped_text ( std::vector< attributed_grapheme > const & text,
float width,
tt::alignment const alignment = alignment::middle_center,
bool wrap = true )
noexcept

Create shaped text from attributed text.

This function is used to draw rich-text. Each grapheme comes with its own text-style.

Vertical alignment is based on base line at y=0.0:

  • Bottom -> base line of the last line is at y=0.0
  • Top -> base line of the first line is at y=0.0
  • Middle ->
    • Odd # lines -> base line of middle line is at y=0.0
    • Even # lines -> gap between the two middle lines is at y=0.0

Horizontal alignment is based on the given width:

  • Left -> first character starts at x=0.0
  • Right -> last visible character end at x=maximum_width
  • Center -> middle of the visible text at x=maximum_width/2
Parameters
textThe text to draw.
widthThe width into which the text is horizontally aligned.
alignmentThe alignment of the text within the extent.
wrapTrue when text should be wrapped to fit inside the given width.

◆ shaped_text() [2/3]

tt::shaped_text::shaped_text ( gstring const & text,
text_style const & style,
float width,
tt::alignment const alignment = alignment::middle_center,
bool wrap = true )
noexcept

Create shaped text from a string.

This function is mostly used for drawing label text.

Parameters
textThe text to draw.
styleThe text style.
widthThe maximum a width of the text.
alignmentThe alignment of the text within the extent.
wrapWhen fitting the text in the extent wrap lines when needed.

◆ shaped_text() [3/3]

tt::shaped_text::shaped_text ( std::u8string_view text,
text_style const & style,
float width,
tt::alignment const alignment = alignment::middle_center,
bool wrap = true )
noexcept

Create shaped text from a string.

This function is mostly used for drawing label text.

Parameters
textThe text to draw.
styleThe text style.
widthThe maximum width of the text.
alignmentThe alignment of the text within the extent.
wrapWhen fitting the text in the extent wrap lines when needed.

Member Function Documentation

◆ baselineOffset()

float tt::shaped_text::baselineOffset ( float height)
inlinenoexcept

Get the offset of the baseline The offset of the baseline when the text needs to be rendered inside a box of the given height.

The offset is depended on the vertical alignment of the shaped text.

◆ find()

const_iterator tt::shaped_text::find ( ssize_t position) const
noexcept

Find a glyph that corresponds to position.

◆ get_path()

graphic_path tt::shaped_text::get_path ( ) const
noexcept

Convert the whole shaped text into a layered path.

◆ indexAtRightSideOfWord()

ssize_t tt::shaped_text::indexAtRightSideOfWord ( ssize_t logical_index) const
noexcept

Get the character right of the given character.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical indices beyond the last character of a word.

◆ indexFromCoordinate()

int tt::shaped_text::indexFromCoordinate ( point2 coordinate) const
noexcept

Get the index into the text from a coordinate.

The index returned is from the text that was used to construct the shaped_text.

Parameters
coordinateA coordinate within the box.
Returns
index of the selected grapheme, or -1 if no grapheme was found near the coordinate.

◆ indexOfCharAtCoordinate()

std::optional< ssize_t > tt::shaped_text::indexOfCharAtCoordinate ( point2 coordinate) const
noexcept

Get the character close to a coordinate.

Parameters
coordinateThe coordinate of the mouse pointer.
Returns
The logical index of the character closest to the coordinate

◆ indexOfCharOnTheLeft()

std::optional< ssize_t > tt::shaped_text::indexOfCharOnTheLeft ( ssize_t logical_index) const
noexcept

Get the character left of the given character.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical index of the character left-closest to the given character.

◆ indexOfCharOnTheRight()

std::optional< ssize_t > tt::shaped_text::indexOfCharOnTheRight ( ssize_t logical_index) const
noexcept

Get the character right of the given character.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical index of the character right-closest to the given character.

◆ indexOfWordOnTheLeft()

std::optional< ssize_t > tt::shaped_text::indexOfWordOnTheLeft ( ssize_t logical_index) const
noexcept

Get the first character of the word on the left.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical index of a first letter of the word on the left

◆ indexOfWordOnTheRight()

std::optional< ssize_t > tt::shaped_text::indexOfWordOnTheRight ( ssize_t logical_index) const
noexcept

Get the last character of the word on the right.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical index of a last letter of the word on the right

◆ indicesFromCoordinates()

std::vector< int > tt::shaped_text::indicesFromCoordinates ( point2 start,
point2 current ) const
noexcept

Get the index into the text from a coordinate.

The index returned is from the text that was used to construct the shaped_text.

Parameters
startThe coordinate at the start of a mouse drag.
currentThe current coordinate of the mouse pointer, during the drag.
Returns
indices of all the graphemes selected during a drag.

◆ indicesOfParagraph()

std::pair< ssize_t, ssize_t > tt::shaped_text::indicesOfParagraph ( ssize_t logical_index) const
noexcept

Get the character right of the given character.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical indices of the first and last character of a paragraph.

◆ indicesOfWord()

std::pair< ssize_t, ssize_t > tt::shaped_text::indicesOfWord ( ssize_t logical_index) const
noexcept

Get the word with the given character.

Parameters
logical_indexThe index of the logical character pointed to.
Returns
The logical indices of the first and last character of a word.

◆ leftToRightCaret()

aarectangle tt::shaped_text::leftToRightCaret ( ssize_t index,
bool overwrite ) const
noexcept

Return the cursor-carets.

The caret will be to the left of the character at position.

Parameters
indexLogical grapheme index.
overwriteWhen true display a overwrite cursor.
Returns
left-to-right caret rectangle to display.

◆ middleCapHeight()

float tt::shaped_text::middleCapHeight ( ) const
inlinenoexcept

Get the capHeight of the middle line(s).

◆ middleOffset()

float tt::shaped_text::middleOffset ( float height) const
inlinenoexcept

Get the offset of the middle of a line.

The offset of the baseline when the middle of a line needs to be at a specific height. The offset is depended on the vertical alignment of the shaped text.

◆ rectangleOfgrapheme()

aarectangle tt::shaped_text::rectangleOfgrapheme ( ssize_t index) const
noexcept

Get a rectangle for the grapheme.

The rectangle describes the edges of the grapheme:

  • From left side bearing to right side bearing of the glyph.
  • from descender to ascender of the line that the glyph is part of.
Parameters
index
Returns
A rectangle describing the position of the grapheme.

◆ selectionRectangles()

std::vector< aarectangle > tt::shaped_text::selectionRectangles ( ssize_t first,
ssize_t last ) const
noexcept

Return a list of merged rectangles to display for the selection.

The selection may be discontinues due to bidirectional text.

Parameters
firstThe first logical grapheme that is selected.
lastOne beyond the last logical grapheme that is selected.
Returns
A list of rectangles to display.

◆ translate_base_line()

translate2 tt::shaped_text::translate_base_line ( point2 position)
inlinenoexcept

Get the translation for where to place the text.

Parameters
positionx is the left position, y is where the middle of the line should be.

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