#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2026 Alain Matthes # SPDX-License-Identifier: LPPL-1.3c # Maintainer: Alain Matthes """ svg2pgf.py -- convert SVG drawings into ornament files for pgfornament. Output format (the short macros defined by \\pgfornament@shortcuts): \\m x y moveto \\l x y lineto \\c x1 y1 x2 y2 x y curveto \\o closepath \\s fill and stroke \\k stroke only \\pgfusepathqfill fill only (svg elements without stroke: thin gaps stay open) \\r 0 0 W H + \\ubb exact bounding box (first lines of each file) Coordinates are in bp, origin at the lower left corner of the drawing. Usage ----- A sheet with several ornaments (eps, pdf or svg): python3 svg2pgf.py --family celtic --split pack.eps -> look at build/test-celtic.pdf, then e.g. --skip 1,2 to drop texts One file: python3 svg2pgf.py ornament.svg -o pgfornament-myfam1.pgf --height 60 A whole family (all SVG files of a folder, in alphabetical order): python3 svg2pgf.py --family myfam --out-dir build svgs/*.svg --height 60 -> build/generic/myfam/pgfornament-myfam1.pgf, pgfornament-myfam2.pgf, ... build/latex/pgfornament-lib-myfam.code.tex (table \\@pgfornamentDim) build/test-myfam.tex (catalogue to check the result) Options ------- --width W / --height H scale the drawing to this width / height (bp) --scale S otherwise: 1 SVG unit = S bp (default 0.75 : 1px = 0.75bp, 1 for eps/pdf files) --digits N decimals in the output (default 2) --source TEXT text written in the header (origin, licence) --split the svg is a sheet with several ornaments (needs --family): one file per group of overlapping shapes, in reading order; small groups (texts, logos) are dropped --min-size F with --split: minimal size relative to the largest ornament (default 0.25) --skip 1,2 leave out these parts (numbers shown by a first run) --keep-white keep white elements (by default they are ignored: pgfornament draws with only one colour, so a white background would become a black rectangle) Input: .svg files, or .eps / .ps / .pdf files (first page) if ghostscript and pdftocairo are installed (TeX Live provides neither; MacTeX includes gs, pdftocairo comes with poppler: brew install poppler). Supported: (all commands, arcs included), (rounded corners), , , , , , , , nested transform attributes, fill-rule evenodd, fill="none" (stroke only). CSS: style attribute and simple