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
];
733 GpGraphics
*graphics
;
735 GpFontFamily
*family
;
738 hdc
= CreateCompatibleDC(0);
739 status
= GdipCreateFromHDC(hdc
, &graphics
);
742 hfont
= GetStockObject(DEFAULT_GUI_FONT
);
743 ok(hfont
!= 0, "GetStockObject(DEFAULT_GUI_FONT) failed\n");
745 memset(&lf
, 0xfe, sizeof(lf
));
746 ret
= GetObjectA(hfont
, sizeof(lf
), &lf
);
747 ok(ret
== sizeof(lf
), "GetObject failed\n");
748 ok(!lstrcmpA(lf
.lfFaceName
, "MS Shell Dlg"), "wrong face name %s\n", lf
.lfFaceName
);
749 MultiByteToWideChar(CP_ACP
, 0, lf
.lfFaceName
, -1, ms_shell_dlg
, LF_FACESIZE
);
751 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
753 memset(&lf
, 0xfe, sizeof(lf
));
754 status
= GdipGetLogFontA(font
, graphics
, &lf
);
756 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
757 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
758 GdipDeleteFont(font
);
760 status
= GdipCreateFontFamilyFromName(ms_shell_dlg
, NULL
, &family
);
762 status
= GdipCreateFont(family
, 12, FontStyleRegular
, UnitPoint
, &font
);
764 memset(&lf
, 0xfe, sizeof(lf
));
765 status
= GdipGetLogFontA(font
, graphics
, &lf
);
767 ok(!lstrcmpA(lf
.lfFaceName
, "Microsoft Sans Serif") ||
768 !lstrcmpA(lf
.lfFaceName
, "Tahoma"), "wrong face name %s\n", lf
.lfFaceName
);
769 GdipDeleteFont(font
);
770 GdipDeleteFontFamily(family
);
772 status
= GdipCreateFontFamilyFromName(nonexistent
, NULL
, &family
);
773 ok(status
== FontFamilyNotFound
, "expected FontFamilyNotFound, got %d\n", status
);
775 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
776 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
778 memset(&lf
, 0xfe, sizeof(lf
));
779 status
= GdipGetLogFontA(font
, graphics
, &lf
);
781 ok(!lstrcmpA(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
782 GdipDeleteFont(font
);
785 lf
.lfFaceName
[0] = 0;
786 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
788 memset(&lf
, 0xfe, sizeof(lf
));
789 status
= GdipGetLogFontA(font
, graphics
, &lf
);
791 ok(!lstrcmpA(lf
.lfFaceName
, "Arial"), "wrong face name %s\n", lf
.lfFaceName
);
792 GdipDeleteFont(font
);
794 /* zeroing out lfWeight and lfCharSet leads to font creation failure */
797 lstrcpyA(lf
.lfFaceName
, "ThisFontShouldNotExist");
799 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
801 ok(status
== NotTrueTypeFont
|| broken(status
== FileNotFound
), /* before XP */
802 "expected NotTrueTypeFont, got %d\n", status
);
803 /* FIXME: remove when wine is fixed */
804 if (font
) GdipDeleteFont(font
);
807 lf
.lfFaceName
[0] = 0;
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
);
816 GdipDeleteGraphics(graphics
);
820 static void test_font_transform(void)
822 static const WCHAR string
[] = { 'A',0 };
827 GpGraphics
*graphics
;
829 GpStringFormat
*format
, *typographic
;
830 PointF pos
[1] = { { 0,0 } };
831 REAL height
, margin_y
;
834 hdc
= CreateCompatibleDC(0);
835 status
= GdipCreateFromHDC(hdc
, &graphics
);
838 status
= GdipSetPageUnit(graphics
, UnitPixel
);
841 status
= GdipCreateStringFormat(0, LANG_NEUTRAL
, &format
);
843 status
= GdipStringFormatGetGenericTypographic(&typographic
);
846 memset(&lf
, 0, sizeof(lf
));
847 lstrcpyA(lf
.lfFaceName
, "Tahoma");
850 status
= GdipCreateFontFromLogfontA(hdc
, &lf
, &font
);
853 margin_y
= 100.0 / 8.0;
855 /* identity matrix */
856 status
= GdipCreateMatrix(&matrix
);
858 status
= GdipSetWorldTransform(graphics
, matrix
);
860 status
= GdipGetLogFontA(font
, graphics
, &lf
);
862 expect(-100, lf
.lfHeight
);
863 expect(0, lf
.lfWidth
);
864 expect(0, lf
.lfEscapement
);
865 expect(0, lf
.lfOrientation
);
866 status
= GdipGetFontHeight(font
, graphics
, &height
);
868 expectf(120.703125, height
);
869 set_rect_empty(&rect
);
870 set_rect_empty(&bounds
);
871 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
873 expectf(0.0, bounds
.X
);
874 expectf(0.0, bounds
.Y
);
876 expectf(height
+ margin_y
, bounds
.Height
);
877 set_rect_empty(&rect
);
878 set_rect_empty(&bounds
);
879 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
881 expectf(0.0, bounds
.X
);
882 expectf(0.0, bounds
.Y
);
883 expectf_(height
, bounds
.Height
, 1.0);
884 set_rect_empty(&bounds
);
885 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
886 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
888 expectf(0.0, bounds
.X
);
889 expectf_(-100.0, bounds
.Y
, 0.05);
890 expectf_(height
, bounds
.Height
, 0.5);
891 set_rect_empty(&bounds
);
892 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
893 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
895 expectf(0.0, bounds
.X
);
896 expectf_(-100.0, bounds
.Y
, 0.05);
897 expectf_(height
, bounds
.Height
, 0.5);
900 status
= GdipScaleMatrix(matrix
, 2.0, 3.0, MatrixOrderAppend
);
902 status
= GdipSetWorldTransform(graphics
, matrix
);
904 status
= GdipGetLogFontA(font
, graphics
, &lf
);
906 expect(-300, lf
.lfHeight
);
907 expect(0, lf
.lfWidth
);
908 expect(0, lf
.lfEscapement
);
909 expect(0, lf
.lfOrientation
);
910 status
= GdipGetFontHeight(font
, graphics
, &height
);
912 expectf(120.703125, height
);
913 set_rect_empty(&rect
);
914 set_rect_empty(&bounds
);
915 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
917 expectf(0.0, bounds
.X
);
918 expectf(0.0, bounds
.Y
);
920 expectf(height
+ margin_y
, bounds
.Height
);
921 set_rect_empty(&rect
);
922 set_rect_empty(&bounds
);
923 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
925 expectf(0.0, bounds
.X
);
926 expectf(0.0, bounds
.Y
);
927 expectf_(height
, bounds
.Height
, 0.05);
928 set_rect_empty(&bounds
);
929 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
930 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
932 expectf(0.0, bounds
.X
);
933 expectf_(-100.0, bounds
.Y
, 0.05);
934 expectf_(height
, bounds
.Height
, 0.2);
935 set_rect_empty(&bounds
);
936 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
937 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
939 expectf(0.0, bounds
.X
);
941 expectf_(-300.0, bounds
.Y
, 0.15);
943 expectf(height
* 3.0, bounds
.Height
);
945 /* scale + ratate matrix */
946 status
= GdipRotateMatrix(matrix
, 45.0, MatrixOrderAppend
);
948 status
= GdipSetWorldTransform(graphics
, matrix
);
950 status
= GdipGetLogFontA(font
, graphics
, &lf
);
952 expect(-300, lf
.lfHeight
);
953 expect(0, lf
.lfWidth
);
954 expect_(3151, lf
.lfEscapement
, 1);
955 expect_(3151, lf
.lfOrientation
, 1);
956 status
= GdipGetFontHeight(font
, graphics
, &height
);
958 expectf(120.703125, height
);
959 set_rect_empty(&rect
);
960 set_rect_empty(&bounds
);
961 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
963 expectf(0.0, bounds
.X
);
964 expectf(0.0, bounds
.Y
);
966 expectf(height
+ margin_y
, bounds
.Height
);
967 set_rect_empty(&rect
);
968 set_rect_empty(&bounds
);
969 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
971 expectf(0.0, bounds
.X
);
972 expectf(0.0, bounds
.Y
);
973 expectf_(height
, bounds
.Height
, 0.05);
974 set_rect_empty(&bounds
);
975 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
976 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
978 expectf(0.0, bounds
.X
);
979 expectf_(-100.0, bounds
.Y
, 0.05);
980 expectf_(height
, bounds
.Height
, 0.2);
981 set_rect_empty(&bounds
);
982 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
983 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
986 expectf_(-43.814377, bounds
.X
, 0.05);
988 expectf_(-212.235611, bounds
.Y
, 0.05);
990 expectf_(340.847534, bounds
.Height
, 0.05);
992 /* scale + ratate + shear matrix */
993 status
= GdipShearMatrix(matrix
, 4.0, 5.0, MatrixOrderAppend
);
995 status
= GdipSetWorldTransform(graphics
, matrix
);
997 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1000 expect(1032, lf
.lfHeight
);
1001 expect(0, lf
.lfWidth
);
1002 expect_(3099, lf
.lfEscapement
, 1);
1003 expect_(3099, lf
.lfOrientation
, 1);
1004 status
= GdipGetFontHeight(font
, graphics
, &height
);
1006 expectf(120.703125, height
);
1007 set_rect_empty(&rect
);
1008 set_rect_empty(&bounds
);
1009 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1011 expectf(0.0, bounds
.X
);
1012 expectf(0.0, bounds
.Y
);
1014 expectf(height
+ margin_y
, bounds
.Height
);
1015 set_rect_empty(&rect
);
1016 set_rect_empty(&bounds
);
1017 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1019 expectf(0.0, bounds
.X
);
1020 expectf(0.0, bounds
.Y
);
1021 expectf_(height
, bounds
.Height
, 0.2);
1022 set_rect_empty(&bounds
);
1023 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1024 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1026 expectf(0.0, bounds
.X
);
1027 expectf_(-100.0, bounds
.Y
, 0.2);
1028 expectf_(height
, bounds
.Height
, 0.2);
1029 set_rect_empty(&bounds
);
1030 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1031 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1034 expectf_(-636.706848, bounds
.X
, 0.05);
1036 expectf_(-175.257523, bounds
.Y
, 0.05);
1038 expectf_(1532.984985, bounds
.Height
, 0.05);
1040 /* scale + ratate + shear + translate matrix */
1041 status
= GdipTranslateMatrix(matrix
, 10.0, 20.0, MatrixOrderAppend
);
1043 status
= GdipSetWorldTransform(graphics
, matrix
);
1045 status
= GdipGetLogFontA(font
, graphics
, &lf
);
1048 expect(1032, lf
.lfHeight
);
1049 expect(0, lf
.lfWidth
);
1050 expect_(3099, lf
.lfEscapement
, 1);
1051 expect_(3099, lf
.lfOrientation
, 1);
1052 status
= GdipGetFontHeight(font
, graphics
, &height
);
1054 expectf(120.703125, height
);
1055 set_rect_empty(&rect
);
1056 set_rect_empty(&bounds
);
1057 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, format
, &bounds
, NULL
, NULL
);
1059 expectf(0.0, bounds
.X
);
1060 expectf(0.0, bounds
.Y
);
1062 expectf(height
+ margin_y
, bounds
.Height
);
1063 set_rect_empty(&rect
);
1064 set_rect_empty(&bounds
);
1065 status
= GdipMeasureString(graphics
, string
, -1, font
, &rect
, typographic
, &bounds
, NULL
, NULL
);
1067 expectf(0.0, bounds
.X
);
1068 expectf(0.0, bounds
.Y
);
1069 expectf_(height
, bounds
.Height
, 0.1);
1070 set_rect_empty(&bounds
);
1071 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1072 DriverStringOptionsCmapLookup
, NULL
, &bounds
);
1074 expectf(0.0, bounds
.X
);
1075 expectf_(-100.0, bounds
.Y
, 0.2);
1076 expectf_(height
, bounds
.Height
, 0.2);
1077 set_rect_empty(&bounds
);
1078 status
= GdipMeasureDriverString(graphics
, (const UINT16
*)string
, -1, font
, pos
,
1079 DriverStringOptionsCmapLookup
, matrix
, &bounds
);
1082 expectf_(-626.706848, bounds
.X
, 0.05);
1084 expectf_(-155.257523, bounds
.Y
, 0.05);
1086 expectf_(1532.984985, bounds
.Height
, 0.05);
1088 GdipDeleteMatrix(matrix
);
1089 GdipDeleteFont(font
);
1090 GdipDeleteGraphics(graphics
);
1091 GdipDeleteStringFormat(typographic
);
1092 GdipDeleteStringFormat(format
);
1098 struct GdiplusStartupInput gdiplusStartupInput
;
1099 ULONG_PTR gdiplusToken
;
1101 gdiplusStartupInput
.GdiplusVersion
= 1;
1102 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1103 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1104 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1106 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1108 test_font_transform();
1109 test_font_substitution();
1110 test_font_metrics();
1114 test_fontfamily_properties();
1116 test_installedfonts();
1117 test_heightgivendpi();
1119 GdiplusShutdown(gdiplusToken
);