[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.
***Download ***
* [https://sourceforge.net/projects/irrational-numbers/files/extrafont-1.0.zip/download] '''extrafont-1.0''' Multi-platform package (Windows/Linux/MacOSX)
* [https://sourceforge.net/p/irrational-numbers/code/HEAD/tree/pkgs/extrafont-devkit] extrafont Development-Kit. For developers/maintainers.
[Image Img-PrivateFonts]
**SYNOPSYS**
The '''extrafont''' package provides one core command
extrafont::load
and two convenience commands
extrafont::isAvailable
extrafont::availableFamilies
'''extrafont::load''' ''filename'': After loading ''filename'', a new font-family will be available to the current Tk app.
'''extrafont::isAvailable''' ''fontFamily'': Return true is ''fontFamily'' is avaiable.
'''extrafont::availableFamilies''' ''fontFamilyPattern'': Return the list of font-families matching the glob-style ''fontFamilyPattern''.
e.g.
extrafont::availableFamilies co*
returns
Courier {Comic Sans MS} .....
One important distinction to keep in mind is among
* font-filename
* font-family
* fontname
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:
* It would be super handy if [extrafont::load] returned the font family, so you could do
font create myNewFont -family [extrafont::load $file]
* In your pkgIndex.tcl, I ''think'' you're better off using [info sharedlibextension] rather than trying to guess it by platform
* On Windows, I think it's better to check if $tcl_platform(machine) == amd64 to determine if it's 64bit rather than 32. (IIRC, I stole that from the source for the [platform::generic] command when I needed to do something similar before)
* In your availableFamilies command, I'd suggest replacing the foreach with an lsearch, which I think should be slightly faster/more efficient
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 !
<>Enter Category Here