neu_draw.vectorfile

A vector figure as a tree of named groups, and its two writers: SVG and PDF.

Needs only numpy and the standard library (and imageio, to encode an SVG’s embedded PNGs); neu_draw.backends.vector builds the tree from a live view. Coordinates are logical pixels, y down, one pixel per point. Colours are RGBA floats in 0-1, and both formats composite opacity in sRGB.

Illustrator keeps named groups from the SVG, not the PDF: it opens a PDF it did not write onto a single layer, while Acrobat shows the PDF’s nested optional content as a layer tree. The SVG is therefore written for Illustrator’s importer: SVG 1.1, xlink:href on images (a bare href leaves them blank), no clipPath wrapper, a baseline offset instead of dominant-baseline, and group ids in Illustrator’s _xHH_ escaping, which it decodes back into layer names.

Attributes

Classes

Group

Image

Markers

Many point markers of one shape and style, e.g. one drawable's synapse set.

Rect

Segments

Independent line segments as one stroked path, e.g. a skeleton.

Text

Functions

illustrator_id(name) → str

name in Illustrator's id escaping: anything but a letter, digit, - or

to_pdf(root, width, height) → bytes

The tree as a one-page PDF, each group a nested optional-content layer.

to_svg(root, width, height) → str

The tree as SVG 1.1. Every group is a <g> with an Illustrator-style id and an

write(root, width, height, path) → str

Write .svg or .pdf by extension.

Module Contents

class neu_draw.vectorfile.Group
child(name: str) → Group

The sub-group called name, created at the end if it is not there yet.

nested(path: Iterable[str]) → Group
prune() → Group

Drop empty sub-groups, which an editor shows as layers holding nothing.

walk()
children: list = []
name: str
class neu_draw.vectorfile.Image
h: float
rgba: numpy.ndarray
w: float
x: float
y: float
class neu_draw.vectorfile.Markers

Many point markers of one shape and style, e.g. one drawable’s synapse set.

fill: RGBA
shape: str
size: float
stroke: RGBA | None = None
stroke_width: float = 0.0
xy: numpy.ndarray
class neu_draw.vectorfile.Rect
fill: RGBA
h: float
w: float
x: float
y: float
class neu_draw.vectorfile.Segments

Independent line segments as one stroked path, e.g. a skeleton.

cap: str = 'round'
segments: numpy.ndarray
stroke: RGBA
width: float
class neu_draw.vectorfile.Text
fill: RGBA
size: float
text: str
x: float
y: float
neu_draw.vectorfile.illustrator_id(name: str) → str

name in Illustrator’s id escaping: anything but a letter, digit, - or . becomes _xHH_, as does a leading digit. Illustrator writes ids this way and decodes them on import, so the layer panel reads T4a 78044864 : Mi1 (17).

neu_draw.vectorfile.to_pdf(root: Group, width: float, height: float) → bytes

The tree as a one-page PDF, each group a nested optional-content layer.

neu_draw.vectorfile.to_svg(root: Group, width: float, height: float) → str

The tree as SVG 1.1. Every group is a <g> with an Illustrator-style id and an inkscape:label; the top-level groups are marked as Inkscape layers too.

neu_draw.vectorfile.write(root: Group, width: float, height: float, path: str) → str

Write .svg or .pdf by extension.

neu_draw.vectorfile.BASELINE = 0.35
neu_draw.vectorfile.FONT_FAMILY = "'Noto Sans', Helvetica, Arial, sans-serif"
neu_draw.vectorfile.KAPPA = 0.5522847498
neu_draw.vectorfile.RGBA
neu_draw.vectorfile.Shape