Module: wine Branch: master Commit: f6d9908e4864efd59e26c41129aeef6880c53b22 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f6d9908e4864efd59e26c4112...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Oct 26 12:05:19 2020 +0100
gdi32: Move the AddFontMemResourceEx() implementation out of freetype.c.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/gdi32/font.c | 44 +++++++++++++++++++++++++++++--------------- dlls/gdi32/freetype.c | 35 +++++++++-------------------------- dlls/gdi32/gdi_private.h | 2 +- 3 files changed, 39 insertions(+), 42 deletions(-)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index 2e926fa52fc..af87c66498f 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -5429,34 +5429,48 @@ BOOL WINAPI RemoveFontResourceW( LPCWSTR str ) /*********************************************************************** * AddFontMemResourceEx (GDI32.@) */ -HANDLE WINAPI AddFontMemResourceEx( PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD *pcFonts) +HANDLE WINAPI AddFontMemResourceEx( PVOID ptr, DWORD size, PVOID pdv, DWORD *pcFonts ) { HANDLE ret; DWORD num_fonts; + void *copy;
- if (!pbFont || !cbFont || !pcFonts) + if (!ptr || !size || !pcFonts) { SetLastError(ERROR_INVALID_PARAMETER); return NULL; } if (!font_funcs) return NULL; + if (!(copy = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL; + memcpy( copy, ptr, size ); + EnterCriticalSection( &font_cs ); - ret = font_funcs->pAddFontMemResourceEx( pbFont, cbFont, pdv, &num_fonts ); + num_fonts = font_funcs->add_mem_font( copy, size, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); LeaveCriticalSection( &font_cs ); - if (ret) + + if (!num_fonts) { - __TRY - { - *pcFonts = num_fonts; - } - __EXCEPT_PAGE_FAULT - { - WARN("page fault while writing to *pcFonts (%p)\n", pcFonts); - RemoveFontMemResourceEx(ret); - ret = 0; - } - __ENDTRY + HeapFree( GetProcessHeap(), 0, copy ); + return NULL; + } + + /* FIXME: is the handle only for use in RemoveFontMemResourceEx or should it be a true handle? + * For now return something unique but quite random + */ + ret = (HANDLE)((INT_PTR)copy ^ 0x87654321); + + __TRY + { + *pcFonts = num_fonts; + } + __EXCEPT_PAGE_FAULT + { + WARN("page fault while writing to *pcFonts (%p)\n", pcFonts); + RemoveFontMemResourceEx( ret ); + ret = 0; } + __ENDTRY + TRACE( "Returning handle %p\n", ret ); return ret; }
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 286af040355..9ed6077443f 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -2107,6 +2107,14 @@ static INT CDECL freetype_add_font( const WCHAR *file, DWORD flags ) return ret; }
+/************************************************************* + * freetype_add_mem_font + */ +static INT CDECL freetype_add_mem_font( void *ptr, SIZE_T size, DWORD flags ) +{ + return AddFontToList( NULL, NULL, ptr, size, flags ); +} + /************************************************************* * freetype_remove_font */ @@ -3049,31 +3057,6 @@ static void delete_external_font_keys(void) if(winnt_key) RegCloseKey(winnt_key); }
-/************************************************************* - * freetype_AddFontMemResourceEx - * - */ -static HANDLE CDECL freetype_AddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD *pcFonts) -{ - PVOID pFontCopy = HeapAlloc(GetProcessHeap(), 0, cbFont); - - TRACE("Copying %d bytes of data from %p to %p\n", cbFont, pbFont, pFontCopy); - memcpy(pFontCopy, pbFont, cbFont); - - *pcFonts = AddFontToList(NULL, NULL, pFontCopy, cbFont, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE); - 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); -} - static WCHAR *get_ttf_file_name( LPCWSTR font_file, LPCWSTR font_path ) { WCHAR *fullname; @@ -7477,9 +7460,9 @@ static const struct font_backend_funcs font_funcs = freetype_GetCharWidthInfo, freetype_GetFontUnicodeRanges, freetype_SelectFont, - freetype_AddFontMemResourceEx, freetype_CreateScalableFontResource, freetype_add_font, + freetype_add_mem_font, freetype_remove_font, freetype_alloc_font, freetype_get_font_data, diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index 4fd59cfd9bc..32cdace5c7d 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -370,10 +370,10 @@ struct font_backend_funcs DWORD (CDECL *pGetFontUnicodeRanges)( struct gdi_font *font, GLYPHSET *glyphset ); struct gdi_font * (CDECL *pSelectFont)( DC *dc, HFONT hfont, UINT *aa_flags, UINT default_aa_flags );
- HANDLE (CDECL *pAddFontMemResourceEx)( void *font, DWORD size, PVOID pdv, DWORD *count ); BOOL (CDECL *pCreateScalableFontResource)( DWORD hidden, LPCWSTR resource, LPCWSTR font_file, LPCWSTR font_path ); INT (CDECL *add_font)( const WCHAR *file, DWORD flags ); + INT (CDECL *add_mem_font)( void *ptr, SIZE_T size, DWORD flags ); BOOL (CDECL *remove_font)( const WCHAR *file, DWORD flags );
BOOL (CDECL *alloc_font)( struct gdi_font *font );