I want to display a character of the Kannada language (used in India). To display it correctly ligation is required. I use the following MFC code:
Constructor:
mi_Font.CreateFontW(85, 0, 0, 0, 500, 0, 0, 0,
DEFAULT_CHARSET, 0, 0, 0, 0, L"Tunga");
in OnPaint():
HDC h_DC = ::GetDC(m_hWnd);
HFONT h_OldFont = (HFONT)::SelectObject(h_DC, mi_Font);
WCHAR u16_Face[100];
::GetTextFace(h_DC, 100, u16_Face);
if (wcscmp(u16_Face, L"Tunga") != 0)
throw "Invalid font."; // Just assure that the font has been created correctly
WCHAR u16_Glyphs[100] = {0};
GCP_RESULTS k_Results = {0};
k_Results.lStructSize = sizeof(k_Results);
k_Results.lpGlyphs = u16_Glyphs;
k_Results.nGlyphs = 100;
const WCHAR* u16_Str = L"\x0C95\x0CCD\x0C95\x0CBE"; // Kannada
int s32_Len = (int)wcslen(u16_Str);
GetCharacterPlacement(h_DC, u16_Str, s32_Len, 0, &k_Results, GCP_LIGATE);
ExtTextOut(h_DC, 0, 0, ETO_GLYPH_INDEX, NULL, u16_Glyphs, k_Results.nGlyphs, NULL);
SelectObject(h_DC, h_OldFont);
::ReleaseDC(m_hWnd, h_DC);
This code works perfectly on Windows 7. But on Windows XP the flag GCP_LIGATE has no effect. (On Windows 7 it even works without that flag!)
To assure that the font is not the problem I copied the same font file (Tunga.ttf) to both computers.
The problem is in GetCharacterPlacement()
.
On XP it returns the glyph indices 66,114,66,101 (no ligation)
On Win7 it returns 144,101,180 (ligated)
I cannot believe that Windows XP is not able to display Kannada correctly because GetCharacterPlacement()
has already been introduced in Windows 2000!
And when I manually enter the values into k_Result:
u16_Glyphs[0] = 144;
u16_Glyphs[1] = 101;
u16_Glyphs[2] = 180;
k_Results.nGlyphs = 3;
ExtTextOut()
shows the correct glyph also on XP.
When I check the return value from GetFontLanguageInfo(h_DC)
I get on both operating systems the same value: 0x40000.
Has anybody experience with this API ?