2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 WINE_DEFAULT_DEBUG_CHANNEL (gdiplus);
34 #include "gdiplus_private.h"
36 static const REAL mm_per_inch = 25.4;
37 static const REAL inch_per_point = 1.0/72.0;
39 static GpFontCollection installedFontCollection = {0};
41 static inline REAL get_dpi (void)
46 GdipCreateFromHDC (hdc, &graphics);
47 GdipGetDpiX(graphics, &dpi);
48 GdipDeleteGraphics(graphics);
54 static inline REAL point_to_pixel (REAL point)
56 return point * get_dpi() * inch_per_point;
59 static inline REAL inch_to_pixel (REAL inch)
61 return inch * get_dpi();
64 static inline REAL document_to_pixel (REAL doc)
66 return doc * (get_dpi() / 300.0); /* Per MSDN */
69 static inline REAL mm_to_pixel (REAL mm)
71 return mm * (get_dpi() / mm_per_inch);
74 /*******************************************************************************
75 * GdipCreateFont [GDIPLUS.@]
77 * Create a new font based off of a FontFamily
80 * *fontFamily [I] Family to base the font off of
81 * emSize [I] Size of the font
82 * style [I] Bitwise OR of FontStyle enumeration
83 * unit [I] Unit emSize is measured in
84 * **font [I] the resulting Font object
88 * FAILURE: InvalidParameter if fontfamily or font is NULL.
89 * FAILURE: FontFamilyNotFound if an invalid FontFamily is given
92 * UnitDisplay is unsupported.
93 * emSize is stored separately from lfHeight, to hold the fraction.
95 GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
96 REAL emSize, INT style, Unit unit, GpFont **font)
98 WCHAR facename[LF_FACESIZE];
100 const NEWTEXTMETRICW* tmw;
103 if (!fontFamily || !font)
104 return InvalidParameter;
106 TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily,
107 debugstr_w(fontFamily->FamilyName), emSize, style, unit, font);
109 stat = GdipGetFamilyName (fontFamily, facename, 0);
110 if (stat != Ok) return stat;
111 *font = GdipAlloc(sizeof(GpFont));
113 tmw = &fontFamily->tmw;
114 lfw = &((*font)->lfw);
115 ZeroMemory(&(*lfw), sizeof(*lfw));
117 lfw->lfWeight = tmw->tmWeight;
118 lfw->lfItalic = tmw->tmItalic;
119 lfw->lfUnderline = tmw->tmUnderlined;
120 lfw->lfStrikeOut = tmw->tmStruckOut;
121 lfw->lfCharSet = tmw->tmCharSet;
122 lfw->lfPitchAndFamily = tmw->tmPitchAndFamily;
123 lstrcpynW(lfw->lfFaceName, facename, LF_FACESIZE);
128 /* FIXME: Figure out when World != Pixel */
129 lfw->lfHeight = emSize; break;
131 FIXME("Unknown behavior for UnitDisplay! Please report!\n");
132 /* FIXME: Figure out how this works...
133 * MSDN says that if "DISPLAY" is a monitor, then pixel should be
134 * used. That's not what I got. Tests on Windows revealed no output,
135 * and the tests in tests/font crash windows */
136 lfw->lfHeight = 0; break;
138 lfw->lfHeight = emSize; break;
140 lfw->lfHeight = point_to_pixel(emSize); break;
142 lfw->lfHeight = inch_to_pixel(emSize); break;
144 lfw->lfHeight = document_to_pixel(emSize); break;
146 lfw->lfHeight = mm_to_pixel(emSize); break;
151 lfw->lfWeight = style & FontStyleBold ? 700 : 400;
152 lfw->lfItalic = style & FontStyleItalic;
153 lfw->lfUnderline = style & FontStyleUnderline;
154 lfw->lfStrikeOut = style & FontStyleStrikeout;
156 (*font)->unit = unit;
157 (*font)->emSize = emSize;
158 (*font)->height = tmw->ntmSizeEM;
159 (*font)->line_spacing = tmw->tmAscent + tmw->tmDescent + tmw->tmExternalLeading;
161 TRACE("<-- %p\n", *font);
166 /*******************************************************************************
167 * GdipCreateFontFromLogfontW [GDIPLUS.@]
169 GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
170 GDIPCONST LOGFONTW *logfont, GpFont **font)
172 HFONT hfont, oldfont;
175 TRACE("(%p, %p, %p)\n", hdc, logfont, font);
177 if(!logfont || !font)
178 return InvalidParameter;
180 if (logfont->lfFaceName[0] == 0)
181 return NotTrueTypeFont;
183 *font = GdipAlloc(sizeof(GpFont));
184 if(!*font) return OutOfMemory;
186 memcpy((*font)->lfw.lfFaceName, logfont->lfFaceName, LF_FACESIZE *
188 (*font)->lfw.lfHeight = logfont->lfHeight;
189 (*font)->lfw.lfItalic = logfont->lfItalic;
190 (*font)->lfw.lfUnderline = logfont->lfUnderline;
191 (*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
193 (*font)->emSize = logfont->lfHeight;
194 (*font)->unit = UnitPixel;
196 hfont = CreateFontIndirectW(&(*font)->lfw);
197 oldfont = SelectObject(hdc, hfont);
198 GetTextMetricsW(hdc, &textmet);
200 (*font)->lfw.lfHeight = -(textmet.tmHeight-textmet.tmInternalLeading);
201 (*font)->lfw.lfWeight = textmet.tmWeight;
202 (*font)->lfw.lfCharSet = textmet.tmCharSet;
204 (*font)->height = 1; /* FIXME: need NEWTEXTMETRIC.ntmSizeEM here */
205 (*font)->line_spacing = textmet.tmAscent + textmet.tmDescent + textmet.tmExternalLeading;
207 SelectObject(hdc, oldfont);
210 TRACE("<-- %p\n", *font);
215 /*******************************************************************************
216 * GdipCreateFontFromLogfontA [GDIPLUS.@]
218 GpStatus WINGDIPAPI GdipCreateFontFromLogfontA(HDC hdc,
219 GDIPCONST LOGFONTA *lfa, GpFont **font)
223 TRACE("(%p, %p, %p)\n", hdc, lfa, font);
226 return InvalidParameter;
228 memcpy(&lfw, lfa, FIELD_OFFSET(LOGFONTA,lfFaceName) );
230 if(!MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE))
233 return GdipCreateFontFromLogfontW(hdc, &lfw, font);
236 /*******************************************************************************
237 * GdipDeleteFont [GDIPLUS.@]
239 GpStatus WINGDIPAPI GdipDeleteFont(GpFont* font)
241 TRACE("(%p)\n", font);
244 return InvalidParameter;
251 /*******************************************************************************
252 * GdipCreateFontFromDC [GDIPLUS.@]
254 GpStatus WINGDIPAPI GdipCreateFontFromDC(HDC hdc, GpFont **font)
259 TRACE("(%p, %p)\n", hdc, font);
262 return InvalidParameter;
264 hfont = GetCurrentObject(hdc, OBJ_FONT);
268 if(!GetObjectW(hfont, sizeof(LOGFONTW), &lfw))
271 return GdipCreateFontFromLogfontW(hdc, &lfw, font);
274 /*******************************************************************************
275 * GdipGetFamily [GDIPLUS.@]
277 * Returns the FontFamily for the specified Font
280 * font [I] Font to request from
281 * family [O] Resulting FontFamily object
285 * FAILURE: An element of GpStatus
287 GpStatus WINGDIPAPI GdipGetFamily(GpFont *font, GpFontFamily **family)
289 TRACE("%p %p\n", font, family);
291 if (!(font && family))
292 return InvalidParameter;
294 return GdipCreateFontFamilyFromName(font->lfw.lfFaceName, NULL, family);
297 /******************************************************************************
298 * GdipGetFontSize [GDIPLUS.@]
300 * Returns the size of the font in Units
303 * *font [I] The font to retrieve size from
304 * *size [O] Pointer to hold retrieved value
308 * FAILURE: InvalidParameter (font or size was NULL)
311 * Size returned is actually emSize -- not internal size used for drawing.
313 GpStatus WINGDIPAPI GdipGetFontSize(GpFont *font, REAL *size)
315 TRACE("(%p, %p)\n", font, size);
317 if (!(font && size)) return InvalidParameter;
319 *size = font->emSize;
324 /*******************************************************************************
325 * GdipGetFontStyle [GDIPLUS.@]
327 * Gets the font's style, returned in bitwise OR of FontStyle enumeration
330 * font [I] font to request from
331 * style [O] resulting pointer to a FontStyle enumeration
335 * FAILURE: InvalidParameter
337 GpStatus WINGDIPAPI GdipGetFontStyle(GpFont *font, INT *style)
339 TRACE("%p %p\n", font, style);
341 if (!(font && style))
342 return InvalidParameter;
344 if (font->lfw.lfWeight > 400)
345 *style = FontStyleBold;
348 if (font->lfw.lfItalic)
349 *style |= FontStyleItalic;
350 if (font->lfw.lfUnderline)
351 *style |= FontStyleUnderline;
352 if (font->lfw.lfStrikeOut)
353 *style |= FontStyleStrikeout;
358 /*******************************************************************************
359 * GdipGetFontUnit [GDIPLUS.@]
362 * font [I] Font to retrieve from
363 * unit [O] Return value
366 * FAILURE: font or unit was NULL
369 GpStatus WINGDIPAPI GdipGetFontUnit(GpFont *font, Unit *unit)
371 TRACE("(%p, %p)\n", font, unit);
373 if (!(font && unit)) return InvalidParameter;
380 /*******************************************************************************
381 * GdipGetLogFontA [GDIPLUS.@]
383 GpStatus WINGDIPAPI GdipGetLogFontA(GpFont *font, GpGraphics *graphics,
389 TRACE("(%p, %p, %p)\n", font, graphics, lfa);
391 status = GdipGetLogFontW(font, graphics, &lfw);
395 memcpy(lfa, &lfw, FIELD_OFFSET(LOGFONTA,lfFaceName) );
397 if(!WideCharToMultiByte(CP_ACP, 0, lfw.lfFaceName, -1, lfa->lfFaceName, LF_FACESIZE, NULL, NULL))
403 /*******************************************************************************
404 * GdipGetLogFontW [GDIPLUS.@]
406 GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
409 TRACE("(%p, %p, %p)\n", font, graphics, lfw);
411 /* FIXME: use graphics */
412 if(!font || !graphics || !lfw)
413 return InvalidParameter;
420 /*******************************************************************************
421 * GdipCloneFont [GDIPLUS.@]
423 GpStatus WINGDIPAPI GdipCloneFont(GpFont *font, GpFont **cloneFont)
425 TRACE("(%p, %p)\n", font, cloneFont);
427 if(!font || !cloneFont)
428 return InvalidParameter;
430 *cloneFont = GdipAlloc(sizeof(GpFont));
431 if(!*cloneFont) return OutOfMemory;
438 /*******************************************************************************
439 * GdipGetFontHeight [GDIPLUS.@]
441 * font [I] Font to retrieve height from
442 * graphics [I] The current graphics context
443 * height [O] Resulting height
446 * FAILURE: Another element of GpStatus
449 * Forwards to GdipGetFontHeightGivenDPI
451 GpStatus WINGDIPAPI GdipGetFontHeight(GDIPCONST GpFont *font,
452 GDIPCONST GpGraphics *graphics, REAL *height)
457 TRACE("%p %p %p\n", font, graphics, height);
459 stat = GdipGetDpiY((GpGraphics*)graphics, &dpi);
462 stat = GdipGetFontHeightGivenDPI(font, dpi, height);
467 /*******************************************************************************
468 * GdipGetFontHeightGivenDPI [GDIPLUS.@]
470 * font [I] Font to retrieve DPI from
471 * dpi [I] DPI to assume
472 * height [O] Return value
476 * FAILURE: InvalidParameter if font or height is NULL
479 * According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
480 * (for anything other than unit Pixel)
482 GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
486 TRACE("%p (%s), %f, %p\n", font,
487 debugstr_w(font->lfw.lfFaceName), dpi, height);
489 if (!(font && height)) return InvalidParameter;
491 font_height = font->line_spacing * (font->emSize / font->height);
497 *height = font_height;
500 *height = font_height * dpi * inch_per_point;
503 *height = font_height * dpi;
506 *height = font_height * (dpi / 300.0);
509 *height = font_height * (dpi / mm_per_inch);
512 FIXME("Unhandled unit type: %d\n", font->unit);
513 return NotImplemented;
519 /***********************************************************************
520 * Borrowed from GDI32:
522 * Elf is really an ENUMLOGFONTEXW, and ntm is a NEWTEXTMETRICEXW.
523 * We have to use other types because of the FONTENUMPROCW definition.
525 static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
526 const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
528 if (!ntm || type == RASTER_FONTTYPE)
533 *(NEWTEXTMETRICW*)lParam = *(const NEWTEXTMETRICW*)ntm;
538 static BOOL find_installed_font(const WCHAR *name, NEWTEXTMETRICW *ntm)
543 if(!EnumFontFamiliesW(hdc, name, is_font_installed_proc, (LPARAM)ntm))
550 /*******************************************************************************
551 * GdipCreateFontFamilyFromName [GDIPLUS.@]
553 * Creates a font family object based on a supplied name
556 * name [I] Name of the font
557 * fontCollection [I] What font collection (if any) the font belongs to (may be NULL)
558 * FontFamily [O] Pointer to the resulting FontFamily object
562 * FAILURE: FamilyNotFound if the requested FontFamily does not exist on the system
563 * FAILURE: Invalid parameter if FontFamily or name is NULL
566 * If fontCollection is NULL then the object is not part of any collection
570 GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
571 GpFontCollection *fontCollection,
572 GpFontFamily **FontFamily)
574 GpFontFamily* ffamily;
577 TRACE("%s, %p %p\n", debugstr_w(name), fontCollection, FontFamily);
579 if (!(name && FontFamily))
580 return InvalidParameter;
582 FIXME("No support for FontCollections yet!\n");
584 if (!find_installed_font(name, &ntm))
585 return FontFamilyNotFound;
587 ffamily = GdipAlloc(sizeof (GpFontFamily));
588 if (!ffamily) return OutOfMemory;
591 lstrcpynW(ffamily->FamilyName, name, LF_FACESIZE);
593 *FontFamily = ffamily;
595 TRACE("<-- %p\n", ffamily);
600 /*******************************************************************************
601 * GdipCloneFontFamily [GDIPLUS.@]
603 * Creates a deep copy of a Font Family object
606 * FontFamily [I] Font to clone
607 * clonedFontFamily [O] The resulting cloned font
612 GpStatus WINGDIPAPI GdipCloneFontFamily(GpFontFamily* FontFamily, GpFontFamily** clonedFontFamily)
614 if (!(FontFamily && clonedFontFamily)) return InvalidParameter;
616 TRACE("stub: %p (%s), %p\n", FontFamily,
617 debugstr_w(FontFamily->FamilyName), clonedFontFamily);
619 *clonedFontFamily = GdipAlloc(sizeof(GpFontFamily));
620 if (!*clonedFontFamily) return OutOfMemory;
622 (*clonedFontFamily)->tmw = FontFamily->tmw;
623 lstrcpyW((*clonedFontFamily)->FamilyName, FontFamily->FamilyName);
625 TRACE("<-- %p\n", *clonedFontFamily);
630 /*******************************************************************************
631 * GdipGetFamilyName [GDIPLUS.@]
633 * Returns the family name into name
636 * *family [I] Family to retrieve from
637 * *name [O] WCHARS of the family name
642 * FAILURE: InvalidParameter if family is NULL
645 * If name is a NULL ptr, then both XP and Vista will crash (so we do as well)
647 GpStatus WINGDIPAPI GdipGetFamilyName (GDIPCONST GpFontFamily *family,
648 WCHAR *name, LANGID language)
650 static int lang_fixme;
653 return InvalidParameter;
655 TRACE("%p, %p, %d\n", family, name, language);
657 if (language != LANG_NEUTRAL && !lang_fixme++)
658 FIXME("No support for handling of multiple languages!\n");
660 lstrcpynW (name, family->FamilyName, LF_FACESIZE);
666 /*****************************************************************************
667 * GdipDeleteFontFamily [GDIPLUS.@]
669 * Removes the specified FontFamily
672 * *FontFamily [I] The family to delete
676 * FAILURE: InvalidParameter if FontFamily is NULL.
679 GpStatus WINGDIPAPI GdipDeleteFontFamily(GpFontFamily *FontFamily)
682 return InvalidParameter;
683 TRACE("Deleting %p (%s)\n", FontFamily, debugstr_w(FontFamily->FamilyName));
685 GdipFree (FontFamily);
690 GpStatus WINGDIPAPI GdipGetCellAscent(GDIPCONST GpFontFamily *family,
691 INT style, UINT16* CellAscent)
693 if (!(family && CellAscent)) return InvalidParameter;
695 *CellAscent = family->tmw.tmAscent;
700 GpStatus WINGDIPAPI GdipGetCellDescent(GDIPCONST GpFontFamily *family,
701 INT style, UINT16* CellDescent)
703 TRACE("(%p, %d, %p)\n", family, style, CellDescent);
705 if (!(family && CellDescent)) return InvalidParameter;
707 *CellDescent = family->tmw.tmDescent;
712 /*******************************************************************************
713 * GdipGetEmHeight [GDIPLUS.@]
715 * Gets the height of the specified family in EmHeights
718 * family [I] Family to retrieve from
719 * style [I] (optional) style
720 * EmHeight [O] return value
724 * FAILURE: InvalidParameter
726 GpStatus WINGDIPAPI GdipGetEmHeight(GDIPCONST GpFontFamily *family, INT style, UINT16* EmHeight)
728 if (!(family && EmHeight)) return InvalidParameter;
730 TRACE("%p (%s), %d, %p\n", family, debugstr_w(family->FamilyName), style, EmHeight);
732 *EmHeight = family->tmw.ntmSizeEM;
738 /*******************************************************************************
739 * GdipGetLineSpacing [GDIPLUS.@]
741 * Returns the line spacing in design units
744 * family [I] Family to retrieve from
745 * style [I] (Optional) font style
746 * LineSpacing [O] Return value
750 * FAILURE: InvalidParameter (family or LineSpacing was NULL)
752 GpStatus WINGDIPAPI GdipGetLineSpacing(GDIPCONST GpFontFamily *family,
753 INT style, UINT16* LineSpacing)
755 TRACE("%p, %d, %p\n", family, style, LineSpacing);
757 if (!(family && LineSpacing))
758 return InvalidParameter;
760 if (style) FIXME("ignoring style\n");
762 *LineSpacing = family->tmw.tmAscent + family->tmw.tmDescent + family->tmw.tmExternalLeading;
767 static INT CALLBACK font_has_style_proc(const LOGFONTW *elf,
768 const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
774 if (ntm->tmWeight >= FW_BOLD) fontstyle |= FontStyleBold;
775 if (ntm->tmItalic) fontstyle |= FontStyleItalic;
776 if (ntm->tmUnderlined) fontstyle |= FontStyleUnderline;
777 if (ntm->tmStruckOut) fontstyle |= FontStyleStrikeout;
779 return (INT)lParam != fontstyle;
782 GpStatus WINGDIPAPI GdipIsStyleAvailable(GDIPCONST GpFontFamily* family,
783 INT style, BOOL* IsStyleAvailable)
787 TRACE("%p %d %p\n", family, style, IsStyleAvailable);
789 if (!(family && IsStyleAvailable))
790 return InvalidParameter;
792 *IsStyleAvailable = FALSE;
796 if(!EnumFontFamiliesW(hdc, family->FamilyName, font_has_style_proc, (LPARAM)style))
797 *IsStyleAvailable = TRUE;
804 /*****************************************************************************
805 * GdipGetGenericFontFamilyMonospace [GDIPLUS.@]
807 * Obtains a serif family (Courier New on Windows)
810 * **nativeFamily [I] Where the font will be stored
813 * InvalidParameter if nativeFamily is NULL.
816 GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily)
818 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
820 if (nativeFamily == NULL) return InvalidParameter;
822 return GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily);
825 /*****************************************************************************
826 * GdipGetGenericFontFamilySerif [GDIPLUS.@]
828 * Obtains a serif family (Times New Roman on Windows)
831 * **nativeFamily [I] Where the font will be stored
834 * InvalidParameter if nativeFamily is NULL.
837 GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily)
839 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
841 TRACE("(%p)\n", nativeFamily);
843 if (nativeFamily == NULL) return InvalidParameter;
845 return GdipCreateFontFamilyFromName(TimesNewRoman, NULL, nativeFamily);
848 /*****************************************************************************
849 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
851 * Obtains a serif family (Microsoft Sans Serif on Windows)
854 * **nativeFamily [I] Where the font will be stored
857 * InvalidParameter if nativeFamily is NULL.
860 GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily)
863 static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
864 static const WCHAR Tahoma[] = {'T','a','h','o','m','a','\0'};
866 TRACE("(%p)\n", nativeFamily);
868 if (nativeFamily == NULL) return InvalidParameter;
870 stat = GdipCreateFontFamilyFromName(MicrosoftSansSerif, NULL, nativeFamily);
872 if (stat == FontFamilyNotFound)
873 /* FIXME: Microsoft Sans Serif is not installed on Wine. */
874 stat = GdipCreateFontFamilyFromName(Tahoma, NULL, nativeFamily);
879 /*****************************************************************************
880 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
882 GpStatus WINGDIPAPI GdipNewPrivateFontCollection(GpFontCollection** fontCollection)
884 TRACE("%p\n", fontCollection);
887 return InvalidParameter;
889 *fontCollection = GdipAlloc(sizeof(GpFontCollection));
890 if (!*fontCollection) return OutOfMemory;
892 (*fontCollection)->FontFamilies = NULL;
893 (*fontCollection)->count = 0;
894 (*fontCollection)->allocated = 0;
896 TRACE("<-- %p\n", *fontCollection);
901 /*****************************************************************************
902 * GdipDeletePrivateFontCollection [GDIPLUS.@]
904 GpStatus WINGDIPAPI GdipDeletePrivateFontCollection(GpFontCollection **fontCollection)
908 TRACE("%p\n", fontCollection);
911 return InvalidParameter;
913 for (i = 0; i < (*fontCollection)->count; i++) GdipFree((*fontCollection)->FontFamilies[i]);
914 GdipFree(*fontCollection);
919 /*****************************************************************************
920 * GdipPrivateAddFontFile [GDIPLUS.@]
922 GpStatus WINGDIPAPI GdipPrivateAddFontFile(GpFontCollection* fontCollection,
923 GDIPCONST WCHAR* filename)
925 FIXME("stub: %p, %s\n", fontCollection, debugstr_w(filename));
927 if (!(fontCollection && filename))
928 return InvalidParameter;
930 return NotImplemented;
933 /*****************************************************************************
934 * GdipPrivateAddMemoryFont [GDIPLUS.@]
936 GpStatus WINGDIPAPI GdipPrivateAddMemoryFont(GpFontCollection* fontCollection,
937 GDIPCONST void* memory, INT length)
939 FIXME("%p, %p, %d\n", fontCollection, memory, length);
941 if (!(fontCollection && memory && length))
942 return InvalidParameter;
947 /*****************************************************************************
948 * GdipGetFontCollectionFamilyCount [GDIPLUS.@]
950 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyCount(
951 GpFontCollection* fontCollection, INT* numFound)
953 TRACE("%p, %p\n", fontCollection, numFound);
955 if (!(fontCollection && numFound))
956 return InvalidParameter;
958 *numFound = fontCollection->count;
962 /*****************************************************************************
963 * GdipGetFontCollectionFamilyList [GDIPLUS.@]
965 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyList(
966 GpFontCollection* fontCollection, INT numSought,
967 GpFontFamily* gpfamilies[], INT* numFound)
972 TRACE("%p, %d, %p, %p\n", fontCollection, numSought, gpfamilies, numFound);
974 if (!(fontCollection && gpfamilies && numFound))
975 return InvalidParameter;
977 memset(gpfamilies, 0, sizeof(*gpfamilies) * numSought);
979 for (i = 0; i < numSought && i < fontCollection->count && stat == Ok; i++)
981 stat = GdipCloneFontFamily(fontCollection->FontFamilies[i], &gpfamilies[i]);
989 for (i=0; i<numToFree; i++)
991 GdipDeleteFontFamily(gpfamilies[i]);
992 gpfamilies[i] = NULL;
999 void free_installed_fonts(void)
1001 while (installedFontCollection.count)
1002 GdipDeleteFontFamily(installedFontCollection.FontFamilies[--installedFontCollection.count]);
1003 HeapFree(GetProcessHeap(), 0, installedFontCollection.FontFamilies);
1004 installedFontCollection.FontFamilies = NULL;
1005 installedFontCollection.allocated = 0;
1008 static INT CALLBACK add_font_proc(const LOGFONTW *lfw, const TEXTMETRICW *ntm,
1009 DWORD type, LPARAM lParam)
1011 GpFontCollection* fonts = (GpFontCollection*)lParam;
1014 if (type == RASTER_FONTTYPE)
1017 /* skip duplicates */
1018 for (i=0; i<fonts->count; i++)
1019 if (strcmpiW(lfw->lfFaceName, fonts->FontFamilies[i]->FamilyName) == 0)
1022 if (fonts->allocated == fonts->count)
1024 INT new_alloc_count = fonts->allocated+50;
1025 GpFontFamily** new_family_list = HeapAlloc(GetProcessHeap(), 0, new_alloc_count*sizeof(void*));
1027 if (!new_family_list)
1030 memcpy(new_family_list, fonts->FontFamilies, fonts->count*sizeof(void*));
1031 HeapFree(GetProcessHeap(), 0, fonts->FontFamilies);
1032 fonts->FontFamilies = new_family_list;
1033 fonts->allocated = new_alloc_count;
1036 if (GdipCreateFontFamilyFromName(lfw->lfFaceName, NULL, &fonts->FontFamilies[fonts->count]) == Ok)
1044 GpStatus WINGDIPAPI GdipNewInstalledFontCollection(
1045 GpFontCollection** fontCollection)
1047 TRACE("(%p)\n",fontCollection);
1049 if (!fontCollection)
1050 return InvalidParameter;
1052 if (installedFontCollection.count == 0)
1059 lfw.lfCharSet = DEFAULT_CHARSET;
1060 lfw.lfFaceName[0] = 0;
1061 lfw.lfPitchAndFamily = 0;
1063 if (!EnumFontFamiliesExW(hdc, &lfw, add_font_proc, (LPARAM)&installedFontCollection, 0))
1065 free_installed_fonts();
1073 *fontCollection = &installedFontCollection;