Commit f6d9908e authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Move the AddFontMemResourceEx() implementation out of freetype.c.

parent 047bf252
......@@ -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;
}
......
......@@ -2108,6 +2108,14 @@ static INT CDECL freetype_add_font( const WCHAR *file, DWORD flags )
}
/*************************************************************
* 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
*/
static INT CDECL freetype_remove_font( const WCHAR *file, DWORD flags )
......@@ -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,
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment