[GTALUG] Scripting Inkscape, and a new font appears

Stewart C. Russell scruss at gmail.com
Wed May 11 08:57:05 EDT 2016


Hi - it was great to see a bunch of you all last night. That was a good
round table last night.

[Impatient types can skip to the end, where you get to play with a free
font I made.]

A couple of months back at the Graphics session, someone asked if
Inkscape - the 2D vector graphics workhorse that everyone seems to use -
could be scripted. We pretty much said that it couldn't. Recently, I
found out that it does support a limited form of scripting, and wish to
pass this on.

The key to it is understanding Inkscape's command verbs. These can be
listed using:

	inkscape --verb-list

These verbs map to Inkscape commands, and often have names linked to the
menu they live in (such as "FileQuit" doing what you'd expect).

I had a task I had to repeat on many files: convert all the stroked
lines to filled paths. You'd need to do this if you are laser engraving
a simple drawing, but there are other applications for this too. Here's
a command that would do this for all objects in a drawing, and
_overwrite_ the input file:

	inkscape --verb EditSelectAll --verb SelectionUnGroup \
		 --verb EditSelectAll --verb SelectionUnGroup \
		 --verb EditSelectAll --verb SelectionUnGroup \
		 --verb EditSelectAll --verb ObjectToPath \
		 --verb EditSelectAll --verb SelectionCombine \
		 --verb EditSelectAll --verb StrokeToPath \
		 --verb FileSave      --verb FileClose \
		 --verb FileQuit      input.svg

What this does:

1. Selects everything, and ungroups all objects (×3, to break up most
nested groups);
2. Selects everything, and converts all objects to paths (so text,
circles, polygons, spirals become paths, the lowest-level SVG object);
3. Selects everything, and combines everything into one path;
4. Selects everything, and converts all strokes to filled paths (so a
two node straight line 1 mm wide would become a four node filled
rectangle 1 mm thick);
5. Overwrite the input file, close it, and quit.

The process has some disadvantages:

1. It opens a window *every* *time*. You can't execute verbs without the
GUI opening.
2. You can't have another copy of Inkscape open while you do this.
3. Realistically, you can't really do *anything* at your computer until
this is done, as it's popping up windows and shifting focus like crazy.
(ssh types can say “heh!” in a smug manner now)
4. You can't set parameters to verbs.
5. It will overwrite the input file.
6. It clogs up your "File / Recent" menu with all of the files you scripted.

So, about that font:-

Years ago, Commodore made a fairly terrible little pen plotter, the
1520. Its main claim to nerdworthiness was that, until recently, its 2KB
microcontroller had never been successfully dumped. When it was finally
cracked open (details: http://e4aws.silverdr.com/hacks/6500_1/) it
revealed a rather cleverly encoded vector font. This encoding - packing
a simple but complete 8×8 plotting language into 8 bits - used only 660
bytes to describe an entire font.

With a bit of PostScript, that ugly Inkscape script up there, and
Fontforge (and its slightly less ugly-but-still-Python scripting) I made
a family of OpenType fonts from the Commodore 1520 ROM dump. You can
even use 'em on the web (if you really want to embrace that "No, Really,
I Wouldn't" aesthetic):

	https://fontlibrary.org/en/font/fifteentwenty

Or source:

	https://github.com/scruss/FifteenTwenty

Have fun!

 Stewart


More information about the talk mailing list