2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gdiplus_private.h"
22 /* PANOSE is 10 bytes in size, need to pack the structure properly */
31 SHORT ySubscriptXSize
;
32 SHORT ySubscriptYSize
;
33 SHORT ySubscriptXOffset
;
34 SHORT ySubscriptYOffset
;
35 SHORT ySuperscriptXSize
;
36 SHORT ySuperscriptYSize
;
37 SHORT ySuperscriptXOffset
;
38 SHORT ySuperscriptYOffset
;
40 SHORT yStrikeoutPosition
;
43 ULONG ulUnicodeRange1
;
44 ULONG ulUnicodeRange2
;
45 ULONG ulUnicodeRange3
;
46 ULONG ulUnicodeRange4
;
49 USHORT usFirstCharIndex
;
50 USHORT usLastCharIndex
;
51 /* According to the Apple spec, original version didn't have the below fields,
52 * version numbers were taken from the OpenType spec.
54 /* version 0 (TrueType 1.5) */
56 USHORT sTypoDescender
;
60 /* version 1 (TrueType 1.66) */
61 ULONG ulCodePageRange1
;
62 ULONG ulCodePageRange2
;
63 /* version 2 (OpenType 1.2) */
77 USHORT advanceWidthMax
;
78 SHORT minLeftSideBearing
;
79 SHORT minRightSideBearing
;
85 SHORT metricDataFormat
;
86 USHORT numberOfHMetrics
;
90 #ifdef WORDS_BIGENDIAN
91 #define GET_BE_WORD(x) (x)
92 #define GET_BE_DWORD(x) (x)
94 #define GET_BE_WORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
95 #define GET_BE_DWORD(x) MAKELONG(GET_BE_WORD(HIWORD(x)), GET_BE_WORD(LOWORD(x)));
98 #define MS_MAKE_TAG(ch0, ch1, ch2, ch3) \
99 ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
100 ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
101 #define MS_OS2_TAG MS_MAKE_TAG('O','S','/','2')
102 #define MS_HHEA_TAG MS_MAKE_TAG('h','h','e','a')
104 static GpStatus
clone_font_family(const GpFontFamily
*, GpFontFamily
**);
106 static GpFontCollection installedFontCollection
= {0};
108 /*******************************************************************************
109 * GdipCreateFont [GDIPLUS.@]
111 * Create a new font based off of a FontFamily
114 * *fontFamily [I] Family to base the font off of
115 * emSize [I] Size of the font
116 * style [I] Bitwise OR of FontStyle enumeration
117 * unit [I] Unit emSize is measured in
118 * **font [I] the resulting Font object
122 * FAILURE: InvalidParameter if fontfamily or font is NULL.
123 * FAILURE: FontFamilyNotFound if an invalid FontFamily is given
126 * UnitDisplay is unsupported.
127 * emSize is stored separately from lfHeight, to hold the fraction.
129 GpStatus WINGDIPAPI
GdipCreateFont(GDIPCONST GpFontFamily
*fontFamily
,
130 REAL emSize
, INT style
, Unit unit
, GpFont
**font
)
133 OUTLINETEXTMETRICW otm
;
139 if (!fontFamily
|| !font
|| emSize
< 0.0)
140 return InvalidParameter
;
142 TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily
,
143 debugstr_w(fontFamily
->FamilyName
), emSize
, style
, unit
, font
);
145 memset(&lfw
, 0, sizeof(lfw
));
147 stat
= GdipGetFamilyName(fontFamily
, lfw
.lfFaceName
, LANG_NEUTRAL
);
148 if (stat
!= Ok
) return stat
;
150 lfw
.lfHeight
= -units_to_pixels(emSize
, unit
, fontFamily
->dpi
);
151 lfw
.lfWeight
= style
& FontStyleBold
? FW_BOLD
: FW_REGULAR
;
152 lfw
.lfItalic
= style
& FontStyleItalic
;
153 lfw
.lfUnderline
= style
& FontStyleUnderline
;
154 lfw
.lfStrikeOut
= style
& FontStyleStrikeout
;
156 hfont
= CreateFontIndirectW(&lfw
);
157 hdc
= CreateCompatibleDC(0);
158 SelectObject(hdc
, hfont
);
159 otm
.otmSize
= sizeof(otm
);
160 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
164 if (!ret
) return NotTrueTypeFont
;
166 *font
= heap_alloc_zero(sizeof(GpFont
));
167 if (!*font
) return OutOfMemory
;
169 (*font
)->unit
= unit
;
170 (*font
)->emSize
= emSize
;
173 stat
= clone_font_family(fontFamily
, &(*font
)->family
);
180 TRACE("<-- %p\n", *font
);
185 /*******************************************************************************
186 * GdipCreateFontFromLogfontW [GDIPLUS.@]
188 GpStatus WINGDIPAPI
GdipCreateFontFromLogfontW(HDC hdc
,
189 GDIPCONST LOGFONTW
*logfont
, GpFont
**font
)
191 HFONT hfont
, oldfont
;
192 OUTLINETEXTMETRICW otm
;
193 WCHAR facename
[LF_FACESIZE
];
197 TRACE("(%p, %p, %p)\n", hdc
, logfont
, font
);
199 if (!hdc
|| !logfont
|| !font
)
200 return InvalidParameter
;
202 hfont
= CreateFontIndirectW(logfont
);
203 oldfont
= SelectObject(hdc
, hfont
);
204 otm
.otmSize
= sizeof(otm
);
205 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
206 GetTextFaceW(hdc
, LF_FACESIZE
, facename
);
207 SelectObject(hdc
, oldfont
);
210 if (!ret
) return NotTrueTypeFont
;
212 *font
= heap_alloc_zero(sizeof(GpFont
));
213 if (!*font
) return OutOfMemory
;
215 (*font
)->unit
= UnitWorld
;
216 (*font
)->emSize
= otm
.otmTextMetrics
.tmAscent
;
219 stat
= GdipCreateFontFamilyFromName(facename
, NULL
, &(*font
)->family
);
223 return NotTrueTypeFont
;
226 TRACE("<-- %p\n", *font
);
231 /*******************************************************************************
232 * GdipCreateFontFromLogfontA [GDIPLUS.@]
234 GpStatus WINGDIPAPI
GdipCreateFontFromLogfontA(HDC hdc
,
235 GDIPCONST LOGFONTA
*lfa
, GpFont
**font
)
239 TRACE("(%p, %p, %p)\n", hdc
, lfa
, font
);
242 return InvalidParameter
;
244 memcpy(&lfw
, lfa
, FIELD_OFFSET(LOGFONTA
,lfFaceName
) );
246 if(!MultiByteToWideChar(CP_ACP
, 0, lfa
->lfFaceName
, -1, lfw
.lfFaceName
, LF_FACESIZE
))
249 return GdipCreateFontFromLogfontW(hdc
, &lfw
, font
);
252 /*******************************************************************************
253 * GdipDeleteFont [GDIPLUS.@]
255 GpStatus WINGDIPAPI
GdipDeleteFont(GpFont
* font
)
257 TRACE("(%p)\n", font
);
260 return InvalidParameter
;
262 GdipDeleteFontFamily(font
->family
);
268 /*******************************************************************************
269 * GdipCreateFontFromDC [GDIPLUS.@]
271 GpStatus WINGDIPAPI
GdipCreateFontFromDC(HDC hdc
, GpFont
**font
)
276 TRACE("(%p, %p)\n", hdc
, font
);
279 return InvalidParameter
;
281 hfont
= GetCurrentObject(hdc
, OBJ_FONT
);
285 if(!GetObjectW(hfont
, sizeof(LOGFONTW
), &lfw
))
288 return GdipCreateFontFromLogfontW(hdc
, &lfw
, font
);
291 /*******************************************************************************
292 * GdipGetFamily [GDIPLUS.@]
294 * Returns the FontFamily for the specified Font
297 * font [I] Font to request from
298 * family [O] Resulting FontFamily object
302 * FAILURE: An element of GpStatus
304 GpStatus WINGDIPAPI
GdipGetFamily(GpFont
*font
, GpFontFamily
**family
)
306 TRACE("%p %p\n", font
, family
);
308 if (!(font
&& family
))
309 return InvalidParameter
;
311 return GdipCloneFontFamily(font
->family
, family
);
314 static REAL
get_font_size(const GpFont
*font
)
319 /******************************************************************************
320 * GdipGetFontSize [GDIPLUS.@]
322 * Returns the size of the font in Units
325 * *font [I] The font to retrieve size from
326 * *size [O] Pointer to hold retrieved value
330 * FAILURE: InvalidParameter (font or size was NULL)
333 * Size returned is actually emSize -- not internal size used for drawing.
335 GpStatus WINGDIPAPI
GdipGetFontSize(GpFont
*font
, REAL
*size
)
337 TRACE("(%p, %p)\n", font
, size
);
339 if (!(font
&& size
)) return InvalidParameter
;
341 *size
= get_font_size(font
);
342 TRACE("%s,%d => %f\n", debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, *size
);
347 static INT
get_font_style(const GpFont
*font
)
351 if (font
->otm
.otmTextMetrics
.tmWeight
> FW_REGULAR
)
352 style
= FontStyleBold
;
354 style
= FontStyleRegular
;
355 if (font
->otm
.otmTextMetrics
.tmItalic
)
356 style
|= FontStyleItalic
;
357 if (font
->otm
.otmTextMetrics
.tmUnderlined
)
358 style
|= FontStyleUnderline
;
359 if (font
->otm
.otmTextMetrics
.tmStruckOut
)
360 style
|= FontStyleStrikeout
;
365 /*******************************************************************************
366 * GdipGetFontStyle [GDIPLUS.@]
368 * Gets the font's style, returned in bitwise OR of FontStyle enumeration
371 * font [I] font to request from
372 * style [O] resulting pointer to a FontStyle enumeration
376 * FAILURE: InvalidParameter
378 GpStatus WINGDIPAPI
GdipGetFontStyle(GpFont
*font
, INT
*style
)
380 TRACE("%p %p\n", font
, style
);
382 if (!(font
&& style
))
383 return InvalidParameter
;
385 *style
= get_font_style(font
);
386 TRACE("%s,%d => %d\n", debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, *style
);
391 /*******************************************************************************
392 * GdipGetFontUnit [GDIPLUS.@]
395 * font [I] Font to retrieve from
396 * unit [O] Return value
399 * FAILURE: font or unit was NULL
402 GpStatus WINGDIPAPI
GdipGetFontUnit(GpFont
*font
, Unit
*unit
)
404 TRACE("(%p, %p)\n", font
, unit
);
406 if (!(font
&& unit
)) return InvalidParameter
;
409 TRACE("%s,%d => %d\n", debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, *unit
);
414 /*******************************************************************************
415 * GdipGetLogFontA [GDIPLUS.@]
417 GpStatus WINGDIPAPI
GdipGetLogFontA(GpFont
*font
, GpGraphics
*graphics
,
423 TRACE("(%p, %p, %p)\n", font
, graphics
, lfa
);
425 status
= GdipGetLogFontW(font
, graphics
, &lfw
);
429 memcpy(lfa
, &lfw
, FIELD_OFFSET(LOGFONTA
,lfFaceName
) );
431 if(!WideCharToMultiByte(CP_ACP
, 0, lfw
.lfFaceName
, -1, lfa
->lfFaceName
, LF_FACESIZE
, NULL
, NULL
))
437 /*******************************************************************************
438 * GdipGetLogFontW [GDIPLUS.@]
440 GpStatus WINGDIPAPI
GdipGetLogFontW(GpFont
*font
, GpGraphics
*graphics
, LOGFONTW
*lf
)
442 REAL angle
, rel_height
, height
;
446 TRACE("(%p, %p, %p)\n", font
, graphics
, lf
);
448 if (!font
|| !graphics
|| !lf
)
449 return InvalidParameter
;
451 matrix
= graphics
->worldtrans
;
453 if (font
->unit
== UnitPixel
|| font
->unit
== UnitWorld
)
455 height
= units_to_pixels(font
->emSize
, graphics
->unit
, graphics
->yres
);
456 if (graphics
->unit
!= UnitDisplay
)
457 GdipScaleMatrix(&matrix
, graphics
->scale
, graphics
->scale
, MatrixOrderAppend
);
461 if (graphics
->unit
== UnitDisplay
|| graphics
->unit
== UnitPixel
)
462 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->xres
);
464 height
= units_to_pixels(font
->emSize
, font
->unit
, graphics
->yres
);
473 GdipTransformMatrixPoints(&matrix
, pt
, 3);
474 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
475 rel_height
= sqrt((pt
[2].Y
- pt
[0].Y
) * (pt
[2].Y
- pt
[0].Y
)+
476 (pt
[2].X
- pt
[0].X
) * (pt
[2].X
- pt
[0].X
));
478 lf
->lfHeight
= -gdip_round(height
* rel_height
);
480 lf
->lfEscapement
= lf
->lfOrientation
= gdip_round((angle
/ M_PI
) * 1800.0);
481 if (lf
->lfEscapement
< 0)
483 lf
->lfEscapement
+= 3600;
484 lf
->lfOrientation
+= 3600;
486 lf
->lfWeight
= font
->otm
.otmTextMetrics
.tmWeight
;
487 lf
->lfItalic
= font
->otm
.otmTextMetrics
.tmItalic
? 1 : 0;
488 lf
->lfUnderline
= font
->otm
.otmTextMetrics
.tmUnderlined
? 1 : 0;
489 lf
->lfStrikeOut
= font
->otm
.otmTextMetrics
.tmStruckOut
? 1 : 0;
490 lf
->lfCharSet
= font
->otm
.otmTextMetrics
.tmCharSet
;
491 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
492 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
493 lf
->lfQuality
= DEFAULT_QUALITY
;
494 lf
->lfPitchAndFamily
= 0;
495 strcpyW(lf
->lfFaceName
, font
->family
->FamilyName
);
497 TRACE("=> %s,%d\n", debugstr_w(lf
->lfFaceName
), lf
->lfHeight
);
502 /*******************************************************************************
503 * GdipCloneFont [GDIPLUS.@]
505 GpStatus WINGDIPAPI
GdipCloneFont(GpFont
*font
, GpFont
**cloneFont
)
509 TRACE("(%p, %p)\n", font
, cloneFont
);
511 if(!font
|| !cloneFont
)
512 return InvalidParameter
;
514 *cloneFont
= heap_alloc_zero(sizeof(GpFont
));
515 if(!*cloneFont
) return OutOfMemory
;
518 stat
= GdipCloneFontFamily(font
->family
, &(*cloneFont
)->family
);
519 if (stat
!= Ok
) heap_free(*cloneFont
);
524 /*******************************************************************************
525 * GdipGetFontHeight [GDIPLUS.@]
527 * font [I] Font to retrieve height from
528 * graphics [I] The current graphics context
529 * height [O] Resulting height
532 * FAILURE: Another element of GpStatus
535 * Forwards to GdipGetFontHeightGivenDPI
537 GpStatus WINGDIPAPI
GdipGetFontHeight(GDIPCONST GpFont
*font
,
538 GDIPCONST GpGraphics
*graphics
, REAL
*height
)
544 TRACE("%p %p %p\n", font
, graphics
, height
);
546 stat
= GdipGetFontHeightGivenDPI(font
, font
->family
->dpi
, &font_height
);
547 if (stat
!= Ok
) return stat
;
551 *height
= font_height
;
552 TRACE("%s,%d => %f\n",
553 debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, *height
);
557 stat
= GdipGetDpiY((GpGraphics
*)graphics
, &dpi
);
558 if (stat
!= Ok
) return stat
;
560 *height
= pixels_to_units(font_height
, graphics
->unit
, dpi
);
562 TRACE("%s,%d(unit %d) => %f\n",
563 debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, graphics
->unit
, *height
);
567 /*******************************************************************************
568 * GdipGetFontHeightGivenDPI [GDIPLUS.@]
570 * font [I] Font to retrieve DPI from
571 * dpi [I] DPI to assume
572 * height [O] Return value
576 * FAILURE: InvalidParameter if font or height is NULL
579 * According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
580 * (for anything other than unit Pixel)
582 GpStatus WINGDIPAPI
GdipGetFontHeightGivenDPI(GDIPCONST GpFont
*font
, REAL dpi
, REAL
*height
)
586 UINT16 line_spacing
, em_height
;
589 if (!font
|| !height
) return InvalidParameter
;
591 TRACE("%p (%s), %f, %p\n", font
,
592 debugstr_w(font
->family
->FamilyName
), dpi
, height
);
594 font_size
= units_to_pixels(get_font_size(font
), font
->unit
, dpi
);
595 style
= get_font_style(font
);
596 stat
= GdipGetLineSpacing(font
->family
, style
, &line_spacing
);
597 if (stat
!= Ok
) return stat
;
598 stat
= GdipGetEmHeight(font
->family
, style
, &em_height
);
599 if (stat
!= Ok
) return stat
;
601 *height
= (REAL
)line_spacing
* font_size
/ (REAL
)em_height
;
603 TRACE("%s,%d => %f\n",
604 debugstr_w(font
->family
->FamilyName
), font
->otm
.otmTextMetrics
.tmHeight
, *height
);
609 /***********************************************************************
610 * Borrowed from GDI32:
612 * Elf is really an ENUMLOGFONTEXW, and ntm is a NEWTEXTMETRICEXW.
613 * We have to use other types because of the FONTENUMPROCW definition.
615 static INT CALLBACK
is_font_installed_proc(const LOGFONTW
*elf
,
616 const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lParam
)
618 const ENUMLOGFONTW
*elfW
= (const ENUMLOGFONTW
*)elf
;
619 LOGFONTW
*lf
= (LOGFONTW
*)lParam
;
621 if (type
& RASTER_FONTTYPE
)
625 /* replace substituted font name by a real one */
626 lstrcpynW(lf
->lfFaceName
, elfW
->elfFullName
, LF_FACESIZE
);
632 WCHAR facename
[LF_FACESIZE
];
633 UINT16 em_height
, ascent
, descent
, line_spacing
; /* in font units */
637 static BOOL
get_font_metrics(HDC hdc
, struct font_metrics
*fm
)
639 OUTLINETEXTMETRICW otm
;
645 otm
.otmSize
= sizeof(otm
);
646 if (!GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
)) return FALSE
;
648 fm
->em_height
= otm
.otmEMSquare
;
649 fm
->dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
);
651 memset(&tt_hori
, 0, sizeof(tt_hori
));
652 if (GetFontData(hdc
, MS_HHEA_TAG
, 0, &tt_hori
, sizeof(tt_hori
)) != GDI_ERROR
)
654 fm
->ascent
= GET_BE_WORD(tt_hori
.Ascender
);
655 fm
->descent
= -GET_BE_WORD(tt_hori
.Descender
);
656 TRACE("hhea: ascent %d, descent %d\n", fm
->ascent
, fm
->descent
);
657 line_gap
= GET_BE_WORD(tt_hori
.LineGap
);
658 fm
->line_spacing
= fm
->ascent
+ fm
->descent
+ line_gap
;
659 TRACE("line_gap %u, line_spacing %u\n", line_gap
, fm
->line_spacing
);
660 if (fm
->ascent
+ fm
->descent
!= 0) return TRUE
;
663 size
= GetFontData(hdc
, MS_OS2_TAG
, 0, NULL
, 0);
664 if (size
== GDI_ERROR
) return FALSE
;
666 if (size
> sizeof(tt_os2
)) size
= sizeof(tt_os2
);
668 memset(&tt_os2
, 0, sizeof(tt_os2
));
669 if (GetFontData(hdc
, MS_OS2_TAG
, 0, &tt_os2
, size
) != size
) return FALSE
;
671 fm
->ascent
= GET_BE_WORD(tt_os2
.usWinAscent
);
672 fm
->descent
= GET_BE_WORD(tt_os2
.usWinDescent
);
673 TRACE("usWinAscent %u, usWinDescent %u\n", fm
->ascent
, fm
->descent
);
674 if (fm
->ascent
+ fm
->descent
== 0)
676 fm
->ascent
= GET_BE_WORD(tt_os2
.sTypoAscender
);
677 fm
->descent
= GET_BE_WORD(tt_os2
.sTypoDescender
);
678 TRACE("sTypoAscender %u, sTypoDescender %u\n", fm
->ascent
, fm
->descent
);
680 line_gap
= GET_BE_WORD(tt_os2
.sTypoLineGap
);
681 fm
->line_spacing
= fm
->ascent
+ fm
->descent
+ line_gap
;
682 TRACE("line_gap %u, line_spacing %u\n", line_gap
, fm
->line_spacing
);
686 static GpStatus
find_installed_font(const WCHAR
*name
, struct font_metrics
*fm
)
689 HDC hdc
= CreateCompatibleDC(0);
690 GpStatus ret
= FontFamilyNotFound
;
692 if(!EnumFontFamiliesW(hdc
, name
, is_font_installed_proc
, (LPARAM
)&lf
))
694 HFONT hfont
, old_font
;
696 strcpyW(fm
->facename
, lf
.lfFaceName
);
698 hfont
= CreateFontIndirectW(&lf
);
699 old_font
= SelectObject(hdc
, hfont
);
700 ret
= get_font_metrics(hdc
, fm
) ? Ok
: NotTrueTypeFont
;
701 SelectObject(hdc
, old_font
);
709 /*******************************************************************************
710 * GdipCreateFontFamilyFromName [GDIPLUS.@]
712 * Creates a font family object based on a supplied name
715 * name [I] Name of the font
716 * fontCollection [I] What font collection (if any) the font belongs to (may be NULL)
717 * FontFamily [O] Pointer to the resulting FontFamily object
721 * FAILURE: FamilyNotFound if the requested FontFamily does not exist on the system
722 * FAILURE: Invalid parameter if FontFamily or name is NULL
725 * If fontCollection is NULL then the object is not part of any collection
729 GpStatus WINGDIPAPI
GdipCreateFontFamilyFromName(GDIPCONST WCHAR
*name
,
730 GpFontCollection
*fontCollection
,
731 GpFontFamily
**FontFamily
)
734 GpFontFamily
* ffamily
;
735 struct font_metrics fm
;
737 TRACE("%s, %p %p\n", debugstr_w(name
), fontCollection
, FontFamily
);
739 if (!(name
&& FontFamily
))
740 return InvalidParameter
;
742 FIXME("No support for FontCollections yet!\n");
744 stat
= find_installed_font(name
, &fm
);
745 if (stat
!= Ok
) return stat
;
747 ffamily
= heap_alloc_zero(sizeof (GpFontFamily
));
748 if (!ffamily
) return OutOfMemory
;
750 lstrcpyW(ffamily
->FamilyName
, fm
.facename
);
751 ffamily
->em_height
= fm
.em_height
;
752 ffamily
->ascent
= fm
.ascent
;
753 ffamily
->descent
= fm
.descent
;
754 ffamily
->line_spacing
= fm
.line_spacing
;
755 ffamily
->dpi
= fm
.dpi
;
757 *FontFamily
= ffamily
;
759 TRACE("<-- %p\n", ffamily
);
764 static GpStatus
clone_font_family(const GpFontFamily
*family
, GpFontFamily
**clone
)
766 *clone
= heap_alloc_zero(sizeof(GpFontFamily
));
767 if (!*clone
) return OutOfMemory
;
774 /*******************************************************************************
775 * GdipCloneFontFamily [GDIPLUS.@]
777 * Creates a deep copy of a Font Family object
780 * FontFamily [I] Font to clone
781 * clonedFontFamily [O] The resulting cloned font
786 GpStatus WINGDIPAPI
GdipCloneFontFamily(GpFontFamily
* FontFamily
, GpFontFamily
** clonedFontFamily
)
790 if (!(FontFamily
&& clonedFontFamily
)) return InvalidParameter
;
792 TRACE("%p (%s), %p\n", FontFamily
,
793 debugstr_w(FontFamily
->FamilyName
), clonedFontFamily
);
795 status
= clone_font_family(FontFamily
, clonedFontFamily
);
796 if (status
!= Ok
) return status
;
798 TRACE("<-- %p\n", *clonedFontFamily
);
803 /*******************************************************************************
804 * GdipGetFamilyName [GDIPLUS.@]
806 * Returns the family name into name
809 * *family [I] Family to retrieve from
810 * *name [O] WCHARS of the family name
815 * FAILURE: InvalidParameter if family is NULL
818 * If name is a NULL ptr, then both XP and Vista will crash (so we do as well)
820 GpStatus WINGDIPAPI
GdipGetFamilyName (GDIPCONST GpFontFamily
*family
,
821 WCHAR
*name
, LANGID language
)
823 static int lang_fixme
;
826 return InvalidParameter
;
828 TRACE("%p, %p, %d\n", family
, name
, language
);
830 if (language
!= LANG_NEUTRAL
&& !lang_fixme
++)
831 FIXME("No support for handling of multiple languages!\n");
833 lstrcpynW (name
, family
->FamilyName
, LF_FACESIZE
);
839 /*****************************************************************************
840 * GdipDeleteFontFamily [GDIPLUS.@]
842 * Removes the specified FontFamily
845 * *FontFamily [I] The family to delete
849 * FAILURE: InvalidParameter if FontFamily is NULL.
852 GpStatus WINGDIPAPI
GdipDeleteFontFamily(GpFontFamily
*FontFamily
)
855 return InvalidParameter
;
856 TRACE("Deleting %p (%s)\n", FontFamily
, debugstr_w(FontFamily
->FamilyName
));
858 heap_free (FontFamily
);
863 GpStatus WINGDIPAPI
GdipGetCellAscent(GDIPCONST GpFontFamily
*family
,
864 INT style
, UINT16
* CellAscent
)
866 if (!(family
&& CellAscent
)) return InvalidParameter
;
868 *CellAscent
= family
->ascent
;
869 TRACE("%s => %u\n", debugstr_w(family
->FamilyName
), *CellAscent
);
874 GpStatus WINGDIPAPI
GdipGetCellDescent(GDIPCONST GpFontFamily
*family
,
875 INT style
, UINT16
* CellDescent
)
877 TRACE("(%p, %d, %p)\n", family
, style
, CellDescent
);
879 if (!(family
&& CellDescent
)) return InvalidParameter
;
881 *CellDescent
= family
->descent
;
882 TRACE("%s => %u\n", debugstr_w(family
->FamilyName
), *CellDescent
);
887 /*******************************************************************************
888 * GdipGetEmHeight [GDIPLUS.@]
890 * Gets the height of the specified family in EmHeights
893 * family [I] Family to retrieve from
894 * style [I] (optional) style
895 * EmHeight [O] return value
899 * FAILURE: InvalidParameter
901 GpStatus WINGDIPAPI
GdipGetEmHeight(GDIPCONST GpFontFamily
*family
, INT style
, UINT16
* EmHeight
)
903 if (!(family
&& EmHeight
)) return InvalidParameter
;
905 TRACE("%p (%s), %d, %p\n", family
, debugstr_w(family
->FamilyName
), style
, EmHeight
);
907 *EmHeight
= family
->em_height
;
908 TRACE("%s => %u\n", debugstr_w(family
->FamilyName
), *EmHeight
);
914 /*******************************************************************************
915 * GdipGetLineSpacing [GDIPLUS.@]
917 * Returns the line spacing in design units
920 * family [I] Family to retrieve from
921 * style [I] (Optional) font style
922 * LineSpacing [O] Return value
926 * FAILURE: InvalidParameter (family or LineSpacing was NULL)
928 GpStatus WINGDIPAPI
GdipGetLineSpacing(GDIPCONST GpFontFamily
*family
,
929 INT style
, UINT16
* LineSpacing
)
931 TRACE("%p, %d, %p\n", family
, style
, LineSpacing
);
933 if (!(family
&& LineSpacing
))
934 return InvalidParameter
;
936 if (style
) FIXME("ignoring style\n");
938 *LineSpacing
= family
->line_spacing
;
939 TRACE("%s => %u\n", debugstr_w(family
->FamilyName
), *LineSpacing
);
944 static INT CALLBACK
font_has_style_proc(const LOGFONTW
*elf
,
945 const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lParam
)
947 INT fontstyle
= FontStyleRegular
;
951 if (ntm
->tmWeight
>= FW_BOLD
) fontstyle
|= FontStyleBold
;
952 if (ntm
->tmItalic
) fontstyle
|= FontStyleItalic
;
953 if (ntm
->tmUnderlined
) fontstyle
|= FontStyleUnderline
;
954 if (ntm
->tmStruckOut
) fontstyle
|= FontStyleStrikeout
;
956 return (INT
)lParam
!= fontstyle
;
959 GpStatus WINGDIPAPI
GdipIsStyleAvailable(GDIPCONST GpFontFamily
* family
,
960 INT style
, BOOL
* IsStyleAvailable
)
964 TRACE("%p %d %p\n", family
, style
, IsStyleAvailable
);
966 if (!(family
&& IsStyleAvailable
))
967 return InvalidParameter
;
969 *IsStyleAvailable
= FALSE
;
971 hdc
= CreateCompatibleDC(0);
973 if(!EnumFontFamiliesW(hdc
, family
->FamilyName
, font_has_style_proc
, (LPARAM
)style
))
974 *IsStyleAvailable
= TRUE
;
981 /*****************************************************************************
982 * GdipGetGenericFontFamilyMonospace [GDIPLUS.@]
984 * Obtains a serif family (Courier New on Windows)
987 * **nativeFamily [I] Where the font will be stored
990 * InvalidParameter if nativeFamily is NULL.
993 GpStatus WINGDIPAPI
GdipGetGenericFontFamilyMonospace(GpFontFamily
**nativeFamily
)
995 static const WCHAR CourierNew
[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
996 static const WCHAR LiberationMono
[] = {'L','i','b','e','r','a','t','i','o','n',' ','M','o','n','o','\0'};
999 if (nativeFamily
== NULL
) return InvalidParameter
;
1001 stat
= GdipCreateFontFamilyFromName(CourierNew
, NULL
, nativeFamily
);
1003 if (stat
== FontFamilyNotFound
)
1004 stat
= GdipCreateFontFamilyFromName(LiberationMono
, NULL
, nativeFamily
);
1006 if (stat
== FontFamilyNotFound
)
1007 ERR("Missing 'Courier New' font\n");
1012 /*****************************************************************************
1013 * GdipGetGenericFontFamilySerif [GDIPLUS.@]
1015 * Obtains a serif family (Times New Roman on Windows)
1018 * **nativeFamily [I] Where the font will be stored
1021 * InvalidParameter if nativeFamily is NULL.
1024 GpStatus WINGDIPAPI
GdipGetGenericFontFamilySerif(GpFontFamily
**nativeFamily
)
1026 static const WCHAR TimesNewRoman
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
1027 static const WCHAR LiberationSerif
[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f','\0'};
1030 TRACE("(%p)\n", nativeFamily
);
1032 if (nativeFamily
== NULL
) return InvalidParameter
;
1034 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, nativeFamily
);
1036 if (stat
== FontFamilyNotFound
)
1037 stat
= GdipCreateFontFamilyFromName(LiberationSerif
, NULL
, nativeFamily
);
1039 if (stat
== FontFamilyNotFound
)
1040 ERR("Missing 'Times New Roman' font\n");
1045 /*****************************************************************************
1046 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
1048 * Obtains a serif family (Microsoft Sans Serif on Windows)
1051 * **nativeFamily [I] Where the font will be stored
1054 * InvalidParameter if nativeFamily is NULL.
1057 GpStatus WINGDIPAPI
GdipGetGenericFontFamilySansSerif(GpFontFamily
**nativeFamily
)
1060 static const WCHAR MicrosoftSansSerif
[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
1061 static const WCHAR Tahoma
[] = {'T','a','h','o','m','a','\0'};
1063 TRACE("(%p)\n", nativeFamily
);
1065 if (nativeFamily
== NULL
) return InvalidParameter
;
1067 stat
= GdipCreateFontFamilyFromName(MicrosoftSansSerif
, NULL
, nativeFamily
);
1069 if (stat
== FontFamilyNotFound
)
1070 /* FIXME: Microsoft Sans Serif is not installed on Wine. */
1071 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, nativeFamily
);
1076 /*****************************************************************************
1077 * GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
1079 GpStatus WINGDIPAPI
GdipNewPrivateFontCollection(GpFontCollection
** fontCollection
)
1081 TRACE("%p\n", fontCollection
);
1083 if (!fontCollection
)
1084 return InvalidParameter
;
1086 *fontCollection
= heap_alloc_zero(sizeof(GpFontCollection
));
1087 if (!*fontCollection
) return OutOfMemory
;
1089 (*fontCollection
)->FontFamilies
= NULL
;
1090 (*fontCollection
)->count
= 0;
1091 (*fontCollection
)->allocated
= 0;
1093 TRACE("<-- %p\n", *fontCollection
);
1098 /*****************************************************************************
1099 * GdipDeletePrivateFontCollection [GDIPLUS.@]
1101 GpStatus WINGDIPAPI
GdipDeletePrivateFontCollection(GpFontCollection
**fontCollection
)
1105 TRACE("%p\n", fontCollection
);
1107 if (!fontCollection
)
1108 return InvalidParameter
;
1110 for (i
= 0; i
< (*fontCollection
)->count
; i
++) heap_free((*fontCollection
)->FontFamilies
[i
]);
1111 heap_free(*fontCollection
);
1116 /*****************************************************************************
1117 * GdipPrivateAddFontFile [GDIPLUS.@]
1119 GpStatus WINGDIPAPI
GdipPrivateAddFontFile(GpFontCollection
*collection
, GDIPCONST WCHAR
*name
)
1121 HANDLE file
, mapping
;
1126 TRACE("%p, %s\n", collection
, debugstr_w(name
));
1128 if (!collection
|| !name
) return InvalidParameter
;
1130 file
= CreateFileW(name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1131 if (file
== INVALID_HANDLE_VALUE
) return InvalidParameter
;
1133 if (!GetFileSizeEx(file
, &size
) || size
.u
.HighPart
)
1136 return InvalidParameter
;
1139 mapping
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
1141 if (!mapping
) return InvalidParameter
;
1143 mem
= MapViewOfFile(mapping
, FILE_MAP_READ
, 0, 0, 0);
1144 CloseHandle(mapping
);
1145 if (!mem
) return InvalidParameter
;
1147 /* GdipPrivateAddMemoryFont creates a copy of the memory block */
1148 status
= GdipPrivateAddMemoryFont(collection
, mem
, size
.u
.LowPart
);
1149 UnmapViewOfFile(mem
);
1154 #define TT_PLATFORM_APPLE_UNICODE 0
1155 #define TT_PLATFORM_MACINTOSH 1
1156 #define TT_PLATFORM_MICROSOFT 3
1158 #define TT_APPLE_ID_DEFAULT 0
1159 #define TT_APPLE_ID_ISO_10646 2
1160 #define TT_APPLE_ID_UNICODE_2_0 3
1162 #define TT_MS_ID_SYMBOL_CS 0
1163 #define TT_MS_ID_UNICODE_CS 1
1165 #define TT_MAC_ID_SIMPLIFIED_CHINESE 25
1167 #define NAME_ID_FULL_FONT_NAME 4
1170 USHORT major_version
;
1171 USHORT minor_version
;
1173 USHORT search_range
;
1174 USHORT entry_selector
;
1179 char tag
[4]; /* table name */
1180 ULONG check_sum
; /* Check sum */
1181 ULONG offset
; /* Offset from beginning of file */
1182 ULONG length
; /* length of the table in bytes */
1183 } tt_table_directory
;
1186 USHORT format
; /* format selector. Always 0 */
1187 USHORT count
; /* Name Records count */
1188 USHORT string_offset
; /* Offset for strings storage, * from start of the table */
1197 USHORT offset
; /* from start of storage area */
1200 /* Copied from gdi32/freetype.c */
1202 static const LANGID mac_langid_table
[] =
1204 MAKELANGID(LANG_ENGLISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ENGLISH */
1205 MAKELANGID(LANG_FRENCH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_FRENCH */
1206 MAKELANGID(LANG_GERMAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GERMAN */
1207 MAKELANGID(LANG_ITALIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ITALIAN */
1208 MAKELANGID(LANG_DUTCH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_DUTCH */
1209 MAKELANGID(LANG_SWEDISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SWEDISH */
1210 MAKELANGID(LANG_SPANISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SPANISH */
1211 MAKELANGID(LANG_DANISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_DANISH */
1212 MAKELANGID(LANG_PORTUGUESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_PORTUGUESE */
1213 MAKELANGID(LANG_NORWEGIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_NORWEGIAN */
1214 MAKELANGID(LANG_HEBREW
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_HEBREW */
1215 MAKELANGID(LANG_JAPANESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_JAPANESE */
1216 MAKELANGID(LANG_ARABIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ARABIC */
1217 MAKELANGID(LANG_FINNISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_FINNISH */
1218 MAKELANGID(LANG_GREEK
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GREEK */
1219 MAKELANGID(LANG_ICELANDIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ICELANDIC */
1220 MAKELANGID(LANG_MALTESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MALTESE */
1221 MAKELANGID(LANG_TURKISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TURKISH */
1222 MAKELANGID(LANG_CROATIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_CROATIAN */
1223 MAKELANGID(LANG_CHINESE_TRADITIONAL
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_CHINESE_TRADITIONAL */
1224 MAKELANGID(LANG_URDU
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_URDU */
1225 MAKELANGID(LANG_HINDI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_HINDI */
1226 MAKELANGID(LANG_THAI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_THAI */
1227 MAKELANGID(LANG_KOREAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KOREAN */
1228 MAKELANGID(LANG_LITHUANIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_LITHUANIAN */
1229 MAKELANGID(LANG_POLISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_POLISH */
1230 MAKELANGID(LANG_HUNGARIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_HUNGARIAN */
1231 MAKELANGID(LANG_ESTONIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ESTONIAN */
1232 MAKELANGID(LANG_LATVIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_LETTISH */
1233 MAKELANGID(LANG_SAMI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SAAMISK */
1234 MAKELANGID(LANG_FAEROESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_FAEROESE */
1235 MAKELANGID(LANG_FARSI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_FARSI */
1236 MAKELANGID(LANG_RUSSIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_RUSSIAN */
1237 MAKELANGID(LANG_CHINESE_SIMPLIFIED
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_CHINESE_SIMPLIFIED */
1238 MAKELANGID(LANG_DUTCH
,SUBLANG_DUTCH_BELGIAN
), /* TT_MAC_LANGID_FLEMISH */
1239 MAKELANGID(LANG_IRISH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_IRISH */
1240 MAKELANGID(LANG_ALBANIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ALBANIAN */
1241 MAKELANGID(LANG_ROMANIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ROMANIAN */
1242 MAKELANGID(LANG_CZECH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_CZECH */
1243 MAKELANGID(LANG_SLOVAK
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SLOVAK */
1244 MAKELANGID(LANG_SLOVENIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SLOVENIAN */
1245 0, /* TT_MAC_LANGID_YIDDISH */
1246 MAKELANGID(LANG_SERBIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SERBIAN */
1247 MAKELANGID(LANG_MACEDONIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MACEDONIAN */
1248 MAKELANGID(LANG_BULGARIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_BULGARIAN */
1249 MAKELANGID(LANG_UKRAINIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_UKRAINIAN */
1250 MAKELANGID(LANG_BELARUSIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_BYELORUSSIAN */
1251 MAKELANGID(LANG_UZBEK
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_UZBEK */
1252 MAKELANGID(LANG_KAZAK
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KAZAKH */
1253 MAKELANGID(LANG_AZERI
,SUBLANG_AZERI_CYRILLIC
), /* TT_MAC_LANGID_AZERBAIJANI */
1254 0, /* TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT */
1255 MAKELANGID(LANG_ARMENIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ARMENIAN */
1256 MAKELANGID(LANG_GEORGIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GEORGIAN */
1257 0, /* TT_MAC_LANGID_MOLDAVIAN */
1258 MAKELANGID(LANG_KYRGYZ
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KIRGHIZ */
1259 MAKELANGID(LANG_TAJIK
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TAJIKI */
1260 MAKELANGID(LANG_TURKMEN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TURKMEN */
1261 MAKELANGID(LANG_MONGOLIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MONGOLIAN */
1262 MAKELANGID(LANG_MONGOLIAN
,SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
), /* TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT */
1263 MAKELANGID(LANG_PASHTO
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_PASHTO */
1264 0, /* TT_MAC_LANGID_KURDISH */
1265 MAKELANGID(LANG_KASHMIRI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KASHMIRI */
1266 MAKELANGID(LANG_SINDHI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SINDHI */
1267 MAKELANGID(LANG_TIBETAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TIBETAN */
1268 MAKELANGID(LANG_NEPALI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_NEPALI */
1269 MAKELANGID(LANG_SANSKRIT
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SANSKRIT */
1270 MAKELANGID(LANG_MARATHI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MARATHI */
1271 MAKELANGID(LANG_BENGALI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_BENGALI */
1272 MAKELANGID(LANG_ASSAMESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ASSAMESE */
1273 MAKELANGID(LANG_GUJARATI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GUJARATI */
1274 MAKELANGID(LANG_PUNJABI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_PUNJABI */
1275 MAKELANGID(LANG_ORIYA
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ORIYA */
1276 MAKELANGID(LANG_MALAYALAM
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MALAYALAM */
1277 MAKELANGID(LANG_KANNADA
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KANNADA */
1278 MAKELANGID(LANG_TAMIL
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TAMIL */
1279 MAKELANGID(LANG_TELUGU
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TELUGU */
1280 MAKELANGID(LANG_SINHALESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SINHALESE */
1281 0, /* TT_MAC_LANGID_BURMESE */
1282 MAKELANGID(LANG_KHMER
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_KHMER */
1283 MAKELANGID(LANG_LAO
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_LAO */
1284 MAKELANGID(LANG_VIETNAMESE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_VIETNAMESE */
1285 MAKELANGID(LANG_INDONESIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_INDONESIAN */
1286 0, /* TT_MAC_LANGID_TAGALOG */
1287 MAKELANGID(LANG_MALAY
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MALAY_ROMAN_SCRIPT */
1288 0, /* TT_MAC_LANGID_MALAY_ARABIC_SCRIPT */
1289 MAKELANGID(LANG_AMHARIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_AMHARIC */
1290 MAKELANGID(LANG_TIGRIGNA
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TIGRINYA */
1291 0, /* TT_MAC_LANGID_GALLA */
1292 0, /* TT_MAC_LANGID_SOMALI */
1293 MAKELANGID(LANG_SWAHILI
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SWAHILI */
1294 0, /* TT_MAC_LANGID_RUANDA */
1295 0, /* TT_MAC_LANGID_RUNDI */
1296 0, /* TT_MAC_LANGID_CHEWA */
1297 MAKELANGID(LANG_MALAGASY
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MALAGASY */
1298 MAKELANGID(LANG_ESPERANTO
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_ESPERANTO */
1299 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 95-111 */
1300 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 112-127 */
1301 MAKELANGID(LANG_WELSH
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_WELSH */
1302 MAKELANGID(LANG_BASQUE
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_BASQUE */
1303 MAKELANGID(LANG_CATALAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_CATALAN */
1304 0, /* TT_MAC_LANGID_LATIN */
1305 MAKELANGID(LANG_QUECHUA
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_QUECHUA */
1306 0, /* TT_MAC_LANGID_GUARANI */
1307 0, /* TT_MAC_LANGID_AYMARA */
1308 MAKELANGID(LANG_TATAR
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_TATAR */
1309 MAKELANGID(LANG_UIGHUR
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_UIGHUR */
1310 0, /* TT_MAC_LANGID_DZONGKHA */
1311 0, /* TT_MAC_LANGID_JAVANESE */
1312 0, /* TT_MAC_LANGID_SUNDANESE */
1313 MAKELANGID(LANG_GALICIAN
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GALICIAN */
1314 MAKELANGID(LANG_AFRIKAANS
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_AFRIKAANS */
1315 MAKELANGID(LANG_BRETON
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_BRETON */
1316 MAKELANGID(LANG_INUKTITUT
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_INUKTITUT */
1317 MAKELANGID(LANG_SCOTTISH_GAELIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_SCOTTISH_GAELIC */
1318 MAKELANGID(LANG_MANX_GAELIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_MANX_GAELIC */
1319 MAKELANGID(LANG_IRISH
,SUBLANG_IRISH_IRELAND
), /* TT_MAC_LANGID_IRISH_GAELIC */
1320 0, /* TT_MAC_LANGID_TONGAN */
1321 0, /* TT_MAC_LANGID_GREEK_POLYTONIC */
1322 MAKELANGID(LANG_GREENLANDIC
,SUBLANG_DEFAULT
), /* TT_MAC_LANGID_GREELANDIC */
1323 MAKELANGID(LANG_AZERI
,SUBLANG_AZERI_LATIN
), /* TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT */
1326 static inline WORD
get_mac_code_page( const tt_name_record
*name
)
1328 WORD encoding_id
= GET_BE_WORD(name
->encoding_id
);
1329 if (encoding_id
== TT_MAC_ID_SIMPLIFIED_CHINESE
) return 10008; /* special case */
1330 return 10000 + encoding_id
;
1333 static int match_name_table_language( const tt_name_record
*name
, LANGID lang
)
1337 switch (GET_BE_WORD(name
->platform_id
))
1339 case TT_PLATFORM_MICROSOFT
:
1340 switch (GET_BE_WORD(name
->encoding_id
))
1342 case TT_MS_ID_UNICODE_CS
:
1343 case TT_MS_ID_SYMBOL_CS
:
1344 name_lang
= GET_BE_WORD(name
->language_id
);
1350 case TT_PLATFORM_MACINTOSH
:
1351 if (!IsValidCodePage( get_mac_code_page( name
))) return 0;
1352 name_lang
= GET_BE_WORD(name
->language_id
);
1353 if (name_lang
>= sizeof(mac_langid_table
)/sizeof(mac_langid_table
[0])) return 0;
1354 name_lang
= mac_langid_table
[name_lang
];
1356 case TT_PLATFORM_APPLE_UNICODE
:
1357 switch (GET_BE_WORD(name
->encoding_id
))
1359 case TT_APPLE_ID_DEFAULT
:
1360 case TT_APPLE_ID_ISO_10646
:
1361 case TT_APPLE_ID_UNICODE_2_0
:
1362 name_lang
= GET_BE_WORD(name
->language_id
);
1363 if (name_lang
>= sizeof(mac_langid_table
)/sizeof(mac_langid_table
[0])) return 0;
1364 name_lang
= mac_langid_table
[name_lang
];
1373 if (name_lang
== lang
) return 3;
1374 if (PRIMARYLANGID( name_lang
) == PRIMARYLANGID( lang
)) return 2;
1375 if (name_lang
== MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
)) return 1;
1379 static WCHAR
*copy_name_table_string( const tt_name_record
*name
, const BYTE
*data
, WCHAR
*ret
, DWORD len
)
1381 WORD name_len
= GET_BE_WORD(name
->length
);
1384 switch (GET_BE_WORD(name
->platform_id
))
1386 case TT_PLATFORM_APPLE_UNICODE
:
1387 case TT_PLATFORM_MICROSOFT
:
1388 if (name_len
>= len
*sizeof(WCHAR
))
1390 for (len
= 0; len
< name_len
/ 2; len
++)
1391 ret
[len
] = (data
[len
* 2] << 8) | data
[len
* 2 + 1];
1394 case TT_PLATFORM_MACINTOSH
:
1395 codepage
= get_mac_code_page( name
);
1396 len
= MultiByteToWideChar( codepage
, 0, (char *)data
, name_len
, ret
, len
-1 );
1405 static WCHAR
*load_ttf_name_id( const BYTE
*mem
, DWORD_PTR size
, DWORD id
, WCHAR
*ret
, DWORD len
)
1407 LANGID lang
= GetSystemDefaultLangID();
1408 const tt_header
*header
;
1409 const tt_name_table
*name_table
;
1410 const tt_name_record
*name_record
;
1411 DWORD pos
, ofs
, count
;
1412 int i
, res
, best_lang
= 0, best_index
= -1;
1414 if (sizeof(tt_header
) > size
)
1416 header
= (const tt_header
*)mem
;
1417 count
= GET_BE_WORD(header
->tables_no
);
1419 if (GET_BE_WORD(header
->major_version
) != 1 || GET_BE_WORD(header
->minor_version
) != 0)
1422 pos
= sizeof(*header
);
1423 for (i
= 0; i
< count
; i
++)
1425 const tt_table_directory
*table_directory
= (const tt_table_directory
*)&mem
[pos
];
1426 pos
+= sizeof(*table_directory
);
1427 if (memcmp(table_directory
->tag
, "name", 4) == 0)
1429 ofs
= GET_BE_DWORD(table_directory
->offset
);
1438 pos
= ofs
+ sizeof(*name_table
);
1441 name_table
= (const tt_name_table
*)&mem
[ofs
];
1442 count
= GET_BE_WORD(name_table
->count
);
1443 if (GET_BE_WORD(name_table
->string_offset
) >= size
- ofs
) return NULL
;
1444 ofs
+= GET_BE_WORD(name_table
->string_offset
);
1445 for (i
=0; i
<count
; i
++)
1447 name_record
= (const tt_name_record
*)&mem
[pos
];
1448 pos
+= sizeof(*name_record
);
1452 if (GET_BE_WORD(name_record
->name_id
) != id
) continue;
1453 if (GET_BE_WORD(name_record
->offset
) >= size
- ofs
) return NULL
;
1454 if (GET_BE_WORD(name_record
->length
) > size
- ofs
- GET_BE_WORD(name_record
->offset
)) return NULL
;
1456 res
= match_name_table_language( name_record
, lang
);
1457 if (res
> best_lang
)
1466 name_record
= (const tt_name_record
*)(name_table
+ 1) + best_index
;
1467 ret
= copy_name_table_string( name_record
, mem
+ofs
+GET_BE_WORD(name_record
->offset
), ret
, len
);
1468 TRACE( "name %u found platform %u lang %04x %s\n", GET_BE_WORD(name_record
->name_id
),
1469 GET_BE_WORD(name_record
->platform_id
), GET_BE_WORD(name_record
->language_id
), debugstr_w( ret
));
1475 static INT CALLBACK
add_font_proc(const LOGFONTW
*lfw
, const TEXTMETRICW
*ntm
, DWORD type
, LPARAM lParam
);
1477 /*****************************************************************************
1478 * GdipPrivateAddMemoryFont [GDIPLUS.@]
1480 GpStatus WINGDIPAPI
GdipPrivateAddMemoryFont(GpFontCollection
* fontCollection
,
1481 GDIPCONST
void* memory
, INT length
)
1483 WCHAR buf
[32], *name
;
1486 TRACE("%p, %p, %d\n", fontCollection
, memory
, length
);
1488 if (!fontCollection
|| !memory
|| !length
)
1489 return InvalidParameter
;
1491 name
= load_ttf_name_id(memory
, length
, NAME_ID_FULL_FONT_NAME
, buf
, sizeof(buf
)/sizeof(*buf
));
1495 font
= AddFontMemResourceEx((void*)memory
, length
, NULL
, &count
);
1496 TRACE("%s: %p/%u\n", debugstr_w(name
), font
, count
);
1497 if (!font
|| !count
)
1498 return InvalidParameter
;
1505 hdc
= CreateCompatibleDC(0);
1507 lfw
.lfCharSet
= DEFAULT_CHARSET
;
1508 lstrcpyW(lfw
.lfFaceName
, name
);
1509 lfw
.lfPitchAndFamily
= 0;
1511 if (!EnumFontFamiliesExW(hdc
, &lfw
, add_font_proc
, (LPARAM
)fontCollection
, 0))
1522 /*****************************************************************************
1523 * GdipGetFontCollectionFamilyCount [GDIPLUS.@]
1525 GpStatus WINGDIPAPI
GdipGetFontCollectionFamilyCount(
1526 GpFontCollection
* fontCollection
, INT
* numFound
)
1528 TRACE("%p, %p\n", fontCollection
, numFound
);
1530 if (!(fontCollection
&& numFound
))
1531 return InvalidParameter
;
1533 *numFound
= fontCollection
->count
;
1537 /*****************************************************************************
1538 * GdipGetFontCollectionFamilyList [GDIPLUS.@]
1540 GpStatus WINGDIPAPI
GdipGetFontCollectionFamilyList(
1541 GpFontCollection
* fontCollection
, INT numSought
,
1542 GpFontFamily
* gpfamilies
[], INT
* numFound
)
1547 TRACE("%p, %d, %p, %p\n", fontCollection
, numSought
, gpfamilies
, numFound
);
1549 if (!(fontCollection
&& gpfamilies
&& numFound
))
1550 return InvalidParameter
;
1552 memset(gpfamilies
, 0, sizeof(*gpfamilies
) * numSought
);
1554 for (i
= 0; i
< numSought
&& i
< fontCollection
->count
&& stat
== Ok
; i
++)
1556 stat
= GdipCloneFontFamily(fontCollection
->FontFamilies
[i
], &gpfamilies
[i
]);
1564 for (i
=0; i
<numToFree
; i
++)
1566 GdipDeleteFontFamily(gpfamilies
[i
]);
1567 gpfamilies
[i
] = NULL
;
1574 void free_installed_fonts(void)
1576 while (installedFontCollection
.count
)
1577 GdipDeleteFontFamily(installedFontCollection
.FontFamilies
[--installedFontCollection
.count
]);
1578 heap_free(installedFontCollection
.FontFamilies
);
1579 installedFontCollection
.FontFamilies
= NULL
;
1580 installedFontCollection
.allocated
= 0;
1583 static INT CALLBACK
add_font_proc(const LOGFONTW
*lfw
, const TEXTMETRICW
*ntm
,
1584 DWORD type
, LPARAM lParam
)
1586 GpFontCollection
* fonts
= (GpFontCollection
*)lParam
;
1589 if (type
== RASTER_FONTTYPE
)
1592 /* skip duplicates */
1593 for (i
=0; i
<fonts
->count
; i
++)
1594 if (strcmpiW(lfw
->lfFaceName
, fonts
->FontFamilies
[i
]->FamilyName
) == 0)
1597 if (fonts
->allocated
== fonts
->count
)
1599 INT new_alloc_count
= fonts
->allocated
+50;
1600 GpFontFamily
** new_family_list
= heap_alloc(new_alloc_count
*sizeof(void*));
1602 if (!new_family_list
)
1605 memcpy(new_family_list
, fonts
->FontFamilies
, fonts
->count
*sizeof(void*));
1606 heap_free(fonts
->FontFamilies
);
1607 fonts
->FontFamilies
= new_family_list
;
1608 fonts
->allocated
= new_alloc_count
;
1611 if (GdipCreateFontFamilyFromName(lfw
->lfFaceName
, NULL
, &fonts
->FontFamilies
[fonts
->count
]) == Ok
)
1619 GpStatus WINGDIPAPI
GdipNewInstalledFontCollection(
1620 GpFontCollection
** fontCollection
)
1622 TRACE("(%p)\n",fontCollection
);
1624 if (!fontCollection
)
1625 return InvalidParameter
;
1627 if (installedFontCollection
.count
== 0)
1632 hdc
= CreateCompatibleDC(0);
1634 lfw
.lfCharSet
= DEFAULT_CHARSET
;
1635 lfw
.lfFaceName
[0] = 0;
1636 lfw
.lfPitchAndFamily
= 0;
1638 if (!EnumFontFamiliesExW(hdc
, &lfw
, add_font_proc
, (LPARAM
)&installedFontCollection
, 0))
1640 free_installed_fonts();
1648 *fontCollection
= &installedFontCollection
;