-
Notifications
You must be signed in to change notification settings - Fork 3
/
DWrite.h
4995 lines (4538 loc) · 202 KB
/
DWrite.h
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) Microsoft Corporation. All rights reserved.
//
// Abstract:
// DirectX Typography Services public API definitions.
//
//----------------------------------------------------------------------------
#ifndef DWRITE_H_INCLUDED
#define DWRITE_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef DWRITE_NO_WINDOWS_H
#include <specstrings.h>
#include <unknwn.h>
#endif // DWRITE_NO_WINDOWS_H
#include <dcommon.h>
#ifndef DWRITE_DECLARE_INTERFACE
#define DWRITE_DECLARE_INTERFACE(iid) DECLSPEC_UUID(iid) DECLSPEC_NOVTABLE
#endif
#ifndef DWRITE_EXPORT
#define DWRITE_EXPORT __declspec(dllimport) WINAPI
#endif
/// <summary>
/// The type of a font represented by a single font file.
/// Font formats that consist of multiple files, e.g. Type 1 .PFM and .PFB, have
/// separate enum values for each of the file type.
/// </summary>
enum DWRITE_FONT_FILE_TYPE
{
/// <summary>
/// Font type is not recognized by the DirectWrite font system.
/// </summary>
DWRITE_FONT_FILE_TYPE_UNKNOWN,
/// <summary>
/// OpenType font with CFF outlines.
/// </summary>
DWRITE_FONT_FILE_TYPE_CFF,
/// <summary>
/// OpenType font with TrueType outlines.
/// </summary>
DWRITE_FONT_FILE_TYPE_TRUETYPE,
/// <summary>
/// OpenType font that contains a TrueType collection.
/// </summary>
DWRITE_FONT_FILE_TYPE_TRUETYPE_COLLECTION,
/// <summary>
/// Type 1 PFM font.
/// </summary>
DWRITE_FONT_FILE_TYPE_TYPE1_PFM,
/// <summary>
/// Type 1 PFB font.
/// </summary>
DWRITE_FONT_FILE_TYPE_TYPE1_PFB,
/// <summary>
/// Vector .FON font.
/// </summary>
DWRITE_FONT_FILE_TYPE_VECTOR,
/// <summary>
/// Bitmap .FON font.
/// </summary>
DWRITE_FONT_FILE_TYPE_BITMAP
};
/// <summary>
/// The file format of a complete font face.
/// Font formats that consist of multiple files, e.g. Type 1 .PFM and .PFB, have
/// a single enum entry.
/// </summary>
enum DWRITE_FONT_FACE_TYPE
{
/// <summary>
/// OpenType font face with CFF outlines.
/// </summary>
DWRITE_FONT_FACE_TYPE_CFF,
/// <summary>
/// OpenType font face with TrueType outlines.
/// </summary>
DWRITE_FONT_FACE_TYPE_TRUETYPE,
/// <summary>
/// OpenType font face that is a part of a TrueType collection.
/// </summary>
DWRITE_FONT_FACE_TYPE_TRUETYPE_COLLECTION,
/// <summary>
/// A Type 1 font face.
/// </summary>
DWRITE_FONT_FACE_TYPE_TYPE1,
/// <summary>
/// A vector .FON format font face.
/// </summary>
DWRITE_FONT_FACE_TYPE_VECTOR,
/// <summary>
/// A bitmap .FON format font face.
/// </summary>
DWRITE_FONT_FACE_TYPE_BITMAP,
/// <summary>
/// Font face type is not recognized by the DirectWrite font system.
/// </summary>
DWRITE_FONT_FACE_TYPE_UNKNOWN
};
/// <summary>
/// Specifies algorithmic style simulations to be applied to the font face.
/// Bold and oblique simulations can be combined via bitwise OR operation.
/// </summary>
enum DWRITE_FONT_SIMULATIONS
{
/// <summary>
/// No simulations are performed.
/// </summary>
DWRITE_FONT_SIMULATIONS_NONE = 0x0000,
/// <summary>
/// Algorithmic emboldening is performed.
/// </summary>
DWRITE_FONT_SIMULATIONS_BOLD = 0x0001,
/// <summary>
/// Algorithmic italicization is performed.
/// </summary>
DWRITE_FONT_SIMULATIONS_OBLIQUE = 0x0002
};
#ifdef DEFINE_ENUM_FLAG_OPERATORS
DEFINE_ENUM_FLAG_OPERATORS(DWRITE_FONT_SIMULATIONS);
#endif
/// <summary>
/// The font weight enumeration describes common values for degree of blackness or thickness of strokes of characters in a font.
/// Font weight values less than 1 or greater than 999 are considered to be invalid, and they are rejected by font API functions.
/// </summary>
enum DWRITE_FONT_WEIGHT
{
/// <summary>
/// Predefined font weight : Thin (100).
/// </summary>
DWRITE_FONT_WEIGHT_THIN = 100,
/// <summary>
/// Predefined font weight : Extra-light (200).
/// </summary>
DWRITE_FONT_WEIGHT_EXTRA_LIGHT = 200,
/// <summary>
/// Predefined font weight : Ultra-light (200).
/// </summary>
DWRITE_FONT_WEIGHT_ULTRA_LIGHT = 200,
/// <summary>
/// Predefined font weight : Light (300).
/// </summary>
DWRITE_FONT_WEIGHT_LIGHT = 300,
/// <summary>
/// Predefined font weight : Normal (400).
/// </summary>
DWRITE_FONT_WEIGHT_NORMAL = 400,
/// <summary>
/// Predefined font weight : Regular (400).
/// </summary>
DWRITE_FONT_WEIGHT_REGULAR = 400,
/// <summary>
/// Predefined font weight : Medium (500).
/// </summary>
DWRITE_FONT_WEIGHT_MEDIUM = 500,
/// <summary>
/// Predefined font weight : Demi-bold (600).
/// </summary>
DWRITE_FONT_WEIGHT_DEMI_BOLD = 600,
/// <summary>
/// Predefined font weight : Semi-bold (600).
/// </summary>
DWRITE_FONT_WEIGHT_SEMI_BOLD = 600,
/// <summary>
/// Predefined font weight : Bold (700).
/// </summary>
DWRITE_FONT_WEIGHT_BOLD = 700,
/// <summary>
/// Predefined font weight : Extra-bold (800).
/// </summary>
DWRITE_FONT_WEIGHT_EXTRA_BOLD = 800,
/// <summary>
/// Predefined font weight : Ultra-bold (800).
/// </summary>
DWRITE_FONT_WEIGHT_ULTRA_BOLD = 800,
/// <summary>
/// Predefined font weight : Black (900).
/// </summary>
DWRITE_FONT_WEIGHT_BLACK = 900,
/// <summary>
/// Predefined font weight : Heavy (900).
/// </summary>
DWRITE_FONT_WEIGHT_HEAVY = 900,
/// <summary>
/// Predefined font weight : Extra-black (950).
/// </summary>
DWRITE_FONT_WEIGHT_EXTRA_BLACK = 950,
/// <summary>
/// Predefined font weight : Ultra-black (950).
/// </summary>
DWRITE_FONT_WEIGHT_ULTRA_BLACK = 950
};
/// <summary>
/// The font stretch enumeration describes relative change from the normal aspect ratio
/// as specified by a font designer for the glyphs in a font.
/// Values less than 1 or greater than 9 are considered to be invalid, and they are rejected by font API functions.
/// </summary>
enum DWRITE_FONT_STRETCH
{
/// <summary>
/// Predefined font stretch : Not known (0).
/// </summary>
DWRITE_FONT_STRETCH_UNDEFINED = 0,
/// <summary>
/// Predefined font stretch : Ultra-condensed (1).
/// </summary>
DWRITE_FONT_STRETCH_ULTRA_CONDENSED = 1,
/// <summary>
/// Predefined font stretch : Extra-condensed (2).
/// </summary>
DWRITE_FONT_STRETCH_EXTRA_CONDENSED = 2,
/// <summary>
/// Predefined font stretch : Condensed (3).
/// </summary>
DWRITE_FONT_STRETCH_CONDENSED = 3,
/// <summary>
/// Predefined font stretch : Semi-condensed (4).
/// </summary>
DWRITE_FONT_STRETCH_SEMI_CONDENSED = 4,
/// <summary>
/// Predefined font stretch : Normal (5).
/// </summary>
DWRITE_FONT_STRETCH_NORMAL = 5,
/// <summary>
/// Predefined font stretch : Medium (5).
/// </summary>
DWRITE_FONT_STRETCH_MEDIUM = 5,
/// <summary>
/// Predefined font stretch : Semi-expanded (6).
/// </summary>
DWRITE_FONT_STRETCH_SEMI_EXPANDED = 6,
/// <summary>
/// Predefined font stretch : Expanded (7).
/// </summary>
DWRITE_FONT_STRETCH_EXPANDED = 7,
/// <summary>
/// Predefined font stretch : Extra-expanded (8).
/// </summary>
DWRITE_FONT_STRETCH_EXTRA_EXPANDED = 8,
/// <summary>
/// Predefined font stretch : Ultra-expanded (9).
/// </summary>
DWRITE_FONT_STRETCH_ULTRA_EXPANDED = 9
};
/// <summary>
/// The font style enumeration describes the slope style of a font face, such as Normal, Italic or Oblique.
/// Values other than the ones defined in the enumeration are considered to be invalid, and they are rejected by font API functions.
/// </summary>
enum DWRITE_FONT_STYLE
{
/// <summary>
/// Font slope style : Normal.
/// </summary>
DWRITE_FONT_STYLE_NORMAL,
/// <summary>
/// Font slope style : Oblique.
/// </summary>
DWRITE_FONT_STYLE_OBLIQUE,
/// <summary>
/// Font slope style : Italic.
/// </summary>
DWRITE_FONT_STYLE_ITALIC
};
/// <summary>
/// The informational string enumeration identifies a string in a font.
/// </summary>
enum DWRITE_INFORMATIONAL_STRING_ID
{
/// <summary>
/// Unspecified name ID.
/// </summary>
DWRITE_INFORMATIONAL_STRING_NONE,
/// <summary>
/// Copyright notice provided by the font.
/// </summary>
DWRITE_INFORMATIONAL_STRING_COPYRIGHT_NOTICE,
/// <summary>
/// String containing a version number.
/// </summary>
DWRITE_INFORMATIONAL_STRING_VERSION_STRINGS,
/// <summary>
/// Trademark information provided by the font.
/// </summary>
DWRITE_INFORMATIONAL_STRING_TRADEMARK,
/// <summary>
/// Name of the font manufacturer.
/// </summary>
DWRITE_INFORMATIONAL_STRING_MANUFACTURER,
/// <summary>
/// Name of the font designer.
/// </summary>
DWRITE_INFORMATIONAL_STRING_DESIGNER,
/// <summary>
/// URL of font designer (with protocol, e.g., http://, ftp://).
/// </summary>
DWRITE_INFORMATIONAL_STRING_DESIGNER_URL,
/// <summary>
/// Description of the font. Can contain revision information, usage recommendations, history, features, etc.
/// </summary>
DWRITE_INFORMATIONAL_STRING_DESCRIPTION,
/// <summary>
/// URL of font vendor (with protocol, e.g., http://, ftp://). If a unique serial number is embedded in the URL, it can be used to register the font.
/// </summary>
DWRITE_INFORMATIONAL_STRING_FONT_VENDOR_URL,
/// <summary>
/// Description of how the font may be legally used, or different example scenarios for licensed use. This field should be written in plain language, not legalese.
/// </summary>
DWRITE_INFORMATIONAL_STRING_LICENSE_DESCRIPTION,
/// <summary>
/// URL where additional licensing information can be found.
/// </summary>
DWRITE_INFORMATIONAL_STRING_LICENSE_INFO_URL,
/// <summary>
/// GDI-compatible family name. Because GDI allows a maximum of four fonts per family, fonts in the same family may have different GDI-compatible family names
/// (e.g., "Arial", "Arial Narrow", "Arial Black").
/// </summary>
DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES,
/// <summary>
/// GDI-compatible subfamily name.
/// </summary>
DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES,
/// <summary>
/// Family name preferred by the designer. This enables font designers to group more than four fonts in a single family without losing compatibility with
/// GDI. This name is typically only present if it differs from the GDI-compatible family name.
/// </summary>
DWRITE_INFORMATIONAL_STRING_PREFERRED_FAMILY_NAMES,
/// <summary>
/// Subfamily name preferred by the designer. This name is typically only present if it differs from the GDI-compatible subfamily name.
/// </summary>
DWRITE_INFORMATIONAL_STRING_PREFERRED_SUBFAMILY_NAMES,
/// <summary>
/// Sample text. This can be the font name or any other text that the designer thinks is the best example to display the font in.
/// </summary>
DWRITE_INFORMATIONAL_STRING_SAMPLE_TEXT
};
/// <summary>
/// The DWRITE_FONT_METRICS structure specifies the metrics of a font face that
/// are applicable to all glyphs within the font face.
/// </summary>
struct DWRITE_FONT_METRICS
{
/// <summary>
/// The number of font design units per em unit.
/// Font files use their own coordinate system of font design units.
/// A font design unit is the smallest measurable unit in the em square,
/// an imaginary square that is used to size and align glyphs.
/// The concept of em square is used as a reference scale factor when defining font size and device transformation semantics.
/// The size of one em square is also commonly used to compute the paragraph identation value.
/// </summary>
UINT16 designUnitsPerEm;
/// <summary>
/// Ascent value of the font face in font design units.
/// Ascent is the distance from the top of font character alignment box to English baseline.
/// </summary>
UINT16 ascent;
/// <summary>
/// Descent value of the font face in font design units.
/// Descent is the distance from the bottom of font character alignment box to English baseline.
/// </summary>
UINT16 descent;
/// <summary>
/// Line gap in font design units.
/// Recommended additional white space to add between lines to improve legibility. The recommended line spacing
/// (baseline-to-baseline distance) is thus the sum of ascent, descent, and lineGap. The line gap is usually
/// positive or zero but can be negative, in which case the recommended line spacing is less than the height
/// of the character alignment box.
/// </summary>
INT16 lineGap;
/// <summary>
/// Cap height value of the font face in font design units.
/// Cap height is the distance from English baseline to the top of a typical English capital.
/// Capital "H" is often used as a reference character for the purpose of calculating the cap height value.
/// </summary>
UINT16 capHeight;
/// <summary>
/// x-height value of the font face in font design units.
/// x-height is the distance from English baseline to the top of lowercase letter "x", or a similar lowercase character.
/// </summary>
UINT16 xHeight;
/// <summary>
/// The underline position value of the font face in font design units.
/// Underline position is the position of underline relative to the English baseline.
/// The value is usually made negative in order to place the underline below the baseline.
/// </summary>
INT16 underlinePosition;
/// <summary>
/// The suggested underline thickness value of the font face in font design units.
/// </summary>
UINT16 underlineThickness;
/// <summary>
/// The strikethrough position value of the font face in font design units.
/// Strikethrough position is the position of strikethrough relative to the English baseline.
/// The value is usually made positive in order to place the strikethrough above the baseline.
/// </summary>
INT16 strikethroughPosition;
/// <summary>
/// The suggested strikethrough thickness value of the font face in font design units.
/// </summary>
UINT16 strikethroughThickness;
};
/// <summary>
/// The DWRITE_GLYPH_METRICS structure specifies the metrics of an individual glyph.
/// The units depend on how the metrics are obtained.
/// </summary>
struct DWRITE_GLYPH_METRICS
{
/// <summary>
/// Specifies the X offset from the glyph origin to the left edge of the black box.
/// The glyph origin is the current horizontal writing position.
/// A negative value means the black box extends to the left of the origin (often true for lowercase italic 'f').
/// </summary>
INT32 leftSideBearing;
/// <summary>
/// Specifies the X offset from the origin of the current glyph to the origin of the next glyph when writing horizontally.
/// </summary>
UINT32 advanceWidth;
/// <summary>
/// Specifies the X offset from the right edge of the black box to the origin of the next glyph when writing horizontally.
/// The value is negative when the right edge of the black box overhangs the layout box.
/// </summary>
INT32 rightSideBearing;
/// <summary>
/// Specifies the vertical offset from the vertical origin to the top of the black box.
/// Thus, a positive value adds whitespace whereas a negative value means the glyph overhangs the top of the layout box.
/// </summary>
INT32 topSideBearing;
/// <summary>
/// Specifies the Y offset from the vertical origin of the current glyph to the vertical origin of the next glyph when writing vertically.
/// (Note that the term "origin" by itself denotes the horizontal origin. The vertical origin is different.
/// Its Y coordinate is specified by verticalOriginY value,
/// and its X coordinate is half the advanceWidth to the right of the horizontal origin).
/// </summary>
UINT32 advanceHeight;
/// <summary>
/// Specifies the vertical distance from the black box's bottom edge to the advance height.
/// Positive when the bottom edge of the black box is within the layout box.
/// Negative when the bottom edge of black box overhangs the layout box.
/// </summary>
INT32 bottomSideBearing;
/// <summary>
/// Specifies the Y coordinate of a glyph's vertical origin, in the font's design coordinate system.
/// The y coordinate of a glyph's vertical origin is the sum of the glyph's top side bearing
/// and the top (i.e. yMax) of the glyph's bounding box.
/// </summary>
INT32 verticalOriginY;
};
/// <summary>
/// Optional adjustment to a glyph's position. An glyph offset changes the position of a glyph without affecting
/// the pen position. Offsets are in logical, pre-transform units.
/// </summary>
struct DWRITE_GLYPH_OFFSET
{
/// <summary>
/// Offset in the advance direction of the run. A positive advance offset moves the glyph to the right
/// (in pre-transform coordinates) if the run is left-to-right or to the left if the run is right-to-left.
/// </summary>
FLOAT advanceOffset;
/// <summary>
/// Offset in the ascent direction, i.e., the direction ascenders point. A positive ascender offset moves
/// the glyph up (in pre-transform coordinates).
/// </summary>
FLOAT ascenderOffset;
};
/// <summary>
/// Specifies the type of DirectWrite factory object.
/// DirectWrite factory contains internal state such as font loader registration and cached font data.
/// In most cases it is recommended to use the shared factory object, because it allows multiple components
/// that use DirectWrite to share internal DirectWrite state and reduce memory usage.
/// However, there are cases when it is desirable to reduce the impact of a component,
/// such as a plug-in from an untrusted source, on the rest of the process by sandboxing and isolating it
/// from the rest of the process components. In such cases, it is recommended to use an isolated factory for the sandboxed
/// component.
/// </summary>
enum DWRITE_FACTORY_TYPE
{
/// <summary>
/// Shared factory allow for re-use of cached font data across multiple in process components.
/// Such factories also take advantage of cross process font caching components for better performance.
/// </summary>
DWRITE_FACTORY_TYPE_SHARED,
/// <summary>
/// Objects created from the isolated factory do not interact with internal DirectWrite state from other components.
/// </summary>
DWRITE_FACTORY_TYPE_ISOLATED
};
// Creates an OpenType tag as a 32bit integer such that
// the first character in the tag is the lowest byte,
// (least significant on little endian architectures)
// which can be used to compare with tags in the font file.
// This macro is compatible with DWRITE_FONT_FEATURE_TAG.
//
// Example: DWRITE_MAKE_OPENTYPE_TAG('c','c','m','p')
// Dword: 0x706D6363
//
#define DWRITE_MAKE_OPENTYPE_TAG(a,b,c,d) ( \
(static_cast<UINT32>(static_cast<UINT8>(d)) << 24) | \
(static_cast<UINT32>(static_cast<UINT8>(c)) << 16) | \
(static_cast<UINT32>(static_cast<UINT8>(b)) << 8) | \
static_cast<UINT32>(static_cast<UINT8>(a)))
interface IDWriteFontFileStream;
/// <summary>
/// Font file loader interface handles loading font file resources of a particular type from a key.
/// The font file loader interface is recommended to be implemented by a singleton object.
/// IMPORTANT: font file loader implementations must not register themselves with DirectWrite factory
/// inside their constructors and must not unregister themselves in their destructors, because
/// registration and unregistraton operations increment and decrement the object reference count respectively.
/// Instead, registration and unregistration of font file loaders with DirectWrite factory should be performed
/// outside of the font file loader implementation as a separate step.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("727cad4e-d6af-4c9e-8a08-d695b11caa49") IDWriteFontFileLoader : public IUnknown
{
/// <summary>
/// Creates a font file stream object that encapsulates an open file resource.
/// The resource is closed when the last reference to fontFileStream is released.
/// </summary>
/// <param name="fontFileReferenceKey">Font file reference key that uniquely identifies the font file resource
/// within the scope of the font loader being used.</param>
/// <param name="fontFileReferenceKeySize">Size of font file reference key in bytes.</param>
/// <param name="fontFileStream">Pointer to the newly created font file stream.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(CreateStreamFromKey)(
__in_bcount(fontFileReferenceKeySize) void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
__out IDWriteFontFileStream** fontFileStream
) PURE;
};
/// <summary>
/// A built-in implementation of IDWriteFontFileLoader interface that operates on local font files
/// and exposes local font file information from the font file reference key.
/// Font file references created using CreateFontFileReference use this font file loader.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("b2d9f3ec-c9fe-4a11-a2ec-d86208f7c0a2") IDWriteLocalFontFileLoader : public IDWriteFontFileLoader
{
/// <summary>
/// Obtains the length of the absolute file path from the font file reference key.
/// </summary>
/// <param name="fontFileReferenceKey">Font file reference key that uniquely identifies the local font file
/// within the scope of the font loader being used.</param>
/// <param name="fontFileReferenceKeySize">Size of font file reference key in bytes.</param>
/// <param name="filePathLength">Length of the file path string not including the terminated NULL character.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetFilePathLengthFromKey)(
__in_bcount(fontFileReferenceKeySize) void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
__out UINT32* filePathLength
) PURE;
/// <summary>
/// Obtains the absolute font file path from the font file reference key.
/// </summary>
/// <param name="fontFileReferenceKey">Font file reference key that uniquely identifies the local font file
/// within the scope of the font loader being used.</param>
/// <param name="fontFileReferenceKeySize">Size of font file reference key in bytes.</param>
/// <param name="filePath">Character array that receives the local file path.</param>
/// <param name="filePathSize">Size of the filePath array in character count including the terminated NULL character.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetFilePathFromKey)(
__in_bcount(fontFileReferenceKeySize) void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
__out_ecount_z(filePathSize) WCHAR* filePath,
UINT32 filePathSize
) PURE;
/// <summary>
/// Obtains the last write time of the file from the font file reference key.
/// </summary>
/// <param name="fontFileReferenceKey">Font file reference key that uniquely identifies the local font file
/// within the scope of the font loader being used.</param>
/// <param name="fontFileReferenceKeySize">Size of font file reference key in bytes.</param>
/// <param name="lastWriteTime">Last modified time of the font file.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetLastWriteTimeFromKey)(
__in_bcount(fontFileReferenceKeySize) void const* fontFileReferenceKey,
UINT32 fontFileReferenceKeySize,
__out FILETIME* lastWriteTime
) PURE;
};
/// <summary>
/// The interface for loading font file data.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("6d4865fe-0ab8-4d91-8f62-5dd6be34a3e0") IDWriteFontFileStream : public IUnknown
{
/// <summary>
/// Reads a fragment from a file.
/// </summary>
/// <param name="fragmentStart">Receives the pointer to the start of the font file fragment.</param>
/// <param name="fileOffset">Offset of the fragment from the beginning of the font file.</param>
/// <param name="fragmentSize">Size of the fragment in bytes.</param>
/// <param name="fragmentContext">The client defined context to be passed to the ReleaseFileFragment.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
/// <remarks>
/// IMPORTANT: ReadFileFragment() implementations must check whether the requested file fragment
/// is within the file bounds. Otherwise, an error should be returned from ReadFileFragment.
/// </remarks>
STDMETHOD(ReadFileFragment)(
__deref_out_bcount(fragmentSize) void const** fragmentStart,
UINT64 fileOffset,
UINT64 fragmentSize,
__out void** fragmentContext
) PURE;
/// <summary>
/// Releases a fragment from a file.
/// </summary>
/// <param name="fragmentContext">The client defined context of a font fragment returned from ReadFileFragment.</param>
STDMETHOD_(void, ReleaseFileFragment)(
void* fragmentContext
) PURE;
/// <summary>
/// Obtains the total size of a file.
/// </summary>
/// <param name="fileSize">Receives the total size of the file.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
/// <remarks>
/// Implementing GetFileSize() for asynchronously loaded font files may require
/// downloading the complete file contents, therefore this method should only be used for operations that
/// either require complete font file to be loaded (e.g., copying a font file) or need to make
/// decisions based on the value of the file size (e.g., validation against a persisted file size).
/// </remarks>
STDMETHOD(GetFileSize)(
__out UINT64* fileSize
) PURE;
/// <summary>
/// Obtains the last modified time of the file. The last modified time is used by DirectWrite font selection algorithms
/// to determine whether one font resource is more up to date than another one.
/// </summary>
/// <param name="lastWriteTime">Receives the last modifed time of the file in the format that represents
/// the number of 100-nanosecond intervals since January 1, 1601 (UTC).</param>
/// <returns>
/// Standard HRESULT error code. For resources that don't have a concept of the last modified time, the implementation of
/// GetLastWriteTime should return E_NOTIMPL.
/// </returns>
STDMETHOD(GetLastWriteTime)(
__out UINT64* lastWriteTime
) PURE;
};
/// <summary>
/// The interface that represents a reference to a font file.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("739d886a-cef5-47dc-8769-1a8b41bebbb0") IDWriteFontFile : public IUnknown
{
/// <summary>
/// This method obtains the pointer to the reference key of a font file. The pointer is only valid until the object that refers to it is released.
/// </summary>
/// <param name="fontFileReferenceKey">Pointer to the font file reference key.
/// IMPORTANT: The pointer value is valid until the font file reference object it is obtained from is released.</param>
/// <param name="fontFileReferenceKeySize">Size of font file reference key in bytes.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetReferenceKey)(
__deref_out_bcount(*fontFileReferenceKeySize) void const** fontFileReferenceKey,
__out UINT32* fontFileReferenceKeySize
) PURE;
/// <summary>
/// Obtains the file loader associated with a font file object.
/// </summary>
/// <param name="fontFileLoader">The font file loader associated with the font file object.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetLoader)(
__out IDWriteFontFileLoader** fontFileLoader
) PURE;
/// <summary>
/// Analyzes a file and returns whether it represents a font, and whether the font type is supported by the font system.
/// </summary>
/// <param name="isSupportedFontType">TRUE if the font type is supported by the font system, FALSE otherwise.</param>
/// <param name="fontFileType">The type of the font file. Note that even if isSupportedFontType is FALSE,
/// the fontFileType value may be different from DWRITE_FONT_FILE_TYPE_UNKNOWN.</param>
/// <param name="fontFaceType">The type of the font face that can be constructed from the font file.
/// Note that even if isSupportedFontType is FALSE, the fontFaceType value may be different from
/// DWRITE_FONT_FACE_TYPE_UNKNOWN.</param>
/// <param name="numberOfFaces">Number of font faces contained in the font file.</param>
/// <returns>
/// Standard HRESULT error code if there was a processing error during analysis.
/// </returns>
/// <remarks>
/// IMPORTANT: certain font file types are recognized, but not supported by the font system.
/// For example, the font system will recognize a file as a Type 1 font file,
/// but will not be able to construct a font face object from it. In such situations, Analyze will set
/// isSupportedFontType output parameter to FALSE.
/// </remarks>
STDMETHOD(Analyze)(
__out BOOL* isSupportedFontType,
__out DWRITE_FONT_FILE_TYPE* fontFileType,
__out_opt DWRITE_FONT_FACE_TYPE* fontFaceType,
__out UINT32* numberOfFaces
) PURE;
};
/// <summary>
/// Represents the internal structure of a device pixel (i.e., the physical arrangement of red,
/// green, and blue color components) that is assumed for purposes of rendering text.
/// </summary>
#ifndef DWRITE_PIXEL_GEOMETRY_DEFINED
enum DWRITE_PIXEL_GEOMETRY
{
/// <summary>
/// The red, green, and blue color components of each pixel are assumed to occupy the same point.
/// </summary>
DWRITE_PIXEL_GEOMETRY_FLAT,
/// <summary>
/// Each pixel comprises three vertical stripes, with red on the left, green in the center, and
/// blue on the right. This is the most common pixel geometry for LCD monitors.
/// </summary>
DWRITE_PIXEL_GEOMETRY_RGB,
/// <summary>
/// Each pixel comprises three vertical stripes, with blue on the left, green in the center, and
/// red on the right.
/// </summary>
DWRITE_PIXEL_GEOMETRY_BGR
};
#define DWRITE_PIXEL_GEOMETRY_DEFINED
#endif
/// <summary>
/// Represents a method of rendering glyphs.
/// </summary>
enum DWRITE_RENDERING_MODE
{
/// <summary>
/// Specifies that the rendering mode is determined automatically based on the font and size.
/// </summary>
DWRITE_RENDERING_MODE_DEFAULT,
/// <summary>
/// Specifies that no anti-aliasing is performed. Each pixel is either set to the foreground
/// color of the text or retains the color of the background.
/// </summary>
DWRITE_RENDERING_MODE_ALIASED,
/// <summary>
/// Specifies ClearType rendering with the same metrics as aliased text. Glyphs can only
/// be positioned on whole-pixel boundaries.
/// </summary>
DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC,
/// <summary>
/// Specifies ClearType rendering with the same metrics as text rendering using GDI using a font
/// created with CLEARTYPE_NATURAL_QUALITY. Glyph metrics are closer to their ideal values than
/// with aliased text, but glyphs are still positioned on whole-pixel boundaries.
/// </summary>
DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL,
/// <summary>
/// Specifies ClearType rendering with anti-aliasing in the horizontal dimension only. This is
/// typically used with small to medium font sizes (up to 16 ppem).
/// </summary>
DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL,
/// <summary>
/// Specifies ClearType rendering with anti-aliasing in both horizontal and vertical dimensions.
/// This is typically used at larger sizes to makes curves and diagonal lines look smoother, at
/// the expense of some softness.
/// </summary>
DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC,
/// <summary>
/// Specifies that rendering should bypass the rasterizer and use the outlines directly. This is
/// typically used at very large sizes.
/// </summary>
DWRITE_RENDERING_MODE_OUTLINE
};
/// <summary>
/// The DWRITE_MATRIX structure specifies the graphics transform to be applied
/// to rendered glyphs.
/// </summary>
struct DWRITE_MATRIX
{
/// <summary>
/// Horizontal scaling / cosine of rotation
/// </summary>
FLOAT m11;
/// <summary>
/// Vertical shear / sine of rotation
/// </summary>
FLOAT m12;
/// <summary>
/// Horizontal shear / negative sine of rotation
/// </summary>
FLOAT m21;
/// <summary>
/// Vertical scaling / cosine of rotation
/// </summary>
FLOAT m22;
/// <summary>
/// Horizontal shift (always orthogonal regardless of rotation)
/// </summary>
FLOAT dx;
/// <summary>
/// Vertical shift (always orthogonal regardless of rotation)
/// </summary>
FLOAT dy;
};
/// <summary>
/// The interface that represents text rendering settings for glyph rasterization and filtering.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("2f0da53a-2add-47cd-82ee-d9ec34688e75") IDWriteRenderingParams : public IUnknown
{
/// <summary>
/// Gets the gamma value used for gamma correction. Valid values must be
/// greater than zero and cannot exceed 256.
/// </summary>
STDMETHOD_(FLOAT, GetGamma)() PURE;
/// <summary>
/// Gets the amount of contrast enhancement. Valid values are greater than
/// or equal to zero.
/// </summary>
STDMETHOD_(FLOAT, GetEnhancedContrast)() PURE;
/// <summary>
/// Gets the ClearType level. Valid values range from 0.0f (no ClearType)
/// to 1.0f (full ClearType).
/// </summary>
STDMETHOD_(FLOAT, GetClearTypeLevel)() PURE;
/// <summary>
/// Gets the pixel geometry.
/// </summary>
STDMETHOD_(DWRITE_PIXEL_GEOMETRY, GetPixelGeometry)() PURE;
/// <summary>
/// Gets the rendering mode.
/// </summary>
STDMETHOD_(DWRITE_RENDERING_MODE, GetRenderingMode)() PURE;
};
// Forward declarations of D2D types
interface ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
/// <summary>
/// The interface that represents an absolute reference to a font face.
/// It contains font face type, appropriate file references and face identification data.
/// Various font data such as metrics, names and glyph outlines is obtained from IDWriteFontFace.
/// </summary>
interface DWRITE_DECLARE_INTERFACE("5f49804d-7024-4d43-bfa9-d25984f53849") IDWriteFontFace : public IUnknown
{
/// <summary>
/// Obtains the file format type of a font face.
/// </summary>
STDMETHOD_(DWRITE_FONT_FACE_TYPE, GetType)() PURE;
/// <summary>
/// Obtains the font files representing a font face.
/// </summary>
/// <param name="numberOfFiles">The number of files representing the font face.</param>
/// <param name="fontFiles">User provided array that stores pointers to font files representing the font face.
/// This parameter can be NULL if the user is only interested in the number of files representing the font face.
/// This API increments reference count of the font file pointers returned according to COM conventions, and the client
/// should release them when finished.</param>
/// <returns>
/// Standard HRESULT error code.
/// </returns>
STDMETHOD(GetFiles)(
__inout UINT32* numberOfFiles,
__out_ecount_opt(*numberOfFiles) IDWriteFontFile** fontFiles
) PURE;
/// <summary>
/// Obtains the zero-based index of the font face in its font file or files. If the font files contain a single face,
/// the return value is zero.
/// </summary>
STDMETHOD_(UINT32, GetIndex)() PURE;
/// <summary>
/// Obtains the algorithmic style simulation flags of a font face.
/// </summary>
STDMETHOD_(DWRITE_FONT_SIMULATIONS, GetSimulations)() PURE;