Question

I'm working on a wxPython project with text editing capabilities. I want to package a font with this project (a .ttf file) and have it as the default font for the text editor. Can this be done in wxPython? There was a similar question in 2007 in the wxPython-users mailing list. At that time it was not possible. It's now seven years later and I'm hoping that someone came up with a solution for this.

I am currently using wx.richtextctrl for the text editing box. I might consider using wx.styledtextctrl instead if it helps to solve my problem.

Was it helpful?

Solution

No, wx can still only use fonts that are installed in the system. If you distribute your project using an installer then it can install the font and your application can access it by its facename.

OTHER TIPS

wxpython 4.1 added the method

wx.Font.AddPrivateFont(path)

which allows the program to use fonts even if they aren't installed globally on the system

The docs add two important disclaimers

  • Under OS X this method actually doesn’t do anything other than check for the existence of the file in the “Fonts” subdirectory of the application bundle “Resources” directory. You are responsible for actually making the font file available in this directory and setting ATSApplicationFontsPath to Fonts value in your Info.plist file. See also wx.StandardPaths.GetResourcesDir
  • Under MSW this method must be called before any wx.GraphicsContext objects have been created, otherwise the private font won’t be usable from them.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top