TIP 64: Improvements to Windows Font Handling

EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA
Author:         Chris Nelson <[email protected]>
Author:         Kevin Kenny <[email protected]>
State:          Deferred
Type:           Project
Vote:           Done
Created:        27-Sep-2001
Tcl-Version:    8.4
Obsoleted-By:	145


This TIP improves handling of native fonts in Tk under Microsoft Windows making Tk applications more aesthetic and more consistent with users' expectations of 'Windows applications.


Tk 8.4 includes platform-specific system font names which relate to configurable aspects of the native system.

Through v8.4a3, Tk used 8pt MS Sans Serif as the default font for widgets. While this was almost OK, it fails in two respects:

SourceForge patch #461442 (Make Tk use the default Windows font) http://sf.net/tracker/?func=detail&aid=461442&group_id=12997&atid=312997 attempts to address Tk's deficiency by adding a windefault font based on the Message font configured for the Windows desktop. This appears to be wrong.

This TIP attempts to fix the default Tk font the right way as well as giving Tk programmers access to the rest of the fonts configured for the 'Windows desktop.

NOTE: RFE 220772 on SourceForge http://sf.net/tracker/?func=detail&aid=220772&group_id=12997&atid=362997 has a related patch.

The Default GUI Font

The Win API call GetStockObject() accesses brushes, pens, and fonts which are pre-configured on the system. The available fonts are:








The TkStateMap systemMap in tkWinFont.c listed all but one of these, DEFAULT_GUI_FONT. As it turns out, this is the most important as it is the one that 'Windows uses as it's default font (for example, in Control Panel Applets).

I propose to add DEFAULT_GUI_FONT to the systemMap with a font name of defaultgui and to change CTL_FONT in tkWinDefault.h from {MS Sans Serif} 8 to defaultgui. This will require a change in documentation to list the new system font name but is otherwise simple and painless. Furthermore, it makes Tk GUIs look right on W2k.

A reference implementation for this is available in patch 461442 (referenced above).

Access to Desktop Fonts

The original implementation of windefault as a new font, accessed the message font from the NONCLIENTMETRICS structure. While this is not, in fact, the correct default GUI font, it is an important system font, as are the others on the NONCLIENTMETRICS structure. The structure lists:

The 'Windows Desktop Properties also include a font for icon labels on the desktop. This font is accessed with SystemParametersInfo().

I propose to add 6 desktop fonts as system fonts on Windows. The names would be derived from their Desktop Properties entries: dtIcon, dtTitleBar, dtMenu, dtMessageBox, dtPaletteTitle, dtToolTip. The "dt" prefix associates the fonts with the desktop properties. (Can or should font names have internal capital letters?)

We might also add synonyms which relate to the structure field names and/or customary use of the font. I'd propose adding dtCaption as equivalent to dtTitleBar, dtSmallCaption as equivalent to dtPaletteTitle, and dtStatus as equivalent to dtToolTip.

A reference implementation for this is available in Patch #461442 (referenced above) albeit with different font names.

Dynamic fonts

Many 'Windows applications respond on-the-fly to changes in the desktop fonts. Tk responds to changes in Tk fonts via [font configure]. I propose that Tk respond to the WM_SETTINGCHANGE message from Windows to propagate changes to the desktop fonts enumerated above as it propagates changes to Tk fonts when they are reconfigured. I have yet to prototype these changes.


KBK wonders whether the dt* fonts have logical counterparts on the other platforms (KDE, Gnome/Gtk, Macintosh, HP-VUE, ...) and if implementors on those platforms might want to try to mirror this functionality. Since nobody has commented, he assumes that they at least do not find the idea objectionable.


This document has been placed in the public domain.