Font Height for Screen & Printer

--- A HotBasic Tutorial ---

The HotBasic MyFont.height property requires the height to be in logical units. This makes sense, because the screen and printer require the font size to be expressed in this way. The problem is, that the screen and the printer has a completely different resolution. Furthermore, printers differ in resolution from one another too.

We all know that a font size (from an application user point of view) is specified in points, so this tutorial describes how to bring all this information together.

What is a pointsize?
A point is a printers term that equates to 0.013837 of an inch. It is common practice approximate a point as 1/72 inch.

How is a font measured?
Micosoft's documentation states that in Windows, the size of a font is an imprecise value, but can be generally determined by measuring the distance from the bottom of a lowercase 'g' to the top of an uppercase 'M', as follows: gM

Setting the font-size for screen
The screen is usually set to 96 dots per inch (dpi). So, to convert a font's point size to pixels for display purposes, we can use the following formula.

DEFREAL10 point = 10 '10 points
ScreenFont.height = ((point/72)*96)
Will set ScreenFont.height to 13

Setting the font-size for printer
Firstly, we need to find out what the default Yresolution of the printer is, which is derived from PrintDev. (Please see PrintDev.bas for more information on this.)

To convert a font's point size to dpi for printing:

PrintFont.height = point*(Yres/72)

Please note that Yres should be defined as Real10 in your source code.

The above formula does produce an acceptable result (I have used it in my Minitex editor for some time), but if you compare the printed text with the same output printed by MS NotePad, you will see that your printed output will be a bit smaller. There is no reason why we should emulate what MS does, but if you plan to distribute your program, you may prefer your program to produce an output as near as possible to that a commercial product may produce.

So, we now need to scale the output to obtain a more expected result. Our formula above may be modified as follows:

DEFREAL10  pScale = 1.25
PrintFont.height=(point*(Yres/72))*pScale

Note: that I have spent quite some time on the formula as shown above and found that it prints the same height as NotePad.

An experiment
If a point equates to 1/72 inch, it follows that if we print at 72 points, our font should be 1 inch high.

Let's try it. Use MS Word, use a classic font such as Times New Roman, and set the font to 72 points. Print gM and measure the distance from the bottom of the g to top of M. Does it measure 1 inch?

I have done this for the writing of this tutorial. It measures 7/8 inch. Quite a surprise, but Microsoft did say that in Windows it's an imprecise value