# Making text appear with a specific point size

Is it possible to make text appear onscreen with a specific point size, say 10pt, similar to the text in this post?

With some methods I can obtain the height, width, left, right, top, bottom from a text node or onscreen text, but i can’t find any way to relate this to a font point size.

PS: By the way i assumed that height=top+(-bottom) and width=right+(-left) as invariants, since the results allways match.

Use scale to set the “point size” of the text. This will set the text size in screen units, which are typically -1 … 1 for the entire height of the screen (so usually your text is a very small scale, for instance 0.07).

The units aren’t going to be points, because everything is relative to the size of the window. If you really want to specify the size in points, you’ll have to figure out what scale that is for a given pixel size window.

David

Well the point size is easy to obtain without knowing the screen resolution. I will assume a 17inch screen and point size is by convention 1/72inch, since the panda screen is 2.0 pu height (lets call it panda units) the point size in panda units can be calculated: pu = 2*(1/72)/17 = 0.0016. So a 12pt font would have an height of 0.0192.

I still don’t know exactly how to apply the correct scale to an OnscreenText. Should i obtain the text height, rescale the font to 1pu height and then mutliply by the required ps (12 pt) in panda units like this?

th = text.getHeight()
scale = (1.0/th)*0.0192

Close. Unless you mean your screen is 17 inches tall, you probably are referring to a screen that is 17 inches on the diagonal, which (assuming a 4x3 aspect ratio) means that it is 10.2 inches tall. Also, this computation assumes that your window completely fills your screen (e.g. you are running in fullscreen mode).

Anyway, this means that the point size for a fullscreen window on a 17 inch monitor is 2*(1/72)/10.2 = 0.0027, and a 12pt font on this window would have an height of 0.0327.

Don’t ask the TextNode for its height; that’s not the metric you want (it counts the height of all lines of generated text, as well as the spacing between them).

In fact, by Panda convention, almost all fonts have a design height of 1.0. So you don’t really need to monkey with the scaling beyond that. Thus, the correct scale for your 12-point text is always 0.0327 on your 17-inch monitor, regardless of the font you choose.

(This is not 100% true. It is possible to load a font with a design height different than 1.0, but you have to go out of your way to do it. When you call loader.loadFont(), if you are loading a .ttf or other FreeType-implemented font file (as opposed to a font generated into an egg file via egg-mkfont), you can specify a pointSize parameter to the loadFont call. The default pointSize is 10, and by Panda convention, a 10 point font is scaled to 1.0 screen units. But if you specify a different point size, the font will be scaled correspondingly internally; for instance, if you load a font at a point size of 12, it will be 1.2 screen units high. The only reason you’d want to do this is if you want to have different fonts at different heights without specifying a different scale for each one, which is probably a silly thing to do, since that’s a big waste of texture memory.)

David

I get it now, thanks.