[3/5] gdi32: Implement RemoveFontMemResourceEx.

Kusanagi Kouichi slash at ac.auone-net.jp
Sun Apr 22 05:56:18 CDT 2012


Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
---
 dlls/gdi32/font.c        |    3 +--
 dlls/gdi32/freetype.c    |   56 +++++++++++++++++++++++++++++++++++++++++++++-
 dlls/gdi32/gdi_private.h |    1 +
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index d9c16a4..c45da99 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -3606,8 +3606,7 @@ HANDLE WINAPI AddFontMemResourceEx( PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD
  */
 BOOL WINAPI RemoveFontMemResourceEx( HANDLE fh )
 {
-    FIXME("(%p) stub\n", fh);
-    return TRUE;
+    return WineEngRemoveFontMemResourceEx(fh);
 }
 
 /***********************************************************************
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 332ebf2..a29ae78 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1225,6 +1225,7 @@ static inline BOOL faces_equal( const Face *f1, const Face *f2 )
 
 static inline void free_face( Face *face )
 {
+    list_remove( &face->entry );
     HeapFree( GetProcessHeap(), 0, face->StyleName );
     HeapFree( GetProcessHeap(), 0, face->FullName );
     HeapFree( GetProcessHeap(), 0, face->cached_enum_data );
@@ -1237,7 +1238,6 @@ static inline void free_family( Family *family )
 
     LIST_FOR_EACH_ENTRY_SAFE( face, cursor2, &family->faces, Face, entry )
     {
-        list_remove( &face->entry );
         free_face( face );
     }
     HeapFree( GetProcessHeap(), 0, family->FamilyName );
@@ -2902,6 +2902,60 @@ BOOL WineEngRemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv)
     return TRUE;
 }
 
+static Font *find_font_data(const void *addr)
+{
+    Font *font;
+
+    LIST_FOR_EACH_ENTRY(font, &font_list, Font, entry)
+    {
+        if (font->data_ptr == addr)
+            return font;
+    }
+
+    return NULL;
+}
+
+static void free_font_entry(Font *font)
+{
+    Face *face, *cursor2;
+
+    list_remove(&font->entry);
+    LIST_FOR_EACH_ENTRY_SAFE(face, cursor2, &font->faces, Face, entry)
+    {
+        free_face(face);
+    }
+    HeapFree(GetProcessHeap(), 0, font->file);
+    HeapFree(GetProcessHeap(), 0, font->data_ptr);
+    HeapFree(GetProcessHeap(), 0, font);
+}
+
+/*************************************************************
+ *    WineEngRemoveFontMemResourceEx
+ *
+ */
+BOOL WineEngRemoveFontMemResourceEx(HANDLE fh)
+{
+    BOOL ret = FALSE;
+
+    GDI_CheckNotLock();
+
+    if (ft_handle)  /* do it only if we have freetype up and running */
+    {
+        Font *font;
+
+        EnterCriticalSection(&freetype_cs);
+        font = find_font_data((const void *)((INT_PTR)fh ^ 0x87654321));
+        if (font != NULL)
+        {
+            free_font_entry(font);
+            ret = TRUE;
+        }
+        LeaveCriticalSection(&freetype_cs);
+    }
+
+    return ret;
+}
+
 static char *get_ttf_file_name( LPCWSTR font_file, LPCWSTR font_path )
 {
     WCHAR *fullname;
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 20b522d..6d62a4f 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -294,6 +294,7 @@ extern BOOL WineEngDestroyFontInstance(HFONT handle) DECLSPEC_HIDDEN;
 extern BOOL WineEngGetLinkedHFont(DC *dc, WCHAR c, HFONT *new_hfont, UINT *glyph) DECLSPEC_HIDDEN;
 extern BOOL WineEngInit(void) DECLSPEC_HIDDEN;
 extern BOOL WineEngRemoveFontResourceEx(LPCWSTR, DWORD, PVOID) DECLSPEC_HIDDEN;
+extern BOOL WineEngRemoveFontMemResourceEx(HANDLE) DECLSPEC_HIDDEN;
 
 /* gdiobj.c */
 extern HGDIOBJ alloc_gdi_handle( GDIOBJHDR *obj, WORD type, const struct gdi_obj_funcs *funcs ) DECLSPEC_HIDDEN;
-- 
1.7.10




More information about the wine-patches mailing list