7#include "attributed_glyph_line.hpp"
9#include "../required.hpp"
11#include "../graphic_path.hpp"
12#include "../recursive_iterator.hpp"
13#include "../geometry/extent.hpp"
14#include "../geometry/point.hpp"
39 alignment(alignment::middle_center), boundingBox(), width(0.0f), _preferred_extent(), lines() {}
104 std::string_view text,
111 [[nodiscard]]
size_t size() const noexcept {
113 for (ttlet &line: lines) {
114 count += std::ssize(line);
116 return narrow_cast<size_t>(count);
119 [[nodiscard]]
extent2 minimum_size() const noexcept
121 return _preferred_extent;
124 [[nodiscard]] extent2 preferred_size() const noexcept
126 return _preferred_extent;
129 [[nodiscard]] extent2 maximum_size() const noexcept
131 return _preferred_extent;
134 [[nodiscard]] iterator begin() noexcept {
return recursive_iterator_begin(lines); }
135 [[nodiscard]] const_iterator begin() const noexcept {
return recursive_iterator_begin(lines); }
136 [[nodiscard]] const_iterator cbegin() const noexcept {
return recursive_iterator_begin(lines); }
138 [[nodiscard]] iterator end() noexcept {
return recursive_iterator_end(lines); }
139 [[nodiscard]] const_iterator end() const noexcept {
return recursive_iterator_end(lines); }
140 [[nodiscard]] const_iterator cend() const noexcept {
return recursive_iterator_end(lines); }
142 float topAccender() const noexcept {
143 return lines.
front().ascender;
146 float bottomDescender() const noexcept {
147 return lines.
back().descender;
150 float topCapHeight() const noexcept {
151 return lines.
front().capHeight;
154 float bottomCapHeight() const noexcept {
155 return lines.
back().capHeight;
161 if ((std::ssize(lines) % 2) == 1) {
162 return lines[std::ssize(lines) / 2].capHeight;
164 return (lines[std::ssize(lines) / 2 - 1].capHeight + lines[std::ssize(lines) / 2].capHeight) * 0.5f;
174 if (
alignment == vertical_alignment::top) {
175 return height - topAccender();
176 }
else if (
alignment == vertical_alignment::bottom) {
177 return bottomDescender();
178 }
else if (
alignment == vertical_alignment::middle) {
191 if (
alignment == vertical_alignment::top) {
192 return height - topCapHeight() * 0.5f;
193 }
else if (
alignment == vertical_alignment::bottom) {
194 return height - bottomCapHeight() * 0.5f;
195 }
else if (
alignment == vertical_alignment::middle) {
alignment
Vertical and horizontal alignment.
Definition alignment.hpp:47
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
A path is a vector graphics object.
Definition graphic_path.hpp:28
An iterator which recursively iterates through nested containers.
Definition recursive_iterator.hpp:18
font_book keeps track of multiple fonts.
Definition font_book.hpp:30
Definition gstring.hpp:13
shaped_text represent a piece of text shaped to be displayed.
Definition shaped_text.hpp:23
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 shaped_text.hpp:173
std::vector< int > indicesFromCoordinates(point2 start, point2 current) const noexcept
Get the index into the text from a coordinate.
std::optional< ssize_t > index_of_grapheme_at_coordinate(point2 coordinate) const noexcept
Get the character close to a coordinate.
shaped_text(tt::font_book const &font_book, 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.
std::vector< aarectangle > selection_rectangles(ssize_t first, ssize_t last) const noexcept
Return a list of merged rectangles to display for the selection.
std::optional< ssize_t > indexOfWordOnTheLeft(ssize_t logical_index) const noexcept
Get the first character of the word on the left.
std::optional< ssize_t > indexOfCharOnTheRight(ssize_t logical_index) const noexcept
Get the character right of the given character.
std::optional< ssize_t > indexOfWordOnTheRight(ssize_t logical_index) const noexcept
Get the last character of the word on the right.
aarectangle left_to_right_caret(ssize_t index, bool overwrite) const noexcept
Return the cursor-carets.
float middleCapHeight() const noexcept
Get the capHeight of the middle line(s).
Definition shaped_text.hpp:160
translate2 translate_base_line(point2 position) noexcept
Get the translation for where to place the text.
Definition shaped_text.hpp:206
graphic_path get_path() const noexcept
Convert the whole shaped text into a layered path.
std::pair< ssize_t, ssize_t > indices_of_word(ssize_t logical_index) const noexcept
Get the word with the given character.
ssize_t indexAtRightSideOfWord(ssize_t logical_index) const noexcept
Get the character right of the given character.
const_iterator find(ssize_t position) const noexcept
Find a glyph that corresponds to position.
float middleOffset(float height) const noexcept
Get the offset of the middle of a line.
Definition shaped_text.hpp:190
aarectangle rectangleOfgrapheme(ssize_t index) const noexcept
Get a rectangle for the grapheme.
int indexFromCoordinate(point2 coordinate) const noexcept
Get the index into the text from a coordinate.
std::pair< ssize_t, ssize_t > indices_of_paragraph(ssize_t logical_index) const noexcept
Get the character right of the given character.
std::optional< ssize_t > indexOfCharOnTheLeft(ssize_t logical_index) const noexcept
Get the character left of the given character.
Definition text_style.hpp:17