2 * Unit test suite for fonts
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
29 #define expect_(expected, got, precision) ok(abs((expected) - (got)) <= (precision), "Expected %d, got %d\n", (expected), (got))
30 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
31 #define expectf(expected, got) expectf_((expected), (got), 0.001)
33 static const WCHAR nonexistent
[] = {'T','h','i','s','F','o','n','t','s','h','o','u','l','d','N','o','t','E','x','i','s','t','\0'};
34 static const WCHAR MSSansSerif
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
35 static const WCHAR TimesNewRoman
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
36 static const WCHAR Tahoma
[] = {'T','a','h','o','m','a',0};
38 static void set_rect_empty(RectF
*rc
)
46 static void test_createfont(void)
48 GpFontFamily
* fontfamily
= NULL
, *fontfamily2
;
54 WCHAR familyname
[LF_FACESIZE
];
56 stat
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &fontfamily
);
57 expect (FontFamilyNotFound
, stat
);
58 stat
= GdipDeleteFont(font
);
59 expect (InvalidParameter
, stat
);
60 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
62 stat
= GdipCreateFont(fontfamily
, 12, FontStyleRegular
, UnitPoint
, &font
);
64 stat
= GdipGetFontUnit (font
, &unit
);
66 expect (UnitPoint
, unit
);
68 stat
= GdipGetFamily(font
, &fontfamily2
);
70 stat
= GdipGetFamilyName(fontfamily2
, familyname
, 0);
72 ok (lstrcmpiW(Tahoma
, familyname
) == 0, "Expected Tahoma, got %s\n",
73 wine_dbgstr_w(familyname
));
74 stat
= GdipDeleteFontFamily(fontfamily2
);
77 /* Test to see if returned size is based on unit (its not) */
78 GdipGetFontSize(font
, &size
);
79 ok (size
== 12, "Expected 12, got %f\n", size
);
82 /* Make sure everything is converted correctly for all Units */
83 for (i
= UnitWorld
; i
<=UnitMillimeter
; i
++)
85 if (i
== UnitDisplay
) continue; /* Crashes WindowsXP, wtf? */
86 GdipCreateFont(fontfamily
, 24, FontStyleRegular
, i
, &font
);
87 GdipGetFontSize (font
, &size
);
88 ok (size
== 24, "Expected 24, got %f (with unit: %d)\n", size
, i
);
89 GdipGetFontUnit (font
, &unit
);
94 GdipDeleteFontFamily(fontfamily
);
97 static void test_logfont(void)
101 GpFontFamily
*family
;
103 GpGraphics
*graphics
;
107 UINT16 em_height
, line_spacing
;
110 GdipCreateFromHDC(hdc
, &graphics
);
112 memset(&lfa
, 0, sizeof(LOGFONTA
));
113 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
114 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
116 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
118 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
121 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
122 expect(0, lfa2
.lfWidth
);
123 expect(0, lfa2
.lfEscapement
);
124 expect(0, lfa2
.lfOrientation
);
125 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
126 expect(0, lfa2
.lfItalic
);
127 expect(0, lfa2
.lfUnderline
);
128 expect(0, lfa2
.lfStrikeOut
);
129 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
130 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
131 expect(0, lfa2
.lfOutPrecision
);
132 expect(0, lfa2
.lfClipPrecision
);
133 expect(0, lfa2
.lfQuality
);
134 expect(0, lfa2
.lfPitchAndFamily
);
136 GdipDeleteFont(font
);
138 memset(&lfa
, 0, sizeof(LOGFONTA
));
141 lfa
.lfEscapement
= lfa
.lfOrientation
= 50;
142 lfa
.lfItalic
= lfa
.lfUnderline
= lfa
.lfStrikeOut
= TRUE
;
144 memset(&lfa2
, 0xff, sizeof(LOGFONTA
));
145 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
147 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
149 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
152 ok(lfa2
.lfHeight
< 0, "Expected negative height\n");
153 expect(0, lfa2
.lfWidth
);
154 expect(0, lfa2
.lfEscapement
);
155 expect(0, lfa2
.lfOrientation
);
156 ok((lfa2
.lfWeight
>= 100) && (lfa2
.lfWeight
<= 900), "Expected weight to be set\n");
157 expect(TRUE
, lfa2
.lfItalic
);
158 expect(TRUE
, lfa2
.lfUnderline
);
159 expect(TRUE
, lfa2
.lfStrikeOut
);
160 ok(lfa2
.lfCharSet
== GetTextCharset(hdc
) || lfa2
.lfCharSet
== ANSI_CHARSET
,
161 "Expected %x or %x, got %x\n", GetTextCharset(hdc
), ANSI_CHARSET
, lfa2
.lfCharSet
);
162 expect(0, lfa2
.lfOutPrecision
);
163 expect(0, lfa2
.lfClipPrecision
);
164 expect(0, lfa2
.lfQuality
);
165 expect(0, lfa2
.lfPitchAndFamily
);
167 stat
= GdipGetFontStyle(font
, &style
);
169 ok (style
== (FontStyleItalic
| FontStyleUnderline
| FontStyleStrikeout
),
170 "Expected , got %d\n", style
);
172 stat
= GdipGetFontUnit(font
, &unit
);
174 expect(UnitWorld
, unit
);
176 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
178 expectf(25.347656, rval
);
179 stat
= GdipGetFontSize(font
, &rval
);
183 stat
= GdipGetFamily(font
, &family
);
185 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
187 expect(2048, em_height
);
188 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
190 expect(2472, line_spacing
);
191 GdipDeleteFontFamily(family
);
193 GdipDeleteFont(font
);
195 memset(&lfa
, 0, sizeof(lfa
));
197 lstrcpyA(lfa
.lfFaceName
, "Tahoma");
198 stat
= GdipCreateFontFromLogfontA(hdc
, &lfa
, &font
);
200 memset(&lfa2
, 0xff, sizeof(lfa2
));
201 stat
= GdipGetLogFontA(font
, graphics
, &lfa2
);
203 expect(lfa
.lfHeight
, lfa2
.lfHeight
);
205 stat
= GdipGetFontUnit(font
, &unit
);
207 expect(UnitWorld
, unit
);
209 stat
= GdipGetFontHeight(font
, graphics
, &rval
);
211 expectf(30.175781, rval
);
212 stat
= GdipGetFontSize(font
, &rval
);
216 stat
= GdipGetFamily(font
, &family
);
218 stat
= GdipGetEmHeight(family
, FontStyleRegular
, &em_height
);
220 expect(2048, em_height
);
221 stat
= GdipGetLineSpacing(family
, FontStyleRegular
, &line_spacing
);
223 expect(2472, line_spacing
);
224 GdipDeleteFontFamily(family
);
226 GdipDeleteFont(font
);
228 GdipDeleteGraphics(graphics
);
232 static void test_fontfamily (void)
234 GpFontFamily
*family
, *clonedFontFamily
;
235 WCHAR itsName
[LF_FACESIZE
];
238 /* FontFamily cannot be NULL */
239 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, NULL
);
240 expect (InvalidParameter
, stat
);
242 /* FontFamily must be able to actually find the family.
243 * If it can't, any subsequent calls should fail.
245 stat
= GdipCreateFontFamilyFromName (nonexistent
, NULL
, &family
);
246 expect (FontFamilyNotFound
, stat
);
248 /* Bitmap fonts are not found */
249 stat
= GdipCreateFontFamilyFromName (MSSansSerif
, NULL
, &family
);
250 expect (FontFamilyNotFound
, stat
);
251 if(stat
== Ok
) GdipDeleteFontFamily(family
);
253 stat
= GdipCreateFontFamilyFromName (Tahoma
, NULL
, &family
);
256 stat
= GdipGetFamilyName (family
, itsName
, LANG_NEUTRAL
);
258 expect (0, lstrcmpiW(itsName
, Tahoma
));
262 /* Crashes on Windows XP SP2, Vista, and so Wine as well */
263 stat
= GdipGetFamilyName (family
, NULL
, LANG_NEUTRAL
);
267 /* Make sure we don't read old data */
268 ZeroMemory (itsName
, sizeof(itsName
));
269 stat
= GdipCloneFontFamily(family
, &clonedFontFamily
);
271 GdipDeleteFontFamily(family
);
272 stat
= GdipGetFamilyName(clonedFontFamily
, itsName
, LANG_NEUTRAL
);
274 expect(0, lstrcmpiW(itsName
, Tahoma
));
276 GdipDeleteFontFamily(clonedFontFamily
);
279 static void test_fontfamily_properties (void)
281 GpFontFamily
* FontFamily
= NULL
;
285 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &FontFamily
);
288 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
290 ok (result
== 2472, "Expected 2472, got %d\n", result
);
292 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
294 ok(result
== 2048, "Expected 2048, got %d\n", result
);
296 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
298 ok(result
== 2049, "Expected 2049, got %d\n", result
);
300 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
302 ok(result
== 423, "Expected 423, got %d\n", result
);
303 GdipDeleteFontFamily(FontFamily
);
305 stat
= GdipCreateFontFamilyFromName(TimesNewRoman
, NULL
, &FontFamily
);
306 if(stat
== FontFamilyNotFound
)
307 skip("Times New Roman not installed\n");
311 stat
= GdipGetLineSpacing(FontFamily
, FontStyleRegular
, &result
);
313 ok(result
== 2355, "Expected 2355, got %d\n", result
);
315 stat
= GdipGetEmHeight(FontFamily
, FontStyleRegular
, &result
);
317 ok(result
== 2048, "Expected 2048, got %d\n", result
);
319 stat
= GdipGetCellAscent(FontFamily
, FontStyleRegular
, &result
);
321 ok(result
== 1825, "Expected 1825, got %d\n", result
);
323 stat
= GdipGetCellDescent(FontFamily
, FontStyleRegular
, &result
);
325 ok(result
== 443, "Expected 443 got %d\n", result
);
326 GdipDeleteFontFamily(FontFamily
);
330 static void check_family(const char* context
, GpFontFamily
*family
, WCHAR
*name
)
336 stat
= GdipGetFamilyName(family
, name
, LANG_NEUTRAL
);
337 ok(stat
== Ok
, "could not get the %s family name: %.8x\n", context
, stat
);
339 stat
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPixel
, &font
);
340 ok(stat
== Ok
, "could not create a font for the %s family: %.8x\n", context
, stat
);
343 stat
= GdipDeleteFont(font
);
344 ok(stat
== Ok
, "could not delete the %s family font: %.8x\n", context
, stat
);
347 stat
= GdipDeleteFontFamily(family
);
348 ok(stat
== Ok
, "could not delete the %s family: %.8x\n", context
, stat
);
351 static void test_getgenerics (void)
354 GpFontFamily
*family
;
355 WCHAR sansname
[LF_FACESIZE
], serifname
[LF_FACESIZE
], mononame
[LF_FACESIZE
];
356 int missingfonts
= 0;
358 stat
= GdipGetGenericFontFamilySansSerif(&family
);
360 if (stat
== FontFamilyNotFound
)
363 check_family("Sans Serif", family
, sansname
);
365 stat
= GdipGetGenericFontFamilySerif(&family
);
367 if (stat
== FontFamilyNotFound
)
370 check_family("Serif", family
, serifname
);
372 stat
= GdipGetGenericFontFamilyMonospace(&family
);
374 if (stat
== FontFamilyNotFound
)
377 check_family("Monospace", family
, mononame
);
379 if (missingfonts
&& strcmp(winetest_platform
, "wine") == 0)
380 trace("You may need to install either the Microsoft Web Fonts or the Liberation Fonts\n");
382 /* Check that the family names are all different */
383 ok(lstrcmpiW(sansname
, serifname
) != 0, "Sans Serif and Serif families should be different: %s\n", wine_dbgstr_w(sansname
));
384 ok(lstrcmpiW(sansname
, mononame
) != 0, "Sans Serif and Monospace families should be different: %s\n", wine_dbgstr_w(sansname
));
385 ok(lstrcmpiW(serifname
, mononame
) != 0, "Serif and Monospace families should be different: %s\n", wine_dbgstr_w(serifname
));
388 static void test_installedfonts (void)
391 GpFontCollection
* collection
=NULL
;
393 stat
= GdipNewInstalledFontCollection(NULL
);
394 expect (InvalidParameter
, stat
);
396 stat
= GdipNewInstalledFontCollection(&collection
);
398 ok (collection
!= NULL
, "got NULL font collection\n");
401 static void test_heightgivendpi(void)
405 GpFontFamily
* fontfamily
= NULL
;
409 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &fontfamily
);
412 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPixel
, &font
);
415 stat
= GdipGetFontHeightGivenDPI(NULL
, 96, &height
);
416 expect(InvalidParameter
, stat
);
418 stat
= GdipGetFontHeightGivenDPI(font
, 96, NULL
);
419 expect(InvalidParameter
, stat
);
421 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
423 expectf(36.210938, height
);
424 GdipDeleteFont(font
);
427 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitWorld
, &font
);
430 stat
= GdipGetFontUnit(font
, &unit
);
432 expect(UnitWorld
, unit
);
434 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
436 expectf(36.210938, height
);
437 GdipDeleteFont(font
);
440 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitPoint
, &font
);
442 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
444 expectf(48.281250, height
);
445 GdipDeleteFont(font
);
448 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitInch
, &font
);
451 stat
= GdipGetFontUnit(font
, &unit
);
453 expect(UnitInch
, unit
);
455 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
457 expectf(3476.250000, height
);
458 GdipDeleteFont(font
);
461 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitDocument
, &font
);
464 stat
= GdipGetFontUnit(font
, &unit
);
466 expect(UnitDocument
, unit
);
468 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
470 expectf(11.587500, height
);
471 GdipDeleteFont(font
);
474 stat
= GdipCreateFont(fontfamily
, 30, FontStyleRegular
, UnitMillimeter
, &font
);
477 stat
= GdipGetFontUnit(font
, &unit
);
479 expect(UnitMillimeter
, unit
);
481 stat
= GdipGetFontHeightGivenDPI(font
, 96, &height
);
483 expectf(136.860245, height
);
484 GdipDeleteFont(font
);
486 GdipDeleteFontFamily(fontfamily
);
489 static int CALLBACK
font_enum_proc(const LOGFONTW
*lfe
, const TEXTMETRICW
*ntme
,
490 DWORD type
, LPARAM lparam
)
492 NEWTEXTMETRICW
*ntm
= (NEWTEXTMETRICW
*)lparam
;
494 if (type
!= TRUETYPE_FONTTYPE
) return 1;
496 *ntm
= *(NEWTEXTMETRICW
*)ntme
;
502 UINT16 em_height
, line_spacing
, ascent
, descent
;
503 REAL font_height
, font_size
;
507 static void gdi_get_font_metrics(LOGFONTW
*lf
, struct font_metrics
*fm
)
512 OUTLINETEXTMETRICW otm
;
515 hdc
= CreateCompatibleDC(0);
517 /* it's the only way to get extended NEWTEXTMETRIC fields */
518 ret
= EnumFontFamiliesExW(hdc
, lf
, font_enum_proc
, (LPARAM
)&ntm
, 0);
519 ok(!ret
, "EnumFontFamiliesExW failed to find %s\n", wine_dbgstr_w(lf
->lfFaceName
));
521 hfont
= CreateFontIndirectW(lf
);
522 SelectObject(hdc
, hfont
);
524 otm
.otmSize
= sizeof(otm
);
525 ret
= GetOutlineTextMetricsW(hdc
, otm
.otmSize
, &otm
);
526 ok(ret
, "GetOutlineTextMetrics failed\n");
531 fm
->lfHeight
= -otm
.otmTextMetrics
.tmAscent
;
532 fm
->line_spacing
= ntm
.ntmCellHeight
;
533 fm
->font_size
= (REAL
)otm
.otmTextMetrics
.tmAscent
;
534 fm
->font_height
= (REAL
)fm
->line_spacing
* fm
->font_size
/ (REAL
)ntm
.ntmSizeEM
;
535 fm
->em_height
= ntm
.ntmSizeEM
;
536 fm
->ascent
= ntm
.ntmSizeEM
;
537 fm
->descent
= ntm
.ntmCellHeight
- ntm
.ntmSizeEM
;
540 static void gdip_get_font_metrics(GpFont
*font
, struct font_metrics
*fm
)
543 GpFontFamily
*family
;
546 stat
= GdipGetFontStyle(font
, &style
);
549 stat
= GdipGetFontHeight(font
, NULL
, &fm
->font_height
);
551 stat
= GdipGetFontSize(font
, &fm
->font_size
);
554 fm
->lfHeight
= (INT
)(fm
->font_size
* -1.0);
556 stat
= GdipGetFamily(font
, &family
);
559 stat
= GdipGetEmHeight(family
, style
, &fm
->em_height
);
561 stat
= GdipGetLineSpacing(family
, style
, &fm
->line_spacing
);
563 stat
= GdipGetCellAscent(family
, style
, &fm
->ascent
);
565 stat
= GdipGetCellDescent(family
, style
, &fm
->descent
);
568 GdipDeleteFontFamily(family
);
571 static void cmp_font_metrics(struct font_metrics
*fm1
, struct font_metrics
*fm2
, int line
)
573 ok_(__FILE__
, line
)(fm1
->lfHeight
== fm2
->lfHeight
, "lfHeight %d != %d\n", fm1
->lfHeight
, fm2
->lfHeight
);
574 ok_(__FILE__
, line
)(fm1
->em_height
== fm2
->em_height
, "em_height %u != %u\n", fm1
->em_height
, fm2
->em_height
);
575 ok_(__FILE__
, line
)(fm1
->line_spacing
== fm2
->line_spacing
, "line_spacing %u != %u\n", fm1
->line_spacing
, fm2
->line_spacing
);
576 ok_(__FILE__
, line
)(abs(fm1
->ascent
- fm2
->ascent
) <= 1, "ascent %u != %u\n", fm1
->ascent
, fm2
->ascent
);
577 ok_(__FILE__
, line
)(abs(fm1
->descent
- fm2
->descent
) <= 1, "descent %u != %u\n", fm1
->descent
, fm2
->descent
);
578 ok(fm1
->font_height
> 0.0, "fm1->font_height should be positive, got %f\n", fm1
->font_height
);
579 ok(fm2
->font_height
> 0.0, "fm2->font_height should be positive, got %f\n", fm2
->font_height
);
580 ok_(__FILE__
, line
)(fm1
->font_height
== fm2
->font_height
, "font_height %f != %f\n", fm1
->font_height
, fm2
->font_height
);
581 ok(fm1
->font_size
> 0.0, "fm1->font_size should be positive, got %f\n", fm1
->font_size
);
582 ok(fm2
->font_size
> 0.0, "fm2->font_size should be positive, got %f\n", fm2
->font_size
);
583 ok_(__FILE__
, line
)(fm1
->font_size
== fm2
->font_size
, "font_size %f != %f\n", fm1
->font_size
, fm2
->font_size
);
586 static void test_font_metrics(void)
590 GpFontFamily
*family
;
591 GpGraphics
*graphics
;
594 struct font_metrics fm_gdi
, fm_gdip
;
597 hdc
= CreateCompatibleDC(0);
598 stat
= GdipCreateFromHDC(hdc
, &graphics
);
601 memset(&lf
, 0, sizeof(lf
));
604 lstrcpyW(lf
.lfFaceName
, Tahoma
);
606 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
609 stat
= GdipGetFontUnit(font
, &unit
);
611 expect(UnitWorld
, unit
);
613 gdip_get_font_metrics(font
, &fm_gdip
);
615 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
616 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
617 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
618 fm_gdip
.font_height
, fm_gdip
.font_size
);
620 gdi_get_font_metrics(&lf
, &fm_gdi
);
622 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
623 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
624 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
625 fm_gdi
.font_height
, fm_gdi
.font_size
);
627 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
629 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
631 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
632 gdi_get_font_metrics(&lf
, &fm_gdi
);
634 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
635 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
636 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
637 fm_gdi
.font_height
, fm_gdi
.font_size
);
638 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
640 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
642 GdipDeleteFont(font
);
645 lstrcpyW(lf
.lfFaceName
, Tahoma
);
647 stat
= GdipCreateFontFromLogfontW(hdc
, &lf
, &font
);
650 stat
= GdipGetFontUnit(font
, &unit
);
652 expect(UnitWorld
, unit
);
654 gdip_get_font_metrics(font
, &fm_gdip
);
656 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
657 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
658 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
659 fm_gdip
.font_height
, fm_gdip
.font_size
);
661 gdi_get_font_metrics(&lf
, &fm_gdi
);
663 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
664 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
665 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
666 fm_gdi
.font_height
, fm_gdi
.font_size
);
668 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
670 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
672 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
673 gdi_get_font_metrics(&lf
, &fm_gdi
);
675 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
676 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
677 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
678 fm_gdi
.font_height
, fm_gdi
.font_size
);
679 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
681 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
683 GdipDeleteFont(font
);
685 stat
= GdipCreateFontFamilyFromName(Tahoma
, NULL
, &family
);
689 stat
= GdipCreateFont(family
, 13.0, FontStyleRegular
, UnitPixel
, &font
);
692 gdip_get_font_metrics(font
, &fm_gdip
);
694 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
695 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
696 fm_gdip
.em_height
, fm_gdip
.line_spacing
, fm_gdip
.ascent
, fm_gdip
.descent
,
697 fm_gdip
.font_height
, fm_gdip
.font_size
);
699 stat
= GdipGetLogFontW(font
, graphics
, &lf
);
701 ok(lf
.lfHeight
< 0, "lf.lfHeight should be negative, got %d\n", lf
.lfHeight
);
702 gdi_get_font_metrics(&lf
, &fm_gdi
);
704 trace("%s,%d: EmHeight %u, LineSpacing %u, CellAscent %u, CellDescent %u, FontHeight %f, FontSize %f\n",
705 wine_dbgstr_w(lf
.lfFaceName
), lf
.lfHeight
,
706 fm_gdi
.em_height
, fm_gdi
.line_spacing
, fm_gdi
.ascent
, fm_gdi
.descent
,
707 fm_gdi
.font_height
, fm_gdi
.font_size
);
708 ok((REAL
)lf
.lfHeight
* -1.0 == fm_gdi
.font_size
, "expected %f, got %f\n", (REAL
)lf
.lfHeight
* -1.0, fm_gdi
.font_size
);
710 cmp_font_metrics(&fm_gdip
, &fm_gdi
, __LINE__
);
712 stat
= GdipGetLogFontW(font
, NULL
, &lf
);
713 expect(InvalidParameter
, stat
);
715 GdipDeleteFont(font
);
717 stat
= GdipCreateFont(family
, -13.0, FontStyleRegular
, UnitPixel
, &font
);
718 expect(InvalidParameter
, stat
);
720 GdipDeleteFontFamily(family
);
722 GdipDeleteGraphics(graphics
);
726 static void test_font_substitution(void)
728 WCHAR ms_shell_dlg
[LF_FACESIZE
];
729 char fallback_font
[LF_FACESIZE
];
734 GpGraphics
*graphics
;
736 GpFontFamily
*family
;
739 hdc
= CreateCompatibleDC(0);
740 status
= GdipCreateFromHDC(hdc
, &graphics
);
743 hfont
= GetStockObject(DEFAULT_GUI_FONT
);
744 ok(hfont
!= 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
746 memset(&lf
, 0xfe, sizeof(lf
));
747 ret
= GetObjectA(hfont
, sizeof(lf
), &lf
);
748 ok(ret
== sizeof(lf
), "GetObject failed\n");
749 ok(!lstrcmpA(lf
.lfFaceName
, "MS Shell Dlg"), "wrong face name %s\n", lf
.lfFaceName
);
750 MultiByteToWideChar(CP_ACP
, 0, lf
.lfFaceName
, -1, ms_shell_dlg
, LF_FACESIZE
);
752 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
754 memset(&lf
, 0xfe, sizeof(lf
));
755 status
= GdipGetLogFontA(font
, graphics
, &lf
);
757 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
758 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
759 GdipDeleteFont(font
);
761 status
= GdipCreateFontFamilyFromName(ms_shell_dlg
, NULL
, &family
);
763 status
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPoint
, &font
);
765 memset(&lf
, 0xfe, sizeof(lf
));
766 status
= GdipGetLogFontA(font
, graphics
, &lf
);
768 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
769 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
770 GdipDeleteFont(font
);
771 GdipDeleteFontFamily(family
);
773 status
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &family
);
774 ok(status
== FontFamilyNotFound
, "expected FontFamilyNotFound, got %d\n", status
);
776 /* nonexistent fonts fallback to Arial, or something else if it's missing */
777 strcpy(lf
.lfFaceName
,"Arial");
778 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
780 status
= GdipGetLogFontA(font
, graphics
, &lf
);
782 strcpy(fallback_font
,lf
.lfFaceName
);
783 trace("fallback font %s\n", fallback_font
);
785 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
786 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
788 memset(&lf
, 0xfe, sizeof(lf
));
789 status
= GdipGetLogFontA(font
, graphics
, &lf
);
791 ok(!lstrcmpA(lf
.lfFaceName
, fallback_font
), "wrong face name %s / %s\n", lf
.lfFaceName
, fallback_font
);
792 GdipDeleteFont(font
);
795 lf
.lfFaceName
[0] = 0;
796 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
798 memset(&lf
, 0xfe, sizeof(lf
));
799 status
= GdipGetLogFontA(font
, graphics
, &lf
);
801 ok(!lstrcmpA(lf
.lfFaceName
, fallback_font
), "wrong face name %s / %s\n", lf
.lfFaceName
, fallback_font
);
802 GdipDeleteFont(font
);
804 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
807 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
809 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
811 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
812 "expected NotTrueTypeFont, got %d\n", status
);
813 /* FIXME: remove when wine is fixed */
814 if (font
) GdipDeleteFont(font
);
817 lf
.lfFaceName
[0] = 0;
819 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
821 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
822 "expected NotTrueTypeFont, got %d\n", status
);
823 /* FIXME: remove when wine is fixed */
824 if (font
) GdipDeleteFont(font
);
826 GdipDeleteGraphics(graphics
);
830 static void test_font_transform(void)
832 static const WCHAR string
[] = { 'A',0 };
837 GpGraphics
*graphics
;
839 GpStringFormat
*format
, *typographic
;
840 PointF pos
[1] = { { 0,0 } };
841 REAL height
, margin_y
;
844 hdc
= CreateCompatibleDC(0);
845 status
= GdipCreateFromHDC(hdc
, &graphics
);
848 status
= GdipSetPageUnit(graphics
, UnitPixel
);
851 status
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
853 status
= GdipStringFormatGetGenericTypographic(&typographic
);
856 memset(&lf
, 0, sizeof(lf
));
857 lstrcpyA(lf
.lfFaceName
, "Tahoma");
860 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
863 margin_y
= 100.0 / 8.0;
865 /* identity matrix */
866 status
= GdipCreateMatrix(&matrix
);
868 status
= GdipSetWorldTransform(graphics
, matrix
);
870 status
= GdipGetLogFontA(font
, graphics
, &lf
);
872 expect(-100, lf
.lfHeight
);
873 expect(0, lf
.lfWidth
);
874 expect(0, lf
.lfEscapement
);
875 expect(0, lf
.lfOrientation
);
876 status
= GdipGetFontHeight(font
, graphics
, &height
);
878 expectf(120.703125, height
);
879 set_rect_empty(&rect
);
880 set_rect_empty(&bounds
);
881 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
883 expectf(0.0, bounds
.X
);
884 expectf(0.0, bounds
.Y
);
886 expectf(height
+ margin_y
, bounds
.Height
);
887 set_rect_empty(&rect
);
888 set_rect_empty(&bounds
);
889 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
891 expectf(0.0, bounds
.X
);
892 expectf(0.0, bounds
.Y
);
893 expectf_(height
, bounds
.Height
, 1.0);
894 set_rect_empty(&bounds
);
895 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
896 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
898 expectf(0.0, bounds
.X
);
899 expectf_(-100.0, bounds
.Y
, 0.05);
900 expectf_(height
, bounds
.Height
, 0.5);
901 set_rect_empty(&bounds
);
902 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
903 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
905 expectf(0.0, bounds
.X
);
906 expectf_(-100.0, bounds
.Y
, 0.05);
907 expectf_(height
, bounds
.Height
, 0.5);
910 status
= GdipScaleMatrix(matrix
, 2.0, 3.0, MatrixOrderAppend
);
912 status
= GdipSetWorldTransform(graphics
, matrix
);
914 status
= GdipGetLogFontA(font
, graphics
, &lf
);
916 expect(-300, lf
.lfHeight
);
917 expect(0, lf
.lfWidth
);
918 expect(0, lf
.lfEscapement
);
919 expect(0, lf
.lfOrientation
);
920 status
= GdipGetFontHeight(font
, graphics
, &height
);
922 expectf(120.703125, height
);
923 set_rect_empty(&rect
);
924 set_rect_empty(&bounds
);
925 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
927 expectf(0.0, bounds
.X
);
928 expectf(0.0, bounds
.Y
);
930 expectf(height
+ margin_y
, bounds
.Height
);
931 set_rect_empty(&rect
);
932 set_rect_empty(&bounds
);
933 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
935 expectf(0.0, bounds
.X
);
936 expectf(0.0, bounds
.Y
);
937 expectf_(height
, bounds
.Height
, 0.05);
938 set_rect_empty(&bounds
);
939 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
940 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
942 expectf(0.0, bounds
.X
);
943 expectf_(-100.0, bounds
.Y
, 0.05);
944 expectf_(height
, bounds
.Height
, 0.2);
945 set_rect_empty(&bounds
);
946 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
947 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
949 expectf(0.0, bounds
.X
);
951 expectf_(-300.0, bounds
.Y
, 0.15);
953 expectf(height
* 3.0, bounds
.Height
);
955 /* scale + ratate matrix */
956 status
= GdipRotateMatrix(matrix
, 45.0, MatrixOrderAppend
);
958 status
= GdipSetWorldTransform(graphics
, matrix
);
960 status
= GdipGetLogFontA(font
, graphics
, &lf
);
962 expect(-300, lf
.lfHeight
);
963 expect(0, lf
.lfWidth
);
964 expect_(3151, lf
.lfEscapement
, 1);
965 expect_(3151, lf
.lfOrientation
, 1);
966 status
= GdipGetFontHeight(font
, graphics
, &height
);
968 expectf(120.703125, height
);
969 set_rect_empty(&rect
);
970 set_rect_empty(&bounds
);
971 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
973 expectf(0.0, bounds
.X
);
974 expectf(0.0, bounds
.Y
);
976 expectf(height
+ margin_y
, bounds
.Height
);
977 set_rect_empty(&rect
);
978 set_rect_empty(&bounds
);
979 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
981 expectf(0.0, bounds
.X
);
982 expectf(0.0, bounds
.Y
);
983 expectf_(height
, bounds
.Height
, 0.05);
984 set_rect_empty(&bounds
);
985 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
986 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
988 expectf(0.0, bounds
.X
);
989 expectf_(-100.0, bounds
.Y
, 0.05);
990 expectf_(height
, bounds
.Height
, 0.2);
991 set_rect_empty(&bounds
);
992 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
993 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
996 expectf_(-43.814377, bounds
.X
, 0.05);
998 expectf_(-212.235611, bounds
.Y
, 0.05);
1000 expectf_(340.847534, bounds
.Height
, 0.05);
1002 /* scale + ratate + shear matrix */
1003 status
= GdipShearMatrix(matrix
, 4.0, 5.0, MatrixOrderAppend
);
1005 status
= GdipSetWorldTransform(graphics
, matrix
);
1007 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1010 expect(1032, lf
.lfHeight
);
1011 expect(0, lf
.lfWidth
);
1012 expect_(3099, lf
.lfEscapement
, 1);
1013 expect_(3099, lf
.lfOrientation
, 1);
1014 status
= GdipGetFontHeight(font
, graphics
, &height
);
1016 expectf(120.703125, height
);
1017 set_rect_empty(&rect
);
1018 set_rect_empty(&bounds
);
1019 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1021 expectf(0.0, bounds
.X
);
1022 expectf(0.0, bounds
.Y
);
1024 expectf(height
+ margin_y
, bounds
.Height
);
1025 set_rect_empty(&rect
);
1026 set_rect_empty(&bounds
);
1027 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1029 expectf(0.0, bounds
.X
);
1030 expectf(0.0, bounds
.Y
);
1031 expectf_(height
, bounds
.Height
, 0.2);
1032 set_rect_empty(&bounds
);
1033 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1034 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1036 expectf(0.0, bounds
.X
);
1037 expectf_(-100.0, bounds
.Y
, 0.2);
1038 expectf_(height
, bounds
.Height
, 0.2);
1039 set_rect_empty(&bounds
);
1040 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1041 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1044 expectf_(-636.706848, bounds
.X
, 0.05);
1046 expectf_(-175.257523, bounds
.Y
, 0.05);
1048 expectf_(1532.984985, bounds
.Height
, 0.05);
1050 /* scale + ratate + shear + translate matrix */
1051 status
= GdipTranslateMatrix(matrix
, 10.0, 20.0, MatrixOrderAppend
);
1053 status
= GdipSetWorldTransform(graphics
, matrix
);
1055 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1058 expect(1032, lf
.lfHeight
);
1059 expect(0, lf
.lfWidth
);
1060 expect_(3099, lf
.lfEscapement
, 1);
1061 expect_(3099, lf
.lfOrientation
, 1);
1062 status
= GdipGetFontHeight(font
, graphics
, &height
);
1064 expectf(120.703125, height
);
1065 set_rect_empty(&rect
);
1066 set_rect_empty(&bounds
);
1067 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1069 expectf(0.0, bounds
.X
);
1070 expectf(0.0, bounds
.Y
);
1072 expectf(height
+ margin_y
, bounds
.Height
);
1073 set_rect_empty(&rect
);
1074 set_rect_empty(&bounds
);
1075 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1077 expectf(0.0, bounds
.X
);
1078 expectf(0.0, bounds
.Y
);
1079 expectf_(height
, bounds
.Height
, 0.1);
1080 set_rect_empty(&bounds
);
1081 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1082 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1084 expectf(0.0, bounds
.X
);
1085 expectf_(-100.0, bounds
.Y
, 0.2);
1086 expectf_(height
, bounds
.Height
, 0.2);
1087 set_rect_empty(&bounds
);
1088 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1089 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1092 expectf_(-626.706848, bounds
.X
, 0.05);
1094 expectf_(-155.257523, bounds
.Y
, 0.05);
1096 expectf_(1532.984985, bounds
.Height
, 0.05);
1098 GdipDeleteMatrix(matrix
);
1099 GdipDeleteFont(font
);
1100 GdipDeleteGraphics(graphics
);
1101 GdipDeleteStringFormat(typographic
);
1102 GdipDeleteStringFormat(format
);
1108 struct GdiplusStartupInput gdiplusStartupInput
;
1109 ULONG_PTR gdiplusToken
;
1111 gdiplusStartupInput
.GdiplusVersion
= 1;
1112 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1113 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1114 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1116 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1118 test_font_transform();
1119 test_font_substitution();
1120 test_font_metrics();
1124 test_fontfamily_properties();
1126 test_installedfonts();
1127 test_heightgivendpi();
1129 GdiplusShutdown(gdiplusToken
);