From 591a31ba67ba1fcf8baea702b6460868ab3522e8 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 4 Mar 2013 11:35:50 +0100 Subject: [PATCH] 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(+) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 5b10d0d9cc0..a452fa0c7b3 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 b72a423db32..aa94dea828b 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 */