views:

26

answers:

1

Suppose you have a string with text in two or more scripts. When you use a GDI function like TextOut, (modern versions of) Windows will do "font-linking". That is, GDI will draw what it can with your selected font and draw the rest in an appropriate font that it chooses automagically. For example, if part of your text is in English (using the Roman alphabet), and part of it is Chinese (using CJK characters), and you have Arial selected, the English portion will be drawn in Arial, and the Chinese portion will be drawn in another font that has the CJK glyphs.

My question is, is there a way to determine which fonts TextOut will choose (or did choose) for the font linking?

I have to draw some text with the low-level Uniscribe API, which doesn't do automatic font-linking. I've implemented my own font-linking, but sometimes my algorithm chooses a different font than TextOut does for the same text. I'm trying to understand the Windows algorithm better, but I'm not real good at identifying fonts on sight (especially in unfamiliar scripts).

+2  A: 

The font is selected by a registry entry. It is well described in this article. Quoting the relevant part:

If font linking is enabled on your device, you can examine the registry by enumerating the subkeys of the registry key at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink to determine the mappings of linked fonts to base fonts. You can add links by using Regedit to create additional subkeys.

Hans Passant
Thanks, that's an excellent resource. But I've read in another blog that those registry keys are there just for backward compatibility and that they don't really drive font linking anymore. For example, on my machine TextOut will do font linking for base fonts that aren't in that part of the registry. And it's not font fallback either, as the fonts that are selected for the other scripts are different depending on the base font.
Adrian McCarthy
Check out IMLangFontLink: http://msdn.microsoft.com/en-us/library/aa767872%28v=VS.85%29.aspx
Hans Passant
I used IMLangFontLink2 in an earlier iteration, but it caused problems when I mixed LTR scripts with RTL scripts. I think that's a pretty old solution and it probably remains for backward compatibility.
Adrian McCarthy