Question

The little web application I am writing populates a temporary invisible container with some text, measures the resulting height, and then uses it to generate some guis based on that height.

This is done because, not all fonts are mon-spaced and as such need to be measured each time to determine how much space they will take up.

Now, I may need to scale the entire UI to fit a different screen size and was wondering if I can just scale the resulting height reliably.

Simply Put: Are all front glyphs guaranteed to be proportionate when scaled or can you have different glyph widths/spacing at different font sizes?

e.g. Will a font set at size 20 always be exactly 2 times the size of a font set at size 10?

EDIT: Here is another view of the test I did and posted in the comments below: A test confirming width isn

Was it helpful?

Solution

When you double font size, it is doubled exactly. But this does not mean that glyphs are scaled proportionally. The font size is simply a property of the font, not a property of glyphs. Glyphs are scaled, but the results are not and cannot be exact, due to the granularity of rendering: the abstract glyph shapes must be rasterized, i.e. converted to pixel maps, and this inevitably changes their shapes.

For example, consider the horizontal stroke of the letter “e”. The width depends on the font size, of course, but in rasterization, it needs to be mapped to one pixel, two pixels, or some other number of pixels. Even subpixel rendering does not change this; it just modifies the way rasterization works. Thus, the width of the stroke as rendered on screen (or paper) cannot exactly reflect the font size. And different strokes in a glyph will behave differently, so that an increase of font size does not mean exact magnification of a glyph.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top