1 //+--------------------------------------------------------------------------
2 //
3 //  Copyright (c) Microsoft Corporation.  All rights reserved.
4 //
5 //  Abstract:
6 //     DirectX Typography Services public API definitions.
7 //
8 //----------------------------------------------------------------------------
9 
10 #ifndef DWRITE_2_H_INCLUDED
11 #define DWRITE_2_H_INCLUDED
12 
13 #pragma once
14 
15 #include <dwrite_1.h>
16 
17 interface IDWriteFontFallback;
18 
19 /// <summary>
20 /// How to align glyphs to the margin.
21 /// </summary>
22 enum DWRITE_OPTICAL_ALIGNMENT
23 {
24     /// <summary>
25     /// Align to the default metrics of the glyph.
26     /// </summary>
27     DWRITE_OPTICAL_ALIGNMENT_NONE,
28 
29     /// <summary>
30     /// Align glyphs to the margins. Without this, some small whitespace
31     /// may be present between the text and the margin from the glyph's side
32     /// bearing values. Note that glyphs may still overhang outside the
33     /// margin, such as flourishes or italic slants.
34     /// </summary>
35     DWRITE_OPTICAL_ALIGNMENT_NO_SIDE_BEARINGS,
36 };
37 
38 /// <summary>
39 /// Whether to enable grid-fitting of glyph outlines (a.k.a. hinting).
40 /// </summary>
41 enum DWRITE_GRID_FIT_MODE
42 {
43     /// <summary>
44     /// Choose grid fitting base on the font's gasp table information.
45     /// </summary>
46     DWRITE_GRID_FIT_MODE_DEFAULT,
47 
48     /// <summary>
49     /// Always disable grid fitting, using the ideal glyph outlines.
50     /// </summary>
51     DWRITE_GRID_FIT_MODE_DISABLED,
52 
53     /// <summary>
54     /// Enable grid fitting, adjusting glyph outlines for device pixel display.
55     /// </summary>
56     DWRITE_GRID_FIT_MODE_ENABLED
57 };
58 
59 /// <summary>
60 /// Overall metrics associated with text after layout.
61 /// All coordinates are in device independent pixels (DIPs).
62 /// </summary>
63 struct DWRITE_TEXT_METRICS1 : DWRITE_TEXT_METRICS
64 {
65     /// <summary>
66     /// The height of the formatted text taking into account the
67     /// trailing whitespace at the end of each line, which will
68     /// matter for vertical reading directions.
69     /// </summary>
70     FLOAT heightIncludingTrailingWhitespace;
71 };
72 
73 /// <summary>
74 /// The text renderer interface represents a set of application-defined
75 /// callbacks that perform rendering of text, inline objects, and decorations
76 /// such as underlines.
77 /// </summary>
78 interface DWRITE_DECLARE_INTERFACE("D3E0E934-22A0-427E-AAE4-7D9574B59DB1") IDWriteTextRenderer1 : public IDWriteTextRenderer
79 {
80     /// <summary>
81     /// IDWriteTextLayout::Draw calls this function to instruct the client to
82     /// render a run of glyphs.
83     /// </summary>
84     /// <param name="clientDrawingContext">The context passed to
85     ///     IDWriteTextLayout::Draw.</param>
86     /// <param name="baselineOriginX">X-coordinate of the baseline.</param>
87     /// <param name="baselineOriginY">Y-coordinate of the baseline.</param>
88     /// <param name="orientationAngle">Orientation of the glyph run.</param>
89     /// <param name="measuringMode">Specifies measuring method for glyphs in
90     ///     the run. Renderer implementations may choose different rendering
91     ///     modes for given measuring methods, but best results are seen when
92     ///     the rendering mode matches the corresponding measuring mode:
93     ///     DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL for DWRITE_MEASURING_MODE_NATURAL
94     ///     DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC for DWRITE_MEASURING_MODE_GDI_CLASSIC
95     ///     DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL for DWRITE_MEASURING_MODE_GDI_NATURAL
96     /// </param>
97     /// <param name="glyphRun">The glyph run to draw.</param>
98     /// <param name="glyphRunDescription">Properties of the characters
99     ///     associated with this run.</param>
100     /// <param name="clientDrawingEffect">The drawing effect set in
101     ///     IDWriteTextLayout::SetDrawingEffect.</param>
102     /// <returns>
103     /// Standard HRESULT error code.
104     /// </returns>
105     /// <remarks>
106     /// If a non-identity orientation is passed, the glyph run should be
107     /// rotated around the given baseline x and y coordinates. The function
108     /// IDWriteAnalyzer2::GetGlyphOrientationTransform will return the
109     /// necessary transform for you, which can be combined with any existing
110     /// world transform on the drawing context.
111     /// </remarks>
112     STDMETHOD(DrawGlyphRun)(
113         _In_opt_ void* clientDrawingContext,
114         FLOAT baselineOriginX,
115         FLOAT baselineOriginY,
116         DWRITE_GLYPH_ORIENTATION_ANGLE orientationAngle,
117         DWRITE_MEASURING_MODE measuringMode,
118         _In_ DWRITE_GLYPH_RUN const* glyphRun,
119         _In_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
120         _In_opt_ IUnknown* clientDrawingEffect
121         ) PURE;
122 
123     /// <summary>
124     /// IDWriteTextLayout::Draw calls this function to instruct the client to draw
125     /// an underline.
126     /// </summary>
127     /// <param name="clientDrawingContext">The context passed to
128     /// IDWriteTextLayout::Draw.</param>
129     /// <param name="baselineOriginX">X-coordinate of the baseline.</param>
130     /// <param name="baselineOriginY">Y-coordinate of the baseline.</param>
131     /// <param name="orientationAngle">Orientation of the underline.</param>
132     /// <param name="underline">Underline logical information.</param>
133     /// <param name="clientDrawingEffect">The drawing effect set in
134     ///     IDWriteTextLayout::SetDrawingEffect.</param>
135     /// <returns>
136     /// Standard HRESULT error code.
137     /// </returns>
138     /// <remarks>
139     /// A single underline can be broken into multiple calls, depending on
140     /// how the formatting changes attributes. If font sizes/styles change
141     /// within an underline, the thickness and offset will be averaged
142     /// weighted according to characters.
143     ///
144     /// To get the correct top coordinate of the underline rect, add
145     /// underline::offset to the baseline's Y. Otherwise the underline will
146     /// be immediately under the text. The x coordinate will always be passed
147     /// as the left side, regardless of text directionality. This simplifies
148     /// drawing and reduces the problem of round-off that could potentially
149     /// cause gaps or a double stamped alpha blend. To avoid alpha overlap,
150     /// round the end points to the nearest device pixel.
151     /// </remarks>
152     STDMETHOD(DrawUnderline)(
153         _In_opt_ void* clientDrawingContext,
154         FLOAT baselineOriginX,
155         FLOAT baselineOriginY,
156         DWRITE_GLYPH_ORIENTATION_ANGLE orientationAngle,
157         _In_ DWRITE_UNDERLINE const* underline,
158         _In_opt_ IUnknown* clientDrawingEffect
159         ) PURE;
160 
161     /// <summary>
162     /// IDWriteTextLayout::Draw calls this function to instruct the client to draw
163     /// a strikethrough.
164     /// </summary>
165     /// <param name="clientDrawingContext">The context passed to
166     /// IDWriteTextLayout::Draw.</param>
167     /// <param name="baselineOriginX">X-coordinate of the baseline.</param>
168     /// <param name="baselineOriginY">Y-coordinate of the baseline.</param>
169     /// <param name="orientationAngle">Orientation of the strikethrough.</param>
170     /// <param name="strikethrough">Strikethrough logical information.</param>
171     /// <param name="clientDrawingEffect">The drawing effect set in
172     ///     IDWriteTextLayout::SetDrawingEffect.</param>
173     /// <returns>
174     /// Standard HRESULT error code.
175     /// </returns>
176     /// <remarks>
177     /// A single strikethrough can be broken into multiple calls, depending on
178     /// how the formatting changes attributes. Strikethrough is not averaged
179     /// across font sizes/styles changes.
180     /// To get the correct top coordinate of the strikethrough rect,
181     /// add strikethrough::offset to the baseline's Y.
182     /// Like underlines, the x coordinate will always be passed as the left side,
183     /// regardless of text directionality.
184     /// </remarks>
185     STDMETHOD(DrawStrikethrough)(
186         _In_opt_ void* clientDrawingContext,
187         FLOAT baselineOriginX,
188         FLOAT baselineOriginY,
189         DWRITE_GLYPH_ORIENTATION_ANGLE orientationAngle,
190         _In_ DWRITE_STRIKETHROUGH const* strikethrough,
191         _In_opt_ IUnknown* clientDrawingEffect
192         ) PURE;
193 
194     /// <summary>
195     /// IDWriteTextLayout::Draw calls this application callback when it needs to
196     /// draw an inline object.
197     /// </summary>
198     /// <param name="clientDrawingContext">The context passed to
199     ///     IDWriteTextLayout::Draw.</param>
200     /// <param name="originX">X-coordinate at the top-left corner of the
201     ///     inline object.</param>
202     /// <param name="originY">Y-coordinate at the top-left corner of the
203     ///     inline object.</param>
204     /// <param name="orientationAngle">Orientation of the inline object.</param>
205     /// <param name="inlineObject">The object set using IDWriteTextLayout::SetInlineObject.</param>
206     /// <param name="isSideways">The object should be drawn on its side.</param>
207     /// <param name="isRightToLeft">The object is in an right-to-left context
208     ///     and should be drawn flipped.</param>
209     /// <param name="clientDrawingEffect">The drawing effect set in
210     ///     IDWriteTextLayout::SetDrawingEffect.</param>
211     /// <returns>
212     /// Standard HRESULT error code.
213     /// </returns>
214     /// <remarks>
215     /// The right-to-left flag is a hint to draw the appropriate visual for
216     /// that reading direction. For example, it would look strange to draw an
217     /// arrow pointing to the right to indicate a submenu. The sideways flag
218     /// similarly hints that the object is drawn in a different orientation.
219     /// If a non-identity orientation is passed, the top left of the inline
220     /// object should be rotated around the given x and y coordinates.
221     /// IDWriteAnalyzer2::GetGlyphOrientationTransform returns the necessary
222     /// transform for this.
223     /// </remarks>
224     STDMETHOD(DrawInlineObject)(
225         _In_opt_ void* clientDrawingContext,
226         FLOAT originX,
227         FLOAT originY,
228         DWRITE_GLYPH_ORIENTATION_ANGLE orientationAngle,
229         _In_ IDWriteInlineObject* inlineObject,
230         BOOL isSideways,
231         BOOL isRightToLeft,
232         _In_opt_ IUnknown* clientDrawingEffect
233         ) PURE;
234 
235     using IDWriteTextRenderer::DrawGlyphRun;
236     using IDWriteTextRenderer::DrawUnderline;
237     using IDWriteTextRenderer::DrawStrikethrough;
238     using IDWriteTextRenderer::DrawInlineObject;
239 };
240 
241 /// <summary>
242 /// The format of text used for text layout.
243 /// </summary>
244 /// <remarks>
245 /// This object may not be thread-safe and it may carry the state of text format change.
246 /// </remarks>
247 interface DWRITE_DECLARE_INTERFACE("5F174B49-0D8B-4CFB-8BCA-F1CCE9D06C67") IDWriteTextFormat1 : public IDWriteTextFormat
248 {
249     /// <summary>
250     /// Set the preferred orientation of glyphs when using a vertical reading direction.
251     /// </summary>
252     /// <param name="glyphOrientation">Preferred glyph orientation.</param>
253     /// <returns>
254     /// Standard HRESULT error code.
255     /// </returns>
256     STDMETHOD(SetVerticalGlyphOrientation)(
257         DWRITE_VERTICAL_GLYPH_ORIENTATION glyphOrientation
258         ) PURE;
259 
260     /// <summary>
261     /// Get the preferred orientation of glyphs when using a vertical reading
262     /// direction.
263     /// </summary>
264     STDMETHOD_(DWRITE_VERTICAL_GLYPH_ORIENTATION, GetVerticalGlyphOrientation)() PURE;
265 
266     /// <summary>
267     /// Set whether or not the last word on the last line is wrapped.
268     /// </summary>
269     /// <param name="isLastLineWrappingEnabled">Line wrapping option.</param>
270     /// <returns>
271     /// Standard HRESULT error code.
272     /// </returns>
273     STDMETHOD(SetLastLineWrapping)(
274         BOOL isLastLineWrappingEnabled
275         ) PURE;
276 
277     /// <summary>
278     /// Get whether or not the last word on the last line is wrapped.
279     /// </summary>
280     STDMETHOD_(BOOL, GetLastLineWrapping)() PURE;
281 
282     /// <summary>
283     /// Set how the glyphs align to the edges the margin. Default behavior is
284     /// to align glyphs using their default glyphs metrics which include side
285     /// bearings.
286     /// </summary>
287     /// <param name="opticalAlignment">Optical alignment option.</param>
288     /// <returns>
289     /// Standard HRESULT error code.
290     /// </returns>
291     STDMETHOD(SetOpticalAlignment)(
292         DWRITE_OPTICAL_ALIGNMENT opticalAlignment
293         ) PURE;
294 
295     /// <summary>
296     /// Get how the glyphs align to the edges the margin.
297     /// </summary>
298     STDMETHOD_(DWRITE_OPTICAL_ALIGNMENT, GetOpticalAlignment)() PURE;
299 
300     /// <summary>
301     /// Apply a custom font fallback onto layout. If none is specified,
302     /// layout uses the system fallback list.
303     /// </summary>
304     /// <param name="fontFallback">Custom font fallback created from
305     ///     IDWriteFontFallbackBuilder::CreateFontFallback or from
306     ///     IDWriteFactory2::GetSystemFontFallback.</param>
307     /// <returns>
308     /// Standard HRESULT error code.
309     /// </returns>
310     STDMETHOD(SetFontFallback)(
311         IDWriteFontFallback* fontFallback
312         ) PURE;
313 
314     /// <summary>
315     /// Get the current font fallback object.
316     /// </summary>
317     STDMETHOD(GetFontFallback)(
318         __out IDWriteFontFallback** fontFallback
319         ) PURE;
320 };
321 
322 /// <summary>
323 /// The text layout interface represents a block of text after it has
324 /// been fully analyzed and formatted.
325 ///
326 /// All coordinates are in device independent pixels (DIPs).
327 /// </summary>
328 interface DWRITE_DECLARE_INTERFACE("1093C18F-8D5E-43F0-B064-0917311B525E") IDWriteTextLayout2 : public IDWriteTextLayout1
329 {
330     /// <summary>
331     /// GetMetrics retrieves overall metrics for the formatted string.
332     /// </summary>
333     /// <param name="textMetrics">The returned metrics.</param>
334     /// <returns>
335     /// Standard HRESULT error code.
336     /// </returns>
337     /// <remarks>
338     /// Drawing effects like underline and strikethrough do not contribute
339     /// to the text size, which is essentially the sum of advance widths and
340     /// line heights. Additionally, visible swashes and other graphic
341     /// adornments may extend outside the returned width and height.
342     /// </remarks>
343     STDMETHOD(GetMetrics)(
344         _Out_ DWRITE_TEXT_METRICS1* textMetrics
345         ) PURE;
346 
347     using IDWriteTextLayout::GetMetrics;
348 
349     /// <summary>
350     /// Set the preferred orientation of glyphs when using a vertical reading direction.
351     /// </summary>
352     /// <param name="glyphOrientation">Preferred glyph orientation.</param>
353     /// <returns>
354     /// Standard HRESULT error code.
355     /// </returns>
356     STDMETHOD(SetVerticalGlyphOrientation)(
357         DWRITE_VERTICAL_GLYPH_ORIENTATION glyphOrientation
358         ) PURE;
359 
360     /// <summary>
361     /// Get the preferred orientation of glyphs when using a vertical reading
362     /// direction.
363     /// </summary>
364     STDMETHOD_(DWRITE_VERTICAL_GLYPH_ORIENTATION, GetVerticalGlyphOrientation)() PURE;
365 
366     /// <summary>
367     /// Set whether or not the last word on the last line is wrapped.
368     /// </summary>
369     /// <param name="isLastLineWrappingEnabled">Line wrapping option.</param>
370     /// <returns>
371     /// Standard HRESULT error code.
372     /// </returns>
373     STDMETHOD(SetLastLineWrapping)(
374         BOOL isLastLineWrappingEnabled
375         ) PURE;
376 
377     /// <summary>
378     /// Get whether or not the last word on the last line is wrapped.
379     /// </summary>
380     STDMETHOD_(BOOL, GetLastLineWrapping)() PURE;
381 
382     /// <summary>
383     /// Set how the glyphs align to the edges the margin. Default behavior is
384     /// to align glyphs using their default glyphs metrics which include side
385     /// bearings.
386     /// </summary>
387     /// <param name="opticalAlignment">Optical alignment option.</param>
388     /// <returns>
389     /// Standard HRESULT error code.
390     /// </returns>
391     STDMETHOD(SetOpticalAlignment)(
392         DWRITE_OPTICAL_ALIGNMENT opticalAlignment
393         ) PURE;
394 
395     /// <summary>
396     /// Get how the glyphs align to the edges the margin.
397     /// </summary>
398     STDMETHOD_(DWRITE_OPTICAL_ALIGNMENT, GetOpticalAlignment)() PURE;
399 
400     /// <summary>
401     /// Apply a custom font fallback onto layout. If none is specified,
402     /// layout uses the system fallback list.
403     /// </summary>
404     /// <param name="fontFallback">Custom font fallback created from
405     ///     IDWriteFontFallbackBuilder::CreateFontFallback or
406     ///     IDWriteFactory2::GetSystemFontFallback.</param>
407     /// <returns>
408     /// Standard HRESULT error code.
409     /// </returns>
410     STDMETHOD(SetFontFallback)(
411         IDWriteFontFallback* fontFallback
412         ) PURE;
413 
414     /// <summary>
415     /// Get the current font fallback object.
416     /// </summary>
417     STDMETHOD(GetFontFallback)(
418         __out IDWriteFontFallback** fontFallback
419         ) PURE;
420 };
421 
422 /// <summary>
423 /// The text analyzer interface represents a set of application-defined
424 /// callbacks that perform rendering of text, inline objects, and decorations
425 /// such as underlines.
426 /// </summary>
427 interface DWRITE_DECLARE_INTERFACE("553A9FF3-5693-4DF7-B52B-74806F7F2EB9") IDWriteTextAnalyzer2 : public IDWriteTextAnalyzer1
428 {
429     /// <summary>
430     /// Returns 2x3 transform matrix for the respective angle to draw the
431     /// glyph run or other object.
432     /// </summary>
433     /// <param name="glyphOrientationAngle">The angle reported to one of the application callbacks,
434     ///     including IDWriteTextAnalysisSink1::SetGlyphOrientation and IDWriteTextRenderer1::Draw*.</param>
435     /// <param name="isSideways">Whether the run's glyphs are sideways or not.</param>
436     /// <param name="originX">X origin of the element, be it a glyph run or underline or other.</param>
437     /// <param name="originY">Y origin of the element, be it a glyph run or underline or other.</param>
438     /// <param name="transform">Returned transform.</param>
439     /// <returns>
440     /// Standard HRESULT error code.
441     /// </returns>
442     /// <remarks>
443     /// This rotates around the given origin x and y, returning a translation component
444     /// such that the glyph run, text decoration, or inline object is drawn with the
445     /// right orientation at the expected coordinate.
446     /// </remarks>
447     STDMETHOD(GetGlyphOrientationTransform)(
448         DWRITE_GLYPH_ORIENTATION_ANGLE glyphOrientationAngle,
449         BOOL isSideways,
450         FLOAT originX,
451         FLOAT originY,
452         _Out_ DWRITE_MATRIX* transform
453         ) PURE;
454 
455     /// <summary>
456     /// Returns a list of typographic feature tags for the given script and language.
457     /// </summary>
458     /// <param name="fontFace">The font face to get features from.</param>
459     /// <param name="scriptAnalysis">Script analysis result from AnalyzeScript.</param>
460     /// <param name="localeName">The locale to use when selecting the feature,
461     ///     such en-us or ja-jp.</param>
462     /// <param name="maxTagCount">Maximum tag count.</param>
463     /// <param name="actualTagCount">Actual tag count. If greater than
464     ///     maxTagCount, E_NOT_SUFFICIENT_BUFFER is returned, and the call
465     ///     should be retried with a larger buffer.</param>
466     /// <param name="tags">Feature tag list.</param>
467     /// <returns>
468     /// Standard HRESULT error code.
469     /// </returns>
470     STDMETHOD(GetTypographicFeatures)(
471         IDWriteFontFace* fontFace,
472         DWRITE_SCRIPT_ANALYSIS scriptAnalysis,
473         _In_opt_z_ WCHAR const* localeName,
474         UINT32 maxTagCount,
475         _Out_ UINT32* actualTagCount,
476         _Out_writes_(maxTagCount) DWRITE_FONT_FEATURE_TAG* tags
477         ) PURE;
478 
479     /// <summary>
480     /// Returns an array of which glyphs are affected by a given feature.
481     /// </summary>
482     /// <param name="fontFace">The font face to read glyph information from.</param>
483     /// <param name="scriptAnalysis">Script analysis result from AnalyzeScript.</param>
484     /// <param name="localeName">The locale to use when selecting the feature,
485     ///     such en-us or ja-jp.</param>
486     /// <param name="featureTag">OpenType feature name to use, which may be one
487     ///     of the DWRITE_FONT_FEATURE_TAG values or a custom feature using
488     ///     DWRITE_MAKE_OPENTYPE_TAG.</param>
489     /// <param name="glyphCount">Number of glyph indices to check.</param>
490     /// <param name="glyphIndices">Glyph indices to check for feature application.</param>
491     /// <param name="featureApplies">Output of which glyphs are affected by the
492     ///     feature, where for each glyph affected, the respective array index
493     ///     will be 1. The result is returned per-glyph without regard to
494     ///     neighboring context of adjacent glyphs.</param>
495     /// </remarks>
496     /// <returns>
497     /// Standard HRESULT error code.
498     /// </returns>
499     STDMETHOD(CheckTypographicFeature)(
500         IDWriteFontFace* fontFace,
501         DWRITE_SCRIPT_ANALYSIS scriptAnalysis,
502         _In_opt_z_ WCHAR const* localeName,
503         DWRITE_FONT_FEATURE_TAG featureTag,
504         UINT32 glyphCount,
505         _In_reads_(glyphCount) UINT16 const* glyphIndices,
506         _Out_writes_(glyphCount) UINT8* featureApplies
507         ) PURE;
508 
509     using IDWriteTextAnalyzer1::GetGlyphOrientationTransform;
510 };
511 
512 /// <summary>
513 /// A font fallback definition used for mapping characters to fonts capable of
514 /// supporting them.
515 /// </summary>
516 interface DWRITE_DECLARE_INTERFACE("EFA008F9-F7A1-48BF-B05C-F224713CC0FF") IDWriteFontFallback : public IUnknown
517 {
518     /// <summary>
519     /// Determines an appropriate font to use to render the range of text.
520     /// </summary>
521     /// <param name="source">The text source implementation holds the text and
522     ///     locale.</param>
523     /// <param name="textLength">Length of the text to analyze.</param>
524     /// <param name="baseFontCollection">Default font collection to use.</param>
525     /// <param name="baseFamilyName">Family name of the base font. If you pass
526     ///     null, no matching will be done against the family.</param>
527     /// <param name="baseWeight">Desired weight.</param>
528     /// <param name="baseStyle">Desired style.</param>
529     /// <param name="baseStretch">Desired stretch.</param>
530     /// <param name="mappedLength">Length of text mapped to the mapped font.
531     ///     This will always be less or equal to the input text length and
532     ///     greater than zero (if the text length is non-zero) so that the
533     ///     caller advances at least one character each call.</param>
534     /// <param name="mappedFont">The font that should be used to render the
535     ///     first mappedLength characters of the text. If it returns NULL,
536     ///     then no known font can render the text, and mappedLength is the
537     ///     number of unsupported characters to skip.</param>
538     /// <param name="scale">Scale factor to multiply the em size of the
539     ///     returned font by.</param>
540     /// <returns>
541     /// Standard HRESULT error code.
542     /// </returns>
543     STDMETHOD(MapCharacters)(
544         IDWriteTextAnalysisSource* analysisSource,
545         UINT32 textPosition,
546         UINT32 textLength,
547         _In_opt_ IDWriteFontCollection* baseFontCollection,
548         _In_opt_z_ wchar_t const* baseFamilyName,
549         DWRITE_FONT_WEIGHT baseWeight,
550         DWRITE_FONT_STYLE baseStyle,
551         DWRITE_FONT_STRETCH baseStretch,
552         _Out_range_(0, textLength) UINT32* mappedLength,
553         _COM_Outptr_result_maybenull_ IDWriteFont** mappedFont,
554         _Out_ FLOAT* scale
555         ) PURE;
556 };
557 
558 /// <summary>
559 /// Builder used to create a font fallback definition by appending a series of
560 /// fallback mappings, followed by a creation call.
561 /// </summary>
562 /// <remarks>
563 /// This object may not be thread-safe.
564 /// </remarks>
565 interface DWRITE_DECLARE_INTERFACE("FD882D06-8ABA-4FB8-B849-8BE8B73E14DE") IDWriteFontFallbackBuilder : public IUnknown
566 {
567     /// <summary>
568     /// Appends a single mapping to the list. Call this once for each additional mapping.
569     /// </summary>
570     /// <param name="ranges">Unicode ranges that apply to this mapping.</param>
571     /// <param name="rangesCount">Number of Unicode ranges.</param>
572     /// <param name="localeName">Locale of the context (e.g. document locale).</param>
573     /// <param name="baseFamilyName">Base family name to match against, if applicable.</param>
574     /// <param name="fontCollection">Explicit font collection for this mapping (optional).</param>
575     /// <param name="targetFamilyNames">List of target family name strings.</param>
576     /// <param name="targetFamilyNamesCount">Number of target family names.</param>
577     /// <param name="scale">Scale factor to multiply the result target font by.</param>
578     /// <returns>
579     /// Standard HRESULT error code.
580     /// </returns>
581     STDMETHOD(AddMapping)(
582         _In_reads_(rangesCount) DWRITE_UNICODE_RANGE const* ranges,
583         UINT32 rangesCount,
584         _In_reads_(targetFamilyNamesCount) WCHAR const** targetFamilyNames,
585         UINT32 targetFamilyNamesCount,
586         _In_opt_ IDWriteFontCollection* fontCollection = NULL,
587         _In_opt_z_ WCHAR const* localeName = NULL,
588         _In_opt_z_ WCHAR const* baseFamilyName = NULL,
589         FLOAT scale = 1.0f
590         ) PURE;
591 
592     /// <summary>
593     /// Appends all the mappings from an existing font fallback object.
594     /// </summary>
595     /// <param name="fontFallback">Font fallback to read mappings from.</param>
596     /// <returns>
597     /// Standard HRESULT error code.
598     /// </returns>
599     STDMETHOD(AddMappings)(
600         IDWriteFontFallback* fontFallback
601         ) PURE;
602 
603     /// <summary>
604     /// Creates the finalized fallback object from the mappings added.
605     /// </summary>
606     /// <param name="fontFallback">Created fallback list.</param>
607     /// <returns>
608     /// Standard HRESULT error code.
609     /// </returns>
610    STDMETHOD(CreateFontFallback)(
611         _COM_Outptr_ IDWriteFontFallback** fontFallback
612         ) PURE;
613 };
614 
615 /// <summary>
616 /// DWRITE_COLOR_F
617 /// </summary>
618 #ifndef D3DCOLORVALUE_DEFINED
619 
620 typedef struct _D3DCOLORVALUE {
621     union {
622     FLOAT r;
623     FLOAT dvR;
624     };
625     union {
626     FLOAT g;
627     FLOAT dvG;
628     };
629     union {
630     FLOAT b;
631     FLOAT dvB;
632     };
633     union {
634     FLOAT a;
635     FLOAT dvA;
636     };
637 } D3DCOLORVALUE;
638 
639 #define D3DCOLORVALUE_DEFINED
640 #endif // D3DCOLORVALUE_DEFINED
641 
642 typedef D3DCOLORVALUE DWRITE_COLOR_F;
643 
644 /// <summary>
645 /// The IDWriteFont interface represents a physical font in a font collection.
646 /// </summary>
647 interface DWRITE_DECLARE_INTERFACE("29748ed6-8c9c-4a6a-be0b-d912e8538944") IDWriteFont2 : public IDWriteFont1
648 {
649     /// <summary>
650     /// Returns TRUE if the font contains tables that can provide color information
651     /// (including COLR, CPAL, SVG, CBDT, sbix  tables), or FALSE if not. Note that
652     /// TRUE is returned even in the case when the font tables contain only grayscale
653     /// images.
654     /// </summary>
655     STDMETHOD_(BOOL, IsColorFont)() PURE;
656 };
657 
658 /// <summary>
659 /// The interface that represents an absolute reference to a font face.
660 /// It contains font face type, appropriate file references and face identification data.
661 /// Various font data such as metrics, names and glyph outlines is obtained from IDWriteFontFace.
662 /// </summary>
663 interface DWRITE_DECLARE_INTERFACE("d8b768ff-64bc-4e66-982b-ec8e87f693f7") IDWriteFontFace2 : public IDWriteFontFace1
664 {
665     /// <summary>
666     /// Returns TRUE if the font contains tables that can provide color information
667     /// (including COLR, CPAL, SVG, CBDT, sbix  tables), or FALSE if not. Note that
668     /// TRUE is returned even in the case when the font tables contain only grayscale
669     /// images.
670     /// </summary>
671     STDMETHOD_(BOOL, IsColorFont)() PURE;
672 
673     /// <summary>
674     /// Returns the number of color palettes defined by the font. The return
675     /// value is zero if the font has no color information. Color fonts must
676     /// have at least one palette, with palette index zero being the default.
677     /// </summary>
678     STDMETHOD_(UINT32, GetColorPaletteCount)() PURE;
679 
680     /// <summary>
681     /// Returns the number of entries in each color palette. All color palettes
682     /// in a font have the same number of palette entries. The return value is
683     /// zero if the font has no color information.
684     /// </summary>
685     STDMETHOD_(UINT32, GetPaletteEntryCount)() PURE;
686 
687     /// <summary>
688     /// Reads color values from the font's color palette.
689     /// </summary>
690     /// <param name="colorPaletteIndex">Zero-based index of the color palette. If the
691     /// font does not have a palette with the specified index, the method returns
692     /// DWRITE_E_NOCOLOR.<param>
693     /// <param name="firstEntryIndex">Zero-based index of the first palette entry
694     /// to read.</param>
695     /// <param name="entryCount">Number of palette entries to read.</param>
696     /// <param name="paletteEntries">Array that receives the color values.<param>
697     /// <returns>
698     /// Standard HRESULT error code.
699     /// The return value is E_INVALIDARG if firstEntryIndex + entryCount is greater
700     /// than the actual number of palette entries as returned by GetPaletteEntryCount.
701     /// The return value is DWRITE_E_NOCOLOR if the font does not have a palette
702     /// with the specified palette index.
703     /// </returns>
704     STDMETHOD(GetPaletteEntries)(
705         UINT32 colorPaletteIndex,
706         UINT32 firstEntryIndex,
707         UINT32 entryCount,
708         _Out_writes_(entryCount) DWRITE_COLOR_F* paletteEntries
709         ) PURE;
710 
711     /// <summary>
712     /// Determines the recommended text rendering and grid-fit mode to be used based on the
713     /// font, size, world transform, and measuring mode.
714     /// </summary>
715     /// <param name="fontEmSize">Logical font size in DIPs.</param>
716     /// <param name="dpiX">Number of pixels per logical inch in the horizontal direction.</param>
717     /// <param name="dpiY">Number of pixels per logical inch in the vertical direction.</param>
718     /// <param name="transform">Specifies the world transform.</param>
719     /// <param name="outlineThreshold">Specifies the quality of the graphics system's outline rendering,
720     /// affects the size threshold above which outline rendering is used.</param>
721     /// <param name="measuringMode">Specifies the method used to measure during text layout. For proper
722     /// glyph spacing, the function returns a rendering mode that is compatible with the specified
723     /// measuring mode.</param>
724     /// <param name="renderingParams">Rendering parameters object. This parameter is necessary in case the rendering parameters
725     /// object overrides the rendering mode.</param>
726     /// <param name="renderingMode">Receives the recommended rendering mode.</param>
727     /// <param name="gridFitMode">Receives the recommended grid-fit mode.</param>
728     /// <remarks>
729     /// This method should be used to determine the actual rendering mode in cases where the rendering
730     /// mode of the rendering params object is DWRITE_RENDERING_MODE_DEFAULT, and the actual grid-fit
731     /// mode when the rendering params object is DWRITE_GRID_FIT_MODE_DEFAULT.
732     /// </remarks>
733     /// <returns>
734     /// Standard HRESULT error code.
735     /// </returns>
736     STDMETHOD(GetRecommendedRenderingMode)(
737         FLOAT fontEmSize,
738         FLOAT dpiX,
739         FLOAT dpiY,
740         _In_opt_ DWRITE_MATRIX const* transform,
741         BOOL isSideways,
742         DWRITE_OUTLINE_THRESHOLD outlineThreshold,
743         DWRITE_MEASURING_MODE measuringMode,
744         _In_opt_ IDWriteRenderingParams* renderingParams,
745         _Out_ DWRITE_RENDERING_MODE* renderingMode,
746         _Out_ DWRITE_GRID_FIT_MODE* gridFitMode
747         ) PURE;
748 
749     using IDWriteFontFace1::GetRecommendedRenderingMode;
750 };
751 
752 /// <summary>
753 /// Represents a color glyph run. The IDWriteFactory2::TranslateColorGlyphRun
754 /// method returns an ordered collection of color glyph runs, which can be
755 /// layered on top of each other to produce a color representation of the
756 /// given base glyph run.
757 /// </summary>
758 struct DWRITE_COLOR_GLYPH_RUN
759 {
760     /// <summary>
761     /// Glyph run to render.
762     /// </summary>
763     DWRITE_GLYPH_RUN glyphRun;
764 
765     /// <summary>
766     /// Optional glyph run description.
767     /// </summary>
768     _Maybenull_ DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription;
769 
770     /// <summary>
771     /// Location at which to draw this glyph run.
772     /// </summary>
773     FLOAT baselineOriginX;
774     FLOAT baselineOriginY;
775 
776     /// <summary>
777     /// Color to use for this layer, if any. This is the same color that
778     /// IDWriteFontFace2::GetPaletteEntries would return for the current
779     /// palette index if the paletteIndex member is less than 0xFFFF. If
780     /// the paletteIndex member is 0xFFFF then there is no associated
781     /// palette entry, this member is set to { 0, 0, 0, 0 }, and the client
782     /// should use the current foreground brush.
783     /// </summary>
784     DWRITE_COLOR_F runColor;
785 
786     /// <summary>
787     /// Zero-based index of this layer's color entry in the current color
788     /// palette, or 0xFFFF if this layer is to be rendered using
789     /// the current foreground brush.
790     /// </summary>
791     UINT16 paletteIndex;
792 };
793 
794 /// <summary>
795 /// Enumerator for an ordered collection of color glyph runs.
796 /// </summary>
797 interface DWRITE_DECLARE_INTERFACE("d31fbe17-f157-41a2-8d24-cb779e0560e8") IDWriteColorGlyphRunEnumerator : public IUnknown
798 {
799     /// <summary>
800     /// Advances to the first or next color run. The runs are enumerated
801     /// in order from back to front.
802     /// </summary>
803     /// <param name="hasRun">Receives TRUE if there is a current run or
804     /// FALSE if the end of the sequence has been reached.</param>
805     /// <returns>
806     /// Standard HRESULT error code.
807     /// </returns>
808     STDMETHOD(MoveNext)(
809         _Out_ BOOL* hasRun
810         ) PURE;
811 
812     /// <summary>
813     /// Gets the current color glyph run.
814     /// </summary>
815     /// <param name="colorGlyphRun">Receives a pointer to the color
816     /// glyph run. The pointer remains valid until the next call to
817     /// MoveNext or until the interface is released.</param>
818     /// <returns>
819     /// Standard HRESULT error code. An error is returned if there is
820     /// no current glyph run, i.e., if MoveNext has not yet been called
821     /// or if the end of the sequence has been reached.
822     /// </returns>
823     STDMETHOD(GetCurrentRun)(
824         _Outptr_ DWRITE_COLOR_GLYPH_RUN const** colorGlyphRun
825         ) PURE;
826 };
827 
828 /// <summary>
829 /// The interface that represents text rendering settings for glyph rasterization and filtering.
830 /// </summary>
831 interface DWRITE_DECLARE_INTERFACE("F9D711C3-9777-40AE-87E8-3E5AF9BF0948") IDWriteRenderingParams2 : public IDWriteRenderingParams1
832 {
833     /// <summary>
834     /// Gets the grid fitting mode.
835     /// </summary>
836     STDMETHOD_(DWRITE_GRID_FIT_MODE, GetGridFitMode)() PURE;
837 };
838 
839 /// <summary>
840 /// The root factory interface for all DWrite objects.
841 /// </summary>
842 interface DWRITE_DECLARE_INTERFACE("0439fc60-ca44-4994-8dee-3a9af7b732ec") IDWriteFactory2 : public IDWriteFactory1
843 {
844     /// <summary>
845     /// Get the system-appropriate font fallback mapping list.
846     /// </summary>
847     /// <param name="fontFallback">The system fallback list.</param>
848     /// <returns>
849     /// Standard HRESULT error code.
850     /// </returns>
851     STDMETHOD(GetSystemFontFallback)(
852         _COM_Outptr_ IDWriteFontFallback** fontFallback
853         ) PURE;
854 
855     /// <summary>
856     /// Create a custom font fallback builder.
857     /// </summary>
858     /// <param name="fontFallbackBuilder">Empty font fallback builder.</param>
859     /// <returns>
860     /// Standard HRESULT error code.
861     /// </returns>
862     STDMETHOD(CreateFontFallbackBuilder)(
863         _COM_Outptr_ IDWriteFontFallbackBuilder** fontFallbackBuilder
864         ) PURE;
865 
866     /// <summary>
867     /// Translates a glyph run to a sequence of color glyph runs, which can be
868     /// rendered to produce a color representation of the original "base" run.
869     /// </summary>
870     /// <param name="baselineOriginX">Horizontal origin of the base glyph run in
871     /// pre-transform coordinates.</param>
872     /// <param name="baselineOriginY">Vertical origin of the base glyph run in
873     /// pre-transform coordinates.</param>
874     /// <param name="glyphRun">Pointer to the original "base" glyph run.</param>
875     /// <param name="glyphRunDescription">Optional glyph run description.</param>
876     /// <param name="measuringMode">Measuring mode, needed to compute the origins
877     /// of each glyph.</param>
878     /// <param name="worldToDeviceTransform">Matrix converting from the client's
879     /// coordinate space to device coordinates (pixels), i.e., the world transform
880     /// multiplied by any DPI scaling.</param>
881     /// <param name="colorPaletteIndex">Zero-based index of the color palette to use.
882     /// Valid indices are less than the number of palettes in the font, as returned
883     /// by IDWriteFontFace2::GetColorPaletteCount.</param>
884     /// <param name="colorLayers">If the function succeeds, receives a pointer
885     /// to an enumerator object that can be used to obtain the color glyph runs.
886     /// If the base run has no color glyphs, then the output pointer is NULL
887     /// and the method returns DWRITE_E_NOCOLOR.</param>
888     /// <returns>
889     /// Returns DWRITE_E_NOCOLOR if the font has no color information, the base
890     /// glyph run does not contain any color glyphs, or the specified color palette
891     /// index is out of range. In this case, the client should render the base glyph
892     /// run. Otherwise, returns a standard HRESULT error code.
893     /// </returns>
894     STDMETHOD(TranslateColorGlyphRun)(
895         FLOAT baselineOriginX,
896         FLOAT baselineOriginY,
897         _In_ DWRITE_GLYPH_RUN const* glyphRun,
898         _In_opt_ DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
899         DWRITE_MEASURING_MODE measuringMode,
900         _In_opt_ DWRITE_MATRIX const* worldToDeviceTransform,
901         UINT32 colorPaletteIndex,
902         _COM_Outptr_ IDWriteColorGlyphRunEnumerator** colorLayers
903         ) PURE;
904 
905     /// <summary>
906     /// Creates a rendering parameters object with the specified properties.
907     /// </summary>
908     /// <param name="gamma">The gamma value used for gamma correction, which must be greater than zero and cannot exceed 256.</param>
909     /// <param name="enhancedContrast">The amount of contrast enhancement, zero or greater.</param>
910     /// <param name="clearTypeLevel">The degree of ClearType level, from 0.0f (no ClearType) to 1.0f (full ClearType).</param>
911     /// <param name="pixelGeometry">The geometry of a device pixel.</param>
912     /// <param name="renderingMode">Method of rendering glyphs. In most cases, this should be DWRITE_RENDERING_MODE_DEFAULT to automatically use an appropriate mode.</param>
913     /// <param name="gridFitMode">How to grid fit glyph outlines. In most cases, this should be DWRITE_GRID_FIT_DEFAULT to automatically choose an appropriate mode.</param>
914     /// <param name="renderingParams">Holds the newly created rendering parameters object, or NULL in case of failure.</param>
915     /// <returns>
916     /// Standard HRESULT error code.
917     /// </returns>
918     STDMETHOD(CreateCustomRenderingParams)(
919         FLOAT gamma,
920         FLOAT enhancedContrast,
921         FLOAT grayscaleEnhancedContrast,
922         FLOAT clearTypeLevel,
923         DWRITE_PIXEL_GEOMETRY pixelGeometry,
924         DWRITE_RENDERING_MODE renderingMode,
925         DWRITE_GRID_FIT_MODE gridFitMode,
926         _COM_Outptr_ IDWriteRenderingParams2** renderingParams
927         ) PURE;
928 
929     using IDWriteFactory::CreateCustomRenderingParams;
930     using IDWriteFactory1::CreateCustomRenderingParams;
931 
932     /// <summary>
933     /// Creates a glyph run analysis object, which encapsulates information
934     /// used to render a glyph run.
935     /// </summary>
936     /// <param name="glyphRun">Structure specifying the properties of the glyph run.</param>
937     /// <param name="transform">Optional transform applied to the glyphs and their positions. This transform is applied after the
938     /// scaling specified by the emSize and pixelsPerDip.</param>
939     /// <param name="renderingMode">Specifies the rendering mode, which must be one of the raster rendering modes (i.e., not default
940     /// and not outline).</param>
941     /// <param name="measuringMode">Specifies the method to measure glyphs.</param>
942     /// <param name="gridFitMode">How to grid-fit glyph outlines. This must be non-default.</param>
943     /// <param name="baselineOriginX">Horizontal position of the baseline origin, in DIPs.</param>
944     /// <param name="baselineOriginY">Vertical position of the baseline origin, in DIPs.</param>
945     /// <param name="glyphRunAnalysis">Receives a pointer to the newly created object.</param>
946     /// <returns>
947     /// Standard HRESULT error code.
948     /// </returns>
949     STDMETHOD(CreateGlyphRunAnalysis)(
950         _In_ DWRITE_GLYPH_RUN const* glyphRun,
951         _In_opt_ DWRITE_MATRIX const* transform,
952         DWRITE_RENDERING_MODE renderingMode,
953         DWRITE_MEASURING_MODE measuringMode,
954         DWRITE_GRID_FIT_MODE gridFitMode,
955         DWRITE_TEXT_ANTIALIAS_MODE antialiasMode,
956         FLOAT baselineOriginX,
957         FLOAT baselineOriginY,
958         _COM_Outptr_ IDWriteGlyphRunAnalysis** glyphRunAnalysis
959         ) PURE;
960 
961     using IDWriteFactory::CreateGlyphRunAnalysis;
962 };
963 
964 #endif /* DWRITE_2_H_INCLUDED */
965