views:

272

answers:

4

We have a requirement where our application needs to support high resolution monitors. Currently, when the application comes up in High res monitor, the text that it displays is too small. We use Arial 12 point font by default.

Now to make the text visible, I need to change the font size proportionally. I am finding it tough to come up with a formula which would give me the target font size given the monitor resolution.

Here is my understanding of the problem.

1) On windows, by default 96 pixels correpond to 1 Logical inch. This means that when the monitor resolution increases, the screen size in logical inches also increase.

2) 1 Point font is 1/72 of a Logical Inch. So combined with the fact that there are 96 Pixels per Logical inch, it turns out that, there are 96/72 Pixels per Point of Font.

This means that for a 12 point font, The number of Pixels it will occupy is 12*96/72 = 16 Pixels.

Now I need to know the scaling factor by which I need to increase these Number of Pixels so that the resultant Font is properly visible. If I know the scaled pixel count, I can get the Font size simply by dividing it by (96/72)

What is the suggested scaling factor which would ensure properly scaled Fonts on all monitor resolutions?

Also, please correct if my understanding is wrong.

+2  A: 

There's an example on the MSDN page for LOGFONT structure. Your understanding is correct, you need to scale the point size by vertres / 72.

lfHeight = -PointSize * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
avakar
+2  A: 

If you set the resolution in Windows to match that of the physical monitor, no adjustment should be needed. Any well written program will do the multiplication and division necessary to scale the font properly, and in the newest versions of Windows the OS will lie about the resolution and scale the fonts automatically.

If you wish to handle this outside of the Windows settings, simply multiply your font size by your actual DPI and divide by 96.

Edit: Beginning with Windows Vista, Windows will not report your actual configured DPI unless you write a DPI-aware program. Microsoft has some guidance on the subject. You might find that the default scaling that Microsoft provides for non-DPI-aware programs is good enough for your purposes.

Mark Ransom
Divide by 72. [15char]
avakar
A: 

Why not let the users alter the size of the rendering as they wish, like in web browsers?

Matt Howells
A: 

First I would like to thank for this post and replies. I had the same problem and thanks to u guys now I have a better way of scaling my font size. But when increasing DPI to a custom value, above mentioned scaling factor swill not get the correct value. used the facItor of ScaleContro override and its still the same. I want the font size like in 96DPI resolution when using 125% or 130% or in any custom DPI. Can anyone please help me to solve this.

Thanks Viraj

Ultimately I used a simple scaling factor. It is equal to current vertical resolution divided by 1024 (the default res for our application). This works reasonably well and I guess it should work for you too.
Canopus