4 * Copyright 2012, 2014 Nikolay Sivov for CodeWeavers
5 * Copyright 2014 Aric Stewart for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/list.h"
25 #include "dwrite_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(dwrite
);
29 #define MS_HEAD_TAG DWRITE_MAKE_OPENTYPE_TAG('h','e','a','d')
30 #define MS_OS2_TAG DWRITE_MAKE_OPENTYPE_TAG('O','S','/','2')
31 #define MS_CMAP_TAG DWRITE_MAKE_OPENTYPE_TAG('c','m','a','p')
32 #define MS_NAME_TAG DWRITE_MAKE_OPENTYPE_TAG('n','a','m','e')
34 static const IID IID_issystemcollection
= {0x14d88047,0x331f,0x4cd3,{0xbc,0xa8,0x3e,0x67,0x99,0xaf,0x34,0x75}};
36 struct dwrite_font_data
{
39 DWRITE_FONT_STYLE style
;
40 DWRITE_FONT_STRETCH stretch
;
41 DWRITE_FONT_WEIGHT weight
;
42 DWRITE_FONT_METRICS1 metrics
;
43 IDWriteLocalizedStrings
*info_strings
[DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME
+1];
45 /* data needed to create fontface instance */
46 IDWriteFactory2
*factory
;
47 DWRITE_FONT_FACE_TYPE face_type
;
48 IDWriteFontFile
*file
;
54 struct dwrite_fontfamily_data
{
57 IDWriteLocalizedStrings
*familyname
;
59 struct dwrite_font_data
**fonts
;
64 struct dwrite_fontcollection
{
65 IDWriteFontCollection IDWriteFontCollection_iface
;
68 struct dwrite_fontfamily_data
**family_data
;
74 struct dwrite_fontfamily
{
75 IDWriteFontFamily IDWriteFontFamily_iface
;
78 struct dwrite_fontfamily_data
*data
;
80 IDWriteFontCollection
* collection
;
84 IDWriteFont2 IDWriteFont2_iface
;
87 IDWriteFontFamily
*family
;
90 DWRITE_FONT_STYLE style
;
91 struct dwrite_font_data
*data
;
94 struct dwrite_fonttable
{
100 #define GLYPH_BLOCK_SHIFT 8
101 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
102 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
103 #define GLYPH_MAX 65536
105 struct dwrite_fontface
{
106 IDWriteFontFace2 IDWriteFontFace2_iface
;
109 IDWriteFontFileStream
**streams
;
110 IDWriteFontFile
**files
;
115 DWRITE_FONT_FACE_TYPE type
;
116 DWRITE_FONT_METRICS1 metrics
;
117 DWRITE_CARET_METRICS caret
;
119 struct dwrite_fonttable cmap
;
120 DWRITE_GLYPH_METRICS
*glyphs
[GLYPH_MAX
/GLYPH_BLOCK_SIZE
];
123 struct dwrite_fontfile
{
124 IDWriteFontFile IDWriteFontFile_iface
;
127 IDWriteFontFileLoader
*loader
;
130 IDWriteFontFileStream
*stream
;
133 static inline struct dwrite_fontface
*impl_from_IDWriteFontFace2(IDWriteFontFace2
*iface
)
135 return CONTAINING_RECORD(iface
, struct dwrite_fontface
, IDWriteFontFace2_iface
);
138 static inline struct dwrite_font
*impl_from_IDWriteFont2(IDWriteFont2
*iface
)
140 return CONTAINING_RECORD(iface
, struct dwrite_font
, IDWriteFont2_iface
);
143 static inline struct dwrite_fontfile
*impl_from_IDWriteFontFile(IDWriteFontFile
*iface
)
145 return CONTAINING_RECORD(iface
, struct dwrite_fontfile
, IDWriteFontFile_iface
);
148 static inline struct dwrite_fontfamily
*impl_from_IDWriteFontFamily(IDWriteFontFamily
*iface
)
150 return CONTAINING_RECORD(iface
, struct dwrite_fontfamily
, IDWriteFontFamily_iface
);
153 static inline struct dwrite_fontcollection
*impl_from_IDWriteFontCollection(IDWriteFontCollection
*iface
)
155 return CONTAINING_RECORD(iface
, struct dwrite_fontcollection
, IDWriteFontCollection_iface
);
158 static HRESULT
get_cached_glyph_metrics(struct dwrite_fontface
*fontface
, UINT16 glyph
, DWRITE_GLYPH_METRICS
*metrics
)
160 static const DWRITE_GLYPH_METRICS nil
;
161 DWRITE_GLYPH_METRICS
*block
= fontface
->glyphs
[glyph
>> GLYPH_BLOCK_SHIFT
];
163 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(DWRITE_GLYPH_METRICS
))) return S_FALSE
;
164 memcpy(metrics
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(*metrics
));
168 static HRESULT
set_cached_glyph_metrics(struct dwrite_fontface
*fontface
, UINT16 glyph
, DWRITE_GLYPH_METRICS
*metrics
)
170 DWRITE_GLYPH_METRICS
**block
= &fontface
->glyphs
[glyph
>> GLYPH_BLOCK_SHIFT
];
173 /* start new block */
174 *block
= heap_alloc_zero(sizeof(*metrics
) * GLYPH_BLOCK_SIZE
);
176 return E_OUTOFMEMORY
;
179 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], metrics
, sizeof(*metrics
));
183 static inline void* get_fontface_cmap(struct dwrite_fontface
*fontface
)
188 if (fontface
->cmap
.data
)
189 return fontface
->cmap
.data
;
191 hr
= IDWriteFontFace2_TryGetFontTable(&fontface
->IDWriteFontFace2_iface
, MS_CMAP_TAG
, (const void**)&fontface
->cmap
.data
,
192 &fontface
->cmap
.size
, &fontface
->cmap
.context
, &exists
);
193 if (FAILED(hr
) || !exists
) {
194 ERR("Font does not have a CMAP table\n");
198 return fontface
->cmap
.data
;
201 static void release_font_data(struct dwrite_font_data
*data
)
205 if (InterlockedDecrement(&data
->ref
) > 0)
208 for (i
= DWRITE_INFORMATIONAL_STRING_NONE
; i
< sizeof(data
->info_strings
)/sizeof(data
->info_strings
[0]); i
++) {
209 if (data
->info_strings
[i
])
210 IDWriteLocalizedStrings_Release(data
->info_strings
[i
]);
213 IDWriteFontFile_Release(data
->file
);
214 IDWriteFactory2_Release(data
->factory
);
215 heap_free(data
->facename
);
219 static void release_fontfamily_data(struct dwrite_fontfamily_data
*data
)
223 if (InterlockedDecrement(&data
->ref
) > 0)
226 for (i
= 0; i
< data
->font_count
; i
++)
227 release_font_data(data
->fonts
[i
]);
228 heap_free(data
->fonts
);
229 IDWriteLocalizedStrings_Release(data
->familyname
);
233 static HRESULT WINAPI
dwritefontface_QueryInterface(IDWriteFontFace2
*iface
, REFIID riid
, void **obj
)
235 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
237 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
239 if (IsEqualIID(riid
, &IID_IDWriteFontFace2
) ||
240 IsEqualIID(riid
, &IID_IDWriteFontFace1
) ||
241 IsEqualIID(riid
, &IID_IDWriteFontFace
) ||
242 IsEqualIID(riid
, &IID_IUnknown
))
245 IDWriteFontFace2_AddRef(iface
);
250 return E_NOINTERFACE
;
253 static ULONG WINAPI
dwritefontface_AddRef(IDWriteFontFace2
*iface
)
255 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
256 ULONG ref
= InterlockedIncrement(&This
->ref
);
257 TRACE("(%p)->(%d)\n", This
, ref
);
261 static ULONG WINAPI
dwritefontface_Release(IDWriteFontFace2
*iface
)
263 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
264 ULONG ref
= InterlockedDecrement(&This
->ref
);
266 TRACE("(%p)->(%d)\n", This
, ref
);
271 if (This
->cmap
.context
)
272 IDWriteFontFace2_ReleaseFontTable(iface
, This
->cmap
.context
);
273 for (i
= 0; i
< This
->file_count
; i
++) {
274 if (This
->streams
[i
])
275 IDWriteFontFileStream_Release(This
->streams
[i
]);
277 IDWriteFontFile_Release(This
->files
[i
]);
280 for (i
= 0; i
< sizeof(This
->glyphs
)/sizeof(This
->glyphs
[0]); i
++)
281 heap_free(This
->glyphs
[i
]);
283 freetype_notify_cacheremove(iface
);
290 static DWRITE_FONT_FACE_TYPE WINAPI
dwritefontface_GetType(IDWriteFontFace2
*iface
)
292 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
293 TRACE("(%p)\n", This
);
297 static HRESULT WINAPI
dwritefontface_GetFiles(IDWriteFontFace2
*iface
, UINT32
*number_of_files
,
298 IDWriteFontFile
**fontfiles
)
300 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
303 TRACE("(%p)->(%p %p)\n", This
, number_of_files
, fontfiles
);
304 if (fontfiles
== NULL
)
306 *number_of_files
= This
->file_count
;
309 if (*number_of_files
< This
->file_count
)
312 for (i
= 0; i
< This
->file_count
; i
++)
314 IDWriteFontFile_AddRef(This
->files
[i
]);
315 fontfiles
[i
] = This
->files
[i
];
321 static UINT32 WINAPI
dwritefontface_GetIndex(IDWriteFontFace2
*iface
)
323 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
324 TRACE("(%p)\n", This
);
328 static DWRITE_FONT_SIMULATIONS WINAPI
dwritefontface_GetSimulations(IDWriteFontFace2
*iface
)
330 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
331 TRACE("(%p)\n", This
);
332 return This
->simulations
;
335 static BOOL WINAPI
dwritefontface_IsSymbolFont(IDWriteFontFace2
*iface
)
337 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
338 FIXME("(%p): stub\n", This
);
342 static void WINAPI
dwritefontface_GetMetrics(IDWriteFontFace2
*iface
, DWRITE_FONT_METRICS
*metrics
)
344 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
345 TRACE("(%p)->(%p)\n", This
, metrics
);
346 memcpy(metrics
, &This
->metrics
, sizeof(*metrics
));
349 static UINT16 WINAPI
dwritefontface_GetGlyphCount(IDWriteFontFace2
*iface
)
351 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
352 TRACE("(%p)\n", This
);
353 return freetype_get_glyphcount(iface
);
356 static HRESULT WINAPI
dwritefontface_GetDesignGlyphMetrics(IDWriteFontFace2
*iface
,
357 UINT16
const *glyphs
, UINT32 glyph_count
, DWRITE_GLYPH_METRICS
*ret
, BOOL is_sideways
)
359 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
363 TRACE("(%p)->(%p %u %p %d)\n", This
, glyphs
, glyph_count
, ret
, is_sideways
);
369 FIXME("sideways metrics are not supported.\n");
371 for (i
= 0; i
< glyph_count
; i
++) {
372 DWRITE_GLYPH_METRICS metrics
;
374 hr
= get_cached_glyph_metrics(This
, glyphs
[i
], &metrics
);
376 freetype_get_design_glyph_metrics(iface
, This
->metrics
.designUnitsPerEm
, glyphs
[i
], &metrics
);
377 hr
= set_cached_glyph_metrics(This
, glyphs
[i
], &metrics
);
387 static HRESULT WINAPI
dwritefontface_GetGlyphIndices(IDWriteFontFace2
*iface
, UINT32
const *codepoints
,
388 UINT32 count
, UINT16
*glyph_indices
)
390 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
394 TRACE("(%p)->(%p %u %p)\n", This
, codepoints
, count
, glyph_indices
);
396 data
= get_fontface_cmap(This
);
400 for (i
= 0; i
< count
; i
++)
401 opentype_cmap_get_glyphindex(data
, codepoints
[i
], &glyph_indices
[i
]);
406 static HRESULT WINAPI
dwritefontface_TryGetFontTable(IDWriteFontFace2
*iface
, UINT32 table_tag
,
407 const void **table_data
, UINT32
*table_size
, void **context
, BOOL
*exists
)
409 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
411 TRACE("(%p)->(%u %p %p %p %p)\n", This
, table_tag
, table_data
, table_size
, context
, exists
);
413 return opentype_get_font_table(This
->streams
[0], This
->type
, This
->index
, table_tag
, table_data
, context
, table_size
, exists
);
416 static void WINAPI
dwritefontface_ReleaseFontTable(IDWriteFontFace2
*iface
, void *table_context
)
418 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
420 TRACE("(%p)->(%p)\n", This
, table_context
);
422 IDWriteFontFileStream_ReleaseFileFragment(This
->streams
[0], table_context
);
425 HRESULT
new_glyph_outline(UINT32 count
, struct glyph_outline
**ret
)
427 struct glyph_outline
*outline
;
428 D2D1_POINT_2F
*points
;
433 outline
= heap_alloc(sizeof(*outline
));
435 return E_OUTOFMEMORY
;
437 points
= heap_alloc(count
*sizeof(D2D1_POINT_2F
));
438 tags
= heap_alloc(count
*sizeof(UINT8
));
439 if (!points
|| !tags
) {
443 return E_OUTOFMEMORY
;
446 outline
->points
= points
;
447 outline
->tags
= tags
;
448 outline
->count
= count
;
449 outline
->advance
= 0.0;
455 static void free_glyph_outline(struct glyph_outline
*outline
)
457 heap_free(outline
->points
);
458 heap_free(outline
->tags
);
462 static void report_glyph_outline(const struct glyph_outline
*outline
, IDWriteGeometrySink
*sink
)
466 for (p
= 0; p
< outline
->count
; p
++) {
467 if (outline
->tags
[p
] & OUTLINE_POINT_START
) {
468 ID2D1SimplifiedGeometrySink_BeginFigure(sink
, outline
->points
[p
], D2D1_FIGURE_BEGIN_FILLED
);
472 if (outline
->tags
[p
] & OUTLINE_POINT_LINE
)
473 ID2D1SimplifiedGeometrySink_AddLines(sink
, outline
->points
+p
, 1);
474 else if (outline
->tags
[p
] & OUTLINE_POINT_BEZIER
) {
475 static const UINT16 segment_length
= 3;
476 ID2D1SimplifiedGeometrySink_AddBeziers(sink
, (D2D1_BEZIER_SEGMENT
*)&outline
->points
[p
], 1);
477 p
+= segment_length
- 1;
480 if (outline
->tags
[p
] & OUTLINE_POINT_END
)
481 ID2D1SimplifiedGeometrySink_EndFigure(sink
, D2D1_FIGURE_END_CLOSED
);
485 static inline void translate_glyph_outline(struct glyph_outline
*outline
, FLOAT xoffset
, FLOAT yoffset
)
489 for (p
= 0; p
< outline
->count
; p
++) {
490 outline
->points
[p
].x
+= xoffset
;
491 outline
->points
[p
].y
+= yoffset
;
495 static HRESULT WINAPI
dwritefontface_GetGlyphRunOutline(IDWriteFontFace2
*iface
, FLOAT emSize
,
496 UINT16
const *glyphs
, FLOAT
const* advances
, DWRITE_GLYPH_OFFSET
const *offsets
,
497 UINT32 count
, BOOL is_sideways
, BOOL is_rtl
, IDWriteGeometrySink
*sink
)
499 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
504 TRACE("(%p)->(%.2f %p %p %p %u %d %d %p)\n", This
, emSize
, glyphs
, advances
, offsets
,
505 count
, is_sideways
, is_rtl
, sink
);
507 if (!glyphs
|| !sink
)
511 FIXME("sideways mode is not supported.\n");
513 for (g
= 0; g
< count
; g
++) {
514 FLOAT xoffset
= 0.0, yoffset
= 0.0;
515 struct glyph_outline
*outline
;
517 /* FIXME: cache outlines */
519 hr
= freetype_get_glyph_outline(iface
, emSize
, glyphs
[g
], This
->simulations
, &outline
);
523 /* glyph offsets act as current glyph adjustment */
525 xoffset
+= is_rtl
? -offsets
[g
].advanceOffset
: offsets
[g
].advanceOffset
;
526 yoffset
-= offsets
[g
].ascenderOffset
;
530 advance
= is_rtl
? -outline
->advance
: 0.0;
533 translate_glyph_outline(outline
, xoffset
, yoffset
);
535 /* update advance to next glyph */
537 advance
+= is_rtl
? -advances
[g
] : advances
[g
];
539 advance
+= is_rtl
? -outline
->advance
: outline
->advance
;
541 report_glyph_outline(outline
, sink
);
542 free_glyph_outline(outline
);
548 static HRESULT WINAPI
dwritefontface_GetRecommendedRenderingMode(IDWriteFontFace2
*iface
, FLOAT emSize
,
549 FLOAT pixels_per_dip
, DWRITE_MEASURING_MODE mode
, IDWriteRenderingParams
* params
, DWRITE_RENDERING_MODE
* rendering_mode
)
551 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
552 FIXME("(%p)->(%f %f %d %p %p): stub\n", This
, emSize
, pixels_per_dip
, mode
, params
, rendering_mode
);
556 static HRESULT WINAPI
dwritefontface_GetGdiCompatibleMetrics(IDWriteFontFace2
*iface
, FLOAT emSize
, FLOAT pixels_per_dip
,
557 DWRITE_MATRIX
const *transform
, DWRITE_FONT_METRICS
*metrics
)
559 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
560 DWRITE_FONT_METRICS1 metrics1
;
563 TRACE("(%p)->(%.2f %.2f %p %p)\n", This
, emSize
, pixels_per_dip
, transform
, metrics
);
565 hr
= IDWriteFontFace2_GetGdiCompatibleMetrics(iface
, emSize
, pixels_per_dip
, transform
, &metrics1
);
569 memcpy(metrics
, &metrics1
, sizeof(*metrics
));
573 static HRESULT WINAPI
dwritefontface_GetGdiCompatibleGlyphMetrics(IDWriteFontFace2
*iface
, FLOAT emSize
, FLOAT pixels_per_dip
,
574 DWRITE_MATRIX
const *transform
, BOOL use_gdi_natural
, UINT16
const *glyph_indices
, UINT32 glyph_count
,
575 DWRITE_GLYPH_METRICS
*metrics
, BOOL is_sideways
)
577 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
578 FIXME("(%p)->(%f %f %p %d %p %u %p %d): stub\n", This
, emSize
, pixels_per_dip
, transform
, use_gdi_natural
, glyph_indices
,
579 glyph_count
, metrics
, is_sideways
);
583 static void WINAPI
dwritefontface1_GetMetrics(IDWriteFontFace2
*iface
, DWRITE_FONT_METRICS1
*metrics
)
585 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
586 TRACE("(%p)->(%p)\n", This
, metrics
);
587 *metrics
= This
->metrics
;
590 static HRESULT WINAPI
dwritefontface1_GetGdiCompatibleMetrics(IDWriteFontFace2
*iface
, FLOAT em_size
, FLOAT pixels_per_dip
,
591 const DWRITE_MATRIX
*transform
, DWRITE_FONT_METRICS1
*metrics
)
593 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
594 FIXME("(%p)->(%f %f %p %p): stub\n", This
, em_size
, pixels_per_dip
, transform
, metrics
);
598 static void WINAPI
dwritefontface1_GetCaretMetrics(IDWriteFontFace2
*iface
, DWRITE_CARET_METRICS
*metrics
)
600 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
601 TRACE("(%p)->(%p)\n", This
, metrics
);
602 *metrics
= This
->caret
;
605 static HRESULT WINAPI
dwritefontface1_GetUnicodeRanges(IDWriteFontFace2
*iface
, UINT32 max_count
,
606 DWRITE_UNICODE_RANGE
*ranges
, UINT32
*count
)
608 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
610 TRACE("(%p)->(%u %p %p)\n", This
, max_count
, ranges
, count
);
613 if (max_count
&& !ranges
)
616 return opentype_cmap_get_unicode_ranges(get_fontface_cmap(This
), max_count
, ranges
, count
);
619 static BOOL WINAPI
dwritefontface1_IsMonospacedFont(IDWriteFontFace2
*iface
)
621 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
622 TRACE("(%p)\n", This
);
623 return freetype_is_monospaced(iface
);
626 static HRESULT WINAPI
dwritefontface1_GetDesignGlyphAdvances(IDWriteFontFace2
*iface
,
627 UINT32 glyph_count
, UINT16
const *glyphs
, INT32
*advances
, BOOL is_sideways
)
629 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
632 TRACE("(%p)->(%u %p %p %d)\n", This
, glyph_count
, glyphs
, advances
, is_sideways
);
634 for (i
= 0; i
< glyph_count
; i
++) {
635 DWRITE_GLYPH_METRICS metrics
= { 0 };
638 hr
= IDWriteFontFace2_GetDesignGlyphMetrics(iface
, glyphs
+ i
, 1, &metrics
, is_sideways
);
642 advances
[i
] = is_sideways
? metrics
.advanceHeight
: metrics
.advanceWidth
;
648 static HRESULT WINAPI
dwritefontface1_GetGdiCompatibleGlyphAdvances(IDWriteFontFace2
*iface
,
649 FLOAT em_size
, FLOAT pixels_per_dip
, const DWRITE_MATRIX
*transform
, BOOL use_gdi_natural
,
650 BOOL is_sideways
, UINT32 glyph_count
, UINT16
const *indices
, INT32
*advances
)
652 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
653 FIXME("(%p)->(%f %f %p %d %d %u %p %p): stub\n", This
, em_size
, pixels_per_dip
, transform
,
654 use_gdi_natural
, is_sideways
, glyph_count
, indices
, advances
);
658 static HRESULT WINAPI
dwritefontface1_GetKerningPairAdjustments(IDWriteFontFace2
*iface
, UINT32 glyph_count
,
659 const UINT16
*indices
, INT32
*adjustments
)
661 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
662 FIXME("(%p)->(%u %p %p): stub\n", This
, glyph_count
, indices
, adjustments
);
666 static BOOL WINAPI
dwritefontface1_HasKerningPairs(IDWriteFontFace2
*iface
)
668 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
669 FIXME("(%p): stub\n", This
);
673 static HRESULT WINAPI
dwritefontface1_GetRecommendedRenderingMode(IDWriteFontFace2
*iface
,
674 FLOAT font_emsize
, FLOAT dpiX
, FLOAT dpiY
, const DWRITE_MATRIX
*transform
, BOOL is_sideways
,
675 DWRITE_OUTLINE_THRESHOLD threshold
, DWRITE_MEASURING_MODE measuring_mode
, DWRITE_RENDERING_MODE
*rendering_mode
)
677 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
678 FIXME("(%p)->(%f %f %f %p %d %d %d %p): stub\n", This
, font_emsize
, dpiX
, dpiY
, transform
, is_sideways
,
679 threshold
, measuring_mode
, rendering_mode
);
683 static HRESULT WINAPI
dwritefontface1_GetVerticalGlyphVariants(IDWriteFontFace2
*iface
, UINT32 glyph_count
,
684 const UINT16
*nominal_indices
, UINT16
*vertical_indices
)
686 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
687 FIXME("(%p)->(%u %p %p): stub\n", This
, glyph_count
, nominal_indices
, vertical_indices
);
691 static BOOL WINAPI
dwritefontface1_HasVerticalGlyphVariants(IDWriteFontFace2
*iface
)
693 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
694 FIXME("(%p): stub\n", This
);
698 static BOOL WINAPI
dwritefontface2_IsColorFont(IDWriteFontFace2
*iface
)
700 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
701 FIXME("(%p): stub\n", This
);
705 static UINT32 WINAPI
dwritefontface2_GetColorPaletteCount(IDWriteFontFace2
*iface
)
707 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
708 FIXME("(%p): stub\n", This
);
712 static UINT32 WINAPI
dwritefontface2_GetPaletteEntryCount(IDWriteFontFace2
*iface
)
714 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
715 FIXME("(%p): stub\n", This
);
719 static HRESULT WINAPI
dwritefontface2_GetPaletteEntries(IDWriteFontFace2
*iface
, UINT32 palette_index
,
720 UINT32 first_entry_index
, UINT32 entry_count
, DWRITE_COLOR_F
*entries
)
722 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
723 FIXME("(%p)->(%u %u %u %p): stub\n", This
, palette_index
, first_entry_index
, entry_count
, entries
);
727 static HRESULT WINAPI
dwritefontface2_GetRecommendedRenderingMode(IDWriteFontFace2
*iface
, FLOAT fontEmSize
,
728 FLOAT dpiX
, FLOAT dpiY
, DWRITE_MATRIX
const *transform
, BOOL is_sideways
, DWRITE_OUTLINE_THRESHOLD threshold
,
729 DWRITE_MEASURING_MODE measuringmode
, IDWriteRenderingParams
*params
, DWRITE_RENDERING_MODE
*renderingmode
,
730 DWRITE_GRID_FIT_MODE
*gridfitmode
)
732 struct dwrite_fontface
*This
= impl_from_IDWriteFontFace2(iface
);
733 FIXME("(%p)->(%f %f %f %p %d %d %d %p %p %p): stub\n", This
, fontEmSize
, dpiX
, dpiY
, transform
, is_sideways
, threshold
,
734 measuringmode
, params
, renderingmode
, gridfitmode
);
738 static const IDWriteFontFace2Vtbl dwritefontfacevtbl
= {
739 dwritefontface_QueryInterface
,
740 dwritefontface_AddRef
,
741 dwritefontface_Release
,
742 dwritefontface_GetType
,
743 dwritefontface_GetFiles
,
744 dwritefontface_GetIndex
,
745 dwritefontface_GetSimulations
,
746 dwritefontface_IsSymbolFont
,
747 dwritefontface_GetMetrics
,
748 dwritefontface_GetGlyphCount
,
749 dwritefontface_GetDesignGlyphMetrics
,
750 dwritefontface_GetGlyphIndices
,
751 dwritefontface_TryGetFontTable
,
752 dwritefontface_ReleaseFontTable
,
753 dwritefontface_GetGlyphRunOutline
,
754 dwritefontface_GetRecommendedRenderingMode
,
755 dwritefontface_GetGdiCompatibleMetrics
,
756 dwritefontface_GetGdiCompatibleGlyphMetrics
,
757 dwritefontface1_GetMetrics
,
758 dwritefontface1_GetGdiCompatibleMetrics
,
759 dwritefontface1_GetCaretMetrics
,
760 dwritefontface1_GetUnicodeRanges
,
761 dwritefontface1_IsMonospacedFont
,
762 dwritefontface1_GetDesignGlyphAdvances
,
763 dwritefontface1_GetGdiCompatibleGlyphAdvances
,
764 dwritefontface1_GetKerningPairAdjustments
,
765 dwritefontface1_HasKerningPairs
,
766 dwritefontface1_GetRecommendedRenderingMode
,
767 dwritefontface1_GetVerticalGlyphVariants
,
768 dwritefontface1_HasVerticalGlyphVariants
,
769 dwritefontface2_IsColorFont
,
770 dwritefontface2_GetColorPaletteCount
,
771 dwritefontface2_GetPaletteEntryCount
,
772 dwritefontface2_GetPaletteEntries
,
773 dwritefontface2_GetRecommendedRenderingMode
776 HRESULT
get_family_names_from_stream(IDWriteFontFileStream
*stream
, UINT32 index
, DWRITE_FONT_FACE_TYPE facetype
,
777 IDWriteLocalizedStrings
**names
)
779 const void *name_table
= NULL
;
783 opentype_get_font_table(stream
, facetype
, index
, MS_NAME_TAG
, &name_table
, &name_context
, NULL
, NULL
);
785 hr
= opentype_get_font_strings_from_id(name_table
, DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES
, names
);
786 IDWriteFontFileStream_ReleaseFileFragment(stream
, name_context
);
794 static HRESULT
get_fontface_from_font(struct dwrite_font
*font
, IDWriteFontFace2
**fontface
)
796 struct dwrite_font_data
*data
= font
->data
;
797 IDWriteFontFace
*face
;
802 hr
= IDWriteFactory2_CreateFontFace(data
->factory
, data
->face_type
, 1, &data
->file
,
803 data
->face_index
, font
->simulations
, &face
);
807 hr
= IDWriteFontFace_QueryInterface(face
, &IID_IDWriteFontFace2
, (void**)fontface
);
808 IDWriteFontFace_Release(face
);
813 static HRESULT WINAPI
dwritefont_QueryInterface(IDWriteFont2
*iface
, REFIID riid
, void **obj
)
815 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
817 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
819 if (IsEqualIID(riid
, &IID_IDWriteFont2
) ||
820 IsEqualIID(riid
, &IID_IDWriteFont1
) ||
821 IsEqualIID(riid
, &IID_IDWriteFont
) ||
822 IsEqualIID(riid
, &IID_IUnknown
))
825 IDWriteFont2_AddRef(iface
);
830 return E_NOINTERFACE
;
833 static ULONG WINAPI
dwritefont_AddRef(IDWriteFont2
*iface
)
835 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
836 ULONG ref
= InterlockedIncrement(&This
->ref
);
837 TRACE("(%p)->(%d)\n", This
, ref
);
841 static ULONG WINAPI
dwritefont_Release(IDWriteFont2
*iface
)
843 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
844 ULONG ref
= InterlockedDecrement(&This
->ref
);
846 TRACE("(%p)->(%d)\n", This
, ref
);
849 IDWriteFontFamily_Release(This
->family
);
850 release_font_data(This
->data
);
857 static HRESULT WINAPI
dwritefont_GetFontFamily(IDWriteFont2
*iface
, IDWriteFontFamily
**family
)
859 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
860 TRACE("(%p)->(%p)\n", This
, family
);
862 *family
= This
->family
;
863 IDWriteFontFamily_AddRef(*family
);
867 static DWRITE_FONT_WEIGHT WINAPI
dwritefont_GetWeight(IDWriteFont2
*iface
)
869 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
870 TRACE("(%p)\n", This
);
871 return This
->data
->weight
;
874 static DWRITE_FONT_STRETCH WINAPI
dwritefont_GetStretch(IDWriteFont2
*iface
)
876 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
877 TRACE("(%p)\n", This
);
878 return This
->data
->stretch
;
881 static DWRITE_FONT_STYLE WINAPI
dwritefont_GetStyle(IDWriteFont2
*iface
)
883 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
884 TRACE("(%p)\n", This
);
888 static BOOL WINAPI
dwritefont_IsSymbolFont(IDWriteFont2
*iface
)
890 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
891 IDWriteFontFace2
*fontface
;
894 TRACE("(%p)\n", This
);
896 hr
= get_fontface_from_font(This
, &fontface
);
900 return IDWriteFontFace2_IsSymbolFont(fontface
);
903 static HRESULT WINAPI
dwritefont_GetFaceNames(IDWriteFont2
*iface
, IDWriteLocalizedStrings
**names
)
905 static const WCHAR boldobliqueW
[] = {'B','o','l','d',' ','O','b','l','i','q','u','e',0};
906 static const WCHAR obliqueW
[] = {'O','b','l','i','q','u','e',0};
907 static const WCHAR boldW
[] = {'B','o','l','d',0};
908 static const WCHAR enusW
[] = {'e','n','-','u','s',0};
910 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
911 IDWriteLocalizedStrings
*strings
;
915 TRACE("(%p)->(%p)\n", This
, names
);
919 if (This
->simulations
== DWRITE_FONT_SIMULATIONS_NONE
) {
921 return IDWriteFont2_GetInformationalStrings(iface
, DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES
,
925 switch (This
->simulations
) {
926 case DWRITE_FONT_SIMULATIONS_BOLD
|DWRITE_FONT_SIMULATIONS_OBLIQUE
:
929 case DWRITE_FONT_SIMULATIONS_BOLD
:
932 case DWRITE_FONT_SIMULATIONS_OBLIQUE
:
936 ERR("unknown simulations %d\n", This
->simulations
);
940 hr
= create_localizedstrings(&strings
);
941 if (FAILED(hr
)) return hr
;
943 hr
= add_localizedstring(strings
, enusW
, name
);
945 IDWriteLocalizedStrings_Release(strings
);
954 static HRESULT WINAPI
dwritefont_GetInformationalStrings(IDWriteFont2
*iface
,
955 DWRITE_INFORMATIONAL_STRING_ID stringid
, IDWriteLocalizedStrings
**strings
, BOOL
*exists
)
957 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
958 struct dwrite_font_data
*data
= This
->data
;
961 TRACE("(%p)->(%d %p %p)\n", This
, stringid
, strings
, exists
);
966 if (stringid
> DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_CID_NAME
|| stringid
== DWRITE_INFORMATIONAL_STRING_NONE
)
969 if (!data
->info_strings
[stringid
]) {
970 IDWriteFontFace2
*fontface
;
971 const void *table_data
;
976 hr
= get_fontface_from_font(This
, &fontface
);
980 table_exists
= FALSE
;
981 hr
= IDWriteFontFace2_TryGetFontTable(fontface
, MS_NAME_TAG
, &table_data
, &size
, &context
, &table_exists
);
982 if (FAILED(hr
) || !table_exists
)
983 WARN("no NAME table found.\n");
986 hr
= opentype_get_font_strings_from_id(table_data
, stringid
, &data
->info_strings
[stringid
]);
987 if (FAILED(hr
) || !data
->info_strings
[stringid
])
989 IDWriteFontFace2_ReleaseFontTable(fontface
, context
);
993 hr
= clone_localizedstring(data
->info_strings
[stringid
], strings
);
1001 static DWRITE_FONT_SIMULATIONS WINAPI
dwritefont_GetSimulations(IDWriteFont2
*iface
)
1003 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1004 TRACE("(%p)\n", This
);
1005 return This
->simulations
;
1008 static void WINAPI
dwritefont_GetMetrics(IDWriteFont2
*iface
, DWRITE_FONT_METRICS
*metrics
)
1010 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1012 TRACE("(%p)->(%p)\n", This
, metrics
);
1013 memcpy(metrics
, &This
->data
->metrics
, sizeof(*metrics
));
1016 static HRESULT WINAPI
dwritefont_HasCharacter(IDWriteFont2
*iface
, UINT32 value
, BOOL
*exists
)
1018 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1019 IDWriteFontFace2
*fontface
;
1023 TRACE("(%p)->(0x%08x %p)\n", This
, value
, exists
);
1027 hr
= get_fontface_from_font(This
, &fontface
);
1032 hr
= IDWriteFontFace2_GetGlyphIndices(fontface
, &value
, 1, &index
);
1036 *exists
= index
!= 0;
1040 static HRESULT WINAPI
dwritefont_CreateFontFace(IDWriteFont2
*iface
, IDWriteFontFace
**face
)
1042 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1045 TRACE("(%p)->(%p)\n", This
, face
);
1047 hr
= get_fontface_from_font(This
, (IDWriteFontFace2
**)face
);
1049 IDWriteFontFace_AddRef(*face
);
1054 static void WINAPI
dwritefont1_GetMetrics(IDWriteFont2
*iface
, DWRITE_FONT_METRICS1
*metrics
)
1056 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1057 TRACE("(%p)->(%p)\n", This
, metrics
);
1058 *metrics
= This
->data
->metrics
;
1061 static void WINAPI
dwritefont1_GetPanose(IDWriteFont2
*iface
, DWRITE_PANOSE
*panose
)
1063 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1064 FIXME("(%p)->(%p): stub\n", This
, panose
);
1067 static HRESULT WINAPI
dwritefont1_GetUnicodeRanges(IDWriteFont2
*iface
, UINT32 max_count
, DWRITE_UNICODE_RANGE
*ranges
, UINT32
*count
)
1069 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1070 IDWriteFontFace2
*fontface
;
1073 TRACE("(%p)->(%u %p %p)\n", This
, max_count
, ranges
, count
);
1075 hr
= get_fontface_from_font(This
, &fontface
);
1079 return IDWriteFontFace2_GetUnicodeRanges(fontface
, max_count
, ranges
, count
);
1082 static BOOL WINAPI
dwritefont1_IsMonospacedFont(IDWriteFont2
*iface
)
1084 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1085 IDWriteFontFace2
*fontface
;
1088 TRACE("(%p)\n", This
);
1090 hr
= get_fontface_from_font(This
, &fontface
);
1094 return IDWriteFontFace2_IsMonospacedFont(fontface
);
1097 static HRESULT WINAPI
dwritefont2_IsColorFont(IDWriteFont2
*iface
)
1099 struct dwrite_font
*This
= impl_from_IDWriteFont2(iface
);
1100 IDWriteFontFace2
*fontface
;
1103 TRACE("(%p)\n", This
);
1105 hr
= get_fontface_from_font(This
, &fontface
);
1109 return IDWriteFontFace2_IsColorFont(fontface
);
1112 static const IDWriteFont2Vtbl dwritefontvtbl
= {
1113 dwritefont_QueryInterface
,
1116 dwritefont_GetFontFamily
,
1117 dwritefont_GetWeight
,
1118 dwritefont_GetStretch
,
1119 dwritefont_GetStyle
,
1120 dwritefont_IsSymbolFont
,
1121 dwritefont_GetFaceNames
,
1122 dwritefont_GetInformationalStrings
,
1123 dwritefont_GetSimulations
,
1124 dwritefont_GetMetrics
,
1125 dwritefont_HasCharacter
,
1126 dwritefont_CreateFontFace
,
1127 dwritefont1_GetMetrics
,
1128 dwritefont1_GetPanose
,
1129 dwritefont1_GetUnicodeRanges
,
1130 dwritefont1_IsMonospacedFont
,
1131 dwritefont2_IsColorFont
1134 static HRESULT
create_font(struct dwrite_font_data
*data
, IDWriteFontFamily
*family
, DWRITE_FONT_SIMULATIONS simulations
,
1137 struct dwrite_font
*This
;
1140 This
= heap_alloc(sizeof(struct dwrite_font
));
1141 if (!This
) return E_OUTOFMEMORY
;
1143 This
->IDWriteFont2_iface
.lpVtbl
= &dwritefontvtbl
;
1145 This
->family
= family
;
1146 IDWriteFontFamily_AddRef(family
);
1147 This
->simulations
= simulations
;
1148 This
->style
= data
->style
;
1150 InterlockedIncrement(&This
->data
->ref
);
1152 /* set oblique style from requested simulation */
1153 if ((simulations
& DWRITE_FONT_SIMULATIONS_OBLIQUE
) && data
->style
== DWRITE_FONT_STYLE_NORMAL
)
1154 This
->style
= DWRITE_FONT_STYLE_OBLIQUE
;
1156 *font
= (IDWriteFont
*)&This
->IDWriteFont2_iface
;
1161 static HRESULT WINAPI
dwritefontfamily_QueryInterface(IDWriteFontFamily
*iface
, REFIID riid
, void **obj
)
1163 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1164 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1166 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1167 IsEqualIID(riid
, &IID_IDWriteFontList
) ||
1168 IsEqualIID(riid
, &IID_IDWriteFontFamily
))
1171 IDWriteFontFamily_AddRef(iface
);
1176 return E_NOINTERFACE
;
1179 static ULONG WINAPI
dwritefontfamily_AddRef(IDWriteFontFamily
*iface
)
1181 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1182 ULONG ref
= InterlockedIncrement(&This
->ref
);
1183 TRACE("(%p)->(%d)\n", This
, ref
);
1187 static ULONG WINAPI
dwritefontfamily_Release(IDWriteFontFamily
*iface
)
1189 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1190 ULONG ref
= InterlockedDecrement(&This
->ref
);
1192 TRACE("(%p)->(%d)\n", This
, ref
);
1196 IDWriteFontCollection_Release(This
->collection
);
1197 release_fontfamily_data(This
->data
);
1204 static HRESULT WINAPI
dwritefontfamily_GetFontCollection(IDWriteFontFamily
*iface
, IDWriteFontCollection
**collection
)
1206 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1207 TRACE("(%p)->(%p)\n", This
, collection
);
1209 *collection
= This
->collection
;
1210 IDWriteFontCollection_AddRef(This
->collection
);
1214 static UINT32 WINAPI
dwritefontfamily_GetFontCount(IDWriteFontFamily
*iface
)
1216 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1217 TRACE("(%p)\n", This
);
1218 return This
->data
->font_count
;
1221 static HRESULT WINAPI
dwritefontfamily_GetFont(IDWriteFontFamily
*iface
, UINT32 index
, IDWriteFont
**font
)
1223 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1225 TRACE("(%p)->(%u %p)\n", This
, index
, font
);
1229 if (This
->data
->font_count
== 0)
1232 if (index
>= This
->data
->font_count
)
1233 return E_INVALIDARG
;
1235 return create_font(This
->data
->fonts
[index
], iface
, DWRITE_FONT_SIMULATIONS_NONE
, font
);
1238 static HRESULT WINAPI
dwritefontfamily_GetFamilyNames(IDWriteFontFamily
*iface
, IDWriteLocalizedStrings
**names
)
1240 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1241 return clone_localizedstring(This
->data
->familyname
, names
);
1244 static inline BOOL
is_matching_font_style(DWRITE_FONT_STYLE style
, DWRITE_FONT_STYLE font_style
)
1246 if (style
== font_style
)
1249 if (((style
== DWRITE_FONT_STYLE_ITALIC
) || (style
== DWRITE_FONT_STYLE_OBLIQUE
)) && font_style
== DWRITE_FONT_STYLE_NORMAL
)
1255 static HRESULT WINAPI
dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily
*iface
, DWRITE_FONT_WEIGHT weight
,
1256 DWRITE_FONT_STRETCH stretch
, DWRITE_FONT_STYLE style
, IDWriteFont
**font
)
1258 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1259 UINT32 min_weight_diff
= ~0u;
1262 TRACE("(%p)->(%d %d %d %p)\n", This
, weight
, stretch
, style
, font
);
1264 for (i
= 0; i
< This
->data
->font_count
; i
++) {
1265 if (is_matching_font_style(style
, This
->data
->fonts
[i
]->style
) && stretch
== This
->data
->fonts
[i
]->stretch
) {
1266 DWRITE_FONT_WEIGHT font_weight
= This
->data
->fonts
[i
]->weight
;
1267 UINT32 weight_diff
= abs(font_weight
- weight
);
1268 if (weight_diff
< min_weight_diff
) {
1269 min_weight_diff
= weight_diff
;
1276 DWRITE_FONT_SIMULATIONS simulations
= DWRITE_FONT_SIMULATIONS_NONE
;
1278 if (((style
== DWRITE_FONT_STYLE_ITALIC
) || (style
== DWRITE_FONT_STYLE_OBLIQUE
)) &&
1279 This
->data
->fonts
[found
]->style
== DWRITE_FONT_STYLE_NORMAL
) {
1280 simulations
= DWRITE_FONT_SIMULATIONS_OBLIQUE
;
1282 return create_font(This
->data
->fonts
[found
], iface
, simulations
, font
);
1286 return DWRITE_E_NOFONT
;
1290 static HRESULT WINAPI
dwritefontfamily_GetMatchingFonts(IDWriteFontFamily
*iface
, DWRITE_FONT_WEIGHT weight
,
1291 DWRITE_FONT_STRETCH stretch
, DWRITE_FONT_STYLE style
, IDWriteFontList
**fonts
)
1293 struct dwrite_fontfamily
*This
= impl_from_IDWriteFontFamily(iface
);
1294 FIXME("(%p)->(%d %d %d %p): stub\n", This
, weight
, stretch
, style
, fonts
);
1298 static const IDWriteFontFamilyVtbl fontfamilyvtbl
= {
1299 dwritefontfamily_QueryInterface
,
1300 dwritefontfamily_AddRef
,
1301 dwritefontfamily_Release
,
1302 dwritefontfamily_GetFontCollection
,
1303 dwritefontfamily_GetFontCount
,
1304 dwritefontfamily_GetFont
,
1305 dwritefontfamily_GetFamilyNames
,
1306 dwritefontfamily_GetFirstMatchingFont
,
1307 dwritefontfamily_GetMatchingFonts
1310 static HRESULT
create_fontfamily(struct dwrite_fontfamily_data
*data
, IDWriteFontCollection
*collection
, IDWriteFontFamily
**family
)
1312 struct dwrite_fontfamily
*This
;
1316 This
= heap_alloc(sizeof(struct dwrite_fontfamily
));
1317 if (!This
) return E_OUTOFMEMORY
;
1319 This
->IDWriteFontFamily_iface
.lpVtbl
= &fontfamilyvtbl
;
1321 This
->collection
= collection
;
1322 IDWriteFontCollection_AddRef(collection
);
1324 InterlockedIncrement(&This
->data
->ref
);
1326 *family
= &This
->IDWriteFontFamily_iface
;
1331 BOOL
is_system_collection(IDWriteFontCollection
*collection
)
1334 return IDWriteFontCollection_QueryInterface(collection
, &IID_issystemcollection
, (void**)&obj
) == S_OK
;
1337 static HRESULT WINAPI
dwritefontcollection_QueryInterface(IDWriteFontCollection
*iface
, REFIID riid
, void **obj
)
1339 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1340 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1342 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1343 IsEqualIID(riid
, &IID_IDWriteFontCollection
))
1346 IDWriteFontCollection_AddRef(iface
);
1352 if (This
->is_system
&& IsEqualIID(riid
, &IID_issystemcollection
))
1355 return E_NOINTERFACE
;
1358 static ULONG WINAPI
dwritefontcollection_AddRef(IDWriteFontCollection
*iface
)
1360 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1361 ULONG ref
= InterlockedIncrement(&This
->ref
);
1362 TRACE("(%p)->(%d)\n", This
, ref
);
1366 static ULONG WINAPI
dwritefontcollection_Release(IDWriteFontCollection
*iface
)
1369 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1370 ULONG ref
= InterlockedDecrement(&This
->ref
);
1371 TRACE("(%p)->(%d)\n", This
, ref
);
1374 for (i
= 0; i
< This
->family_count
; i
++)
1375 release_fontfamily_data(This
->family_data
[i
]);
1376 heap_free(This
->family_data
);
1383 static UINT32 WINAPI
dwritefontcollection_GetFontFamilyCount(IDWriteFontCollection
*iface
)
1385 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1386 TRACE("(%p)\n", This
);
1387 return This
->family_count
;
1390 static HRESULT WINAPI
dwritefontcollection_GetFontFamily(IDWriteFontCollection
*iface
, UINT32 index
, IDWriteFontFamily
**family
)
1392 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1394 TRACE("(%p)->(%u %p)\n", This
, index
, family
);
1396 if (index
>= This
->family_count
) {
1401 return create_fontfamily(This
->family_data
[index
], iface
, family
);
1404 static UINT32
collection_find_family(struct dwrite_fontcollection
*collection
, const WCHAR
*name
)
1408 for (i
= 0; i
< collection
->family_count
; i
++) {
1409 IDWriteLocalizedStrings
*family_name
= collection
->family_data
[i
]->familyname
;
1413 for (j
= 0; j
< IDWriteLocalizedStrings_GetCount(family_name
); j
++) {
1415 hr
= IDWriteLocalizedStrings_GetString(family_name
, j
, buffer
, 255);
1416 if (SUCCEEDED(hr
) && !strcmpW(buffer
, name
))
1424 static HRESULT WINAPI
dwritefontcollection_FindFamilyName(IDWriteFontCollection
*iface
, const WCHAR
*name
, UINT32
*index
, BOOL
*exists
)
1426 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1427 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(name
), index
, exists
);
1428 *index
= collection_find_family(This
, name
);
1429 *exists
= *index
!= ~0u;
1433 static BOOL
is_same_fontfile(IDWriteFontFile
*left
, IDWriteFontFile
*right
)
1435 UINT32 left_key_size
, right_key_size
;
1436 const void *left_key
, *right_key
;
1442 hr
= IDWriteFontFile_GetReferenceKey(left
, &left_key
, &left_key_size
);
1446 hr
= IDWriteFontFile_GetReferenceKey(right
, &right_key
, &right_key_size
);
1450 if (left_key_size
!= right_key_size
)
1453 return !memcmp(left_key
, right_key
, left_key_size
);
1456 static HRESULT WINAPI
dwritefontcollection_GetFontFromFontFace(IDWriteFontCollection
*iface
, IDWriteFontFace
*face
, IDWriteFont
**font
)
1458 struct dwrite_fontcollection
*This
= impl_from_IDWriteFontCollection(iface
);
1459 struct dwrite_fontfamily_data
*found_family
= NULL
;
1460 struct dwrite_font_data
*found_font
= NULL
;
1461 DWRITE_FONT_SIMULATIONS simulations
;
1462 IDWriteFontFamily
*family
;
1463 UINT32 i
, j
, face_index
;
1464 IDWriteFontFile
*file
;
1467 TRACE("(%p)->(%p %p)\n", This
, face
, font
);
1472 return E_INVALIDARG
;
1475 hr
= IDWriteFontFace_GetFiles(face
, &i
, &file
);
1478 face_index
= IDWriteFontFace_GetIndex(face
);
1480 for (i
= 0; i
< This
->family_count
; i
++) {
1481 struct dwrite_fontfamily_data
*family_data
= This
->family_data
[i
];
1482 for (j
= 0; j
< family_data
->font_count
; j
++) {
1483 struct dwrite_font_data
*font_data
= family_data
->fonts
[j
];
1485 if (face_index
== font_data
->face_index
&& is_same_fontfile(file
, font_data
->file
)) {
1486 found_font
= font_data
;
1487 found_family
= family_data
;
1494 return DWRITE_E_NOFONT
;
1496 hr
= create_fontfamily(found_family
, iface
, &family
);
1500 simulations
= IDWriteFontFace_GetSimulations(face
);
1501 hr
= create_font(found_font
, family
, simulations
, font
);
1502 IDWriteFontFamily_Release(family
);
1506 static const IDWriteFontCollectionVtbl fontcollectionvtbl
= {
1507 dwritefontcollection_QueryInterface
,
1508 dwritefontcollection_AddRef
,
1509 dwritefontcollection_Release
,
1510 dwritefontcollection_GetFontFamilyCount
,
1511 dwritefontcollection_GetFontFamily
,
1512 dwritefontcollection_FindFamilyName
,
1513 dwritefontcollection_GetFontFromFontFace
1516 static HRESULT
fontfamily_add_font(struct dwrite_fontfamily_data
*family_data
, struct dwrite_font_data
*font_data
)
1518 if (family_data
->font_count
+ 1 >= family_data
->font_alloc
) {
1519 struct dwrite_font_data
**new_list
;
1522 new_alloc
= family_data
->font_alloc
* 2;
1523 new_list
= heap_realloc(family_data
->fonts
, sizeof(*family_data
->fonts
) * new_alloc
);
1525 return E_OUTOFMEMORY
;
1526 family_data
->fonts
= new_list
;
1527 family_data
->font_alloc
= new_alloc
;
1530 family_data
->fonts
[family_data
->font_count
] = font_data
;
1531 family_data
->font_count
++;
1535 static HRESULT
fontcollection_add_family(struct dwrite_fontcollection
*collection
, struct dwrite_fontfamily_data
*family
)
1537 if (collection
->family_alloc
< collection
->family_count
+ 1) {
1538 struct dwrite_fontfamily_data
**new_list
;
1541 new_alloc
= collection
->family_alloc
* 2;
1542 new_list
= heap_realloc(collection
->family_data
, sizeof(*new_list
) * new_alloc
);
1544 return E_OUTOFMEMORY
;
1546 collection
->family_alloc
= new_alloc
;
1547 collection
->family_data
= new_list
;
1550 collection
->family_data
[collection
->family_count
] = family
;
1551 collection
->family_count
++;
1556 static HRESULT
init_font_collection(struct dwrite_fontcollection
*collection
, BOOL is_system
)
1558 collection
->IDWriteFontCollection_iface
.lpVtbl
= &fontcollectionvtbl
;
1559 collection
->ref
= 1;
1560 collection
->family_count
= 0;
1561 collection
->family_alloc
= 2;
1562 collection
->is_system
= is_system
;
1564 collection
->family_data
= heap_alloc(sizeof(*collection
->family_data
)*2);
1565 if (!collection
->family_data
)
1566 return E_OUTOFMEMORY
;
1571 HRESULT
get_filestream_from_file(IDWriteFontFile
*file
, IDWriteFontFileStream
**stream
)
1573 IDWriteFontFileLoader
*loader
;
1580 hr
= IDWriteFontFile_GetReferenceKey(file
, &key
, &key_size
);
1584 hr
= IDWriteFontFile_GetLoader(file
, &loader
);
1588 hr
= IDWriteFontFileLoader_CreateStreamFromKey(loader
, key
, key_size
, stream
);
1589 IDWriteFontFileLoader_Release(loader
);
1596 static HRESULT
init_font_data(IDWriteFactory2
*factory
, IDWriteFontFile
*file
, UINT32 face_index
, DWRITE_FONT_FACE_TYPE face_type
,
1597 IDWriteFontFileStream
**stream
, struct dwrite_font_data
**ret
)
1599 void *os2_context
, *head_context
;
1600 const void *tt_os2
= NULL
, *tt_head
= NULL
;
1601 struct dwrite_font_data
*data
;
1604 data
= heap_alloc_zero(sizeof(*data
));
1606 return E_OUTOFMEMORY
;
1608 hr
= get_filestream_from_file(file
, stream
);
1615 data
->factory
= factory
;
1617 data
->face_index
= face_index
;
1618 data
->face_type
= face_type
;
1619 IDWriteFontFile_AddRef(file
);
1620 IDWriteFactory2_AddRef(factory
);
1622 opentype_get_font_table(*stream
, face_type
, face_index
, MS_OS2_TAG
, &tt_os2
, &os2_context
, NULL
, NULL
);
1623 opentype_get_font_table(*stream
, face_type
, face_index
, MS_HEAD_TAG
, &tt_head
, &head_context
, NULL
, NULL
);
1625 opentype_get_font_properties(*stream
, face_type
, face_index
, &data
->stretch
, &data
->weight
, &data
->style
);
1626 opentype_get_font_metrics(*stream
, face_type
, face_index
, &data
->metrics
, NULL
);
1629 IDWriteFontFileStream_ReleaseFileFragment(*stream
, os2_context
);
1631 IDWriteFontFileStream_ReleaseFileFragment(*stream
, head_context
);
1637 static HRESULT
init_fontfamily_data(IDWriteLocalizedStrings
*familyname
, struct dwrite_fontfamily_data
**ret
)
1639 struct dwrite_fontfamily_data
*data
;
1641 data
= heap_alloc(sizeof(*data
));
1643 return E_OUTOFMEMORY
;
1646 data
->font_count
= 0;
1647 data
->font_alloc
= 2;
1649 data
->fonts
= heap_alloc(sizeof(*data
->fonts
)*data
->font_alloc
);
1652 return E_OUTOFMEMORY
;
1655 data
->familyname
= familyname
;
1656 IDWriteLocalizedStrings_AddRef(familyname
);
1662 HRESULT
create_font_collection(IDWriteFactory2
* factory
, IDWriteFontFileEnumerator
*enumerator
, BOOL is_system
, IDWriteFontCollection
**ret
)
1664 struct dwrite_fontcollection
*collection
;
1665 BOOL current
= FALSE
;
1670 collection
= heap_alloc(sizeof(struct dwrite_fontcollection
));
1671 if (!collection
) return E_OUTOFMEMORY
;
1673 hr
= init_font_collection(collection
, is_system
);
1675 heap_free(collection
);
1679 *ret
= &collection
->IDWriteFontCollection_iface
;
1681 TRACE("building font collection:\n");
1683 while (hr
== S_OK
) {
1684 DWRITE_FONT_FACE_TYPE face_type
;
1685 DWRITE_FONT_FILE_TYPE file_type
;
1686 IDWriteFontFile
*file
;
1692 hr
= IDWriteFontFileEnumerator_MoveNext(enumerator
, ¤t
);
1693 if (FAILED(hr
) || !current
)
1696 hr
= IDWriteFontFileEnumerator_GetCurrentFontFile(enumerator
, &file
);
1700 hr
= IDWriteFontFile_Analyze(file
, &supported
, &file_type
, &face_type
, &face_count
);
1701 if (FAILED(hr
) || !supported
|| face_count
== 0) {
1702 TRACE("unsupported font (0x%08x, %d, %u)\n", hr
, supported
, face_count
);
1703 IDWriteFontFile_Release(file
);
1707 for (i
= 0; i
< face_count
; i
++) {
1708 IDWriteLocalizedStrings
*family_name
= NULL
;
1709 struct dwrite_font_data
*font_data
;
1710 IDWriteFontFileStream
*stream
;
1714 /* alloc and init new font data structure */
1715 hr
= init_font_data(factory
, file
, i
, face_type
, &stream
, &font_data
);
1719 /* get family name from font file */
1720 hr
= get_family_names_from_stream(stream
, i
, face_type
, &family_name
);
1721 IDWriteFontFileStream_Release(stream
);
1723 WARN("unable to get family name from font\n");
1724 release_font_data(font_data
);
1729 IDWriteLocalizedStrings_GetString(family_name
, 0, buffer
, sizeof(buffer
)/sizeof(WCHAR
));
1731 index
= collection_find_family(collection
, buffer
);
1733 hr
= fontfamily_add_font(collection
->family_data
[index
], font_data
);
1735 struct dwrite_fontfamily_data
*family_data
;
1737 /* create and init new family */
1738 hr
= init_fontfamily_data(family_name
, &family_data
);
1740 /* add font to family, family - to collection */
1741 hr
= fontfamily_add_font(family_data
, font_data
);
1743 hr
= fontcollection_add_family(collection
, family_data
);
1746 release_fontfamily_data(family_data
);
1750 IDWriteLocalizedStrings_Release(family_name
);
1756 IDWriteFontFile_Release(file
);
1762 struct system_fontfile_enumerator
1764 IDWriteFontFileEnumerator IDWriteFontFileEnumerator_iface
;
1767 IDWriteFactory2
*factory
;
1772 static inline struct system_fontfile_enumerator
*impl_from_IDWriteFontFileEnumerator(IDWriteFontFileEnumerator
* iface
)
1774 return CONTAINING_RECORD(iface
, struct system_fontfile_enumerator
, IDWriteFontFileEnumerator_iface
);
1777 static HRESULT WINAPI
systemfontfileenumerator_QueryInterface(IDWriteFontFileEnumerator
*iface
, REFIID riid
, void **obj
)
1781 if (IsEqualIID(riid
, &IID_IDWriteFontFileEnumerator
) || IsEqualIID(riid
, &IID_IUnknown
)) {
1782 IDWriteFontFileEnumerator_AddRef(iface
);
1787 return E_NOINTERFACE
;
1790 static ULONG WINAPI
systemfontfileenumerator_AddRef(IDWriteFontFileEnumerator
*iface
)
1792 struct system_fontfile_enumerator
*enumerator
= impl_from_IDWriteFontFileEnumerator(iface
);
1793 return InterlockedIncrement(&enumerator
->ref
);
1796 static ULONG WINAPI
systemfontfileenumerator_Release(IDWriteFontFileEnumerator
*iface
)
1798 struct system_fontfile_enumerator
*enumerator
= impl_from_IDWriteFontFileEnumerator(iface
);
1799 ULONG ref
= InterlockedDecrement(&enumerator
->ref
);
1802 IDWriteFactory2_Release(enumerator
->factory
);
1803 RegCloseKey(enumerator
->hkey
);
1804 heap_free(enumerator
);
1810 static HRESULT WINAPI
systemfontfileenumerator_GetCurrentFontFile(IDWriteFontFileEnumerator
*iface
, IDWriteFontFile
**file
)
1812 struct system_fontfile_enumerator
*enumerator
= impl_from_IDWriteFontFileEnumerator(iface
);
1813 DWORD ret
, type
, count
;
1819 if (enumerator
->index
< 0)
1822 if (RegEnumValueW(enumerator
->hkey
, enumerator
->index
, NULL
, NULL
, NULL
, &type
, NULL
, &count
))
1825 if (!(filename
= heap_alloc(count
)))
1826 return E_OUTOFMEMORY
;
1828 ret
= RegEnumValueW(enumerator
->hkey
, enumerator
->index
, NULL
, NULL
, NULL
, &type
, (BYTE
*)filename
, &count
);
1830 heap_free(filename
);
1834 /* Fonts installed in 'Fonts' system dir don't get full path in registry font files cache */
1835 if (!strchrW(filename
, '\\')) {
1836 static const WCHAR fontsW
[] = {'\\','f','o','n','t','s','\\',0};
1837 WCHAR fullpathW
[MAX_PATH
];
1839 GetWindowsDirectoryW(fullpathW
, sizeof(fullpathW
)/sizeof(WCHAR
));
1840 strcatW(fullpathW
, fontsW
);
1841 strcatW(fullpathW
, filename
);
1843 hr
= IDWriteFactory2_CreateFontFileReference(enumerator
->factory
, fullpathW
, NULL
, file
);
1846 hr
= IDWriteFactory2_CreateFontFileReference(enumerator
->factory
, filename
, NULL
, file
);
1848 heap_free(filename
);
1852 static HRESULT WINAPI
systemfontfileenumerator_MoveNext(IDWriteFontFileEnumerator
*iface
, BOOL
*current
)
1854 struct system_fontfile_enumerator
*enumerator
= impl_from_IDWriteFontFileEnumerator(iface
);
1857 enumerator
->index
++;
1859 /* iterate until we find next string value */
1861 DWORD type
= 0, count
;
1862 if (RegEnumValueW(enumerator
->hkey
, enumerator
->index
, NULL
, NULL
, NULL
, &type
, NULL
, &count
))
1864 if (type
== REG_SZ
) {
1868 enumerator
->index
++;
1871 TRACE("index = %d, current = %d\n", enumerator
->index
, *current
);
1875 static const struct IDWriteFontFileEnumeratorVtbl systemfontfileenumeratorvtbl
=
1877 systemfontfileenumerator_QueryInterface
,
1878 systemfontfileenumerator_AddRef
,
1879 systemfontfileenumerator_Release
,
1880 systemfontfileenumerator_MoveNext
,
1881 systemfontfileenumerator_GetCurrentFontFile
1884 static HRESULT
create_system_fontfile_enumerator(IDWriteFactory2
*factory
, IDWriteFontFileEnumerator
**ret
)
1886 struct system_fontfile_enumerator
*enumerator
;
1887 static const WCHAR fontslistW
[] = {
1888 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1889 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1890 'F','o','n','t','s',0
1895 enumerator
= heap_alloc(sizeof(*enumerator
));
1897 return E_OUTOFMEMORY
;
1899 enumerator
->IDWriteFontFileEnumerator_iface
.lpVtbl
= &systemfontfileenumeratorvtbl
;
1900 enumerator
->ref
= 1;
1901 enumerator
->factory
= factory
;
1902 enumerator
->index
= -1;
1903 IDWriteFactory2_AddRef(factory
);
1905 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, fontslistW
, 0, GENERIC_READ
, &enumerator
->hkey
)) {
1906 ERR("failed to open fonts list key\n");
1907 IDWriteFactory2_Release(factory
);
1908 heap_free(enumerator
);
1912 *ret
= &enumerator
->IDWriteFontFileEnumerator_iface
;
1917 HRESULT
get_system_fontcollection(IDWriteFactory2
*factory
, IDWriteFontCollection
**collection
)
1919 IDWriteFontFileEnumerator
*enumerator
;
1924 hr
= create_system_fontfile_enumerator(factory
, &enumerator
);
1928 TRACE("building system font collection for factory %p\n", factory
);
1929 hr
= create_font_collection(factory
, enumerator
, TRUE
, collection
);
1930 IDWriteFontFileEnumerator_Release(enumerator
);
1934 static HRESULT WINAPI
eudcfontfileenumerator_QueryInterface(IDWriteFontFileEnumerator
*iface
, REFIID riid
, void **obj
)
1938 if (IsEqualIID(riid
, &IID_IDWriteFontFileEnumerator
) || IsEqualIID(riid
, &IID_IUnknown
)) {
1939 IDWriteFontFileEnumerator_AddRef(iface
);
1944 return E_NOINTERFACE
;
1947 static ULONG WINAPI
eudcfontfileenumerator_AddRef(IDWriteFontFileEnumerator
*iface
)
1952 static ULONG WINAPI
eudcfontfileenumerator_Release(IDWriteFontFileEnumerator
*iface
)
1957 static HRESULT WINAPI
eudcfontfileenumerator_GetCurrentFontFile(IDWriteFontFileEnumerator
*iface
, IDWriteFontFile
**file
)
1963 static HRESULT WINAPI
eudcfontfileenumerator_MoveNext(IDWriteFontFileEnumerator
*iface
, BOOL
*current
)
1969 static const struct IDWriteFontFileEnumeratorVtbl eudcfontfileenumeratorvtbl
=
1971 eudcfontfileenumerator_QueryInterface
,
1972 eudcfontfileenumerator_AddRef
,
1973 eudcfontfileenumerator_Release
,
1974 eudcfontfileenumerator_MoveNext
,
1975 eudcfontfileenumerator_GetCurrentFontFile
1978 static IDWriteFontFileEnumerator eudc_fontfile_enumerator
= { &eudcfontfileenumeratorvtbl
};
1980 HRESULT
get_eudc_fontcollection(IDWriteFactory2
*factory
, IDWriteFontCollection
**collection
)
1982 TRACE("building EUDC font collection for factory %p\n", factory
);
1983 return create_font_collection(factory
, &eudc_fontfile_enumerator
, FALSE
, collection
);
1986 static HRESULT WINAPI
dwritefontfile_QueryInterface(IDWriteFontFile
*iface
, REFIID riid
, void **obj
)
1988 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
1990 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
1992 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteFontFile
))
1995 IDWriteFontFile_AddRef(iface
);
2000 return E_NOINTERFACE
;
2003 static ULONG WINAPI
dwritefontfile_AddRef(IDWriteFontFile
*iface
)
2005 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
2006 ULONG ref
= InterlockedIncrement(&This
->ref
);
2007 TRACE("(%p)->(%d)\n", This
, ref
);
2011 static ULONG WINAPI
dwritefontfile_Release(IDWriteFontFile
*iface
)
2013 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
2014 ULONG ref
= InterlockedDecrement(&This
->ref
);
2016 TRACE("(%p)->(%d)\n", This
, ref
);
2020 IDWriteFontFileLoader_Release(This
->loader
);
2021 if (This
->stream
) IDWriteFontFileStream_Release(This
->stream
);
2022 heap_free(This
->reference_key
);
2029 static HRESULT WINAPI
dwritefontfile_GetReferenceKey(IDWriteFontFile
*iface
, const void **fontFileReferenceKey
, UINT32
*fontFileReferenceKeySize
)
2031 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
2032 TRACE("(%p)->(%p, %p)\n", This
, fontFileReferenceKey
, fontFileReferenceKeySize
);
2033 *fontFileReferenceKey
= This
->reference_key
;
2034 *fontFileReferenceKeySize
= This
->key_size
;
2039 static HRESULT WINAPI
dwritefontfile_GetLoader(IDWriteFontFile
*iface
, IDWriteFontFileLoader
**fontFileLoader
)
2041 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
2042 TRACE("(%p)->(%p)\n", This
, fontFileLoader
);
2043 *fontFileLoader
= This
->loader
;
2044 IDWriteFontFileLoader_AddRef(This
->loader
);
2049 static HRESULT WINAPI
dwritefontfile_Analyze(IDWriteFontFile
*iface
, BOOL
*isSupportedFontType
, DWRITE_FONT_FILE_TYPE
*fontFileType
, DWRITE_FONT_FACE_TYPE
*fontFaceType
, UINT32
*numberOfFaces
)
2051 struct dwrite_fontfile
*This
= impl_from_IDWriteFontFile(iface
);
2052 IDWriteFontFileStream
*stream
;
2055 TRACE("(%p)->(%p, %p, %p, %p)\n", This
, isSupportedFontType
, fontFileType
, fontFaceType
, numberOfFaces
);
2057 *isSupportedFontType
= FALSE
;
2058 *fontFileType
= DWRITE_FONT_FILE_TYPE_UNKNOWN
;
2060 *fontFaceType
= DWRITE_FONT_FACE_TYPE_UNKNOWN
;
2063 hr
= IDWriteFontFileLoader_CreateStreamFromKey(This
->loader
, This
->reference_key
, This
->key_size
, &stream
);
2067 hr
= opentype_analyze_font(stream
, numberOfFaces
, fontFileType
, fontFaceType
, isSupportedFontType
);
2069 /* TODO: Further Analysis */
2070 IDWriteFontFileStream_Release(stream
);
2074 static const IDWriteFontFileVtbl dwritefontfilevtbl
= {
2075 dwritefontfile_QueryInterface
,
2076 dwritefontfile_AddRef
,
2077 dwritefontfile_Release
,
2078 dwritefontfile_GetReferenceKey
,
2079 dwritefontfile_GetLoader
,
2080 dwritefontfile_Analyze
,
2083 HRESULT
create_font_file(IDWriteFontFileLoader
*loader
, const void *reference_key
, UINT32 key_size
, IDWriteFontFile
**font_file
)
2085 struct dwrite_fontfile
*This
;
2087 This
= heap_alloc(sizeof(struct dwrite_fontfile
));
2088 if (!This
) return E_OUTOFMEMORY
;
2090 This
->IDWriteFontFile_iface
.lpVtbl
= &dwritefontfilevtbl
;
2092 IDWriteFontFileLoader_AddRef(loader
);
2093 This
->loader
= loader
;
2094 This
->stream
= NULL
;
2095 This
->reference_key
= heap_alloc(key_size
);
2096 memcpy(This
->reference_key
, reference_key
, key_size
);
2097 This
->key_size
= key_size
;
2099 *font_file
= &This
->IDWriteFontFile_iface
;
2104 static HRESULT
get_stream_from_file(IDWriteFontFile
*file
, IDWriteFontFileStream
**stream
)
2106 IDWriteFontFileLoader
*loader
;
2112 hr
= IDWriteFontFile_GetLoader(file
, &loader
);
2116 hr
= IDWriteFontFile_GetReferenceKey(file
, &key
, &key_size
);
2118 IDWriteFontFileLoader_Release(loader
);
2122 hr
= IDWriteFontFileLoader_CreateStreamFromKey(loader
, key
, key_size
, stream
);
2123 IDWriteFontFileLoader_Release(loader
);
2128 HRESULT
create_fontface(DWRITE_FONT_FACE_TYPE facetype
, UINT32 files_number
, IDWriteFontFile
* const* font_files
, UINT32 index
,
2129 DWRITE_FONT_SIMULATIONS simulations
, IDWriteFontFace2
**ret
)
2131 struct dwrite_fontface
*fontface
;
2137 fontface
= heap_alloc(sizeof(struct dwrite_fontface
));
2139 return E_OUTOFMEMORY
;
2141 fontface
->files
= heap_alloc_zero(sizeof(*fontface
->files
) * files_number
);
2142 fontface
->streams
= heap_alloc_zero(sizeof(*fontface
->streams
) * files_number
);
2144 if (!fontface
->files
|| !fontface
->streams
) {
2145 heap_free(fontface
->files
);
2146 heap_free(fontface
->streams
);
2147 heap_free(fontface
);
2148 return E_OUTOFMEMORY
;
2151 fontface
->IDWriteFontFace2_iface
.lpVtbl
= &dwritefontfacevtbl
;
2153 fontface
->type
= facetype
;
2154 fontface
->file_count
= files_number
;
2155 fontface
->cmap
.data
= NULL
;
2156 fontface
->cmap
.context
= NULL
;
2157 fontface
->cmap
.size
= 0;
2158 fontface
->index
= index
;
2159 fontface
->simulations
= simulations
;
2160 memset(fontface
->glyphs
, 0, sizeof(fontface
->glyphs
));
2162 for (i
= 0; i
< fontface
->file_count
; i
++) {
2163 hr
= get_stream_from_file(font_files
[i
], &fontface
->streams
[i
]);
2165 IDWriteFontFace2_Release(&fontface
->IDWriteFontFace2_iface
);
2169 fontface
->files
[i
] = font_files
[i
];
2170 IDWriteFontFile_AddRef(font_files
[i
]);
2173 opentype_get_font_metrics(fontface
->streams
[0], facetype
, index
, &fontface
->metrics
, &fontface
->caret
);
2174 if (simulations
& DWRITE_FONT_SIMULATIONS_OBLIQUE
) {
2175 /* TODO: test what happens if caret is already slanted */
2176 if (fontface
->caret
.slopeRise
== 1) {
2177 fontface
->caret
.slopeRise
= fontface
->metrics
.designUnitsPerEm
;
2178 fontface
->caret
.slopeRun
= fontface
->caret
.slopeRise
/ 3;
2182 *ret
= &fontface
->IDWriteFontFace2_iface
;
2186 /* IDWriteLocalFontFileLoader and its required IDWriteFontFileStream */
2193 struct local_cached_stream
2196 IDWriteFontFileStream
*stream
;
2197 struct local_refkey
*key
;
2201 struct dwrite_localfontfilestream
2203 IDWriteFontFileStream IDWriteFontFileStream_iface
;
2206 struct local_cached_stream
*entry
;
2207 const void *file_ptr
;
2211 struct dwrite_localfontfileloader
{
2212 IDWriteLocalFontFileLoader IDWriteLocalFontFileLoader_iface
;
2215 struct list streams
;
2218 static inline struct dwrite_localfontfileloader
*impl_from_IDWriteLocalFontFileLoader(IDWriteLocalFontFileLoader
*iface
)
2220 return CONTAINING_RECORD(iface
, struct dwrite_localfontfileloader
, IDWriteLocalFontFileLoader_iface
);
2223 static inline struct dwrite_localfontfilestream
*impl_from_IDWriteFontFileStream(IDWriteFontFileStream
*iface
)
2225 return CONTAINING_RECORD(iface
, struct dwrite_localfontfilestream
, IDWriteFontFileStream_iface
);
2228 static HRESULT WINAPI
localfontfilestream_QueryInterface(IDWriteFontFileStream
*iface
, REFIID riid
, void **obj
)
2230 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2231 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
2232 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteFontFileStream
))
2235 IDWriteFontFileStream_AddRef(iface
);
2240 return E_NOINTERFACE
;
2243 static ULONG WINAPI
localfontfilestream_AddRef(IDWriteFontFileStream
*iface
)
2245 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2246 ULONG ref
= InterlockedIncrement(&This
->ref
);
2247 TRACE("(%p)->(%d)\n", This
, ref
);
2251 static inline void release_cached_stream(struct local_cached_stream
*stream
)
2253 list_remove(&stream
->entry
);
2254 heap_free(stream
->key
);
2258 static ULONG WINAPI
localfontfilestream_Release(IDWriteFontFileStream
*iface
)
2260 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2261 ULONG ref
= InterlockedDecrement(&This
->ref
);
2263 TRACE("(%p)->(%d)\n", This
, ref
);
2266 UnmapViewOfFile(This
->file_ptr
);
2267 release_cached_stream(This
->entry
);
2274 static HRESULT WINAPI
localfontfilestream_ReadFileFragment(IDWriteFontFileStream
*iface
, void const **fragment_start
, UINT64 offset
, UINT64 fragment_size
, void **fragment_context
)
2276 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2278 TRACE("(%p)->(%p, %s, %s, %p)\n",This
, fragment_start
,
2279 wine_dbgstr_longlong(offset
), wine_dbgstr_longlong(fragment_size
), fragment_context
);
2281 *fragment_context
= NULL
;
2283 if ((offset
>= This
->size
- 1) || (fragment_size
> This
->size
- offset
)) {
2284 *fragment_start
= NULL
;
2288 *fragment_start
= (char*)This
->file_ptr
+ offset
;
2292 static void WINAPI
localfontfilestream_ReleaseFileFragment(IDWriteFontFileStream
*iface
, void *fragment_context
)
2294 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2295 TRACE("(%p)->(%p)\n", This
, fragment_context
);
2298 static HRESULT WINAPI
localfontfilestream_GetFileSize(IDWriteFontFileStream
*iface
, UINT64
*size
)
2300 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2301 TRACE("(%p)->(%p)\n", This
, size
);
2306 static HRESULT WINAPI
localfontfilestream_GetLastWriteTime(IDWriteFontFileStream
*iface
, UINT64
*last_writetime
)
2308 struct dwrite_localfontfilestream
*This
= impl_from_IDWriteFontFileStream(iface
);
2311 TRACE("(%p)->(%p)\n", This
, last_writetime
);
2313 li
.u
.LowPart
= This
->entry
->key
->writetime
.dwLowDateTime
;
2314 li
.u
.HighPart
= This
->entry
->key
->writetime
.dwHighDateTime
;
2315 *last_writetime
= li
.QuadPart
;
2320 static const IDWriteFontFileStreamVtbl localfontfilestreamvtbl
=
2322 localfontfilestream_QueryInterface
,
2323 localfontfilestream_AddRef
,
2324 localfontfilestream_Release
,
2325 localfontfilestream_ReadFileFragment
,
2326 localfontfilestream_ReleaseFileFragment
,
2327 localfontfilestream_GetFileSize
,
2328 localfontfilestream_GetLastWriteTime
2331 static HRESULT
create_localfontfilestream(const void *file_ptr
, UINT64 size
, struct local_cached_stream
*entry
, IDWriteFontFileStream
** iface
)
2333 struct dwrite_localfontfilestream
*This
= heap_alloc(sizeof(struct dwrite_localfontfilestream
));
2335 return E_OUTOFMEMORY
;
2337 This
->IDWriteFontFileStream_iface
.lpVtbl
= &localfontfilestreamvtbl
;
2340 This
->file_ptr
= file_ptr
;
2342 This
->entry
= entry
;
2344 *iface
= &This
->IDWriteFontFileStream_iface
;
2348 static HRESULT WINAPI
localfontfileloader_QueryInterface(IDWriteLocalFontFileLoader
*iface
, REFIID riid
, void **obj
)
2350 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2352 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
2354 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDWriteFontFileLoader
) || IsEqualIID(riid
, &IID_IDWriteLocalFontFileLoader
))
2357 IDWriteLocalFontFileLoader_AddRef(iface
);
2362 return E_NOINTERFACE
;
2365 static ULONG WINAPI
localfontfileloader_AddRef(IDWriteLocalFontFileLoader
*iface
)
2367 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2368 ULONG ref
= InterlockedIncrement(&This
->ref
);
2369 TRACE("(%p)->(%d)\n", This
, ref
);
2373 static ULONG WINAPI
localfontfileloader_Release(IDWriteLocalFontFileLoader
*iface
)
2375 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2376 ULONG ref
= InterlockedDecrement(&This
->ref
);
2378 TRACE("(%p)->(%d)\n", This
, ref
);
2381 struct local_cached_stream
*stream
, *stream2
;
2383 /* This will detach all entries from cache. Entries are released together with streams,
2384 so stream controls its lifetime. */
2385 LIST_FOR_EACH_ENTRY_SAFE(stream
, stream2
, &This
->streams
, struct local_cached_stream
, entry
)
2386 list_init(&stream
->entry
);
2394 static HRESULT WINAPI
localfontfileloader_CreateStreamFromKey(IDWriteLocalFontFileLoader
*iface
, const void *key
, UINT32 key_size
, IDWriteFontFileStream
**ret
)
2396 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2397 const struct local_refkey
*refkey
= key
;
2398 struct local_cached_stream
*stream
;
2399 IDWriteFontFileStream
*filestream
;
2400 HANDLE file
, mapping
;
2405 TRACE("(%p)->(%p, %i, %p)\n", This
, key
, key_size
, ret
);
2406 TRACE("name: %s\n", debugstr_w(refkey
->name
));
2408 /* search cache first */
2409 LIST_FOR_EACH_ENTRY(stream
, &This
->streams
, struct local_cached_stream
, entry
) {
2410 if (key_size
== stream
->key_size
&& !memcmp(stream
->key
, key
, key_size
)) {
2411 *ret
= stream
->stream
;
2412 IDWriteFontFileStream_AddRef(*ret
);
2419 file
= CreateFileW(refkey
->name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
2420 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2421 if (file
== INVALID_HANDLE_VALUE
)
2424 GetFileSizeEx(file
, &size
);
2425 mapping
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2430 file_ptr
= MapViewOfFile(mapping
, FILE_MAP_READ
, 0, 0, 0);
2431 CloseHandle(mapping
);
2433 stream
= heap_alloc(sizeof(*stream
));
2435 UnmapViewOfFile(file_ptr
);
2436 return E_OUTOFMEMORY
;
2439 stream
->key
= heap_alloc(key_size
);
2441 UnmapViewOfFile(file_ptr
);
2443 return E_OUTOFMEMORY
;
2446 stream
->key_size
= key_size
;
2447 memcpy(stream
->key
, key
, key_size
);
2449 hr
= create_localfontfilestream(file_ptr
, size
.QuadPart
, stream
, &filestream
);
2451 UnmapViewOfFile(file_ptr
);
2452 heap_free(stream
->key
);
2457 stream
->stream
= filestream
;
2458 list_add_head(&This
->streams
, &stream
->entry
);
2460 *ret
= stream
->stream
;
2465 static HRESULT WINAPI
localfontfileloader_GetFilePathLengthFromKey(IDWriteLocalFontFileLoader
*iface
, void const *key
, UINT32 key_size
, UINT32
*length
)
2467 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2468 const struct local_refkey
*refkey
= key
;
2470 TRACE("(%p)->(%p, %i, %p)\n", This
, key
, key_size
, length
);
2472 *length
= strlenW(refkey
->name
);
2476 static HRESULT WINAPI
localfontfileloader_GetFilePathFromKey(IDWriteLocalFontFileLoader
*iface
, void const *key
, UINT32 key_size
, WCHAR
*path
, UINT32 length
)
2478 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2479 const struct local_refkey
*refkey
= key
;
2481 TRACE("(%p)->(%p, %i, %p, %i)\n", This
, key
, key_size
, path
, length
);
2483 if (length
< strlenW(refkey
->name
))
2484 return E_INVALIDARG
;
2486 strcpyW(path
, refkey
->name
);
2490 static HRESULT WINAPI
localfontfileloader_GetLastWriteTimeFromKey(IDWriteLocalFontFileLoader
*iface
, void const *key
, UINT32 key_size
, FILETIME
*writetime
)
2492 struct dwrite_localfontfileloader
*This
= impl_from_IDWriteLocalFontFileLoader(iface
);
2493 const struct local_refkey
*refkey
= key
;
2495 TRACE("(%p)->(%p, %i, %p)\n", This
, key
, key_size
, writetime
);
2497 *writetime
= refkey
->writetime
;
2501 static const struct IDWriteLocalFontFileLoaderVtbl localfontfileloadervtbl
= {
2502 localfontfileloader_QueryInterface
,
2503 localfontfileloader_AddRef
,
2504 localfontfileloader_Release
,
2505 localfontfileloader_CreateStreamFromKey
,
2506 localfontfileloader_GetFilePathLengthFromKey
,
2507 localfontfileloader_GetFilePathFromKey
,
2508 localfontfileloader_GetLastWriteTimeFromKey
2511 HRESULT
create_localfontfileloader(IDWriteLocalFontFileLoader
** iface
)
2513 struct dwrite_localfontfileloader
*This
= heap_alloc(sizeof(struct dwrite_localfontfileloader
));
2515 return E_OUTOFMEMORY
;
2517 This
->IDWriteLocalFontFileLoader_iface
.lpVtbl
= &localfontfileloadervtbl
;
2519 list_init(&This
->streams
);
2521 *iface
= &This
->IDWriteLocalFontFileLoader_iface
;
2525 HRESULT
get_local_refkey(const WCHAR
*path
, const FILETIME
*writetime
, void **key
, UINT32
*size
)
2527 struct local_refkey
*refkey
;
2529 *size
= FIELD_OFFSET(struct local_refkey
, name
) + (strlenW(path
)+1)*sizeof(WCHAR
);
2532 refkey
= heap_alloc(*size
);
2534 return E_OUTOFMEMORY
;
2537 refkey
->writetime
= *writetime
;
2539 WIN32_FILE_ATTRIBUTE_DATA info
;
2541 if (GetFileAttributesExW(path
, GetFileExInfoStandard
, &info
))
2542 refkey
->writetime
= info
.ftLastWriteTime
;
2544 memset(&refkey
->writetime
, 0, sizeof(refkey
->writetime
));
2546 strcpyW(refkey
->name
, path
);