TIP 64: Improvements to Windows Font Handling

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Chris Nelson <chris@pinebush.com>
Author:         Kevin Kenny <kennykb@acm.org>
State:          Deferred
Type:           Project
Vote:           Done
Created:        27-Sep-2001
Post-History:   
Tcl-Version:    8.4
Obsoleted-By:	145

Abstract

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.

Background

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:

1. ANSI\_FIXED\_FONT

2. ANSI\_VAR\_FONT

3. DEVICE\_DEFAULT\_FONT

4. DEFAULT\_GUI\_FONT

5. OEM\_FIXED\_FONT

6. SYSTEM\_FIXED\_FONT

7. SYSTEM\_FONT

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.

Comments

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.

Copyright

This document has been placed in the public domain.

History