[NTOSKRNL] More asserts regarding reference count
[reactos.git] / dll / win32 / usp10 / usp10_internal.h
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
3 *
4 * Copyright 2010 CodeWeavers, Aric Stewart
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21
22 #ifndef _USP10_INTERNAL_H_
23 #define _USP10_INTERNAL_H_
24
25 #include <config.h>
26
27 #include <stdarg.h>
28
29 #define WIN32_NO_STATUS
30 #define _INC_WINDOWS
31 #define COM_NO_WINDOWS_H
32
33 #include <windef.h>
34 #include <winbase.h>
35 #include <wingdi.h>
36 #include <usp10.h>
37
38 #include <wine/debug.h>
39 #include <wine/unicode.h>
40 #include <wine/list.h>
41
42 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
43 ( ( (ULONG)_x4 << 24 ) | \
44 ( (ULONG)_x3 << 16 ) | \
45 ( (ULONG)_x2 << 8 ) | \
46 (ULONG)_x1 )
47
48 #ifndef ARRAY_SIZE
49 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
50 #endif
51
52 enum usp10_script
53 {
54 Script_Undefined = 0x00,
55 Script_Latin = 0x01,
56 Script_CR = 0x02,
57 Script_Numeric = 0x03,
58 Script_Control = 0x04,
59 Script_Punctuation = 0x05,
60 Script_Arabic = 0x06,
61 Script_Arabic_Numeric = 0x07,
62 Script_Hebrew = 0x08,
63 Script_Syriac = 0x09,
64 Script_Persian = 0x0a,
65 Script_Thaana = 0x0b,
66 Script_Greek = 0x0c,
67 Script_Cyrillic = 0x0d,
68 Script_Armenian = 0x0e,
69 Script_Georgian = 0x0f,
70 /* Unicode Chapter 10 */
71 Script_Sinhala = 0x10,
72 Script_Tibetan = 0x11,
73 Script_Tibetan_Numeric = 0x12,
74 Script_Phags_pa = 0x13,
75 /* Unicode Chapter 11 */
76 Script_Thai = 0x14,
77 Script_Thai_Numeric = 0x15,
78 Script_Lao = 0x16,
79 Script_Lao_Numeric = 0x17,
80 /* Unicode Chapter 9 */
81 Script_Devanagari = 0x18,
82 Script_Devanagari_Numeric = 0x19,
83 Script_Bengali = 0x1a,
84 Script_Bengali_Numeric = 0x1b,
85 Script_Bengali_Currency = 0x1c,
86 Script_Gurmukhi = 0x1d,
87 Script_Gurmukhi_Numeric = 0x1e,
88 Script_Gujarati = 0x1f,
89 Script_Gujarati_Numeric = 0x20,
90 Script_Gujarati_Currency = 0x21,
91 Script_Oriya = 0x22,
92 Script_Oriya_Numeric = 0x23,
93 Script_Tamil = 0x24,
94 Script_Tamil_Numeric = 0x25,
95 Script_Telugu = 0x26,
96 Script_Telugu_Numeric = 0x27,
97 Script_Kannada = 0x28,
98 Script_Kannada_Numeric = 0x29,
99 Script_Malayalam = 0x2a,
100 Script_Malayalam_Numeric = 0x2b,
101 /* More supplemental */
102 Script_Diacritical = 0x2c,
103 Script_Punctuation2 = 0x2d,
104 Script_Numeric2 = 0x2e,
105 /* Unicode Chapter 11 continued */
106 Script_Myanmar = 0x2f,
107 Script_Myanmar_Numeric = 0x30,
108 Script_Tai_Le = 0x31,
109 Script_New_Tai_Lue = 0x32,
110 Script_New_Tai_Lue_Numeric = 0x33,
111 Script_Khmer = 0x34,
112 Script_Khmer_Numeric = 0x35,
113 /* Unicode Chapter 12 */
114 Script_CJK_Han = 0x36,
115 Script_Ideograph = 0x37,
116 Script_Bopomofo = 0x38,
117 Script_Kana = 0x39,
118 Script_Hangul = 0x3a,
119 Script_Yi = 0x3b,
120 /* Unicode Chapter 13 */
121 Script_Ethiopic = 0x3c,
122 Script_Ethiopic_Numeric = 0x3d,
123 Script_Mongolian = 0x3e,
124 Script_Mongolian_Numeric = 0x3f,
125 Script_Tifinagh = 0x40,
126 Script_NKo = 0x41,
127 Script_Vai = 0x42,
128 Script_Vai_Numeric = 0x43,
129 Script_Cherokee = 0x44,
130 Script_Canadian = 0x45,
131 /* Unicode Chapter 14 */
132 Script_Ogham = 0x46,
133 Script_Runic = 0x47,
134 /* Unicode Chapter 15 */
135 Script_Braille = 0x48,
136 /* Unicode Chapter 16 */
137 Script_Surrogates = 0x49,
138 Script_Private = 0x4a,
139 /* Unicode Chapter 13 : Plane 1 */
140 Script_Deseret = 0x4b,
141 Script_Osmanya = 0x4c,
142 Script_Osmanya_Numeric = 0x4d,
143 /* Unicode Chapter 15 : Plane 1 */
144 Script_MathAlpha = 0x4e,
145 /* Additional Currency Scripts */
146 Script_Hebrew_Currency = 0x4f,
147 Script_Vietnamese_Currency = 0x50,
148 Script_Thai_Currency = 0x51,
149 };
150
151 #define GLYPH_BLOCK_SHIFT 8
152 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
153 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
154 #define GLYPH_MAX 65536
155
156 #define NUM_PAGES 17
157
158 #define GSUB_E_NOFEATURE -20
159 #define GSUB_E_NOGLYPH -10
160
161 #define FEATURE_ALL_TABLES 0
162 #define FEATURE_GSUB_TABLE 1
163 #define FEATURE_GPOS_TABLE 2
164
165 typedef struct {
166 OPENTYPE_TAG tag;
167 CHAR tableType;
168 const void *feature;
169 INT lookup_count;
170 WORD *lookups;
171 } LoadedFeature;
172
173 typedef struct {
174 OPENTYPE_TAG tag;
175 const void *gsub_table;
176 const void *gpos_table;
177 BOOL features_initialized;
178 INT feature_count;
179 LoadedFeature *features;
180 } LoadedLanguage;
181
182 typedef struct {
183 OPENTYPE_TAG tag;
184 const void *gsub_table;
185 const void *gpos_table;
186 LoadedLanguage default_language;
187 BOOL languages_initialized;
188 LoadedLanguage *languages;
189 SIZE_T languages_size;
190 SIZE_T language_count;
191 } LoadedScript;
192
193 typedef struct {
194 WORD *glyphs[GLYPH_MAX / GLYPH_BLOCK_SIZE];
195 } CacheGlyphPage;
196
197 typedef struct {
198 struct list entry;
199 DWORD refcount;
200 LOGFONTW lf;
201 TEXTMETRICW tm;
202 OUTLINETEXTMETRICW *otm;
203 SCRIPT_FONTPROPERTIES sfp;
204 BOOL sfnt;
205 CacheGlyphPage *page[NUM_PAGES];
206 ABC *widths[GLYPH_MAX / GLYPH_BLOCK_SIZE];
207 void *GSUB_Table;
208 void *GDEF_Table;
209 void *CMAP_Table;
210 void *CMAP_format12_Table;
211 void *GPOS_Table;
212 BOOL scripts_initialized;
213 LoadedScript *scripts;
214 SIZE_T scripts_size;
215 SIZE_T script_count;
216
217 OPENTYPE_TAG userScript;
218 OPENTYPE_TAG userLang;
219 } ScriptCache;
220
221 typedef struct _scriptData
222 {
223 SCRIPT_ANALYSIS a;
224 SCRIPT_PROPERTIES props;
225 OPENTYPE_TAG scriptTag;
226 WCHAR fallbackFont[LF_FACESIZE];
227 } scriptData;
228
229 typedef struct {
230 INT start;
231 INT base;
232 INT ralf;
233 INT blwf;
234 INT pref;
235 INT end;
236 } IndicSyllable;
237
238 enum {lex_Halant, lex_Composed_Vowel, lex_Matra_post, lex_Matra_pre, lex_Matra_above, lex_Matra_below, lex_ZWJ, lex_ZWNJ, lex_NBSP, lex_Modifier, lex_Vowel, lex_Consonant, lex_Generic, lex_Ra, lex_Vedic, lex_Anudatta, lex_Nukta};
239
240 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
241 {
242 return HeapAlloc(GetProcessHeap(), 0, size);
243 }
244
245 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
246 {
247 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
248 }
249
250 static inline BOOL heap_free(void *mem)
251 {
252 return HeapFree(GetProcessHeap(), 0, mem);
253 }
254
255 static inline BOOL is_consonant( int type )
256 {
257 return (type == lex_Ra || type == lex_Consonant);
258 }
259
260 static inline unsigned short get_table_entry( const unsigned short *table, WCHAR ch )
261 {
262 return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
263 }
264
265 typedef int (*lexical_function)(WCHAR c);
266 typedef void (*reorder_function)(WCHAR *chars, IndicSyllable *syllable, lexical_function lex);
267
268 #define odd(x) ((x) & 1)
269 #define BIDI_STRONG 1
270 #define BIDI_WEAK 2
271 #define BIDI_NEUTRAL 0
272
273 BOOL usp10_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
274 int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target) DECLSPEC_HIDDEN;
275
276 BOOL BIDI_DetermineLevels(const WCHAR *string, unsigned int count, const SCRIPT_STATE *s,
277 const SCRIPT_CONTROL *c, WORD *levels, WORD *overrides) DECLSPEC_HIDDEN;
278 BOOL BIDI_GetStrengths(const WCHAR *string, unsigned int count,
279 const SCRIPT_CONTROL *c, WORD *strength) DECLSPEC_HIDDEN;
280 INT BIDI_ReorderV2lLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
281 INT BIDI_ReorderL2vLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
282 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust) DECLSPEC_HIDDEN;
283 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust) DECLSPEC_HIDDEN;
284 void SHAPE_ApplyOpenTypePositions(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WORD* pwGlyphs, INT cGlyphs, int *piAdvance, GOFFSET *pGoffset ) DECLSPEC_HIDDEN;
285 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa) DECLSPEC_HIDDEN;
286 void SHAPE_CharGlyphProp(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp) DECLSPEC_HIDDEN;
287 INT SHAPE_does_GSUB_feature_apply_to_chars(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache* psc, const WCHAR *chars, INT write_dir, INT count, const char* feature) DECLSPEC_HIDDEN;
288 HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
289 HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags) DECLSPEC_HIDDEN;
290 HRESULT SHAPE_GetFontFeatureTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags) DECLSPEC_HIDDEN;
291
292 void Indic_ReorderCharacters(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, WCHAR *input, unsigned int cChars,
293 IndicSyllable **syllables, int *syllable_count, lexical_function lexical_f,
294 reorder_function reorder_f, BOOL modern) DECLSPEC_HIDDEN;
295 void Indic_ParseSyllables(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache* psc, const WCHAR *input, unsigned int cChar,
296 IndicSyllable **syllables, int *syllable_count, lexical_function lex, BOOL modern) DECLSPEC_HIDDEN;
297
298 void BREAK_line(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la) DECLSPEC_HIDDEN;
299
300 DWORD OpenType_CMAP_GetGlyphIndex(HDC hdc, ScriptCache *psc, DWORD utf32c, LPWORD pgi, DWORD flags) DECLSPEC_HIDDEN;
301 void OpenType_GDEF_UpdateGlyphProps(ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, const WORD cChars, SCRIPT_GLYPHPROP *pGlyphProp) DECLSPEC_HIDDEN;
302 int OpenType_apply_GSUB_lookup(const void *table, unsigned int lookup_index, WORD *glyphs,
303 unsigned int glyph_index, int write_dir, int *glyph_count) DECLSPEC_HIDDEN;
304 unsigned int OpenType_apply_GPOS_lookup(const ScriptCache *psc, const OUTLINETEXTMETRICW *otm,
305 const LOGFONTW *logfont, const SCRIPT_ANALYSIS *analysis, int *advance, unsigned int lookup_index,
306 const WORD *glyphs, unsigned int glyph_index, unsigned int glyph_count, GOFFSET *goffset) DECLSPEC_HIDDEN;
307 HRESULT OpenType_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
308 HRESULT OpenType_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags) DECLSPEC_HIDDEN;
309 HRESULT OpenType_GetFontFeatureTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG language_tag, BOOL filtered, OPENTYPE_TAG searchingFor, char tableType, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags, LoadedFeature** feature) DECLSPEC_HIDDEN;
310
311 #endif /* _USP10_INTERNAL_H_ */