Font resources?

I’m looking for font resources appropriate for PCBs. Does anyone have any leads on:

  • Suitable fonts for use on a PCB? (Lines/dots that meet manufacturing rules)?
  • Free and open source tools for converting font glyphs into vectors?
  • Any existing efforts on PCB fonts?

See https://gitlab.com/kicad/code/kicad/-/issues/2441#note_340918734.

1 Like

The Inkscape > PNG Export > Bitmap to Component workaround listed in the link above is what I have to do to get custom fonts into pcbnew. It is a lot of work because you have to ensure what you create in inkscape is exactly the size it needs to be on the PCB, but its the only option in lieu of external font support.

The advantage of the workaround is you can do all your arrangement of the text or even other monochrome graphics first before converting it to a footprint. I have found it handy to utilize pcbnew’s SVG export tool (or alternatively the tool at tracespace.io, which can give you an SVG stackup from a Gerber file), which you can use as a guide in inkscape to size your text/graphics. Then export only the text/graphics to PNG for use in the conversion tool.

Thank you for listing your workflow. I’m doing preliminary research on adding font capability to KiCommand. I just recalled that i’ve done some work with Unicode fonts, and i’ll Likely try the Unicode font from google (“Noto”) either sans or sans display to see what it looks like.

The links @eelik mentioned will also be very useful.

Thank you for the link. It led me to Python package fontTools. I’ve been able to decode some of the noto sans mono regular font ttf file from google, but haven’t found the glyph data points. I’m still looking, but if you have any pointers (especially with using fontTools in python), I’m certainly open to listen :slight_smile: (no obligation on your part, however).

I think you have to delve deep into the font file format if you need to know more. Naturally there’s a gap between a noobie (like you and me) and the documentation because using a python library for fonts pretty much necessarily requires some background knowledge.

If you want to know more about technical font design, take a look at FontForge.

Thank you. I’ve been trying to figure out how to implement fonts and I think I have course corrected for the moment. Instead of seeking to convert a ttf directly, I’m looking to convert ttf to svg, then use the already-built svg command in KiCommand. I should have results within the hour. I’ll post an update here.

It took way more than an hour. I had to rework SVG handling code to accommodate more of the path commands. My code now support cubic and quadratic Bezier curves as well as the smooth continuation Bezier curves. I was hoping that the TTF to SVG converter would output a simple vector where the strokes would match the strokes of the text, but instead it outputs the outline. This is what I have so far, an example Unicode character 7121.

Edit: And here’s the greek letter PHI:
image

1 Like

More than one whole hour !!?? You are slacking @HiGreg!

p.s. In case it is not obvious, it is a joke, it is amazing to see how fast you work! Thank you for all your efforts!

2 Likes

Your U+7121 is vertically flipped.

2 Likes

Ah. Thanks for mentioning it’s flipped. I now remember that when I printed a character I know (the number “4”) it was upside down. I think the KiCAD X/Y directions (Y being opposite sign to many other programs) caught me. I’ll fix. Thanks!

無 problem…

Is this better? I went ahead and developed the framework for full 2d transformations using a matrix. This will make it easier to place, rotate, resize, shear and any other transformations in 2d space using 3x3 matrix transformation.

Edit: I work on so many different things that I find myself relearning over and over (and over). I’m pretty sure that with 3x3 matrix transformation in 2d space, you can represent any Affine Transformation “Examples of affine transformations include translation, scaling, homothety, similarity, reflection, rotation, shear mapping, and compositions of them in any combination and sequence.” (Wikipedia)

Yes, that mu character is correct now.

This is of course impossible (in any simple way) because the TTF fonts are by definition outlines. It doesn’t know about strokes. For certain fonts it would be possible to programmatically calculate the strokes, but I don’t think it would work for nearly all fonts.

I’m interested in seeing how you convert the glyphs to polygons and how they are rendered in different layers (especially copper, silk and mask). Drawing the outlines with segments isn’t very useful for most use cases.

In my recent work on KiCommand to add (what I call) geoms, I added support for all DRAWSEGMENT shapes, including Bezier curves. It was a short (ish) exercise to convert SVG “d” path support and convert SVG d path commands into geoms. KiCAD implements (only?) cubic Bezier curves, so I added code to convert the SVG quadratic Bezier curve into cubic. I had to totally rework my existing fromsvg code to handle a more general input format. A couple of years ago, I posted the results of KiCommand’s ability to add text similar to your image.

As far as translating the outlines to polygons, this will be a little harder because KiCAD zones only support straight line edges. However, it’s technically possible (mathematically) to convert each of the SVG d path commands (shapes) into a straight-edged outline. I’d have to work through the possible difference in polygon specification (SVG: the “inside” of the polygon is to the right). I don’t think KiCAD recognizes the difference between CW/RW and CCW/LW points. It is also the standard for GIS ShapeFile format and other GIS formats, where outer contours are CCW/LW and interior contours (holes) are CW/RW. This also makes the 2d calculations easier (I think).

In any case, I’ll see what I can do to generate polygons from SVG.

I believe this is exactly what the snippet in the stackexchange answer linked to in the bug report does. https://gis.stackexchange.com/questions/258076/how-to-generate-wkt-geometries-from-true-type-font-glyphs-python. It seems to create a simplified outline with straight edges. Internally it seems to “render” the glyph so that “pixels” will be the corners of the polygon.

Yes, indeed. That looks very promising. Is there a standard way for KiCAD plugins to require a package? I’ve written all my KiCAD code from scratch (and copy/convert/paste from a wide variety of websites) and haven’t relied on installed packages. I’m not sure if a “normal user” could navigate the installation of third-party Python packages into KiCAD’s python and plugin framework. Do you have any observations on that topic?

AFAIK there’s no way to ensure or even ask the user for installation of an external python library. I’m not terribly familiar with the situation, but probably the pip repo has all interesting packages. Pip itself is part of python.

External requirements could be part of the planned content manager. Has @qu1ck thought about this?

About non-straight polygon outlines, give your vote here: https://gitlab.com/kicad/code/kicad/-/issues/4493. (I added a comment about beziers there. Beziers would probably be relatively easy to approximate with a couple of arcs, though, and there should exist algorithms for that.)

1 Like

I would also advocate for elliptical arcs similar to SVG a and A d path commands.