From: | Olaf Barthel |
Date: | 15 Aug 99 at 17:21:22 |
Subject: | Re: Font sizes. |
From: "Olaf Barthel" <olsen-amigac@sourcery.han.de>
On Aug 15 Lee (Lee Atkins) wrote:
> From: Lee Atkins <lee@loonyjuicesoftware.freeserve.co.uk>
>
> Hello,
>
> Is there a way of getting the size of a font Text() will use before opening
> a window?
Depends upon which screen the window opens on. There are few funny
rules involved here which are too silly to contemplate. You should plan
ahead as to which font you really want to use later, such as the screen
font or the system default font.
> I want to adjust the size of the window depending on the size of the font
> the user has selected as the system default.
Ah, that's simple. It goes like this:
struct RastPort rp;
struct TextAttr ta;
struct TextFont * tf;
InitRastPort(&rp);
AskFont(&rp,&ta);
tf = OpenFont(&ta);
This works because InitRastPort() will put a pointer to the system default
font into the RastPort data structur you provide. To turn this into a
TextAttr suitable for submission to OpenFont(), you call AskFont() and
then open the font. We're using OpenFont() to open a font already in
memory. That's all you should need. I would advise against using
GfxBase->DefaultFont. The OpenFont() trick outlined above will make sure that
the font usage counts are adjusted accordingly. Simply grabbing the
GfxBase->DefaultFont pointer won't do that for you.