Donner SVG main
0.8.0 ยท 64d9612f0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
PlacedTextGeometry.h File Reference

Shared, backend-agnostic text geometry for RendererInterface::drawText. More...

#include <functional>
#include <span>
#include <vector>
#include "donner/base/Box.h"
#include "donner/base/Path.h"
#include "donner/base/RelativeLengthMetrics.h"
#include "donner/base/Transform.h"
#include "donner/svg/components/text/ComputedTextComponent.h"
#include "donner/svg/text/TextEngine.h"
#include "donner/svg/text/TextTypes.h"
Include dependency graph for PlacedTextGeometry.h:

Classes

struct  donner::svg::PreparedTextDraw
 Immutable layout slice and full-element bounds prepared once for a text effect owner. More...
struct  donner::svg::TextDrawGeometry
 Mutable per-call run copy after effect ownership and visibility filtering. More...
struct  donner::svg::GlyphOutlineAndPlacement
 A glyph's outline split into the part that depends only on the glyph and the part that depends only on where the glyph sits in the run. More...
struct  donner::svg::GlyphFaceScale
 The face that draws one glyph, with its outline scale and whether it has only bitmap glyphs. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.
namespace  donner::svg
 Donner SVG library, which can load, manipulate and render SVG files.

Functions

TextLayoutParams donner::svg::ToTextLayoutParams (const TextParams &params)
 Convert renderer-facing text parameters to the shared layout engine's input.
TextDrawGeometry donner::svg::PrepareTextDrawGeometry (Registry &registry, const components::ComputedTextComponent &text, const TextParams &params, TextEngine &textEngine)
 Resolve one backend draw from a shared element preparation or the direct-caller fallback.
Path donner::svg::TransformPath (const Path &path, const Transform2d &transform)
 Apply an affine transform to every point of a path.
Transform2d donner::svg::GlyphPlacementTransform (const TextGlyph &glyph)
 The affine that places a glyph's unplaced outline at its baseline position in the text element's local space.
GlyphOutlineAndPlacement donner::svg::UnplacedGlyphOutline (const TextEngine &textEngine, FontHandle font, const TextGlyph &glyph, float scale)
 Build a glyph's unplaced outline and its placement transform.
Path donner::svg::PlacedGlyphOutline (const TextEngine &textEngine, FontHandle font, const TextRun &run, const TextGlyph &glyph, float scale, double warpTolerance)
 Build the placed outline for a single glyph in document space.
GlyphFaceScale donner::svg::ResolveGlyphFace (const TextEngine &textEngine, const TextRun &run, const TextGlyph &glyph, float runScale, bool runBitmapOnly)
 Resolves the face that draws glyph.
Path donner::svg::WarpGlyphOutline (const Path &outline, const StretchedTextPath &mapping, const TextGlyph &glyph, double tolerance=Path::kLocalFlattenTolerance)
 Warp a glyph-local outline onto the perpendicular vectors of a stretched text path.
double donner::svg::TextWarpToleranceFor (const Transform2d &deviceFromLocal)
 Derive a path-local warp tolerance from a local-to-device transform.
Box2d donner::svg::ComputeTextBounds (const TextEngine &textEngine, const std::vector< TextRun > &runs)
 Compute the text element's bounding box for objectBoundingBox paint.
void donner::svg::ClearUnpaintedSpanGlyphs (const components::ComputedTextComponent &text, entt::entity spanEffectOwner, std::vector< TextRun > &runs)
 Drop the glyphs of runs this draw is not responsible for painting.
template<typename DrawFn>
void donner::svg::ForEachEmittingOrigin (std::span< const components::TextDecorationOrigin > origins, TextDecoration emittedLines, const DrawFn &draw)
 Call draw for each origin that has a line in emittedLines, so a paint pass skips origins it would draw nothing for before resolving their paint.
template<typename FillFn, typename StrokeFn>
void donner::svg::PaintFillAndStroke (const PaintOrder &paintOrder, const FillFn &fill, const StrokeFn &stroke)
 Run fill and stroke in the order paintOrder gives them; SVG 2 section 11.11 orders a decoration's own fill and stroke by the paint-order where it is declared.
void donner::svg::EmitTextDecorationPaths (const TextRun &run, const components::TextDecorationOrigin &origin, TextDecoration emittedLines, std::size_t originCount, float fontSize, const TextEngine &engine, const Transform2d &deviceFromLocal, std::size_t &remainingWork, const std::function< void(const Path &)> &emit)
 Emit bounded decoration paths while preserving each originating declaration.

Variables

constexpr TextDecoration donner::svg::kDecorationLinesBeneathText
 Lines that CSS Text Decoration 3 paints beneath a run's glyphs; line-through paints above them.

Detailed Description

Shared, backend-agnostic text geometry for RendererInterface::drawText.

RendererTinySkia::drawText and RendererGeode::drawText historically each re-derived per-glyph placement (outline โ†’ stretch โ†’ translate โ†’ rotate), which let the two copies drift. This header is the shared placement layer both backends consume so the geometry is computed once. It encodes tiny-skia's behavior verbatim (tiny-skia is the parity reference); geode converges to it.

Pure geometry only: inputs/outputs are donner::Path / Transform2d / TextEngine - no backend paint types. No allocation beyond what Path itself does; no exceptions.


Class Documentation

◆ donner::svg::PreparedTextDraw

struct donner::svg::PreparedTextDraw

Immutable layout slice and full-element bounds prepared once for a text effect owner.

Class Members
Box2d elementBounds
vector< TextRun > runs

◆ donner::svg::TextDrawGeometry

struct donner::svg::TextDrawGeometry

Mutable per-call run copy after effect ownership and visibility filtering.

Class Members
Box2d elementBounds
vector< TextRun > runs

◆ donner::svg::GlyphOutlineAndPlacement

struct donner::svg::GlyphOutlineAndPlacement

A glyph's outline split into the part that depends only on the glyph and the part that depends only on where the glyph sits in the run.

The two compose back into the placed outline: TransformPath(outline, glyphFromLocal) maps to the same place PlacedGlyphOutline does. It is not the same arithmetic - that one composes the placement into a single affine - so the two agree as mappings, not bit for bit, whenever a rotation is present.

Splitting them lets a renderer key a cache on glyph identity (font, glyph index, effective scale, stretch, rotation) and reuse one outline for every occurrence, carrying the per-occurrence placement as a transform instead of re-deriving and re-transforming the outline for each one.

Class Members
Transform2d glyphFromLocal Pure translation placing outline at its baseline position in the text element's local space.
Path outline Raw glyph outline at the glyph's effective scale, with the lengthAdjust stretch and the per-glyph rotation already baked in. Empty for .notdef and for glyphs with no vector outline.

◆ donner::svg::GlyphFaceScale

struct donner::svg::GlyphFaceScale

The face that draws one glyph, with its outline scale and whether it has only bitmap glyphs.

Class Members
bool bitmapOnly = false True when font has no vector outlines.
FontHandle font Face that draws the glyph.
float scale = 0.0f scaleForPixelHeight of font at the run's used size.