\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#64: Improvements to Windows Font Handling}
\date{September 27, 2001}
\author{Chris Nelson, Kevin Kenny}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#64}&\textbf{Improvements to Windows Font Handling}\\\hline
Author&

Chris Nelson \tipmail{chris}{pinebush.com}
\par
Kevin Kenny \tipmail{kennykb}{acm.org}
\\
Created&Thursday, \(\text{27}^{\text{th}}\) September 2001\\
Type&Project\\
Tcl Version&\(8.4\)\\
State&Deferred\\
Vote&Done\\
Version&\tipversion$Revision: 1.9 $\\
Post History&\\
Obsoleted By&145\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

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.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Background}

Tk 8.4 includes platform-specific system font names which relate to configurable aspects of the native system.
\begin{itemize}
\item{}
On UNIX, this includes all X font names (e.g. as listed by \textit{xlsfonts}).
\item{}
On Macintosh, this includes \textit{system} and \textit{application}.
\item{}
On Microsoft Windows, this includes \textit{system}, \textit{systemfixed}, \textit{ansi}, \textit{ansifixed}, \textit{device}, and \textit{oemfixed}.
\end{itemize}

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:
\begin{itemize}
\item{}
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.
\item{}
Windows 2000 and Windows XP use Tahoma, not MS Sans Serif as their default font.
\end{itemize}

SourceForge patch \#461442 (Make Tk use the default Windows font) [\url{http://sf.net/tracker/?func=detail&aid=461442&group_id=12997&atid=312997}] attempts to address Tk's deficiency by adding a \textit{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 [\url{http://sf.net/tracker/?func=detail&aid=220772&group_id=12997&atid=362997}] has a related patch.

\section{The Default GUI Font}

The Win API call \textit{GetStockObject()} accesses brushes, pens, and fonts which are pre-configured on the system. The available fonts are:
\begin{enumerate}
\item{}
ANSI\_FIXED\_FONT
\setcounter{enumi}{1}
\item{}
ANSI\_VAR\_FONT
\setcounter{enumi}{2}
\item{}
DEVICE\_DEFAULT\_FONT
\setcounter{enumi}{3}
\item{}
DEFAULT\_GUI\_FONT
\setcounter{enumi}{4}
\item{}
OEM\_FIXED\_FONT
\setcounter{enumi}{5}
\item{}
SYSTEM\_FIXED\_FONT
\setcounter{enumi}{6}
\item{}
SYSTEM\_FONT
\end{enumerate}

The \textit{TkStateMap systemMap} in \textit{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 \textit{systemMap} with a font name of \textit{defaultgui} and to change CTL\_FONT in \textit{tkWinDefault.h} from \textit{\{MS Sans Serif\} 8} to \textit{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).

\section{Access to Desktop Fonts}

The original implementation of \textit{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:
\begin{itemize}
\item{}
 Caption (title bar) font
\item{}
 Small Caption (palette title bar) font
\item{}
 Menu font
\item{}
 Tooltip (and status bar) font
\item{}
 Message box font 
\end{itemize}

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

I propose to add 6 desktop fonts as system fonts on Windows. The names would be derived from their Desktop Properties entries: \textit{dtIcon}, \textit{dtTitleBar}, \textit{dtMenu}, \textit{dtMessageBox}, \textit{dtPaletteTitle}, \textit{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 \textit{dtCaption} as equivalent to \textit{dtTitleBar}, \textit{dtSmallCaption} as equivalent to \textit{dtPaletteTitle}, and \textit{dtStatus} as equivalent to \textit{dtToolTip}.

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

\section{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.

\section{Comments}

\textit{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.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
