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

#include <text_run_planner.hpp>

Public Member Functions

ShapedText shape (std::string_view text, const FontOptions &options)
 Produce a ShapedText for text under options.
std::vector< ShapedText > shape_batch (const std::vector< std::pair< std::string, FontOptions > > &inputs)
 Shape N independent inputs in parallel and return the artifacts in input order.
void clear_cache ()
 Test-only: discard the internal cache.

Static Public Member Functions

static TextRunPlanner & instance ()
 Process-wide singleton. Thread-safe.

Member Function Documentation

◆ clear_cache()

void pulp::canvas::TextRunPlanner::clear_cache ( )

Test-only: discard the internal cache.

Production code never calls this — invalidation flows through the scope generation counter automatically.

◆ instance()

TextRunPlanner & pulp::canvas::TextRunPlanner::instance ( )
static

Process-wide singleton. Thread-safe.

◆ shape()

ShapedText pulp::canvas::TextRunPlanner::shape ( std::string_view text,
const FontOptions & options )

Produce a ShapedText for text under options.

The planner is responsible for: resolving the typeface cascade (delegating to FontResolver), shaping each run via SkShaper (or falling back to the width-estimator on non-Skia builds), computing per-run metrics, populating the cluster table + line-break opportunities + Unicode index map, and recording fallback / synthesis traces on the runs.

Calling with the same arguments is cache-hit cheap — the internal cache is keyed on the full FontOptions blob plus the text (interned). The cache invalidates automatically when FontScope::generation() advances on any consulted scope, because options.registry_generation is part of the key.

◆ shape_batch()

std::vector< ShapedText > pulp::canvas::TextRunPlanner::shape_batch ( const std::vector< std::pair< std::string, FontOptions > > & inputs)

Shape N independent inputs in parallel and return the artifacts in input order.

Same output as N sequential shape() calls. Uses std::async(launch::async, ...) to fan out work; the resolver, FontFlightRecorder, and per-planner cache are all synchronized internally. The cache lookup happens once per future, so duplicate inputs across the batch coalesce as expected.

Shapes SERIALLY, in the same input order and with identical output, where there is no thread to fan out to: a non-pthread wasm build (__EMSCRIPTEN__, where std::async(launch::async, ...) throws), and natively under PULP_TEXT_SHAPE_SERIAL so that arm stays testable.

The serial shape() API is preferred for one-off labels; this batch entry point is intended for design-tool panels, docs views, or any other surface that needs to lay out many independent paragraphs at startup. Inputs are owned by the caller via std::string for thread safety; small allocations are cheap relative to the shaping cost we parallelise.


The documentation for this class was generated from the following file: