python-tkextrafont icon indicating copy to clipboard operation
python-tkextrafont copied to clipboard

Problems loading some fonts (e.g. Google fonts)

Open RedFantom opened this issue 4 years ago • 2 comments

Loading some fonts, in this case tested with the Google fonts Roboto and Noto Sans, is not possible with the package. This is due to problems in the fontnameinfo.tcl file, which is unable to parse the required information from the font files.

Additional complications arise with these fonts as they are split into multiple separate files. Loading the fonts with extrafont::core::load works just fine, but only one weight can be loaded at the same time. This can be avoided by merging the different files into a single file using fonttools.

If fonttools is already added as a dependency to make the package work with many different fonts, a rewrite of the Tcl files into Python seems appropriate to make the package more maintainable.

RedFantom avatar Apr 16 '21 20:04 RedFantom

Hi!

a rewrite of the Tcl files into Python seems appropriate to make the package more maintainable.

In tukaan I use the extrafont package, and there I rewrote the Tcl files into Python, which actually wasn't a big deal, and made the package indeed much more maintainable.

I experimented a bit with Google fonts and found the problem with their name info. Actually this problem seems to be Unix-specific, though I haven't tried if Google fonts work on Windows with it. Normal font files contain name records in latin-1 (for *nix) and UTF 16 BigEndian (for Windows). The problem is that these Google fonts store the records in the name table only in utf16be, however extrafont reads records encoded in utf16be only under Windows. https://github.com/TkinterEP/python-tkextrafont/blob/bbbfb0a246fb16de0d7c224f1c592af6cbfc072d/tkextrafont/fontnameinfo.tcl#L209-L213 So if you remove the triplet and platform checking stuff from fontnameinfo.tcl, it works just fine with Google fonts too.

rdbende avatar Apr 21 '22 19:04 rdbende

Hey!

That is super cool, thank you for letting me know you looked into this! If you are okay with it, I might at some point back-port your changes to this repository, for the sake of the tkextrafont package.

For now I am regularly looking at your progress on tukaan, which is a much more radical approach to what I tried to accomplish with TkinterEP, but it looks really promising. Unfortunately I have very little time for hobby-programming at the moment, but I am eager to see what you create.

RedFantom avatar Apr 22 '22 08:04 RedFantom