[PATCH 0/2] MR10073: gdi32: Look for fonts in system32.
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
From: Elizabeth Figura <zfigura@codeweavers.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58963 --- dlls/gdi32/tests/font.c | 2 +- dlls/gdi32/text.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index 87cb27ba710..c56180b1ce6 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -7991,7 +7991,7 @@ static void test_add_font_path(void) * 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 ); + ok( count == 1 || broken( wow64 ), "got %d\n", count ); if (count == 1) { path = get_font_path( "wine_heavy" ); diff --git a/dlls/gdi32/text.c b/dlls/gdi32/text.c index b0a3e98f588..000878ccf6a 100644 --- a/dlls/gdi32/text.c +++ b/dlls/gdi32/text.c @@ -2524,7 +2524,24 @@ static int add_font_resource( const WCHAR *str, DWORD flags, void *dv ) if (!ret && !wcschr( str, '\\' )) { /* try as system font */ - ret = NtGdiAddFontResourceW( str, lstrlenW( str ) + 1, 1, flags, 0, dv ); + WCHAR *system_dir; + + if ((ret = NtGdiAddFontResourceW( str, wcslen( str ) + 1, 1, flags, 0, dv ))) + return ret; + + if (!(system_dir = malloc( (MAX_PATH + 1 + wcslen( str )) * sizeof(WCHAR) ))) + return 0; + GetSystemDirectoryW( system_dir, MAX_PATH + 1 + wcslen( str )); + wcscat( system_dir, L"\\" ); + wcscat( system_dir, str ); + if (!RtlDosPathNameToNtPathName_U( system_dir, &nt_name, NULL, NULL )) + { + free( system_dir ); + return 0; + } + ret = NtGdiAddFontResourceW( nt_name.Buffer, nt_name.Length / sizeof(WCHAR) + 1, + 1, flags, 0, dv ); + RtlFreeUnicodeString( &nt_name ); } return ret; } @@ -2559,7 +2576,24 @@ static int remove_font_resource( const WCHAR *str, DWORD flags, void *dv ) if (!ret && !wcschr( str, '\\' )) { /* try as system font */ - ret = NtGdiRemoveFontResourceW( str, lstrlenW( str ) + 1, 1, flags, 0, dv ); + WCHAR *system_dir; + + if ((ret = NtGdiRemoveFontResourceW( str, wcslen( str ) + 1, 1, flags, 0, dv ))) + return ret; + + if (!(system_dir = malloc( (MAX_PATH + 1 + wcslen( str )) * sizeof(WCHAR) ))) + return 0; + GetSystemDirectoryW( system_dir, MAX_PATH + 1 + wcslen( str )); + wcscat( system_dir, L"\\" ); + wcscat( system_dir, str ); + if (!RtlDosPathNameToNtPathName_U( system_dir, &nt_name, NULL, NULL )) + { + free( system_dir ); + return 0; + } + ret = NtGdiRemoveFontResourceW( nt_name.Buffer, nt_name.Length / sizeof(WCHAR) + 1, + 1, flags, 0, dv ); + RtlFreeUnicodeString( &nt_name ); } return ret; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10073
This merge request was approved by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10073
participants (3)
-
Elizabeth Figura -
Elizabeth Figura (@zfigura) -
Huw Davies (@huw)