f56d2a09096ac443dcaa9580a863b25a328360d0
[reactos.git] / reactos / dll / win32 / usp10 / usp10.c
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
3 *
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 *
22 * Notes:
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
25 */
26
27 #include "usp10_internal.h"
28
29 #include <math.h>
30 #include <winuser.h>
31 #include <winreg.h>
32
33 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
34
35 typedef struct _scriptRange
36 {
37 WORD script;
38 DWORD rangeFirst;
39 DWORD rangeLast;
40 WORD numericScript;
41 WORD punctScript;
42 } scriptRange;
43
44 static const scriptRange scriptRanges[] = {
45 /* Basic Latin: U+0000–U+007A */
46 { Script_Latin, 0x00, 0x07a , Script_Numeric, Script_Punctuation},
47 /* Latin-1 Supplement: U+0080–U+00FF */
48 /* Latin Extended-A: U+0100–U+017F */
49 /* Latin Extended-B: U+0180–U+024F */
50 /* IPA Extensions: U+0250–U+02AF */
51 /* Spacing Modifier Letters:U+02B0–U+02FF */
52 { Script_Latin, 0x80, 0x2ff , Script_Numeric2, Script_Punctuation},
53 /* Combining Diacritical Marks : U+0300–U+036F */
54 { Script_Diacritical,0x300, 0x36f, 0, 0},
55 /* Greek: U+0370–U+03FF */
56 { Script_Greek, 0x370, 0x3ff, 0, 0},
57 /* Cyrillic: U+0400–U+04FF */
58 /* Cyrillic Supplement: U+0500–U+052F */
59 { Script_Cyrillic, 0x400, 0x52f, 0, 0},
60 /* Armenian: U+0530–U+058F */
61 { Script_Armenian, 0x530, 0x58f, 0, 0},
62 /* Hebrew: U+0590–U+05FF */
63 { Script_Hebrew, 0x590, 0x5ff, 0, 0},
64 /* Arabic: U+0600–U+06FF */
65 { Script_Arabic, 0x600, 0x6ef, Script_Arabic_Numeric, 0},
66 /* Defined by Windows */
67 { Script_Persian, 0x6f0, 0x6f9, 0, 0},
68 /* Continue Arabic: U+0600–U+06FF */
69 { Script_Arabic, 0x6fa, 0x6ff, 0, 0},
70 /* Syriac: U+0700–U+074F*/
71 { Script_Syriac, 0x700, 0x74f, 0, 0},
72 /* Arabic Supplement: U+0750–U+077F */
73 { Script_Arabic, 0x750, 0x77f, 0, 0},
74 /* Thaana: U+0780–U+07BF */
75 { Script_Thaana, 0x780, 0x7bf, 0, 0},
76 /* N’Ko: U+07C0–U+07FF */
77 { Script_NKo, 0x7c0, 0x7ff, 0, 0},
78 /* Devanagari: U+0900–U+097F */
79 { Script_Devanagari, 0x900, 0x97f, Script_Devanagari_Numeric, 0},
80 /* Bengali: U+0980–U+09FF */
81 { Script_Bengali, 0x980, 0x9ff, Script_Bengali_Numeric, 0},
82 /* Gurmukhi: U+0A00–U+0A7F*/
83 { Script_Gurmukhi, 0xa00, 0xa7f, Script_Gurmukhi_Numeric, 0},
84 /* Gujarati: U+0A80–U+0AFF*/
85 { Script_Gujarati, 0xa80, 0xaff, Script_Gujarati_Numeric, 0},
86 /* Oriya: U+0B00–U+0B7F */
87 { Script_Oriya, 0xb00, 0xb7f, Script_Oriya_Numeric, 0},
88 /* Tamil: U+0B80–U+0BFF */
89 { Script_Tamil, 0xb80, 0xbff, Script_Tamil_Numeric, 0},
90 /* Telugu: U+0C00–U+0C7F */
91 { Script_Telugu, 0xc00, 0xc7f, Script_Telugu_Numeric, 0},
92 /* Kannada: U+0C80–U+0CFF */
93 { Script_Kannada, 0xc80, 0xcff, Script_Kannada_Numeric, 0},
94 /* Malayalam: U+0D00–U+0D7F */
95 { Script_Malayalam, 0xd00, 0xd7f, Script_Malayalam_Numeric, 0},
96 /* Sinhala: U+0D80–U+0DFF */
97 { Script_Sinhala, 0xd80, 0xdff, 0, 0},
98 /* Thai: U+0E00–U+0E7F */
99 { Script_Thai, 0xe00, 0xe7f, Script_Thai_Numeric, 0},
100 /* Lao: U+0E80–U+0EFF */
101 { Script_Lao, 0xe80, 0xeff, Script_Lao_Numeric, 0},
102 /* Tibetan: U+0F00–U+0FFF */
103 { Script_Tibetan, 0xf00, 0xfff, 0, 0},
104 /* Myanmar: U+1000–U+109F */
105 { Script_Myanmar, 0x1000, 0x109f, Script_Myanmar_Numeric, 0},
106 /* Georgian: U+10A0–U+10FF */
107 { Script_Georgian, 0x10a0, 0x10ff, 0, 0},
108 /* Hangul Jamo: U+1100–U+11FF */
109 { Script_Hangul, 0x1100, 0x11ff, 0, 0},
110 /* Ethiopic: U+1200–U+137F */
111 /* Ethiopic Extensions: U+1380–U+139F */
112 { Script_Ethiopic, 0x1200, 0x139f, 0, 0},
113 /* Cherokee: U+13A0–U+13FF */
114 { Script_Cherokee, 0x13a0, 0x13ff, 0, 0},
115 /* Canadian Aboriginal Syllabics: U+1400–U+167F */
116 { Script_Canadian, 0x1400, 0x167f, 0, 0},
117 /* Ogham: U+1680–U+169F */
118 { Script_Ogham, 0x1680, 0x169f, 0, 0},
119 /* Runic: U+16A0–U+16F0 */
120 { Script_Runic, 0x16a0, 0x16f0, 0, 0},
121 /* Khmer: U+1780–U+17FF */
122 { Script_Khmer, 0x1780, 0x17ff, Script_Khmer_Numeric, 0},
123 /* Mongolian: U+1800–U+18AF */
124 { Script_Mongolian, 0x1800, 0x18af, Script_Mongolian_Numeric, 0},
125 /* Canadian Aboriginal Syllabics Extended: U+18B0–U+18FF */
126 { Script_Canadian, 0x18b0, 0x18ff, 0, 0},
127 /* Tai Le: U+1950–U+197F */
128 { Script_Tai_Le, 0x1950, 0x197f, 0, 0},
129 /* New Tai Lue: U+1980–U+19DF */
130 { Script_New_Tai_Lue,0x1980, 0x19df, Script_New_Tai_Lue_Numeric, 0},
131 /* Khmer Symbols: U+19E0–U+19FF */
132 { Script_Khmer, 0x19e0, 0x19ff, Script_Khmer_Numeric, 0},
133 /* Vedic Extensions: U+1CD0-U+1CFF */
134 { Script_Devanagari, 0x1cd0, 0x1cff, Script_Devanagari_Numeric, 0},
135 /* Phonetic Extensions: U+1D00–U+1DBF */
136 { Script_Latin, 0x1d00, 0x1dbf, 0, 0},
137 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
138 { Script_Diacritical,0x1dc0, 0x1dff, 0, 0},
139 /* Latin Extended Additional: U+1E00–U+1EFF */
140 { Script_Latin, 0x1e00, 0x1eff, 0, 0},
141 /* Greek Extended: U+1F00–U+1FFF */
142 { Script_Greek, 0x1f00, 0x1fff, 0, 0},
143 /* General Punctuation: U+2000 –U+206f */
144 { Script_Latin, 0x2000, 0x206f, 0, 0},
145 /* Superscripts and Subscripts : U+2070 –U+209f */
146 /* Currency Symbols : U+20a0 –U+20cf */
147 { Script_Numeric2, 0x2070, 0x2070, 0, 0},
148 { Script_Latin, 0x2071, 0x2073, 0, 0},
149 { Script_Numeric2, 0x2074, 0x2079, 0, 0},
150 { Script_Latin, 0x207a, 0x207f, 0, 0},
151 { Script_Numeric2, 0x2080, 0x2089, 0, 0},
152 { Script_Latin, 0x208a, 0x20cf, 0, 0},
153 /* Letterlike Symbols : U+2100 –U+214f */
154 /* Number Forms : U+2150 –U+218f */
155 /* Arrows : U+2190 –U+21ff */
156 /* Mathematical Operators : U+2200 –U+22ff */
157 /* Miscellaneous Technical : U+2300 –U+23ff */
158 /* Control Pictures : U+2400 –U+243f */
159 /* Optical Character Recognition : U+2440 –U+245f */
160 /* Enclosed Alphanumerics : U+2460 –U+24ff */
161 /* Box Drawing : U+2500 –U+25ff */
162 /* Block Elements : U+2580 –U+259f */
163 /* Geometric Shapes : U+25a0 –U+25ff */
164 /* Miscellaneous Symbols : U+2600 –U+26ff */
165 /* Dingbats : U+2700 –U+27bf */
166 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
167 /* Supplemental Arrows-A : U+27f0 –U+27ff */
168 { Script_Latin, 0x2100, 0x27ff, 0, 0},
169 /* Braille Patterns: U+2800–U+28FF */
170 { Script_Braille, 0x2800, 0x28ff, 0, 0},
171 /* Supplemental Arrows-B : U+2900 –U+297f */
172 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
173 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
174 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
175 { Script_Latin, 0x2900, 0x2bff, 0, 0},
176 /* Latin Extended-C: U+2C60–U+2C7F */
177 { Script_Latin, 0x2c60, 0x2c7f, 0, 0},
178 /* Georgian: U+2D00–U+2D2F */
179 { Script_Georgian, 0x2d00, 0x2d2f, 0, 0},
180 /* Tifinagh: U+2D30–U+2D7F */
181 { Script_Tifinagh, 0x2d30, 0x2d7f, 0, 0},
182 /* Ethiopic Extensions: U+2D80–U+2DDF */
183 { Script_Ethiopic, 0x2d80, 0x2ddf, 0, 0},
184 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
185 { Script_Cyrillic, 0x2de0, 0x2dff, 0, 0},
186 /* CJK Radicals Supplement: U+2E80–U+2EFF */
187 /* Kangxi Radicals: U+2F00–U+2FDF */
188 { Script_CJK_Han, 0x2e80, 0x2fdf, 0, 0},
189 /* Ideographic Description Characters: U+2FF0–U+2FFF */
190 { Script_Ideograph ,0x2ff0, 0x2fff, 0, 0},
191 /* CJK Symbols and Punctuation: U+3000–U+303F */
192 { Script_Ideograph ,0x3000, 0x3004, 0, 0},
193 { Script_CJK_Han ,0x3005, 0x3005, 0, 0},
194 { Script_Ideograph ,0x3006, 0x3006, 0, 0},
195 { Script_CJK_Han ,0x3007, 0x3007, 0, 0},
196 { Script_Ideograph ,0x3008, 0x3020, 0, 0},
197 { Script_CJK_Han ,0x3021, 0x3029, 0, 0},
198 { Script_Ideograph ,0x302a, 0x3030, 0, 0},
199 /* Kana Marks: */
200 { Script_Kana ,0x3031, 0x3035, 0, 0},
201 { Script_Ideograph ,0x3036, 0x3037, 0, 0},
202 { Script_CJK_Han ,0x3038, 0x303b, 0, 0},
203 { Script_Ideograph ,0x303c, 0x303f, 0, 0},
204 /* Hiragana: U+3040–U+309F */
205 /* Katakana: U+30A0–U+30FF */
206 { Script_Kana ,0x3040, 0x30ff, 0, 0},
207 /* Bopomofo: U+3100–U+312F */
208 { Script_Bopomofo ,0x3100, 0x312f, 0, 0},
209 /* Hangul Compatibility Jamo: U+3130–U+318F */
210 { Script_Hangul ,0x3130, 0x318f, 0, 0},
211 /* Kanbun: U+3190–U+319F */
212 { Script_Ideograph ,0x3190, 0x319f, 0, 0},
213 /* Bopomofo Extended: U+31A0–U+31BF */
214 { Script_Bopomofo ,0x31a0, 0x31bf, 0, 0},
215 /* CJK Strokes: U+31C0–U+31EF */
216 { Script_Ideograph ,0x31c0, 0x31ef, 0, 0},
217 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
218 { Script_Kana ,0x31f0, 0x31ff, 0, 0},
219 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
220 { Script_Hangul ,0x3200, 0x321f, 0, 0},
221 { Script_Ideograph ,0x3220, 0x325f, 0, 0},
222 { Script_Hangul ,0x3260, 0x327f, 0, 0},
223 { Script_Ideograph ,0x3280, 0x32ef, 0, 0},
224 { Script_Kana ,0x32d0, 0x31ff, 0, 0},
225 /* CJK Compatibility: U+3300–U+33FF*/
226 { Script_Kana ,0x3300, 0x3357, 0, 0},
227 { Script_Ideograph ,0x3358, 0x33ff, 0, 0},
228 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
229 { Script_CJK_Han ,0x3400, 0x4dbf, 0, 0},
230 /* CJK Unified Ideographs: U+4E00–U+9FFF */
231 { Script_CJK_Han ,0x4e00, 0x9fff, 0, 0},
232 /* Yi: U+A000–U+A4CF */
233 { Script_Yi ,0xa000, 0xa4cf, 0, 0},
234 /* Vai: U+A500–U+A63F */
235 { Script_Vai ,0xa500, 0xa63f, Script_Vai_Numeric, 0},
236 /* Cyrillic Extended-B: U+A640–U+A69F */
237 { Script_Cyrillic, 0xa640, 0xa69f, 0, 0},
238 /* Modifier Tone Letters: U+A700–U+A71F */
239 /* Latin Extended-D: U+A720–U+A7FF */
240 { Script_Latin, 0xa700, 0xa7ff, 0, 0},
241 /* Phags-pa: U+A840–U+A87F */
242 { Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
243 /* Devanagari Extended: U+A8E0-U+A8FF */
244 { Script_Devanagari, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric, 0},
245 /* Myanmar Extended-A: U+AA60–U+AA7F */
246 { Script_Myanmar, 0xaa60, 0xaa7f, Script_Myanmar_Numeric, 0},
247 /* Hangul Jamo Extended-A: U+A960–U+A97F */
248 { Script_Hangul, 0xa960, 0xa97f, 0, 0},
249 /* Hangul Syllables: U+AC00–U+D7A3 */
250 { Script_Hangul, 0xac00, 0xd7a3, 0, 0},
251 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
252 { Script_Hangul, 0xd7b0, 0xd7ff, 0, 0},
253 /* Surrogates Area: U+D800–U+DFFF */
254 { Script_Surrogates, 0xd800, 0xdbfe, 0, 0},
255 { Script_Private, 0xdbff, 0xdc00, 0, 0},
256 { Script_Surrogates, 0xdc01, 0xdfff, 0, 0},
257 /* Private Use Area: U+E000–U+F8FF */
258 { Script_Private, 0xe000, 0xf8ff, 0, 0},
259 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
260 { Script_CJK_Han ,0xf900, 0xfaff, 0, 0},
261 /* Latin Ligatures: U+FB00–U+FB06 */
262 { Script_Latin, 0xfb00, 0xfb06, 0, 0},
263 /* Armenian ligatures U+FB13..U+FB17 */
264 { Script_Armenian, 0xfb13, 0xfb17, 0, 0},
265 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
266 { Script_Hebrew, 0xfb1d, 0xfb4f, 0, 0},
267 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
268 { Script_Arabic, 0xfb50, 0xfdff, 0, 0},
269 /* Vertical Forms: U+FE10–U+FE1F */
270 /* Combining Half Marks: U+FE20–U+FE2F */
271 /* CJK Compatibility Forms: U+FE30–U+FE4F */
272 /* Small Form Variants: U+FE50–U+FE6F */
273 { Script_Ideograph ,0xfe10, 0xfe6f, 0, 0},
274 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
275 { Script_Arabic, 0xfe70, 0xfeff, 0, 0},
276 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
277 { Script_Ideograph ,0xff00, 0xff64, Script_Numeric2, 0},
278 { Script_Kana ,0xff65, 0xff9f, 0, 0},
279 { Script_Hangul ,0xffa0, 0xffdf, 0, 0},
280 { Script_Ideograph ,0xffe0, 0xffef, 0, 0},
281 /* Plane - 1 */
282 /* Deseret: U+10400–U+1044F */
283 { Script_Deseret, 0x10400, 0x1044F, 0, 0},
284 /* Osmanya: U+10480–U+104AF */
285 { Script_Osmanya, 0x10480, 0x104AF, Script_Osmanya_Numeric, 0},
286 /* Mathematical Alphanumeric Symbols: U+1D400–U+1D7FF */
287 { Script_MathAlpha, 0x1D400, 0x1D7FF, 0, 0},
288 /* END */
289 { SCRIPT_UNDEFINED, 0, 0, 0}
290 };
291
292 /* this must be in order so that the index matches the Script value */
293 const scriptData scriptInformation[] = {
294 {{SCRIPT_UNDEFINED, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
295 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
296 0x00000000,
297 {0}},
298 {{Script_Latin, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
299 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
300 MS_MAKE_TAG('l','a','t','n'),
301 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
302 {{Script_CR, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
303 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
304 0x00000000,
305 {0}},
306 {{Script_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
307 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
308 0x00000000,
309 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
310 {{Script_Control, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
311 {LANG_ENGLISH, 0, 1, 0, 0, ANSI_CHARSET, 1, 0, 0, 0, 0, 0, 1, 0, 0},
312 0x00000000,
313 {0}},
314 {{Script_Punctuation, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
315 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
316 0x00000000,
317 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
318 {{Script_Arabic, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
319 {LANG_ARABIC, 0, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 1, 0},
320 MS_MAKE_TAG('a','r','a','b'),
321 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
322 {{Script_Arabic_Numeric, 0, 1, 0, 0, 0, 0, { 2,0,0,0,0,0,0,0,0,0,0}},
323 {LANG_ARABIC, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
324 MS_MAKE_TAG('a','r','a','b'),
325 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
326 {{Script_Hebrew, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
327 {LANG_HEBREW, 0, 1, 0, 1, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
328 MS_MAKE_TAG('h','e','b','r'),
329 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
330 {{Script_Syriac, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
331 {LANG_SYRIAC, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 1, 0},
332 MS_MAKE_TAG('s','y','r','c'),
333 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
334 {{Script_Persian, 0, 1, 0, 0, 0, 0, { 2,0,0,0,0,0,0,0,0,0,0}},
335 {LANG_PERSIAN, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
336 MS_MAKE_TAG('a','r','a','b'),
337 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
338 {{Script_Thaana, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
339 {LANG_DIVEHI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
340 MS_MAKE_TAG('t','h','a','a'),
341 {'M','V',' ','B','o','l','i',0}},
342 {{Script_Greek, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
343 {LANG_GREEK, 0, 0, 0, 0, GREEK_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
344 MS_MAKE_TAG('g','r','e','k'),
345 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
346 {{Script_Cyrillic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
347 {LANG_RUSSIAN, 0, 0, 0, 0, RUSSIAN_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
348 MS_MAKE_TAG('c','y','r','l'),
349 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
350 {{Script_Armenian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
351 {LANG_ARMENIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
352 MS_MAKE_TAG('a','r','m','n'),
353 {'S','y','l','f','a','e','n',0}},
354 {{Script_Georgian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
355 {LANG_GEORGIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
356 MS_MAKE_TAG('g','e','o','r'),
357 {'S','y','l','f','a','e','n',0}},
358 {{Script_Sinhala, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
359 {LANG_SINHALESE, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
360 MS_MAKE_TAG('s','i','n','h'),
361 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
362 {{Script_Tibetan, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
363 {LANG_TIBETAN, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
364 MS_MAKE_TAG('t','i','b','t'),
365 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
366 {{Script_Tibetan_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
367 {LANG_TIBETAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
368 MS_MAKE_TAG('t','i','b','t'),
369 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
370 {{Script_Phags_pa, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
371 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
372 MS_MAKE_TAG('p','h','a','g'),
373 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
374 {{Script_Thai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
375 {LANG_THAI, 0, 1, 1, 1, THAI_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 1},
376 MS_MAKE_TAG('t','h','a','i'),
377 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
378 {{Script_Thai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
379 {LANG_THAI, 1, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
380 MS_MAKE_TAG('t','h','a','i'),
381 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
382 {{Script_Lao, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
383 {LANG_LAO, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
384 MS_MAKE_TAG('l','a','o',' '),
385 {'D','o','k','C','h','a','m','p','a',0}},
386 {{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
387 {LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
388 MS_MAKE_TAG('l','a','o',' '),
389 {'D','o','k','C','h','a','m','p','a',0}},
390 {{Script_Devanagari, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
391 {LANG_HINDI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
392 MS_MAKE_TAG('d','e','v','a'),
393 {'M','a','n','g','a','l',0}},
394 {{Script_Devanagari_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
395 {LANG_HINDI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
396 MS_MAKE_TAG('d','e','v','a'),
397 {'M','a','n','g','a','l',0}},
398 {{Script_Bengali, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
399 {LANG_BENGALI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
400 MS_MAKE_TAG('b','e','n','g'),
401 {'V','r','i','n','d','a',0}},
402 {{Script_Bengali_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
403 {LANG_BENGALI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
404 MS_MAKE_TAG('b','e','n','g'),
405 {'V','r','i','n','d','a',0}},
406 {{Script_Bengali_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
407 {LANG_BENGALI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
408 MS_MAKE_TAG('b','e','n','g'),
409 {'V','r','i','n','d','a',0}},
410 {{Script_Gurmukhi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
411 {LANG_PUNJABI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
412 MS_MAKE_TAG('g','u','r','u'),
413 {'R','a','a','v','i',0}},
414 {{Script_Gurmukhi_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
415 {LANG_PUNJABI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
416 MS_MAKE_TAG('g','u','r','u'),
417 {'R','a','a','v','i',0}},
418 {{Script_Gujarati, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
419 {LANG_GUJARATI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
420 MS_MAKE_TAG('g','u','j','r'),
421 {'S','h','r','u','t','i',0}},
422 {{Script_Gujarati_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
423 {LANG_GUJARATI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
424 MS_MAKE_TAG('g','u','j','r'),
425 {'S','h','r','u','t','i',0}},
426 {{Script_Gujarati_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
427 {LANG_GUJARATI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
428 MS_MAKE_TAG('g','u','j','r'),
429 {'S','h','r','u','t','i',0}},
430 {{Script_Oriya, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
431 {LANG_ORIYA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
432 MS_MAKE_TAG('o','r','y','a'),
433 {'K','a','l','i','n','g','a',0}},
434 {{Script_Oriya_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
435 {LANG_ORIYA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
436 MS_MAKE_TAG('o','r','y','a'),
437 {'K','a','l','i','n','g','a',0}},
438 {{Script_Tamil, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
439 {LANG_TAMIL, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
440 MS_MAKE_TAG('t','a','m','l'),
441 {'L','a','t','h','a',0}},
442 {{Script_Tamil_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
443 {LANG_TAMIL, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
444 MS_MAKE_TAG('t','a','m','l'),
445 {'L','a','t','h','a',0}},
446 {{Script_Telugu, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
447 {LANG_TELUGU, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
448 MS_MAKE_TAG('t','e','l','u'),
449 {'G','a','u','t','a','m','i',0}},
450 {{Script_Telugu_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
451 {LANG_TELUGU, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
452 MS_MAKE_TAG('t','e','l','u'),
453 {'G','a','u','t','a','m','i',0}},
454 {{Script_Kannada, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
455 {LANG_KANNADA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
456 MS_MAKE_TAG('k','n','d','a'),
457 {'T','u','n','g','a',0}},
458 {{Script_Kannada_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
459 {LANG_KANNADA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
460 MS_MAKE_TAG('k','n','d','a'),
461 {'T','u','n','g','a',0}},
462 {{Script_Malayalam, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
463 {LANG_MALAYALAM, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
464 MS_MAKE_TAG('m','l','y','m'),
465 {'K','a','r','t','i','k','a',0}},
466 {{Script_Malayalam_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
467 {LANG_MALAYALAM, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
468 MS_MAKE_TAG('m','l','y','m'),
469 {'K','a','r','t','i','k','a',0}},
470 {{Script_Diacritical, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
471 {LANG_ENGLISH, 0, 1, 0, 1, ANSI_CHARSET, 0, 0, 0, 0, 0, 1, 1, 0, 0},
472 0x00000000,
473 {0}},
474 {{Script_Punctuation2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
475 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
476 MS_MAKE_TAG('l','a','t','n'),
477 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
478 {{Script_Numeric2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
479 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
480 0x00000000,
481 {0}},
482 {{Script_Myanmar, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
483 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
484 MS_MAKE_TAG('m','y','m','r'),
485 {'M','y','a','n','m','a','r',' ','T','e','x','t',0}},
486 {{Script_Myanmar_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
487 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
488 MS_MAKE_TAG('m','y','m','r'),
489 {0}},
490 {{Script_Tai_Le, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
491 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
492 MS_MAKE_TAG('t','a','l','e'),
493 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e',0}},
494 {{Script_New_Tai_Lue, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
495 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
496 MS_MAKE_TAG('t','a','l','u'),
497 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e',0}},
498 {{Script_New_Tai_Lue_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
499 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
500 MS_MAKE_TAG('t','a','l','u'),
501 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e',0}},
502 {{Script_Khmer, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
503 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
504 MS_MAKE_TAG('k','h','m','r'),
505 {'D','a','u','n','P','e','n','h',0}},
506 {{Script_Khmer_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
507 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
508 MS_MAKE_TAG('k','h','m','r'),
509 {'D','a','u','n','P','e','n','h',0}},
510 {{Script_CJK_Han, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
511 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
512 MS_MAKE_TAG('h','a','n','i'),
513 {0}},
514 {{Script_Ideograph, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
515 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
516 MS_MAKE_TAG('h','a','n','i'),
517 {0}},
518 {{Script_Bopomofo, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
519 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
520 MS_MAKE_TAG('b','o','p','o'),
521 {0}},
522 {{Script_Kana, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
523 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
524 MS_MAKE_TAG('k','a','n','a'),
525 {0}},
526 {{Script_Hangul, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
527 {LANG_KOREAN, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
528 MS_MAKE_TAG('h','a','n','g'),
529 {0}},
530 {{Script_Yi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
531 {LANG_ENGLISH, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
532 MS_MAKE_TAG('y','i',' ',' '),
533 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i',0}},
534 {{Script_Ethiopic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
535 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
536 MS_MAKE_TAG('e','t','h','i'),
537 {'N','y','a','l','a',0}},
538 {{Script_Ethiopic_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
539 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
540 MS_MAKE_TAG('e','t','h','i'),
541 {'N','y','a','l','a',0}},
542 {{Script_Mongolian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
543 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
544 MS_MAKE_TAG('m','o','n','g'),
545 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i',0}},
546 {{Script_Mongolian_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
547 {LANG_MONGOLIAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
548 MS_MAKE_TAG('m','o','n','g'),
549 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i',0}},
550 {{Script_Tifinagh, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
551 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
552 MS_MAKE_TAG('t','f','n','g'),
553 {'E','b','r','i','m','a',0}},
554 {{Script_NKo, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
555 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
556 MS_MAKE_TAG('n','k','o',' '),
557 {'E','b','r','i','m','a',0}},
558 {{Script_Vai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
559 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
560 MS_MAKE_TAG('v','a','i',' '),
561 {'E','b','r','i','m','a',0}},
562 {{Script_Vai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
563 {0, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
564 MS_MAKE_TAG('v','a','i',' '),
565 {'E','b','r','i','m','a',0}},
566 {{Script_Cherokee, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
567 {0x5c, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
568 MS_MAKE_TAG('c','h','e','r'),
569 {'P','l','a','n','t','a','g','e','n','e','t',' ','C','h','e','r','o','k','e','e',0}},
570 {{Script_Canadian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
571 {0x5d, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
572 MS_MAKE_TAG('c','a','n','s'),
573 {'E','u','p','h','e','m','i','a',0}},
574 {{Script_Ogham, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
575 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
576 MS_MAKE_TAG('o','g','a','m'),
577 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l',0}},
578 {{Script_Runic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
579 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
580 MS_MAKE_TAG('r','u','n','r'),
581 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l',0}},
582 {{Script_Braille, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
583 {LANG_ENGLISH, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
584 MS_MAKE_TAG('b','r','a','i'),
585 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l',0}},
586 {{Script_Surrogates, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
587 {LANG_ENGLISH, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
588 0x00000000,
589 {0}},
590 {{Script_Private, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
591 {0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 1, 0, 0, 0, 0, 1, 0, 0},
592 0x00000000,
593 {0}},
594 {{Script_Deseret, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
595 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
596 MS_MAKE_TAG('d','s','r','t'),
597 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l',0}},
598 {{Script_Osmanya, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
599 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
600 MS_MAKE_TAG('o','s','m','a'),
601 {'E','b','r','i','m','a',0}},
602 {{Script_Osmanya_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
603 {0, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
604 MS_MAKE_TAG('o','s','m','a'),
605 {'E','b','r','i','m','a',0}},
606 {{Script_MathAlpha, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
607 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
608 MS_MAKE_TAG('m','a','t','h'),
609 {'C','a','m','b','r','i','a',' ','M','a','t','h',0}},
610 {{Script_Hebrew_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
611 {LANG_HEBREW, 0, 1, 0, 0, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
612 MS_MAKE_TAG('h','e','b','r'),
613 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
614 {{Script_Vietnamese_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
615 {LANG_VIETNAMESE, 0, 0, 0, 0, VIETNAMESE_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
616 MS_MAKE_TAG('l','a','t','n'),
617 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
618 {{Script_Thai_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
619 {LANG_THAI, 0, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
620 MS_MAKE_TAG('t','h','a','i'),
621 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
622 };
623
624 static const SCRIPT_PROPERTIES *script_props[] =
625 {
626 &scriptInformation[0].props, &scriptInformation[1].props,
627 &scriptInformation[2].props, &scriptInformation[3].props,
628 &scriptInformation[4].props, &scriptInformation[5].props,
629 &scriptInformation[6].props, &scriptInformation[7].props,
630 &scriptInformation[8].props, &scriptInformation[9].props,
631 &scriptInformation[10].props, &scriptInformation[11].props,
632 &scriptInformation[12].props, &scriptInformation[13].props,
633 &scriptInformation[14].props, &scriptInformation[15].props,
634 &scriptInformation[16].props, &scriptInformation[17].props,
635 &scriptInformation[18].props, &scriptInformation[19].props,
636 &scriptInformation[20].props, &scriptInformation[21].props,
637 &scriptInformation[22].props, &scriptInformation[23].props,
638 &scriptInformation[24].props, &scriptInformation[25].props,
639 &scriptInformation[26].props, &scriptInformation[27].props,
640 &scriptInformation[28].props, &scriptInformation[29].props,
641 &scriptInformation[30].props, &scriptInformation[31].props,
642 &scriptInformation[32].props, &scriptInformation[33].props,
643 &scriptInformation[34].props, &scriptInformation[35].props,
644 &scriptInformation[36].props, &scriptInformation[37].props,
645 &scriptInformation[38].props, &scriptInformation[39].props,
646 &scriptInformation[40].props, &scriptInformation[41].props,
647 &scriptInformation[42].props, &scriptInformation[43].props,
648 &scriptInformation[44].props, &scriptInformation[45].props,
649 &scriptInformation[46].props, &scriptInformation[47].props,
650 &scriptInformation[48].props, &scriptInformation[49].props,
651 &scriptInformation[50].props, &scriptInformation[51].props,
652 &scriptInformation[52].props, &scriptInformation[53].props,
653 &scriptInformation[54].props, &scriptInformation[55].props,
654 &scriptInformation[56].props, &scriptInformation[57].props,
655 &scriptInformation[58].props, &scriptInformation[59].props,
656 &scriptInformation[60].props, &scriptInformation[61].props,
657 &scriptInformation[62].props, &scriptInformation[63].props,
658 &scriptInformation[64].props, &scriptInformation[65].props,
659 &scriptInformation[66].props, &scriptInformation[67].props,
660 &scriptInformation[68].props, &scriptInformation[69].props,
661 &scriptInformation[70].props, &scriptInformation[71].props,
662 &scriptInformation[72].props, &scriptInformation[73].props,
663 &scriptInformation[74].props, &scriptInformation[75].props,
664 &scriptInformation[76].props, &scriptInformation[77].props,
665 &scriptInformation[78].props, &scriptInformation[79].props,
666 &scriptInformation[80].props, &scriptInformation[81].props
667 };
668
669 typedef struct {
670 ScriptCache *sc;
671 int numGlyphs;
672 WORD* glyphs;
673 WORD* pwLogClust;
674 int* piAdvance;
675 SCRIPT_VISATTR* psva;
676 GOFFSET* pGoffset;
677 ABC* abc;
678 int iMaxPosX;
679 HFONT fallbackFont;
680 } StringGlyphs;
681
682 typedef struct {
683 HDC hdc;
684 DWORD dwFlags;
685 BOOL invalid;
686 int clip_len;
687 int cItems;
688 int cMaxGlyphs;
689 SCRIPT_ITEM* pItem;
690 int numItems;
691 StringGlyphs* glyphs;
692 SCRIPT_LOGATTR* logattrs;
693 SIZE* sz;
694 int* logical2visual;
695 } StringAnalysis;
696
697 typedef struct {
698 BOOL ascending;
699 WORD target;
700 } FindGlyph_struct;
701
702 static inline void *heap_alloc(SIZE_T size)
703 {
704 return HeapAlloc(GetProcessHeap(), 0, size);
705 }
706
707 static inline void *heap_alloc_zero(SIZE_T size)
708 {
709 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
710 }
711
712 static inline BOOL heap_free(LPVOID mem)
713 {
714 return HeapFree(GetProcessHeap(), 0, mem);
715 }
716
717 /* TODO Fix font properties on Arabic locale */
718 static inline BOOL set_cache_font_properties(const HDC hdc, ScriptCache *sc)
719 {
720 if (!sc->sfnt)
721 {
722 sc->sfp.wgBlank = sc->tm.tmBreakChar;
723 sc->sfp.wgDefault = sc->tm.tmDefaultChar;
724 sc->sfp.wgInvalid = sc->sfp.wgBlank;
725 sc->sfp.wgKashida = 0xFFFF;
726 sc->sfp.iKashidaWidth = 0;
727 }
728 else
729 {
730 static const WCHAR chars[4] = {0x0020, 0x200B, 0xF71B, 0x0640};
731 /* U+0020: numeric space
732 U+200B: zero width space
733 U+F71B: unknown char found by black box testing
734 U+0640: kashida */
735 WORD gi[4];
736
737 if (GetGlyphIndicesW(hdc, chars, 4, gi, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR)
738 {
739 if(gi[0] != 0xFFFF) /* 0xFFFF: index of default non exist char */
740 sc->sfp.wgBlank = gi[0];
741 else
742 sc->sfp.wgBlank = 0;
743
744 sc->sfp.wgDefault = 0;
745
746 if (gi[2] != 0xFFFF)
747 sc->sfp.wgInvalid = gi[2];
748 else if (gi[1] != 0xFFFF)
749 sc->sfp.wgInvalid = gi[1];
750 else if (gi[0] != 0xFFFF)
751 sc->sfp.wgInvalid = gi[0];
752 else
753 sc->sfp.wgInvalid = 0;
754
755 sc->sfp.wgKashida = gi[3];
756
757 sc->sfp.iKashidaWidth = 0; /* TODO */
758 }
759 else
760 return FALSE;
761 }
762 return TRUE;
763 }
764
765 static inline void get_cache_font_properties(SCRIPT_FONTPROPERTIES *sfp, ScriptCache *sc)
766 {
767 sfp->wgBlank = sc->sfp.wgBlank;
768 sfp->wgDefault = sc->sfp.wgDefault;
769 sfp->wgInvalid = sc->sfp.wgInvalid;
770 sfp->wgKashida = sc->sfp.wgKashida;
771 sfp->iKashidaWidth = sc->sfp.iKashidaWidth;
772 }
773
774 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
775 {
776 return ((ScriptCache *)*psc)->tm.tmHeight;
777 }
778
779 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
780 {
781 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
782 }
783
784 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, DWORD c)
785 {
786 CacheGlyphPage *page = ((ScriptCache *)*psc)->page[c / 0x10000];
787 WORD *block;
788
789 if (!page) return 0;
790 block = page->glyphs[(c % 0x10000) >> GLYPH_BLOCK_SHIFT];
791 if (!block) return 0;
792 return block[(c % 0x10000) & GLYPH_BLOCK_MASK];
793 }
794
795 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
796 {
797 CacheGlyphPage **page = &((ScriptCache *)*psc)->page[c / 0x10000];
798 WORD **block;
799 if (!*page && !(*page = heap_alloc_zero(sizeof(CacheGlyphPage)))) return 0;
800
801 block = &(*page)->glyphs[(c % 0x10000) >> GLYPH_BLOCK_SHIFT];
802 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
803 return ((*block)[(c % 0x10000) & GLYPH_BLOCK_MASK] = glyph);
804 }
805
806 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
807 {
808 static const ABC nil;
809 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
810
811 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
812 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
813 return TRUE;
814 }
815
816 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
817 {
818 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
819
820 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
821 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
822 return TRUE;
823 }
824
825 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
826 {
827 ScriptCache *sc;
828 int size;
829
830 if (!psc) return E_INVALIDARG;
831 if (*psc) return S_OK;
832 if (!hdc) return E_PENDING;
833
834 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
835 if (!GetTextMetricsW(hdc, &sc->tm))
836 {
837 heap_free(sc);
838 return E_INVALIDARG;
839 }
840 size = GetOutlineTextMetricsW(hdc, 0, NULL);
841 if (size)
842 {
843 sc->otm = heap_alloc(size);
844 sc->otm->otmSize = size;
845 GetOutlineTextMetricsW(hdc, size, sc->otm);
846 }
847 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
848 {
849 heap_free(sc);
850 return E_INVALIDARG;
851 }
852 sc->sfnt = (GetFontData(hdc, MS_MAKE_TAG('h','e','a','d'), 0, NULL, 0)!=GDI_ERROR);
853 if (!set_cache_font_properties(hdc, sc))
854 {
855 heap_free(sc);
856 return E_INVALIDARG;
857 }
858 *psc = sc;
859 TRACE("<- %p\n", sc);
860 return S_OK;
861 }
862
863 static WCHAR mirror_char( WCHAR ch )
864 {
865 extern const WCHAR wine_mirror_map[] DECLSPEC_HIDDEN;
866 return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)];
867 }
868
869 static inline DWORD decode_surrogate_pair(LPCWSTR str, INT index, INT end)
870 {
871 if (index < end-1 && IS_SURROGATE_PAIR(str[index],str[index+1]))
872 {
873 DWORD ch = 0x10000 + ((str[index] - 0xd800) << 10) + (str[index+1] - 0xdc00);
874 TRACE("Surrogate Pair %x %x => %x\n",str[index], str[index+1], ch);
875 return ch;
876 }
877 return 0;
878 }
879
880 static WORD get_char_script( LPCWSTR str, INT index, INT end, INT *consumed)
881 {
882 static const WCHAR latin_punc[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
883 WORD type = 0, type2 = 0;
884 DWORD ch;
885 int i;
886
887 *consumed = 1;
888
889 if (str[index] == 0xc || str[index] == 0x20 || str[index] == 0x202f)
890 return Script_CR;
891
892 /* These punctuation characters are separated out as Latin punctuation */
893 if (strchrW(latin_punc,str[index]))
894 return Script_Punctuation2;
895
896 /* These chars are itemized as Punctuation by Windows */
897 if (str[index] == 0x2212 || str[index] == 0x2044)
898 return Script_Punctuation;
899
900 /* Currency Symbols by Unicode point */
901 switch (str[index])
902 {
903 case 0x09f2:
904 case 0x09f3: return Script_Bengali_Currency;
905 case 0x0af1: return Script_Gujarati_Currency;
906 case 0x0e3f: return Script_Thai_Currency;
907 case 0x20aa: return Script_Hebrew_Currency;
908 case 0x20ab: return Script_Vietnamese_Currency;
909 case 0xfb29: return Script_Hebrew_Currency;
910 }
911
912 GetStringTypeW(CT_CTYPE1, &str[index], 1, &type);
913 GetStringTypeW(CT_CTYPE2, &str[index], 1, &type2);
914
915 if (type == 0)
916 return SCRIPT_UNDEFINED;
917
918 if (type & C1_CNTRL)
919 return Script_Control;
920
921 ch = decode_surrogate_pair(str, index, end);
922 if (ch)
923 *consumed = 2;
924 else
925 ch = str[index];
926
927 i = 0;
928 do
929 {
930 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
931 break;
932
933 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
934 {
935 if (scriptRanges[i].numericScript && (type & C1_DIGIT || type2 == C2_ARABICNUMBER))
936 return scriptRanges[i].numericScript;
937 if (scriptRanges[i].punctScript && type & C1_PUNCT)
938 return scriptRanges[i].punctScript;
939 return scriptRanges[i].script;
940 }
941 i++;
942 } while (1);
943
944 return SCRIPT_UNDEFINED;
945 }
946
947 static int compare_FindGlyph(const void *a, const void* b)
948 {
949 const FindGlyph_struct *find = (FindGlyph_struct*)a;
950 const WORD *idx= (WORD*)b;
951 int rc = 0;
952
953 if ( find->target > *idx)
954 rc = 1;
955 else if (find->target < *idx)
956 rc = -1;
957
958 if (!find->ascending)
959 rc *= -1;
960 return rc;
961 }
962
963 int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target)
964 {
965 FindGlyph_struct fgs;
966 WORD *ptr;
967 INT k;
968
969 if (pwLogClust[0] < pwLogClust[cChars-1])
970 fgs.ascending = TRUE;
971 else
972 fgs.ascending = FALSE;
973
974 fgs.target = target;
975 ptr = bsearch(&fgs, pwLogClust, cChars, sizeof(WORD), compare_FindGlyph);
976
977 if (!ptr)
978 return -1;
979
980 for (k = (ptr - pwLogClust)-1; k >= 0 && pwLogClust[k] == target; k--)
981 ;
982 k++;
983
984 return k;
985 }
986
987 /***********************************************************************
988 * ScriptFreeCache (USP10.@)
989 *
990 * Free a script cache.
991 *
992 * PARAMS
993 * psc [I/O] Script cache.
994 *
995 * RETURNS
996 * Success: S_OK
997 * Failure: Non-zero HRESULT value.
998 */
999 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
1000 {
1001 TRACE("%p\n", psc);
1002
1003 if (psc && *psc)
1004 {
1005 unsigned int i;
1006 INT n;
1007 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
1008 {
1009 heap_free(((ScriptCache *)*psc)->widths[i]);
1010 }
1011 for (i = 0; i < NUM_PAGES; i++)
1012 {
1013 unsigned int j;
1014 if (((ScriptCache *)*psc)->page[i])
1015 for (j = 0; j < GLYPH_MAX / GLYPH_BLOCK_SIZE; j++)
1016 heap_free(((ScriptCache *)*psc)->page[i]->glyphs[j]);
1017 heap_free(((ScriptCache *)*psc)->page[i]);
1018 }
1019 heap_free(((ScriptCache *)*psc)->GSUB_Table);
1020 heap_free(((ScriptCache *)*psc)->GDEF_Table);
1021 heap_free(((ScriptCache *)*psc)->CMAP_Table);
1022 heap_free(((ScriptCache *)*psc)->GPOS_Table);
1023 for (n = 0; n < ((ScriptCache *)*psc)->script_count; n++)
1024 {
1025 int j;
1026 for (j = 0; j < ((ScriptCache *)*psc)->scripts[n].language_count; j++)
1027 {
1028 int k;
1029 for (k = 0; k < ((ScriptCache *)*psc)->scripts[n].languages[j].feature_count; k++)
1030 heap_free(((ScriptCache *)*psc)->scripts[n].languages[j].features[k].lookups);
1031 heap_free(((ScriptCache *)*psc)->scripts[n].languages[j].features);
1032 }
1033 for (j = 0; j < ((ScriptCache *)*psc)->scripts[n].default_language.feature_count; j++)
1034 heap_free(((ScriptCache *)*psc)->scripts[n].default_language.features[j].lookups);
1035 heap_free(((ScriptCache *)*psc)->scripts[n].default_language.features);
1036 heap_free(((ScriptCache *)*psc)->scripts[n].languages);
1037 }
1038 heap_free(((ScriptCache *)*psc)->scripts);
1039 heap_free(((ScriptCache *)*psc)->otm);
1040 heap_free(*psc);
1041 *psc = NULL;
1042 }
1043 return S_OK;
1044 }
1045
1046 /***********************************************************************
1047 * ScriptGetProperties (USP10.@)
1048 *
1049 * Retrieve a list of script properties.
1050 *
1051 * PARAMS
1052 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
1053 * num [I] Pointer to the number of scripts.
1054 *
1055 * RETURNS
1056 * Success: S_OK
1057 * Failure: Non-zero HRESULT value.
1058 *
1059 * NOTES
1060 * Behaviour matches WinXP.
1061 */
1062 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
1063 {
1064 TRACE("(%p,%p)\n", props, num);
1065
1066 if (!props && !num) return E_INVALIDARG;
1067
1068 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
1069 if (props) *props = script_props;
1070
1071 return S_OK;
1072 }
1073
1074 /***********************************************************************
1075 * ScriptGetFontProperties (USP10.@)
1076 *
1077 * Get information on special glyphs.
1078 *
1079 * PARAMS
1080 * hdc [I] Device context.
1081 * psc [I/O] Opaque pointer to a script cache.
1082 * sfp [O] Font properties structure.
1083 */
1084 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
1085 {
1086 HRESULT hr;
1087
1088 TRACE("%p,%p,%p\n", hdc, psc, sfp);
1089
1090 if (!sfp) return E_INVALIDARG;
1091 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1092
1093 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
1094 return E_INVALIDARG;
1095
1096 get_cache_font_properties(sfp, *psc);
1097
1098 return S_OK;
1099 }
1100
1101 /***********************************************************************
1102 * ScriptRecordDigitSubstitution (USP10.@)
1103 *
1104 * Record digit substitution settings for a given locale.
1105 *
1106 * PARAMS
1107 * locale [I] Locale identifier.
1108 * sds [I] Structure to record substitution settings.
1109 *
1110 * RETURNS
1111 * Success: S_OK
1112 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
1113 *
1114 * SEE ALSO
1115 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
1116 */
1117 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
1118 {
1119 DWORD plgid, sub;
1120
1121 TRACE("0x%x, %p\n", locale, sds);
1122
1123 /* This implementation appears to be correct for all languages, but it's
1124 * not clear if sds->DigitSubstitute is ever set to anything except
1125 * CONTEXT or NONE in reality */
1126
1127 if (!sds) return E_POINTER;
1128
1129 locale = ConvertDefaultLocale(locale);
1130
1131 if (!IsValidLocale(locale, LCID_INSTALLED))
1132 return E_INVALIDARG;
1133
1134 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
1135 sds->TraditionalDigitLanguage = plgid;
1136
1137 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
1138 sds->NationalDigitLanguage = plgid;
1139 else
1140 sds->NationalDigitLanguage = LANG_ENGLISH;
1141
1142 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
1143 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
1144
1145 switch (sub)
1146 {
1147 case 0:
1148 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
1149 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
1150 else
1151 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
1152 break;
1153 case 1:
1154 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
1155 break;
1156 case 2:
1157 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
1158 break;
1159 default:
1160 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
1161 break;
1162 }
1163
1164 sds->dwReserved = 0;
1165 return S_OK;
1166 }
1167
1168 /***********************************************************************
1169 * ScriptApplyDigitSubstitution (USP10.@)
1170 *
1171 * Apply digit substitution settings.
1172 *
1173 * PARAMS
1174 * sds [I] Structure with recorded substitution settings.
1175 * sc [I] Script control structure.
1176 * ss [I] Script state structure.
1177 *
1178 * RETURNS
1179 * Success: S_OK
1180 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
1181 */
1182 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
1183 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
1184 {
1185 SCRIPT_DIGITSUBSTITUTE psds;
1186
1187 TRACE("%p, %p, %p\n", sds, sc, ss);
1188
1189 if (!sc || !ss) return E_POINTER;
1190 if (!sds)
1191 {
1192 sds = &psds;
1193 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
1194 return E_INVALIDARG;
1195 }
1196
1197 sc->uDefaultLanguage = LANG_ENGLISH;
1198 sc->fContextDigits = 0;
1199 ss->fDigitSubstitute = 0;
1200
1201 switch (sds->DigitSubstitute) {
1202 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
1203 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
1204 case SCRIPT_DIGITSUBSTITUTE_NONE:
1205 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
1206 return S_OK;
1207 default:
1208 return E_INVALIDARG;
1209 }
1210 }
1211
1212 static inline BOOL is_indic(WORD script)
1213 {
1214 return (script >= Script_Devanagari && script <= Script_Malayalam_Numeric);
1215 }
1216
1217 static inline WORD base_indic(WORD script)
1218 {
1219 switch (script)
1220 {
1221 case Script_Devanagari:
1222 case Script_Devanagari_Numeric: return Script_Devanagari;
1223 case Script_Bengali:
1224 case Script_Bengali_Numeric:
1225 case Script_Bengali_Currency: return Script_Bengali;
1226 case Script_Gurmukhi:
1227 case Script_Gurmukhi_Numeric: return Script_Gurmukhi;
1228 case Script_Gujarati:
1229 case Script_Gujarati_Numeric:
1230 case Script_Gujarati_Currency: return Script_Gujarati;
1231 case Script_Oriya:
1232 case Script_Oriya_Numeric: return Script_Oriya;
1233 case Script_Tamil:
1234 case Script_Tamil_Numeric: return Script_Tamil;
1235 case Script_Telugu:
1236 case Script_Telugu_Numeric: return Script_Telugu;
1237 case Script_Kannada:
1238 case Script_Kannada_Numeric: return Script_Kannada;
1239 case Script_Malayalam:
1240 case Script_Malayalam_Numeric: return Script_Malayalam;
1241 default:
1242 return -1;
1243 };
1244 }
1245
1246 static BOOL script_is_numeric(WORD script)
1247 {
1248 return scriptInformation[script].props.fNumeric;
1249 }
1250
1251 static HRESULT _ItemizeInternal(const WCHAR *pwcInChars, int cInChars,
1252 int cMaxItems, const SCRIPT_CONTROL *psControl,
1253 const SCRIPT_STATE *psState, SCRIPT_ITEM *pItems,
1254 OPENTYPE_TAG *pScriptTags, int *pcItems)
1255 {
1256
1257 #define Numeric_space 0x0020
1258 #define ZWSP 0x200B
1259 #define ZWNJ 0x200C
1260 #define ZWJ 0x200D
1261
1262 int cnt = 0, index = 0, str = 0;
1263 int New_Script = -1;
1264 int i;
1265 WORD *levels = NULL;
1266 WORD *layout_levels = NULL;
1267 WORD *overrides = NULL;
1268 WORD *strength = NULL;
1269 WORD *scripts = NULL;
1270 WORD baselevel = 0;
1271 WORD baselayout = 0;
1272 BOOL new_run;
1273 WORD last_indic = -1;
1274 WORD layoutRTL = 0;
1275 BOOL forceLevels = FALSE;
1276 INT consumed = 0;
1277 HRESULT res = E_OUTOFMEMORY;
1278
1279 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
1280 psControl, psState, pItems, pcItems);
1281
1282 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
1283 return E_INVALIDARG;
1284
1285 scripts = heap_alloc(cInChars * sizeof(WORD));
1286 if (!scripts)
1287 return E_OUTOFMEMORY;
1288
1289 for (i = 0; i < cInChars; i++)
1290 {
1291 if (consumed <= 0)
1292 {
1293 scripts[i] = get_char_script(pwcInChars,i,cInChars,&consumed);
1294 consumed --;
1295 }
1296 else
1297 {
1298 scripts[i] = scripts[i-1];
1299 consumed --;
1300 }
1301 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1302 all Indic scripts */
1303 if ((pwcInChars[i] == 0x964 || pwcInChars[i] ==0x965) && last_indic > 0)
1304 scripts[i] = last_indic;
1305 else if (is_indic(scripts[i]))
1306 last_indic = base_indic(scripts[i]);
1307
1308 /* Some unicode points :
1309 (Zero Width Space U+200B - Right-to-Left Mark U+200F)
1310 (Left Right Embed U+202A - Left Right Override U+202D)
1311 (Left Right Isolate U+2066 - Pop Directional Isolate U+2069)
1312 will force us into bidi mode */
1313 if (!forceLevels && ((pwcInChars[i] >= 0x200B && pwcInChars[i] <= 0x200F) ||
1314 (pwcInChars[i] >= 0x202A && pwcInChars[i] <= 0x202E) ||
1315 (pwcInChars[i] >= 0x2066 && pwcInChars[i] <= 0x2069)))
1316
1317 forceLevels = TRUE;
1318
1319 /* Diacritical marks merge with other scripts */
1320 if (scripts[i] == Script_Diacritical)
1321 {
1322 if (i > 0)
1323 {
1324 if (pScriptTags)
1325 scripts[i] = scripts[i-1];
1326 else
1327 {
1328 int j;
1329 BOOL asian = FALSE;
1330 WORD first_script = scripts[i-1];
1331 for (j = i-1; j >= 0 && scripts[j] == first_script && pwcInChars[j] != Numeric_space; j--)
1332 {
1333 WORD original = scripts[j];
1334 if (original == Script_Ideograph || original == Script_Kana || original == Script_Yi || original == Script_CJK_Han || original == Script_Bopomofo)
1335 {
1336 asian = TRUE;
1337 break;
1338 }
1339 if (original != Script_MathAlpha && scriptInformation[scripts[j]].props.fComplex)
1340 break;
1341 scripts[j] = scripts[i];
1342 if (original == Script_Punctuation2)
1343 break;
1344 }
1345 if (j >= 0 && (scriptInformation[scripts[j]].props.fComplex || asian))
1346 scripts[i] = scripts[j];
1347 }
1348 }
1349 }
1350 }
1351
1352 for (i = 0; i < cInChars; i++)
1353 {
1354 /* Joiners get merged preferencially right */
1355 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ || pwcInChars[i] == ZWSP))
1356 {
1357 int j;
1358 if (i+1 == cInChars)
1359 scripts[i] = scripts[i-1];
1360 else
1361 {
1362 for (j = i+1; j < cInChars; j++)
1363 {
1364 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ
1365 && pwcInChars[j] != ZWSP && pwcInChars[j] != Numeric_space)
1366 {
1367 scripts[i] = scripts[j];
1368 break;
1369 }
1370 }
1371 }
1372 }
1373 }
1374
1375 if (psState && psControl)
1376 {
1377 levels = heap_alloc_zero(cInChars * sizeof(WORD));
1378 if (!levels)
1379 goto nomemory;
1380
1381 overrides = heap_alloc_zero(cInChars * sizeof(WORD));
1382 if (!overrides)
1383 goto nomemory;
1384
1385 layout_levels = heap_alloc_zero(cInChars * sizeof(WORD));
1386 if (!layout_levels)
1387 goto nomemory;
1388
1389 if (psState->fOverrideDirection)
1390 {
1391 if (!forceLevels)
1392 {
1393 SCRIPT_STATE s = *psState;
1394 s.fOverrideDirection = FALSE;
1395 BIDI_DetermineLevels(pwcInChars, cInChars, &s, psControl, layout_levels, overrides);
1396 if (odd(layout_levels[0]))
1397 forceLevels = TRUE;
1398 else for (i = 0; i < cInChars; i++)
1399 if (layout_levels[i]!=layout_levels[0])
1400 {
1401 forceLevels = TRUE;
1402 break;
1403 }
1404 }
1405
1406 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels, overrides);
1407 }
1408 else
1409 {
1410 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels, overrides);
1411 memcpy(layout_levels, levels, cInChars * sizeof(WORD));
1412 }
1413 baselevel = levels[0];
1414 baselayout = layout_levels[0];
1415 for (i = 0; i < cInChars; i++)
1416 if (levels[i]!=levels[0])
1417 break;
1418 if (i >= cInChars && !odd(baselevel) && !odd(psState->uBidiLevel) && !forceLevels)
1419 {
1420 heap_free(levels);
1421 heap_free(overrides);
1422 heap_free(layout_levels);
1423 overrides = NULL;
1424 levels = NULL;
1425 layout_levels = NULL;
1426 }
1427 else
1428 {
1429 static const WCHAR math_punc[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1430 static const WCHAR repeatable_math_punc[] = {'#','$','%','+','-','/',0x2212, 0x2044,0};
1431
1432 strength = heap_alloc_zero(cInChars * sizeof(WORD));
1433 if (!strength)
1434 goto nomemory;
1435 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
1436
1437 /* We currently mis-level leading Diacriticals */
1438 if (scripts[0] == Script_Diacritical)
1439 for (i = 0; i < cInChars && scripts[0] == Script_Diacritical; i++)
1440 {
1441 levels[i] = odd(levels[i])?levels[i]+1:levels[i];
1442 strength[i] = BIDI_STRONG;
1443 }
1444
1445 /* Math punctuation bordered on both sides by numbers can be
1446 merged into the number */
1447 for (i = 0; i < cInChars; i++)
1448 {
1449 if (i > 0 && i < cInChars-1 &&
1450 script_is_numeric(scripts[i-1]) &&
1451 strchrW(math_punc, pwcInChars[i]))
1452 {
1453 if (script_is_numeric(scripts[i+1]))
1454 {
1455 scripts[i] = scripts[i+1];
1456 levels[i] = levels[i-1];
1457 strength[i] = strength[i-1];
1458 i++;
1459 }
1460 else if (strchrW(repeatable_math_punc, pwcInChars[i]))
1461 {
1462 int j;
1463 for (j = i+1; j < cInChars; j++)
1464 {
1465 if (script_is_numeric(scripts[j]))
1466 {
1467 for(;i<j; i++)
1468 {
1469 scripts[i] = scripts[j];
1470 levels[i] = levels[i-1];
1471 strength[i] = strength[i-1];
1472 }
1473 }
1474 else if (pwcInChars[i] != pwcInChars[j]) break;
1475 }
1476 }
1477 }
1478 }
1479
1480 for (i = 0; i < cInChars; i++)
1481 {
1482 /* Numerics at level 0 get bumped to level 2 */
1483 if (!overrides[i] && (levels[i] == 0 || (odd(psState->uBidiLevel)
1484 && levels[i] == psState->uBidiLevel + 1)) && script_is_numeric(scripts[i]))
1485 {
1486 levels[i] = 2;
1487 }
1488
1489 /* Joiners get merged preferencially right */
1490 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ || pwcInChars[i] == ZWSP))
1491 {
1492 int j;
1493 if (i+1 == cInChars && levels[i-1] == levels[i])
1494 strength[i] = strength[i-1];
1495 else
1496 for (j = i+1; j < cInChars && levels[i] == levels[j]; j++)
1497 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ
1498 && pwcInChars[j] != ZWSP && pwcInChars[j] != Numeric_space)
1499 {
1500 strength[i] = strength[j];
1501 break;
1502 }
1503 }
1504 }
1505 if (psControl->fMergeNeutralItems)
1506 {
1507 /* Merge the neutrals */
1508 for (i = 0; i < cInChars; i++)
1509 {
1510 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1511 {
1512 int j;
1513 for (j = i; j > 0; j--)
1514 {
1515 if (levels[i] != levels[j])
1516 break;
1517 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1518 {
1519 scripts[i] = scripts[j];
1520 strength[i] = strength[j];
1521 break;
1522 }
1523 }
1524 }
1525 /* Try going the other way */
1526 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1527 {
1528 int j;
1529 for (j = i; j < cInChars; j++)
1530 {
1531 if (levels[i] != levels[j])
1532 break;
1533 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1534 {
1535 scripts[i] = scripts[j];
1536 strength[i] = strength[j];
1537 break;
1538 }
1539 }
1540 }
1541 }
1542 }
1543 }
1544 }
1545
1546 while ((!levels || (levels && cnt+1 < cInChars && levels[cnt+1] == levels[0]))
1547 && (cnt < cInChars && pwcInChars[cnt] == Numeric_space))
1548 cnt++;
1549
1550 if (cnt == cInChars) /* All Spaces */
1551 {
1552 cnt = 0;
1553 New_Script = scripts[cnt];
1554 }
1555
1556 pItems[index].iCharPos = 0;
1557 pItems[index].a = scriptInformation[scripts[cnt]].a;
1558 if (pScriptTags)
1559 pScriptTags[index] = scriptInformation[scripts[cnt]].scriptTag;
1560
1561 if (strength && strength[cnt] == BIDI_STRONG)
1562 str = strength[cnt];
1563 else if (strength)
1564 str = strength[0];
1565
1566 cnt = 0;
1567
1568 if (levels)
1569 {
1570 if (strength[cnt] == BIDI_STRONG)
1571 layoutRTL = odd(layout_levels[cnt]);
1572 else
1573 layoutRTL = (psState->uBidiLevel || odd(layout_levels[cnt]));
1574 if (overrides)
1575 pItems[index].a.s.fOverrideDirection = (overrides[cnt] != 0);
1576 pItems[index].a.fRTL = odd(levels[cnt]);
1577 if (script_is_numeric(pItems[index].a.eScript))
1578 pItems[index].a.fLayoutRTL = layoutRTL;
1579 else
1580 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1581 pItems[index].a.s.uBidiLevel = levels[cnt];
1582 }
1583 else if (!pItems[index].a.s.uBidiLevel || (overrides && overrides[cnt]))
1584 {
1585 if (pItems[index].a.s.uBidiLevel != baselevel)
1586 pItems[index].a.s.fOverrideDirection = TRUE;
1587 layoutRTL = odd(baselayout);
1588 pItems[index].a.s.uBidiLevel = baselevel;
1589 pItems[index].a.fRTL = odd(baselevel);
1590 if (script_is_numeric(pItems[index].a.eScript))
1591 pItems[index].a.fLayoutRTL = odd(baselayout);
1592 else
1593 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1594 }
1595
1596 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1597 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
1598 pItems[index].iCharPos);
1599
1600 for (cnt=1; cnt < cInChars; cnt++)
1601 {
1602 if(pwcInChars[cnt] != Numeric_space)
1603 New_Script = scripts[cnt];
1604 else if (levels)
1605 {
1606 int j = 1;
1607 while (cnt + j < cInChars - 1 && pwcInChars[cnt+j] == Numeric_space && levels[cnt] == levels[cnt+j])
1608 j++;
1609 if (cnt + j < cInChars && levels[cnt] == levels[cnt+j])
1610 New_Script = scripts[cnt+j];
1611 else
1612 New_Script = scripts[cnt];
1613 }
1614
1615 new_run = FALSE;
1616 /* merge space strengths*/
1617 if (strength && strength[cnt] == BIDI_STRONG && str != BIDI_STRONG && New_Script == pItems[index].a.eScript)
1618 str = BIDI_STRONG;
1619
1620 if (strength && strength[cnt] == BIDI_NEUTRAL && str == BIDI_STRONG && pwcInChars[cnt] != Numeric_space && New_Script == pItems[index].a.eScript)
1621 str = BIDI_NEUTRAL;
1622
1623 /* changes in level */
1624 if (levels && (levels[cnt] != pItems[index].a.s.uBidiLevel))
1625 {
1626 TRACE("Level break(%i/%i)\n",pItems[index].a.s.uBidiLevel,levels[cnt]);
1627 new_run = TRUE;
1628 }
1629 /* changes in strength */
1630 else if (strength && pwcInChars[cnt] != Numeric_space && str != strength[cnt])
1631 {
1632 TRACE("Strength break (%i/%i)\n",str,strength[cnt]);
1633 new_run = TRUE;
1634 }
1635 /* changes in script */
1636 else if (((pwcInChars[cnt] != Numeric_space) && (New_Script != -1) && (New_Script != pItems[index].a.eScript)) || (New_Script == Script_Control))
1637 {
1638 TRACE("Script break(%i/%i)\n",pItems[index].a.eScript,New_Script);
1639 new_run = TRUE;
1640 }
1641
1642 if (!new_run && strength && str == BIDI_STRONG)
1643 {
1644 layoutRTL = odd(layout_levels[cnt]);
1645 if (script_is_numeric(pItems[index].a.eScript))
1646 pItems[index].a.fLayoutRTL = layoutRTL;
1647 }
1648
1649 if (new_run)
1650 {
1651 TRACE("New_Level = %i, New_Strength = %i, New_Script=%d, eScript=%d\n", levels?levels[cnt]:-1, strength?strength[cnt]:str, New_Script, pItems[index].a.eScript);
1652
1653 index++;
1654 if (index+1 > cMaxItems)
1655 goto nomemory;
1656
1657 if (strength)
1658 str = strength[cnt];
1659
1660 pItems[index].iCharPos = cnt;
1661 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1662
1663 pItems[index].a = scriptInformation[New_Script].a;
1664 if (pScriptTags)
1665 pScriptTags[index] = scriptInformation[New_Script].scriptTag;
1666 if (levels)
1667 {
1668 if (overrides)
1669 pItems[index].a.s.fOverrideDirection = (overrides[cnt] != 0);
1670 if (layout_levels[cnt] == 0)
1671 layoutRTL = 0;
1672 else
1673 layoutRTL = (layoutRTL || odd(layout_levels[cnt]));
1674 pItems[index].a.fRTL = odd(levels[cnt]);
1675 if (script_is_numeric(pItems[index].a.eScript))
1676 pItems[index].a.fLayoutRTL = layoutRTL;
1677 else
1678 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1679 pItems[index].a.s.uBidiLevel = levels[cnt];
1680 }
1681 else if (!pItems[index].a.s.uBidiLevel || (overrides && overrides[cnt]))
1682 {
1683 if (pItems[index].a.s.uBidiLevel != baselevel)
1684 pItems[index].a.s.fOverrideDirection = TRUE;
1685 pItems[index].a.s.uBidiLevel = baselevel;
1686 pItems[index].a.fRTL = odd(baselevel);
1687 if (script_is_numeric(pItems[index].a.eScript))
1688 pItems[index].a.fLayoutRTL = layoutRTL;
1689 else
1690 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1691 }
1692
1693 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1694 }
1695 }
1696
1697 /* While not strictly necessary according to the spec, make sure the n+1
1698 * item is set up to prevent random behaviour if the caller erroneously
1699 * checks the n+1 structure */
1700 index++;
1701 if (index + 1 > cMaxItems) goto nomemory;
1702 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1703
1704 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1705
1706 /* Set one SCRIPT_STATE item being returned */
1707 if (pcItems) *pcItems = index;
1708
1709 /* Set SCRIPT_ITEM */
1710 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
1711 res = S_OK;
1712 nomemory:
1713 heap_free(levels);
1714 heap_free(overrides);
1715 heap_free(layout_levels);
1716 heap_free(strength);
1717 heap_free(scripts);
1718 return res;
1719 }
1720
1721 /***********************************************************************
1722 * ScriptItemizeOpenType (USP10.@)
1723 *
1724 * Split a Unicode string into shapeable parts.
1725 *
1726 * PARAMS
1727 * pwcInChars [I] String to split.
1728 * cInChars [I] Number of characters in pwcInChars.
1729 * cMaxItems [I] Maximum number of items to return.
1730 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1731 * psState [I] Pointer to a SCRIPT_STATE structure.
1732 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1733 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1734 * pcItems [O] Number of script items returned.
1735 *
1736 * RETURNS
1737 * Success: S_OK
1738 * Failure: Non-zero HRESULT value.
1739 */
1740 HRESULT WINAPI ScriptItemizeOpenType(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1741 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1742 SCRIPT_ITEM *pItems, OPENTYPE_TAG *pScriptTags, int *pcItems)
1743 {
1744 return _ItemizeInternal(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems);
1745 }
1746
1747 /***********************************************************************
1748 * ScriptItemize (USP10.@)
1749 *
1750 * Split a Unicode string into shapeable parts.
1751 *
1752 * PARAMS
1753 * pwcInChars [I] String to split.
1754 * cInChars [I] Number of characters in pwcInChars.
1755 * cMaxItems [I] Maximum number of items to return.
1756 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1757 * psState [I] Pointer to a SCRIPT_STATE structure.
1758 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1759 * pcItems [O] Number of script items returned.
1760 *
1761 * RETURNS
1762 * Success: S_OK
1763 * Failure: Non-zero HRESULT value.
1764 */
1765 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1766 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1767 SCRIPT_ITEM *pItems, int *pcItems)
1768 {
1769 return _ItemizeInternal(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, NULL, pcItems);
1770 }
1771
1772 static inline int getGivenTabWidth(ScriptCache *psc, SCRIPT_TABDEF *pTabdef, int charPos, int current_x)
1773 {
1774 int defWidth;
1775 int cTabStops=0;
1776 INT *lpTabPos = NULL;
1777 INT nTabOrg = 0;
1778 INT x = 0;
1779
1780 if (pTabdef)
1781 lpTabPos = pTabdef->pTabStops;
1782
1783 if (pTabdef && pTabdef->iTabOrigin)
1784 {
1785 if (pTabdef->iScale)
1786 nTabOrg = (pTabdef->iTabOrigin * pTabdef->iScale)/4;
1787 else
1788 nTabOrg = pTabdef->iTabOrigin * psc->tm.tmAveCharWidth;
1789 }
1790
1791 if (pTabdef)
1792 cTabStops = pTabdef->cTabStops;
1793
1794 if (cTabStops == 1)
1795 {
1796 if (pTabdef->iScale)
1797 defWidth = ((pTabdef->pTabStops[0])*pTabdef->iScale) / 4;
1798 else
1799 defWidth = (pTabdef->pTabStops[0])*psc->tm.tmAveCharWidth;
1800 cTabStops = 0;
1801 }
1802 else
1803 defWidth = 8 * psc->tm.tmAveCharWidth;
1804
1805 for (; cTabStops>0 ; lpTabPos++, cTabStops--)
1806 {
1807 int position = *lpTabPos;
1808 if (position < 0)
1809 position = -1 * position;
1810 if (pTabdef->iScale)
1811 position = (position * pTabdef->iScale) / 4;
1812 else
1813 position = position * psc->tm.tmAveCharWidth;
1814
1815 if( nTabOrg + position > current_x)
1816 {
1817 if( *lpTabPos >= 0)
1818 {
1819 /* a left aligned tab */
1820 x = (nTabOrg + *lpTabPos) - current_x;
1821 break;
1822 }
1823 else
1824 {
1825 FIXME("Negative tabstop\n");
1826 break;
1827 }
1828 }
1829 }
1830 if ((!cTabStops) && (defWidth > 0))
1831 x =((((current_x - nTabOrg) / defWidth)+1) * defWidth) - current_x;
1832 else if ((!cTabStops) && (defWidth < 0))
1833 FIXME("TODO: Negative defWidth\n");
1834
1835 return x;
1836 }
1837
1838 /***********************************************************************
1839 * Helper function for ScriptStringAnalyse
1840 */
1841 static BOOL requires_fallback(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
1842 const WCHAR *pwcInChars, int cChars )
1843 {
1844 /* FIXME: When to properly fallback is still a bit of a mystery */
1845 WORD *glyphs;
1846
1847 if (psa->fNoGlyphIndex)
1848 return FALSE;
1849
1850 if (init_script_cache(hdc, psc) != S_OK)
1851 return FALSE;
1852
1853 if (SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa) != S_OK)
1854 return TRUE;
1855
1856 glyphs = heap_alloc(sizeof(WORD) * cChars);
1857 if (!glyphs)
1858 return FALSE;
1859 if (ScriptGetCMap(hdc, psc, pwcInChars, cChars, 0, glyphs) != S_OK)
1860 {
1861 heap_free(glyphs);
1862 return TRUE;
1863 }
1864 heap_free(glyphs);
1865
1866 return FALSE;
1867 }
1868
1869 static void find_fallback_font(DWORD scriptid, LPWSTR FaceName)
1870 {
1871 HKEY hkey;
1872
1873 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Uniscribe\\Fallback", &hkey))
1874 {
1875 static const WCHAR szFmt[] = {'%','x',0};
1876 WCHAR value[10];
1877 DWORD count = LF_FACESIZE * sizeof(WCHAR);
1878 DWORD type;
1879
1880 sprintfW(value, szFmt, scriptInformation[scriptid].scriptTag);
1881 if (RegQueryValueExW(hkey, value, 0, &type, (LPBYTE)FaceName, &count))
1882 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1883 RegCloseKey(hkey);
1884 }
1885 else
1886 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1887 }
1888
1889 /***********************************************************************
1890 * ScriptStringAnalyse (USP10.@)
1891 *
1892 */
1893 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
1894 int cGlyphs, int iCharset, DWORD dwFlags,
1895 int iReqWidth, SCRIPT_CONTROL *psControl,
1896 SCRIPT_STATE *psState, const int *piDx,
1897 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
1898 SCRIPT_STRING_ANALYSIS *pssa)
1899 {
1900 HRESULT hr = E_OUTOFMEMORY;
1901 StringAnalysis *analysis = NULL;
1902 SCRIPT_CONTROL sControl;
1903 SCRIPT_STATE sState;
1904 int i, num_items = 255;
1905 BYTE *BidiLevel;
1906 WCHAR *iString = NULL;
1907
1908 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1909 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
1910 psControl, psState, piDx, pTabdef, pbInClass, pssa);
1911
1912 if (iCharset != -1)
1913 {
1914 FIXME("Only Unicode strings are supported\n");
1915 return E_INVALIDARG;
1916 }
1917 if (cString < 1 || !pString) return E_INVALIDARG;
1918 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
1919
1920 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
1921 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
1922
1923 /* FIXME: handle clipping */
1924 analysis->clip_len = cString;
1925 analysis->hdc = hdc;
1926 analysis->dwFlags = dwFlags;
1927
1928 if (psState)
1929 sState = *psState;
1930 else
1931 memset(&sState, 0, sizeof(SCRIPT_STATE));
1932
1933 if (psControl)
1934 sControl = *psControl;
1935 else
1936 memset(&sControl, 0, sizeof(SCRIPT_CONTROL));
1937
1938 if (dwFlags & SSA_PASSWORD)
1939 {
1940 iString = heap_alloc(sizeof(WCHAR)*cString);
1941 if (!iString)
1942 {
1943 hr = E_OUTOFMEMORY;
1944 goto error;
1945 }
1946 for (i = 0; i < cString; i++)
1947 iString[i] = *((const WCHAR *)pString);
1948 pString = iString;
1949 }
1950
1951 hr = ScriptItemize(pString, cString, num_items, &sControl, &sState, analysis->pItem,
1952 &analysis->numItems);
1953
1954 if (FAILED(hr))
1955 {
1956 if (hr == E_OUTOFMEMORY)
1957 hr = E_INVALIDARG;
1958 goto error;
1959 }
1960
1961 /* set back to out of memory for default goto error behaviour */
1962 hr = E_OUTOFMEMORY;
1963
1964 if (dwFlags & SSA_BREAK)
1965 {
1966 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
1967 {
1968 for (i = 0; i < analysis->numItems; i++)
1969 ScriptBreak(&((LPWSTR)pString)[analysis->pItem[i].iCharPos], analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos, &analysis->pItem[i].a, &analysis->logattrs[analysis->pItem[i].iCharPos]);
1970 }
1971 else
1972 goto error;
1973 }
1974
1975 if (!(analysis->logical2visual = heap_alloc_zero(sizeof(int) * analysis->numItems)))
1976 goto error;
1977 if (!(BidiLevel = heap_alloc_zero(analysis->numItems)))
1978 goto error;
1979
1980 if (dwFlags & SSA_GLYPHS)
1981 {
1982 int tab_x = 0;
1983 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
1984 {
1985 heap_free(BidiLevel);
1986 goto error;
1987 }
1988
1989 for (i = 0; i < analysis->numItems; i++)
1990 {
1991 SCRIPT_CACHE *sc = (SCRIPT_CACHE*)&analysis->glyphs[i].sc;
1992 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1993 int numGlyphs = 1.5 * cChar + 16;
1994 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
1995 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
1996 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
1997 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * numGlyphs);
1998 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
1999 ABC *abc = heap_alloc_zero(sizeof(ABC));
2000 int numGlyphsReturned;
2001 HFONT originalFont = 0x0;
2002
2003 /* FIXME: non unicode strings */
2004 const WCHAR* pStr = (const WCHAR*)pString;
2005 analysis->glyphs[i].fallbackFont = NULL;
2006
2007 if (!glyphs || !pwLogClust || !piAdvance || !psva || !pGoffset || !abc)
2008 {
2009 heap_free (BidiLevel);
2010 heap_free (glyphs);
2011 heap_free (pwLogClust);
2012 heap_free (piAdvance);
2013 heap_free (psva);
2014 heap_free (pGoffset);
2015 heap_free (abc);
2016 hr = E_OUTOFMEMORY;
2017 goto error;
2018 }
2019
2020 if ((dwFlags & SSA_FALLBACK) && requires_fallback(hdc, sc, &analysis->pItem[i].a, &pStr[analysis->pItem[i].iCharPos], cChar))
2021 {
2022 LOGFONTW lf;
2023 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), & lf);
2024 lf.lfCharSet = scriptInformation[analysis->pItem[i].a.eScript].props.bCharSet;
2025 lf.lfFaceName[0] = 0;
2026 find_fallback_font(analysis->pItem[i].a.eScript, lf.lfFaceName);
2027 if (lf.lfFaceName[0])
2028 {
2029 analysis->glyphs[i].fallbackFont = CreateFontIndirectW(&lf);
2030 if (analysis->glyphs[i].fallbackFont)
2031 {
2032 ScriptFreeCache(sc);
2033 originalFont = SelectObject(hdc, analysis->glyphs[i].fallbackFont);
2034 }
2035 }
2036 }
2037
2038 /* FIXME: When we properly shape Hangul remove this check */
2039 if ((dwFlags & SSA_LINK) && !analysis->glyphs[i].fallbackFont && analysis->pItem[i].a.eScript == Script_Hangul)
2040 analysis->pItem[i].a.fNoGlyphIndex = TRUE;
2041
2042 if ((dwFlags & SSA_LINK) && !analysis->glyphs[i].fallbackFont && !scriptInformation[analysis->pItem[i].a.eScript].props.fComplex && !analysis->pItem[i].a.fRTL)
2043 analysis->pItem[i].a.fNoGlyphIndex = TRUE;
2044
2045 ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos], cChar, numGlyphs,
2046 &analysis->pItem[i].a, glyphs, pwLogClust, psva, &numGlyphsReturned);
2047 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
2048 piAdvance, pGoffset, abc);
2049 if (originalFont)
2050 SelectObject(hdc,originalFont);
2051
2052 if (dwFlags & SSA_TAB)
2053 {
2054 int tabi = 0;
2055 for (tabi = 0; tabi < cChar; tabi++)
2056 {
2057 if (pStr[analysis->pItem[i].iCharPos+tabi] == 0x0009)
2058 piAdvance[tabi] = getGivenTabWidth(analysis->glyphs[i].sc, pTabdef, analysis->pItem[i].iCharPos+tabi, tab_x);
2059 tab_x+=piAdvance[tabi];
2060 }
2061 }
2062
2063 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
2064 analysis->glyphs[i].glyphs = glyphs;
2065 analysis->glyphs[i].pwLogClust = pwLogClust;
2066 analysis->glyphs[i].piAdvance = piAdvance;
2067 analysis->glyphs[i].psva = psva;
2068 analysis->glyphs[i].pGoffset = pGoffset;
2069 analysis->glyphs[i].abc = abc;
2070 analysis->glyphs[i].iMaxPosX= -1;
2071
2072 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
2073 }
2074 }
2075 else
2076 {
2077 for (i = 0; i < analysis->numItems; i++)
2078 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
2079 }
2080
2081 ScriptLayout(analysis->numItems, BidiLevel, NULL, analysis->logical2visual);
2082 heap_free(BidiLevel);
2083
2084 *pssa = analysis;
2085 heap_free(iString);
2086 return S_OK;
2087
2088 error:
2089 heap_free(iString);
2090 heap_free(analysis->glyphs);
2091 heap_free(analysis->logattrs);
2092 heap_free(analysis->pItem);
2093 heap_free(analysis->logical2visual);
2094 heap_free(analysis);
2095 return hr;
2096 }
2097
2098 static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
2099 {
2100 if (pva[glyph].fClusterStart)
2101 return TRUE;
2102 if (USP10_FindGlyphInLogClust(pwLogClust, cChars, glyph) >= 0)
2103 return TRUE;
2104
2105 return FALSE;
2106 }
2107
2108
2109 static HRESULT SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa,
2110 int iX,
2111 int iY,
2112 int iItem,
2113 int cStart,
2114 int cEnd,
2115 UINT uOptions,
2116 const RECT *prc,
2117 BOOL fSelected,
2118 BOOL fDisabled)
2119 {
2120 StringAnalysis *analysis;
2121 int off_x = 0;
2122 HRESULT hr;
2123 COLORREF BkColor = 0x0;
2124 COLORREF TextColor = 0x0;
2125 INT BkMode = 0;
2126 INT runStart, runEnd;
2127 INT iGlyph, cGlyphs;
2128 HFONT oldFont = 0x0;
2129 RECT crc;
2130 int i;
2131
2132 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
2133 ssa, iX, iY, iItem, cStart, cEnd, uOptions, fSelected, fDisabled);
2134
2135 if (!(analysis = ssa)) return E_INVALIDARG;
2136
2137 if ((cStart >= 0 && analysis->pItem[iItem+1].iCharPos <= cStart) ||
2138 (cEnd >= 0 && analysis->pItem[iItem].iCharPos >= cEnd))
2139 return S_OK;
2140
2141 CopyRect(&crc,prc);
2142 if (fSelected)
2143 {
2144 BkMode = GetBkMode(analysis->hdc);
2145 SetBkMode( analysis->hdc, OPAQUE);
2146 BkColor = GetBkColor(analysis->hdc);
2147 SetBkColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHT));
2148 if (!fDisabled)
2149 {
2150 TextColor = GetTextColor(analysis->hdc);
2151 SetTextColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2152 }
2153 }
2154 if (analysis->glyphs[iItem].fallbackFont)
2155 oldFont = SelectObject(analysis->hdc, analysis->glyphs[iItem].fallbackFont);
2156
2157 if (cStart >= 0 && analysis->pItem[iItem+1].iCharPos > cStart && analysis->pItem[iItem].iCharPos <= cStart)
2158 runStart = cStart - analysis->pItem[iItem].iCharPos;
2159 else
2160 runStart = 0;
2161 if (cEnd >= 0 && analysis->pItem[iItem+1].iCharPos > cEnd && analysis->pItem[iItem].iCharPos <= cEnd)
2162 runEnd = (cEnd-1) - analysis->pItem[iItem].iCharPos;
2163 else
2164 runEnd = (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos) - 1;
2165
2166 if (analysis->pItem[iItem].a.fRTL)
2167 {
2168 if (cEnd >= 0 && cEnd < analysis->pItem[iItem+1].iCharPos)
2169 ScriptStringCPtoX(ssa, cEnd, FALSE, &off_x);
2170 else
2171 ScriptStringCPtoX(ssa, analysis->pItem[iItem+1].iCharPos-1, TRUE, &off_x);
2172 crc.left = iX + off_x;
2173 }
2174 else
2175 {
2176 if (cStart >=0 && runStart)
2177 ScriptStringCPtoX(ssa, cStart, FALSE, &off_x);
2178 else
2179 ScriptStringCPtoX(ssa, analysis->pItem[iItem].iCharPos, FALSE, &off_x);
2180 crc.left = iX + off_x;
2181 }
2182
2183 if (analysis->pItem[iItem].a.fRTL)
2184 iGlyph = analysis->glyphs[iItem].pwLogClust[runEnd];
2185 else
2186 iGlyph = analysis->glyphs[iItem].pwLogClust[runStart];
2187
2188 if (analysis->pItem[iItem].a.fRTL)
2189 cGlyphs = analysis->glyphs[iItem].pwLogClust[runStart] - iGlyph;
2190 else
2191 cGlyphs = analysis->glyphs[iItem].pwLogClust[runEnd] - iGlyph;
2192
2193 cGlyphs++;
2194
2195 /* adjust for cluster glyphs when starting */
2196 if (analysis->pItem[iItem].a.fRTL)
2197 i = analysis->pItem[iItem+1].iCharPos - 1;
2198 else
2199 i = analysis->pItem[iItem].iCharPos;
2200
2201 for (; i >=analysis->pItem[iItem].iCharPos && i < analysis->pItem[iItem+1].iCharPos; (analysis->pItem[iItem].a.fRTL)?i--:i++)
2202 {
2203 if (analysis->glyphs[iItem].pwLogClust[i - analysis->pItem[iItem].iCharPos] == iGlyph)
2204 {
2205 if (analysis->pItem[iItem].a.fRTL)
2206 ScriptStringCPtoX(ssa, i, TRUE, &off_x);
2207 else
2208 ScriptStringCPtoX(ssa, i, FALSE, &off_x);
2209 break;
2210 }
2211 }
2212
2213 if (cEnd < 0 || scriptInformation[analysis->pItem[iItem].a.eScript].props.fNeedsCaretInfo)
2214 {
2215 INT direction;
2216 INT clust_glyph;
2217
2218 clust_glyph = iGlyph + cGlyphs;
2219 if (analysis->pItem[iItem].a.fRTL)
2220 direction = -1;
2221 else
2222 direction = 1;
2223
2224 while(clust_glyph < analysis->glyphs[iItem].numGlyphs &&
2225 !does_glyph_start_cluster(analysis->glyphs[iItem].psva, analysis->glyphs[iItem].pwLogClust, (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos), clust_glyph, direction))
2226 {
2227 cGlyphs++;
2228 clust_glyph++;
2229 }
2230 }
2231
2232 hr = ScriptTextOut(analysis->hdc,
2233 (SCRIPT_CACHE *)&analysis->glyphs[iItem].sc, iX + off_x,
2234 iY, uOptions, &crc, &analysis->pItem[iItem].a, NULL, 0,
2235 &analysis->glyphs[iItem].glyphs[iGlyph], cGlyphs,
2236 &analysis->glyphs[iItem].piAdvance[iGlyph], NULL,
2237 &analysis->glyphs[iItem].pGoffset[iGlyph]);
2238
2239 TRACE("ScriptTextOut hr=%08x\n", hr);
2240
2241 if (fSelected)
2242 {
2243 SetBkColor(analysis->hdc, BkColor);
2244 SetBkMode( analysis->hdc, BkMode);
2245 if (!fDisabled)
2246 SetTextColor(analysis->hdc, TextColor);
2247 }
2248 if (analysis->glyphs[iItem].fallbackFont)
2249 SelectObject(analysis->hdc, oldFont);
2250
2251 return hr;
2252 }
2253
2254 /***********************************************************************
2255 * ScriptStringOut (USP10.@)
2256 *
2257 * This function takes the output of ScriptStringAnalyse and joins the segments
2258 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
2259 * only processes glyphs.
2260 *
2261 * Parameters:
2262 * ssa [I] buffer to hold the analysed string components
2263 * iX [I] X axis displacement for output
2264 * iY [I] Y axis displacement for output
2265 * uOptions [I] flags controlling output processing
2266 * prc [I] rectangle coordinates
2267 * iMinSel [I] starting pos for substringing output string
2268 * iMaxSel [I] ending pos for substringing output string
2269 * fDisabled [I] controls text highlighting
2270 *
2271 * RETURNS
2272 * Success: S_OK
2273 * Failure: is the value returned by ScriptTextOut
2274 */
2275 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
2276 int iX,
2277 int iY,
2278 UINT uOptions,
2279 const RECT *prc,
2280 int iMinSel,
2281 int iMaxSel,
2282 BOOL fDisabled)
2283 {
2284 StringAnalysis *analysis;
2285 int item;
2286 HRESULT hr;
2287
2288 TRACE("(%p,%d,%d,0x%08x,%s,%d,%d,%d)\n",
2289 ssa, iX, iY, uOptions, wine_dbgstr_rect(prc), iMinSel, iMaxSel, fDisabled);
2290
2291 if (!(analysis = ssa)) return E_INVALIDARG;
2292 if (!(analysis->dwFlags & SSA_GLYPHS)) return E_INVALIDARG;
2293
2294 for (item = 0; item < analysis->numItems; item++)
2295 {
2296 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], -1, -1, uOptions, prc, FALSE, fDisabled);
2297 if (FAILED(hr))
2298 return hr;
2299 }
2300
2301 if (iMinSel < iMaxSel && (iMinSel > 0 || iMaxSel > 0))
2302 {
2303 if (iMaxSel > 0 && iMinSel < 0)
2304 iMinSel = 0;
2305 for (item = 0; item < analysis->numItems; item++)
2306 {
2307 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], iMinSel, iMaxSel, uOptions, prc, TRUE, fDisabled);
2308 if (FAILED(hr))
2309 return hr;
2310 }
2311 }
2312
2313 return S_OK;
2314 }
2315
2316 /***********************************************************************
2317 * ScriptStringCPtoX (USP10.@)
2318 *
2319 */
2320 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
2321 {
2322 int item;
2323 int runningX = 0;
2324 StringAnalysis* analysis = ssa;
2325
2326 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
2327
2328 if (!ssa || !pX) return S_FALSE;
2329 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2330
2331 /* icp out of range */
2332 if(icp < 0)
2333 {
2334 analysis->invalid = TRUE;
2335 return E_INVALIDARG;
2336 }
2337
2338 for(item=0; item<analysis->numItems; item++)
2339 {
2340 int CP, i;
2341 int offset;
2342
2343 i = analysis->logical2visual[item];
2344 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2345 /* initialize max extents for uninitialized runs */
2346 if (analysis->glyphs[i].iMaxPosX == -1)
2347 {
2348 if (analysis->pItem[i].a.fRTL)
2349 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2350 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2351 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2352 else
2353 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2354 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2355 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2356 }
2357
2358 if (icp >= analysis->pItem[i+1].iCharPos || icp < analysis->pItem[i].iCharPos)
2359 {
2360 runningX += analysis->glyphs[i].iMaxPosX;
2361 continue;
2362 }
2363
2364 icp -= analysis->pItem[i].iCharPos;
2365 ScriptCPtoX(icp, fTrailing, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2366 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2367 &analysis->pItem[i].a, &offset);
2368 runningX += offset;
2369
2370 *pX = runningX;
2371 return S_OK;
2372 }
2373
2374 /* icp out of range */
2375 analysis->invalid = TRUE;
2376 return E_INVALIDARG;
2377 }
2378
2379 /***********************************************************************
2380 * ScriptStringXtoCP (USP10.@)
2381 *
2382 */
2383 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
2384 {
2385 StringAnalysis* analysis = ssa;
2386 int item;
2387
2388 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
2389
2390 if (!ssa || !piCh || !piTrailing) return S_FALSE;
2391 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2392
2393 /* out of range */
2394 if(iX < 0)
2395 {
2396 if (analysis->pItem[0].a.fRTL)
2397 {
2398 *piCh = 1;
2399 *piTrailing = FALSE;
2400 }
2401 else
2402 {
2403 *piCh = -1;
2404 *piTrailing = TRUE;
2405 }
2406 return S_OK;
2407 }
2408
2409 for(item=0; item<analysis->numItems; item++)
2410 {
2411 int i;
2412 int CP;
2413
2414 for (i = 0; i < analysis->numItems && analysis->logical2visual[i] != item; i++)
2415 /* nothing */;
2416
2417 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2418 /* initialize max extents for uninitialized runs */
2419 if (analysis->glyphs[i].iMaxPosX == -1)
2420 {
2421 if (analysis->pItem[i].a.fRTL)
2422 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2423 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2424 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2425 else
2426 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2427 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2428 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2429 }
2430
2431 if (iX > analysis->glyphs[i].iMaxPosX)
2432 {
2433 iX -= analysis->glyphs[i].iMaxPosX;
2434 continue;
2435 }
2436
2437 ScriptXtoCP(iX, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2438 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2439 &analysis->pItem[i].a, piCh, piTrailing);
2440 *piCh += analysis->pItem[i].iCharPos;
2441
2442 return S_OK;
2443 }
2444
2445 /* out of range */
2446 *piCh = analysis->pItem[analysis->numItems].iCharPos;
2447 *piTrailing = FALSE;
2448
2449 return S_OK;
2450 }
2451
2452
2453 /***********************************************************************
2454 * ScriptStringFree (USP10.@)
2455 *
2456 * Free a string analysis.
2457 *
2458 * PARAMS
2459 * pssa [I] string analysis.
2460 *
2461 * RETURNS
2462 * Success: S_OK
2463 * Failure: Non-zero HRESULT value.
2464 */
2465 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
2466 {
2467 StringAnalysis* analysis;
2468 BOOL invalid;
2469 int i;
2470
2471 TRACE("(%p)\n", pssa);
2472
2473 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
2474
2475 invalid = analysis->invalid;
2476
2477 if (analysis->glyphs)
2478 {
2479 for (i = 0; i < analysis->numItems; i++)
2480 {
2481 heap_free(analysis->glyphs[i].glyphs);
2482 heap_free(analysis->glyphs[i].pwLogClust);
2483 heap_free(analysis->glyphs[i].piAdvance);
2484 heap_free(analysis->glyphs[i].psva);
2485 heap_free(analysis->glyphs[i].pGoffset);
2486 heap_free(analysis->glyphs[i].abc);
2487 if (analysis->glyphs[i].fallbackFont)
2488 DeleteObject(analysis->glyphs[i].fallbackFont);
2489 ScriptFreeCache((SCRIPT_CACHE *)&analysis->glyphs[i].sc);
2490 heap_free(analysis->glyphs[i].sc);
2491 }
2492 heap_free(analysis->glyphs);
2493 }
2494
2495 heap_free(analysis->pItem);
2496 heap_free(analysis->logattrs);
2497 heap_free(analysis->sz);
2498 heap_free(analysis->logical2visual);
2499 heap_free(analysis);
2500
2501 if (invalid) return E_INVALIDARG;
2502 return S_OK;
2503 }
2504
2505 static inline int get_cluster_size(const WORD *pwLogClust, int cChars, int item,
2506 int direction, int* iCluster, int *check_out)
2507 {
2508 int clust_size = 1;
2509 int check;
2510 WORD clust = pwLogClust[item];
2511
2512 for (check = item+direction; check < cChars && check >= 0; check+=direction)
2513 {
2514 if (pwLogClust[check] == clust)
2515 {
2516 clust_size ++;
2517 if (iCluster && *iCluster == -1)
2518 *iCluster = item;
2519 }
2520 else break;
2521 }
2522
2523 if (check_out)
2524 *check_out = check;
2525
2526 return clust_size;
2527 }
2528
2529 static inline int get_glyph_cluster_advance(const int* piAdvance, const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cGlyphs, int cChars, int glyph, int direction)
2530 {
2531 int advance;
2532 int log_clust_max;
2533
2534 advance = piAdvance[glyph];
2535
2536 if (pwLogClust[0] > pwLogClust[cChars-1])
2537 log_clust_max = pwLogClust[0];
2538 else
2539 log_clust_max = pwLogClust[cChars-1];
2540
2541 if (glyph > log_clust_max)
2542 return advance;
2543
2544 for (glyph+=direction; glyph < cGlyphs && glyph >= 0; glyph +=direction)
2545 {
2546
2547 if (does_glyph_start_cluster(pva, pwLogClust, cChars, glyph, direction))
2548 break;
2549 if (glyph > log_clust_max)
2550 break;
2551 advance += piAdvance[glyph];
2552 }
2553
2554 return advance;
2555 }
2556
2557 /***********************************************************************
2558 * ScriptCPtoX (USP10.@)
2559 *
2560 */
2561 HRESULT WINAPI ScriptCPtoX(int iCP,
2562 BOOL fTrailing,
2563 int cChars,
2564 int cGlyphs,
2565 const WORD *pwLogClust,
2566 const SCRIPT_VISATTR *psva,
2567 const int *piAdvance,
2568 const SCRIPT_ANALYSIS *psa,
2569 int *piX)
2570 {
2571 int item;
2572 float iPosX;
2573 int iSpecial = -1;
2574 int iCluster = -1;
2575 int clust_size = 1;
2576 float special_size = 0.0;
2577 int iMaxPos = 0;
2578 int advance = 0;
2579 BOOL rtl = FALSE;
2580
2581 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2582 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
2583 psa, piX);
2584
2585 if (psa->fRTL && ! psa->fLogicalOrder)
2586 rtl = TRUE;
2587
2588 if (fTrailing)
2589 iCP++;
2590
2591 if (rtl)
2592 {
2593 int max_clust = pwLogClust[0];
2594
2595 for (item=0; item < cGlyphs; item++)
2596 if (pwLogClust[item] > max_clust)
2597 {
2598 ERR("We do not handle non reversed clusters properly\n");
2599 break;
2600 }
2601
2602 iMaxPos = 0;
2603 for (item = max_clust; item >=0; item --)
2604 iMaxPos += piAdvance[item];
2605 }
2606
2607 iPosX = 0.0;
2608 for (item=0; item < iCP && item < cChars; item++)
2609 {
2610 if (iSpecial == -1 && (iCluster == -1 || (iCluster != -1 && iCluster+clust_size <= item)))
2611 {
2612 int check;
2613 int clust = pwLogClust[item];
2614
2615 iCluster = -1;
2616 clust_size = get_cluster_size(pwLogClust, cChars, item, 1, &iCluster,
2617 &check);
2618
2619 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, 1);
2620
2621 if (check >= cChars && !iMaxPos)
2622 {
2623 int glyph;
2624 for (glyph = clust; glyph < cGlyphs; glyph++)
2625 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, glyph, 1);
2626 iSpecial = item;
2627 special_size /= (cChars - item);
2628 iPosX += special_size;
2629 }
2630 else
2631 {
2632 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2633 {
2634 clust_size --;
2635 if (clust_size == 0)
2636 iPosX += advance;
2637 }
2638 else
2639 iPosX += advance / (float)clust_size;
2640 }
2641 }
2642 else if (iSpecial != -1)
2643 iPosX += special_size;
2644 else /* (iCluster != -1) */
2645 {
2646 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], 1);
2647 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2648 {
2649 clust_size --;
2650 if (clust_size == 0)
2651 iPosX += adv;
2652 }
2653 else
2654 iPosX += adv / (float)clust_size;
2655 }
2656 }
2657
2658 if (iMaxPos > 0)
2659 {
2660 iPosX = iMaxPos - iPosX;
2661 if (iPosX < 0)
2662 iPosX = 0;
2663 }
2664
2665 *piX = iPosX;
2666 TRACE("*piX=%d\n", *piX);
2667 return S_OK;
2668 }
2669
2670 /* Count the number of characters in a cluster and its starting index*/
2671 static inline BOOL get_cluster_data(const WORD *pwLogClust, int cChars, int cluster_index, int *cluster_size, int *start_index)
2672 {
2673 int size = 0;
2674 int i;
2675
2676 for (i = 0; i < cChars; i++)
2677 {
2678 if (pwLogClust[i] == cluster_index)
2679 {
2680 if (!size && start_index)
2681 {
2682 *start_index = i;
2683 if (!cluster_size)
2684 return TRUE;
2685 }
2686 size++;
2687 }
2688 else if (size) break;
2689 }
2690 if (cluster_size)
2691 *cluster_size = size;