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
ViewportSvgExport.h File Reference

Viewport SVG export. More...

Include dependency graph for ViewportSvgExport.h:

Classes

struct  donner::editor::Result< T, E >
 A success-or-error value used by the viewport SVG exporter. More...
struct  donner::editor::ViewportExportOptions
 Options controlling viewport SVG export behavior. More...

Namespaces

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

Typedefs

using donner::editor::Recti = Box2<int>
 Integer screen-pixel rectangle (top-left / bottom-right corners). Used for the render pane content rect supplied to ExportViewportAsSvg.

Functions

std::string donner::editor::SerializeOverlaySnapshotToSvg (const SelectionChromeSnapshot &snapshot)
 Serialize an editor selection-chrome snapshot to overlay SVG children.
Result< std::string, std::string > donner::editor::ExportViewportAsSvg (const svg::SVGDocument &doc, const ViewportState &viewport, const Recti &renderPaneRect, const ViewportExportOptions &options, const SelectionChromeSnapshot *overlaySnapshot=nullptr)
 Export the currently-visible document region as a cropped, standalone SVG.

Detailed Description

Viewport SVG export.

Exports the document region currently visible in the editor render pane as a standalone, cropped SVG. The export is vector-first: the source SVG children are copied verbatim into a clipped <g>, never snapshotted as a raster <image>. The crop is derived entirely from ViewportState - it is the single source of truth for the screen↔document mapping.

Content export is vector-first as described above. When ViewportExportOptions::includeSelectionOverlay is set and a SelectionChromeSnapshot is supplied, the editor selection chrome (path outlines, AABBs, resize handles, marquee) is serialized into the id="donner-editor-overlay" group via SerializeOverlaySnapshotToSvg. The overlay group is clipped to the same donner-viewport-clip clipPath as the content and uses deterministic, theme-independent styling.

Function Documentation

◆ ExportViewportAsSvg()

Result< std::string, std::string > donner::editor::ExportViewportAsSvg ( const svg::SVGDocument & doc,
const ViewportState & viewport,
const Recti & renderPaneRect,
const ViewportExportOptions & options,
const SelectionChromeSnapshot * overlaySnapshot = nullptr )

Export the currently-visible document region as a cropped, standalone SVG.

The exported root viewBox is viewport.screenToDocument(renderPaneRect) formatted as min-x min-y width height; width/height are the render pane dimensions in CSS pixels. Source root attributes (xmlns, etc.) are carried onto the exported root with viewBox/width/height replaced. The source SVG children are wrapped verbatim in a <g> clipped to the document-space viewport rect.

The export reads from doc only; it does not reparse the active document or clear any compositor cache. The source document is never mutated.

Self-contained documents export successfully. Documents that reference external resources over http://, https://, or file:// via href / xlink:href are refused with a human-readable error, since the export cannot embed or safely reference them (vector-first; no rasterizing).

When options.includeSelectionOverlay is true and overlaySnapshot is non-null, the overlay group is populated with the serialized snapshot (see SerializeOverlaySnapshotToSvg). When the flag is true but the pointer is null, an empty overlay group is emitted (M6 back-compat). The overlay group is clipped to the same donner-viewport-clip clipPath as the content.

Parameters
docSource SVG document. Must have an owned XML source store.
viewportViewport state describing the screen↔document mapping.
renderPaneRectRender pane content rect in screen (CSS) pixels.
optionsExport options (background + overlay handling).
overlaySnapshotOptional selection-chrome snapshot, used only when options.includeSelectionOverlay is true. The snapshot must be captured at export time so the overlay samples the same selection state the editor currently displays.
Returns
Exported SVG text, or a human-readable error string.

◆ SerializeOverlaySnapshotToSvg()

std::string donner::editor::SerializeOverlaySnapshotToSvg ( const SelectionChromeSnapshot & snapshot)

Serialize an editor selection-chrome snapshot to overlay SVG children.

Emits overlay primitives (selected path outlines, selection AABBs, the oriented rotation box, resize handles, and the marquee rect) as SVG element strings in document space, with NO wrapping <g> - the caller is responsible for the enclosing <g id="donner-editor-overlay">.

Backend-neutral: this reads only the snapshot struct and Path geometry. It never touches ImGui, a GPU backend, or any renderer. Styling is governed by fixed, theme-independent constants so the exported chrome is deterministic regardless of ImGui theme drift.

Parameters
snapshotCaptured selection chrome (document-space geometry).
Returns
Concatenated overlay SVG children, or an empty string when the snapshot has no drawable primitives.