64.md at [34c2234998]

Login

File tip/64.md artifact ac09607afa part of check-in 34c2234998


# TIP 64: Improvements to Windows Font Handling
	Author:         Chris Nelson <[email protected]>
	Author:         Kevin Kenny <[email protected]>
	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.

  * On UNIX, this includes all X font names \(e.g. as listed by
    _xlsfonts_\).

  * On Macintosh, this includes _system_ and _application_.

  * On Microsoft Windows, this includes _system_, _systemfixed_,
    _ansi_, _ansifixed_, _device_, and _oemfixed_.

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:

   * Users can change the font used for various 'Windows desktop
     features so MS Sans Serif may not be the correct font for, for
     example, menus.

   * Windows 2000 and Windows XP use Tahoma, not MS Sans Serif as
     their default font.

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:

   *  Caption \(title bar\) font

   *  Small Caption \(palette title bar\) font

   *  Menu font

   *  Tooltip \(and status bar\) font

   *  Message box font 

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.