New Hershey Text extension
Briefly: I've rewritten Hershey Text from scratch. This has been underway for some time, but I've copied it to a public repository since things are now reasonably stable on Inkscape 0.92.x, and it now appears to be running well on 1.0 also.
Links:
- Hershey Text 3.0 for Inkscape 0.92: https://gitlab.com/oskay/hershey-text
- Hershey Text 3.0 for Inkscape 1.x : https://gitlab.com/oskay/hershey-text/tree/Inkscape_v1
Why is this needed?
Two main reasons:
(1) When I wrote Hershey Text, it filled a need for adding engraving fonts for plotters and CNC applications. However, it was based on a lightly-modified historical font format that had significant limitations. Amongst them:
- As a "custom" (not proprietary, but not standard) font format, there was no readily available font editor for the format.
- The format only supported characters made of straight line segments.
- The format was based on ascii character position, and did not support extended Latin-1 extended characters, let alone Unicode.
- The font data was stored as a set of data arrays in a single large python file. This made adding new fonts (even if the data were available) very cumbersome, since even the .inx file would need to be edited.
(2) Additionally, the extension itself was relatively simplistic: It rendered text that you entered in the text entry box. This restriction led to several efforts (by other people) to add layout information to the extension (e.g,. !25 (closed) and https://github.com/VirToReal/Hardy-Hershey-Text ).
However (IMHO), adding layout data within the extension is only a partial solution to the issue, which is that you would really like to convert text in your document into stroke fonts1. Since Inkscape already offers ample text layout and manipulation tools, we should take advantage of them, and use Hershey Text after performing the layout, to convert the text into stroke fonts. We should render the text where it belongs.
The major changes are:
-
Migrate font format to use SVG fonts.2
- SVG fonts support unicode, meaning that we can use a full range of characters. We are no longer limited to the ASCII range that the historical Hershey font formats used.
- Arbitrary curves are supported within glyphs; we are no longer limited to the straight line segments used in the historical Hershey format.
- The set of fonts can now be expanded.
-
Add a mechanism for adding your own SVG fonts, either within the folder containing the default fonts, or from an external file or directory. This is particularly important for installations where one does not have access to edit the contents of the Inkscape extensions directory.
-
Support font mapping: If a given font face is used for a given block of text, check first to see if a matching SVG font is present. If not, substitute with the default (selected) stroke font from the list of included fonts. 3
-
Instead of entering text (one line at a time) in the extension, this script now converts text (either all text, or all selected text) in the document, replacing it in place. While not every possible method of formatting text is supported, many are.
-
Add several new fonts beyond those included with the original Hershey Text.4
-
Include the license for the new fonts. Some of the fonts are licensed under the SIL OFL. Distributing them with GPL licensed software is allowed, so long as the license is included and the font files are easily separable. 5
Work in progress and current status (Updated 2019-05-29)
- Code appears to be working well in general.
- As of 2019-05-01, the extension now appears to work reasonably well on 1.0, on a Mac
- As of 2019-05-13, with fixes committed to the inkex framework, working well on Windows also.
- One significant text alignment issue remains, but appears to be due due to Inkscape behavior. Issues are noted at: https://gitlab.com/oskay/hershey-text/issues
- Tests are complete and pipelines are passing.
- Character set has been expanded to include most of latin-1 6. I expect to submit a future MR for future font updates.
- Ready for code review and merge request.
Cross-reference:
This topic has come up previously a couple of times, so I'm tagging the relevant discussions:
(1) !25 (closed) (2) #63 (closed)
Footnotes:
-
Ideally, of course, it would be nice if Inkscape offered full support to display and manipulate text in SVG fonts. Since I don't see that happening in the foreseeable future, this is a next-best solution for those of us that need and use stroke fonts.
↩ -
Why, of all formats, SVG?
Which format to use is a big, tough question. It's one of the reasons that it's been years between versions. The reason to choose it is not because Inkscape is an SVG editor. (That's just a coincidence really -- Inkscape does not really support SVG fonts.) However, the choice is clear. Of all the modern standard font formats, the only one that offers true support for stroke-based fonts is SVG. Any other "modern" font format that you can name is probably just another outline font. However the SVG font format allows characters to be SVG elements -- that may be composed of strokes, fills, and so on.
Aside: Now as you may know, the SVG font format -- as a stand-alone font format -- is essentially a dead format. More or less, no one is using stand-alone SVG fonts. However, SVG fonts are perhaps surprisingly alive, thanks to emoji. The SVG font format has actually been enshrined within OpenType, and OpenType fonts can contain an "SVG font table", which is simply a font constructed according to the SVG 1.1 font format. Fonts of this spec are called "OTF+SVG" fonts, and typically intend that when client software cannot display a given character in the SVG table, it will fall back and display a TTF alternative. The neat thing about OTF+SVG is that in addition to having stroke-based characters, it can also contain color information -- and so this format is sometimes referred to as a "Color Font". OTF+SVG is supported by Photoshop, Illustrator, Firefox, MS Edge, Pages, Keynote, TextEdit, and others. Your takeaway message should be that SVG fonts do still exist, even though they aren't often observed on their own.
↩ -
One font designer (not me!) is already selling matched pairs of TTF and SVG fonts, to allow users to lay out their text with the Truetype font, and then use this new version of Hershey Text to substitute their stroke-based versions, right in place. Users should, if they want to, be able to do this kind of thing on their own without buying fonts.
↩ -
The new Hershey Text repository currently contains 18 font faces, carefully chosen. Total size is about 540 kB. That will go up a bit with the expanded character sets. This is a much more useful set than those included with the original Hershey Text. It does not include all of the fonts that are in hersheydata.py -- I do not recommend putting all of those out there for general distribution. There's a lot of semi-useless stuff in there, and we should keep the main distribution clean and useful. Additional fonts will be made available in a public repository for users to download and install if they want to.
↩ -
Someone previously pulled in a lot of fonts (in the hersheydata.py) from my EggBot repository, without really thinking through the license implications. I asked about the license implications on chat.inkscape.org, and we do need to make sure that we're covering all bases correctly in this matter.
↩ -
Update: As of 2019-05-02, the fonts in the repository currently include most of the Latin-1 characters.
↩