programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: changing fonts and sizes

From: Glenn Dixon <dixong_at_networld.com>
Date: Thu, 29 May 2003 04:58:21 -0600

Here are some tips. You'll have to decide whether or not it is worth
it. Fonts are complicated things, obsfucated by typesetter's lore.

1. You must have a handle to the desired font. You can get pre-
defined font handles through the EnumFontFamilies API call, but this
is complicated. Some system fonts have predefined constants you can
feed into GetStockObject to get their handles:

DEFAULT_GUI_FONT \ is the font used in dialog boxes
SYSTEM_FIXED_FONT \ is what is used by default in Forth

others:
ANSI_FIXED_FONT
ANSI_VAR_FONT
DEVICE_DEFAULT_FONT
OEM_FIXED_FONT
SYSTEM_FONT

Not all of these return unique fonts. Get the handle like this:
SYSTEM_GUI_FONT GetStockObject ( --hnd)

If you know the name of your font, you can create it in whatever size
you wish:

14 import: CreateFont

8 0 0 0 0 0 0 0 ANSI_CHARSET OUT_DEFAULT_PRECIS CLIP_DEFAULT_PRECIS
DEFAULT_QUALITY
FF_DONTCARE z" Terminal" CreateFont value tinyfont

12 0 0 0 0 0 0 0 ANSI_CHARSET OUT_DEFAULT_PRECIS CLIP_DEFAULT_PRECIS
DEFAULT_QUALITY
FF_DONTCARE z" Terminal" CreateFont value medfont

22 0 0 0 0 0 0 0 ANSI_CHARSET OUT_DEFAULT_PRECIS CLIP_DEFAULT_PRECIS
DEFAULT_QUALITY
FF_DONTCARE z" Terminal" CreateFont value largefont

26 0 0 0 0 0 0 0 ANSI_CHARSET OUT_DEFAULT_PRECIS CLIP_DEFAULT_PRECIS
DEFAULT_QUALITY
FF_DONTCARE z" Terminal" CreateFont value hugefont

See the docs for CreateFont to see what all the above values are for.
The zstring is the name of the font.

2. You must have the handle for the window you want the font to be
selected into. The Forth TTY window handle can be obtained by

console-window +order htty console-window -order ( --handle)

Because a font is a graphical thing, it goes into the window's device
context:

window-handle GetDC ( --DC)
dup font-handle SelectObject drop
window-handle swap ReleaseDC drop

Here is code that puts the SYSTEM_GUI_FONT into the forth window:

console-window +order htty console-window -order value htty

htty GetDC
dup DEFAULT_GUI_FONT GetStockObject SelectObject drop
htty swap ReleaseDC drop

Only four lines, but it gets a lot more complicated if you want
something other than the system fonts, and don't have the font handle.

The font-picker uses the windows font picking dialog box, which can't
be used for unattended on-the-fly font changing.

Hope this helps.

Glenn

-----Original Message-----
From: "Jason Damisch" <jdamisch_at_hotmail.com>
To: sftalk_at_forth.com
Date: Wed, 28 May 2003 23:55:44 -0700
Subject: [sftalk] Re: changing fonts and sizes

>
>
> >Dear Forth People,
> >Is there an easy Forth-like way to change fonts and sizes on the
> fly, such
> >as
> >
> >( code1 code2 code3 code4 --- ) CHANGE-FONT
>
> I searched through the manual for refernces to the word 'font" and I
> also
> typed in WORDS FONT into
> the command line, and poked around a bit in reguards to this. I
> would say
> that no, there is not an
> easy way to change the font. There is probably an uneasy way to do
> it so my
> guess would be that
> if you wanted to tear apart the code for the Font Picker, you could
> fashion
> something resembling
> what you desire.
>
> Good Luck
>
> jdamisch
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> ---------------------------------------------------------------------
> -
> sftalk_at_forth.com The SwiftForth programming discussion email
> list
> To unsubscribe, send subject "unsubscribe" to
> sftalk-request_at_forth.com
> For list command help, send subject "help" to
> sftalk-request_at_forth.com
> Message archives are located at http://www.forth.com/archive/sftalk
> ---------------------------------------------------------------------
> -
> This list is a forum for SwiftForth users. For product support and
> bug
> reports, please send email to support_at_forth.com
> ---------------------------------------------------------------------
> -
>

*********************************
Get your free E-Mail and Homepage
Go to http://www.networld.com
*********************************

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Thu May 29 2003 - 04:30:31 PDT

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:32 PST