Search code examples
fontswxpythonwxwidgetsvector-graphics

wxPython getting system font contours data


I'm writing code for a some lasercutter software ( https://github.com/meerk40t/meerk40t ) and I want to lasercut the contours of the glyphs in the font. Now wxPython has a bunch of nice font stuff already built in, so you can list the fonts in an OS independent way, but these actually refer to the wx.Font object and I don't see an easy way to access the contours through that.

If I got the file, I could run something like freetype or fonttools and use that to get the contours, but I would still want OS independent font accessing, I don't see an easy way to process that. There are some weird things like sending writing this into an SVG and sending it through Inkscape commandline to convert text to paths. I would prefer fewer rather than more dependencies, but I would also prefer it working to the bupkis I currently have.

wxPython currently lets me get system fonts and put them out to the graphics contexts so there should be a way in there. But, I see no way forward. I could access the ttf files directly but without the font stuff done for me, I don't know what the current selected font file would be, and I would need to add a dependency for font contour reading or code up my own.


Solution

  • There is nothing in wxWidgets API that would give you the font glyphs data itself directly. You will need to do it in using platform-specific APIs, which is not going to be simple or pleasant, but should be doable as you can get whatever these APIs take on input from a wxNativeFontInfo object that you can obtain from wxFont (e.g. under MSW the native font info contains LOGFONT, under GTK -- PangoFontDescription etc).