[GDIPLUS] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / dll / win32 / gdiplus / font.c
index 5630972..399595f 100644 (file)
@@ -163,7 +163,7 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
 
     if (!ret) return NotTrueTypeFont;
 
-    *font = GdipAlloc(sizeof(GpFont));
+    *font = heap_alloc_zero(sizeof(GpFont));
     if (!*font) return OutOfMemory;
 
     (*font)->unit = unit;
@@ -173,7 +173,7 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
     stat = clone_font_family(fontFamily, &(*font)->family);
     if (stat != Ok)
     {
-        GdipFree(*font);
+        heap_free(*font);
         return stat;
     }
 
@@ -209,7 +209,7 @@ GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
 
     if (!ret) return NotTrueTypeFont;
 
-    *font = GdipAlloc(sizeof(GpFont));
+    *font = heap_alloc_zero(sizeof(GpFont));
     if (!*font) return OutOfMemory;
 
     (*font)->unit = UnitWorld;
@@ -219,7 +219,7 @@ GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
     stat = GdipCreateFontFamilyFromName(facename, NULL, &(*font)->family);
     if (stat != Ok)
     {
-        GdipFree(*font);
+        heap_free(*font);
         return NotTrueTypeFont;
     }
 
@@ -260,7 +260,7 @@ GpStatus WINGDIPAPI GdipDeleteFont(GpFont* font)
         return InvalidParameter;
 
     GdipDeleteFontFamily(font->family);
-    GdipFree(font);
+    heap_free(font);
 
     return Ok;
 }
@@ -511,12 +511,12 @@ GpStatus WINGDIPAPI GdipCloneFont(GpFont *font, GpFont **cloneFont)
     if(!font || !cloneFont)
         return InvalidParameter;
 
-    *cloneFont = GdipAlloc(sizeof(GpFont));
+    *cloneFont = heap_alloc_zero(sizeof(GpFont));
     if(!*cloneFont)    return OutOfMemory;
 
     **cloneFont = *font;
     stat = GdipCloneFontFamily(font->family, &(*cloneFont)->family);
-    if (stat != Ok) GdipFree(*cloneFont);
+    if (stat != Ok) heap_free(*cloneFont);
 
     return stat;
 }
@@ -615,11 +615,15 @@ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi,
 static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
                             const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
 {
+    const ENUMLOGFONTW *elfW = (const ENUMLOGFONTW *)elf;
+    LOGFONTW *lf = (LOGFONTW *)lParam;
+
     if (type & RASTER_FONTTYPE)
         return 1;
 
-    *(LOGFONTW *)lParam = *elf;
-
+    *lf = *elf;
+    /* replace substituted font name by a real one */
+    lstrcpynW(lf->lfFaceName, elfW->elfFullName, LF_FACESIZE);
     return 0;
 }
 
@@ -641,8 +645,6 @@ static BOOL get_font_metrics(HDC hdc, struct font_metrics *fm)
     otm.otmSize = sizeof(otm);
     if (!GetOutlineTextMetricsW(hdc, otm.otmSize, &otm)) return FALSE;
 
-    GetTextFaceW(hdc, LF_FACESIZE, fm->facename);
-
     fm->em_height = otm.otmEMSquare;
     fm->dpi = GetDeviceCaps(hdc, LOGPIXELSY);
 
@@ -691,6 +693,8 @@ static GpStatus find_installed_font(const WCHAR *name, struct font_metrics *fm)
     {
         HFONT hfont, old_font;
 
+        strcpyW(fm->facename, lf.lfFaceName);
+
         hfont = CreateFontIndirectW(&lf);
         old_font = SelectObject(hdc, hfont);
         ret = get_font_metrics(hdc, fm) ? Ok : NotTrueTypeFont;
@@ -740,7 +744,7 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
     stat = find_installed_font(name, &fm);
     if (stat != Ok) return stat;
 
-    ffamily = GdipAlloc(sizeof (GpFontFamily));
+    ffamily = heap_alloc_zero(sizeof (GpFontFamily));
     if (!ffamily) return OutOfMemory;
 
     lstrcpyW(ffamily->FamilyName, fm.facename);
@@ -759,7 +763,7 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
 
 static GpStatus clone_font_family(const GpFontFamily *family, GpFontFamily **clone)
 {
-    *clone = GdipAlloc(sizeof(GpFontFamily));
+    *clone = heap_alloc_zero(sizeof(GpFontFamily));
     if (!*clone) return OutOfMemory;
 
     **clone = *family;
@@ -851,7 +855,7 @@ GpStatus WINGDIPAPI GdipDeleteFontFamily(GpFontFamily *FontFamily)
         return InvalidParameter;
     TRACE("Deleting %p (%s)\n", FontFamily, debugstr_w(FontFamily->FamilyName));
 
-    GdipFree (FontFamily);
+    heap_free (FontFamily);
 
     return Ok;
 }
@@ -1079,7 +1083,7 @@ GpStatus WINGDIPAPI GdipNewPrivateFontCollection(GpFontCollection** fontCollecti
     if (!fontCollection)
         return InvalidParameter;
 
-    *fontCollection = GdipAlloc(sizeof(GpFontCollection));
+    *fontCollection = heap_alloc_zero(sizeof(GpFontCollection));
     if (!*fontCollection) return OutOfMemory;
 
     (*fontCollection)->FontFamilies = NULL;
@@ -1103,8 +1107,8 @@ GpStatus WINGDIPAPI GdipDeletePrivateFontCollection(GpFontCollection **fontColle
     if (!fontCollection)
         return InvalidParameter;
 
-    for (i = 0; i < (*fontCollection)->count; i++) GdipFree((*fontCollection)->FontFamilies[i]);
-    GdipFree(*fontCollection);
+    for (i = 0; i < (*fontCollection)->count; i++) heap_free((*fontCollection)->FontFamilies[i]);
+    heap_free(*fontCollection);
 
     return Ok;
 }
@@ -1571,7 +1575,7 @@ void free_installed_fonts(void)
 {
     while (installedFontCollection.count)
         GdipDeleteFontFamily(installedFontCollection.FontFamilies[--installedFontCollection.count]);
-    HeapFree(GetProcessHeap(), 0, installedFontCollection.FontFamilies);
+    heap_free(installedFontCollection.FontFamilies);
     installedFontCollection.FontFamilies = NULL;
     installedFontCollection.allocated = 0;
 }
@@ -1593,13 +1597,13 @@ static INT CALLBACK add_font_proc(const LOGFONTW *lfw, const TEXTMETRICW *ntm,
     if (fonts->allocated == fonts->count)
     {
         INT new_alloc_count = fonts->allocated+50;
-        GpFontFamily** new_family_list = HeapAlloc(GetProcessHeap(), 0, new_alloc_count*sizeof(void*));
+        GpFontFamily** new_family_list = heap_alloc(new_alloc_count*sizeof(void*));
 
         if (!new_family_list)
             return 0;
 
         memcpy(new_family_list, fonts->FontFamilies, fonts->count*sizeof(void*));
-        HeapFree(GetProcessHeap(), 0, fonts->FontFamilies);
+        heap_free(fonts->FontFamilies);
         fonts->FontFamilies = new_family_list;
         fonts->allocated = new_alloc_count;
     }