61 const std::vector<TextLine>&
lines()
const {
return lines_; }
62 int line_count()
const {
return static_cast<int>(lines_.size()); }
67 for (
auto& line : lines_) w = std::max(w, line.width);
72 if (lines_.empty())
return 0;
73 auto& last = lines_.back();
74 return last.baseline_y + last.descent;
84 void clear() { lines_.clear(); }
87 std::vector<TextLine> lines_;
114 return {x + shear, y, x + w + shear, y, x + w, y + h, x, y + h};
120 auto cross = [](
float ax,
float ay,
float bx,
float by) {
return ax * by - ay * bx; };
125 return (d1 >= 0 && d2 >= 0 && d3 >= 0 && d4 >= 0) ||
126 (d1 <= 0 && d2 <= 0 && d3 <= 0 && d4 <= 0);
Glyph arrangement — the result of text layout, containing positioned glyphs for each line.
Definition text_layout.hpp:53
float total_height() const
Definition text_layout.hpp:71
float total_width() const
Get the bounding box of all laid-out text.
Definition text_layout.hpp:65
GlyphArrangement()=default
size_t hit_test(float x, float y) const
Find the text index nearest to a point (for cursor positioning).
void clear()
Clear all layout data.
Definition text_layout.hpp:84
void add_line(TextLine line)
Add a line of laid-out text.
Definition text_layout.hpp:58
const std::vector< TextLine > & lines() const
Get all lines.
Definition text_layout.hpp:61
float position_for_index(size_t index) const
Get the x position for a given text index (for cursor rendering).
int line_count() const
Definition text_layout.hpp:62
Definition affine_transform.hpp:24
GlyphArrangement layout_paragraph(const std::string &text, const FontSpec &font, float max_width=0, Color color=Color::rgba(1.0f, 1.0f, 1.0f))
Layout a paragraph of text with word wrapping.
@ text
Definition scene_node.hpp:96
static constexpr Color rgba(float r, float g, float b, float a=1.0f)
Construct from float channels [0,1] (>1.0 allowed for HDR).
Definition canvas.hpp:56
Font style specification for text layout.
Definition text_layout.hpp:10
int weight
100-900, 400=normal, 700=bold
Definition text_layout.hpp:13
bool italic
Definition text_layout.hpp:14
float size
Definition text_layout.hpp:12
std::string family
Definition text_layout.hpp:11
float letter_spacing
Definition text_layout.hpp:15
Result of laying out a line of text — position and metrics for each glyph.
Definition text_layout.hpp:28
float x
Definition text_layout.hpp:29
size_t text_index
Index into the source text.
Definition text_layout.hpp:32
float advance
Horizontal advance to next glyph.
Definition text_layout.hpp:30
float y
Position relative to the line origin.
Definition text_layout.hpp:29
uint32_t codepoint
Unicode codepoint.
Definition text_layout.hpp:31
Parallelogram — a skewed rectangle defined by base point and two edge vectors.
Definition text_layout.hpp:106
float x2
Definition text_layout.hpp:109
bool contains(float px, float py) const
Check if a point is inside.
Definition text_layout.hpp:118
float x1
Definition text_layout.hpp:108
float y0
Top-left corner.
Definition text_layout.hpp:107
float y1
Top-right corner.
Definition text_layout.hpp:108
static Parallelogram from_rect_shear(float x, float y, float w, float h, float shear)
Create from a rectangle with horizontal shear.
Definition text_layout.hpp:113
float y3
Bottom-left corner.
Definition text_layout.hpp:110
float x3
Definition text_layout.hpp:110
float x0
Definition text_layout.hpp:107
float y2
Bottom-right corner.
Definition text_layout.hpp:109
A single line of laid-out text.
Definition text_layout.hpp:36
float descent
Distance below baseline.
Definition text_layout.hpp:40
std::vector< GlyphPosition > glyphs
Definition text_layout.hpp:37
float leading
Extra spacing between lines.
Definition text_layout.hpp:41
float width
Total line width.
Definition text_layout.hpp:38
float ascent
Distance above baseline.
Definition text_layout.hpp:39
float baseline_y
Y position of baseline in the layout.
Definition text_layout.hpp:42
A run of text with uniform style within a paragraph.
Definition text_layout.hpp:19
Color color
Definition text_layout.hpp:22
std::string text
Definition text_layout.hpp:20
FontSpec font
Definition text_layout.hpp:21
size_t length
Length in code units.
Definition text_layout.hpp:24
size_t start
Start index in the full text.
Definition text_layout.hpp:23