Re: Font size when changing screen resolution

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: John Carson (donaldquixote_at_datafast.net.au)
Date: 02/15/04


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)


Relevant Pages

  • Re: Drawing Small Text with Very High Quality in GDI+
    ... When I did the same operation within IE and my application, you could see the pixels on any diagonal. ... draw to bitmap you get pixels instead of curves, so when you zoom in your bitmap you just get bigger pixels. ... i'd suggest creating button on your web page "printable version" that will feed browser with higher resolution image for printing purpouses that has the same size set inside tag - just like Lloyd suggested. ... ton of pixels into an image and get it to print super HQ smal font. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Most common fonts?
    ... and set font size to an appropriate number of pixels ... Use resolution independent font sizes ... {bitstream vera sans} ...
    (comp.lang.tcl)
  • Re: Units: Pixels vs. Points?
    ... I'll simply have more room to fit more windows. ... pixels) are too small on widescreen computers. ... if it's bigger than the Position, shrink or increase the font size. ... font on any resolution would be unreadable, ...
    (comp.soft-sys.matlab)
  • Re: Firefox Font Rendering
    ... The reason that it should not change font *size*, ... Changing DPI should change the resolution of the font (how many dots are ... state the physical screen size and the number of pixels, ...
    (Fedora)
  • Re: TextWidth() Alternative?
    ... It returns the width of the text in device logical units. ... course depends on which font is currently selected into the device. ... Printer Object always use device pixels as the device logical units, ... of the text in a RichTextBox then the "screen pixel width" of the text it ...
    (microsoft.public.vb.general.discussion)