wined3d: Use glFinish() for synchronisation when cleaning up a destroyed context...
[wine.git] / dlls / dwrite / dwrite_private.h
blob7c9fe8a6873893e7dd7193cbdf90039c69adec5d
1 /*
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
19 #include "dwrite_3.h"
20 #include "d2d1.h"
22 #include "wine/debug.h"
23 #include "wine/heap.h"
24 #include "wine/list.h"
25 #include "wine/unicode.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 =
32 1.0f, 0.0f,
33 0.0f, 1.0f,
34 0.0f, 0.0f
37 static inline LPWSTR heap_strdupW(const WCHAR *str)
39 LPWSTR ret = NULL;
41 if(str) {
42 DWORD size;
44 size = (strlenW(str)+1)*sizeof(WCHAR);
45 ret = heap_alloc(size);
46 if(ret)
47 memcpy(ret, str, size);
50 return ret;
53 static inline LPWSTR heap_strdupnW(const WCHAR *str, UINT32 len)
55 WCHAR *ret = NULL;
57 if (len)
59 ret = heap_alloc((len+1)*sizeof(WCHAR));
60 if(ret)
62 memcpy(ret, str, len*sizeof(WCHAR));
63 ret[len] = 0;
67 return ret;
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,
79 m->dx, m->dy);
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;
85 void *new_elements;
87 if (count <= *capacity)
88 return TRUE;
90 max_capacity = ~(SIZE_T)0 / size;
91 if (count > max_capacity)
92 return FALSE;
94 new_capacity = max(4, *capacity);
95 while (new_capacity < count && new_capacity <= max_capacity / 2)
96 new_capacity *= 2;
97 if (new_capacity < count)
98 new_capacity = max_capacity;
100 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
101 return FALSE;
103 *elements = new_elements;
104 *capacity = new_capacity;
106 return TRUE;
109 static inline const char *debugstr_tag(DWORD tag)
111 return debugstr_an((char *)&tag, 4);
114 const char *debugstr_sa_script(UINT16) DECLSPEC_HIDDEN;
116 static inline unsigned short get_table_entry(const unsigned short *table, WCHAR ch)
118 return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
121 static inline FLOAT get_scaled_advance_width(INT32 advance, FLOAT emSize, const DWRITE_FONT_METRICS *metrics)
123 return (FLOAT)advance * emSize / (FLOAT)metrics->designUnitsPerEm;
126 static inline BOOL is_simulation_valid(DWRITE_FONT_SIMULATIONS simulations)
128 return (simulations & ~(DWRITE_FONT_SIMULATIONS_NONE | DWRITE_FONT_SIMULATIONS_BOLD |
129 DWRITE_FONT_SIMULATIONS_OBLIQUE)) == 0;
132 struct textlayout_desc
134 IDWriteFactory7 *factory;
135 const WCHAR *string;
136 UINT32 length;
137 IDWriteTextFormat *format;
138 FLOAT max_width;
139 FLOAT max_height;
140 BOOL is_gdi_compatible;
141 /* fields below are only meaningful for gdi-compatible layout */
142 FLOAT ppdip;
143 const DWRITE_MATRIX *transform;
144 BOOL use_gdi_natural;
147 struct glyphrunanalysis_desc
149 const DWRITE_GLYPH_RUN *run;
150 const DWRITE_MATRIX *transform;
151 DWRITE_RENDERING_MODE1 rendering_mode;
152 DWRITE_MEASURING_MODE measuring_mode;
153 DWRITE_GRID_FIT_MODE gridfit_mode;
154 DWRITE_TEXT_ANTIALIAS_MODE aa_mode;
155 D2D_POINT_2F origin;
158 struct fontface_desc
160 IDWriteFactory7 *factory;
161 DWRITE_FONT_FACE_TYPE face_type;
162 IDWriteFontFile * const *files;
163 IDWriteFontFileStream *stream;
164 UINT32 files_number;
165 UINT32 index;
166 DWRITE_FONT_SIMULATIONS simulations;
167 struct dwrite_font_data *font_data; /* could be NULL when face is created directly with IDWriteFactory::CreateFontFace() */
170 struct dwrite_fonttable
172 const BYTE *data;
173 void *context;
174 UINT32 size;
175 BOOL exists;
178 struct fontfacecached
180 struct list entry;
181 IDWriteFontFace5 *fontface;
184 #define GLYPH_BLOCK_SHIFT 8
185 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
186 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
187 #define GLYPH_MAX 65536
189 enum font_flags
191 FONT_IS_SYMBOL = 1 << 0,
192 FONT_IS_MONOSPACED = 1 << 1,
193 FONT_IS_COLORED = 1 << 2, /* CPAL/COLR support */
194 FONTFACE_HAS_KERNING_PAIRS = 1 << 3,
195 FONTFACE_HAS_VERTICAL_VARIANTS = 1 << 4
198 struct dwrite_cmap;
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);
204 struct dwrite_cmap
206 const void *data;
207 union
209 struct
211 unsigned int seg_count;
212 unsigned int glyph_id_array_len;
214 const UINT16 *ends;
215 const UINT16 *starts;
216 const UINT16 *id_delta;
217 const UINT16 *id_range_offset;
218 const UINT16 *glyph_id_array;
219 } format4;
220 struct
222 unsigned int first;
223 unsigned int last;
224 } format6_10;
225 struct
227 unsigned int group_count;
228 } format12_13;
229 } u;
230 p_cmap_get_glyph_func get_glyph;
231 p_cmap_get_ranges_func get_ranges;
232 unsigned short symbol : 1;
233 IDWriteFontFileStream *stream;
234 void *table_context;
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;
248 LONG refcount;
250 IDWriteFontFileStream *stream;
251 IDWriteFontFile **files;
252 UINT32 file_count;
253 UINT32 index;
255 IDWriteFactory7 *factory;
256 struct fontfacecached *cached;
258 USHORT simulations;
259 DWRITE_FONT_FACE_TYPE type;
260 DWRITE_FONT_METRICS1 metrics;
261 DWRITE_CARET_METRICS caret;
262 struct
264 unsigned int ascent;
265 unsigned int descent;
266 } typo_metrics;
267 UINT32 flags;
269 struct dwrite_cmap cmap;
271 struct dwrite_fonttable vdmx;
272 struct dwrite_fonttable gasp;
273 struct dwrite_fonttable cpal;
274 struct dwrite_fonttable colr;
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;
290 LOGFONTW lf;
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 HRESULT get_system_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection1 **collection) DECLSPEC_HIDDEN;
306 extern HRESULT get_eudc_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection3 **collection) DECLSPEC_HIDDEN;
307 extern IDWriteTextAnalyzer *get_text_analyzer(void) DECLSPEC_HIDDEN;
308 extern HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_key, UINT32 key_size, IDWriteFontFile **font_file) DECLSPEC_HIDDEN;
309 extern void init_local_fontfile_loader(void) DECLSPEC_HIDDEN;
310 extern IDWriteFontFileLoader *get_local_fontfile_loader(void) DECLSPEC_HIDDEN;
311 extern HRESULT create_fontface(const struct fontface_desc *desc, struct list *cached_list,
312 IDWriteFontFace5 **fontface) DECLSPEC_HIDDEN;
313 extern HRESULT create_font_collection(IDWriteFactory7 *factory, IDWriteFontFileEnumerator *enumerator, BOOL is_system,
314 IDWriteFontCollection3 **collection) DECLSPEC_HIDDEN;
315 extern HRESULT create_glyphrunanalysis(const struct glyphrunanalysis_desc*,IDWriteGlyphRunAnalysis**) DECLSPEC_HIDDEN;
316 extern BOOL is_system_collection(IDWriteFontCollection*) DECLSPEC_HIDDEN;
317 extern HRESULT get_local_refkey(const WCHAR*,const FILETIME*,void**,UINT32*) DECLSPEC_HIDDEN;
318 extern HRESULT get_filestream_from_file(IDWriteFontFile*,IDWriteFontFileStream**) DECLSPEC_HIDDEN;
319 extern BOOL is_face_type_supported(DWRITE_FONT_FACE_TYPE) DECLSPEC_HIDDEN;
320 extern HRESULT get_family_names_from_stream(IDWriteFontFileStream*,UINT32,DWRITE_FONT_FACE_TYPE,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
321 extern HRESULT create_colorglyphenum(FLOAT,FLOAT,const DWRITE_GLYPH_RUN*,const DWRITE_GLYPH_RUN_DESCRIPTION*,DWRITE_MEASURING_MODE,
322 const DWRITE_MATRIX*,UINT32,IDWriteColorGlyphRunEnumerator**) DECLSPEC_HIDDEN;
323 extern BOOL lb_is_newline_char(WCHAR) DECLSPEC_HIDDEN;
324 extern HRESULT create_system_fontfallback(IDWriteFactory7 *factory, IDWriteFontFallback1 **fallback) DECLSPEC_HIDDEN;
325 extern void release_system_fontfallback(IDWriteFontFallback1 *fallback) DECLSPEC_HIDDEN;
326 extern HRESULT create_fontfallback_builder(IDWriteFactory7 *factory, IDWriteFontFallbackBuilder **builder) DECLSPEC_HIDDEN;
327 extern HRESULT create_matching_font(IDWriteFontCollection*,const WCHAR*,DWRITE_FONT_WEIGHT,DWRITE_FONT_STYLE,DWRITE_FONT_STRETCH,
328 IDWriteFont**) DECLSPEC_HIDDEN;
329 extern HRESULT create_fontfacereference(IDWriteFactory7 *factory, IDWriteFontFile *file, UINT32 face_index,
330 DWRITE_FONT_SIMULATIONS simulations, DWRITE_FONT_AXIS_VALUE const *axis_values, UINT32 axis_values_count,
331 IDWriteFontFaceReference1 **reference) DECLSPEC_HIDDEN;
332 extern HRESULT factory_get_cached_fontface(IDWriteFactory7 *factory, IDWriteFontFile * const *files, UINT32 num_files,
333 DWRITE_FONT_SIMULATIONS simulations, struct list **cache, REFIID riid, void **obj) DECLSPEC_HIDDEN;
334 extern void factory_detach_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection3 *collection) DECLSPEC_HIDDEN;
335 extern void factory_detach_gdiinterop(IDWriteFactory7 *factory, IDWriteGdiInterop1 *interop) DECLSPEC_HIDDEN;
336 extern struct fontfacecached *factory_cache_fontface(IDWriteFactory7 *factory, struct list *fontfaces,
337 IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
338 extern void get_logfont_from_font(IDWriteFont*,LOGFONTW*) DECLSPEC_HIDDEN;
339 extern void get_logfont_from_fontface(IDWriteFontFace*,LOGFONTW*) DECLSPEC_HIDDEN;
340 extern HRESULT get_fontsig_from_font(IDWriteFont*,FONTSIGNATURE*) DECLSPEC_HIDDEN;
341 extern HRESULT get_fontsig_from_fontface(IDWriteFontFace*,FONTSIGNATURE*) DECLSPEC_HIDDEN;
342 extern HRESULT create_gdiinterop(IDWriteFactory7 *factory, IDWriteGdiInterop1 **interop) DECLSPEC_HIDDEN;
343 extern void fontface_detach_from_cache(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
344 extern void factory_lock(IDWriteFactory7 *factory) DECLSPEC_HIDDEN;
345 extern void factory_unlock(IDWriteFactory7 *factory) DECLSPEC_HIDDEN;
346 extern HRESULT create_inmemory_fileloader(IDWriteInMemoryFontFileLoader **loader) DECLSPEC_HIDDEN;
347 extern HRESULT create_font_resource(IDWriteFactory7 *factory, IDWriteFontFile *file, UINT32 face_index,
348 IDWriteFontResource **resource) DECLSPEC_HIDDEN;
350 struct dwrite_fontface;
352 extern float fontface_get_scaled_design_advance(struct dwrite_fontface *fontface, DWRITE_MEASURING_MODE measuring_mode,
353 float emsize, float ppdip, const DWRITE_MATRIX *transform, UINT16 glyph, BOOL is_sideways) DECLSPEC_HIDDEN;
354 extern struct dwrite_fontface *unsafe_impl_from_IDWriteFontFace(IDWriteFontFace *iface) DECLSPEC_HIDDEN;
356 /* Opentype font table functions */
357 struct dwrite_font_props
359 DWRITE_FONT_STYLE style;
360 DWRITE_FONT_STRETCH stretch;
361 DWRITE_FONT_WEIGHT weight;
362 DWRITE_PANOSE panose;
363 FONTSIGNATURE fontsig;
364 LOGFONTW lf;
365 UINT32 flags;
368 struct file_stream_desc {
369 IDWriteFontFileStream *stream;
370 DWRITE_FONT_FACE_TYPE face_type;
371 UINT32 face_index;
374 extern const void* get_fontface_table(IDWriteFontFace5 *fontface, UINT32 tag,
375 struct dwrite_fonttable *table) DECLSPEC_HIDDEN;
377 struct tag_array
379 unsigned int *tags;
380 size_t capacity;
381 size_t count;
384 struct ot_gsubgpos_table
386 struct dwrite_fonttable table;
387 unsigned int script_list;
388 unsigned int feature_list;
389 unsigned int lookup_list;
392 extern HRESULT opentype_analyze_font(IDWriteFontFileStream*,BOOL*,DWRITE_FONT_FILE_TYPE*,DWRITE_FONT_FACE_TYPE*,UINT32*) DECLSPEC_HIDDEN;
393 extern HRESULT opentype_try_get_font_table(const struct file_stream_desc *stream_desc, UINT32 tag, const void **data,
394 void **context, UINT32 *size, BOOL *exists) DECLSPEC_HIDDEN;
395 extern void opentype_get_font_properties(struct file_stream_desc*,struct dwrite_font_props*) DECLSPEC_HIDDEN;
396 extern void opentype_get_font_metrics(struct file_stream_desc*,DWRITE_FONT_METRICS1*,DWRITE_CARET_METRICS*) DECLSPEC_HIDDEN;
397 extern void opentype_get_font_typo_metrics(struct file_stream_desc *stream_desc, unsigned int *ascent,
398 unsigned int *descent) DECLSPEC_HIDDEN;
399 extern HRESULT opentype_get_font_info_strings(const struct file_stream_desc *stream_desc,
400 DWRITE_INFORMATIONAL_STRING_ID id, IDWriteLocalizedStrings **strings) DECLSPEC_HIDDEN;
401 extern HRESULT opentype_get_font_familyname(struct file_stream_desc*,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
402 extern HRESULT opentype_get_font_facename(struct file_stream_desc*,WCHAR*,IDWriteLocalizedStrings**) DECLSPEC_HIDDEN;
403 extern void opentype_get_typographic_features(struct ot_gsubgpos_table *table, unsigned int script_index,
404 unsigned int language_index, struct tag_array *tags) DECLSPEC_HIDDEN;
405 extern BOOL opentype_get_vdmx_size(const struct dwrite_fonttable *table, INT ppem, UINT16 *ascent,
406 UINT16 *descent) DECLSPEC_HIDDEN;
407 extern unsigned int opentype_get_cpal_palettecount(const struct dwrite_fonttable *table) DECLSPEC_HIDDEN;
408 extern unsigned int opentype_get_cpal_paletteentrycount(const struct dwrite_fonttable *table) DECLSPEC_HIDDEN;
409 extern HRESULT opentype_get_cpal_entries(const struct dwrite_fonttable *table, unsigned int palette,
410 unsigned int first_entry_index, unsigned int entry_count, DWRITE_COLOR_F *entries) DECLSPEC_HIDDEN;
411 extern UINT32 opentype_get_glyph_image_formats(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
412 extern DWRITE_CONTAINER_TYPE opentype_analyze_container_type(void const *, UINT32) DECLSPEC_HIDDEN;
414 struct dwrite_colorglyph {
415 USHORT layer; /* [0, num_layers) index indicating current layer */
416 /* base glyph record data, set once on initialization */
417 USHORT first_layer;
418 USHORT num_layers;
419 /* current layer record data, updated every time glyph is switched to next layer */
420 UINT16 glyph;
421 UINT16 palette_index;
424 extern HRESULT opentype_get_colr_glyph(const struct dwrite_fonttable *table, UINT16 glyph,
425 struct dwrite_colorglyph *color_glyph) DECLSPEC_HIDDEN;
426 extern void opentype_colr_next_glyph(const struct dwrite_fonttable *table,
427 struct dwrite_colorglyph *color_glyph) DECLSPEC_HIDDEN;
429 enum gasp_flags {
430 GASP_GRIDFIT = 0x0001,
431 GASP_DOGRAY = 0x0002,
432 GASP_SYMMETRIC_GRIDFIT = 0x0004,
433 GASP_SYMMETRIC_SMOOTHING = 0x0008,
436 extern unsigned int opentype_get_gasp_flags(const struct dwrite_fonttable *gasp, float emsize) DECLSPEC_HIDDEN;
438 /* BiDi helpers */
439 extern HRESULT bidi_computelevels(const WCHAR*,UINT32,UINT8,UINT8*,UINT8*) DECLSPEC_HIDDEN;
441 /* FreeType integration */
442 struct dwrite_glyphbitmap
444 IDWriteFontFace4 *fontface;
445 DWORD simulations;
446 float emsize;
447 BOOL nohint;
448 BOOL aliased;
449 UINT16 glyph;
450 INT pitch;
451 RECT bbox;
452 BYTE *buf;
453 DWRITE_MATRIX *m;
456 extern BOOL init_freetype(void) DECLSPEC_HIDDEN;
457 extern void release_freetype(void) DECLSPEC_HIDDEN;
459 extern HRESULT freetype_get_design_glyph_metrics(struct dwrite_fontface *fontface, UINT16 glyph,
460 DWRITE_GLYPH_METRICS *metrics) DECLSPEC_HIDDEN;
461 extern void freetype_notify_cacheremove(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
462 extern HRESULT freetype_get_glyphrun_outline(IDWriteFontFace5 *fontface, float emsize, UINT16 const *glyphs,
463 float const *advances, DWRITE_GLYPH_OFFSET const *offsets, unsigned int count, BOOL is_rtl,
464 IDWriteGeometrySink *sink) DECLSPEC_HIDDEN;
465 extern UINT16 freetype_get_glyphcount(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
466 extern BOOL freetype_has_kerning_pairs(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
467 extern INT32 freetype_get_kerning_pair_adjustment(IDWriteFontFace5 *fontface, UINT16 left, UINT16 right) DECLSPEC_HIDDEN;
468 extern void freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap_desc) DECLSPEC_HIDDEN;
469 extern BOOL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap*) DECLSPEC_HIDDEN;
470 extern INT32 freetype_get_glyph_advance(IDWriteFontFace5 *fontface, FLOAT emsize, UINT16 index,
471 DWRITE_MEASURING_MODE measuring_mode, BOOL *has_contours) DECLSPEC_HIDDEN;
472 extern void freetype_get_design_glyph_bbox(IDWriteFontFace4*,UINT16,UINT16,RECT*) DECLSPEC_HIDDEN;
474 /* Glyph shaping */
475 enum SCRIPT_JUSTIFY
477 SCRIPT_JUSTIFY_NONE,
478 SCRIPT_JUSTIFY_ARABIC_BLANK,
479 SCRIPT_JUSTIFY_CHARACTER,
480 SCRIPT_JUSTIFY_RESERVED1,
481 SCRIPT_JUSTIFY_BLANK,
482 SCRIPT_JUSTIFY_RESERVED2,
483 SCRIPT_JUSTIFY_RESERVED3,
484 SCRIPT_JUSTIFY_ARABIC_NORMAL,
485 SCRIPT_JUSTIFY_ARABIC_KASHIDA,
486 SCRIPT_JUSTIFY_ARABIC_ALEF,
487 SCRIPT_JUSTIFY_ARABIC_HA,
488 SCRIPT_JUSTIFY_ARABIC_RA,
489 SCRIPT_JUSTIFY_ARABIC_BA,
490 SCRIPT_JUSTIFY_ARABIC_BARA,
491 SCRIPT_JUSTIFY_ARABIC_SEEN,
492 SCRIPT_JUSTIFY_ARABIC_SEEN_M
495 struct scriptshaping_cache
497 const struct shaping_font_ops *font;
498 void *context;
499 UINT16 upem;
501 struct ot_gsubgpos_table gsub;
502 struct ot_gsubgpos_table gpos;
504 struct
506 struct dwrite_fonttable table;
507 unsigned int classdef;
508 unsigned int markattachclassdef;
509 unsigned int markglyphsetdef;
510 } gdef;
513 struct shaping_glyph_info
515 /* Combined features mask. */
516 unsigned int mask;
517 /* Derived from glyph class, supplied by GDEF. */
518 unsigned int props;
519 /* Only relevant for isClusterStart glyphs. Indicates text position for this cluster. */
520 unsigned int start_text_idx;
523 struct shaping_glyph_properties
525 UINT16 justification : 4;
526 UINT16 isClusterStart : 1;
527 UINT16 isDiacritic : 1;
528 UINT16 isZeroWidthSpace : 1;
529 UINT16 reserved : 1;
530 UINT16 components : 4;
531 UINT16 lig_component : 4;
534 struct scriptshaping_context;
536 typedef void (*p_apply_context_lookup)(struct scriptshaping_context *context, unsigned int lookup_index);
538 struct scriptshaping_context
540 struct scriptshaping_cache *cache;
541 UINT32 language_tag;
543 const WCHAR *text;
544 unsigned int length;
545 BOOL is_rtl;
546 BOOL is_sideways;
548 union
550 struct
552 const UINT16 *glyphs;
553 const DWRITE_SHAPING_GLYPH_PROPERTIES *glyph_props;
554 DWRITE_SHAPING_TEXT_PROPERTIES *text_props;
555 const UINT16 *clustermap;
556 p_apply_context_lookup apply_context_lookup;
557 } pos;
558 struct
560 UINT16 *glyphs;
561 DWRITE_SHAPING_GLYPH_PROPERTIES *glyph_props;
562 DWRITE_SHAPING_TEXT_PROPERTIES *text_props;
563 UINT16 *clustermap;
564 p_apply_context_lookup apply_context_lookup;
565 unsigned int max_glyph_count;
566 unsigned int capacity;
567 const WCHAR *digits;
568 } subst;
569 struct
571 UINT16 *glyphs;
572 struct shaping_glyph_properties *glyph_props;
573 DWRITE_SHAPING_TEXT_PROPERTIES *text_props;
574 UINT16 *clustermap;
575 p_apply_context_lookup apply_context_lookup;
576 } buffer;
577 } u;
579 const struct ot_gsubgpos_table *table; /* Either GSUB or GPOS. */
580 struct
582 const DWRITE_TYPOGRAPHIC_FEATURES **features;
583 const unsigned int *range_lengths;
584 unsigned int range_count;
585 } user_features;
586 unsigned int global_mask;
587 unsigned int lookup_mask; /* Currently processed feature mask, set in main loop. */
588 struct shaping_glyph_info *glyph_infos;
590 unsigned int cur;
591 unsigned int glyph_count;
592 unsigned int nesting_level_left;
594 float emsize;
595 DWRITE_MEASURING_MODE measuring_mode;
596 float *advances;
597 DWRITE_GLYPH_OFFSET *offsets;
600 struct shaping_font_ops
602 void (*grab_font_table)(void *context, UINT32 table, const BYTE **data, UINT32 *size, void **data_context);
603 void (*release_font_table)(void *context, void *data_context);
604 UINT16 (*get_font_upem)(void *context);
605 BOOL (*has_glyph)(void *context, unsigned int codepoint);
606 UINT16 (*get_glyph)(void *context, unsigned int codepoint);
609 extern struct scriptshaping_cache *create_scriptshaping_cache(void *context,
610 const struct shaping_font_ops *font_ops) DECLSPEC_HIDDEN;
611 extern void release_scriptshaping_cache(struct scriptshaping_cache*) DECLSPEC_HIDDEN;
612 extern struct scriptshaping_cache *fontface_get_shaping_cache(struct dwrite_fontface *fontface) DECLSPEC_HIDDEN;
614 enum shaping_feature_flags
616 FEATURE_GLOBAL = 0x1,
617 FEATURE_GLOBAL_SEARCH = 0x2,
620 struct shaping_feature
622 unsigned int tag;
623 unsigned int index;
624 unsigned int flags;
625 unsigned int max_value;
626 unsigned int default_value;
627 unsigned int mask;
628 unsigned int shift;
629 unsigned int stage;
632 struct shaping_features
634 struct shaping_feature *features;
635 size_t count;
636 size_t capacity;
637 unsigned int stage;
640 extern void opentype_layout_scriptshaping_cache_init(struct scriptshaping_cache *cache) DECLSPEC_HIDDEN;
641 extern DWORD opentype_layout_find_script(const struct scriptshaping_cache *cache, DWORD kind, DWORD tag,
642 unsigned int *script_index) DECLSPEC_HIDDEN;
643 extern DWORD opentype_layout_find_language(const struct scriptshaping_cache *cache, DWORD kind, DWORD tag,
644 unsigned int script_index, unsigned int *language_index) DECLSPEC_HIDDEN;
645 extern void opentype_layout_apply_gsub_features(struct scriptshaping_context *context, unsigned int script_index,
646 unsigned int language_index, const struct shaping_features *features) DECLSPEC_HIDDEN;
647 extern void opentype_layout_apply_gpos_features(struct scriptshaping_context *context, unsigned int script_index,
648 unsigned int language_index, const struct shaping_features *features) DECLSPEC_HIDDEN;
649 extern BOOL opentype_layout_check_feature(struct scriptshaping_context *context, unsigned int script_index,
650 unsigned int language_index, struct shaping_feature *feature, unsigned int glyph_count,
651 const UINT16 *glyphs, UINT8 *feature_applies) DECLSPEC_HIDDEN;
652 extern BOOL opentype_has_vertical_variants(struct dwrite_fontface *fontface) DECLSPEC_HIDDEN;
653 extern HRESULT opentype_get_vertical_glyph_variants(struct dwrite_fontface *fontface, unsigned int glyph_count,
654 const UINT16 *nominal_glyphs, UINT16 *glyphs) DECLSPEC_HIDDEN;
656 extern HRESULT shape_get_glyphs(struct scriptshaping_context *context, const unsigned int *scripts) DECLSPEC_HIDDEN;
657 extern HRESULT shape_get_positions(struct scriptshaping_context *context, const unsigned int *scripts) DECLSPEC_HIDDEN;
658 extern HRESULT shape_get_typographic_features(struct scriptshaping_context *context, const unsigned int *scripts,
659 unsigned int max_tagcount, unsigned int *actual_tagcount, unsigned int *tags) DECLSPEC_HIDDEN;
660 extern HRESULT shape_check_typographic_feature(struct scriptshaping_context *context, const unsigned int *scripts,
661 unsigned int tag, unsigned int glyph_count, const UINT16 *glyphs, UINT8 *feature_applies) DECLSPEC_HIDDEN;