How on earth does that scale, anyhow?

by Michael S. Kaplan, published on 2012/04/18 07:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2012/04/18/10294867.aspx


Over in the Suggestion Box, sk asked:

Hi Michael,

I noticed you've discussed Font Linking multiple times in your blog posts. In some of your posts, you alluded to the fact that scaling of the font size is done by GDI when using font linking. Could you elaborate more on the algorithm that GDI uses to do this scaling?

You mentioned in:

How Do You Solve a Problem Like Meiryo? (Windows XP edition)

That the font linking registry items contain scaling factors for Vista+. Could you talk about how these are used to scale the fonts?

Could you also explain the algorithm that previous versions of Windows (e.g. XP) used to scale fonts (since these scaling factors weren't present on pre-Vista systems)?

Thanks in advance!

Ah, this falls under the category of question I hope no one asks, since the answers are so limited! :-)

Just kidding.

Kinda!

The prior versions of Windows have an easy answer: they don't do it!

And other technologies also have similar problems/limitations.

Pages like Globalization Step-by-Step: Fonts have a little more info:

With font fallback and font linking, the font size of the newly selected font will be the same as that of the original font. For example, if an 8–point Tahoma font was selected to type English and now the user enters some Japanese text, an 8–point MS UI Gothic font will be automatically selected. The 8–point font size might not be the best choice for some scripts, since it can make them hard to read.

Both font fallback and font linking contain logic to estimate an appropriate font size, but both mechanisms have to use metrics exposed by the font that might or might not actually match the way the font appears. Consider the difference in the height of English letters among 8–point Microsoft Sans Serif, 8–point Traditional Arabic, and 8–point Angsana New:

Even though all of these are supposedly 8–point fonts, the actual size of the English letters varies widely. Font fallback and font linking are no substitutes for choosing the right font in the first place. Rather, these mechanisms are simply a means of preventing the user from manually selecting a font; additionally, they prevent UI text from being displayed as a default glyph.

Even so, when font linking occurs, GDI will attempt scale the linked font with the aim of making the glyphs from the linked font appear to match in size the glyphs from the base font. In Windows XP, an algorithm was used that operates in terms of various font metrics. In Vista, this algorithm was found not to give satisfactory results in all scenarios; in particular, it did not give good results when linking to new East Asian fonts that have no embedded bitmaps. To resolve this problem, an alternate scaling mechanism was introduced: explicit scaling factors for particular linked fonts could be specified in font linking registry entries. Scaling factors are specified as a pair of positive integers. For instance, the value

MEIRYO.TTC,Meiryo,128,85

indicates that the scaling algorithm should apply the scaling factors 128 and 85 whenever the given base font is linked to the Meiryo font.

Note that GDI+ is not able to parse these scaling factors. Thus, references to fonts with scaling factors are repeated without these scaling factors. In GDI+, the first reference, with the scaling factors, will appear to be to an unrecognized font and will be ignored. In GDI, the second reference will be treated as redundant and ignored.

 I suppose that counts as a little more info, maybe.

Right?

Two positive integers.

This works the same way as when someone asks me about how my iBot works.

I say "gyroscopes".

They just nod intelligently, even though most of them don't understand -- because they figure they should understand!

I admit I don't get it....

I suppose maybe we could do a little comparative analysis of various font scaling factors to try and suss out the meaning.

For example:

Okay, I'm starting to get some hints here.

Anyone else seeing a pattern or two, as well?

I'll give my thoughts on this meaning soon....


Joshua on 18 Apr 2012 9:46 AM:

Ah yes conservation of angular momentum.

Random832 on 18 Apr 2012 1:21 PM:

I am guessing that 128 for the first number is the "default" [i.e. means do not scale]. This is symmetric between pairs of fonts that both reference each other.

The second number has something to do with moving the baseline, maybe? If you'd given the values for Segoe UI and/or Microsoft Sans Serif it might help crack the code.

sk on 20 Apr 2012 10:43 AM:

Looking forward to your follow-up post!

I am curious why you mention that on pre-Vista systems, no scaling is done at all. This seems to contradict the page you quoted, which says:

"Even so, when font linking occurs, GDI will attempt scale the linked font with the aim of making the glyphs from the linked font appear to match in size the glyphs from the base font. In Windows XP, an algorithm was used that operates in terms of various font metrics."

I guess, regardless if you call it "scaling" or not, GDI will have to pick a size to display the new text with. So how is that size picked?

I guess there are various ways to do it, such as picking the same _point size_ for the new font, or the same _pixel height_ for the new font - which brings up questions of how do you define height. Is it the height the "ascent + descent" or just "ascent" since CJK fonts don't really have descent. So just saying "no scaling is done" is not really enough information to answer the question.

eN_Joy on 5 Apr 2013 12:36 PM:

Still no clue as how to adjust this "pair of integers"..., say, I've linked consolas to fall back to Microsoft YaHei 128, 96, the screen displayed CJK characters are apparently too big for me, how do I downscale them a little bit?

Michael S. Kaplan on 6 Apr 2013 8:00 PM:

Try making that second number bigger, like in the Gulim example scaling to •Gulim: Microsoft Sans Serif via 128,140.


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day