WIP: Outline font support

Closed Ola Rinta-Koski requested to merge rockola/kicad:strokefont into master

This WIP is intended for KiCAD 7, should it be deemed worthy.

I'm leaving all the text about Hershey fonts here for posterity. However, this MR has evolved into something other than that, namely "outline font support". See below for discussion.

KiCAD 5 (and 6) uses a font called "Newstroke" for all schematic and board text items. This font is derived from one of the Hershey fonts (which see: https://en.wikipedia.org/wiki/Hershey_fonts ). However, it would be nice to use other fonts for silkscreen items. The easiest to implement are the other Hershey fonts, since the reader for Newstroke basically reads the Hershey format. The Newstroke reader code was used to implement a reader for the original Hershey format as found at eg. https://emergent.unpythonic.net/software/hershey

The Hershey fonts are rather anachronistic, and there are not that many of them; I am submitting this in the hope that this work paves the way so that one day other font formats (such as OpenType) may be used for silkscreen text.


As things stand now, the new code works with pcbnew and 3d-viewer, as well as plot/export to PDF/Postscript/Gerber/SVG.

There are a number of issues to be resolved before this is production ready, such as:

  • where to put the fonts?
    • Currently, I'm assuming the fonts are magically installed in a subdirectory called "fonts" in the user config directory. The Hershey fonts have a very liberal licence, so they can be distributed with KiCAD, and only take up about 280kB.
  • how to use different fonts?
    • If a PCB text item starts with "${FONT:timesi}" (where "timesi" is the name of the desired Hershey font), that font is used for the text item in question. Multiple fonts per text item are not implemented. If the FONT "variable" appears anywhere else except at the beginning, it won't be used. I implemented this hack because it meant I did not need to worry about GUI implications, or changing the save file format. However, it is rather hacky. And by the way, schematic text items are not supported (for now).
  • should other items be eligible for font change?
    • I have only implemented the $FONT hack for PCB text items, because I wanted to limit the repercussions of this change, and also because I think that is the most likely use case.
  • should multiple fonts per text item be supported?
    • Probably not. The approach I took would require a lot of rethinking.
  • what to do about missing glyphs?
    • The original Hershey fonts support ASCII only. There are fonts called cyrillic, greek, japanese etc. but these work with the ASCII encoding, so good luck trying to figure out how to write Greek or Russian with them. Umlauts etc. are of course not present at all, or if there are independent diacriticals (I think there are some), characters with diacriticals do not exist.
  • and probably a lot of things I haven't even thought of
Edited by Ola Rinta-Koski