28#ifndef EASY3D_RENDERER_TEXT_LAYOUT_H
29#define EASY3D_RENDERER_TEXT_LAYOUT_H
31#include <easy3d/renderer/render_device.h>
37 enum class TextAlign { left, center, right };
50 TextAlign
align = TextAlign::left;
106 std::size_t
add_font(
const std::string &filename);
110 const std::vector<std::string> &
font_names()
const;
121 layout(
const std::string &utf8,
unsigned width,
unsigned height,
const TextOptions &options = {});
131 std::unique_ptr<Impl> impl_;
Rasterize TrueType glyphs and produce backend-independent text commands.
Definition text_layout.h:85
~TextLayoutEngine()
Destroy the engine; already returned layouts remain valid.
std::size_t add_font(const std::string &filename)
Load a TrueType font.
Definition text_layout.cpp:162
const std::vector< std::string > & font_names() const
Definition text_layout.cpp:155
void clear_cache()
Release cached glyphs and atlas pages.
Definition text_layout.cpp:158
TextLayout layout(const std::string &utf8, unsigned width, unsigned height, const TextOptions &options={})
Lay out UTF-8 text into immutable glyph draw commands.
Definition text_layout.cpp:182
TextLayoutEngine(const TextLayoutEngine &)=delete
Copying is disabled because the engine owns mutable font and glyph caches.
Definition collider.cpp:182
GenericRect< float > Rect
A 2D axis-aligned rectangle of float type.
Definition types.h:111
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46
Immutable draw commands and metrics produced for one text layout.
Definition text_layout.h:63
float advance
Advance of the last line, including its alignment offset.
Definition text_layout.h:69
std::vector< DrawCommand > commands
Draw commands containing glyph geometry and atlas snapshots.
Definition text_layout.h:65
Rect bounds
Actual ink bounds in top-left framebuffer pixel coordinates.
Definition text_layout.h:67
float line_height
Font line height in framebuffer pixels.
Definition text_layout.h:71
Font and placement options for a laid-out UTF-8 string.
Definition text_layout.h:40
bool upper_left
Definition text_layout.h:59
vec4 color
Text color in RGBA.
Definition text_layout.h:48
float character_spacing
Additional horizontal spacing between characters, in framebuffer pixels.
Definition text_layout.h:52
float line_spacing
Additional line spacing as a fraction of font line height; must be at least -1.
Definition text_layout.h:54
TextAlign align
Alignment of shorter lines relative to the longest line.
Definition text_layout.h:50
float y
Definition text_layout.h:46
float size
Font size in framebuffer pixels, independent of platform DPI.
Definition text_layout.h:44
float x
Horizontal framebuffer-pixel origin.
Definition text_layout.h:45
std::size_t font
Index returned by TextLayoutEngine::add_font().
Definition text_layout.h:42
bool kerning
Apply the font's horizontal kerning pairs when positioning glyphs.
Definition text_layout.h:56