Skip to main content

CiHuang (雌黄) - SVG Element Editor

Click any single element of an SVG and move it, repaint it, reshape it, or rewrite its text.

CiHuang (雌黄) is the yellow mineral scholars once used as correction fluid: you brush it over a wrong character and write the right one on top. This tool does the same to a drawing -- pick one piece, fix it, leave everything else untouched.

中文说明

Features

  • Open any SVG -- a real SVG file is parsed as XML, not flattened to an image.
  • Click to select one element -- hit-testing walks the elements in reverse paint order and tests actual pixels, so you select the shape you see, not its bounding box.
  • Select a group of things -- Shift-click to add, or drag a marquee box around several shapes (for example a figure and its caption), then move them together.
  • Group / ungroup -- Ctrl+G wraps the selection in a <g> (clicking then picks the whole group, like Inkscape); Ctrl+Shift+G dissolves it.
  • Smart Group -- Ctrl+Alt+G clusters objects that sit close together (a figure and its caption, say) and groups them automatically.
  • No accidental backdrop grab -- a click on a full-canvas background reads as a click on empty space; select the backdrop from the element list when you mean to.
  • Drag to move -- the move is written as a translate(...) on that element only.
  • Draw new shapes -- Rect, Ellipse, Line, Arrow and Text tools; pick one and drag on the canvas (a click drops a default-sized shape).
  • Connect shapes with arrows -- the Connect tool draws an edge from one shape to another, and the edge follows the shapes when you move them.
  • Repaint -- set fill and stroke with a color picker, or clear them to none.
  • Reshape -- an editable table exposes every raw attribute (cx, r, d, points, transform, ...), so any geometry can be changed.
  • Edit text -- rewrite the content of <text> elements.
  • Duplicate / delete / undo / redo, save as SVG, export to PNG.
  • Scriptable -- the same operations are available from the CLI, a Python API and an OpenAI function-calling tool set.

Limitations

Worth knowing before you rely on it:

  • Hit-testing renders each candidate to a raster capped at 900 px; only elements whose bounding box contains the click are rasterised, so it stays quick on large files.
  • Editing <text> replaces any <tspan> children with a single text run.
  • Grouping requires the selected elements to share the same parent; the tool does not re-order elements across groups.
  • Connectors are straight lines between shape centres (clipped to the box edges); there is no orthogonal or obstacle-avoiding routing, and you cannot drag an edge's handles.
  • It does not touch viewBox, stylesheets inside <style>, or animations.
  • <image> and <use> can be moved and recolored but their referenced content is not edited.
  • It is an annotator, not a full vector editor: no bezier-point editing, no snapping.

Requirements

  • Python 3.10+
  • PySide6 (installed automatically)

Installation

From PyPI:

pip install cihuang

From source:

git clone https://github.com/CodeOfMe/CiHuang.git
cd CiHuang
pip install -e .

Quick Start

# Open the graphical editor
cihuang gui examples/sample.svg

# Or just list the editable elements of a file
cihuang info examples/sample.svg

CiHuang GUI

Usage

GUI

cihuang gui drawing.svg
# or, equivalently:
cihuang-gui drawing.svg

Left mouse button selects and drags. Drag on empty space to marquee-select; hold Shift to add to the selection. Middle button pans; the wheel zooms gently and is limited so the drawing cannot shrink away. Ctrl+G groups the selection, Ctrl+Shift+G ungroups it and Ctrl+Alt+G smart-groups nearby objects. The right dock edits fill, stroke, text and raw attributes; the left dock lists every element.

Pick a Draw tool to add shapes: drag to size a rect or ellipse, drag a line or arrow, click to drop text, or use Connect and drag from one shape to another to link them with an arrow. Esc returns to Select.

CLI

# List elements (add --json for machine output)
cihuang info drawing.svg

# Set the fill of element 3, writing drawing-edited.svg
cihuang fill drawing.svg 3 "#ff6600"

# Recolor the stroke instead, to an explicit output path
cihuang fill drawing.svg 3 "#003366" --stroke -o out.svg

# Clear an element's fill
cihuang fill drawing.svg 3

# Move element 1 by dx=20, dy=-5
cihuang move drawing.svg 1 20 -5

# Rewrite the text of element 5
cihuang text drawing.svg 5 "New label"

# Delete element 0
cihuang remove drawing.svg 0

Python API

from cihuang import SvgDocument, cihuang_set_color

# One-shot, writes drawing-edited.svg
result = cihuang_set_color(input_path="drawing.svg", element_index=3, color="#ff6600")
print(result.success)   # True / False
print(result.data)      # {"output": "...", "index": 3, "prop": "fill", "color": "#ff6600"}

# Or drive the document directly, then save wherever you like
doc = SvgDocument.load("drawing.svg")
doc.push_undo()
doc.set_color(3, "fill", "#ff6600")
doc.translate(3, 20, -5)
doc.set_text(5, "New label")
doc.save("out.svg")

Agent Integration

The TOOLS list exposes the same operations for OpenAI function calling.

from cihuang.tools import TOOLS, dispatch

payload = dispatch("cihuang_inspect", {"input_path": "drawing.svg"})
print(payload["success"])

Development

pip install -e ".[dev]"
ruff format . && ruff check . && pytest

License

GPL-3.0-or-later. See LICENSE.

Metadata

Release files for cihuang 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cihuang 0.2.2
File Size Uploaded
cihuang-0.2.2.tar.gz 43.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cihuang 0.2.2
File Interpreter ABI Platform
cihuang-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 84.9 kB

Release files / cihuang-0.2.2.tar.gz

Download URL cihuang-0.2.2.tar.gz
Size 43.8 kB
Tags Source
SHA-256 checksum
How to use checksums
48409d9c860fe91b892f6d4cb8a50b9731bec9032614d88eec72fc0bab9c9fd3
BLAKE2b-256 checksum
How to use checksums
8f361cb64d961d58cb69bd8c057f07c595f31971601d768de1cf2353f491d065
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / cihuang-0.2.2-py3-none-any.whl

Download URL cihuang-0.2.2-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab66b8369c74456a8868b708fc858905338ab9a9606c9f4650104b37b00e889a
BLAKE2b-256 checksum
How to use checksums
6306f0b85ecbff21d2a412454af3d597fea4cf1a037898e001087ffffe9e0bd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page