2 * Copyright 2012 Nikolay Sivov for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
24 #include "wine/heap.h"
25 #include "wine/list.h"
27 #define MS_GSUB_TAG DWRITE_MAKE_OPENTYPE_TAG('G','S','U','B')
28 #define MS_GPOS_TAG DWRITE_MAKE_OPENTYPE_TAG('G','P','O','S')
30 static const DWRITE_MATRIX identity
=
37 static inline LPWSTR
heap_strdupW(const WCHAR
*str
)
44 size
= (lstrlenW(str
) + 1)*sizeof(WCHAR
);
45 ret
= heap_alloc(size
);
47 memcpy(ret
, str
, size
);
53 static inline LPWSTR
heap_strdupnW(const WCHAR
*str
, UINT32 len
)
59 ret
= heap_alloc((len
+1)*sizeof(WCHAR
));
62 memcpy(ret
, str
, len
*sizeof(WCHAR
));
70 static inline const char *debugstr_range(const DWRITE_TEXT_RANGE
*range
)
72 return wine_dbg_sprintf("%u:%u", range
->startPosition
, range
->length
);
75 static inline const char *debugstr_matrix(const DWRITE_MATRIX
*m
)
77 if (!m
) return "(null)";
78 return wine_dbg_sprintf("{%.2f,%.2f,%.2f,%.2f,%.2f,%.2f}", m
->m11
, m
->m12
, m
->m21
, m
->m22
,
82 static inline BOOL
dwrite_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
84 size_t new_capacity
, max_capacity
;
87 if (count
<= *capacity
)
90 max_capacity
= ~(SIZE_T
)0 / size
;
91 if (count
> max_capacity
)
94 new_capacity
= max(4, *capacity
);
95 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
97 if (new_capacity
< count
)
98 new_capacity
= max_capacity
;
101 new_elements
= RtlAllocateHeap(GetProcessHeap(), 0, new_capacity
* size
);
103 new_elements
= RtlReAllocateHeap(GetProcessHeap(), 0, *elements
, new_capacity
* size
);
107 *elements
= new_elements
;
108 *capacity
= new_capacity
;
113 static inline const char *debugstr_tag(DWORD tag
)
115 return debugstr_an((char *)&tag
, 4);
118 const char *debugstr_sa_script(UINT16
) DECLSPEC_HIDDEN
;
120 static inline unsigned short get_table_entry(const unsigned short *table
, WCHAR ch
)
122 return table
[table
[table
[ch
>> 8] + ((ch
>> 4) & 0x0f)] + (ch
& 0xf)];
125 static inline BOOL
is_simulation_valid(DWRITE_FONT_SIMULATIONS simulations
)
127 return (simulations
& ~(DWRITE_FONT_SIMULATIONS_NONE
| DWRITE_FONT_SIMULATIONS_BOLD
|
128 DWRITE_FONT_SIMULATIONS_OBLIQUE
)) == 0;
131 struct textlayout_desc
133 IDWriteFactory7
*factory
;
136 IDWriteTextFormat
*format
;
139 BOOL is_gdi_compatible
;
140 /* fields below are only meaningful for gdi-compatible layout */
142 const DWRITE_MATRIX
*transform
;
143 BOOL use_gdi_natural
;
146 struct glyphrunanalysis_desc
148 const DWRITE_GLYPH_RUN
*run
;
149 const DWRITE_MATRIX
*transform
;
150 DWRITE_RENDERING_MODE1 rendering_mode
;
151 DWRITE_MEASURING_MODE measuring_mode
;
152 DWRITE_GRID_FIT_MODE gridfit_mode
;
153 DWRITE_TEXT_ANTIALIAS_MODE aa_mode
;
159 IDWriteFactory7
*factory
;
160 DWRITE_FONT_FACE_TYPE face_type
;
161 IDWriteFontFile
*file
;
162 IDWriteFontFileStream
*stream
;
164 DWRITE_FONT_SIMULATIONS simulations
;
165 struct dwrite_font_data
*font_data
; /* could be NULL when face is created directly with IDWriteFactory::CreateFontFace() */
168 struct dwrite_fonttable
176 struct fontfacecached
179 IDWriteFontFace5
*fontface
;
182 #define GLYPH_BLOCK_SHIFT 8
183 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
184 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
185 #define GLYPH_MAX 65536
189 FONT_IS_SYMBOL
= 0x00000001,
190 FONT_IS_MONOSPACED
= 0x00000002,
191 FONT_IS_COLORED
= 0x00000004, /* CPAL/COLR support */
192 FONTFACE_KERNING_PAIRS
= 0x00000008,
193 FONTFACE_NO_KERNING_PAIRS
= 0x00000010,
194 FONTFACE_VERTICAL_VARIANTS
= 0x00000020,
195 FONTFACE_NO_VERTICAL_VARIANTS
= 0x00000040,
200 typedef UINT16 (*p_cmap_get_glyph_func
)(const struct dwrite_cmap
*cmap
, unsigned int ch
);
201 typedef unsigned int (*p_cmap_get_ranges_func
)(const struct dwrite_cmap
*cmap
, unsigned int max_count
,
202 DWRITE_UNICODE_RANGE
*ranges
);
211 unsigned int seg_count
;
212 unsigned int glyph_id_array_len
;
215 const UINT16
*starts
;
216 const UINT16
*id_delta
;
217 const UINT16
*id_range_offset
;
218 const UINT16
*glyph_id_array
;
227 unsigned int group_count
;
230 p_cmap_get_glyph_func get_glyph
;
231 p_cmap_get_ranges_func get_ranges
;
232 unsigned short symbol
: 1;
233 IDWriteFontFileStream
*stream
;
237 extern void dwrite_cmap_init(struct dwrite_cmap
*cmap
, IDWriteFontFile
*file
, unsigned int face_index
,
238 DWRITE_FONT_FACE_TYPE face_type
) DECLSPEC_HIDDEN
;
239 extern void dwrite_cmap_release(struct dwrite_cmap
*cmap
) DECLSPEC_HIDDEN
;
240 extern UINT16
opentype_cmap_get_glyph(const struct dwrite_cmap
*cmap
, unsigned int ch
) DECLSPEC_HIDDEN
;
241 extern HRESULT
opentype_cmap_get_unicode_ranges(const struct dwrite_cmap
*cmap
, unsigned int max_count
,
242 DWRITE_UNICODE_RANGE
*ranges
, unsigned int *count
) DECLSPEC_HIDDEN
;
244 struct dwrite_fontface
246 IDWriteFontFace5 IDWriteFontFace5_iface
;
247 IDWriteFontFaceReference IDWriteFontFaceReference_iface
;
250 IDWriteFontFileStream
*stream
;
251 IDWriteFontFile
*file
;
254 IDWriteFactory7
*factory
;
255 struct fontfacecached
*cached
;
258 DWRITE_FONT_FACE_TYPE type
;
259 DWRITE_FONT_METRICS1 metrics
;
260 DWRITE_CARET_METRICS caret
;
264 unsigned int descent
;
268 struct dwrite_cmap cmap
;
270 struct dwrite_fonttable vdmx
;
271 struct dwrite_fonttable gasp
;
272 struct dwrite_fonttable cpal
;
273 struct dwrite_fonttable colr
;
274 struct dwrite_fonttable kern
;
275 DWRITE_GLYPH_METRICS
*glyphs
[GLYPH_MAX
/GLYPH_BLOCK_SIZE
];
277 DWRITE_FONT_STYLE style
;
278 DWRITE_FONT_STRETCH stretch
;
279 DWRITE_FONT_WEIGHT weight
;
280 DWRITE_PANOSE panose
;
281 FONTSIGNATURE fontsig
;
282 UINT32 glyph_image_formats
;
284 IDWriteLocalizedStrings
*info_strings
[DWRITE_INFORMATIONAL_STRING_SUPPORTED_SCRIPT_LANGUAGE_TAG
+ 1];
285 IDWriteLocalizedStrings
*family_names
;
286 IDWriteLocalizedStrings
*names
;
288 struct scriptshaping_cache
*shaping_cache
;
293 extern HRESULT
create_numbersubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD
,const WCHAR
*locale
,BOOL
,IDWriteNumberSubstitution
**) DECLSPEC_HIDDEN
;
294 extern HRESULT
create_textformat(const WCHAR
*,IDWriteFontCollection
*,DWRITE_FONT_WEIGHT
,DWRITE_FONT_STYLE
,DWRITE_FONT_STRETCH
,
295 FLOAT
,const WCHAR
*,IDWriteTextFormat
**) DECLSPEC_HIDDEN
;
296 extern HRESULT
create_textlayout(const struct textlayout_desc
*,IDWriteTextLayout
**) DECLSPEC_HIDDEN
;
297 extern HRESULT
create_trimmingsign(IDWriteFactory7
*factory
, IDWriteTextFormat
*format
,
298 IDWriteInlineObject
**sign
) DECLSPEC_HIDDEN
;
299 extern HRESULT
create_typography(IDWriteTypography
**) DECLSPEC_HIDDEN
;
300 extern HRESULT
create_localizedstrings(IDWriteLocalizedStrings
**) DECLSPEC_HIDDEN
;
301 extern HRESULT
add_localizedstring(IDWriteLocalizedStrings
*,const WCHAR
*,const WCHAR
*) DECLSPEC_HIDDEN
;
302 extern HRESULT
clone_localizedstrings(IDWriteLocalizedStrings
*iface
, IDWriteLocalizedStrings
**strings
) DECLSPEC_HIDDEN
;
303 extern void set_en_localizedstring(IDWriteLocalizedStrings
*,const WCHAR
*) DECLSPEC_HIDDEN
;
304 extern void sort_localizedstrings(IDWriteLocalizedStrings
*) DECLSPEC_HIDDEN
;
305 extern unsigned int get_localizedstrings_count(IDWriteLocalizedStrings
*strings
) DECLSPEC_HIDDEN
;
306 extern BOOL
localizedstrings_contains(IDWriteLocalizedStrings
*strings
, const WCHAR
*str
) DECLSPEC_HIDDEN
;
307 extern HRESULT
get_system_fontcollection(IDWriteFactory7
*factory
, IDWriteFontCollection1
**collection
) DECLSPEC_HIDDEN
;
308 extern HRESULT
get_eudc_fontcollection(IDWriteFactory7
*factory
, IDWriteFontCollection3
**collection
) DECLSPEC_HIDDEN
;
309 extern IDWriteTextAnalyzer2
*get_text_analyzer(void) DECLSPEC_HIDDEN
;
310 extern HRESULT
create_font_file(IDWriteFontFileLoader
*loader
, const void *reference_key
, UINT32 key_size
, IDWriteFontFile
**font_file
) DECLSPEC_HIDDEN
;
311 extern void init_local_fontfile_loader(void) DECLSPEC_HIDDEN
;
312 extern IDWriteFontFileLoader
*get_local_fontfile_loader(void) DECLSPEC_HIDDEN
;
313 extern HRESULT
create_fontface(const struct fontface_desc
*desc
, struct list
*cached_list
,
314 IDWriteFontFace5
**fontface
) DECLSPEC_HIDDEN
;
315 extern HRESULT
create_font_collection(IDWriteFactory7
*factory
, IDWriteFontFileEnumerator
*enumerator
, BOOL is_system
,
316 IDWriteFontCollection3
**collection
) DECLSPEC_HIDDEN
;
317 extern HRESULT
create_glyphrunanalysis(const struct glyphrunanalysis_desc
*,IDWriteGlyphRunAnalysis
**) DECLSPEC_HIDDEN
;
318 extern BOOL
is_system_collection(IDWriteFontCollection
*) DECLSPEC_HIDDEN
;
319 extern HRESULT
get_local_refkey(const WCHAR
*,const FILETIME
*,void**,UINT32
*) DECLSPEC_HIDDEN
;
320 extern HRESULT
get_filestream_from_file(IDWriteFontFile
*,IDWriteFontFileStream
**) DECLSPEC_HIDDEN
;
321 extern BOOL
is_face_type_supported(DWRITE_FONT_FACE_TYPE
) DECLSPEC_HIDDEN
;
322 extern HRESULT
get_family_names_from_stream(IDWriteFontFileStream
*,UINT32
,DWRITE_FONT_FACE_TYPE
,IDWriteLocalizedStrings
**) DECLSPEC_HIDDEN
;
323 extern HRESULT
create_colorglyphenum(FLOAT
,FLOAT
,const DWRITE_GLYPH_RUN
*,const DWRITE_GLYPH_RUN_DESCRIPTION
*,DWRITE_MEASURING_MODE
,
324 const DWRITE_MATRIX
*,UINT32
,IDWriteColorGlyphRunEnumerator
**) DECLSPEC_HIDDEN
;
325 extern BOOL
lb_is_newline_char(WCHAR
) DECLSPEC_HIDDEN
;
326 extern HRESULT
create_system_fontfallback(IDWriteFactory7
*factory
, IDWriteFontFallback1
**fallback
) DECLSPEC_HIDDEN
;
327 extern void release_system_fontfallback(IDWriteFontFallback1
*fallback
) DECLSPEC_HIDDEN
;
328 extern HRESULT
create_fontfallback_builder(IDWriteFactory7
*factory
, IDWriteFontFallbackBuilder
**builder
) DECLSPEC_HIDDEN
;
329 extern HRESULT
create_matching_font(IDWriteFontCollection
*,const WCHAR
*,DWRITE_FONT_WEIGHT
,DWRITE_FONT_STYLE
,DWRITE_FONT_STRETCH
,
330 IDWriteFont
**) DECLSPEC_HIDDEN
;
331 extern HRESULT
create_fontfacereference(IDWriteFactory7
*factory
, IDWriteFontFile
*file
, UINT32 face_index
,
332 DWRITE_FONT_SIMULATIONS simulations
, DWRITE_FONT_AXIS_VALUE
const *axis_values
, UINT32 axis_values_count
,
333 IDWriteFontFaceReference1
**reference
) DECLSPEC_HIDDEN
;
334 extern HRESULT
factory_get_cached_fontface(IDWriteFactory7
*factory
, IDWriteFontFile
* const *files
, UINT32 num_files
,
335 DWRITE_FONT_SIMULATIONS simulations
, struct list
**cache
, REFIID riid
, void **obj
) DECLSPEC_HIDDEN
;
336 extern void factory_detach_fontcollection(IDWriteFactory7
*factory
, IDWriteFontCollection3
*collection
) DECLSPEC_HIDDEN
;
337 extern void factory_detach_gdiinterop(IDWriteFactory7
*factory
, IDWriteGdiInterop1
*interop
) DECLSPEC_HIDDEN
;
338 extern struct fontfacecached
*factory_cache_fontface(IDWriteFactory7
*factory
, struct list
*fontfaces
,
339 IDWriteFontFace5
*fontface
) DECLSPEC_HIDDEN
;
340 extern void get_logfont_from_font(IDWriteFont
*,LOGFONTW
*) DECLSPEC_HIDDEN
;
341 extern void get_logfont_from_fontface(IDWriteFontFace
*,LOGFONTW
*) DECLSPEC_HIDDEN
;
342 extern HRESULT
get_fontsig_from_font(IDWriteFont
*,FONTSIGNATURE
*) DECLSPEC_HIDDEN
;
343 extern HRESULT
get_fontsig_from_fontface(IDWriteFontFace
*,FONTSIGNATURE
*) DECLSPEC_HIDDEN
;
344 extern HRESULT
create_gdiinterop(IDWriteFactory7
*factory
, IDWriteGdiInterop1
**interop
) DECLSPEC_HIDDEN
;
345 extern void fontface_detach_from_cache(IDWriteFontFace5
*fontface
) DECLSPEC_HIDDEN
;
346 extern void factory_lock(IDWriteFactory7
*factory
) DECLSPEC_HIDDEN
;
347 extern void factory_unlock(IDWriteFactory7
*factory
) DECLSPEC_HIDDEN
;
348 extern HRESULT
create_inmemory_fileloader(IDWriteInMemoryFontFileLoader
**loader
) DECLSPEC_HIDDEN
;
349 extern HRESULT
create_font_resource(IDWriteFactory7
*factory
, IDWriteFontFile
*file
, UINT32 face_index
,
350 IDWriteFontResource
**resource
) DECLSPEC_HIDDEN
;
351 extern HRESULT
create_fontset_builder(IDWriteFactory7
*factory
, IDWriteFontSetBuilder2
**ret
) DECLSPEC_HIDDEN
;
352 extern HRESULT
compute_glyph_origins(DWRITE_GLYPH_RUN
const *run
, DWRITE_MEASURING_MODE measuring_mode
,
353 D2D1_POINT_2F baseline_origin
, DWRITE_MATRIX
const *transform
, D2D1_POINT_2F
*origins
) DECLSPEC_HIDDEN
;
355 struct dwrite_fontface
;
357 extern float fontface_get_scaled_design_advance(struct dwrite_fontface
*fontface
, DWRITE_MEASURING_MODE measuring_mode
,
358 float emsize
, float ppdip
, const DWRITE_MATRIX
*transform
, UINT16 glyph
, BOOL is_sideways
) DECLSPEC_HIDDEN
;
359 extern struct dwrite_fontface
*unsafe_impl_from_IDWriteFontFace(IDWriteFontFace
*iface
) DECLSPEC_HIDDEN
;
361 /* Opentype font table functions */
362 struct dwrite_font_props
364 DWRITE_FONT_STYLE style
;
365 DWRITE_FONT_STRETCH stretch
;
366 DWRITE_FONT_WEIGHT weight
;
367 DWRITE_PANOSE panose
;
368 FONTSIGNATURE fontsig
;
373 struct file_stream_desc
{
374 IDWriteFontFileStream
*stream
;
375 DWRITE_FONT_FACE_TYPE face_type
;
379 extern const void* get_fontface_table(IDWriteFontFace5
*fontface
, UINT32 tag
,
380 struct dwrite_fonttable
*table
) DECLSPEC_HIDDEN
;
389 struct ot_gsubgpos_table
391 struct dwrite_fonttable table
;
392 unsigned int script_list
;
393 unsigned int feature_list
;
394 unsigned int lookup_list
;
397 extern HRESULT
opentype_analyze_font(IDWriteFontFileStream
*,BOOL
*,DWRITE_FONT_FILE_TYPE
*,DWRITE_FONT_FACE_TYPE
*,UINT32
*) DECLSPEC_HIDDEN
;
398 extern HRESULT
opentype_try_get_font_table(const struct file_stream_desc
*stream_desc
, UINT32 tag
, const void **data
,
399 void **context
, UINT32
*size
, BOOL
*exists
) DECLSPEC_HIDDEN
;
400 extern void opentype_get_font_properties(struct file_stream_desc
*,struct dwrite_font_props
*) DECLSPEC_HIDDEN
;
401 extern void opentype_get_font_metrics(struct file_stream_desc
*,DWRITE_FONT_METRICS1
*,DWRITE_CARET_METRICS
*) DECLSPEC_HIDDEN
;
402 extern void opentype_get_font_typo_metrics(struct file_stream_desc
*stream_desc
, unsigned int *ascent
,
403 unsigned int *descent
) DECLSPEC_HIDDEN
;
404 extern HRESULT
opentype_get_font_info_strings(const struct file_stream_desc
*stream_desc
,
405 DWRITE_INFORMATIONAL_STRING_ID id
, IDWriteLocalizedStrings
**strings
) DECLSPEC_HIDDEN
;
406 extern HRESULT
opentype_get_font_familyname(struct file_stream_desc
*,IDWriteLocalizedStrings
**) DECLSPEC_HIDDEN
;
407 extern HRESULT
opentype_get_font_facename(struct file_stream_desc
*,WCHAR
*,IDWriteLocalizedStrings
**) DECLSPEC_HIDDEN
;
408 extern void opentype_get_typographic_features(struct ot_gsubgpos_table
*table
, unsigned int script_index
,
409 unsigned int language_index
, struct tag_array
*tags
) DECLSPEC_HIDDEN
;
410 extern BOOL
opentype_get_vdmx_size(const struct dwrite_fonttable
*table
, INT ppem
, UINT16
*ascent
,
411 UINT16
*descent
) DECLSPEC_HIDDEN
;
412 extern unsigned int opentype_get_cpal_palettecount(const struct dwrite_fonttable
*table
) DECLSPEC_HIDDEN
;
413 extern unsigned int opentype_get_cpal_paletteentrycount(const struct dwrite_fonttable
*table
) DECLSPEC_HIDDEN
;
414 extern HRESULT
opentype_get_cpal_entries(const struct dwrite_fonttable
*table
, unsigned int palette
,
415 unsigned int first_entry_index
, unsigned int entry_count
, DWRITE_COLOR_F
*entries
) DECLSPEC_HIDDEN
;
416 extern UINT32
opentype_get_glyph_image_formats(IDWriteFontFace5
*fontface
) DECLSPEC_HIDDEN
;
417 extern DWRITE_CONTAINER_TYPE
opentype_analyze_container_type(void const *, UINT32
) DECLSPEC_HIDDEN
;
418 extern HRESULT
opentype_get_kerning_pairs(struct dwrite_fontface
*fontface
, unsigned int count
,
419 const UINT16
*glyphs
, INT32
*values
) DECLSPEC_HIDDEN
;
420 extern BOOL
opentype_has_kerning_pairs(struct dwrite_fontface
*fontface
) DECLSPEC_HIDDEN
;
422 struct dwrite_colorglyph
{
423 USHORT layer
; /* [0, num_layers) index indicating current layer */
424 /* base glyph record data, set once on initialization */
427 /* current layer record data, updated every time glyph is switched to next layer */
429 UINT16 palette_index
;
432 extern HRESULT
opentype_get_colr_glyph(const struct dwrite_fonttable
*table
, UINT16 glyph
,
433 struct dwrite_colorglyph
*color_glyph
) DECLSPEC_HIDDEN
;
434 extern void opentype_colr_next_glyph(const struct dwrite_fonttable
*table
,
435 struct dwrite_colorglyph
*color_glyph
) DECLSPEC_HIDDEN
;
438 GASP_GRIDFIT
= 0x0001,
439 GASP_DOGRAY
= 0x0002,
440 GASP_SYMMETRIC_GRIDFIT
= 0x0004,
441 GASP_SYMMETRIC_SMOOTHING
= 0x0008,
444 extern unsigned int opentype_get_gasp_flags(const struct dwrite_fonttable
*gasp
, float emsize
) DECLSPEC_HIDDEN
;
447 extern HRESULT
bidi_computelevels(const WCHAR
*,UINT32
,UINT8
,UINT8
*,UINT8
*) DECLSPEC_HIDDEN
;
449 struct dwrite_glyphbitmap
463 enum dwrite_outline_tags
465 OUTLINE_BEGIN_FIGURE
,
471 struct dwrite_outline
475 unsigned char *values
;
482 D2D1_POINT_2F
*values
;
492 SCRIPT_JUSTIFY_ARABIC_BLANK
,
493 SCRIPT_JUSTIFY_CHARACTER
,
494 SCRIPT_JUSTIFY_RESERVED1
,
495 SCRIPT_JUSTIFY_BLANK
,
496 SCRIPT_JUSTIFY_RESERVED2
,
497 SCRIPT_JUSTIFY_RESERVED3
,
498 SCRIPT_JUSTIFY_ARABIC_NORMAL
,
499 SCRIPT_JUSTIFY_ARABIC_KASHIDA
,
500 SCRIPT_JUSTIFY_ARABIC_ALEF
,
501 SCRIPT_JUSTIFY_ARABIC_HA
,
502 SCRIPT_JUSTIFY_ARABIC_RA
,
503 SCRIPT_JUSTIFY_ARABIC_BA
,
504 SCRIPT_JUSTIFY_ARABIC_BARA
,
505 SCRIPT_JUSTIFY_ARABIC_SEEN
,
506 SCRIPT_JUSTIFY_ARABIC_SEEN_M
509 struct scriptshaping_cache
511 const struct shaping_font_ops
*font
;
515 struct ot_gsubgpos_table gsub
;
516 struct ot_gsubgpos_table gpos
;
520 struct dwrite_fonttable table
;
521 unsigned int classdef
;
522 unsigned int markattachclassdef
;
523 unsigned int markglyphsetdef
;
527 struct shaping_glyph_info
529 /* Combined features mask. */
531 /* Derived from glyph class, supplied by GDEF. */
533 /* Used for GPOS mark and cursive attachments. */
535 /* Only relevant for isClusterStart glyphs. Indicates text position for this cluster. */
536 unsigned int start_text_idx
;
537 unsigned int codepoint
;
540 struct shaping_glyph_properties
542 UINT16 justification
: 4;
543 UINT16 isClusterStart
: 1;
544 UINT16 isDiacritic
: 1;
545 UINT16 isZeroWidthSpace
: 1;
547 UINT16 components
: 4;
548 UINT16 lig_component
: 4;
551 struct scriptshaping_context
;
553 typedef void (*p_apply_context_lookup
)(struct scriptshaping_context
*context
, unsigned int lookup_index
);
555 enum shaping_feature_flags
557 FEATURE_GLOBAL
= 0x1,
558 FEATURE_GLOBAL_SEARCH
= 0x2,
559 FEATURE_MANUAL_ZWNJ
= 0x4,
560 FEATURE_MANUAL_ZWJ
= 0x8,
561 FEATURE_MANUAL_JOINERS
= FEATURE_MANUAL_ZWNJ
| FEATURE_MANUAL_ZWJ
,
562 FEATURE_HAS_FALLBACK
= 0x10,
563 FEATURE_NEEDS_FALLBACK
= 0x20,
566 struct shaping_feature
571 unsigned int max_value
;
572 unsigned int default_value
;
578 #define MAX_SHAPING_STAGE 16
580 struct shaping_features
;
582 typedef void (*stage_func
)(struct scriptshaping_context
*context
,
583 const struct shaping_features
*features
);
588 unsigned int last_lookup
;
591 struct shaping_features
593 struct shaping_feature
*features
;
597 struct shaping_stage stages
[MAX_SHAPING_STAGE
];
602 void (*collect_features
)(struct scriptshaping_context
*context
, struct shaping_features
*features
);
603 void (*setup_masks
)(struct scriptshaping_context
*context
, const struct shaping_features
*features
);
606 extern const struct shaper arabic_shaper DECLSPEC_HIDDEN
;
608 extern void shape_enable_feature(struct shaping_features
*features
, unsigned int tag
,
609 unsigned int flags
) DECLSPEC_HIDDEN
;
610 extern void shape_add_feature_full(struct shaping_features
*features
, unsigned int tag
,
611 unsigned int flags
, unsigned int value
) DECLSPEC_HIDDEN
;
612 extern unsigned int shape_get_feature_1_mask(const struct shaping_features
*features
,
613 unsigned int tag
) DECLSPEC_HIDDEN
;
614 extern void shape_start_next_stage(struct shaping_features
*features
, stage_func func
) DECLSPEC_HIDDEN
;
616 struct scriptshaping_context
618 struct scriptshaping_cache
*cache
;
619 const struct shaper
*shaper
;
632 const UINT16
*glyphs
;
633 const DWRITE_SHAPING_GLYPH_PROPERTIES
*glyph_props
;
634 DWRITE_SHAPING_TEXT_PROPERTIES
*text_props
;
635 const UINT16
*clustermap
;
636 p_apply_context_lookup apply_context_lookup
;
641 DWRITE_SHAPING_GLYPH_PROPERTIES
*glyph_props
;
642 DWRITE_SHAPING_TEXT_PROPERTIES
*text_props
;
644 p_apply_context_lookup apply_context_lookup
;
645 unsigned int max_glyph_count
;
646 unsigned int capacity
;
652 struct shaping_glyph_properties
*glyph_props
;
653 DWRITE_SHAPING_TEXT_PROPERTIES
*text_props
;
655 p_apply_context_lookup apply_context_lookup
;
659 const struct ot_gsubgpos_table
*table
; /* Either GSUB or GPOS. */
662 const DWRITE_TYPOGRAPHIC_FEATURES
**features
;
663 const unsigned int *range_lengths
;
664 unsigned int range_count
;
666 unsigned int global_mask
;
667 unsigned int lookup_mask
; /* Currently processed feature mask, set in main loop. */
668 unsigned int auto_zwj
;
669 unsigned int auto_zwnj
;
670 struct shaping_glyph_info
*glyph_infos
;
671 unsigned int has_gpos_attachment
: 1;
674 unsigned int glyph_count
;
675 unsigned int nesting_level_left
;
678 DWRITE_MEASURING_MODE measuring_mode
;
680 DWRITE_GLYPH_OFFSET
*offsets
;
683 struct shaping_font_ops
685 void (*grab_font_table
)(void *context
, UINT32 table
, const BYTE
**data
, UINT32
*size
, void **data_context
);
686 void (*release_font_table
)(void *context
, void *data_context
);
687 UINT16 (*get_font_upem
)(void *context
);
688 BOOL (*has_glyph
)(void *context
, unsigned int codepoint
);
689 UINT16 (*get_glyph
)(void *context
, unsigned int codepoint
);
692 extern struct scriptshaping_cache
*create_scriptshaping_cache(void *context
,
693 const struct shaping_font_ops
*font_ops
) DECLSPEC_HIDDEN
;
694 extern void release_scriptshaping_cache(struct scriptshaping_cache
*) DECLSPEC_HIDDEN
;
695 extern struct scriptshaping_cache
*fontface_get_shaping_cache(struct dwrite_fontface
*fontface
) DECLSPEC_HIDDEN
;
697 extern void opentype_layout_scriptshaping_cache_init(struct scriptshaping_cache
*cache
) DECLSPEC_HIDDEN
;
698 extern DWORD
opentype_layout_find_script(const struct scriptshaping_cache
*cache
, DWORD kind
, DWORD tag
,
699 unsigned int *script_index
) DECLSPEC_HIDDEN
;
700 extern DWORD
opentype_layout_find_language(const struct scriptshaping_cache
*cache
, DWORD kind
, DWORD tag
,
701 unsigned int script_index
, unsigned int *language_index
) DECLSPEC_HIDDEN
;
702 extern void opentype_layout_apply_gsub_features(struct scriptshaping_context
*context
, unsigned int script_index
,
703 unsigned int language_index
, struct shaping_features
*features
) DECLSPEC_HIDDEN
;
704 extern void opentype_layout_apply_gpos_features(struct scriptshaping_context
*context
, unsigned int script_index
,
705 unsigned int language_index
, struct shaping_features
*features
) DECLSPEC_HIDDEN
;
706 extern BOOL
opentype_layout_check_feature(struct scriptshaping_context
*context
, unsigned int script_index
,
707 unsigned int language_index
, struct shaping_feature
*feature
, unsigned int glyph_count
,
708 const UINT16
*glyphs
, UINT8
*feature_applies
) DECLSPEC_HIDDEN
;
709 extern void opentype_layout_unsafe_to_break(struct scriptshaping_context
*context
, unsigned int start
,
710 unsigned int end
) DECLSPEC_HIDDEN
;
711 extern BOOL
opentype_has_vertical_variants(struct dwrite_fontface
*fontface
) DECLSPEC_HIDDEN
;
712 extern HRESULT
opentype_get_vertical_glyph_variants(struct dwrite_fontface
*fontface
, unsigned int glyph_count
,
713 const UINT16
*nominal_glyphs
, UINT16
*glyphs
) DECLSPEC_HIDDEN
;
715 extern HRESULT
shape_get_glyphs(struct scriptshaping_context
*context
, const unsigned int *scripts
) DECLSPEC_HIDDEN
;
716 extern HRESULT
shape_get_positions(struct scriptshaping_context
*context
, const unsigned int *scripts
) DECLSPEC_HIDDEN
;
717 extern HRESULT
shape_get_typographic_features(struct scriptshaping_context
*context
, const unsigned int *scripts
,
718 unsigned int max_tagcount
, unsigned int *actual_tagcount
, unsigned int *tags
) DECLSPEC_HIDDEN
;
719 extern HRESULT
shape_check_typographic_feature(struct scriptshaping_context
*context
, const unsigned int *scripts
,
720 unsigned int tag
, unsigned int glyph_count
, const UINT16
*glyphs
, UINT8
*feature_applies
) DECLSPEC_HIDDEN
;
722 struct font_data_context
;
723 extern HMODULE dwrite_module DECLSPEC_HIDDEN
;
725 struct font_callback_funcs
727 int (CDECL
*get_font_data
)(void *key
, const void **data_ptr
, UINT64
*data_size
, unsigned int *index
,
728 struct font_data_context
**context
);
729 void (CDECL
*release_font_data
)(struct font_data_context
*context
);
732 struct font_backend_funcs
734 void (CDECL
*notify_release
)(void *key
);
735 int (CDECL
*get_glyph_outline
)(void *key
, float em_size
, unsigned int simulations
, UINT16 glyph
,
736 struct dwrite_outline
*outline
);
737 UINT16 (CDECL
*get_glyph_count
)(void *key
);
738 INT32 (CDECL
*get_glyph_advance
)(void *key
, float em_size
, UINT16 index
, DWRITE_MEASURING_MODE measuring_mode
,
740 void (CDECL
*get_glyph_bbox
)(struct dwrite_glyphbitmap
*bitmap_desc
);
741 BOOL (CDECL
*get_glyph_bitmap
)(struct dwrite_glyphbitmap
*bitmap_desc
);
742 void (CDECL
*get_design_glyph_metrics
)(void *key
, UINT16 upem
, UINT16 ascent
, unsigned int simulations
,
743 UINT16 glyph
, DWRITE_GLYPH_METRICS
*metrics
);
746 extern void init_font_backend(void) DECLSPEC_HIDDEN
;
747 extern void release_font_backend(void) DECLSPEC_HIDDEN
;
749 extern void dwrite_fontface_get_glyph_bbox(struct dwrite_glyphbitmap
*bitmap
) DECLSPEC_HIDDEN
;