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 #pragma once
23
24 #include "wine/list.h"
25
26 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
27 ( ( (ULONG)_x4 << 24 ) | \
28 ( (ULONG)_x3 << 16 ) | \
29 ( (ULONG)_x2 << 8 ) | \
30 (ULONG)_x1 )
31
32 enum usp10_script
33 {
34 Script_Undefined = 0x00,
35 Script_Latin = 0x01,
36 Script_CR = 0x02,
37 Script_Numeric = 0x03,
38 Script_Control = 0x04,
39 Script_Punctuation = 0x05,
40 Script_Arabic = 0x06,
41 Script_Arabic_Numeric = 0x07,
42 Script_Hebrew = 0x08,
43 Script_Syriac = 0x09,
44 Script_Persian = 0x0a,
45 Script_Thaana = 0x0b,
46 Script_Greek = 0x0c,
47 Script_Cyrillic = 0x0d,
48 Script_Armenian = 0x0e,
49 Script_Georgian = 0x0f,
50 /* Unicode Chapter 10 */
51 Script_Sinhala = 0x10,
52 Script_Tibetan = 0x11,
53 Script_Tibetan_Numeric = 0x12,
54 Script_Phags_pa = 0x13,
55 /* Unicode Chapter 11 */
56 Script_Thai = 0x14,
57 Script_Thai_Numeric = 0x15,
58 Script_Lao = 0x16,
59 Script_Lao_Numeric = 0x17,
60 /* Unicode Chapter 9 */
61 Script_Devanagari = 0x18,
62 Script_Devanagari_Numeric = 0x19,
63 Script_Bengali = 0x1a,
64 Script_Bengali_Numeric = 0x1b,
65 Script_Bengali_Currency = 0x1c,
66 Script_Gurmukhi = 0x1d,
67 Script_Gurmukhi_Numeric = 0x1e,
68 Script_Gujarati = 0x1f,
69 Script_Gujarati_Numeric = 0x20,
70 Script_Gujarati_Currency = 0x21,
71 Script_Oriya = 0x22,
72 Script_Oriya_Numeric = 0x23,
73 Script_Tamil = 0x24,
74 Script_Tamil_Numeric = 0x25,
75 Script_Telugu = 0x26,
76 Script_Telugu_Numeric = 0x27,
77 Script_Kannada = 0x28,
78 Script_Kannada_Numeric = 0x29,
79 Script_Malayalam = 0x2a,
80 Script_Malayalam_Numeric = 0x2b,
81 /* More supplemental */
82 Script_Diacritical = 0x2c,
83 Script_Punctuation2 = 0x2d,
84 Script_Numeric2 = 0x2e,
85 /* Unicode Chapter 11 continued */
86 Script_Myanmar = 0x2f,
87 Script_Myanmar_Numeric = 0x30,
88 Script_Tai_Le = 0x31,
89 Script_New_Tai_Lue = 0x32,
90 Script_New_Tai_Lue_Numeric = 0x33,
91 Script_Khmer = 0x34,
92 Script_Khmer_Numeric = 0x35,
93 /* Unicode Chapter 12 */
94 Script_CJK_Han = 0x36,
95 Script_Ideograph = 0x37,
96 Script_Bopomofo = 0x38,
97 Script_Kana = 0x39,
98 Script_Hangul = 0x3a,
99 Script_Yi = 0x3b,
100 /* Unicode Chapter 13 */
101 Script_Ethiopic = 0x3c,
102 Script_Ethiopic_Numeric = 0x3d,
103 Script_Mongolian = 0x3e,
104 Script_Mongolian_Numeric = 0x3f,
105 Script_Tifinagh = 0x40,
106 Script_NKo = 0x41,
107 Script_Vai = 0x42,
108 Script_Vai_Numeric = 0x43,
109 Script_Cherokee = 0x44,
110 Script_Canadian = 0x45,
111 /* Unicode Chapter 14 */
112 Script_Ogham = 0x46,
113 Script_Runic = 0x47,
114 /* Unicode Chapter 15 */
115 Script_Braille = 0x48,
116 /* Unicode Chapter 16 */
117 Script_Surrogates = 0x49,
118 Script_Private = 0x4a,
119 /* Unicode Chapter 13 : Plane 1 */
120 Script_Deseret = 0x4b,
121 Script_Osmanya = 0x4c,
122 Script_Osmanya_Numeric = 0x4d,
123 /* Unicode Chapter 15 : Plane 1 */
124 Script_MathAlpha = 0x4e,
125 /* Additional Currency Scripts */
126 Script_Hebrew_Currency = 0x4f,
127 Script_Vietnamese_Currency = 0x50,
128 Script_Thai_Currency = 0x51,
129 };
130
131 #define GLYPH_BLOCK_SHIFT 8
132 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
133 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
134 #define GLYPH_MAX 65536
135
136 #define NUM_PAGES 17
137
138 #define GSUB_E_NOFEATURE -20
139 #define GSUB_E_NOGLYPH -10
140
141 #define FEATURE_ALL_TABLES 0
142 #define FEATURE_GSUB_TABLE 1
143 #define FEATURE_GPOS_TABLE 2
144
145 typedef struct {
146 OPENTYPE_TAG tag;
147 CHAR tableType;
148 const void *feature;
149 INT lookup_count;
150 WORD *lookups;
151 } LoadedFeature;
152
153 enum usp10_language_table
154 {
155 USP10_LANGUAGE_TABLE_GSUB = 0,
156 USP10_LANGUAGE_TABLE_GPOS,
157 USP10_LANGUAGE_TABLE_COUNT
158 };
159
160 typedef struct {
161 OPENTYPE_TAG tag;
162 const void *table[USP10_LANGUAGE_TABLE_COUNT];
163 BOOL features_initialized;
164 LoadedFeature *features;
165 SIZE_T features_size;
166 SIZE_T feature_count;
167 } LoadedLanguage;
168
169 enum usp10_script_table
170 {
171 USP10_SCRIPT_TABLE_GSUB = 0,
172 USP10_SCRIPT_TABLE_GPOS,
173 USP10_SCRIPT_TABLE_COUNT
174 };
175
176 typedef struct {
177 OPENTYPE_TAG tag;
178 const void *table[USP10_SCRIPT_TABLE_COUNT];
179 LoadedLanguage default_language;
180 BOOL languages_initialized;
181 LoadedLanguage *languages;
182 SIZE_T languages_size;
183 SIZE_T language_count;
184 } LoadedScript;
185
186 typedef struct {
187 WORD *glyphs[GLYPH_MAX / GLYPH_BLOCK_SIZE];
188 } CacheGlyphPage;
189
190 typedef struct {
191 struct list entry;
192 DWORD refcount;
193 LOGFONTW lf;
194 TEXTMETRICW tm;
195 OUTLINETEXTMETRICW *otm;
196 SCRIPT_FONTPROPERTIES sfp;
197 BOOL sfnt;
198 CacheGlyphPage *page[NUM_PAGES];
199 ABC *widths[GLYPH_MAX / GLYPH_BLOCK_SIZE];
200 void *GSUB_Table;
201 void *GDEF_Table;
202 void *CMAP_Table;
203 void *CMAP_format12_Table;
204 void *GPOS_Table;
205 BOOL scripts_initialized;
206 LoadedScript *scripts;
207 SIZE_T scripts_size;
208 SIZE_T script_count;
209
210 OPENTYPE_TAG userScript;
211 OPENTYPE_TAG userLang;
212 } ScriptCache;
213
214 typedef struct _scriptData
215 {
216 SCRIPT_ANALYSIS a;
217 SCRIPT_PROPERTIES props;
218 OPENTYPE_TAG scriptTag;
219 WCHAR fallbackFont[LF_FACESIZE];
220 } scriptData;
221
222 typedef struct {
223 INT start;
224 INT base;
225 INT ralf;
226 INT blwf;
227 INT pref;
228 INT end;
229 } IndicSyllable;
230
231 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};
232
is_consonant(int type)233 static inline BOOL is_consonant( int type )
234 {
235 return (type == lex_Ra || type == lex_Consonant);
236 }
237
get_table_entry(const unsigned short * table,WCHAR ch)238 static inline unsigned short get_table_entry( const unsigned short *table, WCHAR ch )
239 {
240 return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
241 }
242
243 typedef int (*lexical_function)(WCHAR c);
244 typedef void (*reorder_function)(WCHAR *chars, IndicSyllable *syllable, lexical_function lex);
245
246 #define odd(x) ((x) & 1)
247 #define BIDI_STRONG 1
248 #define BIDI_WEAK 2
249 #define BIDI_NEUTRAL 0
250
251 BOOL usp10_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
252 int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target) DECLSPEC_HIDDEN;
253
254 BOOL BIDI_DetermineLevels(const WCHAR *string, unsigned int count, const SCRIPT_STATE *s,
255 const SCRIPT_CONTROL *c, WORD *levels, WORD *overrides) DECLSPEC_HIDDEN;
256 BOOL BIDI_GetStrengths(const WCHAR *string, unsigned int count,
257 const SCRIPT_CONTROL *c, WORD *strength) DECLSPEC_HIDDEN;
258 INT BIDI_ReorderV2lLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
259 INT BIDI_ReorderL2vLevel(int level, int *pIndexs, const BYTE* plevel, int cch, BOOL fReverse) DECLSPEC_HIDDEN;
260 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust) DECLSPEC_HIDDEN;
261 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust) DECLSPEC_HIDDEN;
262 void SHAPE_ApplyOpenTypePositions(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WORD* pwGlyphs, INT cGlyphs, int *piAdvance, GOFFSET *pGoffset ) DECLSPEC_HIDDEN;
263 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa) DECLSPEC_HIDDEN;
264 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;
265 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;
266 HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
267 HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags) DECLSPEC_HIDDEN;
268 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;
269
270 void Indic_ReorderCharacters(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, WCHAR *input, unsigned int cChars,
271 IndicSyllable **syllables, int *syllable_count, lexical_function lexical_f,
272 reorder_function reorder_f, BOOL modern) DECLSPEC_HIDDEN;
273 void Indic_ParseSyllables(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache* psc, const WCHAR *input, unsigned int cChar,
274 IndicSyllable **syllables, int *syllable_count, lexical_function lex, BOOL modern) DECLSPEC_HIDDEN;
275
276 void BREAK_line(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la) DECLSPEC_HIDDEN;
277
278 DWORD OpenType_CMAP_GetGlyphIndex(HDC hdc, ScriptCache *psc, DWORD utf32c, LPWORD pgi, DWORD flags) DECLSPEC_HIDDEN;
279 void OpenType_GDEF_UpdateGlyphProps(ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, const WORD cChars, SCRIPT_GLYPHPROP *pGlyphProp) DECLSPEC_HIDDEN;
280 int OpenType_apply_GSUB_lookup(const void *table, unsigned int lookup_index, WORD *glyphs,
281 unsigned int glyph_index, int write_dir, int *glyph_count) DECLSPEC_HIDDEN;
282 unsigned int OpenType_apply_GPOS_lookup(const ScriptCache *psc, const OUTLINETEXTMETRICW *otm,
283 const LOGFONTW *logfont, const SCRIPT_ANALYSIS *analysis, int *advance, unsigned int lookup_index,
284 const WORD *glyphs, unsigned int glyph_index, unsigned int glyph_count, GOFFSET *goffset) DECLSPEC_HIDDEN;
285 HRESULT OpenType_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags) DECLSPEC_HIDDEN;
286 HRESULT OpenType_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags) DECLSPEC_HIDDEN;
287 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;
288