Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::canvas::TextShaper Class Reference

Text shaper — the PreText-style measure-once-reflow-forever engine. More...

#include <text_shaper.hpp>

Public Member Functions

 TextShaper ()
 ~TextShaper ()
PreparedText prepare (std::string_view text, std::string_view font_family, float font_size, int font_weight=400, int font_slant=0, float letter_spacing=0.0f, const std::vector< Canvas::FontFeature > &font_features={})
 Prepare text for layout — this is the expensive call.
PreparedText prepare (const AttributedString &text, const std::vector< Canvas::FontFeature > &font_features={})
 Prepare an attributed string (mixed styles).
ShapedLayout layout (const PreparedText &prepared, float max_width, float line_height=0, int max_lines=0, BreakMode break_mode=BreakMode::normal) const
 Layout prepared text at a specific width — this is the cheap call.
ShapedLayout layout_with_lines (const PreparedText &prepared, float max_width, float line_height=0, int max_lines=0, BreakMode break_mode=BreakMode::normal) const
 Layout and materialize line text (slightly more expensive than layout()).
float measure_height (const PreparedText &prepared, float max_width, float line_height=0) const
 Quick height calculation (fastest path — just returns height, no line details).
int count_lines (const PreparedText &prepared, float max_width) const
 Quick line count.
void clear_cache ()
 Clear the segment measurement cache.
bool uses_real_shaping () const
 Whether this shaper uses real font shaping (SkParagraph) or estimation.

Detailed Description

Text shaper — the PreText-style measure-once-reflow-forever engine.

Usage: auto prepared = shaper.prepare("Hello world", "system", 14); auto layout = shaper.layout(prepared, 200.0f); // Just arithmetic! // On resize: auto new_layout = shaper.layout(prepared, 300.0f); // Still just arithmetic!

Constructor & Destructor Documentation

◆ TextShaper()

pulp::canvas::TextShaper::TextShaper ( )

◆ ~TextShaper()

pulp::canvas::TextShaper::~TextShaper ( )

Member Function Documentation

◆ clear_cache()

void pulp::canvas::TextShaper::clear_cache ( )

Clear the segment measurement cache.

◆ count_lines()

int pulp::canvas::TextShaper::count_lines ( const PreparedText & prepared,
float max_width ) const

Quick line count.

◆ layout()

ShapedLayout pulp::canvas::TextShaper::layout ( const PreparedText & prepared,
float max_width,
float line_height = 0,
int max_lines = 0,
BreakMode break_mode = BreakMode::normal ) const

Layout prepared text at a specific width — this is the cheap call.

Pure arithmetic over cached segment widths. Call on every resize.

When max_lines > 0, truncate the result to N lines. max_lines == 1 is the canonical CSS white-space: nowrap path — it ignores wrapping at the right edge and emits a single line whose width is the text's full intrinsic width (segments past max_width still count toward the line width so consumers that pair this with ellipsis truncation can see they overflow). 0 = unlimited (default).

◆ layout_with_lines()

ShapedLayout pulp::canvas::TextShaper::layout_with_lines ( const PreparedText & prepared,
float max_width,
float line_height = 0,
int max_lines = 0,
BreakMode break_mode = BreakMode::normal ) const

Layout and materialize line text (slightly more expensive than layout()).

◆ measure_height()

float pulp::canvas::TextShaper::measure_height ( const PreparedText & prepared,
float max_width,
float line_height = 0 ) const

Quick height calculation (fastest path — just returns height, no line details).

◆ prepare() [1/2]

PreparedText pulp::canvas::TextShaper::prepare ( const AttributedString & text,
const std::vector< Canvas::FontFeature > & font_features = {} )

Prepare an attributed string (mixed styles).

Paragraph-wide OpenType features still affect every span's advances, just as they do when the attributed string is painted by Label.

◆ prepare() [2/2]

PreparedText pulp::canvas::TextShaper::prepare ( std::string_view text,
std::string_view font_family,
float font_size,
int font_weight = 400,
int font_slant = 0,
float letter_spacing = 0.0f,
const std::vector< Canvas::FontFeature > & font_features = {} )

Prepare text for layout — this is the expensive call.

Runs text shaping (HarfBuzz via SkShaper when available) and caches segment widths. Call once per (text, font) pair. Do NOT call on every resize.

font_weight is the CSS numeric weight the text will be PAINTED at, and it belongs here because it changes advances. Measuring a bold run through the regular face reports a narrower line than the one that gets drawn, which shows up as text breaking a word or two late and overflowing its box — a wrap bug in appearance, a measurement bug in fact. A caller that omits it is stating the text is Regular.

◆ uses_real_shaping()

bool pulp::canvas::TextShaper::uses_real_shaping ( ) const

Whether this shaper uses real font shaping (SkParagraph) or estimation.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/canvas/include/pulp/canvas/text_shaper.hpp