Donner SVG 0.8.0
0.8.0 · ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
ViewportSvgExport.h File Reference

Viewport SVG export. More...

#include <string>
#include <string_view>
#include "donner/base/Box.h"
#include "donner/editor/OverlayRenderer.h"
#include "donner/editor/ViewportState.h"
#include "donner/svg/SVGDocument.h"
Include dependency graph for ViewportSvgExport.h:
This graph shows which files directly or indirectly include this file:

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, std::string_view elementPrefix="")
 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 crop is limited to the original document bounds, so a viewport that contains the whole image preserves the source viewBox and intrinsic dimensions. The export is vector-first: the source SVG children are copied verbatim into a clipped <g>, never snapshotted as a raster <image>. ViewportState supplies the screen↔document mapping; the source root supplies the document bounds when its viewBox is available.

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 preferred id="donner-editor-overlay" group via SerializeOverlaySnapshotToSvg. If the source already declares that id, the exporter appends a numeric suffix. 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 the intersection of the original document bounds and viewport.screenToDocument(renderPaneRect), formatted as min-x min-y width height. width/height retain the source root's effective preserveAspectRatio scale for a clipped region. An export that contains the entire document retains its intrinsic dimensions, including any original letterbox space. 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 crop 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 are refused with a human-readable error when an href-suffixed attribute targets http://, https://, or file:// (the export cannot embed or safely reference them; vector-first, no rasterizing), when the source has not been reparsed into the tree, or when the prolog declares a DOCTYPE internal subset (the parser drops the declarations, so the exported body could carry undeclared entity references). CSS url() references are not inspected.

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 (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,
std::string_view elementPrefix = "" )

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).
elementPrefixNamespace prefix (including the trailing :) to give the emitted elements, so they resolve to the SVG namespace inside a root that is itself prefixed. Empty for the usual default-namespace root.
Returns
Concatenated overlay SVG children, or an empty string when the snapshot has no drawable primitives.