Work continues on fonts. Because it is difficult to add Python packages to KiCAD python (at least on Windows), I’ve created a separate Python3 program that converts font files (ttf, otf) and font collection files (ttc, otc) into a format suitable for the KiCAD font system I’ve created. The font format is simply a pickle file (created with the pickle Python package) of the font class I’ve written. The font class carries glyphs, glyph names, unicode conversion table, and spacing parameters. Glpyhs are stored as SVG contours and converted to polygons right before placing on the board. Right now I’m focused on left to right fonts only, but others could be supported in the future. Creating this program bypasses the need for me to provide fonts and all of the licensing issues that that entails. With this program, you supply your own TrueType or OpenType font files (or font collection files). This means you could use any fonts you wish.
The fontimport.py is a Python 3.7 file and requires the fontTools Python package to be installed on your system. If you think this will be a barrier for you, please let me know.
On my system, I execute the following on the command line to get help from fontimport.py:
python fontimport.py -h
Here is the current help text for the fontimport.py file:
usage: fontimport.py [-h] [--version] [--output OUTPUT] [--input INPUT]
[--recursive] [--exec]
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--output OUTPUT output directory
--input INPUT input directory or file
--recursive search find files recursively when --input is a directory
--exec without this option, just list environment and files, but do not write to the output. Actually writing to the output requires this option.
The font system is integrated into KiCommand. If you are interested in adding a variety of fonts to your project (or just a font different that KiCAD default font), you may want to have a peek at KiCommand in preparation. It’s currently working on KiCAD 5.1.6-release. There’s a README file on github and a tutorial and a discussion thread on this forum. It’s been designed on Windows and is tested well there. I’ve seen it used on MacOS, but I don’t know if Linux is working. KiCAD on Windows uses Python 2.7, but I think the other OSes are using Python 3. If you have a chance to test KiCommand on MacOS or Linux, please let me know in the Discussion thread or github issues about any problems you discover. If it works without problems, please let me know in the Discussion thread.
There will be new KiCommand commands to place font characters on the board. Here is a sampling of commands in their current state:
-
Noto-sans-regular setfont - set the current font to Noto-sans-regular
-
"Hello World" stringtogeom newdrawing refresh - print Hello World in the current font at 0,0
-
Tmm,235,47 split “Board Version 1.0” stringtogeom append newdrawing refresh - print the indicated string at location 235,37 specified in mm
The default font size is 10 points, where a point is 1/72 of an inch (this is the industry definition of a point, in fontspeak). The “font size” is an indication of the size of the “em height” which is roughly the height of the “m” character. So by default, characters print out at 0.14" or 3.5mm. You can scale with the S parameter like this:
-
S,2,Tmm,235,37 split “Board Version 1.0” stringtogeom append newdrawing refresh - print the indicated string at coordinates (mm) 235,37 at 2 times the default size. Perhaps I’ll modify the size indicator at some point to take advantage of a text height parameter (similar to the way KiCAD text size is handled)
You can embed control characters like newline (\n) or unicode characters with \uXXXX notation where the XXXX is the hexadecimal unicode code point. The wxWidget input to KiCommand should also be able to handle direct unicode input, but I haven’t tried that yet.
There are also ways to specify the accuracy of the bezier approximation by specifying a number of “steps”.
-
beziersteps 5 int params - change the bezier steps parameter to 5 (which happens to be the default)
Here is the lowercase “b” with 2, 3, 4, and 5 bezier steps:
I’ve had no real problems specifying up to 30 steps, but the increase accuracy doesn’t seem worth the significantly larger number of polygon points. Steps of 5 seem sufficient, and maybe up to 10 might be good for super smooth curves. Because I’m not sure of the best number of steps, it can be changed by users.
It would be great to have a GUI to add board text in any chosen font, I just haven’t had the time to build one, and KiCommand seemed like a good way to verify basic functionality and get the fonts tested by a variety of users and systems.
Let me know if you have a specific font you want me to test, and I will, if it is freely available.
Please post comments or questions here.
Edit: clarified that polygons are used on the board, and fixed command-line argument “–exec”