ABU 16-Jul-2017
extrafont is a multi-platform binary package providing a way for loading "private fonts" in a Tk apps.
"Private fonts" are fonts usually delivered with an app.
They don't need to be installed in some 'standard' system-wide directories; once these fonts are loaded, they can be used in the same way of pre-installed fonts.
These loaded fonts are only visible by the process (app) who loaded'em, and then disappear when the app terminates.
1.0 - Initial Release
1.1
The extrafont package provides these commands:
e.g.
extrafont::availableFamilies co* returns Courier {Comic Sans MS} .....
One important distinction to keep in mind is among
Font-filename is used just for loading an external font:
extrafont::load "c:/tmp/Monoton-regular.ttf"
This font will be then available as "Monoton" font-family (note that the family-name may be very different from the font-filename).
extrafont::isAvailable "Monoton" ;# true
Finally, when you want to use this new font, you should create or configure a fontname (using the standard 'font' command)
set myfontname "tk_monoton" ;# ... choose the name you want .. font create $myfontname -family "monoton" -size 20 # or, let tk choose a fontname for you ... set myfontname [font create -family "monoton" -size 20] # then use $myfontname for a new widget ... label .mylabel -font $myfontname .......
MG This is awesome! I have a couple of suggestions/observations, though:
font create myNewFont -family [extrafont::load $file]
lsearch -all -inline -glob -nocase [font families] $familyPattern
This is a really neat functionality to add, thank you. :)
APN I second that.
ABU - Extracting the font-family from a font-file, or better, as suggested by MG, let extrafont::load return the loaded font-family, is a very difficult task.
Windows/Linux/Mac have three very different font-management APIs, and as far as I googled I never found any hint about how to solve it.
Expert help is welcomed !
MG I had, naively, assumed it would be a fairly simple matter, but I can't find any related API calls for getting the info (on Windows). Without something intended specifically for it, all I can think of is looping through the list of installed font families first, storing the list of families, and comparing to the result after loading. However, that is both ridiculously inefficient, and potentially not even useful (since your new font may have the same name as, but be a different font to, something already installed). I'm sure you can extract the information from the font file directly, but given how many different font-file formats there are, that would be rather a pain to do...
beware 13/12/2017. I did this:
set currentfonts [extrafont::availableFamilies] set currfontl [llength $currentfonts] set fontpairs [list] foreach f $fontlist { extrafont::load $f set nowfonts [extrafont::availableFamilies] lappend fontpairs [list $f [lindex $nowfonts $currfontl]] incr currfontl } tk_messageBox -message $fontpairs
Which seems to help. fontlist is the result of glob on my directory of local fonts. Basically, at least on my system, the new fonts are added to the end of the list of available families, so if you add the fonts individually you can tally the filename against the font name.