Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
TextToOutlines.h File Reference

Pure text-to-outline conversion helper, decoupled from ImGui and from the editor shell so it can be unit-tested headlessly (see donner/editor/tests/TextToOutlines_tests.cc). More...

#include <optional>
#include <string>
#include <vector>
#include "donner/svg/SVGDocument.h"
#include "donner/svg/SVGElement.h"
Include dependency graph for TextToOutlines.h:

Classes

struct  donner::editor::ConvertTextToOutlinesResult
 Result of preparing a text-to-outline conversion. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

ConvertTextToOutlinesResult donner::editor::convertTextToOutlines (svg::SVGDocument &document, const svg::SVGElement &textElement)
 Prepare a text-to-outline conversion of textElement within document.

Detailed Description

Pure text-to-outline conversion helper, decoupled from ImGui and from the editor shell so it can be unit-tested headlessly (see donner/editor/tests/TextToOutlines_tests.cc).

This implements the structural core of "Convert Text to Outlines":

  • convertTextToOutlines resolves the computed glyph outlines for a single selected <text> element using Donner's renderer-facing text geometry (SVGTextElement::convertToOutlineGlyphs(), which drives the same TextEngine geometry the renderer consumes and retains the source element that painted each glyph), serializes each placed glyph Path to an SVG <path d="..."> in paint order, and builds a detached replacement <g> group carrying one <path> per glyph.
  • Paint is preserved from the text element's computed style (via SVGElement::getComputedStyle()), not just its presentation attributes, so every styling form survives: presentation attributes, CSS rules (class and inline style), inherited paint, currentColor (resolved against the element's color), and url(#id) paint-server references. The group carries the text root's resolved fill, fill-rule, fill-opacity, stroke, stroke-width, stroke-opacity, opacity, and transform; per-<tspan> paint that differs from the group is applied on the individual glyph <path>s so multi-color runs are not collapsed.

The conversion is DOM-first: it builds unattached DOM elements and never mutates the document. The caller applies it as ordinary structural DOM edits - insert the group before the <text> (preserving paint order), insert each path into the group, delete the <text> - through the editor's mutation seam (EditorCommand::InsertElementCommand / DeleteElementCommand), so source reflection emits deltas and entity identity elsewhere in the document survives.

Error handling: if glyph-outline extraction fails or yields empty outlines, the function fails as a whole (ok == false, no elements created in the document tree) and the caller must not mutate the document.

Function Documentation

◆ convertTextToOutlines()

ConvertTextToOutlinesResult donner::editor::convertTextToOutlines ( svg::SVGDocument & document,
const svg::SVGElement & textElement )
nodiscard

Prepare a text-to-outline conversion of textElement within document.

Builds detached replacement elements; does not attach them or mutate the document tree. See file comment for outline extraction, grouping, and style preservation semantics.

Parameters
documentDocument containing textElement.
textElementThe <text> element to convert. Must be a <text> element belonging to document.