From 4094ff025675a14e7572d975d4fd1bf7c11dc2e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Miko=C5=82aj=20Zalewski?= Date: Sun, 30 Mar 2008 21:43:15 +0200 Subject: [PATCH] gdi32: Fix GetGlyphIndices to select properly the invalid char glyph for TrueType fonts. --- dlls/gdi32/freetype.c | 21 ++++++++++++++------- dlls/gdi32/tests/font.c | 32 +++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 04db3ae8118..6356c1f583c 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -4068,26 +4068,33 @@ static FT_UInt get_glyph_index(const GdiFont *font, UINT glyph) /************************************************************* * WineEngGetGlyphIndices * - * FIXME: add support for GGI_MARK_NONEXISTING_GLYPHS */ DWORD WineEngGetGlyphIndices(GdiFont *font, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags) { int i; - WCHAR default_char = 0; - TEXTMETRICW textm; + int default_char = -1; - if (flags & GGI_MARK_NONEXISTING_GLYPHS) default_char = 0x001f; /* Indicate non existence */ + if (flags & GGI_MARK_NONEXISTING_GLYPHS) default_char = 0xffff; /* XP would use 0x1f for bitmap fonts */ for(i = 0; i < count; i++) { pgi[i] = get_glyph_index(font, lpstr[i]); if (pgi[i] == 0) { - if (!default_char) + if (default_char == -1) { - WineEngGetTextMetrics(font, &textm); - default_char = textm.tmDefaultChar; + if (FT_IS_SFNT(font->ft_face)) + { + TT_OS2 *pOS2 = pFT_Get_Sfnt_Table(font->ft_face, ft_sfnt_os2); + default_char = (pOS2->usDefaultChar ? get_glyph_index(font, pOS2->usDefaultChar) : 0); + } + else + { + TEXTMETRICW textm; + WineEngGetTextMetrics(font, &textm); + default_char = textm.tmDefaultChar; + } } pgi[i] = default_char; } diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index ce34ab2006e..d85ab122d29 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -583,35 +583,49 @@ static void test_GetGlyphIndices(void) WCHAR testtext[] = {'T','e','s','t',0xffff,0}; WORD glyphs[(sizeof(testtext)/2)-1]; TEXTMETRIC textm; + HFONT hOldFont; if (!pGetGlyphIndicesW) { skip("GetGlyphIndices not available on platform\n"); return; } - if(!is_font_installed("Symbol")) + hdc = GetDC(0); + + ok(GetTextMetrics(hdc, &textm), "GetTextMetric failed\n"); + flags |= GGI_MARK_NONEXISTING_GLYPHS; + charcount = pGetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags); + ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %d\n", charcount); + ok((glyphs[4] == 0x001f || glyphs[4] == 0xffff /* Vista */), "GetGlyphIndices should have returned a nonexistent char not %04x\n", glyphs[4]); + flags = 0; + charcount = pGetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags); + ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %d\n", charcount); + ok(glyphs[4] == textm.tmDefaultChar, "GetGlyphIndices should have returned a %04x not %04x\n", + textm.tmDefaultChar, glyphs[4]); + + if(!is_font_installed("Tahoma")) { - skip("Symbol is not installed so skipping this test\n"); + skip("Tahoma is not installed so skipping this test\n"); return; } - memset(&lf, 0, sizeof(lf)); - strcpy(lf.lfFaceName, "Symbol"); + strcpy(lf.lfFaceName, "Tahoma"); lf.lfHeight = 20; hfont = CreateFontIndirectA(&lf); - hdc = GetDC(0); - + hOldFont = SelectObject(hdc, hfont); ok(GetTextMetrics(hdc, &textm), "GetTextMetric failed\n"); flags |= GGI_MARK_NONEXISTING_GLYPHS; charcount = pGetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags); ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %d\n", charcount); - ok((glyphs[4] == 0x001f || glyphs[4] == UNICODE_NOCHAR /* Vista */), "GetGlyphIndices should have returned a nonexistent char not %04x\n", glyphs[4]); + ok(glyphs[4] == 0xffff, "GetGlyphIndices should have returned 0xffff char not %04x\n", glyphs[4]); flags = 0; + testtext[0] = textm.tmDefaultChar; charcount = pGetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags); ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %d\n", charcount); - ok(glyphs[4] == textm.tmDefaultChar, "GetGlyphIndices should have returned a %04x not %04x\n", - textm.tmDefaultChar, glyphs[4]); + todo_wine ok(glyphs[0] == 0, "GetGlyphIndices for tmDefaultChar should be 0 not %04x\n", glyphs[0]); + ok(glyphs[4] == 0, "GetGlyphIndices should have returned 0 not %04x\n", glyphs[4]); + DeleteObject(SelectObject(hdc, hOldFont)); } static void test_GetKerningPairs(void) -- 2.11.4.GIT