From 3e7f8aa272218d1ea08994eced511beb4776493f Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 20 Oct 2020 22:07:06 +0200 Subject: [PATCH] gdi32: Move the other exported freetype functions to the font backend table. Signed-off-by: Alexandre Julliard --- dlls/gdi32/font.c | 57 +++++++++-- dlls/gdi32/freetype.c | 216 ++++++++++++--------------------------- dlls/gdi32/gdi_private.h | 22 +++- 3 files changed, 131 insertions(+), 164 deletions(-) diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index eaf817ec657..a4ed1f0e9cf 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -3880,8 +3880,8 @@ BOOL WINAPI CreateScalableFontResourceW( DWORD hidden, LPCWSTR resource_file, TRACE("(%d, %s, %s, %s)\n", hidden, debugstr_w(resource_file), debugstr_w(font_file), debugstr_w(font_path) ); - return WineEngCreateScalableFontResource( hidden, resource_file, - font_file, font_path ); + if (!font_funcs) return FALSE; + return font_funcs->pCreateScalableFontResource( hidden, resource_file, font_file, font_path ); } /************************************************************************* @@ -4663,11 +4663,12 @@ fail: */ INT WINAPI AddFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv ) { - int ret = WineEngAddFontResourceEx(str, fl, pdv); + int ret; WCHAR *filename; BOOL hidden; - if (ret == 0) + if (!font_funcs) return 1; + if (!(ret = font_funcs->pAddFontResourceEx( str, fl, pdv ))) { /* FreeType <2.3.5 has problems reading resources wrapped in PE files. */ HMODULE hModule = LoadLibraryExW(str, NULL, LOAD_LIBRARY_AS_DATAFILE); @@ -4685,7 +4686,7 @@ INT WINAPI AddFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv ) else if ((filename = get_scalable_filename( str, &hidden )) != NULL) { if (hidden) fl |= FR_PRIVATE | FR_NOT_ENUM; - ret = WineEngAddFontResourceEx( filename, fl, pdv ); + ret = font_funcs->pAddFontResourceEx( filename, fl, pdv ); HeapFree( GetProcessHeap(), 0, filename ); } } @@ -4721,8 +4722,8 @@ HANDLE WINAPI AddFontMemResourceEx( PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD SetLastError(ERROR_INVALID_PARAMETER); return NULL; } - - ret = WineEngAddFontMemResourceEx(pbFont, cbFont, pdv, &num_fonts); + if (!font_funcs) return NULL; + ret = font_funcs->pAddFontMemResourceEx( pbFont, cbFont, pdv, &num_fonts ); if (ret) { __TRY @@ -4769,11 +4770,13 @@ BOOL WINAPI RemoveFontResourceExA( LPCSTR str, DWORD fl, PVOID pdv ) */ BOOL WINAPI RemoveFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv ) { - int ret = WineEngRemoveFontResourceEx( str, fl, pdv ); + int ret; WCHAR *filename; BOOL hidden; - if (ret == 0) + if (!font_funcs) return TRUE; + + if (!(ret = font_funcs->pRemoveFontResourceEx( str, fl, pdv ))) { /* FreeType <2.3.5 has problems reading resources wrapped in PE files. */ HMODULE hModule = LoadLibraryExW(str, NULL, LOAD_LIBRARY_AS_DATAFILE); @@ -4785,7 +4788,7 @@ BOOL WINAPI RemoveFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv ) else if ((filename = get_scalable_filename( str, &hidden )) != NULL) { if (hidden) fl |= FR_PRIVATE | FR_NOT_ENUM; - ret = WineEngRemoveFontResourceEx( filename, fl, pdv ); + ret = font_funcs->pRemoveFontResourceEx( filename, fl, pdv ); HeapFree( GetProcessHeap(), 0, filename ); } } @@ -4967,6 +4970,40 @@ BOOL WINAPI GetFontRealizationInfo(HDC hdc, struct font_realization_info *info) return ret; } +/************************************************************************* + * GetRasterizerCaps (GDI32.@) + */ +BOOL WINAPI GetRasterizerCaps( LPRASTERIZER_STATUS lprs, UINT cbNumBytes) +{ + lprs->nSize = sizeof(RASTERIZER_STATUS); + lprs->wFlags = font_funcs ? (TT_AVAILABLE | TT_ENABLED) : 0; + lprs->nLanguageID = 0; + return TRUE; +} + +/************************************************************************* + * GetFontFileData (GDI32.@) + */ +BOOL WINAPI GetFontFileData( DWORD instance_id, DWORD unknown, UINT64 offset, void *buff, DWORD buff_size ) +{ + if (!font_funcs) return FALSE; + return font_funcs->pGetFontFileData( instance_id, unknown, offset, buff, buff_size ); +} + +/************************************************************************* + * GetFontFileInfo (GDI32.@) + */ +BOOL WINAPI GetFontFileInfo( DWORD instance_id, DWORD unknown, struct font_fileinfo *info, + SIZE_T size, SIZE_T *needed ) +{ + if (!font_funcs) + { + *needed = 0; + return FALSE; + } + return font_funcs->pGetFontFileInfo( instance_id, unknown, info, size, needed ); +} + struct realization_info { DWORD flags; /* 1 for bitmap fonts, 3 for scalable fonts */ diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 2cfc4521b61..4f918c0de74 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -392,12 +392,6 @@ typedef struct { GdiFont *font; } CHILD_FONT; -struct font_fileinfo { - FILETIME writetime; - LARGE_INTEGER size; - WCHAR path[1]; -}; - struct tagGdiFont { struct gdi_font *gdi_font; struct list entry; @@ -3239,113 +3233,93 @@ static void delete_external_font_keys(void) } /************************************************************* - * WineEngAddFontResourceEx + * freetype_AddFontResourceEx * */ -INT WineEngAddFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) +static INT CDECL freetype_AddFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) { WCHAR path[MAX_PATH]; INT ret = 0; + DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE; - GDI_CheckNotLock(); + EnterCriticalSection( &freetype_cs ); - if (ft_handle) /* do it only if we have freetype up and running */ - { - DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE; + if (!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE; + if (GetFullPathNameW( file, MAX_PATH, path, NULL )) + ret = add_font_resource( path, addfont_flags ); - EnterCriticalSection( &freetype_cs ); - - if (!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE; - if (GetFullPathNameW( file, MAX_PATH, path, NULL )) - ret = add_font_resource( path, addfont_flags ); - - if (!ret && !strchrW(file, '\\')) { - /* Try in %WINDIR%/fonts, needed for Fotobuch Designer */ - get_winfonts_dir_path( file, path ); + if (!ret && !strchrW(file, '\\')) { + /* Try in %WINDIR%/fonts, needed for Fotobuch Designer */ + get_winfonts_dir_path( file, path ); + ret = add_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); + /* Try in datadir/fonts (or builddir/fonts), needed for Magic the Gathering Online */ + if (!ret) + { + get_data_dir_path( file, path ); ret = add_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); - /* Try in datadir/fonts (or builddir/fonts), needed for Magic the Gathering Online */ - if (!ret) - { - get_data_dir_path( file, path ); - ret = add_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); - } } - - LeaveCriticalSection( &freetype_cs ); } + + LeaveCriticalSection( &freetype_cs ); return ret; } /************************************************************* - * WineEngAddFontMemResourceEx + * freetype_AddFontMemResourceEx * */ -HANDLE WineEngAddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD *pcFonts) +static HANDLE CDECL freetype_AddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD *pcFonts) { - GDI_CheckNotLock(); + PVOID pFontCopy = HeapAlloc(GetProcessHeap(), 0, cbFont); - if (ft_handle) /* do it only if we have freetype up and running */ + TRACE("Copying %d bytes of data from %p to %p\n", cbFont, pbFont, pFontCopy); + memcpy(pFontCopy, pbFont, cbFont); + + EnterCriticalSection( &freetype_cs ); + *pcFonts = AddFontToList(NULL, NULL, pFontCopy, cbFont, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE); + LeaveCriticalSection( &freetype_cs ); + + if (*pcFonts == 0) { - PVOID pFontCopy = HeapAlloc(GetProcessHeap(), 0, cbFont); - - TRACE("Copying %d bytes of data from %p to %p\n", cbFont, pbFont, pFontCopy); - memcpy(pFontCopy, pbFont, cbFont); - - EnterCriticalSection( &freetype_cs ); - *pcFonts = AddFontToList(NULL, NULL, pFontCopy, cbFont, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE); - LeaveCriticalSection( &freetype_cs ); - - if (*pcFonts == 0) - { - TRACE("AddFontToList failed\n"); - HeapFree(GetProcessHeap(), 0, pFontCopy); - return 0; - } - /* FIXME: is the handle only for use in RemoveFontMemResourceEx or should it be a true handle? - * For now return something unique but quite random - */ - TRACE("Returning handle %lx\n", ((INT_PTR)pFontCopy)^0x87654321); - return (HANDLE)(((INT_PTR)pFontCopy)^0x87654321); + TRACE("AddFontToList failed\n"); + HeapFree(GetProcessHeap(), 0, pFontCopy); + return 0; } - - *pcFonts = 0; - return 0; + /* FIXME: is the handle only for use in RemoveFontMemResourceEx or should it be a true handle? + * For now return something unique but quite random + */ + TRACE("Returning handle %lx\n", ((INT_PTR)pFontCopy)^0x87654321); + return (HANDLE)(((INT_PTR)pFontCopy)^0x87654321); } /************************************************************* - * WineEngRemoveFontResourceEx + * freetype_RemoveFontResourceEx * */ -BOOL WineEngRemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) +static BOOL CDECL freetype_RemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) { WCHAR path[MAX_PATH]; INT ret = 0; + DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE; - GDI_CheckNotLock(); + EnterCriticalSection( &freetype_cs ); - if (ft_handle) /* do it only if we have freetype up and running */ + if(!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE; + if (GetFullPathNameW( file, MAX_PATH, path, NULL )) + ret = remove_font_resource( path, addfont_flags ); + + if (!ret && !strchrW(file, '\\')) { - DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE; - - EnterCriticalSection( &freetype_cs ); - - if(!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE; - if (GetFullPathNameW( file, MAX_PATH, path, NULL )) - ret = remove_font_resource( path, addfont_flags ); - - if (!ret && !strchrW(file, '\\')) + get_winfonts_dir_path( file, path ); + ret = remove_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); + if (!ret) { - get_winfonts_dir_path( file, path ); + get_data_dir_path( file, path ); ret = remove_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); - if (!ret) - { - get_data_dir_path( file, path ); - ret = remove_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); - } } - - LeaveCriticalSection( &freetype_cs ); } + + LeaveCriticalSection( &freetype_cs ); return ret; } @@ -3624,11 +3598,11 @@ static BOOL create_fot( const WCHAR *resource, const WCHAR *font_file, const str } /************************************************************* - * WineEngCreateScalableFontResource + * freetype_CreateScalableFontResource * */ -BOOL WineEngCreateScalableFontResource( DWORD hidden, LPCWSTR resource, - LPCWSTR font_file, LPCWSTR font_path ) +static BOOL CDECL freetype_CreateScalableFontResource( DWORD hidden, LPCWSTR resource, + LPCWSTR font_file, LPCWSTR font_path ) { WCHAR *filename = get_ttf_file_name( font_file, font_path ); struct fontdir fontdir; @@ -8138,17 +8112,6 @@ static BOOL CDECL freetype_FontIsLinked( struct gdi_font *font ) return ret; } -/************************************************************************* - * GetRasterizerCaps (GDI32.@) - */ -BOOL WINAPI GetRasterizerCaps( LPRASTERIZER_STATUS lprs, UINT cbNumBytes) -{ - lprs->nSize = sizeof(RASTERIZER_STATUS); - lprs->wFlags = TT_AVAILABLE | TT_ENABLED; - lprs->nLanguageID = 0; - return TRUE; -} - /************************************************************* * freetype_GetFontRealizationInfo */ @@ -8178,9 +8141,10 @@ static BOOL CDECL freetype_GetFontRealizationInfo( struct gdi_font *gdi_font, st } /************************************************************************* - * GetFontFileData (GDI32.@) + * freetype_GetFontFileData */ -BOOL WINAPI GetFontFileData( DWORD instance_id, DWORD unknown, UINT64 offset, void *buff, DWORD buff_size ) +static BOOL CDECL freetype_GetFontFileData( DWORD instance_id, DWORD unknown, UINT64 offset, + void *buff, DWORD buff_size ) { struct font_handle_entry *entry = handle_entry( instance_id ); DWORD tag = 0, size; @@ -8208,9 +8172,10 @@ BOOL WINAPI GetFontFileData( DWORD instance_id, DWORD unknown, UINT64 offset, vo } /************************************************************************* - * GetFontFileInfo (GDI32.@) + * freetype_GetFontFileInfo */ -BOOL WINAPI GetFontFileInfo( DWORD instance_id, DWORD unknown, struct font_fileinfo *info, SIZE_T size, SIZE_T *needed ) +static BOOL CDECL freetype_GetFontFileInfo( DWORD instance_id, DWORD unknown, + struct font_fileinfo *info, SIZE_T size, SIZE_T *needed ) { struct font_handle_entry *entry = handle_entry( instance_id ); SIZE_T required_size; @@ -8506,14 +8471,18 @@ static const struct font_backend_funcs font_funcs = freetype_GetTextFace, freetype_GetTextMetrics, freetype_SelectFont, + freetype_AddFontResourceEx, + freetype_RemoveFontResourceEx, + freetype_AddFontMemResourceEx, + freetype_CreateScalableFontResource, + freetype_GetFontFileData, + freetype_GetFontFileInfo, freetype_alloc_font, freetype_destroy_font }; #else /* HAVE_FREETYPE */ -struct font_fileinfo; - /*************************************************************************/ BOOL WineEngInit( const struct font_backend_funcs **funcs ) @@ -8521,57 +8490,4 @@ BOOL WineEngInit( const struct font_backend_funcs **funcs ) return FALSE; } -INT WineEngAddFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) -{ - FIXME("(%s, %x, %p): stub\n", debugstr_w(file), flags, pdv); - return 1; -} - -INT WineEngRemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) -{ - FIXME("(%s, %x, %p): stub\n", debugstr_w(file), flags, pdv); - return TRUE; -} - -HANDLE WineEngAddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD *pcFonts) -{ - FIXME("(%p, %u, %p, %p): stub\n", pbFont, cbFont, pdv, pcFonts); - return NULL; -} - -BOOL WineEngCreateScalableFontResource( DWORD hidden, LPCWSTR resource, - LPCWSTR font_file, LPCWSTR font_path ) -{ - FIXME("stub\n"); - return FALSE; -} - -/************************************************************************* - * GetRasterizerCaps (GDI32.@) - */ -BOOL WINAPI GetRasterizerCaps( LPRASTERIZER_STATUS lprs, UINT cbNumBytes) -{ - lprs->nSize = sizeof(RASTERIZER_STATUS); - lprs->wFlags = 0; - lprs->nLanguageID = 0; - return TRUE; -} - -/************************************************************************* - * GetFontFileData (GDI32.@) - */ -BOOL WINAPI GetFontFileData( DWORD instance_id, DWORD unknown, UINT64 offset, void *buff, DWORD buff_size ) -{ - return FALSE; -} - -/************************************************************************* - * GetFontFileInfo (GDI32.@) - */ -BOOL WINAPI GetFontFileInfo( DWORD instance_id, DWORD unknown, struct font_fileinfo *info, SIZE_T size, SIZE_T *needed) -{ - *needed = 0; - return FALSE; -} - #endif /* HAVE_FREETYPE */ diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index 8ced9224af5..70f86711dc0 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -301,6 +301,14 @@ struct char_width_info INT unk; /* unknown */ }; +/* Undocumented structure filled in by GetFontFileInfo */ +struct font_fileinfo +{ + FILETIME writetime; + LARGE_INTEGER size; + WCHAR path[1]; +}; + struct gdi_font { void *private; /* font backend private data */ @@ -329,6 +337,16 @@ struct font_backend_funcs BOOL (CDECL *pGetTextMetrics)( struct gdi_font *font, TEXTMETRICW *metrics ); struct gdi_font * (CDECL *pSelectFont)( struct gdi_font *prev, DC *dc, HFONT hfont, UINT *aa_flags, UINT default_aa_flags ); + INT (CDECL *pAddFontResourceEx)( LPCWSTR file, DWORD flags, PVOID pdv ); + INT (CDECL *pRemoveFontResourceEx)( LPCWSTR file, DWORD flags, PVOID pdv ); + HANDLE (CDECL *pAddFontMemResourceEx)( void *font, DWORD size, PVOID pdv, DWORD *count ); + BOOL (CDECL *pCreateScalableFontResource)( DWORD hidden, LPCWSTR resource, + LPCWSTR font_file, LPCWSTR font_path ); + BOOL (CDECL *pGetFontFileData)( DWORD instance_id, DWORD unknown, UINT64 offset, + void *buff, DWORD buff_size ); + BOOL (CDECL *pGetFontFileInfo)( DWORD instance_id, DWORD unknown, + struct font_fileinfo *info, SIZE_T size, SIZE_T *needed ); + BOOL (CDECL *alloc_font)( struct gdi_font *font ); void (CDECL *destroy_font)( struct gdi_font *font ); }; @@ -339,11 +357,7 @@ extern void font_init(void) DECLSPEC_HIDDEN; /* freetype.c */ -extern INT WineEngAddFontResourceEx(LPCWSTR, DWORD, PVOID) DECLSPEC_HIDDEN; -extern HANDLE WineEngAddFontMemResourceEx(PVOID, DWORD, PVOID, LPDWORD) DECLSPEC_HIDDEN; -extern BOOL WineEngCreateScalableFontResource(DWORD, LPCWSTR, LPCWSTR, LPCWSTR) DECLSPEC_HIDDEN; extern BOOL WineEngInit( const struct font_backend_funcs **funcs ) DECLSPEC_HIDDEN; -extern BOOL WineEngRemoveFontResourceEx(LPCWSTR, DWORD, PVOID) DECLSPEC_HIDDEN; /* gdiobj.c */ extern HGDIOBJ alloc_gdi_handle( void *obj, WORD type, const struct gdi_obj_funcs *funcs ) DECLSPEC_HIDDEN;