-
Notifications
You must be signed in to change notification settings - Fork 1
/
FontSetViewer.cpp
3234 lines (2753 loc) · 119 KB
/
FontSetViewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// FontSet="http://dwayner-test/Fonts/Fonts.json" DWriteDLL="O:\fbl_grfx_dev_proto.obj.x86chk\windows\core\text\dll\win8\objchk\i386\DWrite.dll"
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
//
// Contents: Main user interface window.
//
//----------------------------------------------------------------------------
#include "precomp.h"
#include "resources/resource.h"
#include "font/DWritEx.h"
#include "FontSetViewer.h"
////////////////////////////////////////
// Main entry.
// Shows an error message if the function returned a failing HRESULT,
// then returning that same error code.
HRESULT ShowMessageIfFailed(HRESULT functionResult, const wchar_t* message);
HRESULT CopyImageToClipboard(HWND hwnd, HDC hdc, bool isUpsideDown);
namespace
{
std::wstring g_dwriteDllName = L"dwrite.dll"; // Point elsewhere to load a custom one.
bool g_startBlankList = false;
const static wchar_t* g_locales[][2] = {
{ L"English US", L"en-US"},
{ L"English UK", L"en-GB"},
{ L"الْعَرَبيّة Arabic Egypt", L"ar-EG"},
{ L"الْعَرَبيّة Arabic Iraq", L"ar-IQ"},
{ L"中文 Chinese PRC", L"zh-CN"},
{ L"中文 Chinese Taiwan", L"zh-TW"},
{ L"한글 Hangul Korea", L"ko-KR"},
{ L"עִבְרִית Hebrew Israel", L"he-IL"},
{ L"हिन्दी Hindi India", L"hi-IN"},
{ L"日本語 Japanese", L"ja-JP"},
{ L"Romania" , L"ro-RO"},
{ L"Русский язык Russian", L"ru-RU"},
{ L"ca-ES", L"ca-ES"},
{ L"cs-CZ", L"cs-CZ"},
{ L"da-DK", L"da-DK"},
{ L"de-DE", L"de-DE"},
{ L"el-GR", L"el-GR"},
{ L"es-ES", L"es-ES"},
{ L"es-ES_tradnl", L"es-ES_tradnl"},
{ L"es-MX", L"es-MX"},
{ L"eu-ES", L"eu-ES"},
{ L"fi-FI", L"fi-FI"},
{ L"fr-CA", L"fr-CA"},
{ L"fr-FR", L"fr-FR"},
{ L"hu-HU", L"hu-HU"},
{ L"it-IT", L"it-IT"},
{ L"nb-NO", L"nb-NO"},
{ L"nl-NL", L"nl-NL"},
{ L"pl-PL", L"pl-PL"},
{ L"pt-BR", L"pt-BR"},
{ L"pt-PT", L"pt-PT"},
{ L"ru-RU", L"ru-RU"},
{ L"sk-SK", L"sk-SK"},
{ L"sl-SI", L"sl-SI"},
{ L"sv-SE", L"sv-SE"},
{ L"tr-TR", L"tr-TR"},
};
const static wchar_t* g_fontCollectionFilterModeNames[] = {
L"Ungrouped", // DWRITE_FONT_PROPERTY_ID_NONE
L"WssFamilyName", // DWRITE_FONT_PROPERTY_ID_WEIGHT_STRETCH_STYLE_FAMILY_NAME
L"TypographicFamilyName",// DWRITE_FONT_PROPERTY_ID_TYPOGRAPHIC_FAMILY_NAME
L"WssFaceName", // DWRITE_FONT_PROPERTY_ID_WEIGHT_STRETCH_STYLE_FAMILY_FACE_NAME
L"FullName", // DWRITE_FONT_PROPERTY_ID_FULL_NAME
L"Win32FamilyName", // DWRITE_FONT_PROPERTY_ID_WIN32_FAMILY_NAME
L"PostscriptName", // DWRITE_FONT_PROPERTY_ID_POSTSCRIPT_NAME
L"DesignedScriptTag", // DWRITE_FONT_PROPERTY_ID_DESIGN_SCRIPT_LANGUAGE_TAG,
L"SupportedScriptTag", // DWRITE_FONT_PROPERTY_ID_SUPPORTED_SCRIPT_LANGUAGE_TAG
L"SemanticTag", // DWRITE_FONT_PROPERTY_ID_SEMANTIC_TAG
L"Weight", // DWRITE_FONT_PROPERTY_ID_WEIGHT
L"Stretch", // DWRITE_FONT_PROPERTY_ID_STRETCH
L"Style", // DWRITE_FONT_PROPERTY_ID_STYLE
L"TypographicFaceName", // DWRITE_FONT_PROPERTY_ID_TYPOGRAPHIC_FACE_NAME
};
static_assert(ARRAYSIZE(g_fontCollectionFilterModeNames) == int(MainWindow::FontCollectionFilterMode::Total), "Update the name list to match the actual count.");
struct FamilyNameTags
{
wchar_t const* fontName;
wchar_t const* tags;
wchar_t const* scripts;
};
static FamilyNameTags const g_knownFamilyNameTags[] =
{
{ L"Agency FB", L"Display;", L"Latn;" },
{ L"Aharoni", L"Text;", L"Hebr;" },
{ L"Aharoni Bold", L"Display;", L"Hebr;" },
{ L"Ahn B", L"Display;", L"Kore;" },
{ L"Ahn L", L"Text;", L"Kore;" },
{ L"Ahn M", L"Text;", L"Kore;" },
{ L"Aldhabi", L"Text;", L"Arab;" },
{ L"Algerian", L"Display;", L"Latn;" },
{ L"Ami R", L"Text;", L"Kore;" },
{ L"Andalus", L"Display;", L"Arab;" },
{ L"Angsana New", L"Text;", L"Thai;" },
{ L"AngsanaUPC", L"Text;", L"Thai;" },
{ L"Aparajita", L"Display;", L"Deva;" },
{ L"Arabic Typesetting", L"Text;", L"Arab;" },
{ L"Arial", L"Text;", L"Latn;Grek;Cyrl;Hebr;Arab;" },
{ L"Arial Rounded MT", L"Display;", L"Latn;" },
{ L"Arial Unicode MS", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Arab;Hebr;" },
{ L"Baskerville Old Face", L"Text;", L"Latn;" },
{ L"Batang", L"Text;", L"Kore;" },
{ L"Batang Old Hangul", L"Text;", L"Kore;" },
{ L"Batang Old Koreul", L"Text;", L"Kore;" },
{ L"BatangChe", L"Text;", L"Kore;" },
{ L"Bauhaus 93", L"Display;", L"Latn;" },
{ L"Bell MT", L"Text;", L"Latn;" },
{ L"Berlin Sans FB", L"Display;", L"Latn;" },
{ L"Bernard MT", L"Display;", L"Latn;" },
{ L"Big Round R", L"Display;", L"Kore;" },
{ L"Big Sans R", L"Display;", L"Kore;" },
{ L"Blackadder ITC", L"Display;", L"Latn;" },
{ L"Bodoni MT", L"Text;", L"Latn;" },
{ L"Bodoni MT Poster", L"Display;", L"Latn;" },
{ L"Book Antiqua", L"Text;", L"Latn;" },
{ L"Bookman Old Style", L"Text;", L"Latn;" },
{ L"Bookshelf Symbol 7", L"Symbol;", L"Zsym;" },
{ L"Bradley Hand ITC", L"Informal;", L"Latn;" },
{ L"Britannic", L"Display;", L"Latn;" },
{ L"Broadway", L"Display;", L"Latn;" },
{ L"Browallia New", L"Text;", L"Thai;" },
{ L"BrowalliaUPC", L"Text;", L"Thai;" },
{ L"Brush Script MT", L"Informal;", L"Latn;" },
{ L"Calibri", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Californian FB", L"Text;", L"Latn;" },
{ L"Calisto MT", L"Text;", L"Latn;" },
{ L"Cambria", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Cambria Math", L"Symbol;", L"Zsym;Zmth;" },
{ L"Candara", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Castellar", L"Display;", L"Latn;" },
{ L"Centaur", L"Text;", L"Latn;" },
{ L"Century", L"Text;", L"Latn;" },
{ L"Century Gothic", L"Display;", L"Latn;" },
{ L"Century Schoolbook", L"Text;", L"Latn;" },
{ L"Chiller", L"Display;", L"Latn;" },
{ L"Colonna MT", L"Display;", L"Latn;" },
{ L"Comic Sans MS", L"Informal;", L"Latn;Grek;Cyrl;" },
{ L"Consolas", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Constantia", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Cooper", L"Display;", L"Latn;" },
{ L"Copperplate Gothic", L"Display;", L"Latn;" },
{ L"Corbel", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Cordia New", L"Text;", L"Thai;" },
{ L"CordiaUPC", L"Text;", L"Thai;" },
{ L"Courier", L"Text;", L"Latn;" },
{ L"Courier New", L"Text;", L"Latn;Grek;Cyrl;Hebr;" },
{ L"Curlz MT", L"Display;", L"Latn;" },
{ L"DFKai-SB", L"Text;", L"Hant;" },
{ L"DaunPenh", L"Text;", L"Khmr;" },
{ L"David", L"Text;", L"Hebr;" },
{ L"DejaVu Sans", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"DejaVu Sans Mono", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"DejaVu Serif", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"DilleniaUPC", L"Text;", L"Thai;" },
{ L"DokChampa", L"Text;", L"Laoo;" },
{ L"Dotum", L"Text;", L"Kore;" },
{ L"Dotum Old Hangul", L"Text;", L"Kore;" },
{ L"Dotum Old Koreul", L"Text;", L"Kore;" },
{ L"DotumChe", L"Text;", L"Kore;" },
{ L"Ebrima", L"Text;", L"Vaii;Nkoo;Tfng;Osma;Ethi;" },
{ L"Edwardian Script ITC", L"Display;", L"Latn;" },
{ L"Elephant", L"Display;", L"Latn;" },
{ L"Engravers MT", L"Display;", L"Latn;" },
{ L"Eras ITC", L"Text;", L"Latn;" },
{ L"Eras ITC Medium", L"Display;", L"Latn;" },
{ L"Estrangelo Edessa", L"Text;", L"Syrc;" },
{ L"EucrosiaUPC", L"Text;", L"Thai;" },
{ L"Euphemia", L"Text;", L"Cans;" },
{ L"Expo B", L"Display;", L"Kore;" },
{ L"Expo L", L"Text;", L"Kore;" },
{ L"Expo M", L"Display;", L"Kore;" },
{ L"FZShuTi", L"Text;", L"Hans;" },
{ L"FZYaoTi", L"Text;", L"Hans;" },
{ L"FangSong", L"Text;", L"Hans;" },
{ L"Felix Titling", L"Display;", L"Latn;" },
{ L"Fixedsys", L"Text;", L"Latn;" },
{ L"Footlight MT", L"Text;", L"Latn;" },
{ L"Forte", L"Informal;", L"Latn;" },
{ L"FrankRuehl", L"Text;", L"Hebr;" },
{ L"Franklin Gothic", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Franklin Gothic Book", L"Text;", L"Latn;" },
{ L"FreesiaUPC", L"Text;", L"Thai;" },
{ L"Freestyle Script", L"Informal;", L"Latn;" },
{ L"French Script MT", L"Informal;", L"Latn;" },
{ L"Gabriola", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Gadugi", L"Text;", L"Cher;" },
{ L"Garam B", L"Text;", L"Kore;" },
{ L"Garamond", L"Text;", L"Latn;" },
{ L"Gautami", L"Text;", L"Telu;" },
{ L"Georgia", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Gigi", L"Display;", L"Latn;" },
{ L"Gill Sans", L"Display;", L"Latn;" },
{ L"Gill Sans MT", L"Text;", L"Latn;" },
{ L"Gisha", L"Text;", L"Hebr;" },
{ L"Gloucester MT", L"Display;", L"Latn;" },
{ L"Gothic B", L"Text;", L"Kore;" },
{ L"Gothic L", L"Text;", L"Kore;" },
{ L"Gothic Newsletter", L"Text;", L"Kore;" },
{ L"Gothic R", L"Text;", L"Kore;" },
{ L"Gothic Round B", L"Text;", L"Kore;" },
{ L"Gothic Round L", L"Text;", L"Kore;" },
{ L"Gothic Round R", L"Text;", L"Kore;" },
{ L"Gothic Round XB", L"Display;", L"Kore;" },
{ L"Gothic XB", L"Display;", L"Kore;" },
{ L"Goudy Old Style", L"Text;", L"Latn;" },
{ L"Goudy Stout", L"Display;", L"Latn;" },
{ L"Graphic B", L"Display;", L"Kore;" },
{ L"Graphic New R", L"Display;", L"Kore;" },
{ L"Graphic R", L"Text;", L"Kore;" },
{ L"Graphic Sans B", L"Display;", L"Kore;" },
{ L"Graphic Sans R", L"Text;", L"Kore;" },
{ L"Gulim", L"Text;", L"Kore;" },
{ L"GulimChe", L"Text;", L"Kore;" },
{ L"Gungsuh", L"Text;", L"Kore;" },
{ L"Gungsuh Old Hangul", L"Text;", L"Kore;" },
{ L"Gungsuh Old Koreul", L"Text;", L"Kore;" },
{ L"Gungsuh R", L"Text;", L"Kore;" },
{ L"GungsuhChe", L"Text;", L"Kore;" },
{ L"HGGothicE", L"Text;", L"Jpan;" },
{ L"HGGothicM", L"Text;", L"Jpan;" },
{ L"HGGyoshotai", L"Text;", L"Jpan;" },
{ L"HGKyokashotai", L"Text;", L"Jpan;" },
{ L"HGMaruGothicMPRO", L"Text;", L"Jpan;" },
{ L"HGMinchoB", L"Text;", L"Jpan;" },
{ L"HGMinchoE", L"Text;", L"Jpan;" },
{ L"HGPGothicE", L"Text;", L"Jpan;" },
{ L"HGPGothicM", L"Text;", L"Jpan;" },
{ L"HGPGyoshotai", L"Text;", L"Jpan;" },
{ L"HGPKyokashotai", L"Text;", L"Jpan;" },
{ L"HGPMinchoB", L"Text;", L"Jpan;" },
{ L"HGPMinchoE", L"Text;", L"Jpan;" },
{ L"HGPSoeiKakugothicUB", L"Display;", L"Jpan;" },
{ L"HGPSoeiKakupoptai", L"Display;", L"Jpan;" },
{ L"HGPSoeiPresenceEB", L"Text;", L"Jpan;" },
{ L"HGSGothicE", L"Text;", L"Jpan;" },
{ L"HGSGothicM", L"Text;", L"Jpan;" },
{ L"HGSGyoshotai", L"Text;", L"Jpan;" },
{ L"HGSKyokashotai", L"Text;", L"Jpan;" },
{ L"HGSMinchoB", L"Text;", L"Jpan;" },
{ L"HGSMinchoE", L"Text;", L"Jpan;" },
{ L"HGSSoeiKakugothicUB", L"Display;", L"Jpan;" },
{ L"HGSSoeiKakupoptai", L"Display;", L"Jpan;" },
{ L"HGSSoeiPresenceEB", L"Text;", L"Jpan;" },
{ L"HGSeikaishotaiPRO", L"Text;", L"Jpan;" },
{ L"HGSoeiKakugothicUB", L"Display;", L"Jpan;" },
{ L"HGSoeiKakupoptai", L"Display;", L"Jpan;" },
{ L"HGSoeiPresenceEB", L"Text;", L"Jpan;" },
{ L"HYBackSong", L"Display;", L"Kore;" },
{ L"HYBudle", L"Text;", L"Kore;" },
{ L"HYGothic", L"Text;", L"Kore;" },
{ L"HYGothic-Extra", L"Display;", L"Kore;" },
{ L"HYGraphic", L"Text;", L"Kore;" },
{ L"HYGungSo", L"Text;", L"Kore;" },
{ L"HYHaeSo", L"Text;", L"Kore;" },
{ L"HYHeadLine", L"Display;", L"Kore;" },
{ L"HYKHeadLine", L"Display;", L"Kore;" },
{ L"HYLongSamul", L"Display;", L"Kore;" },
{ L"HYMokGak", L"Display;", L"Kore;" },
{ L"HYMokPan", L"Display;", L"Kore;" },
{ L"HYMyeongJo", L"Text;", L"Kore;" },
{ L"HYMyeongJo Extra Bold", L"Display;", L"Kore;" },
{ L"HYMyeongJo-Extra", L"Text;", L"Kore;" },
{ L"HYPMokGak", L"Display;", L"Kore;" },
{ L"HYPMokPan", L"Display;", L"Kore;" },
{ L"HYPillGi", L"Informal;", L"Kore;" },
{ L"HYPost", L"Informal;", L"Kore;" },
{ L"HYRGothic", L"Text;", L"Kore;" },
{ L"HYSeNse", L"Informal;", L"Kore;" },
{ L"HYShortSamul", L"Text;", L"Kore;" },
{ L"HYSinGraphic", L"Text;", L"Kore;" },
{ L"HYSinMun-MyeongJo", L"Text;", L"Kore;" },
{ L"HYSinMyeongJo", L"Text;", L"Kore;" },
{ L"HYSinMyeongJo-Medium-HanjaA", L"Symbol;", L"Zsym;" },
{ L"HYSinMyeongJo-Medium-HanjaB", L"Symbol;", L"Zsym;" },
{ L"HYSinMyeongJo-Medium-HanjaC", L"Symbol;", L"Zsym;" },
{ L"HYSooN-MyeongJo", L"Text;", L"Kore;" },
{ L"HYSymbolA", L"Symbol;", L"Zsym;" },
{ L"HYSymbolB", L"Symbol;", L"Zsym;" },
{ L"HYSymbolC", L"Symbol;", L"Zsym;" },
{ L"HYSymbolD", L"Symbol;", L"Zsym;" },
{ L"HYSymbolE", L"Symbol;", L"Zsym;" },
{ L"HYSymbolF", L"Symbol;", L"Zsym;" },
{ L"HYSymbolG", L"Symbol;", L"Zsym;" },
{ L"HYSymbolH", L"Symbol;", L"Zsym;" },
{ L"HYTaJa", L"Text;", L"Kore;" },
{ L"HYTaJa Bold", L"Display;", L"Kore;" },
{ L"HYTaJaFull", L"Text;", L"Kore;" },
{ L"HYTaJaFull Bold", L"Display;", L"Kore;" },
{ L"HYTeBack", L"Display;", L"Kore;" },
{ L"HYYeaSo", L"Display;", L"Kore;" },
{ L"HYYeasoL", L"Display;", L"Kore;" },
{ L"HYYeatGul", L"Display;", L"Kore;" },
{ L"Haettenschweiler", L"Display;", L"Latn;" },
{ L"Harlow Solid", L"Display;", L"Latn;" },
{ L"Harrington", L"Display;", L"Latn;" },
{ L"Headline R", L"Display;", L"Kore;" },
{ L"Headline Sans R", L"Display;", L"Kore;" },
{ L"High Tower Text", L"Text;", L"Latn;" },
{ L"Impact", L"Display;", L"Latn;Grek;Cyrl;" },
{ L"Imprint MT Shadow", L"Display;", L"Latn;" },
{ L"Informal Roman", L"Informal;", L"Latn;" },
{ L"IrisUPC", L"Display;", L"Thai;" },
{ L"Iskoola Pota", L"Text;", L"Sinh;" },
{ L"JasmineUPC", L"Display;", L"Thai;" },
{ L"Jasu B", L"Display;", L"Kore;" },
{ L"Jasu L", L"Display;", L"Kore;" },
{ L"Jasu R", L"Display;", L"Kore;" },
{ L"Jasu XB", L"Display;", L"Kore;" },
{ L"Javanese Text", L"Text;", L"Java;" },
{ L"Jokerman", L"Display;", L"Latn;" },
{ L"Juice ITC", L"Display;", L"Latn;" },
{ L"KaiTi", L"Text;", L"Hans;" },
{ L"Kalinga", L"Text;", L"Orya;" },
{ L"Kartika", L"Text;", L"Mlym;" },
{ L"Khmer UI", L"Text;", L"Khmr;" },
{ L"KodchiangUPC", L"Display;", L"Thai;" },
{ L"Kokila", L"Text;", L"Deva;" },
{ L"Kristen ITC", L"Informal;", L"Latn;" },
{ L"Kunstler Script", L"Display;", L"Latn;" },
{ L"Lao UI", L"Text;", L"Laoo;" },
{ L"Latha", L"Text;", L"Taml;" },
{ L"Latin", L"Display;", L"Latn;" },
{ L"Leelawadee", L"Text;", L"Thai;" },
{ L"Leelawadee UI", L"Text;", L"Thai;Laoo;Bugi;Khmr;" },
{ L"Levenim MT", L"Display;", L"Hebr;" },
{ L"LiSu", L"Text;", L"Hans;" },
{ L"LilyUPC", L"Display;", L"Thai;" },
{ L"Lucida Bright", L"Text;", L"Latn;" },
{ L"Lucida Calligraphy", L"Display;", L"Latn;" },
{ L"Lucida Console", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Lucida Fax", L"Text;", L"Latn;" },
{ L"Lucida Handwriting", L"Informal;", L"Latn;" },
{ L"Lucida Sans", L"Text;", L"Latn;" },
{ L"Lucida Sans Typewriter", L"Text;", L"Latn;" },
{ L"Lucida Sans Unicode", L"Text;", L"Latn;Grek;Cyrl;Hebr;" },
{ L"MS Gothic", L"Text;", L"Jpan;" },
{ L"MS Mincho", L"Text;", L"Jpan;" },
{ L"MS Outlook", L"Symbol;", L"Zsym;" },
{ L"MS PGothic", L"Text;", L"Jpan;" },
{ L"MS PMincho", L"Text;", L"Jpan;" },
{ L"MS Reference Sans Serif", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"MS Reference Specialty", L"Symbol;", L"Zsym;" },
{ L"MS Sans Serif", L"Text;", L"Latn;" },
{ L"MS Serif", L"Text;", L"Latn;" },
{ L"MS UI Gothic", L"Text;", L"Jpan;" },
{ L"MV Boli", L"Text;", L"Thaa;" },
{ L"Magic R", L"Display;", L"Kore;" },
{ L"Magneto", L"Display;", L"Latn;" },
{ L"Maiandra GD", L"Text;", L"Latn;" },
{ L"Malgun Gothic", L"Text;", L"Kore;" },
{ L"Mangal", L"Text;", L"Deva;" },
{ L"Marlett", L"Symbol", L"Zsym;" },
{ L"Matura MT Script Capitals", L"Display;", L"Latn;" },
{ L"Meiryo", L"Text;", L"Jpan;" },
{ L"Meiryo UI", L"Text;", L"Jpan;" },
{ L"Meorimyungjo B", L"Display;", L"Kore;" },
{ L"Meorimyungjo XB", L"Display;", L"Kore;" },
{ L"Microsoft Himalaya", L"Text;", L"Tibt;" },
{ L"Microsoft JhengHei", L"Text;", L"Hant;" },
{ L"Microsoft JhengHei Light", L"Text;", L"Hant;" },
{ L"Microsoft JhengHei UI", L"Text;", L"Hant;" },
{ L"Microsoft JhengHei UI Light", L"Text;", L"Hant;" },
{ L"Microsoft New Tai Lue", L"Text;", L"Talu;" },
{ L"Microsoft PhagsPa", L"Text;", L"Phag;" },
{ L"Microsoft Sans Serif", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Microsoft Tai Le", L"Text;", L"Tale;" },
{ L"Microsoft Uighur", L"Text;", L"ug-Arab;" },
{ L"Microsoft YaHei", L"Text;", L"Hans;" },
{ L"Microsoft YaHei Light", L"Text;", L"Hans;" },
{ L"Microsoft YaHei UI", L"Text;", L"Hans;" },
{ L"Microsoft YaHei UI Light", L"Text;", L"Hans;" },
{ L"Microsoft Yi Baiti", L"Text;", L"Yiii;" },
{ L"MingLiU", L"Text;", L"Hant;" },
{ L"MingLiU-ExtB", L"Text;", L"Hant;" },
{ L"MingLiU_HKSCS", L"Text;", L"Hant-HK;" },
{ L"MingLiU_HKSCS-ExtB", L"Text;", L"Hant-HK;" },
{ L"Miriam", L"Text;", L"Hebr;" },
{ L"Miriam Fixed", L"Text;", L"Hebr;" },
{ L"Mistral", L"Informal;", L"Latn;" },
{ L"Modak R", L"Display;", L"Kore;" },
{ L"Modern", L"Text;", L"Latn;" },
{ L"Modern No. 20", L"Text;", L"Latn;" },
{ L"MoeumT B", L"Display;", L"Kore;" },
{ L"MoeumT L", L"Text;", L"Kore;" },
{ L"MoeumT R", L"Text;", L"Kore;" },
{ L"MoeumT XB", L"Display;", L"Kore;" },
{ L"Mongolian Baiti", L"Text;", L"Mong;" },
{ L"Monotype Corsiva", L"Informal;", L"Latn;" },
{ L"MoolBoran", L"Display;", L"Khmr;" },
{ L"Myanmar Text", L"Text;", L"Mymr;" },
{ L"Myungjo B", L"Text;", L"Kore;" },
{ L"Myungjo L", L"Text;", L"Kore;" },
{ L"Myungjo Newsletter", L"Text;", L"Kore;" },
{ L"Myungjo R", L"Text;", L"Kore;" },
{ L"Myungjo SK B", L"Text;", L"Kore;" },
{ L"Myungjo XB", L"Display;", L"Kore;" },
{ L"NSimSun", L"Text;", L"Hans;" },
{ L"Namu B", L"Informal;", L"Kore;" },
{ L"Namu L", L"Text;", L"Kore;" },
{ L"Namu R", L"Text;", L"Kore;" },
{ L"Namu XB", L"Display;", L"Kore;" },
{ L"Narkisim", L"Text;", L"Hebr;" },
{ L"New Batang", L"Text;", L"Kore;" },
{ L"New Dotum", L"Text;", L"Kore;" },
{ L"New Gulim", L"Text;", L"Kore;" },
{ L"New Gungsuh", L"Text;", L"Kore;" },
{ L"NewGulim Old Hangul", L"Text;", L"Kore;" },
{ L"NewGulim Old Koreul", L"Text;", L"Kore;" },
{ L"Niagara Engraved", L"Display;", L"Latn;" },
{ L"Niagara Solid", L"Display;", L"Latn;" },
{ L"Nirmala UI", L"Text;", L"Taml;Beng;Deva;Gujr;Guru;Knda;Mlym;Orya;Sinh;Telu;Olck;Sora;" },
{ L"Nyala", L"Text;", L"Ethi;" },
{ L"OCR A", L"Display;", L"Latn;" },
{ L"OCRB", L"Text;", L"Latn;" },
{ L"Old English Text MT", L"Display;", L"Latn;" },
{ L"Onyx", L"Display;", L"Latn;" },
{ L"OpenSymbol", L"Symbol;", L"Zsym;" },
{ L"PMingLiU", L"Text;", L"Hant;" },
{ L"PMingLiU-ExtB", L"Text;", L"Hant;" },
{ L"Palace Script MT", L"Display;", L"Latn;" },
{ L"Palatino Linotype", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Pam B", L"Display;", L"Kore;" },
{ L"Pam L", L"Text;", L"Kore;" },
{ L"Pam M", L"Text;", L"Kore;" },
{ L"Pam New B", L"Display;", L"Kore;" },
{ L"Pam New L", L"Text;", L"Kore;" },
{ L"Pam New M", L"Text;", L"Kore;" },
{ L"Panhwa R", L"Display;", L"Kore;" },
{ L"Papyrus", L"Informal;", L"Latn;" },
{ L"Parchment", L"Display;", L"Latn;" },
{ L"Perpetua", L"Text;", L"Latn;" },
{ L"Perpetua Titling MT", L"Display;", L"Latn;" },
{ L"Plantagenet Cherokee", L"Text;", L"Cher;" },
{ L"Playbill", L"Display;", L"Latn;" },
{ L"Poor Richard", L"Display;", L"Latn;" },
{ L"Pristina", L"Informal;", L"Latn;" },
{ L"Pyunji R", L"Informal;", L"Kore;" },
{ L"Raavi", L"Text;", L"Guru;" },
{ L"Rage", L"Informal;", L"Latn;" },
{ L"Ravie", L"Display;", L"Latn;" },
{ L"Rockwell", L"Text;", L"Latn;" },
{ L"Rod", L"Text;", L"Hebr;" },
{ L"Roman", L"Text;", L"Latn;" },
{ L"STCaiyun", L"Display;", L"Hans;" },
{ L"STFangsong", L"Text;", L"Hans;" },
{ L"STHupo", L"Display;", L"Hans;" },
{ L"STKaiti", L"Text;", L"Hans;" },
{ L"STLiti", L"Text;", L"Hans;" },
{ L"STSong", L"Text;", L"Hans;" },
{ L"STXihei", L"Text;", L"Hans;" },
{ L"STXingkai", L"Text;", L"Hans;" },
{ L"STXinwei", L"Text;", L"Hans;" },
{ L"STZhongsong", L"Text;", L"Hans;" },
{ L"SWGamekeys MT", L"Symbol;", L"Zsym;" }, // instead of SWGamekeys MT Regular
{ L"SWMacro Regular", L"Symbol;", L"Zsym;" },
{ L"Saenaegi B", L"Text;", L"Kore;" },
{ L"Saenaegi L", L"Text;", L"Kore;" },
{ L"Saenaegi R", L"Text;", L"Kore;" },
{ L"Saenaegi XB", L"Display;", L"Kore;" },
{ L"Sakkal Majalla", L"Text;", L"Arab;" },
{ L"Sam B", L"Display;", L"Kore;" },
{ L"Sam L", L"Text;", L"Kore;" },
{ L"Sam M", L"Text;", L"Kore;" },
{ L"Sam New B", L"Display;", L"Kore;" },
{ L"Sam New L", L"Text;", L"Kore;" },
{ L"Sam New M", L"Text;", L"Kore;" },
{ L"Script", L"Informal;", L"Latn;" },
{ L"Script MT", L"Display;", L"Latn;" },
{ L"Segoe Print", L"Informal;", L"Latn;Grek;Cyrl;" },
{ L"Segoe Script", L"Informal;", L"Latn;Grek;Cyrl;" },
{ L"Segoe UI", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Segoe UI Black", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Segoe UI Black Italic", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Segoe UI Bold", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Geok;Arab;Hebr;Lisu;" },
{ L"Segoe UI Bold Italic", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;" },
{ L"Segoe UI Emoji", L"Symbol;", L"Zsym;" },
{ L"Segoe UI Italic", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;" },
{ L"Segoe UI Light", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Geok;Arab;Hebr;Lisu;" },
{ L"Segoe UI Light Italic", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;" },
{ L"Segoe UI Regular", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Geok;Arab;Hebr;Lisu;" },
{ L"Segoe UI Semibold", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Geok;Arab;Hebr;Lisu;" },
{ L"Segoe UI Semibold Italic", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;" },
{ L"Segoe UI Semilight", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;Geok;Arab;Hebr;Lisu;" },
{ L"Segoe UI Semilight Italic", L"Text;", L"Latn;Grek;Cyrl;Armn;Geor;" },
{ L"Segoe UI Symbol", L"Symbol;", L"Zsym;Brai;Dsrt;Glag;Goth;Ital;Ogam;Orkh;Runr;Copt;Merc;" },
{ L"Shonar Bangla", L"Text;", L"Beng;" },
{ L"Showcard Gothic", L"Display;", L"Latn;" },
{ L"Shruti", L"Text;", L"Gujr;" },
{ L"SimHei", L"Text;", L"Hans;" },
{ L"SimSun", L"Text;", L"Hans;" },
{ L"SimSun-ExtB", L"Text;", L"Hans;" },
{ L"Simplified Arabic", L"Text;", L"Arab;" },
{ L"Simplified Arabic Fixed", L"Text;", L"Arab;" },
{ L"Sitka Banner", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Sitka Display", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Sitka Heading", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Sitka Small", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Sitka Subheading", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Sitka Text", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Small Fonts", L"Text;", L"Latn;" },
{ L"Snap ITC", L"Display;", L"Latn;" },
{ L"Soha R", L"Display;", L"Kore;" },
{ L"Stencil", L"Display;", L"Latn;" },
{ L"Sylfaen", L"Text;", L"Grek;Cyrl;Armn;Geor;" },
{ L"Symbol", L"Symbol;", L"Zsym;" },
{ L"System", L"Text;", L"Latn;" },
{ L"Tahoma", L"Text;", L"Latn;Grek;Cyrl;Armn;Hebr;" },
{ L"Tempus Sans ITC", L"Informal;", L"Latn;" },
{ L"Terminal", L"Text;", L"Latn;" },
{ L"Times New Roman", L"Text;", L"Latn;Grek;Cyrl;Hebr;" },
{ L"Traditional Arabic", L"Text;", L"Arab;" },
{ L"Trebuchet MS", L"Display;", L"Latn;Grek;Cyrl;" },
{ L"Tunga", L"Text;", L"Knda;" },
{ L"Tw Cen MT", L"Text;", L"Latn;" },
{ L"Urdu Typesetting", L"Text;", L"Arab;" },
{ L"Utsaah", L"Text;", L"Deva;" },
{ L"Vani", L"Text;", L"Telu;" },
{ L"Verdana", L"Text;", L"Latn;Grek;Cyrl;" },
{ L"Vijaya", L"Text;", L"Taml;" },
{ L"Viner Hand ITC", L"Informal;", L"Latn;" },
{ L"Vivaldi", L"Display;", L"Latn;" },
{ L"Vladimir Script", L"Display;", L"Latn;" },
{ L"Vrinda", L"Text;", L"Beng;" },
{ L"Webdings", L"Symbol;", L"Zsym;" },
{ L"Wingdings", L"Symbol;", L"Zsym;" },
{ L"Wingdings 2", L"Symbol;", L"Zsym;" },
{ L"Wingdings 3", L"Symbol;", L"Zsym;" },
{ L"Woorin R", L"Text;", L"Kore;" },
{ L"Yeopseo R", L"Informal;", L"Kore;" },
{ L"Yet R", L"Display;", L"Kore;" },
{ L"Yet Sans XB", L"Display;", L"Kore;" },
{ L"Yet Sans B", L"Text;", L"Kore;" },
{ L"Yet Sans L", L"Text;", L"Kore;" },
{ L"Yet Sans R", L"Text;", L"Kore;" },
{ L"YouYuan", L"Text;", L"Hans;" },
{ L"Yu Gothic", L"Text;", L"Jpan;" },
{ L"Yu Gothic Light", L"Text;", L"Jpan;" },
{ L"Yu Mincho", L"Text;", L"Jpan;" },
{ L"Yu Mincho Light", L"Text;", L"Jpan;" },
};
bool FindTagsFromKnownFontName(
wchar_t const* fullFontName,
wchar_t const* familyName,
OUT wchar_t const** tags,
OUT wchar_t const** scripts
) // not WWS or GDI name
{
for (uint32_t i = 0; i < 2; ++i)
{
auto fontName = i == 0 ? fullFontName : familyName;
if (fontName == nullptr || fontName[0] == '\0')
continue;
auto const* begin = g_knownFamilyNameTags;
auto const* end = g_knownFamilyNameTags + ARRAYSIZE(g_knownFamilyNameTags);
while (begin < end)
{
auto const* p = begin + (end - begin) / 2;
auto cmp = _wcsicmp(fontName, p->fontName);
if (cmp == 0)
{
*tags = p->tags;
*scripts = p->scripts;
return true;
}
cmp = wcscmp(fontName, p->fontName);
if (cmp < 0)
{
end = p;
}
else // if (cmp > 0)
{
begin = p + 1;
}
}
}
return false;
}
void AppendStringIfNotPresent(
__in_z wchar_t* newString,
__inout std::wstring& existingString
)
{
if (existingString.find(newString) == std::wstring::npos)
{
existingString.append(newString);
}
}
////////////////////////////////////////
// DWrite helper functions
HRESULT GetLocalFileLoaderAndKey(
IDWriteFontFile* fontFile,
_Out_ void const** fontFileReferenceKey,
_Out_ uint32_t& fontFileReferenceKeySize,
_Out_ IDWriteLocalFontFileLoader** localFontFileLoader
)
{
*localFontFileLoader = nullptr;
*fontFileReferenceKey = nullptr;
fontFileReferenceKeySize = 0;
if (fontFile == nullptr)
return E_INVALIDARG;
ComPtr<IDWriteFontFileLoader> fontFileLoader;
IFR(fontFile->GetLoader(OUT &fontFileLoader));
IFR(fontFileLoader->QueryInterface(OUT localFontFileLoader));
IFR(fontFile->GetReferenceKey(fontFileReferenceKey, OUT &fontFileReferenceKeySize));
return S_OK;
}
HRESULT GetFilePath(
IDWriteFontFile* fontFile,
OUT std::wstring& filePath
) throw()
{
std::wstring tempFilePath;
std::swap(tempFilePath, filePath);
if (fontFile == nullptr)
return E_INVALIDARG;
ComPtr<IDWriteLocalFontFileLoader> localFileLoader;
uint32_t fontFileReferenceKeySize = 0;
const void* fontFileReferenceKey = nullptr;
IFR(GetLocalFileLoaderAndKey(fontFile, OUT &fontFileReferenceKey, OUT fontFileReferenceKeySize, OUT &localFileLoader));
uint32_t filePathLength = 0;
IFR(localFileLoader->GetFilePathLengthFromKey(
fontFileReferenceKey,
fontFileReferenceKeySize,
OUT &filePathLength
));
try
{
tempFilePath.resize(filePathLength);
}
catch (std::bad_alloc const&)
{
return E_OUTOFMEMORY; // This is the only exception type we need to worry about.
}
IFR(localFileLoader->GetFilePathFromKey(
fontFileReferenceKey,
fontFileReferenceKeySize,
OUT &tempFilePath[0],
filePathLength + 1
));
std::swap(tempFilePath, filePath);
return S_OK;
}
HRESULT GetFontFile(
IDWriteFontFace* fontFace,
OUT IDWriteFontFile** fontFile
)
{
*fontFile = nullptr;
if (fontFace == nullptr)
return E_INVALIDARG;
ComPtr<IDWriteFontFile> fontFiles[8];
uint32_t fontFileCount = 0;
IFR(fontFace->GetFiles(OUT &fontFileCount, nullptr));
if (fontFileCount > ARRAYSIZE(fontFiles))
return E_NOT_SUFFICIENT_BUFFER;
IFR(fontFace->GetFiles(IN OUT &fontFileCount, OUT &fontFiles[0]));
if (fontFileCount == 0 || fontFiles[0] == nullptr)
return E_FAIL;
*fontFile = fontFiles[0].Detach();
return S_OK;
}
HRESULT GetFilePath(
IDWriteFontFace* fontFace,
OUT std::wstring& filePath
) throw()
{
filePath.clear();
if (fontFace == nullptr)
return E_INVALIDARG;
ComPtr<IDWriteFontFile> fontFile;
IFR(GetFontFile(fontFace, OUT &fontFile));
return GetFilePath(fontFile, OUT filePath);
}
HRESULT GetFilePath(
IDWriteFontFaceReference* fontFaceReference,
OUT std::wstring& filePath
) throw()
{
filePath.clear();
if (fontFaceReference == nullptr)
return E_INVALIDARG;
ComPtr<IDWriteFontFile> fontFile;
IFR(fontFaceReference->GetFontFile(OUT &fontFile));
return GetFilePath(fontFile, OUT filePath);
}
HRESULT CreateFontSetFromFileNames(
IDWriteFactory5* dwriteFactory,
_In_opt_z_ wchar_t const* baseFilePath,
_In_reads_bytes_(fileNamesCount) wchar_t const* fileNames,
uint32_t fileNamesCount,
_Out_ IDWriteFontSet** fontSet,
std::wstring& failedFileNames
)
{
*fontSet = nullptr;
ComPtr<IDWriteFontSet> newFontSet;
ComPtr<IDWriteFontSetBuilder1> fontSetBuilder;
IFR(dwriteFactory->CreateFontSetBuilder(OUT &fontSetBuilder));
auto fileNamesEnd = fileNames + fileNamesCount;
if (baseFilePath == nullptr)
baseFilePath = L"";
// Create font set with a single file.
for (wchar_t const* fileName = fileNames; fileName < fileNamesEnd && fileName[0] != '\0'; )
{
// Get the full path in case relative filenames were passed.
wchar_t filePath[MAX_PATH + 1];
PathCombine(OUT filePath, baseFilePath, fileName);
ComPtr<IDWriteFontFile> fontFile;
// Add the font file to the set, but don't fail the whole font set if an error happened.
// Instead, return success, but keep track of the failure.
if (FAILED(dwriteFactory->CreateFontFileReference(filePath, nullptr, OUT &fontFile))
|| FAILED(fontSetBuilder->AddFontFile(fontFile)))
{
failedFileNames.append(filePath);
failedFileNames.push_back('\0');
}
fileName = std::find(fileName, fileNamesEnd, '\0') + 1;
}
IFR(fontSetBuilder->CreateFontSet(OUT &newFontSet));
*fontSet = newFontSet.Detach();
return S_OK;
}
HRESULT GetLocalizedString(
_In_ IDWriteStringList* stringList,
uint32_t stringIndex,
_Out_ std::wstring& stringValue
)
{
uint32_t length = 0;
stringValue.clear();
if (stringList == nullptr)
return E_INVALIDARG;
IFR(stringList->GetStringLength(stringIndex, OUT &length));
if (length > 0 && length != UINT32_MAX)
{
stringValue.resize(length);
}
IFR(stringList->GetString(stringIndex, OUT &stringValue[0], length + 1));
return S_OK;
}
}
int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR commandLine,
int nCmdShow
)
{
// The Microsoft Security Development Lifecycle recommends that all
// applications include the following call to ensure that heap corruptions
// do not go unnoticed and therefore do not introduce opportunities
// for security exploits.
HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
MainWindow::RegisterWindowClass();
HWND mainHwnd = CreateDialog(HINST_THISCOMPONENT, MAKEINTRESOURCE(IddMainWindow), nullptr, &MainWindow::StaticDialogProc);
if (mainHwnd == nullptr)
{
IFR(ShowMessageIfFailed(
HRESULT_FROM_WIN32(GetLastError()),
L"Could not create main demo window! CreateWindow()" FAILURE_LOCATION
));
}
else
{
MainWindow::RunMessageLoop();
}
return 0;
}
MainWindow::MainWindow(HWND hwnd)
: hwnd_(hwnd)
{
fontColor_ = GetSysColor(COLOR_WINDOWTEXT) | 0xFF000000; // Ensure opaque
backgroundColor_ = GetSysColor(COLOR_WINDOW) | 0xFF000000;
highlightColor_ = GetSysColor(COLOR_HIGHLIGHTTEXT) | 0xFF000000; // Ensure opaque
highlightBackgroundColor_ = GetSysColor(COLOR_HIGHLIGHT) | 0xFF000000;
faintSelectionColor_ = GetSysColor(COLOR_BTNFACE) | 0xFF000000;
}
ATOM MainWindow::RegisterWindowClass()
{
// Registers the main window class.
// Ensure that the common control DLL is loaded.
// (probably not needed, but do it anyway)
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_STANDARD_CLASSES|ICC_LISTVIEW_CLASSES|ICC_LINK_CLASS;
InitCommonControlsEx(&icex);
return 0;
}
HRESULT MainWindow::Initialize()
{
HRESULT hr = S_OK;
std::wstring commandLine;
GetCommandLineArguments(IN OUT commandLine);
IFR(ParseCommandLine(commandLine.c_str()));
//////////////////////////////
// Create the DWrite factory.
IFR(ShowMessageIfFailed(
LoadDWrite(g_dwriteDllName.c_str(), DWRITE_FACTORY_TYPE_SHARED, OUT &dwriteFactory_, OUT dwriteModule_),
L"Could not create DirectWrite factory! DWriteCreateFactory()" FAILURE_LOCATION
));
//////////////////////////////
// Create the main window
if (hwnd_ == nullptr)
{
IFR(ShowMessageIfFailed(
HRESULT_FROM_WIN32(GetLastError()),
L"Could not create main demo window! CreateWindow()" FAILURE_LOCATION
));
}
else
{
ShowWindow(hwnd_, SW_SHOWNORMAL);
UpdateWindow(hwnd_);
}
//////////////////////////////
// Initialize the render target.
{
ComPtr<IDWriteGdiInterop> gdiInterop;
IFR(dwriteFactory_->GetGdiInterop(OUT &gdiInterop));
uint32_t initialWidth = 256;
uint32_t initialHeight = 256;
HDC hdc = GetDC(hwnd_);
hr = ShowMessageIfFailed(
gdiInterop->CreateBitmapRenderTarget(hdc, initialWidth, initialHeight, OUT &renderTarget_),
L"Could not create render target! CreateBitmapRenderTarget()" FAILURE_LOCATION
);
ReleaseDC(hwnd_, hdc);
IFR(hr);
}
if (g_startBlankList)
{
InitializeBlankFontCollection();
}
OnMove();
OnSize(); // update size and reflow
// Check if it's an older version of DirectWrite, like Windows 7, displaying warning in log.
ComPtr<IDWriteFactory3> factory3;
dwriteFactory_->QueryInterface(OUT &factory3);
if (factory3 == nullptr)
{
AppendLog(AppendLogModeImmediate, L"Windows version is older than Windows 10. Application will have very limited functionality.\r\n");
}
InitializeLanguageMenu();
InitializeFontCollectionFilterUI();
InitializeFontCollectionListUI();
RebuildFontCollectionList();
UpdateFontCollectionFilterUI();
UpdateFontCollectionListUI();
return hr;
}
MainWindow::~MainWindow()
{
if (dwriteFactory_ != nullptr)
{
//-dwriteFactory_->UnregisterFontFileLoader(RemoteStreamFontFileLoader::GetInstance());
}
}
WPARAM MainWindow::RunMessageLoop()
{
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0) > 0)
{
bool messageHandled = false;
const DWORD style = GetWindowStyle(msg.hwnd);
HWND dialog = msg.hwnd;
if (style & WS_CHILD)
dialog = GetAncestor(msg.hwnd, GA_ROOT);
// Send the Return key to the right control (one with focus) so that
// we get a NM_RETURN from that control, not IDOK to the parent window.
if (!messageHandled && msg.message == WM_KEYDOWN && msg.wParam == VK_RETURN)
{
messageHandled = !SendMessage(dialog, msg.message, msg.wParam, msg.lParam);
}
if (!messageHandled)
{
// Let the default dialog processing check it.
messageHandled = !!IsDialogMessage(dialog, &msg);
}
if (!messageHandled)
{
// Not any of the above, so just handle it.
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
INT_PTR CALLBACK MainWindow::StaticDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)