\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#145: Enhanced Tk Font Handling}
\date{July 31, 2003}
\author{Pat Thoyts}
\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 \#145}&\textbf{Enhanced Tk Font Handling}\\\hline
Author&

Pat Thoyts \tipmail{patthoyts}{users.sourceforge.net}
\\
Created&Thursday, \(\text{31}^{\text{st}}\) July 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.10 $\\
Obsoletes&64\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

\cite{tip64} suggests some improvements to font handling under windows. However, not all of this TIP appears to have been implemented and I believe this can be done better using the Tk named fonts mechanism.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Windows, and no doubt MacOS as well, provide a number of system defined fonts. These are fonts that may be configured by the end user and that all applications are expected to use. The list includes the menu font, the caption font, the tooltip font and others. Some of the special fonts have been given symbolic names but these are not available to dynamic inspection. This TIP proposes to make these fonts available using the named font mechanism as used by the \textbf{font create} command. This has some significant advantages. The set of special font names becomes available to the programmer using the \textbf{font names} command. The font configuration is available using the \textbf{font configure} command. Also there is already a scheme in place to update all widgets using a named font when that fonts configuration changes. It is now a simple matter of re-defining the system fonts on receipt of the WM\_SETTINGCHANGE message to have Tk properly reflect changes to the system-wide font selection.

\section{Proposed Changes}

\subsection{Generic changes}

The named font creation routine \textbf{CreateNamedFont()} is to be exposed on the public API as \textbf{Tk\_CreateNamedFont()}. Also, the code used to delete a named font should be factored out into an API function, \textbf{Tk\_DeleteNamedFont()}.

\subsection{Windows Platform-Specific Changes}

A \textbf{TkWinSetupSystemFonts()} function is to be created which obtains the font description for the system fonts and calls \textbf{Tk\_CreateNamedFont()} appropriately. This needs to be called during font package initialization. The fonts are obtained using the Win32 \textit{SystemParameters} API and the set of defined stock object identifiers used with \textit{GetStockObject}.

The toplevel Windows message message handler function \textbf{WmProc} must handle the WM\_SETTINGCHANGE message by calling the \textbf{TkWinSetupSystemFonts()} function. This must call \textbf{Tk\_DeleteNamedFont} and then \textbf{Tk\_CreateNamedFont} to properly re-define the font and to propagate this change to all Tk widgets concerned. The Tk wigets will properly handle the font update by calling their \textit{WorldChanged} procedures.

\subsection{Cross-Platform Concerns}

It seems likely to be useful to ensure that aliases are available for each platform for the set of system fonts. This is currently done for the Tk cursors and helps to ensure that a script written for one system will usefully operate on another platform.

