Thursday, September 24, 2009 5:31 AM
Michael S. Kaplan
Can I show the whole string or can't I?
Jim's question from a few weeks ago was:
I’m being given a Unicode string and I need to determine if it will render cleanly using the system font (not displaying any blocks or “non-supported-glyph” symbols). I’ve tried using ScriptGetCMap() and GetGlyphIndices(), but both of these flag a character like 0x0C60 as not having a glyph – although it’s actually composed of multiple glyphs and it does render properly.
Our product allows an administrator to push policy to client machines, which includes a custom message to show in a notification balloon. The administrator can enter the text on a console and might include Japanese characters, for example, and that text gets pushed to a bunch of clients, some of which can’t display those characters. The client software is supposed to display the custom message if possible (no blocks displayed) and fall back to a built-in message if the custom message won’t display correctly.
Any pointers to APIs or sample code that will accurately determine if a string can be drawn?
Sound familiar?
Well, it should!
At first glance, it is the same problem discussed in Is that character in the font or isn't it?, and that is a blog that is chock full of potential solutions!
Unfortunately, Jim's question adds one element to the problem, one new wrinkle.
And that is to also try and figure out the problem for any fonts that the system might map to via linking/fallback/substitution, etc.
And this does not exist.
To be honest, it isn't actually a problem that is worth trying to solve. As Michael Warning pointed out in that thread:
This unfortunately is a really hard problem. And the answer will be different depending on the text stack you’re using (GDI, GDI+, DWrite). The problem is that each stack has a different set of rules for font fallback – how it automatically changes fonts around when it encounters a character that isn't’t supported in the font you asked for.
Now Michael is thinking about the macro problem -- the complexity of all of the different models and trying to deal with how improbable it would be to capture all of these differences in code.
But to be honest the micro problem (looking at any one of these technologies) is still pretty complicated -- the kind of project where one will almost certainly fail, in the end.
So what can we do?
Well, the answer I would suggest will have to wait for the next blog.... :-)