std.svg.path

SVG-Pfad-Builder: <path d=„…“> programmatisch aufbauen. Unterstützt alle SVG-Pfadbefehle: MoveTo, LineTo, kubische und quadratische Bézier-Kurven, Bögen und ClosePath. Koordinaten können absolut (Großbuchstaben) oder relativ (Kleinbuchstaben) sein.

std.svg · std.svg.elements · std.svg.style

Ein Pfad wird mit SvgPathBegin begonnen, mit den Befehlen unten gefüllt und wie jedes andere Element mit SvgApply abgeschlossen. Stil und Transformation kommen vorher aus std.svg.style.


Verwendung

import std.io;
import std.svg.builder;
import std.svg.elements;
import std.svg.style;
import std.svg.path;

fn main(): int64 {
    var doc: int64 := SvgNew(300.0, 250.0);
    SvgSetPrettyPrint(doc, 1);

    // Fertige Form: fuenfzackiger Stern
    SvgSetFillHex(doc, "gold");
    SvgPathBegin(doc);
    SvgPathStar(doc, 150.0, 120.0, 60.0, 25.0, 5);
    SvgApply(doc);

    // Kubische Bezierkurve: erst die Kontrollpunkte, dann der Endpunkt
    SvgSetFillNone(doc);
    SvgSetStroke(doc, 0.0, 0.0, 0.0);
    SvgPathBegin(doc);
    SvgMoveTo(doc, 10.0, 230.0);
    SvgCurveSetCP(doc, 40.0, 160.0, 65.0, 160.0);
    SvgCurveTo2(doc, 95.0, 230.0);
    SvgApply(doc);

    Print(SvgToString(doc)); Print("\n");
    return 0;
}

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="250">
  <path d="M150 60 L160 105 L198 108 L170 125 L174 156 L150 145 L126 156 L130 125 L102 108 L140 105 Z" fill="gold"/>
  <path d="M10 230 C40 160 65 160 95 230" fill="none" stroke="#000000"/>
</svg>

 
SvgCurveTo stürzt ab — der Aufruf schreibt nach Adresse 0 und beendet das Programm mit einem Speicherzugriffsfehler (#1688). Die reparierte Fassung heißt SvgCurveTo2 und ist im Beispiel oben verwendet.

Ebenfalls zu beachten: Die fertigen Formen (SvgPathStar, SvgPathArc, SvgPathPieSlice, SvgPathArrow) schreiben nur Pfaddaten. Ohne vorangehendes SvgPathBegin erscheint nichts in der Ausgabe — ohne Meldung.

Funktionen

Signatur Sichtbarkeit Beschreibung
SvgPathBegin(doc: int64): void pub Path begin / setup
SvgPathBeginId(doc: int64, id: pchar): void pub
SvgClosePath(doc: int64): void pub
SvgApplyHidden(doc: int64): void pub Applies path as invisible (visibility:hidden, but still referenciable by ID)
SvgSetFillRule(doc: int64, rule: int64): void pub
SvgMoveTo(doc: int64, x: f64, y: f64): void pub Absolute path commands
SvgLineTo(doc: int64, x: f64, y: f64): void pub
SvgHLineTo(doc: int64, x: f64): void pub
SvgVLineTo(doc: int64, y: f64): void pub
SvgCurveSetCP(doc: int64, x1: f64, y1: f64, x2: f64, y2: f64): void pub SvgCurveSetCP sets control points; SvgCurveTo draws cubic bezier
SvgCurveTo(doc: int64, x: f64, y: f64): void pub Stürzt ab (#1688) — SvgCurveTo2 nehmen
SvgCurveTo2(doc: int64, x: f64, y: f64): void pub Kubische Bézierkurve zum Endpunkt, Kontrollpunkte aus SvgCurveSetCP
SvgSmoothCurveSetCP(doc: int64, x2: f64, y2: f64): void pub Smooth cubic bezier (S command): SvgSmoothCurveSetCP + SvgSmoothCurveTo
SvgSmoothCurveTo(doc: int64, x: f64, y: f64): void pub
SvgQuadSetCP(doc: int64, x1: f64, y1: f64): void pub Quadratic bezier (Q command): SvgQuadSetCP + SvgQuadTo
SvgQuadTo(doc: int64, x: f64, y: f64): void pub
SvgSmoothQuadTo(doc: int64, x: f64, y: f64): void pub
SvgArcSetup(doc: int64, rx: f64, ry: f64, rot: f64): void pub Arc: SvgArcSetup sets rx,ry,rot; SvgArcFlags sets laf,sf; SvgArcTo draws
SvgArcFlags(doc: int64, laf: int64, sf: int64): void pub
SvgArcTo(doc: int64, x: f64, y: f64): void pub
SvgMoveToRel(doc: int64, dx: f64, dy: f64): void pub Relative path commands
SvgLineToRel(doc: int64, dx: f64, dy: f64): void pub
SvgHLineToRel(doc: int64, dx: f64): void pub
SvgVLineToRel(doc: int64, dy: f64): void pub
SvgCurveToRel(doc: int64, x: f64, y: f64): void pub
SvgArcToRel(doc: int64, x: f64, y: f64): void pub
SvgPathArc(doc: int64, cx: f64, cy: f64, r: f64, startDeg: f64, endDeg: f64): void pub SvgPathArc: circular arc from startDeg to endDeg around (cx,cy) with radius r Uses A-command for accuracy
SvgPathPieSlice(doc: int64, cx: f64, cy: f64, r: f64, startDeg: f64, endDeg: f64): void pub SvgPathPieSlice: filled pie slice
SvgPathStar(doc: int64, cx: f64, cy: f64, r1: f64, r2: f64, n: int64): void pub SvgPathStar: star with n points, outer radius r1, inner radius r2
SvgPathArrow(doc: int64, x1: f64, y1: f64, x2: f64, y2: f64, headLen: f64): void pub SvgPathArrow: draws an arrow from (x1,y1) to (x2,y2)

Signaturen automatisch aus std/svg/path.lyx erzeugt (Stand 2026-08-02, lyxc 1.0.21A). Beschreibungen stammen aus den Quellkommentaren und sind teilweise unvollständig.

Letzte Aktualisierung: 2026-08-19 — Abschnitt „Verwendung„ ergänzt, Beispiel mit lyxc 1.1.3I übersetzt und ausgeführt; Absturz in SvgCurveTo als #1688 gemeldet.