Tk currently guarantees that ``\textit{Courier}'', ``\textit{Times}'' and ``\textit{Helvetica}'' will always be available and are mapped to something suitable. It has been proposed that these should really be ``\textit{monospace}'', ``\textit{serif}'' and ``\textit{sans-serif}''. The CSS specification [\url{http://www.w3.org/TR/REC-CSS2/fonts.html\#generic-font-families}] defines these plus ``\textit{cursive}'' and ``\textit{fantasy}'' but there seems no good reason to include these two names.

\subsection{System Defined Fonts}

\subsubsection{Windows}

The current set of special font names that Tk defines under windows are as follows, all with -underline 0 -overstrike 0 -slant roman
\begingroup\small\begin{verbatim}
    ansi           -family {MS Sans Serif}  -size 8  -weight normal
    ansifixed      -family {Courier New}    -size 10 -weight normal
    defaultgui     -family {MS Shell Dlg}   -size 8  -weight normal
    device         -family System           -size 10 -weight bold
    fixed          -family {Courier New}    -size 10 -weight normal
    oemfixed       -family Terminal         -size 9  -weight normal
    system         -family System           -size 10 -weight bold
    systemfixed    -family Fixedsys         -size 9  -weight normal
\end{verbatim}
\endgroup

These are: ansi, windows variable pitch system font; ansifixed, a monospace version of ansi; defaultgui, default GDI font for menus and dialog boxes; system, used for system.....

We can additionally provide from Windows system settings
\begingroup\small\begin{verbatim}
    TkCaptionFont      -family {Trebuchet MS} -size 10 -weight bold
    TkIconFont         -family Tahoma         -size 8  -weight normal
    TkMenuFont         -family Tahoma         -size 8  -weight normal
    TkMessageFont      -family Tahoma         -size 8  -weight normal
    TkSmallCaptionFont -family Tahoma         -size 8  -weight bold
    TkStatusFont       -family Tahoma         -size 8  -weight normal
\end{verbatim}
\endgroup

These are fairly obvious. The caption font appears in the window title bar, the icon font for desktop icons, message font for message boxes, menu font, small caption font is for toolbox-type dialogs with very thin title bars. Finally status font is the font used for tooltips and status bars. All these Tk* fonts can be changed via the Windows Desktop properties dialog.

\subsubsection{Motif}
\begingroup\small\begin{verbatim}
    XmNbuttonFontList		(for pushbuttons in dialogs)
    XmNlabelFontList		(for labels)
    XmNtextFontList		(for text entry fields)
    XmNdefaultFontList		(for everything else)
\end{verbatim}
\endgroup

\subsubsection{GNOME}

Gnome or GTK+ documentation, but the Gnome 2.2 ``Font Preferences'' dialog lets you specify:
\begingroup\small\begin{verbatim}
    Application font
    Desktop font
    Window title font
    Terminal font
\end{verbatim}
\endgroup

It appears that all GTK+ UI controls use the same ``Application'' font.

\subsubsection{KDE}

KDE's font preferences dialog lists:
\begingroup\small\begin{verbatim}
    General
    Fixed Width
    Toolbar
    Menu
    Window Title
    Taskbar
\end{verbatim}
\endgroup

\subsubsection{Aqua}

Aqua defines the following [\url{http://developer.apple.com/documentation/UserExperience/Conceptual/AquaHIGuidelines/AHIGFonts/index.html}]:
\begingroup\small\begin{verbatim}
     System font
     Emphasized system font
     Small system font
     Emphasized small system font
     Application font
     Label font
     Mini system font
\end{verbatim}
\endgroup

\begin{quote}
The system font is used for text in menus, modeless dialogs, and titles of document windows [...] The small system font is used for informative text in alerts [...]. It is also the default font for headings in lists, for help tags, and for text in the small versions of many controls. If your application creates text documents, use the application font as the default for user-created content. The label font is used for labels with controls such as sliders and icon bevel buttons. If necessary, the mini system font can be used for utility window labels and text. Use emphasized system fonts sparingly.
\end{quote}

An alternative reference [\url{http://developer.apple.com/documentation/Carbon/Reference/Appearance_Manager/appearance_manager/constant_15.html}] lists:
\begingroup\small\begin{verbatim}
    kThemeSystemFont
    kThemeSmallSystemFont
    kThemeSmallEmphasizedSystemFont
    kThemeViewsFont
    kThemeEmphasizedSystemFont
    kThemeApplicationFont
    kThemeLabelFont
    kThemeMenuTitleFont
    kThemeMenuItemFont
    kThemeMenuItemMarkFont
    kThemeMenuItemCmdKeyFont
    kThemeWindowTitleFont
    kThemePushButtonFont
    kThemeUtilityWindowTitleFont
    kThemeAlertHeaderFont
    kThemeSystemFontDetail
    kThemeSystemFontDetailEmphasized
    kThemeToolbarFont
\end{verbatim}
\endgroup

\section{Suggested Tk Font Aliases}

From all the above this TIP suggests that the following names be provided for all platforms and where possible these map to system defined fonts.
\begin{description}
\item[TkDefaultFont]
the default for all GUI items not otherwise specified.
\item[TkFixedFont]
standard fixed width font
\item[TkMenuFont]
used for menu items
\item[TkCaptionFont]
used for window and dialog caption bars
\item[TkSmallCaptionFont]
used for captions on contained windows or tool dialogs.
\item[TkIconFont]
font in use for icon captions
\item[TkTooltipFont]
a font to use for tooltip windows (transient information windows)
\end{description}

\section{Implementation}

\url{http://sf.net/tracker/?func=detail&aid=780617&group_id=12997&atid=312997}

\section{Copyright}

This document is placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#64]{tip64}
Chris Nelson,
Kevin Kenny,
\emph{Improvements to Windows Font Handling},
on-line at \url{http://purl.org/tcl/tip/64.html}
\end{thebibliography}
\end{document}
