Scripting Inkscape, and a new font appears

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

On 11 May 2016 at 08:57, Stewart C. Russell <scruss@gmail.com> wrote:
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.
Cool!
So, about that font:-
Also (nerdly) cool! You might want to hand-tune the last few of those fonts. They have filled-n letters (like e and o) and i doesn't show up at all. I suspect it is that the rectangles you described above became degenerate, so the fill covers more than you would want. ../Dave

Hi Dave,
Also (nerdly) cool!
Glad you likeed it.
You might want to hand-tune the last few of those fonts. They have filled-n letters (like e and o) and i doesn't show up at all.
That was deliberate. It's what pen plotters do if you try to reproduce detail that's finer than the pen: detail disappears. I made the demi weight so that you could have a bold that had some extra heft yet retained some detail in the counters. I don't recommend using the lightest weight at all outside a CNC shop. It has no stroke weight, so disappears on most screens. It is easy to turn it into single strokes in most CAD packages so you can drive a tool/pen/laser around it quickly. (I clean up my Inkscape exports in the truly awful LaserCut for Windows Demo, that runs nicely under Wine: https://wiki.nottinghack.org.uk/wiki/Laser_cutter/LaserCut/Install - although it's a demo, it does allow you to export DXF, and if you're using a Rabbit Laser driven by LaserCut (like ProtoLab), it saves the project when you exit, and the results work very well.) cheers, Stewart
participants (2)
-
David Mason
-
Stewart C. Russell