Alexandre Julliard : gdi32: Increment the face refcount when loading the same font file multiple times .

Alexandre Julliard julliard at winehq.org
Mon Mar 4 13:23:39 CST 2013


Module: wine
Branch: master
Commit: 591a31ba67ba1fcf8baea702b6460868ab3522e8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=591a31ba67ba1fcf8baea702b6460868ab3522e8

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Mar  4 11:35:50 2013 +0100

gdi32: Increment the face refcount when loading the same font file multiple times.

---

 dlls/gdi32/freetype.c   |    7 +++++++
 dlls/gdi32/tests/font.c |   17 +++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 5b10d0d..a452fa0 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1304,6 +1304,13 @@ static BOOL insert_face_in_family_list( Face *face, Family *family )
                   debugstr_w(family->FamilyName), debugstr_w(face->StyleName),
                   cursor->font_version, face->font_version);
 
+            if (face->file && face->dev == cursor->dev && face->ino == cursor->ino)
+            {
+                cursor->refcount++;
+                TRACE("Font %s already in list, refcount now %d\n",
+                      debugstr_w(face->file), cursor->refcount);
+                return FALSE;
+            }
             if (face->font_version <= cursor->font_version)
             {
                 TRACE("Original font %s is newer so skipping %s\n",
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index b72a423..aa94dea 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -4567,6 +4567,7 @@ static void test_CreateScalableFontResource(void)
     char fot_name[MAX_PATH];
     char *file_part;
     DWORD ret;
+    int i;
 
     if (!pAddFontResourceExA || !pRemoveFontResourceExA)
     {
@@ -4655,6 +4656,22 @@ static void test_CreateScalableFontResource(void)
     ret = pRemoveFontResourceExA(fot_name, 0, 0);
     ok(!ret, "RemoveFontResourceEx() should fail\n");
 
+    /* test refcounting */
+    for (i = 0; i < 5; i++)
+    {
+        SetLastError(0xdeadbeef);
+        ret = pAddFontResourceExA(fot_name, 0, 0);
+        ok(ret, "AddFontResourceEx() error %d\n", GetLastError());
+    }
+    for (i = 0; i < 5; i++)
+    {
+        SetLastError(0xdeadbeef);
+        ret = pRemoveFontResourceExA(fot_name, 0, 0);
+        ok(ret, "RemoveFontResourceEx() error %d\n", GetLastError());
+    }
+    ret = pRemoveFontResourceExA(fot_name, 0, 0);
+    ok(!ret, "RemoveFontResourceEx() should fail\n");
+
     DeleteFile(fot_name);
 
     /* test hidden font resource */




More information about the wine-cvs mailing list