- Sync gdiplus with Wine head
[reactos.git] / reactos / dll / win32 / gdiplus / font.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winnls.h"
25 #include "winreg.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL (gdiplus);
30
31 #include "objbase.h"
32
33 #include "gdiplus.h"
34 #include "gdiplus_private.h"
35
36 static const REAL mm_per_inch = 25.4;
37 static const REAL inch_per_point = 1.0/72.0;
38
39 static inline REAL get_dpi (void)
40 {
41 REAL dpi;
42 GpGraphics *graphics;
43 HDC hdc = GetDC(0);
44 GdipCreateFromHDC (hdc, &graphics);
45 GdipGetDpiX(graphics, &dpi);
46 GdipDeleteGraphics(graphics);
47 ReleaseDC (0, hdc);
48
49 return dpi;
50 }
51
52 static inline REAL point_to_pixel (REAL point)
53 {
54 return point * get_dpi() * inch_per_point;
55 }
56
57 static inline REAL inch_to_pixel (REAL inch)
58 {
59 return inch * get_dpi();
60 }
61
62 static inline REAL document_to_pixel (REAL doc)
63 {
64 return doc * (get_dpi() / 300.0); /* Per MSDN */
65 }
66
67 static inline REAL mm_to_pixel (REAL mm)
68 {
69 return mm * (get_dpi() / mm_per_inch);
70 }
71
72 /*******************************************************************************
73 * GdipCreateFont [GDIPLUS.@]
74 *
75 * Create a new font based off of a FontFamily
76 *
77 * PARAMS
78 * *fontFamily [I] Family to base the font off of
79 * emSize [I] Size of the font
80 * style [I] Bitwise OR of FontStyle enumeration
81 * unit [I] Unit emSize is measured in
82 * **font [I] the resulting Font object
83 *
84 * RETURNS
85 * SUCCESS: Ok
86 * FAILURE: InvalidParameter if fontfamily or font is NULL.
87 * FAILURE: FontFamilyNotFound if an invalid FontFamily is given
88 *
89 * NOTES
90 * UnitDisplay is unsupported.
91 * emSize is stored separately from lfHeight, to hold the fraction.
92 */
93 GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
94 REAL emSize, INT style, Unit unit, GpFont **font)
95 {
96 WCHAR facename[LF_FACESIZE];
97 LOGFONTW* lfw;
98 const NEWTEXTMETRICW* tmw;
99 GpStatus stat;
100
101 if (!fontFamily || !font)
102 return InvalidParameter;
103
104 TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily,
105 debugstr_w(fontFamily->FamilyName), emSize, style, unit, font);
106
107 stat = GdipGetFamilyName (fontFamily, facename, 0);
108 if (stat != Ok) return stat;
109 *font = GdipAlloc(sizeof(GpFont));
110
111 tmw = &fontFamily->tmw;
112 lfw = &((*font)->lfw);
113 ZeroMemory(&(*lfw), sizeof(*lfw));
114
115 lfw->lfWeight = tmw->tmWeight;
116 lfw->lfItalic = tmw->tmItalic;
117 lfw->lfUnderline = tmw->tmUnderlined;
118 lfw->lfStrikeOut = tmw->tmStruckOut;
119 lfw->lfCharSet = tmw->tmCharSet;
120 lfw->lfPitchAndFamily = tmw->tmPitchAndFamily;
121 lstrcpynW(lfw->lfFaceName, facename, LF_FACESIZE);
122
123 switch (unit)
124 {
125 case UnitWorld:
126 /* FIXME: Figure out when World != Pixel */
127 lfw->lfHeight = emSize; break;
128 case UnitDisplay:
129 FIXME("Unknown behavior for UnitDisplay! Please report!\n");
130 /* FIXME: Figure out how this works...
131 * MSDN says that if "DISPLAY" is a monitor, then pixel should be
132 * used. That's not what I got. Tests on Windows revealed no output,
133 * and the tests in tests/font crash windows */
134 lfw->lfHeight = 0; break;
135 case UnitPixel:
136 lfw->lfHeight = emSize; break;
137 case UnitPoint:
138 lfw->lfHeight = point_to_pixel(emSize); break;
139 case UnitInch:
140 lfw->lfHeight = inch_to_pixel(emSize); break;
141 case UnitDocument:
142 lfw->lfHeight = document_to_pixel(emSize); break;
143 case UnitMillimeter:
144 lfw->lfHeight = mm_to_pixel(emSize); break;
145 }
146
147 lfw->lfHeight *= -1;
148
149 lfw->lfWeight = style & FontStyleBold ? 700 : 400;
150 lfw->lfItalic = style & FontStyleItalic;
151 lfw->lfUnderline = style & FontStyleUnderline;
152 lfw->lfStrikeOut = style & FontStyleStrikeout;
153
154 (*font)->unit = unit;
155 (*font)->emSize = emSize;
156 (*font)->height = tmw->ntmSizeEM;
157 (*font)->line_spacing = tmw->tmAscent + tmw->tmDescent + tmw->tmExternalLeading;
158
159 return Ok;
160 }
161
162 /*******************************************************************************
163 * GdipCreateFontFromLogfontW [GDIPLUS.@]
164 */
165 GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
166 GDIPCONST LOGFONTW *logfont, GpFont **font)
167 {
168 HFONT hfont, oldfont;
169 TEXTMETRICW textmet;
170
171 TRACE("(%p, %p, %p)\n", hdc, logfont, font);
172
173 if(!logfont || !font)
174 return InvalidParameter;
175
176 if (logfont->lfFaceName[0] == 0)
177 return NotTrueTypeFont;
178
179 *font = GdipAlloc(sizeof(GpFont));
180 if(!*font) return OutOfMemory;
181
182 memcpy((*font)->lfw.lfFaceName, logfont->lfFaceName, LF_FACESIZE *
183 sizeof(WCHAR));
184 (*font)->lfw.lfHeight = logfont->lfHeight;
185 (*font)->lfw.lfItalic = logfont->lfItalic;
186 (*font)->lfw.lfUnderline = logfont->lfUnderline;
187 (*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
188
189 (*font)->emSize = logfont->lfHeight;
190 (*font)->unit = UnitPixel;
191
192 hfont = CreateFontIndirectW(&(*font)->lfw);
193 oldfont = SelectObject(hdc, hfont);
194 GetTextMetricsW(hdc, &textmet);
195
196 (*font)->lfw.lfHeight = -textmet.tmHeight;
197 (*font)->lfw.lfWeight = textmet.tmWeight;
198 (*font)->lfw.lfCharSet = textmet.tmCharSet;
199
200 (*font)->height = 1; /* FIXME: need NEWTEXTMETRIC.ntmSizeEM here */
201 (*font)->line_spacing = textmet.tmAscent + textmet.tmDescent + textmet.tmExternalLeading;
202
203 SelectObject(hdc, oldfont);
204 DeleteObject(hfont);
205
206 return Ok;
207 }
208
209 /*******************************************************************************
210 * GdipCreateFontFromLogfontA [GDIPLUS.@]
211 */
212 GpStatus WINGDIPAPI GdipCreateFontFromLogfontA(HDC hdc,
213 GDIPCONST LOGFONTA *lfa, GpFont **font)
214 {
215 LOGFONTW lfw;
216
217 TRACE("(%p, %p, %p)\n", hdc, lfa, font);
218
219 if(!lfa || !font)
220 return InvalidParameter;
221
222 memcpy(&lfw, lfa, FIELD_OFFSET(LOGFONTA,lfFaceName) );
223
224 if(!MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE))
225 return GenericError;
226
227 GdipCreateFontFromLogfontW(hdc, &lfw, font);
228
229 return Ok;
230 }
231
232 /*******************************************************************************
233 * GdipDeleteFont [GDIPLUS.@]
234 */
235 GpStatus WINGDIPAPI GdipDeleteFont(GpFont* font)
236 {
237 TRACE("(%p)\n", font);
238
239 if(!font)
240 return InvalidParameter;
241
242 GdipFree(font);
243
244 return Ok;
245 }
246
247 /*******************************************************************************
248 * GdipCreateFontFromDC [GDIPLUS.@]
249 */
250 GpStatus WINGDIPAPI GdipCreateFontFromDC(HDC hdc, GpFont **font)
251 {
252 HFONT hfont;
253 LOGFONTW lfw;
254
255 TRACE("(%p, %p)\n", hdc, font);
256
257 if(!font)
258 return InvalidParameter;
259
260 hfont = GetCurrentObject(hdc, OBJ_FONT);
261 if(!hfont)
262 return GenericError;
263
264 if(!GetObjectW(hfont, sizeof(LOGFONTW), &lfw))
265 return GenericError;
266
267 return GdipCreateFontFromLogfontW(hdc, &lfw, font);
268 }
269
270 /*******************************************************************************
271 * GdipGetFamily [GDIPLUS.@]
272 *
273 * Returns the FontFamily for the specified Font
274 *
275 * PARAMS
276 * font [I] Font to request from
277 * family [O] Resulting FontFamily object
278 *
279 * RETURNS
280 * SUCCESS: Ok
281 * FAILURE: An element of GpStatus
282 */
283 GpStatus WINGDIPAPI GdipGetFamily(GpFont *font, GpFontFamily **family)
284 {
285 TRACE("%p %p\n", font, family);
286
287 if (!(font && family))
288 return InvalidParameter;
289
290 return GdipCreateFontFamilyFromName(font->lfw.lfFaceName, NULL, family);
291 }
292
293 /******************************************************************************
294 * GdipGetFontSize [GDIPLUS.@]
295 *
296 * Returns the size of the font in Units
297 *
298 * PARAMS
299 * *font [I] The font to retrieve size from
300 * *size [O] Pointer to hold retrieved value
301 *
302 * RETURNS
303 * SUCCESS: Ok
304 * FAILURE: InvalidParamter (font or size was NULL)
305 *
306 * NOTES
307 * Size returned is actually emSize -- not internal size used for drawing.
308 */
309 GpStatus WINGDIPAPI GdipGetFontSize(GpFont *font, REAL *size)
310 {
311 TRACE("(%p, %p)\n", font, size);
312
313 if (!(font && size)) return InvalidParameter;
314
315 *size = font->emSize;
316
317 return Ok;
318 }
319
320 /*******************************************************************************
321 * GdipGetFontStyle [GDIPLUS.@]
322 *
323 * Gets the font's style, returned in bitwise OR of FontStyle enumeration
324 *
325 * PARAMS
326 * font [I] font to request from
327 * style [O] resulting pointer to a FontStyle enumeration
328 *
329 * RETURNS
330 * SUCCESS: Ok
331 * FAILURE: InvalidParameter
332 */
333 GpStatus WINGDIPAPI GdipGetFontStyle(GpFont *font, INT *style)
334 {
335 TRACE("%p %p\n", font, style);
336
337 if (!(font && style))
338 return InvalidParameter;
339
340 if (font->lfw.lfWeight > 400)
341 *style = FontStyleBold;
342 else
343 *style = 0;
344 if (font->lfw.lfItalic)
345 *style |= FontStyleItalic;
346 if (font->lfw.lfUnderline)
347 *style |= FontStyleUnderline;
348 if (font->lfw.lfStrikeOut)
349 *style |= FontStyleStrikeout;
350
351 return Ok;
352 }
353
354 /*******************************************************************************
355 * GdipGetFontUnit [GDIPLUS.@]
356 *
357 * PARAMS
358 * font [I] Font to retrieve from
359 * unit [O] Return value
360 *
361 * RETURNS
362 * FAILURE: font or unit was NULL
363 * OK: otherwise
364 */
365 GpStatus WINGDIPAPI GdipGetFontUnit(GpFont *font, Unit *unit)
366 {
367 TRACE("(%p, %p)\n", font, unit);
368
369 if (!(font && unit)) return InvalidParameter;
370
371 *unit = font->unit;
372
373 return Ok;
374 }
375
376 /*******************************************************************************
377 * GdipGetLogFontW [GDIPLUS.@]
378 */
379 GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
380 LOGFONTW *lfw)
381 {
382 TRACE("(%p, %p, %p)\n", font, graphics, lfw);
383
384 /* FIXME: use graphics */
385 if(!font || !graphics || !lfw)
386 return InvalidParameter;
387
388 *lfw = font->lfw;
389
390 return Ok;
391 }
392
393 /*******************************************************************************
394 * GdipCloneFont [GDIPLUS.@]
395 */
396 GpStatus WINGDIPAPI GdipCloneFont(GpFont *font, GpFont **cloneFont)
397 {
398 TRACE("(%p, %p)\n", font, cloneFont);
399
400 if(!font || !cloneFont)
401 return InvalidParameter;
402
403 *cloneFont = GdipAlloc(sizeof(GpFont));
404 if(!*cloneFont) return OutOfMemory;
405
406 **cloneFont = *font;
407
408 return Ok;
409 }
410
411 /*******************************************************************************
412 * GdipGetFontHeight [GDIPLUS.@]
413 * PARAMS
414 * font [I] Font to retrieve height from
415 * graphics [I] The current graphics context
416 * height [O] Resulting height
417 * RETURNS
418 * SUCCESS: Ok
419 * FAILURE: Another element of GpStatus
420 *
421 * NOTES
422 * Forwards to GdipGetFontHeightGivenDPI
423 */
424 GpStatus WINGDIPAPI GdipGetFontHeight(GDIPCONST GpFont *font,
425 GDIPCONST GpGraphics *graphics, REAL *height)
426 {
427 REAL dpi;
428
429 TRACE("%p %p %p\n", font, graphics, height);
430
431 dpi = GetDeviceCaps(graphics->hdc, LOGPIXELSY);
432
433 return GdipGetFontHeightGivenDPI(font, dpi, height);
434 }
435
436 /*******************************************************************************
437 * GdipGetFontHeightGivenDPI [GDIPLUS.@]
438 * PARAMS
439 * font [I] Font to retrieve DPI from
440 * dpi [I] DPI to assume
441 * height [O] Return value
442 *
443 * RETURNS
444 * SUCCESS: Ok
445 * FAILURE: InvalidParameter if font or height is NULL
446 *
447 * NOTES
448 * According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
449 * (for anything other than unit Pixel)
450 */
451 GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
452 {
453 REAL font_height;
454
455 TRACE("%p (%s), %f, %p\n", font,
456 debugstr_w(font->lfw.lfFaceName), dpi, height);
457
458 if (!(font && height)) return InvalidParameter;
459
460 font_height = font->line_spacing * (font->emSize / font->height);
461
462 switch (font->unit)
463 {
464 case UnitPixel:
465 *height = font_height;
466 break;
467 case UnitPoint:
468 *height = font_height * dpi * inch_per_point;
469 break;
470 case UnitInch:
471 *height = font_height * dpi;
472 break;
473 case UnitDocument:
474 *height = font_height * (dpi / 300.0);
475 break;
476 case UnitMillimeter:
477 *height = font_height * (dpi / mm_per_inch);
478 break;
479 default:
480 FIXME("Unhandled unit type: %d\n", font->unit);
481 return NotImplemented;
482 }
483
484 return Ok;
485 }
486
487 /***********************************************************************
488 * Borrowed from GDI32:
489 *
490 * Elf is really an ENUMLOGFONTEXW, and ntm is a NEWTEXTMETRICEXW.
491 * We have to use other types because of the FONTENUMPROCW definition.
492 */
493 static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
494 const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
495 {
496 if (!ntm)
497 {
498 return 1;
499 }
500
501 *(NEWTEXTMETRICW*)lParam = *(const NEWTEXTMETRICW*)ntm;
502
503 return 0;
504 }
505
506 static BOOL find_installed_font(const WCHAR *name, NEWTEXTMETRICW *ntm)
507 {
508 HDC hdc = GetDC(0);
509 BOOL ret = FALSE;
510
511 if(!EnumFontFamiliesW(hdc, name, is_font_installed_proc, (LPARAM)ntm))
512 ret = TRUE;
513
514 ReleaseDC(0, hdc);
515 return ret;
516 }
517
518 /*******************************************************************************
519 * GdipCreateFontFamilyFromName [GDIPLUS.@]
520 *
521 * Creates a font family object based on a supplied name
522 *
523 * PARAMS
524 * name [I] Name of the font
525 * fontCollection [I] What font collection (if any) the font belongs to (may be NULL)
526 * FontFamily [O] Pointer to the resulting FontFamily object
527 *
528 * RETURNS
529 * SUCCESS: Ok
530 * FAILURE: FamilyNotFound if the requested FontFamily does not exist on the system
531 * FAILURE: Invalid parameter if FontFamily or name is NULL
532 *
533 * NOTES
534 * If fontCollection is NULL then the object is not part of any collection
535 *
536 */
537
538 GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
539 GpFontCollection *fontCollection,
540 GpFontFamily **FontFamily)
541 {
542 GpFontFamily* ffamily;
543 NEWTEXTMETRICW ntm;
544
545 TRACE("%s, %p %p\n", debugstr_w(name), fontCollection, FontFamily);
546
547 if (!(name && FontFamily))
548 return InvalidParameter;
549 if (fontCollection)
550 FIXME("No support for FontCollections yet!\n");
551
552 if (!find_installed_font(name, &ntm))
553 return FontFamilyNotFound;
554
555 ffamily = GdipAlloc(sizeof (GpFontFamily));
556 if (!ffamily) return OutOfMemory;
557
558 ffamily->tmw = ntm;
559 lstrcpynW(ffamily->FamilyName, name, LF_FACESIZE);
560
561 *FontFamily = ffamily;
562
563 return Ok;
564 }
565
566 /*******************************************************************************
567 * GdipCloneFontFamily [GDIPLUS.@]
568 *
569 * Creates a deep copy of a Font Family object
570 *
571 * PARAMS
572 * FontFamily [I] Font to clone
573 * clonedFontFamily [O] The resulting cloned font
574 *
575 * RETURNS
576 * SUCCESS: Ok
577 */
578 GpStatus WINGDIPAPI GdipCloneFontFamily(GpFontFamily* FontFamily, GpFontFamily** clonedFontFamily)
579 {
580 if (!(FontFamily && clonedFontFamily)) return InvalidParameter;
581
582 TRACE("stub: %p (%s), %p\n", FontFamily,
583 debugstr_w(FontFamily->FamilyName), clonedFontFamily);
584
585 *clonedFontFamily = GdipAlloc(sizeof(GpFontFamily));
586 if (!*clonedFontFamily) return OutOfMemory;
587
588 (*clonedFontFamily)->tmw = FontFamily->tmw;
589 lstrcpyW((*clonedFontFamily)->FamilyName, FontFamily->FamilyName);
590
591 return Ok;
592 }
593
594 /*******************************************************************************
595 * GdipGetFamilyName [GDIPLUS.@]
596 *
597 * Returns the family name into name
598 *
599 * PARAMS
600 * *family [I] Family to retrieve from
601 * *name [O] WCHARS of the family name
602 * LANGID [I] charset
603 *
604 * RETURNS
605 * SUCCESS: Ok
606 * FAILURE: InvalidParameter if family is NULL
607 *
608 * NOTES
609 * If name is a NULL ptr, then both XP and Vista will crash (so we do as well)
610 */
611 GpStatus WINGDIPAPI GdipGetFamilyName (GDIPCONST GpFontFamily *family,
612 WCHAR *name, LANGID language)
613 {
614 if (family == NULL)
615 return InvalidParameter;
616
617 TRACE("%p, %p, %d\n", family, name, language);
618
619 if (language != LANG_NEUTRAL)
620 FIXME("No support for handling of multiple languages!\n");
621
622 lstrcpynW (name, family->FamilyName, LF_FACESIZE);
623
624 return Ok;
625 }
626
627
628 /*****************************************************************************
629 * GdipDeleteFontFamily [GDIPLUS.@]
630 *
631 * Removes the specified FontFamily
632 *
633 * PARAMS
634 * *FontFamily [I] The family to delete
635 *
636 * RETURNS
637 * SUCCESS: Ok
638 * FAILURE: InvalidParameter if FontFamily is NULL.
639 *
640 */
641 GpStatus WINGDIPAPI GdipDeleteFontFamily(GpFontFamily *FontFamily)
642 {
643 if (!FontFamily)
644 return InvalidParameter;
645 TRACE("Deleting %p (%s)\n", FontFamily, debugstr_w(FontFamily->FamilyName));
646
647 GdipFree (FontFamily);
648
649 return Ok;
650 }
651
652 GpStatus WINGDIPAPI GdipGetCellAscent(GDIPCONST GpFontFamily *family,
653 INT style, UINT16* CellAscent)
654 {
655 if (!(family && CellAscent)) return InvalidParameter;
656
657 *CellAscent = family->tmw.tmAscent;
658
659 return Ok;
660 }
661
662 GpStatus WINGDIPAPI GdipGetCellDescent(GDIPCONST GpFontFamily *family,
663 INT style, UINT16* CellDescent)
664 {
665 TRACE("(%p, %d, %p)\n", family, style, CellDescent);
666
667 if (!(family && CellDescent)) return InvalidParameter;
668
669 *CellDescent = family->tmw.tmDescent;
670
671 return Ok;
672 }
673
674 /*******************************************************************************
675 * GdipGetEmHeight [GDIPLUS.@]
676 *
677 * Gets the height of the specified family in EmHeights
678 *
679 * PARAMS
680 * family [I] Family to retrieve from
681 * style [I] (optional) style
682 * EmHeight [O] return value
683 *
684 * RETURNS
685 * SUCCESS: Ok
686 * FAILURE: InvalidParameter
687 */
688 GpStatus WINGDIPAPI GdipGetEmHeight(GDIPCONST GpFontFamily *family, INT style, UINT16* EmHeight)
689 {
690 if (!(family && EmHeight)) return InvalidParameter;
691
692 TRACE("%p (%s), %d, %p\n", family, debugstr_w(family->FamilyName), style, EmHeight);
693
694 *EmHeight = family->tmw.ntmSizeEM;
695
696 return Ok;
697 }
698
699
700 /*******************************************************************************
701 * GdipGetLineSpacing [GDIPLUS.@]
702 *
703 * Returns the line spacing in design units
704 *
705 * PARAMS
706 * family [I] Family to retrieve from
707 * style [I] (Optional) font style
708 * LineSpacing [O] Return value
709 *
710 * RETURNS
711 * SUCCESS: Ok
712 * FAILURE: InvalidParameter (family or LineSpacing was NULL)
713 */
714 GpStatus WINGDIPAPI GdipGetLineSpacing(GDIPCONST GpFontFamily *family,
715 INT style, UINT16* LineSpacing)
716 {
717 TRACE("%p, %d, %p\n", family, style, LineSpacing);
718
719 if (!(family && LineSpacing))
720 return InvalidParameter;
721
722 if (style) FIXME("ignoring style\n");
723
724 *LineSpacing = family->tmw.tmAscent + family->tmw.tmDescent + family->tmw.tmExternalLeading;
725
726 return Ok;
727 }
728
729 GpStatus WINGDIPAPI GdipIsStyleAvailable(GDIPCONST GpFontFamily* family,
730 INT style, BOOL* IsStyleAvailable)
731 {
732 FIXME("%p %d %p stub!\n", family, style, IsStyleAvailable);
733
734 if (!(family && IsStyleAvailable))
735 return InvalidParameter;
736
737 return NotImplemented;
738 }
739
740 /*****************************************************************************
741 * GdipGetGenericFontFamilyMonospace [GDIPLUS.@]
742 *
743 * Obtains a serif family (Courier New on Windows)
744 *
745 * PARAMS
746 * **nativeFamily [I] Where the font will be stored
747 *
748 * RETURNS
749 * InvalidParameter if nativeFamily is NULL.
750 * Ok otherwise.
751 */
752 GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily)
753 {
754 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
755
756 if (nativeFamily == NULL) return InvalidParameter;
757
758 return GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily);
759 }
760
761 /*****************************************************************************
762 * GdipGetGenericFontFamilySerif [GDIPLUS.@]
763 *
764 * Obtains a serif family (Times New Roman on Windows)
765 *
766 * PARAMS
767 * **nativeFamily [I] Where the font will be stored
768 *
769 * RETURNS
770 * InvalidParameter if nativeFamily is NULL.
771 * Ok otherwise.
772 */
773 GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily)
774 {
775 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
776
777 TRACE("(%p)\n", nativeFamily);
778
779 if (nativeFamily == NULL) return InvalidParameter;
780
781 return GdipCreateFontFamilyFromName(TimesNewRoman, NULL, nativeFamily);
782 }
783
784 /*****************************************************************************
785 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
786 *
787 * Obtains a serif family (Microsoft Sans Serif on Windows)
788 *
789 * PARAMS
790 * **nativeFamily [I] Where the font will be stored
791 *
792 * RETURNS
793 * InvalidParameter if nativeFamily is NULL.
794 * Ok otherwise.
795 */
796 GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily)
797 {
798 /* FIXME: On Windows this is called Microsoft Sans Serif, this shouldn't
799 * affect anything */
800 static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
801
802 TRACE("(%p)\n", nativeFamily);
803
804 if (nativeFamily == NULL) return InvalidParameter;
805
806 return GdipCreateFontFamilyFromName(MSSansSerif, NULL, nativeFamily);
807 }
808
809 /*****************************************************************************
810 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
811 */
812 GpStatus WINGDIPAPI GdipNewPrivateFontCollection(GpFontCollection** fontCollection)
813 {
814 TRACE("%p\n", fontCollection);
815
816 if (!fontCollection)
817 return InvalidParameter;
818
819 *fontCollection = GdipAlloc(sizeof(GpFontCollection));
820 if (!*fontCollection) return OutOfMemory;
821
822 (*fontCollection)->FontFamilies = NULL;
823 (*fontCollection)->count = 0;
824 return Ok;
825 }
826
827 /*****************************************************************************
828 * GdipDeletePrivateFontCollection [GDIPLUS.@]
829 */
830 GpStatus WINGDIPAPI GdipDeletePrivateFontCollection(GpFontCollection **fontCollection)
831 {
832 INT i;
833
834 TRACE("%p\n", fontCollection);
835
836 if (!fontCollection)
837 return InvalidParameter;
838
839 for (i = 0; i < (*fontCollection)->count; i++) GdipFree((*fontCollection)->FontFamilies[i]);
840 GdipFree(*fontCollection);
841
842 return Ok;
843 }
844
845 /*****************************************************************************
846 * GdipPrivateAddFontFile [GDIPLUS.@]
847 */
848 GpStatus WINGDIPAPI GdipPrivateAddFontFile(GpFontCollection* fontCollection,
849 GDIPCONST WCHAR* filename)
850 {
851 FIXME("stub: %p, %s\n", fontCollection, debugstr_w(filename));
852
853 if (!(fontCollection && filename))
854 return InvalidParameter;
855
856 return NotImplemented;
857 }
858
859 /*****************************************************************************
860 * GdipPrivateAddMemoryFont [GDIPLUS.@]
861 */
862 GpStatus WINGDIPAPI GdipPrivateAddMemoryFont(GpFontCollection* fontCollection,
863 GDIPCONST void* memory, INT length)
864 {
865 FIXME("%p, %p, %d\n", fontCollection, memory, length);
866
867 if (!(fontCollection && memory && length))
868 return InvalidParameter;
869
870 return Ok;
871 }
872
873 /*****************************************************************************
874 * GdipGetFontCollectionFamilyCount [GDIPLUS.@]
875 */
876 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyCount(
877 GpFontCollection* fontCollection, INT* numFound)
878 {
879 TRACE("%p, %p\n", fontCollection, numFound);
880
881 if (!(fontCollection && numFound))
882 return InvalidParameter;
883
884 *numFound = fontCollection->count;
885 return Ok;
886 }
887
888 /*****************************************************************************
889 * GdipGetFontCollectionFamilyList [GDIPLUS.@]
890 */
891 GpStatus WINGDIPAPI GdipGetFontCollectionFamilyList(
892 GpFontCollection* fontCollection, INT numSought,
893 GpFontFamily* gpfamilies[], INT* numFound)
894 {
895 INT i;
896
897 TRACE("%p, %d, %p, %p\n", fontCollection, numSought, gpfamilies, numFound);
898
899 if (!(fontCollection && gpfamilies && numFound))
900 return InvalidParameter;
901
902 for (i = 0; i < numSought && i < fontCollection->count; i++)
903 {
904 gpfamilies[i] = fontCollection->FontFamilies[i];
905 }
906 *numFound = i;
907 return Ok;
908 }
909
910 GpStatus WINGDIPAPI GdipNewInstalledFontCollection(
911 GpFontCollection** fontCollection)
912 {
913 FIXME("stub: %p\n",fontCollection);
914
915 if (!fontCollection)
916 return InvalidParameter;
917
918 return NotImplemented;
919 }