1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for CreateFontIndirect
5  * PROGRAMMERS:     Timo Kreuzer
6  *                  Katayama Hirofumi MZ
7  */
8 
9 #include "precomp.h"
10 
11 #define trace_if(val, msg) do { if (!(val)) trace(msg); } while (0)
12 
13 void
14 Test_CreateFontIndirectA(void)
15 {
16     LOGFONTA logfont;
17     HFONT hFont;
18     ULONG ret;
19     ENUMLOGFONTEXDVW elfedv2;
20 
21     logfont.lfHeight = 12;
22     logfont.lfWidth = 0;
23     logfont.lfEscapement = 0;
24     logfont.lfOrientation = 0;
25     logfont.lfWeight = FW_NORMAL;
26     logfont.lfItalic = 0;
27     logfont.lfUnderline = 0;
28     logfont.lfStrikeOut = 0;
29     logfont.lfCharSet = DEFAULT_CHARSET;
30     logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
31     logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
32     logfont.lfQuality = PROOF_QUALITY;
33     logfont.lfPitchAndFamily = DEFAULT_PITCH;
34     memset(logfont.lfFaceName, 'A', LF_FACESIZE);
35     hFont = CreateFontIndirectA(&logfont);
36     ok(hFont != 0, "CreateFontIndirectA failed\n");
37 
38     memset(&elfedv2, 0, sizeof(elfedv2));
39     ret = GetObjectW(hFont, sizeof(elfedv2), &elfedv2);
40     ok(ret == sizeof(ENUMLOGFONTEXW) + 2*sizeof(DWORD), "ret = %ld\n", ret);
41     ok(elfedv2.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == 0, "\n");
42     ok(elfedv2.elfEnumLogfontEx.elfFullName[0] == 0, "\n");
43 }
44 
45 void
46 Test_CreateFontIndirectW(void)
47 {
48     LOGFONTW logfont;
49     HFONT hFont;
50     ULONG ret;
51     ENUMLOGFONTEXDVW elfedv2;
52 
53     logfont.lfHeight = 12;
54     logfont.lfWidth = 0;
55     logfont.lfEscapement = 0;
56     logfont.lfOrientation = 0;
57     logfont.lfWeight = FW_NORMAL;
58     logfont.lfItalic = 0;
59     logfont.lfUnderline = 0;
60     logfont.lfStrikeOut = 0;
61     logfont.lfCharSet = DEFAULT_CHARSET;
62     logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
63     logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
64     logfont.lfQuality = PROOF_QUALITY;
65     logfont.lfPitchAndFamily = DEFAULT_PITCH;
66     memset(logfont.lfFaceName, 'A', LF_FACESIZE * 2);
67     hFont = CreateFontIndirectW(&logfont);
68     ok(hFont != 0, "CreateFontIndirectW failed\n");
69 
70     memset(&elfedv2, 0, sizeof(elfedv2));
71     ret = GetObjectW(hFont, sizeof(elfedv2), &elfedv2);
72     ok(ret == sizeof(ENUMLOGFONTEXW) + 2*sizeof(DWORD), "\n");
73     ok(elfedv2.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == ((WCHAR)'A' << 8) + 'A', "\n");
74     ok(elfedv2.elfEnumLogfontEx.elfFullName[0] == 0, "\n");
75     /* Theres a bunch of data in elfFullName ... */
76 }
77 
78 void
79 Test_CreateFontIndirectExA(void)
80 {
81     ENUMLOGFONTEXDVA elfedva, elfedva2;
82     ENUMLOGFONTEXDVW elfedvw;
83     ENUMLOGFONTEXA *penumlfa;
84     LOGFONTA *plogfonta;
85     HFONT hFont;
86     ULONG ret;
87 
88     memset(&elfedva, 0, sizeof(elfedva));
89     penumlfa = &elfedva.elfEnumLogfontEx;
90     plogfonta = &elfedva.elfEnumLogfontEx.elfLogFont;
91 
92     plogfonta->lfHeight = 12;
93     plogfonta->lfWidth = 0;
94     plogfonta->lfEscapement = 0;
95     plogfonta->lfOrientation = 0;
96     plogfonta->lfWeight = FW_NORMAL;
97     plogfonta->lfItalic = 0;
98     plogfonta->lfUnderline = 0;
99     plogfonta->lfStrikeOut = 0;
100     plogfonta->lfCharSet = DEFAULT_CHARSET;
101     plogfonta->lfOutPrecision = OUT_DEFAULT_PRECIS;
102     plogfonta->lfClipPrecision = CLIP_DEFAULT_PRECIS;
103     plogfonta->lfQuality = PROOF_QUALITY;
104     plogfonta->lfPitchAndFamily = DEFAULT_PITCH;
105 
106     memset(plogfonta->lfFaceName, 'A', LF_FACESIZE * sizeof(WCHAR));
107     memset(penumlfa->elfFullName, 'B', LF_FULLFACESIZE * sizeof(WCHAR));
108 
109     hFont = CreateFontIndirectExA(&elfedva);
110     ok(hFont != 0, "CreateFontIndirectExA failed\n");
111 
112     ret = GetObjectW(hFont, sizeof(elfedvw), &elfedvw);
113     ok(ret == sizeof(ENUMLOGFONTEXW) + 2*sizeof(DWORD), "\n");
114     ok(elfedvw.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == 0, "\n");
115     ok(elfedvw.elfEnumLogfontEx.elfFullName[LF_FULLFACESIZE-1] == 0, "\n");
116 
117     memset(&elfedva2, 0, sizeof(elfedva2));
118     ret = GetObjectA(hFont, sizeof(elfedva2), &elfedva2);
119     ok(ret == sizeof(ENUMLOGFONTEXDVA), "ret = %ld\n", ret);
120     ok(elfedva2.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == 0, "\n");
121     ok(elfedva2.elfEnumLogfontEx.elfFullName[LF_FULLFACESIZE-1] == 0, "\n");
122 }
123 
124 void
125 Test_CreateFontIndirectExW(void)
126 {
127     ENUMLOGFONTEXDVW elfedv, elfedv2;
128     ENUMLOGFONTEXDVA elfedva;
129     ENUMLOGFONTEXW *penumlfw;
130     LOGFONTW *plogfontw;
131     HFONT hFont;
132     ULONG ret;
133 
134     memset(&elfedv, 0, sizeof(elfedv));
135     penumlfw = &elfedv.elfEnumLogfontEx;
136     plogfontw = &elfedv.elfEnumLogfontEx.elfLogFont;
137 
138     plogfontw->lfHeight = 12;
139     plogfontw->lfWidth = 0;
140     plogfontw->lfEscapement = 0;
141     plogfontw->lfOrientation = 0;
142     plogfontw->lfWeight = FW_NORMAL;
143     plogfontw->lfItalic = 0;
144     plogfontw->lfUnderline = 0;
145     plogfontw->lfStrikeOut = 0;
146     plogfontw->lfCharSet = DEFAULT_CHARSET;
147     plogfontw->lfOutPrecision = OUT_DEFAULT_PRECIS;
148     plogfontw->lfClipPrecision = CLIP_DEFAULT_PRECIS;
149     plogfontw->lfQuality = PROOF_QUALITY;
150     plogfontw->lfPitchAndFamily = DEFAULT_PITCH;
151 
152     memset(plogfontw->lfFaceName, 'A', LF_FACESIZE * sizeof(WCHAR));
153     memset(penumlfw->elfFullName, 'B', LF_FULLFACESIZE * sizeof(WCHAR));
154 
155     hFont = CreateFontIndirectExW(&elfedv);
156     ok(hFont != 0, "CreateFontIndirectExW failed\n");
157 
158     memset(&elfedv2, 0, sizeof(elfedv2));
159     ret = GetObjectW(hFont, sizeof(elfedv2), &elfedv2);
160     ok(ret == sizeof(ENUMLOGFONTEXW) + 2*sizeof(DWORD), "\n");
161     ok(elfedv2.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == ((WCHAR)'A' << 8) + 'A', "\n");
162     ok(elfedv2.elfEnumLogfontEx.elfFullName[LF_FULLFACESIZE-1] == ((WCHAR)'B' << 8) + 'B', "\n");
163 
164     memset(&elfedva, 0, sizeof(elfedva));
165     ret = GetObjectA(hFont, sizeof(elfedva), &elfedva);
166     ok(ret == sizeof(ENUMLOGFONTEXDVA), "\n");
167     ok(elfedva.elfEnumLogfontEx.elfLogFont.lfFaceName[LF_FACESIZE-1] == '?', "\n");
168     ok(elfedva.elfEnumLogfontEx.elfFullName[LF_FULLFACESIZE-1] == 0, "\n");
169 }
170 
171 static INT CALLBACK
172 is_truetype_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm,
173                       DWORD type, LPARAM lParam)
174 {
175     if (type != TRUETYPE_FONTTYPE) return 1;
176 
177     return 0;
178 }
179 
180 static BOOL is_truetype_font_installed(HDC hDC, const char *name)
181 {
182     if (!EnumFontFamiliesA(hDC, name, is_truetype_font_proc, 0))
183         return TRUE;
184     return FALSE;
185 }
186 
187 static INT CALLBACK
188 is_charset_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm,
189                                DWORD type, LPARAM lParam)
190 {
191     if (ntm->tmCharSet == (BYTE)lParam)
192         return 0;
193     return 1;
194 }
195 
196 static BOOL is_charset_font_installed(HDC hDC, BYTE CharSet)
197 {
198     if (!EnumFontFamiliesA(hDC, NULL, is_charset_font_proc, CharSet))
199         return TRUE;
200     return FALSE;
201 }
202 
203 /* TMPF_FIXED_PITCH is confusing. brain-damaged api */
204 #define _TMPF_VAR_PITCH     TMPF_FIXED_PITCH
205 
206 static INT CALLBACK
207 is_fixed_charset_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm,
208                                      DWORD type, LPARAM lParam)
209 {
210     if (ntm->tmCharSet == (BYTE)lParam && !(ntm->tmPitchAndFamily & _TMPF_VAR_PITCH))
211         return 0;
212     return 1;
213 }
214 
215 static BOOL
216 is_fixed_charset_font_installed(HDC hDC, BYTE CharSet)
217 {
218     if (!EnumFontFamiliesA(hDC, NULL, is_fixed_charset_font_proc, CharSet))
219         return TRUE;
220     return FALSE;
221 }
222 
223 static void
224 Test_FontPresence(void)
225 {
226     HDC hDC;
227 
228     hDC = CreateCompatibleDC(NULL);
229 
230     ok(is_truetype_font_installed(hDC, "Arial"), "'Arial' is not found\n");
231     ok(is_truetype_font_installed(hDC, "Courier New"), "'Courier New' is not found\n");
232     ok(is_truetype_font_installed(hDC, "Marlett"), "'Marlett' is not found\n");
233     ok(is_truetype_font_installed(hDC, "MS Shell Dlg"), "'MS Shell Dlg' is not found\n");
234     ok(is_truetype_font_installed(hDC, "Tahoma"), "'Tahoma' is not found\n");
235     ok(is_truetype_font_installed(hDC, "Times New Roman"), "'Times New Roman' is not found\n");
236 
237     ok(is_charset_font_installed(hDC, ANSI_CHARSET), "ANSI_CHARSET fonts are not found\n");
238     ok(is_charset_font_installed(hDC, SYMBOL_CHARSET), "SYMBOL_CHARSET fonts are not found\n");
239     trace_if(is_charset_font_installed(hDC, SHIFTJIS_CHARSET), "SHIFTJIS_CHARSET fonts are not found\n");
240     trace_if(is_charset_font_installed(hDC, HANGUL_CHARSET), "HANGUL_CHARSET fonts are not found\n");
241     trace_if(is_charset_font_installed(hDC, GB2312_CHARSET), "GB2312_CHARSET fonts are not found\n");
242     trace_if(is_charset_font_installed(hDC, CHINESEBIG5_CHARSET), "CHINESEBIG5_CHARSET fonts are not found\n");
243     ok(is_charset_font_installed(hDC, OEM_CHARSET), "OEM_CHARSET fonts are not found\n");
244     trace_if(is_charset_font_installed(hDC, JOHAB_CHARSET), "JOHAB_CHARSET fonts are not found\n");
245     trace_if(is_charset_font_installed(hDC, HEBREW_CHARSET), "HEBREW_CHARSET fonts are not found\n");
246     trace_if(is_charset_font_installed(hDC, ARABIC_CHARSET), "ARABIC_CHARSET fonts are not found\n");
247     trace_if(is_charset_font_installed(hDC, GREEK_CHARSET), "GREEK_CHARSET fonts are not found\n");
248     trace_if(is_charset_font_installed(hDC, TURKISH_CHARSET), "TURKISH_CHARSET fonts are not found\n");
249     trace_if(is_charset_font_installed(hDC, VIETNAMESE_CHARSET), "VIETNAMESE_CHARSET fonts are not found\n");
250     trace_if(is_charset_font_installed(hDC, THAI_CHARSET), "THAI_CHARSET fonts are not found\n");
251     trace_if(is_charset_font_installed(hDC, EASTEUROPE_CHARSET), "EASTEUROPE_CHARSET fonts are not found\n");
252     trace_if(is_charset_font_installed(hDC, RUSSIAN_CHARSET), "RUSSIAN_CHARSET fonts are not found\n");
253     trace_if(is_charset_font_installed(hDC, MAC_CHARSET), "MAC_CHARSET fonts are not found\n");
254     trace_if(is_charset_font_installed(hDC, BALTIC_CHARSET), "BALTIC_CHARSET fonts are not found\n");
255 
256     ok(is_fixed_charset_font_installed(hDC, ANSI_CHARSET), "fixed ANSI_CHARSET fonts are not found\n");
257     trace_if(is_fixed_charset_font_installed(hDC, SHIFTJIS_CHARSET), "fixed SHIFTJIS_CHARSET fonts are not found\n");
258     trace_if(is_fixed_charset_font_installed(hDC, HANGUL_CHARSET), "fixed HANGUL_CHARSET fonts are not found\n");
259     trace_if(is_fixed_charset_font_installed(hDC, GB2312_CHARSET), "fixed GB2312_CHARSET fonts are not found\n");
260     trace_if(is_fixed_charset_font_installed(hDC, CHINESEBIG5_CHARSET), "fixed CHINESEBIG5_CHARSET fonts are not found\n");
261     ok(is_fixed_charset_font_installed(hDC, OEM_CHARSET), "fixed OEM_CHARSET fonts are not found\n");
262     trace_if(is_fixed_charset_font_installed(hDC, JOHAB_CHARSET), "fixed JOHAB_CHARSET fonts are not found\n");
263     trace_if(is_fixed_charset_font_installed(hDC, HEBREW_CHARSET), "fixed HEBREW_CHARSET fonts are not found\n");
264     trace_if(is_fixed_charset_font_installed(hDC, ARABIC_CHARSET), "fixed ARABIC_CHARSET fonts are not found\n");
265     trace_if(is_fixed_charset_font_installed(hDC, GREEK_CHARSET), "fixed GREEK_CHARSET fonts are not found\n");
266     trace_if(is_fixed_charset_font_installed(hDC, TURKISH_CHARSET), "fixed TURKISH_CHARSET fonts are not found\n");
267     trace_if(is_fixed_charset_font_installed(hDC, VIETNAMESE_CHARSET), "fixed VIETNAMESE_CHARSET fonts are not found\n");
268     trace_if(is_fixed_charset_font_installed(hDC, THAI_CHARSET), "fixed THAI_CHARSET fonts are not found\n");
269     trace_if(is_fixed_charset_font_installed(hDC, EASTEUROPE_CHARSET), "fixed EASTEUROPE_CHARSET fonts are not found\n");
270     trace_if(is_fixed_charset_font_installed(hDC, RUSSIAN_CHARSET), "fixed RUSSIAN_CHARSET fonts are not found\n");
271     trace_if(is_fixed_charset_font_installed(hDC, MAC_CHARSET), "fixed MAC_CHARSET fonts are not found\n");
272     trace_if(is_fixed_charset_font_installed(hDC, BALTIC_CHARSET), "fixed BALTIC_CHARSET fonts are not found\n");
273 
274     DeleteDC(hDC);
275 }
276 
277 /* NOTE: TMPF_FIXED_PITCH is confusing and brain-dead. */
278 #define _TMPF_VAR_PITCH TMPF_FIXED_PITCH
279 
280 typedef enum TRISTATE {
281     TS_UNKNOWN,
282     TS_TRUE,
283     TS_FALSE
284 } TRISTATE;
285 
286 typedef struct FONT_SEL_TEST {
287     CHAR        FaceNameBefore[LF_FACESIZE];
288 
289     BYTE        CharSetBefore;
290     BYTE        CharSetAfter;
291 
292     TRISTATE    BoldBefore;
293     TRISTATE    BoldAfter;
294 
295     BYTE        ItalicBefore;
296     TRISTATE    ItalicAfter;
297 
298     BYTE        UnderlineBefore;
299     TRISTATE    UnderlineAfter;
300 
301     BYTE        StruckOutBefore;
302     TRISTATE    StruckOutAfter;
303 
304     TRISTATE    FixedPitchBefore;
305     TRISTATE    FixedPitchAfter;
306 } FONT_SEL_TEST;
307 
308 static FONT_SEL_TEST g_Entries[] =
309 {
310     /* Entry #0: default */
311     {
312         "",
313         DEFAULT_CHARSET, DEFAULT_CHARSET,
314         TS_UNKNOWN, TS_FALSE,
315         TS_UNKNOWN, TS_FALSE,
316         TS_UNKNOWN, TS_FALSE,
317         TS_UNKNOWN, TS_FALSE,
318         TS_UNKNOWN, TS_FALSE
319     },
320     /* Entry #1: symbol font*/
321     {
322         "",
323         SYMBOL_CHARSET, SYMBOL_CHARSET
324     },
325     /* Entry #2: non-bold */
326     {
327         "",
328         DEFAULT_CHARSET, DEFAULT_CHARSET,
329         TS_FALSE, TS_FALSE
330     },
331     /* Entry #3: bold */
332     {
333         "",
334         DEFAULT_CHARSET, DEFAULT_CHARSET,
335         TS_TRUE, TS_TRUE
336     },
337     /* Entry #4: non-italic (without specifying bold) */
338     {
339         "",
340         DEFAULT_CHARSET, DEFAULT_CHARSET,
341         TS_UNKNOWN, TS_FALSE,
342         FALSE, TS_FALSE
343     },
344     /* Entry #5: italic (without specifying bold) */
345     {
346         "",
347         DEFAULT_CHARSET, DEFAULT_CHARSET,
348         TS_UNKNOWN, TS_FALSE,
349         TRUE, TS_TRUE
350     },
351     /* Entry #6: non-underline (without specifying bold) */
352     {
353         "",
354         DEFAULT_CHARSET, DEFAULT_CHARSET,
355         TS_UNKNOWN, TS_FALSE,
356         FALSE, TS_UNKNOWN,
357         FALSE, TS_FALSE
358     },
359     /* Entry #7: underline (without specifying bold) */
360     {
361         "",
362         DEFAULT_CHARSET, DEFAULT_CHARSET,
363         TS_UNKNOWN, TS_FALSE,
364         FALSE, TS_UNKNOWN,
365         TRUE, TS_TRUE
366     },
367     /* Entry #8: struck-out (without specifying bold) */
368     {
369         "",
370         DEFAULT_CHARSET, DEFAULT_CHARSET,
371         TS_UNKNOWN, TS_FALSE,
372         FALSE, TS_UNKNOWN,
373         FALSE, TS_UNKNOWN,
374         TRUE, TS_TRUE
375     },
376     /* Entry #9: non-struck-out (without specifying bold) */
377     {
378         "",
379         DEFAULT_CHARSET, DEFAULT_CHARSET,
380         TS_UNKNOWN, TS_FALSE,
381         FALSE, TS_UNKNOWN,
382         FALSE, TS_UNKNOWN,
383         FALSE, TS_FALSE
384     },
385     /* Entry #10: fixed-pitch (without specifying bold) */
386     {
387         "",
388         DEFAULT_CHARSET, DEFAULT_CHARSET,
389         TS_UNKNOWN, TS_FALSE,
390         FALSE, TS_UNKNOWN,
391         FALSE, TS_UNKNOWN,
392         FALSE, TS_UNKNOWN,
393         TS_TRUE, TS_TRUE
394     },
395     /* Entry #11: non-fixed-pitch (without specifying bold) */
396     {
397         "",
398         DEFAULT_CHARSET, DEFAULT_CHARSET,
399         TS_UNKNOWN, TS_FALSE,
400         FALSE, TS_UNKNOWN,
401         FALSE, TS_UNKNOWN,
402         FALSE, TS_UNKNOWN,
403         TS_FALSE, TS_FALSE
404     },
405     /* Entry #12: fixed-pitch and bold */
406     {
407         "",
408         DEFAULT_CHARSET, DEFAULT_CHARSET,
409         TS_TRUE, TS_TRUE,
410         FALSE, TS_UNKNOWN,
411         FALSE, TS_UNKNOWN,
412         FALSE, TS_UNKNOWN,
413         TS_TRUE, TS_TRUE
414     },
415     /* Entry #13: non-fixed-pitch and bold */
416     {
417         "",
418         DEFAULT_CHARSET, DEFAULT_CHARSET,
419         TS_TRUE, TS_TRUE,
420         FALSE, TS_UNKNOWN,
421         FALSE, TS_UNKNOWN,
422         FALSE, TS_UNKNOWN,
423         TS_FALSE, TS_FALSE
424     },
425     /* Entry #14: OEM_CHARSET */
426     {
427         "",
428         OEM_CHARSET, OEM_CHARSET,
429         TS_UNKNOWN, TS_FALSE
430     },
431     /* Entry #15: OEM_CHARSET and bold */
432     {
433         "",
434         OEM_CHARSET, OEM_CHARSET,
435         TS_TRUE, TS_TRUE
436     },
437     /* Entry #16: OEM_CHARSET and fixed-pitch */
438     {
439         "",
440         OEM_CHARSET, OEM_CHARSET,
441         TS_UNKNOWN, TS_FALSE,
442         FALSE, TS_UNKNOWN,
443         FALSE, TS_UNKNOWN,
444         FALSE, TS_UNKNOWN,
445         TS_TRUE, TS_TRUE
446     },
447     /* Entry #17: CHINESEBIG5_CHARSET (Chinese) */
448     {
449         "",
450         CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET,
451         TS_UNKNOWN, TS_FALSE
452     },
453     /* Entry #18: CHINESEBIG5_CHARSET and bold */
454     {
455         "",
456         CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET,
457         TS_TRUE, TS_TRUE
458     },
459     /* Entry #19: CHINESEBIG5_CHARSET and fixed-pitch */
460     {
461         "",
462         CHINESEBIG5_CHARSET, CHINESEBIG5_CHARSET,
463         TS_UNKNOWN, TS_FALSE,
464         FALSE, TS_UNKNOWN,
465         FALSE, TS_UNKNOWN,
466         FALSE, TS_UNKNOWN,
467         TS_TRUE, TS_TRUE
468     },
469     /* Entry #20: GB2312_CHARSET (Chinese) */
470     {
471         "",
472         GB2312_CHARSET, GB2312_CHARSET,
473         TS_UNKNOWN, TS_FALSE
474     },
475     /* Entry #21: GB2312_CHARSET and bold */
476     {
477         "",
478         GB2312_CHARSET, GB2312_CHARSET,
479         TS_TRUE, TS_TRUE
480     },
481     /* Entry #22: GB2312_CHARSET and fixed-pitch */
482     {
483         "",
484         GB2312_CHARSET, GB2312_CHARSET,
485         TS_UNKNOWN, TS_FALSE,
486         FALSE, TS_UNKNOWN,
487         FALSE, TS_UNKNOWN,
488         FALSE, TS_UNKNOWN,
489         TS_TRUE, TS_TRUE
490     },
491     /* Entry #23: RUSSIAN_CHARSET (Russian) */
492     {
493         "",
494         RUSSIAN_CHARSET, RUSSIAN_CHARSET,
495         TS_UNKNOWN, TS_FALSE
496     },
497     /* Entry #24: RUSSIAN_CHARSET and bold */
498     {
499         "",
500         RUSSIAN_CHARSET, RUSSIAN_CHARSET,
501         TS_TRUE, TS_TRUE
502     },
503     /* Entry #25: RUSSIAN_CHARSET and italic */
504     {
505         "",
506         RUSSIAN_CHARSET, RUSSIAN_CHARSET,
507         TS_UNKNOWN, TS_FALSE,
508         TRUE, TS_TRUE,
509     },
510     /* Entry #26: RUSSIAN_CHARSET and fixed-pitch */
511     {
512         "",
513         RUSSIAN_CHARSET, RUSSIAN_CHARSET,
514         TS_UNKNOWN, TS_FALSE,
515         FALSE, TS_UNKNOWN,
516         FALSE, TS_UNKNOWN,
517         FALSE, TS_UNKNOWN,
518         TS_TRUE, TS_TRUE
519     },
520     /* Entry #27: SHIFTJIS_CHARSET (Japanese) */
521     {
522         "",
523         SHIFTJIS_CHARSET, SHIFTJIS_CHARSET,
524         TS_UNKNOWN, TS_FALSE
525     },
526     /* Entry #28: SHIFTJIS_CHARSET and bold */
527     {
528         "",
529         SHIFTJIS_CHARSET, SHIFTJIS_CHARSET,
530         TS_TRUE, TS_TRUE
531     },
532     /* Entry #29: SHIFTJIS_CHARSET and fixed-pitch */
533     {
534         "",
535         SHIFTJIS_CHARSET, SHIFTJIS_CHARSET,
536         TS_UNKNOWN, TS_FALSE,
537         FALSE, TS_UNKNOWN,
538         FALSE, TS_UNKNOWN,
539         FALSE, TS_UNKNOWN,
540         TS_TRUE, TS_TRUE
541     },
542     /* Entry #30: HANGUL_CHARSET (Korean) */
543     {
544         "",
545         HANGUL_CHARSET, HANGUL_CHARSET,
546         TS_UNKNOWN, TS_FALSE
547     },
548     /* Entry #31: HANGUL_CHARSET and bold */
549     {
550         "",
551         HANGUL_CHARSET, HANGUL_CHARSET,
552         TS_TRUE, TS_TRUE
553     },
554     /* Entry #32: HANGUL_CHARSET and fixed-pitch */
555     {
556         "",
557         HANGUL_CHARSET, HANGUL_CHARSET,
558         TS_UNKNOWN, TS_FALSE,
559         FALSE, TS_UNKNOWN,
560         FALSE, TS_UNKNOWN,
561         FALSE, TS_UNKNOWN,
562         TS_TRUE, TS_TRUE
563     },
564     /* Entry #33: JOHAB_CHARSET (Korean) */
565     {
566         "",
567         JOHAB_CHARSET, JOHAB_CHARSET,
568         TS_UNKNOWN, TS_UNKNOWN
569     },
570     /* Entry #34: JOHAB_CHARSET and bold */
571     {
572         "",
573         JOHAB_CHARSET, JOHAB_CHARSET,
574         TS_TRUE, TS_TRUE
575     },
576     /* Entry #35: JOHAB_CHARSET and fixed-pitch */
577     {
578         "",
579         JOHAB_CHARSET, JOHAB_CHARSET,
580         TS_UNKNOWN, TS_UNKNOWN,
581         FALSE, TS_UNKNOWN,
582         FALSE, TS_UNKNOWN,
583         FALSE, TS_UNKNOWN,
584         TS_TRUE, TS_TRUE
585     },
586     /* Entry #36: THAI_CHARSET (Thai) */
587     {
588         "",
589         THAI_CHARSET, THAI_CHARSET,
590         TS_UNKNOWN, TS_FALSE
591     },
592     /* Entry #37: THAI_CHARSET and bold */
593     {
594         "",
595         THAI_CHARSET, THAI_CHARSET,
596         TS_TRUE, TS_TRUE
597     },
598     /* Entry #38: THAI_CHARSET and fixed-pitch */
599     {
600         "",
601         THAI_CHARSET, THAI_CHARSET,
602         TS_UNKNOWN, TS_FALSE,
603         FALSE, TS_UNKNOWN,
604         FALSE, TS_UNKNOWN,
605         FALSE, TS_UNKNOWN,
606         TS_TRUE, TS_TRUE
607     },
608     /* Entry #39: GREEK_CHARSET (Greek) */
609     {
610         "",
611         GREEK_CHARSET, GREEK_CHARSET,
612         TS_UNKNOWN, TS_FALSE
613     },
614     /* Entry #40: GREEK_CHARSET and bold */
615     {
616         "",
617         GREEK_CHARSET, GREEK_CHARSET,
618         TS_TRUE, TS_TRUE
619     },
620     /* Entry #41: GREEK_CHARSET and italic */
621     {
622         "",
623         GREEK_CHARSET, GREEK_CHARSET,
624         TS_UNKNOWN, TS_FALSE,
625         TRUE, TS_TRUE
626     },
627     /* Entry #42: GREEK_CHARSET and fixed-pitch */
628     {
629         "",
630         GREEK_CHARSET, GREEK_CHARSET,
631         TS_UNKNOWN, TS_FALSE,
632         FALSE, TS_UNKNOWN,
633         FALSE, TS_UNKNOWN,
634         FALSE, TS_UNKNOWN,
635         TS_TRUE, TS_TRUE
636     },
637     /* Entry #43: "Marlett" */
638     {
639         "Marlett",
640         DEFAULT_CHARSET, SYMBOL_CHARSET
641     },
642     /* Entry #43: "Arial" */
643     {
644         "Arial",
645         DEFAULT_CHARSET, DEFAULT_CHARSET,
646         TS_UNKNOWN, TS_FALSE,
647         FALSE, TS_UNKNOWN,
648         FALSE, TS_UNKNOWN,
649         FALSE, TS_UNKNOWN,
650         TS_UNKNOWN, TS_FALSE
651     },
652     /* Entry #44: "Courier" */
653     {
654         "Courier",
655         DEFAULT_CHARSET, DEFAULT_CHARSET,
656         TS_UNKNOWN, TS_FALSE,
657         FALSE, TS_UNKNOWN,
658         FALSE, TS_UNKNOWN,
659         FALSE, TS_UNKNOWN,
660         TS_UNKNOWN, TS_TRUE
661     }
662 };
663 
664 static void
665 Test_FontSelectionEntry(HDC hDC, UINT nIndex, FONT_SEL_TEST *Entry)
666 {
667     LOGFONTA        lf;
668     HFONT           hFont;
669     HGDIOBJ         hFontOld;
670     TEXTMETRICA     tm;
671 
672     ZeroMemory(&lf, sizeof(lf));
673 
674     if (Entry->FaceNameBefore[0])
675         lstrcpynA(lf.lfFaceName, Entry->FaceNameBefore, _countof(lf.lfFaceName));
676 
677     lf.lfCharSet = Entry->CharSetBefore;
678 
679     if (Entry->BoldBefore == TS_TRUE)
680         lf.lfWeight = FW_BOLD;
681     else if (Entry->BoldBefore == TS_FALSE)
682         lf.lfWeight = FW_NORMAL;
683     else
684         lf.lfWeight = FW_DONTCARE;
685 
686     lf.lfItalic = Entry->ItalicBefore;
687     lf.lfUnderline = Entry->UnderlineBefore;
688     lf.lfStrikeOut = Entry->StruckOutBefore;
689 
690     if (Entry->FixedPitchBefore == TS_TRUE)
691         lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
692     else if (Entry->FixedPitchBefore == TS_FALSE)
693         lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;
694     else
695         lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
696 
697     hFont = CreateFontIndirectA(&lf);
698     ok(hFont != NULL, "Entry #%u: hFont failed\n", nIndex);
699 
700     hFontOld = SelectObject(hDC, hFont);
701     {
702         ok(GetTextMetricsA(hDC, &tm), "Entry #%u: GetTextMetricsA failed\n", nIndex);
703 
704         if (Entry->CharSetAfter != DEFAULT_CHARSET)
705             ok(tm.tmCharSet == Entry->CharSetAfter, "Entry #%u: CharSet mismatched, it was %u\n", nIndex, tm.tmCharSet);
706 
707         if (Entry->BoldAfter == TS_TRUE)
708             ok(tm.tmWeight >= FW_BOLD, "Entry #%u: Weight was non-bold\n", nIndex);
709         else if (Entry->BoldAfter == TS_FALSE)
710             ok(tm.tmWeight <= FW_MEDIUM, "Entry #%u: Weight was bold\n", nIndex);
711 
712         if (Entry->ItalicAfter == TS_TRUE)
713             ok(tm.tmItalic, "Entry #%u: Italic was non-italic\n", nIndex);
714         else if (Entry->ItalicAfter == TS_FALSE)
715             ok(!tm.tmItalic, "Entry #%u: Italic was italic\n", nIndex);
716 
717         if (Entry->UnderlineAfter == TS_TRUE)
718             ok(tm.tmUnderlined, "Entry #%u: Underlined was FALSE\n", nIndex);
719         else if (Entry->UnderlineAfter == TS_FALSE)
720             ok(!tm.tmUnderlined, "Entry #%u: Underlined was TRUE\n", nIndex);
721 
722         if (Entry->StruckOutAfter == TS_TRUE)
723             ok(tm.tmStruckOut, "Entry #%u: Struck-out was FALSE\n", nIndex);
724         else if (Entry->StruckOutAfter == TS_FALSE)
725             ok(!tm.tmStruckOut, "Entry #%u: Struck-out was TRUE\n", nIndex);
726 
727         if (Entry->FixedPitchAfter == TS_TRUE)
728             ok(!(tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was non-fixed-pitch\n", nIndex);
729         else if (Entry->FixedPitchAfter == TS_FALSE)
730             ok((tm.tmPitchAndFamily & _TMPF_VAR_PITCH), "Entry #%u: Pitch mismatched, it was fixed-pitch\n", nIndex);
731     }
732     SelectObject(hDC, hFontOld);
733     DeleteObject(hFont);
734 }
735 
736 static void
737 Test_FontSelection(void)
738 {
739     UINT nIndex;
740     HDC hDC;
741 
742     hDC = CreateCompatibleDC(NULL);
743     for (nIndex = 0; nIndex < _countof(g_Entries); ++nIndex)
744     {
745         if (!is_charset_font_installed(hDC, g_Entries[nIndex].CharSetBefore))
746             skip("charset not available: 0x%x\n", g_Entries[nIndex].CharSetBefore);
747         else
748             Test_FontSelectionEntry(hDC, nIndex, g_Entries + nIndex);
749     }
750     DeleteDC(hDC);
751 }
752 
753 
754 START_TEST(CreateFontIndirect)
755 {
756     Test_CreateFontIndirectA();
757     Test_CreateFontIndirectW();
758     Test_CreateFontIndirectExA();
759     Test_CreateFontIndirectExW();
760     Test_FontPresence();
761     Test_FontSelection();
762 }
763 
764