6#include "TTauri/Text/AttributedGlyphLine.hpp"
7#include "TTauri/Text/gstring.hpp"
8#include "TTauri/Foundation/required.hpp"
9#include "TTauri/Foundation/attributes.hpp"
10#include "TTauri/Foundation/Path.hpp"
11#include "TTauri/Foundation/vec.hpp"
12#include "TTauri/Foundation/nested_vector_iterator.hpp"
24 std::vector<AttributedGlyphLine>::const_iterator,
25 std::vector<AttributedGlyphLine>::iterator,
26 AttributedGlyphLine::iterator>;
29 std::vector<AttributedGlyphLine>::const_iterator,
30 std::vector<AttributedGlyphLine>::const_iterator,
31 AttributedGlyphLine::const_iterator>;
43 alignment(Alignment::MiddleCenter), boundingBox(), width(0.0f), preferredExtent(), lines() {}
74 Alignment
const alignment=Alignment::MiddleCenter,
91 Alignment const alignment=Alignment::MiddleCenter,
105 std::string_view text,
108 Alignment const alignment=Alignment::MiddleCenter,
112 [[nodiscard]]
size_t size() const noexcept {
114 for (ttlet &line: lines) {
115 count += ssize(line);
117 return numeric_cast<size_t>(count);
120 [[nodiscard]] iterator begin() noexcept {
return nested_vector_iterator_begin(lines); }
121 [[nodiscard]] const_iterator begin() const noexcept {
return nested_vector_iterator_cbegin(lines); }
122 [[nodiscard]] const_iterator cbegin() const noexcept {
return nested_vector_iterator_cbegin(lines); }
124 [[nodiscard]] iterator end() noexcept {
return nested_vector_iterator_end(lines); }
125 [[nodiscard]] const_iterator end() const noexcept {
return nested_vector_iterator_cend(lines); }
126 [[nodiscard]] const_iterator cend() const noexcept {
return nested_vector_iterator_cend(lines); }
128 float topAccender() const noexcept {
129 return lines.
front().ascender;
132 float bottomDescender() const noexcept {
133 return lines.
back().descender;
136 float topCapHeight() const noexcept {
137 return lines.
front().capHeight;
140 float bottomCapHeight() const noexcept {
141 return lines.
back().capHeight;
147 if ((ssize(lines) % 2) == 1) {
148 return lines[ssize(lines) / 2].capHeight;
150 return (lines[ssize(lines) / 2 - 1].capHeight + lines[ssize(lines) / 2].capHeight) * 0.5f;
160 if (alignment == VerticalAlignment::Top) {
161 return height - topAccender();
162 }
else if (alignment == VerticalAlignment::Bottom) {
163 return bottomDescender();
164 }
else if (alignment == VerticalAlignment::Middle) {
177 if (alignment == VerticalAlignment::Top) {
178 return height - topCapHeight() * 0.5f;
179 }
else if (alignment == VerticalAlignment::Bottom) {
180 return height - bottomCapHeight() * 0.5f;
181 }
else if (alignment == VerticalAlignment::Middle) {
Class which represents an axis-aligned rectangle.
Definition aarect.hpp:13
Optimized 2D translate matrix.
Definition mat.hpp:184
An iterator for a vector inside another vector.
Definition nested_vector_iterator.hpp:24
A 4D vector.
Definition vec.hpp:37
Definition gstring.hpp:12
ShapedText represent a piece of text shaped to be displayed.
Definition ShapedText.hpp:21
std::pair< ssize_t, ssize_t > indicesOfWord(ssize_t logicalIndex) const noexcept
Return the index at the left side and right side of a word.
int indexFromCoordinate(vec coordinate) const noexcept
Get the index into the text from a coordinate.
mat::T2 T(aarect rectangle) noexcept
Get the translation for where to place the text.
Definition ShapedText.hpp:193
mat::T2 TMiddle(vec position) noexcept
Get the translation for where to place the text.
Definition ShapedText.hpp:204
float middleCapHeight() const noexcept
Get the capHeight of the middle line(s).
Definition ShapedText.hpp:146
std::optional< ssize_t > indexOfCharOnTheRight(ssize_t logicalIndex) const noexcept
Return the index of the character to the right.
Path get_path() const noexcept
Convert the whole shaped text into a layered path.
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...
Definition ShapedText.hpp:159
const_iterator find(ssize_t position) const noexcept
Find a glyph that corresponds to position.
aarect leftToRightCaret(ssize_t index, bool overwrite) const noexcept
Return the cursor-carets.
ShapedText(std::vector< AttributedGrapheme > const &text, float width, Alignment const alignment=Alignment::MiddleCenter, bool wrap=true) noexcept
Create shaped text from attributed text.
std::pair< ssize_t, ssize_t > indicesOfParagraph(ssize_t logicalIndex) const noexcept
Return the index at the left side and right side of a paragraph.
std::vector< aarect > selectionRectangles(ssize_t first, ssize_t last) const noexcept
Return a list of merged rectangles to display for the selection.
std::optional< ssize_t > indexOfCharOnTheLeft(ssize_t logicalIndex) const noexcept
Return the index of the character to the left.
float middleOffset(float height) const noexcept
Get the offset of the middle of a line.
Definition ShapedText.hpp:176
aarect rectangleOfGrapheme(ssize_t index) const noexcept
Get a rectangle for the grapheme.
std::optional< ssize_t > indexOfWordOnTheRight(ssize_t logicalIndex) const noexcept
Return the index of the word to the right.
ssize_t indexAtRightSideOfWord(ssize_t logicalIndex) const noexcept
Return the index at the left side of a word.
std::optional< ssize_t > indexOfCharAtCoordinate(vec coordinate) const noexcept
Return the index of the character .
std::vector< int > indicesFromCoordinates(vec start, vec current) const noexcept
Get the index into the text from a coordinate.
std::optional< ssize_t > indexOfWordOnTheLeft(ssize_t logicalIndex) const noexcept
Return the index of the word to the left.
Definition TextStyle.hpp:15