forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopennurbs_win_dwrite.cpp
2462 lines (2109 loc) · 85.7 KB
/
opennurbs_win_dwrite.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
//
// Copyright (c) 1993-2018 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
#include "opennurbs.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
#if defined(ON_OS_WINDOWS_GDI)
#include "opennurbs_internal_glyph.h"
#include "opennurbs_win_dwrite.h"
/////////////////////////////////////////////////////////////////////////////
//
// Global
// IDWriteFactory
// IDWriteGdiInterop
//
class ON_IDWrite
{
public:
static IDWriteFactory* Factory();
static IDWriteGdiInterop* GdiInterop();
private:
ON_IDWrite() = default;
~ON_IDWrite() = default;
ON_IDWrite(const ON_IDWrite&) = delete;
ON_IDWrite& operator=(const ON_IDWrite&) = delete;
private:
static IDWriteFactory* the_dwiteFactory;
static IDWriteGdiInterop* the_dwriteGdiInterop;
};
IDWriteFactory* ON_IDWrite::the_dwiteFactory = nullptr;
IDWriteGdiInterop* ON_IDWrite::the_dwriteGdiInterop = nullptr;
IDWriteFactory* ON_IDWrite::Factory()
{
if (nullptr == ON_IDWrite::the_dwiteFactory)
{
IDWriteFactory* dwiteFactory = nullptr;
HRESULT hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&dwiteFactory)
);
if (FAILED(hr) || nullptr == dwiteFactory)
{
ON_ERROR("DWriteCreateFactory() failed.");
return nullptr;
}
dwiteFactory->AddRef();
ON_IDWrite::the_dwiteFactory = dwiteFactory;
}
return ON_IDWrite::the_dwiteFactory;
}
IDWriteGdiInterop* ON_IDWrite::GdiInterop()
{
if (nullptr == ON_IDWrite::the_dwriteGdiInterop)
{
IDWriteFactory* dwiteFactory = ON_IDWrite::Factory();
if (nullptr == dwiteFactory)
return nullptr;
IDWriteGdiInterop* dwriteGdiInterop = nullptr;
HRESULT hr = dwiteFactory->GetGdiInterop(&dwriteGdiInterop);
if (FAILED(hr) || nullptr == dwriteGdiInterop)
{
ON_ERROR("dwiteFactory->GetGdiInterop() failed.");
return nullptr;
}
dwriteGdiInterop->AddRef();
ON_IDWrite::the_dwriteGdiInterop = dwriteGdiInterop;
}
return ON_IDWrite::the_dwriteGdiInterop;
}
/////////////////////////////////////////////////////////////////////////////
//
//
//
static bool Internal_GetLocalizeStrings(
const ON_wString preferedLocaleDirty,
IDWriteLocalizedStrings* pIDWriteLocalizedStrings,
ON_wString& defaultLocaleString,
ON_wString& defaultLocale,
ON_wString& enLocaleString,
ON_wString& enLocale
)
{
defaultLocaleString = ON_wString::EmptyString;
defaultLocale = ON_wString::EmptyString;
enLocaleString = ON_wString::EmptyString;
enLocale = ON_wString::EmptyString;
// get a clean preferedLocale with reliable storage for the string.
ON_wString preferedLocale(preferedLocaleDirty.Duplicate());
preferedLocale.TrimLeftAndRight();
if (ON_wString::EqualOrdinal(preferedLocale, L"GetUserDefaultLocaleName", true))
{
// Get the default locale for this user.
wchar_t userDefaultLocale[LOCALE_NAME_MAX_LENGTH + 1] = {};
userDefaultLocale[LOCALE_NAME_MAX_LENGTH] = 0;
if (0 == ::GetUserDefaultLocaleName(userDefaultLocale, LOCALE_NAME_MAX_LENGTH))
userDefaultLocale[0];
userDefaultLocale[LOCALE_NAME_MAX_LENGTH] = 0;
preferedLocale = ON_wString(userDefaultLocale);
preferedLocale.TrimLeftAndRight();
}
const wchar_t* localeNames[] =
{
static_cast<const wchar_t*>(preferedLocale),
// The preferred English dialect should be listed next
L"en-us", // United States
// Other known English dialects are list below
L"en-au", // Australia
L"en-bz", // Belize
L"en-ca", // Canada
L"en-cb", // Caribbean
L"en-gb", // Great Britain
L"en-in", // India
L"en-ie", // Ireland
L"en-jm", // Jamaica
L"en-nz", // New Zealand
L"en-ph", // Philippines
L"en-tt", // Trinidad
L"en-za", // Southern Africa
};
const int localNamesCount = (int)(sizeof(localeNames)/sizeof(localeNames[0]));
HRESULT hr;
if (nullptr == pIDWriteLocalizedStrings)
return ON_wString::EmptyString;
const UINT32 count = pIDWriteLocalizedStrings->GetCount();
if (count < 1)
return ON_wString::EmptyString;
UINT32 localeIndex = ON_UNSET_UINT_INDEX;
UINT32 enLocaleIndex = ON_UNSET_UINT_INDEX;
for (int i = 0; i < localNamesCount; i++)
{
const wchar_t* s = localeNames[i];
if (nullptr == s || 0 == s[0])
continue;
BOOL exists = 0;
UINT32 idx = ON_UNSET_UINT_INDEX;
hr = pIDWriteLocalizedStrings->FindLocaleName(s, &idx, &exists);
if (FAILED(hr))
continue;
if (false == exists)
continue;
if (idx >= count)
continue;
if (i > 0)
{
enLocaleIndex = idx;
enLocale = s;
}
else
{
// preferred locale
localeIndex = idx;
if (
0 != s[0] && 0 != s[1] && 0 != s[2]
&& ON_wString::EqualOrdinal(L"en-", 3, s, 3, true)
)
{
// preferred local is the preferred English dialect too.
enLocaleIndex = idx;
break;
}
}
}
for (int pass = 0; pass < 3; pass++)
{
if (pass > 1)
{
if (defaultLocaleString.IsNotEmpty() || enLocaleString.IsNotEmpty())
break;
}
UINT32 i0, i1;
if (0 == pass)
{
if (ON_UNSET_UINT_INDEX == localeIndex)
continue;
i0 = localeIndex;
i1 = i0 + 1;
}
else if (1 == pass)
{
if (ON_UNSET_UINT_INDEX == enLocaleIndex || enLocaleIndex == localeIndex )
continue;
i0 = enLocaleIndex;
i1 = i0 + 1;
}
else
{
if (defaultLocaleString.IsNotEmpty())
break;
i0 = 0;
i1 = count;
}
for (UINT32 i = i0; i < i1; i++)
{
ON_wString strStringValue;
ON_wString strLocaleName;
if (i == localeIndex)
strLocaleName = preferedLocale;
else if (i == enLocaleIndex)
strLocaleName = enLocale;
for (int value = 0; value < (strLocaleName.IsEmpty()?2:1); value++)
{
const bool bStringValuePass = (0 == value);
UINT32 slen = 0;
hr = bStringValuePass
? pIDWriteLocalizedStrings->GetStringLength(i, &slen)
: pIDWriteLocalizedStrings->GetLocaleNameLength(i, &slen)
;
if (FAILED(hr))
continue;
if (slen < 1)
continue;
if (slen > 1024 * 1024)
continue; // sanity check
ON_wString& s = bStringValuePass ? strStringValue : strLocaleName;
s.ReserveArray(slen + 2);
wchar_t* buffer = s.Array();
buffer[0] = 0;
buffer[slen] = 0;
buffer[slen + 1] = 0;
hr = bStringValuePass
? pIDWriteLocalizedStrings->GetString(i, buffer, slen + 1)
: pIDWriteLocalizedStrings->GetLocaleName(i, buffer, slen + 1);
if (SUCCEEDED(hr) && 0 != buffer[0] && 0 == buffer[slen + 1])
{
s.SetLength(ON_wString::Length(buffer));
s.TrimLeftAndRight();
}
else
s = ON_wString::EmptyString;
if (bStringValuePass)
{
if (s.IsEmpty())
break;
}
}
if (strStringValue.IsEmpty())
continue;
if ( pass >= 2 && defaultLocaleString.IsEmpty() )
{
defaultLocaleString = strStringValue;
defaultLocale = strLocaleName;
}
if (i == localeIndex)
{
defaultLocaleString = strStringValue;
defaultLocale = strLocaleName;
}
if (i == enLocaleIndex)
{
enLocaleString = strStringValue;
enLocale = strLocaleName;
}
if (
defaultLocaleString.IsNotEmpty()
&& enLocaleString.IsNotEmpty()
)
{
break;
}
}
}
if (defaultLocaleString.IsEmpty())
{
defaultLocaleString = enLocaleString;
defaultLocale = enLocale;
}
return defaultLocaleString.IsNotEmpty();
}
static bool Internal_GetLocalizeStrings(
const wchar_t* preferedLocale,
IDWriteLocalizedStrings* pIDWriteLocalizedStrings,
ON_wString& defaultLocaleString,
ON_wString& enLocaleString
)
{
ON_wString defaultLocale;
ON_wString enusLocale;
return Internal_GetLocalizeStrings(
preferedLocale,
pIDWriteLocalizedStrings,
defaultLocaleString, defaultLocale,
enLocaleString, enusLocale
);
}
static void Internal_PrintLocalizedNames(
const ON_wString stringDescription,
const wchar_t* preferedLocale,
IDWriteLocalizedStrings* pDWriteLocalizedStrings,
ON_TextLog& text_log
)
{
ON_ClassArray<ON_wString> localizedStrings;
ON_wString preferedString;
ON_wString enusString;
Internal_GetLocalizeStrings(preferedLocale, pDWriteLocalizedStrings, preferedString, enusString);
text_log.Print(L"%ls: \"%ls\"\n", static_cast<const wchar_t*>(stringDescription), static_cast<const wchar_t*>(preferedString));
if (enusString.IsNotEmpty() && enusString != preferedString)
{
text_log.PushIndent();
text_log.Print(
L"locale \"en-us\": \"%ls\"\n",
static_cast<const wchar_t*>(enusString)
);
text_log.PopIndent();
}
}
class Internal_DWriteFontInformation
{
public:
Internal_DWriteFontInformation(
DWRITE_INFORMATIONAL_STRING_ID id,
const wchar_t* description
)
: m_id(id)
, m_description(description)
{}
DWRITE_INFORMATIONAL_STRING_ID m_id = DWRITE_INFORMATIONAL_STRING_NONE;
ON_wString m_description;
};
static const ON_wString Internal_DWRITE_FONT_WEIGHT_ToString(DWRITE_FONT_WEIGHT dwrite_weight)
{
ON_wString s;
switch (dwrite_weight)
{
case DWRITE_FONT_WEIGHT_THIN: s = L"THIN"; break;// 100
//case DWRITE_FONT_WEIGHT_EXTRA_LIGHT: s = L""; break; // 200
case DWRITE_FONT_WEIGHT_ULTRA_LIGHT: s = L"ULTRA_LIGHT"; break;// 200,
case DWRITE_FONT_WEIGHT_LIGHT: s = L"LIGHT"; break; // 300,
case DWRITE_FONT_WEIGHT_SEMI_LIGHT: s = L"SEMI_LIGHT"; break; // 350,
case DWRITE_FONT_WEIGHT_NORMAL: s = L"NORMAL"; break; // 400,
//case DWRITE_FONT_WEIGHT_REGULAR: s = L""; break; // 400,
case DWRITE_FONT_WEIGHT_MEDIUM: s = L"MEDIUM"; break; // 500,
//case DWRITE_FONT_WEIGHT_DEMI_BOLD: s = L""; break; // 600,
case DWRITE_FONT_WEIGHT_SEMI_BOLD: s = L"SEMI_BOLD"; break; // 600,
case DWRITE_FONT_WEIGHT_BOLD: s = L"BOLD"; break; // 700,
//case DWRITE_FONT_WEIGHT_EXTRA_BOLD: s = L""; break; // 800,
case DWRITE_FONT_WEIGHT_ULTRA_BOLD: s = L"ULTRA_BOLD"; break; // 800,
//case DWRITE_FONT_WEIGHT_BLACK: s = L""; break; // 900,
case DWRITE_FONT_WEIGHT_HEAVY: s = L"HEAVY"; break; // 900,
//case DWRITE_FONT_WEIGHT_EXTRA_BLACK: s = L""; break; // 950,
case DWRITE_FONT_WEIGHT_ULTRA_BLACK: s = L"ULTRA_BLACK"; break; // 950
default:
s = ON_wString::FromNumber((unsigned int)dwrite_weight); break;
};
return s;
}
static const ON_wString Internal_DWRITE_FONT_STRETCH_ToString(DWRITE_FONT_STRETCH dwrite_stretch)
{
ON_wString s;
switch (dwrite_stretch)
{
case DWRITE_FONT_STRETCH_UNDEFINED: s = L"UNDEFINED"; break; // 0,
case DWRITE_FONT_STRETCH_ULTRA_CONDENSED: s = L"ULTRA_CONDENSED"; break; // 1,
case DWRITE_FONT_STRETCH_EXTRA_CONDENSED: s = L"EXTRA_CONDENSED"; break; // 2,
case DWRITE_FONT_STRETCH_CONDENSED: s = L"CONDENSED"; break; // 3,
case DWRITE_FONT_STRETCH_SEMI_CONDENSED: s = L"CONDENSED"; break; // 4,
case DWRITE_FONT_STRETCH_NORMAL: s = L"NORMAL"; break; // 5,
//case DWRITE_FONT_STRETCH_MEDIUM: s = L"MEDIUM"; break; // 5,
case DWRITE_FONT_STRETCH_SEMI_EXPANDED: s = L"SEMI_EXPANDED"; break; // 6,
case DWRITE_FONT_STRETCH_EXPANDED: s = L"EXPANDED"; break; // 7,
case DWRITE_FONT_STRETCH_EXTRA_EXPANDED: s = L"EXTRA_EXPANDED"; break; // 8,
case DWRITE_FONT_STRETCH_ULTRA_EXPANDED: s = L"ULTRA_EXPANDED"; break; // 9 }; break;
default:
s = ON_wString::FromNumber((unsigned int)dwrite_stretch); break;
}
return s;
}
static const ON_wString Internal_DWRITE_FONT_STYLE_ToString(DWRITE_FONT_STYLE dwrite_style)
{
ON_wString s;
switch (dwrite_style)
{
case DWRITE_FONT_STYLE_NORMAL: s = L"NORMAL"; break;
case DWRITE_FONT_STYLE_OBLIQUE: s = L"OBLIQUE"; break;
case DWRITE_FONT_STYLE_ITALIC: s = L"ITALIC"; break;
default:
s = ON_wString::FromNumber((unsigned int)dwrite_style); break;
};
return s;
}
void ON_Font::DumpWindowsDWriteFont(
IDWriteFont* dwrite_font,
const wchar_t* preferedLocale,
ON_TextLog& text_log
)
{
if (nullptr == dwrite_font)
{
text_log.Print("IDWriteFont = nullptr\n");
return;
}
const DWRITE_FONT_SIMULATIONS simulation = dwrite_font->GetSimulations();
if (DWRITE_FONT_SIMULATIONS_NONE != simulation)
text_log.Print("IDWriteFont SIMULATED:\n");
else
text_log.Print("IDWriteFont:\n");
ON_TextLogIndent indent1(text_log);
HRESULT hr;
// Family name
Microsoft::WRL::ComPtr<IDWriteFontFamily> pIDWriteFontFamily = nullptr;
hr = dwrite_font->GetFontFamily(&pIDWriteFontFamily);
if ((SUCCEEDED(hr)) && nullptr != pIDWriteFontFamily)
{
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> familyNames = nullptr;
hr = pIDWriteFontFamily->GetFamilyNames(&familyNames);
if (SUCCEEDED(hr))
{
Internal_PrintLocalizedNames(L"Family name", preferedLocale, familyNames.Get(), text_log);
}
}
// Face name
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> faceNames = nullptr;
hr = dwrite_font->GetFaceNames(&faceNames);
if (SUCCEEDED(hr))
Internal_PrintLocalizedNames(L"Face name", preferedLocale, faceNames.Get(), text_log);
const DWRITE_FONT_WEIGHT dwrite_weight = dwrite_font->GetWeight();
const ON_wString weightString = Internal_DWRITE_FONT_WEIGHT_ToString(dwrite_weight);
text_log.Print("Weight = %ls\n", static_cast<const wchar_t*>(weightString));
const DWRITE_FONT_STYLE dwrite_style = dwrite_font->GetStyle();
const ON_wString styleString = Internal_DWRITE_FONT_STYLE_ToString(dwrite_style);
text_log.Print("Style = %ls\n", static_cast<const wchar_t*>(styleString));
const DWRITE_FONT_STRETCH dwrite_stretch = dwrite_font->GetStretch();
const ON_wString stretchString = Internal_DWRITE_FONT_STRETCH_ToString(dwrite_stretch);
text_log.Print("Stretch = %ls\n", static_cast<const wchar_t*>(stretchString));
const bool bIsSymbolFont = (dwrite_font->IsSymbolFont() ? true : false);
text_log.Print("IsSymbolFont = %s.\n",(bIsSymbolFont?"true":"false"));
if (DWRITE_FONT_SIMULATIONS_NONE != simulation)
{
const bool bBold = ((ON__UINT32)DWRITE_FONT_SIMULATIONS_BOLD) & ((ON__UINT32)simulation);
const bool bOblique = ((ON__UINT32)DWRITE_FONT_SIMULATIONS_OBLIQUE) & ((ON__UINT32)simulation);
text_log.Print("Simulations:");
if (bBold)
text_log.Print(" BOLD");
if (bOblique)
text_log.Print(" OBLIQUE");
ON__UINT32 s = 0;
if (bBold)
s |= (ON__UINT32)DWRITE_FONT_SIMULATIONS_BOLD;
if (bOblique)
s |= (ON__UINT32)DWRITE_FONT_SIMULATIONS_OBLIQUE;
if ( s != (ON__UINT32)simulation )
text_log.Print(" other");
text_log.PrintNewLine();
}
// Other names:
Internal_DWriteFontInformation info_strings[] =
{
// field 4
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_FULL_NAME,L"DWrite full name"),
// field 6
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME,L"DWrite PostScript name"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES,L"GDI family name"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES,L"GDI sub-family name"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_WEIGHT_STRETCH_STYLE_FAMILY_NAME,L"DWrite weight-stretch-style model family name"),
// other fields - useful when trying to compare fonts / bugs from different computers
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_COPYRIGHT_NOTICE,L"DWrite field 0 copyright"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_VERSION_STRINGS,L"DWrite field 5 version"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_TRADEMARK,L"DWrite field 7 trademark"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_MANUFACTURER,L"DWrite field 8 manufacturer"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_DESIGNER,L"DWrite field 9 designer/foundary"),
// DWRITE_INFORMATIONAL_STRING_DESCRIPTION gets field 10 from the ttf file.
// Opennurbs searches the description saved in field 10 of the name table
// for the strings "Engraving - single stroke" / "Engraving - double stroke" / "Engraving"
// to identify fonts that are desgned for engraving (and which tend to render poorly when
// used to dispaly text devices like screens, monitors, and printers).
// The SLF (single line fonts) are examples of fonts that have Engraving in field 10.
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_DESCRIPTION,L"DWrite field 10 description"),
// other fields - useful when trying to compare fonts / bugs from different computers
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_FONT_VENDOR_URL,L"DWrite field 11 vendor URL"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_DESIGNER_URL,L"DWrite field 12 designer URL"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_LICENSE_DESCRIPTION,L"DWrite field 13 license"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_LICENSE_INFO_URL,L"DWrite field 14 license URL"),
Internal_DWriteFontInformation(DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME,L"Dwrite field 20 PostScript CID findfont name")
};
const size_t info_strings_count = sizeof(info_strings) / sizeof(info_strings[0]);
for (size_t i = 0; i < info_strings_count; i++)
{
BOOL exists = false;
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> fontNames = nullptr;
hr = dwrite_font->GetInformationalStrings(info_strings[i].m_id,&fontNames,&exists);
if (SUCCEEDED(hr) && exists)
Internal_PrintLocalizedNames(info_strings[i].m_description, preferedLocale, fontNames.Get(), text_log);
}
const ON_wString postscriptName = ON_Font::PostScriptNameFromWindowsDWriteFont(dwrite_font, preferedLocale);
text_log.Print(L"ON_Font PostScript name = \"%ls\"\n", static_cast<const wchar_t*>(postscriptName));
// Opennurbs searches the description saved in field 10 of the name table
// for the strings "Engraving - single stroke" / "Engraving - double stroke" / "Engraving"
// to identify fonts that are desgned for engraving (and which tend to render poorly when
// used to dispaly text devices like screens, monitors, and printers).
// The SLF (single line fonts) are examples of fonts that have Engraving in field 10.
const ON_wString field_10_description = ON_Font::Field_10_DescriptionFromWindowsDWriteFont(dwrite_font, preferedLocale);
text_log.Print(L"ON_Font field 10 description = \"%ls\"\n", static_cast<const wchar_t*>(field_10_description));
bool bGotLogfont = false;
for (;;)
{
IDWriteGdiInterop* dwriteGdiInterop = ON_IDWrite::GdiInterop();
if (nullptr == dwriteGdiInterop)
break;
BOOL isSystemFont = false;
LOGFONTW logfont;
memset(&logfont, 0, sizeof(logfont));
hr = dwriteGdiInterop->ConvertFontToLOGFONT(dwrite_font, &logfont, &isSystemFont);
if (FAILED(hr))
break;
text_log.Print("GDI interop IsSystemFont = %s\n", (isSystemFont ? "true" : "false"));
text_log.Print("GDI interop ");
ON_Font::DumpLogfont(&logfont, text_log);
bGotLogfont = true;
break;
}
if (false == bGotLogfont)
{
text_log.Print("GDI interop LOGFONT - FAILED.\n");
}
}
ON_Font::Stretch ON_Font::FontStretchFromDWriteStretch(
unsigned int dwrite_stretch,
ON_Font::Stretch undefined_result
)
{
ON_Font::Stretch font_stretch;
switch (dwrite_stretch)
{
case DWRITE_FONT_STRETCH_UNDEFINED:
font_stretch = undefined_result;
break;
case DWRITE_FONT_STRETCH_ULTRA_CONDENSED:
font_stretch = ON_Font::Stretch::Ultracondensed;
break;
case DWRITE_FONT_STRETCH_EXTRA_CONDENSED:
font_stretch = ON_Font::Stretch::Extracondensed;
break;
case DWRITE_FONT_STRETCH_CONDENSED:
font_stretch = ON_Font::Stretch::Condensed;
break;
case DWRITE_FONT_STRETCH_SEMI_CONDENSED:
font_stretch = ON_Font::Stretch::Semicondensed;
break;
case DWRITE_FONT_STRETCH_MEDIUM:
font_stretch = ON_Font::Stretch::Medium;
break;
case DWRITE_FONT_STRETCH_SEMI_EXPANDED:
font_stretch = ON_Font::Stretch::Semiexpanded;
break;
case DWRITE_FONT_STRETCH_EXPANDED:
font_stretch = ON_Font::Stretch::Expanded;
break;
case DWRITE_FONT_STRETCH_EXTRA_EXPANDED:
font_stretch = ON_Font::Stretch::Extraexpanded;
break;
case DWRITE_FONT_STRETCH_ULTRA_EXPANDED:
font_stretch = ON_Font::Stretch::Ultraexpanded;
break;
default:
font_stretch = undefined_result;
break;
}
return font_stretch;
}
const ON_wString ON_Font::PostScriptNameFromWindowsDWriteFont(
IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
for (;;)
{
if (nullptr == dwrite_font)
break;
BOOL exists = false;
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> postscriptNames = nullptr;
HRESULT hr = dwrite_font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME, &postscriptNames, &exists);
if (FAILED(hr))
break;
ON_wString loc_PostScriptName;
ON_wString en_PostScriptName;
if (exists)
Internal_GetLocalizeStrings(preferedLocale, postscriptNames.Get(), loc_PostScriptName, en_PostScriptName);
// This was wrong.
// Bahnschrift is an OpenType variable font and all faces of variable fonts
// end up with the same PostScript name. In short, a PostScript name property
// cannot be used as a "unique id" for a font face.
////if (ON_wString::EqualOrdinal(L"Bahnschrift", postscriptName, true))
////{
//// // All faces of Bahnshrift (Win 10 en-us Feb 2018) return the same PostScriptName ( "Bahnschrift" ) A bug in the font file?
//// ON_wString suffix;
//// const DWRITE_FONT_WEIGHT weight = dwrite_font->GetWeight();
//// switch (weight)
//// {
//// case DWRITE_FONT_WEIGHT_THIN: suffix += L"Thin"; break; //; // 100
////
//// //case DWRITE_FONT_WEIGHT_EXTRA_LIGHT: suffix += L"Bold"; break; //; // 200
//// case DWRITE_FONT_WEIGHT_ULTRA_LIGHT: suffix += L"UltraLight"; break; //; // 200,
////
//// case DWRITE_FONT_WEIGHT_LIGHT: suffix += L"Light"; break; //; // 300,
//// case DWRITE_FONT_WEIGHT_SEMI_LIGHT: suffix += L"Semilight"; break; //; // 350,
////
//// case DWRITE_FONT_WEIGHT_NORMAL: break;
////
//// case DWRITE_FONT_WEIGHT_MEDIUM: suffix += L"Medium"; break; //; // 500,
////
//// //case DWRITE_FONT_WEIGHT_DEMI_BOLD: suffix += L"Bold"; break; //; // 600,
//// case DWRITE_FONT_WEIGHT_SEMI_BOLD: suffix += L"Semibold"; break; //; // 600,
////
//// case DWRITE_FONT_WEIGHT_BOLD: suffix += L"Bold"; break; //; // 700,
////
//// //case DWRITE_FONT_WEIGHT_EXTRA_BOLD: suffix += L"Bold"; break; //; // 800,
//// case DWRITE_FONT_WEIGHT_ULTRA_BOLD: suffix += L"UltraBold"; break; //; // 800,
////
//// //case DWRITE_FONT_WEIGHT_BLACK: suffix += L"Bold"; break; //; // 900,
//// case DWRITE_FONT_WEIGHT_HEAVY: suffix += L"Heavy"; break; //; // 900,
////
//// //case DWRITE_FONT_WEIGHT_EXTRA_BLACK: suffix += L"Bold"; break; //; // 950,
//// case DWRITE_FONT_WEIGHT_ULTRA_BLACK: suffix += L"UltraBlack"; break; //; // 950
////
//// default:
//// break;
//// }
////
//// const DWRITE_FONT_STYLE style = dwrite_font->GetStyle();
//// switch (style)
//// {
//// case DWRITE_FONT_STYLE_NORMAL: break;
//// case DWRITE_FONT_STYLE_OBLIQUE: suffix += L"Oblique"; break;
//// case DWRITE_FONT_STYLE_ITALIC: suffix += L"Italic"; break;
//// default:
//// break;
//// }
////
//// if (suffix.IsNotEmpty())
//// {
//// postscriptName += ON_wString::HyphenMinus;
//// postscriptName += suffix;
//// }
////}
return loc_PostScriptName.IsNotEmpty() ? loc_PostScriptName : en_PostScriptName;
}
return ON_wString::EmptyString;
}
static const ON_wString Internal_InfoStringFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
enum DWRITE_INFORMATIONAL_STRING_ID info_string_id,
const wchar_t* preferedLocale
)
{
for (;;)
{
if (nullptr == dwrite_font)
break;
BOOL exists = false;
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> info_string = nullptr;
HRESULT hr = dwrite_font->GetInformationalStrings(info_string_id, &info_string, &exists);
if (FAILED(hr))
break;
ON_wString loc_description;
ON_wString en_description;
if (exists)
Internal_GetLocalizeStrings(preferedLocale, info_string.Get(), loc_description, en_description);
return loc_description.IsNotEmpty() ? loc_description : en_description;
}
return ON_wString::EmptyString;
}
const ON_wString ON_Font::WeightStretchStyleModelFamilyNameFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_WEIGHT_STRETCH_STYLE_FAMILY_NAME, preferedLocale);
}
const ON_wString ON_Font::Field_0_CopyrightFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_COPYRIGHT_NOTICE, preferedLocale);
}
const ON_wString ON_Font::Field_5_VersionFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_VERSION_STRINGS, preferedLocale);
}
const ON_wString ON_Font::Field_7_TrademarkFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_TRADEMARK, preferedLocale);
}
const ON_wString ON_Font::Field_8_ManufacturerFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_MANUFACTURER, preferedLocale);
}
const ON_wString ON_Font::Field_9_DesignerFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_DESIGNER, preferedLocale);
}
// Returns the desription saved in field 10.
// Opennurbs searches the description saved in field 10 of the name table
// for the strings "Engraving - single stroke" / "Engraving - double stroke" / "Engraving"
// to identify fonts that are desgned for engraving (and which tend to render poorly when
// used to dispaly text devices like screens, monitors, and printers).
// The SLF (single line fonts) are examples of fonts that have Engraving in field 10.
const ON_wString ON_Font::Field_10_DescriptionFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font,DWRITE_INFORMATIONAL_STRING_DESCRIPTION, preferedLocale);
}
const ON_wString ON_Font::Field_11_VendorURLFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_FONT_VENDOR_URL, preferedLocale);
}
const ON_wString ON_Font::Field_12_DesignerURLFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_DESIGNER_URL, preferedLocale);
}
const ON_wString ON_Font::Field_13_LicenseFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_LICENSE_DESCRIPTION, preferedLocale);
}
const ON_wString ON_Font::Field_14_LicenseURLFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_LICENSE_INFO_URL, preferedLocale);
}
const ON_wString ON_Font::Field_20_PostScriptCIDNameFromWindowsDWriteFont(
struct IDWriteFont* dwrite_font,
const wchar_t* preferedLocale
)
{
return Internal_InfoStringFromWindowsDWriteFont(dwrite_font, DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME, preferedLocale);
}
void ON_WindowsDWriteFontInformation::Dump(ON_TextLog& text_log) const
{
text_log.Print("IDWriteFont:\n");
const bool bTerse = text_log.LevelOfDetailIsAtLeast(ON_TextLog::LevelOfDetail::Medium);
const bool bChatty = text_log.LevelOfDetailIsAtLeast(ON_TextLog::LevelOfDetail::Medium);
const bool bVerbose = text_log.LevelOfDetailIsAtLeast(ON_TextLog::LevelOfDetail::Maximum);
ON_TextLogIndent indent1(text_log);
if ( bVerbose )
{
if (m_prefered_locale.IsNotEmpty())
text_log.Print("Prefered locale = \"%ls\"\n", static_cast<const wchar_t*>(m_prefered_locale));
if (FamilyName().IsNotEmpty())
{
if (FaceName().IsNotEmpty())
text_log.Print("Iteration index = family[%d].font[%u]\n", m_family_index, m_family_font_index);
else
text_log.Print("Iteration index = family[%d]\n", m_family_index);
}
}
ON_wString family_name = m_loc_family_name;
ON_wString face_name = m_loc_face_name;
ON_wString postscript_name = m_loc_postscript_name;
ON_wString logfont_name = m_loc_gdi_family_name;
if (false == bChatty)
{
if (family_name.IsEmpty())
family_name = m_en_family_name;
if (face_name.IsEmpty())
face_name = m_en_face_name;
if (postscript_name.IsEmpty())
postscript_name = m_en_postscript_name;
if (logfont_name.IsEmpty())
logfont_name = m_en_gdi_family_name;
}
if (bChatty)
text_log.Print(L"Localized Names:\n");
else
text_log.Print(L"Names:\n");
text_log.PushIndent();
text_log.Print(L"Family name = \"%ls\"\n", static_cast<const wchar_t*>(family_name));
text_log.Print(L"Face name = \"%ls\"\n", static_cast<const wchar_t*>(face_name));
text_log.Print(L"PostScript name = \"%ls\"\n", static_cast<const wchar_t*>(postscript_name));
text_log.Print(L"GDI LOGFONT name = \"%ls\"\n", static_cast<const wchar_t*>(logfont_name));
if ( bChatty )
{
text_log.Print(L"GDI subfamily name = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_gdi_subfamily_name));
text_log.Print(L"Full name = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_full_name));
if ( bVerbose )
{
text_log.Print(L"Direct Write Weight-Stretch-Style Model Name = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_weight_stretch_style_model_name));
text_log.Print(L"Field 0 Copyright = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_0_copyright));
text_log.Print(L"Field 5 Version = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_5_version));
text_log.Print(L"Field 7 Trademark = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_7_trademark));
text_log.Print(L"Field 8 Manufacturer = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_8_manufacturer));
text_log.Print(L"Field 9 Designer = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_9_designer));
text_log.Print(L"Field 10 Description = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_10_description));
text_log.Print(L"Field 11 Vendor URL = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_11_vendor_URL));
text_log.Print(L"Field 12 Designer_URL = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_12_designer_URL));
text_log.Print(L"Field 13 License = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_13_license));
text_log.Print(L"Field 14 License URL = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_14_license_URL));
text_log.Print(L"Field 20 PostScript CID Name = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_20_postscript_cid));
}
}
if ( false == bVerbose )
{
if (ON_OutlineFigure::Type::Unset != ON_OutlineFigure::FigureTypeFromField10Description(m_loc_field_10_description))
text_log.Print(L"Field 10 Description = \"%ls\"\n", static_cast<const wchar_t*>(m_loc_field_10_description));
else if (ON_OutlineFigure::Type::Unset != ON_OutlineFigure::FigureTypeFromField10Description(m_en_field_10_description))
text_log.Print(L"Field 10 Description = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_10_description));
}
text_log.PopIndent();
if ( bChatty )
{
text_log.Print(L"English Names:\n");
ON_TextLogIndent indent2(text_log);
text_log.Print(L"Family name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_family_name));
text_log.Print(L"Face name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_face_name));
text_log.Print(L"PostScript name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_postscript_name));
text_log.Print(L"GDI LOGFONT name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_gdi_family_name));
text_log.Print(L"GDI subfamily name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_gdi_subfamily_name));
text_log.Print(L"Full name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_full_name));
if ( bVerbose )
{
text_log.Print(L"Direct Write Weight-Stretch-Style Model Name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_weight_stretch_style_model_name));
text_log.Print(L"Field 0 Copyright = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_0_copyright));
text_log.Print(L"Field 5 Version = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_5_version));
text_log.Print(L"Field 7 Trademark = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_7_trademark));
text_log.Print(L"Field 8 Manufacturer = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_8_manufacturer));
text_log.Print(L"Field 9 Designer = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_9_designer));
text_log.Print(L"Field 10 Description = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_10_description));
text_log.Print(L"Field 11 Vendor URL = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_11_vendor_URL));
text_log.Print(L"Field 12 Designer_URL = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_12_designer_URL));
text_log.Print(L"Field 13 License = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_13_license));
text_log.Print(L"Field 14 License URL = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_14_license_URL));
text_log.Print(L"Field 20 PostScript CID Name = \"%ls\"\n", static_cast<const wchar_t*>(m_en_field_20_postscript_cid));
}
}
if (bChatty)
{
if (m_bSimulatedBold || m_bSimulatedOblique || m_bSimulatedOther)
{
text_log.Print("Simuilations =");
if (m_bSimulatedBold)
text_log.Print(" BOLD");
if (m_bSimulatedOblique)
text_log.Print(" OBLIQUE");
if (m_bSimulatedOther)
text_log.Print(" other");
text_log.PrintNewLine();
}
const DWRITE_FONT_WEIGHT dwrite_weight = (DWRITE_FONT_WEIGHT)m_weight;
const ON_wString weightString = Internal_DWRITE_FONT_WEIGHT_ToString(dwrite_weight);
text_log.Print(L"Weight = %ls\n", static_cast<const wchar_t*>(weightString));
const DWRITE_FONT_STYLE dwrite_style = (DWRITE_FONT_STYLE)m_style;
const ON_wString styleString = Internal_DWRITE_FONT_STYLE_ToString(dwrite_style);
text_log.Print(L"Style = %ls\n", static_cast<const wchar_t*>(styleString));