Hello,
Donal K. Fellows asked me to submit the following patch I posted to
comp.lang.tcl. Its purpose is
to make Tk use the standard Windows dialog font by default. In the current
version, the default
font for Tk buttons, labels, entries etc. is "MS Sans Serif" 8 pt
regardless of what font the user
configured in Windows; this makes Tk programs look slightly (but noticably)
different from native
Windows dialog applications. With my patch, Tk uses the Windows standard
dialog font by default.
Here's the news article I wrote on September 13, 2001.
--- 8< ---
To make Tk use the standard Windows dialog font, the Tk
source code has to be patched in two places. I did this
for Tk 8.3.3. Perhaps someone has the time to put this
on a Wiki page, include in a FAQ, or even integrate it
in the official Tk for Windows source codes.
First, a few lines have to be added to function TkpGetNativeFont
in tk/win/tkWinFont.c. These lines add a new font name,
"windefault", which can be used throughout Tk. The windefault
font is always the Windows standard dialog font. Note that
this font is different from all the other system fonts,
like "system" or "ansi". It has to be implemented
differently
from the other system fonts since it can't be retrieved
through GetStockObject. Here's the new version of TkpGetNativeFont:
TkFont *
TkpGetNativeFont(
Tk_Window tkwin, /* For display where font will
be used. */
CONST char *name) /* Platform-specific font name. */
{
int object;
WinFont *fontPtr;
/* New code starts here */
if (strcmp(name,"windefault")==0)
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
&ncm, 0);
tkwin = (Tk_Window) ((TkWindow *)
tkwin)->mainPtr->winPtr;
fontPtr = (WinFont *) ckalloc(sizeof(WinFont));
InitFont(tkwin,
CreateFontIndirect(&ncm.lfMessageFont),
0, fontPtr);
return (TkFont *) fontPtr;
}
/* New code ends here - rest of function unchanged */
object = TkFindStateNum(NULL, NULL, systemMap, name);
if (object < 0) {
return NULL;
}
tkwin = (Tk_Window) ((TkWindow *) tkwin)->mainPtr->winPtr;
fontPtr = (WinFont *) ckalloc(sizeof(WinFont));
InitFont(tkwin, GetStockObject(object), 0, fontPtr);
return (TkFont *) fontPtr;
}
With this modification it's possible to use the new font with any
Tk widget, like this:
button .b -text "Whatever" -font windefault
The second modification sets the windefault font as the default for
all Tk widgets. This is done by replacing the CTL_FONT define in
tk/win/tkWinDefault.h with "windefault", like this:
#define CTL_FONT "windefault"
In the original version, CTL_FONT is hardcoded to 8 pt MS Sans Serif.
After these changes, recompile the Tk library and rebuild wish or
whatever application you're linking Tk into.
--- 8< ---
Sorry for not being able to submit CVS diffs, but I think the above should
be obvious and not too
hard to integrate.
If you have any questions about this, contact me at wr@grp.de.
Thanks
Wolfram Rösler
Nobody/Anonymous ( nobody ) - 2001-09-14 07:32
5
Closed
Duplicate
Jeffrey Hobbs
47. Win Fonts
None
Public
|
Date: 2001-11-17 22:34 Logged In: YES |
|
Date: 2001-10-15 22:05 Logged In: YES |
|
Date: 2001-09-26 19:01 Logged In: YES |
|
Date: 2001-09-21 20:10 Logged In: YES |
|
Date: 2001-09-20 13:11 Logged In: YES |
|
Date: 2001-09-20 10:23 Logged In: NO |
|
Date: 2001-09-20 09:49 Logged In: YES |
|
Date: 2001-09-19 16:10 Logged In: YES |
|
Date: 2001-09-19 16:00 Logged In: YES |
| Filename | Description | Download |
|---|---|---|
| font-461442.dif | Download |
Copyright © 2010 Geeknet, Inc. All rights reserved. Terms of Use