inkscape/agent-harness/INKSCAPE.md
Inkscape is a vector graphics editor whose native format is SVG (XML). This is
a major advantage -- we can directly parse, generate, and manipulate SVG files
using Python's xml.etree.ElementTree module. No binary format parsing needed.
┌─────────────────────────────────────────────────┐
│ Inkscape GUI │
│ ┌──────────┐ ┌──────────┐ ┌───────────────┐ │
│ │ Canvas │ │ Layers │ │ Object Props │ │
│ │ (GTK) │ │ (GTK) │ │ (GTK) │ │
│ └────┬──────┘ └────┬─────┘ └──────┬────────┘ │
│ │ │ │ │
│ ┌────┴─────────────┴──────────────┴──────────┐ │
│ │ SVG Document Object Model │ │
│ │ XML tree of <svg>, <rect>, <circle>, │ │
│ │ <path>, <text>, <g> elements │ │
│ └─────────────────┬──────────────────────────┘ │
│ │ │
│ ┌─────────────────┴──────────────────────────┐ │
│ │ lib2geom (geometry engine) │ │
│ │ Path operations, boolean ops, transforms │ │
│ └─────────────────┬──────────────────────────┘ │
└────────────────────┼────────────────────────────┘
│
┌──────────┴────────────┐
│ Cairo/librsvg │
│ (SVG rendering) │
│ + File format I/O │
└───────────────────────┘
Unlike GIMP (which has a complex binary .xcf format) or Blender (binary .blend), Inkscape's SVG format is plain XML. Our strategy:
inkscape --actions for advanced
operations (PDF export, path boolean ops, text-to-path conversion).We maintain a JSON project file alongside SVG for state tracking:
{
"version": "1.0",
"name": "my_drawing",
"document": {
"width": 1920,
"height": 1080,
"units": "px",
"viewBox": "0 0 1920 1080",
"background": "#ffffff"
},
"objects": [
{
"id": "rect1",
"name": "MyRect",
"type": "rect",
"x": 100, "y": 100,
"width": 200, "height": 150,
"style": "fill:#ff0000;stroke:#000;stroke-width:2",
"transform": "translate(10, 20) rotate(45)",
"layer": "layer1"
}
],
"layers": [
{
"id": "layer1",
"name": "Layer 1",
"visible": true,
"locked": false,
"opacity": 1.0,
"objects": ["rect1"]
}
],
"gradients": [
{
"id": "linearGradient1",
"type": "linear",
"x1": 0, "y1": 0, "x2": 1, "y2": 0,
"stops": [
{"offset": 0, "color": "#ff0000", "opacity": 1},
{"offset": 1, "color": "#0000ff", "opacity": 1}
]
}
],
"metadata": {
"created": "2024-01-01T00:00:00",
"modified": "2024-01-01T00:00:00",
"software": "inkscape-cli 1.0"
}
}
| SVG Element | Inkscape Tool | CLI Command |
|---|---|---|
<rect> | Rectangle | shape add-rect |
<circle> | Circle | shape add-circle |
<ellipse> | Ellipse | shape add-ellipse |
<line> | Line | shape add-line |
<polygon> | Polygon | shape add-polygon |
<path> | Bezier/Pen | shape add-path |
<text> | Text | text add |
<g> | Layer/Group | layer add |
<linearGradient> | Gradient | gradient add-linear |
<radialGradient> | Gradient | gradient add-radial |
CSS style | Fill/Stroke | style set-fill, style set-stroke |
transform | Transform | transform translate/rotate/scale |
| GUI Action | CLI Command |
|---|---|
| File -> New | document new --width W --height H |
| File -> Open | document open <path> |
| File -> Save | document save [path] |
| File -> Export PNG | export png <output> |
| File -> Export SVG | export svg <output> |
| Draw Rectangle | shape add-rect --x X --y Y --width W --height H |
| Draw Circle | shape add-circle --cx X --cy Y --r R |
| Draw Star | shape add-star --points 5 --outer-r 50 --inner-r 25 |
| Edit -> Transform | transform translate/rotate/scale INDEX |
| Object -> Fill/Stroke | style set-fill INDEX COLOR |
| Layer -> Add | layer add --name "Name" |
| Layer -> Reorder | layer reorder FROM TO |
| Path -> Union | path union A B |
| Path -> Difference | path difference A B |
| Path -> Object to Path | path convert INDEX |
| Text Tool | text add --text "Content" --x X --y Y |
| Edit -> Undo | session undo |
| Edit -> Redo | session redo |
<svg> element with dimensions, viewBox, namespaces<defs> with gradient definitions<g> elements for each layer (with inkscape:groupmode="layer")| Format | Method | Fidelity |
|---|---|---|
| SVG | Direct XML generation | Exact |
| PNG | Pillow (basic) / Inkscape (full) | Basic shapes / Full |
| Inkscape CLI | Full | |
| EPS | Inkscape CLI | Full |
Unit tests (test_core.py): Synthetic data, no real files needed
E2E tests (test_full_e2e.py): Real SVG generation