by Michael S. Kaplan, published on 2006/07/25 05:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/07/25/677592.aspx
Michiel Salters asked in the Suggestion Box:
MLang font linking works without us asking , it's just too nice. Really too nice, because MLang isn't telling us it failed. And in fact, we can't figure out that it's failing.
So what's the problem? Most of our users won't have east asian fonts installed. Our application needs to know this. However, due to font linking MLang is rendering our text. It just renders them as a set of boxes.
The first 10 algorithms we tries to distinguish machines with and without east asian fonts have failed. Among the obvious:
CreateFont() with CHINESEBIG5_CHARSET : works even without east asian fonts installed
Call GetGlyphIndices for the font created for CHINESEBIG5_CHARSET : suggests that font created has real glyphs (i.e. U+4E00 and U+4E01 have different glyphs)
Use IMLangFontLink2 and call GetScriptFontInfo : MSDN documentation is incomplete here, and it just font names. We can't hardcode every fontname out there.
Compare IMLangFontLink2::GetFontCodePages with IMLangFontLink2::GetCharCodePages() for U+4e00
Create a font with MLangFontLink2::MapFont, passing U+4E00 to get a chinese font. (fails straight away)
Get the chinese codepage using GetCharCodePages for U+4E00, then create a font for the codepage using MapFont. That does work, but it also works if there is in fact no font installed.
Create the font via that chinese codepage, then get the glyphs with GetGlyphIndices for U+4e00 and U+4e01. Now we were getting pretty annoyed. If there are no east asian fonts installed, we still get a font, GetGlyphIndices tells us the glyphs U+4e00 and U+4e01 differ, yet all we get is boxes (obviously)
The final lie was MLangFontLink2::GetFontUnicodeRanges. If there are no east-asian fonts installed, it will in fact include return a range that contains all 20.000+ CJK ideographs. Apparently means 20.000 different(!) box glyphs.
We currently see two options. The real east asian fonts are incomplete. We can just hardcode a codepoint that is currently missing, and check if MLangFontLink2::GetFontUnicodeRanges claims support. If so, we assume it's lying about all code points. Of course, if Vista adds that code point, or the user installs a font which adds that missing code point, this assumption is wrong.
The only solution we haven't tried, and we really can't imagine we have to resort to this, is rendering U+4e00 to a bitmap and see if this renders a box (two vertical lines connected by two horizontal lines)
So, where is the BOOL IsThereAFontFor(wchar_t) function hidden? And did I mention we'd want it on Windows ME/IE5 as well?
Part of the problem here is simply stated -- MLang is not all about answering whether support is not there -- it is all about trying to make the support work.
And of course the GDI problem (like using CreateFont with the CHINESEBIG5_CHARSET) is similar -- as a function it will do its best to create the requested font but if the final answer is not perfect, GDI does not spend too much time weeping. If you catch my drift.
If you really need to know whether East Asain support is installed, the best way to do it is to use the NLS IsValidLocale function with the LCID_INSTALLED flag -- it is the way that you know whether the OS thinks that all of the supporting files are there....
Be sure to pick the right LCID on downlevel systems, since everything prior to XP was a bit more granular about language support. It is no big deal, just make sure you pick the LCID that best captures the support you are looking for, that's all. :-)
I can't say too much about the IE5/Windows Me situation -- I mean, since as I said in Is MSLU Still Supported?, Windows 98 and Windows Me aren't supported anymore. Though if you truly wanting to go beyond the OS answer when it says FALSE you can see if you have the IE language support -- ether by using the model described in Installable language components in Internet Explorer or looking for the specific fonts that it installs per language....
Generally, I find this whole scenario pretty unconvincing. Maybe that is just me.
But we are talking about users who don't install East Asian support. Yet these users expect a program to magically support CJK ideographs. Users, who further will refuse to understand that they need to install the EA support if they are seeing NULL GLYPHS instead of ideographs.
When I was consulting, I never had problems pointing out this particular requirement; I have even helped write up the justification to companies that were not always willing to allow the users permissions to install stuff like this. It is just not the sort of problem that I have found a huge lack of understanding about.
But if that fails, you can just blame Microsoft. It's not like everyone else dosen't do that. :-)
This post brought to you by ៘ (U+17d8, a.k.a. KHMER SIGN BEYYAL)
# Tom Gewecke on 25 Jul 2006 7:52 AM:
# Michael S. Kaplan on 25 Jul 2006 8:09 AM:
# Serge Wautier on 30 Jul 2006 3:58 PM:
# Michiel Salters on 3 Aug 2006 9:24 AM:
# Michael S. Kaplan on 3 Aug 2006 9:34 AM:
referenced by
2007/02/06 MLang and GDI and Uniscribe, oh my!