<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sat Nov 07 20:39:44 GMT 2009 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='64'>
<header><title>Improvements to Windows Font Handling</title><author address="mailto:chris@pinebush.com">Chris Nelson</author><author address="mailto:kennykb@acm.org">Kevin Kenny</author><status type='project' state='deferred' tclversion="8.4" vote='after'>$Revision: 1.9 $</status><history></history><created day='27' month='sep' year='2001' /><obsoleted tip='145'/></header>
<abstract>This TIP improves handling of native fonts in Tk under Microsoft Windows making Tk applications more aesthetic and more consistent with users&apos; expectations of &apos;Windows applications.</abstract>
<body><section title="Background">
<para>Tk 8.4 includes platform-specific system font names which relate to configurable aspects of the native system.</para>
<itemize><item.i><para>On UNIX, this includes all X font names (e.g. as listed by <emph style="italic">xlsfonts</emph>).</para></item.i><item.i><para>On Macintosh, this includes <emph style="italic">system</emph> and <emph style="italic">application</emph>.</para></item.i><item.i><para>On Microsoft Windows, this includes <emph style="italic">system</emph>, <emph style="italic">systemfixed</emph>, <emph style="italic">ansi</emph>, <emph style="italic">ansifixed</emph>, <emph style="italic">device</emph>, and <emph style="italic">oemfixed</emph>.</para></item.i></itemize>
<para>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:</para>
<itemize><item.i><para>Users can change the font used for various &apos;Windows desktop features so MS Sans Serif may not be the correct font for, for example, menus.</para></item.i><item.i><para>Windows 2000 and Windows XP use Tahoma, not MS Sans Serif as their default font.</para></item.i></itemize>
<para>SourceForge patch #461442 (Make Tk use the default Windows font) [<url ref="http://sf.net/tracker/?func=detail&amp;aid=461442&amp;group_id=12997&amp;atid=312997"/>] attempts to address Tk&apos;s deficiency by adding a <emph style="italic">windefault</emph> font based on the Message font configured for the Windows desktop. This appears to be wrong.</para>
<para>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 &apos;Windows desktop.</para>
<para>NOTE: RFE 220772 on SourceForge [<url ref="http://sf.net/tracker/?func=detail&amp;aid=220772&amp;group_id=12997&amp;atid=362997"/>] has a related patch.</para>
</section>
<section title="The Default GUI Font">
<para>The Win API call <emph style="italic">GetStockObject()</emph> accesses brushes, pens, and fonts which are pre-configured on the system. The available fonts are:</para>
<enumerate><item.e index='1'><para>ANSI_FIXED_FONT</para></item.e><item.e index='2'><para>ANSI_VAR_FONT</para></item.e><item.e index='3'><para>DEVICE_DEFAULT_FONT</para></item.e><item.e index='4'><para>DEFAULT_GUI_FONT</para></item.e><item.e index='5'><para>OEM_FIXED_FONT</para></item.e><item.e index='6'><para>SYSTEM_FIXED_FONT</para></item.e><item.e index='7'><para>SYSTEM_FONT</para></item.e></enumerate>
<para>The <emph style="italic">TkStateMap systemMap</emph> in <emph style="italic">tkWinFont.c</emph> listed all but one of these, DEFAULT_GUI_FONT. As it turns out, this is the most important as it is the one that &apos;Windows uses as it&apos;s default font (for example, in Control Panel Applets).</para>
<para>I propose to add DEFAULT_GUI_FONT to the <emph style="italic">systemMap</emph> with a font name of <emph style="italic">defaultgui</emph> and to change CTL_FONT in <emph style="italic">tkWinDefault.h</emph> from <emph style="italic">{MS Sans Serif} 8</emph> to <emph style="italic">defaultgui</emph>. 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.</para>
<para>A reference implementation for this is available in patch 461442 (referenced above).</para>
</section>
<section title="Access to Desktop Fonts">
<para>The original implementation of <emph style="italic">windefault</emph> 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:</para>
<itemize><item.i><para> Caption (title bar) font</para></item.i><item.i><para> Small Caption (palette title bar) font</para></item.i><item.i><para> Menu font</para></item.i><item.i><para> Tooltip (and status bar) font</para></item.i><item.i><para> Message box font </para></item.i></itemize>
<para>The &apos;Windows Desktop Properties also include a font for icon labels on the desktop. This font is accessed with <emph style="italic">SystemParametersInfo()</emph>.</para>
<para>I propose to add 6 desktop fonts as system fonts on Windows. The names would be derived from their Desktop Properties entries: <emph style="italic">dtIcon</emph>, <emph style="italic">dtTitleBar</emph>, <emph style="italic">dtMenu</emph>, <emph style="italic">dtMessageBox</emph>, <emph style="italic">dtPaletteTitle</emph>, <emph style="italic">dtToolTip</emph>. The &quot;dt&quot; prefix associates the fonts with the desktop properties. (Can or should font names have internal capital letters?)</para>
<para>We might also add synonyms which relate to the structure field names and/or customary use of the font. I&apos;d propose adding <emph style="italic">dtCaption</emph> as equivalent to <emph style="italic">dtTitleBar</emph>, <emph style="italic">dtSmallCaption</emph> as equivalent to <emph style="italic">dtPaletteTitle</emph>, and <emph style="italic">dtStatus</emph> as equivalent to <emph style="italic">dtToolTip</emph>.</para>
<para>A reference implementation for this is available in Patch #461442 (referenced above) albeit with different font names.</para>
</section>
<section title="Dynamic fonts">
<para>Many &apos;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.</para>
</section>
<section title="Comments">
<para><emph style="italic">KBK</emph> 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.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
