From: Elizabeth Figura <zfigura@codeweavers.com> --- dlls/gdi32/tests/font.c | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index 49c78e6894b..87cb27ba710 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -7890,6 +7890,121 @@ static void test_font_weight(void) DeleteObject(hfont2); bret = RemoveFontResourceExA(ttf_name, 0, NULL); ok(bret, "got error %ld\n", GetLastError()); + + bret = DeleteFileA(ttf_name); + ok(bret, "got error %ld\n", GetLastError()); +} + +static WCHAR *get_font_path( const char *face ) +{ + DWORD buffer[32]; + struct font_realization_info *realization_info = (void *)buffer; + struct file_info file_info; + LOGFONTA lf = {0}; + HFONT font, prev; + SIZE_T size; + WCHAR *path; + BOOL ret; + HDC dc; + + dc = GetDC( 0 ); + + strcpy( lf.lfFaceName, face ); + lf.lfHeight = 90; + lf.lfWeight = FW_BOLD; + lf.lfCharSet = DEFAULT_CHARSET; + font = CreateFontIndirectA( &lf ); + prev = SelectObject( dc, font ); + + buffer[0] = 24; + ret = pGetFontRealizationInfo( dc, buffer ); + ok( ret == TRUE, "got %d\n", ret ); + ret = pGetFontFileInfo( realization_info->instance_id, 0, &file_info, sizeof(file_info), &size ); + ok( ret == TRUE, "got %d\n", ret ); + path = wcsdup( file_info.path ); + + DeleteObject( SelectObject( dc, prev )); + ReleaseDC( 0, dc ); + + return path; +} + +/* Test the path search order by AddFontResource(). */ +static void test_add_font_path(void) +{ + static const char system32_path[] = "C:\\windows\\system32\\winetest_font.ttf"; + static const char fonts_path[] = "C:\\windows\\fonts\\winetest_font.ttf"; + WCHAR cwd[MAX_PATH], temp_path[MAX_PATH]; + const void *rsrc_data; + DWORD rsrc_size; + WCHAR *path; + BOOL wow64; + int count; + BOOL ret; + FILE *f; + + IsWow64Process( GetCurrentProcess(), &wow64 ); + + rsrc_data = get_res_data( "wine_heavy.ttf", &rsrc_size ); + if (!(f = fopen( fonts_path, "wb" ))) + { + skip( "not enough permissions to create fonts in C:\\windows\n" ); + return; + } + fwrite( rsrc_data, rsrc_size, 1, f ); + fclose( f ); + + GetCurrentDirectoryW( ARRAY_SIZE(cwd), cwd ); + GetTempPathW( ARRAY_SIZE(temp_path), temp_path ); + SetCurrentDirectoryW( temp_path ); + + ret = CopyFileA( fonts_path, "winetest_font.ttf", FALSE ); + ok( ret, "got error %lu\n", GetLastError() ); + ret = CopyFileA( fonts_path, system32_path, FALSE ); + ok( ret, "got error %lu\n", GetLastError() ); + + count = AddFontResourceExA( "winetest_font.ttf", 0, NULL ); + ok( count == 1, "got %d\n", count ); + path = get_font_path( "wine_heavy" ); + todo_wine ok( !wcscmp( path, L"C:\\WINDOWS\\FONTS\\WINETEST_FONT.TTF" ), + "got %s\n", debugstr_w( path )); + ret = RemoveFontResourceExA( "winetest_font.ttf", 0, NULL ); + ok( ret, "got error %lu\n", GetLastError() ); + + ret = DeleteFileA( fonts_path ); + ok( ret == TRUE, "got error %lu\n", GetLastError() ); + + count = AddFontResourceExA( "winetest_font.ttf", 0, NULL ); + ok( count == 1, "got %d\n", count ); + path = get_font_path( "wine_heavy" ); + wcscat( temp_path, L"winetest_font.ttf" ); + wcsupr( temp_path ); + todo_wine ok( !wcscmp( path, temp_path ), "expected %s, got %s\n", + debugstr_w( temp_path ), debugstr_w( path )); + ret = RemoveFontResourceExA( "winetest_font.ttf", 0, NULL ); + ok( ret, "got error %lu\n", GetLastError() ); + + ret = DeleteFileA( "winetest_font.ttf" ); + ok( ret == TRUE, "failed to delete %s, error %lu\n", debugstr_w( temp_path ), GetLastError() ); + + /* Windows is broken and doesn't redirect this path. + * Stratego (1997) depends on it being redirected, + * and fails on 64-bit Windows */ + count = AddFontResourceExA( "winetest_font.ttf", 0, NULL ); + todo_wine ok( count == 1 || broken( wow64 ), "got %d\n", count ); + if (count == 1) + { + path = get_font_path( "wine_heavy" ); + todo_wine ok( !wcscmp( path, L"C:\\WINDOWS\\SYSTEM32\\WINETEST_FONT.TTF" ), + "got %s\n", debugstr_w( path )); + ret = RemoveFontResourceExA( "winetest_font.ttf", 0, NULL ); + ok( ret, "got error %lu\n", GetLastError() ); + } + + ret = DeleteFileA( system32_path ); + ok( ret == TRUE, "got error %lu\n", GetLastError() ); + + SetCurrentDirectoryW( cwd ); } START_TEST(font) @@ -7982,6 +8097,7 @@ START_TEST(font) test_char_width(); test_select_object(); test_font_weight(); + test_add_font_path(); /* These tests should be last test until RemoveFontResource * is properly implemented. -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10073