Re: Font size when changing screen resolution
From: John Carson (donaldquixote_at_datafast.net.au)
Date: 02/15/04
- Next message: Peter: "HELP! Enabling or disabling system menu items"
- Previous message: Mark Hatsell: "Re: Font size when changing screen resolution"
- In reply to: Mark Hatsell: "Re: Font size when changing screen resolution"
- Next in thread: Mark Hatsell: "Re: Font size when changing screen resolution"
- Reply: Mark Hatsell: "Re: Font size when changing screen resolution"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 16 Feb 2004 07:47:56 +1100
"Mark Hatsell" <mark.hatsell@btinternet.com> wrote in message
news:OCJGEi$8DHA.2432@TK2MSFTNGP10.phx.gbl
> Hi John
>
> Thanks for the reply.
>
>> I see more or the less the opposite to what you describe. Either you
>> are using "size" in an unexpected way or you are making some other
>> compensating change. Are you aiming for a constant size in terms of
>> the number of pixels used or as measured by a ruler placed against
>> the screen? And how EXACTLY do you set the lfHeight value in the
>> LOGFONT structure?
>>
>> Normally, people aim for a pixel count that is independent of screen
>> resolution, with the result that higher resolutions lead to a
>> smaller font size as measured by a ruler against the screen. That is
>> what Windows does in its user interface elements.
>
> I am aiming for a constant size in terms of the number of pixels,
> much like you get in Word, Notepad etc. so that a lower screen
> resolution ends up displaying a larger physical font as measured with
> a ruler. This seems to be what happens in Win9x/ME. However, in
> NT,2000,XP the font stays the same physical size as measured by a
> ruler regardless of resolution. Therefore in low resolution modes the
> text becomes virtually unreadable as there are not enough pixels to
> display it properly.
>
> My lfHeight value is set using the following code:
>
> lfHeight = int(fabs(double(fontdata.LogFont.lfHeight) * MM_INTERNAL *
> AG_MMPERPOINT) + 0.5);
>
> where fontdata.LogFont.lfHeight is the height returned from the common
> font-selection dialog, MM_INTERNAL = 100 (to convert mm to logical
> units) and AG_MMPERPOINT = 0.3514598 to convert mm in points.
>
> Any more ideas?
>
> Mark
You can solve the screen resolution issue as follows. Replace the use of
MM_HIMETRIC with:
SetMapMode(hdc, MM_ANISOTROPIC);
SetViewportExtEx(hdc,
GetDeviceCaps(hdc, LOGPIXELSX),
GetDeviceCaps(hdc, LOGPIXELSY), NULL);
SetWindowExtEx(hdc, 2540, -2540, NULL);
This gives the equivalent of MM_HIMETRIC on a Windows9x/ME system. The
GetDeviceCaps calls are so your font size will vary depending on whether the
user has selected small fonts or large fonts.
There also appears to be a problem with the way you set lfHeight. The
lfHeight value returned by the Common Font Dialog is a pixel measure, not a
points measure. For points, you need to use the iPointSize field of
CHOOSEFONT, which gives the user choice in 1/10 points. A formula that works
is:
lf.lfHeight = - MulDiv(cf.iPointSize,254,72);
where cf is the CHOOSEFONT variable and the minus sign is to signal that the
height does not include internal leading. MulDiv is a Windows function that
multiplies its first two arguments, divides by the third, and then rounds to
the nearest integer. It gives the most accurate results for fonts (254/72 is
roughly 10 times your AG_MMPERPOINT).
-- John Carson 1. To reply to email address, remove donald 2. Don't reply to email address (post here instead)
- Next message: Peter: "HELP! Enabling or disabling system menu items"
- Previous message: Mark Hatsell: "Re: Font size when changing screen resolution"
- In reply to: Mark Hatsell: "Re: Font size when changing screen resolution"
- Next in thread: Mark Hatsell: "Re: Font size when changing screen resolution"
- Reply: Mark Hatsell: "Re: Font size when changing screen resolution"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|