[USP10] Sync with Wine Staging 1.9.4. CORE-10912
[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 /* the 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, 1, 1, 0, 0, 0, 0, { 1,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, 1, 1, 0, 0, 0, 0, { 1,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('s','y','r','c'),
337 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',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: unknow 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[];
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;
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 Symboles 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
914 if (type == 0)
915 return SCRIPT_UNDEFINED;
916
917 if (type & C1_CNTRL)
918 return Script_Control;
919
920 ch = decode_surrogate_pair(str, index, end);
921 if (ch)
922 *consumed = 2;
923 else
924 ch = str[index];
925
926 i = 0;
927 do
928 {
929 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
930 break;
931
932 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
933 {
934 if (scriptRanges[i].numericScript && type & C1_DIGIT)
935 return scriptRanges[i].numericScript;
936 if (scriptRanges[i].punctScript && type & C1_PUNCT)
937 return scriptRanges[i].punctScript;
938 return scriptRanges[i].script;
939 }
940 i++;
941 } while (1);
942
943 return SCRIPT_UNDEFINED;
944 }
945
946 static int compare_FindGlyph(const void *a, const void* b)
947 {
948 const FindGlyph_struct *find = (FindGlyph_struct*)a;
949 const WORD *idx= (WORD*)b;
950 int rc = 0;
951
952 if ( find->target > *idx)
953 rc = 1;
954 else if (find->target < *idx)
955 rc = -1;
956
957 if (!find->ascending)
958 rc *= -1;
959 return rc;
960 }
961
962 int USP10_FindGlyphInLogClust(const WORD* pwLogClust, int cChars, WORD target)
963 {
964 FindGlyph_struct fgs;
965 WORD *ptr;
966 INT k;
967
968 if (pwLogClust[0] < pwLogClust[cChars-1])
969 fgs.ascending = TRUE;
970 else
971 fgs.ascending = FALSE;
972
973 fgs.target = target;
974 ptr = bsearch(&fgs, pwLogClust, cChars, sizeof(WORD), compare_FindGlyph);
975
976 if (!ptr)
977 return -1;
978
979 for (k = (ptr - pwLogClust)-1; k >= 0 && pwLogClust[k] == target; k--)
980 ;
981 k++;
982
983 return k;
984 }
985
986 /***********************************************************************
987 * ScriptFreeCache (USP10.@)
988 *
989 * Free a script cache.
990 *
991 * PARAMS
992 * psc [I/O] Script cache.
993 *
994 * RETURNS
995 * Success: S_OK
996 * Failure: Non-zero HRESULT value.
997 */
998 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
999 {
1000 TRACE("%p\n", psc);
1001
1002 if (psc && *psc)
1003 {
1004 unsigned int i;
1005 INT n;
1006 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
1007 {
1008 heap_free(((ScriptCache *)*psc)->widths[i]);
1009 }
1010 for (i = 0; i < 0x10; i++)
1011 {
1012 unsigned int j;
1013 if (((ScriptCache *)*psc)->page[i])
1014 for (j = 0; j < GLYPH_MAX / GLYPH_BLOCK_SIZE; j++)
1015 heap_free(((ScriptCache *)*psc)->page[i]->glyphs[j]);
1016 heap_free(((ScriptCache *)*psc)->page[i]);
1017 }
1018 heap_free(((ScriptCache *)*psc)->GSUB_Table);
1019 heap_free(((ScriptCache *)*psc)->GDEF_Table);
1020 heap_free(((ScriptCache *)*psc)->CMAP_Table);
1021 heap_free(((ScriptCache *)*psc)->GPOS_Table);
1022 for (n = 0; n < ((ScriptCache *)*psc)->script_count; n++)
1023 {
1024 int j;
1025 for (j = 0; j < ((ScriptCache *)*psc)->scripts[n].language_count; j++)
1026 {
1027 int k;
1028 for (k = 0; k < ((ScriptCache *)*psc)->scripts[n].languages[j].feature_count; k++)
1029 heap_free(((ScriptCache *)*psc)->scripts[n].languages[j].features[k].lookups);
1030 heap_free(((ScriptCache *)*psc)->scripts[n].languages[j].features);
1031 }
1032 for (j = 0; j < ((ScriptCache *)*psc)->scripts[n].default_language.feature_count; j++)
1033 heap_free(((ScriptCache *)*psc)->scripts[n].default_language.features[j].lookups);
1034 heap_free(((ScriptCache *)*psc)->scripts[n].default_language.features);
1035 heap_free(((ScriptCache *)*psc)->scripts[n].languages);
1036 }
1037 heap_free(((ScriptCache *)*psc)->scripts);
1038 heap_free(((ScriptCache *)*psc)->otm);
1039 heap_free(*psc);
1040 *psc = NULL;
1041 }
1042 return S_OK;
1043 }
1044
1045 /***********************************************************************
1046 * ScriptGetProperties (USP10.@)
1047 *
1048 * Retrieve a list of script properties.
1049 *
1050 * PARAMS
1051 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
1052 * num [I] Pointer to the number of scripts.
1053 *
1054 * RETURNS
1055 * Success: S_OK
1056 * Failure: Non-zero HRESULT value.
1057 *
1058 * NOTES
1059 * Behaviour matches WinXP.
1060 */
1061 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
1062 {
1063 TRACE("(%p,%p)\n", props, num);
1064
1065 if (!props && !num) return E_INVALIDARG;
1066
1067 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
1068 if (props) *props = script_props;
1069
1070 return S_OK;
1071 }
1072
1073 /***********************************************************************
1074 * ScriptGetFontProperties (USP10.@)
1075 *
1076 * Get information on special glyphs.
1077 *
1078 * PARAMS
1079 * hdc [I] Device context.
1080 * psc [I/O] Opaque pointer to a script cache.
1081 * sfp [O] Font properties structure.
1082 */
1083 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
1084 {
1085 HRESULT hr;
1086
1087 TRACE("%p,%p,%p\n", hdc, psc, sfp);
1088
1089 if (!sfp) return E_INVALIDARG;
1090 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1091
1092 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
1093 return E_INVALIDARG;
1094
1095 get_cache_font_properties(sfp, *psc);
1096
1097 return S_OK;
1098 }
1099
1100 /***********************************************************************
1101 * ScriptRecordDigitSubstitution (USP10.@)
1102 *
1103 * Record digit substitution settings for a given locale.
1104 *
1105 * PARAMS
1106 * locale [I] Locale identifier.
1107 * sds [I] Structure to record substitution settings.
1108 *
1109 * RETURNS
1110 * Success: S_OK
1111 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
1112 *
1113 * SEE ALSO
1114 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
1115 */
1116 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
1117 {
1118 DWORD plgid, sub;
1119
1120 TRACE("0x%x, %p\n", locale, sds);
1121
1122 /* This implementation appears to be correct for all languages, but it's
1123 * not clear if sds->DigitSubstitute is ever set to anything except
1124 * CONTEXT or NONE in reality */
1125
1126 if (!sds) return E_POINTER;
1127
1128 locale = ConvertDefaultLocale(locale);
1129
1130 if (!IsValidLocale(locale, LCID_INSTALLED))
1131 return E_INVALIDARG;
1132
1133 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
1134 sds->TraditionalDigitLanguage = plgid;
1135
1136 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
1137 sds->NationalDigitLanguage = plgid;
1138 else
1139 sds->NationalDigitLanguage = LANG_ENGLISH;
1140
1141 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
1142 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
1143
1144 switch (sub)
1145 {
1146 case 0:
1147 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
1148 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
1149 else
1150 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
1151 break;
1152 case 1:
1153 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
1154 break;
1155 case 2:
1156 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
1157 break;
1158 default:
1159 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
1160 break;
1161 }
1162
1163 sds->dwReserved = 0;
1164 return S_OK;
1165 }
1166
1167 /***********************************************************************
1168 * ScriptApplyDigitSubstitution (USP10.@)
1169 *
1170 * Apply digit substitution settings.
1171 *
1172 * PARAMS
1173 * sds [I] Structure with recorded substitution settings.
1174 * sc [I] Script control structure.
1175 * ss [I] Script state structure.
1176 *
1177 * RETURNS
1178 * Success: S_OK
1179 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
1180 */
1181 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
1182 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
1183 {
1184 SCRIPT_DIGITSUBSTITUTE psds;
1185
1186 TRACE("%p, %p, %p\n", sds, sc, ss);
1187
1188 if (!sc || !ss) return E_POINTER;
1189 if (!sds)
1190 {
1191 sds = &psds;
1192 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
1193 return E_INVALIDARG;
1194 }
1195
1196 sc->uDefaultLanguage = LANG_ENGLISH;
1197 sc->fContextDigits = 0;
1198 ss->fDigitSubstitute = 0;
1199
1200 switch (sds->DigitSubstitute) {
1201 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
1202 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
1203 case SCRIPT_DIGITSUBSTITUTE_NONE:
1204 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
1205 return S_OK;
1206 default:
1207 return E_INVALIDARG;
1208 }
1209 }
1210
1211 static inline BOOL is_indic(WORD script)
1212 {
1213 return (script >= Script_Devanagari && script <= Script_Malayalam_Numeric);
1214 }
1215
1216 static inline WORD base_indic(WORD script)
1217 {
1218 switch (script)
1219 {
1220 case Script_Devanagari:
1221 case Script_Devanagari_Numeric: return Script_Devanagari;
1222 case Script_Bengali:
1223 case Script_Bengali_Numeric:
1224 case Script_Bengali_Currency: return Script_Bengali;
1225 case Script_Gurmukhi:
1226 case Script_Gurmukhi_Numeric: return Script_Gurmukhi;
1227 case Script_Gujarati:
1228 case Script_Gujarati_Numeric:
1229 case Script_Gujarati_Currency: return Script_Gujarati;
1230 case Script_Oriya:
1231 case Script_Oriya_Numeric: return Script_Oriya;
1232 case Script_Tamil:
1233 case Script_Tamil_Numeric: return Script_Tamil;
1234 case Script_Telugu:
1235 case Script_Telugu_Numeric: return Script_Telugu;
1236 case Script_Kannada:
1237 case Script_Kannada_Numeric: return Script_Kannada;
1238 case Script_Malayalam:
1239 case Script_Malayalam_Numeric: return Script_Malayalam;
1240 default:
1241 return -1;
1242 };
1243 }
1244
1245
1246 static HRESULT _ItemizeInternal(const WCHAR *pwcInChars, int cInChars,
1247 int cMaxItems, const SCRIPT_CONTROL *psControl,
1248 const SCRIPT_STATE *psState, SCRIPT_ITEM *pItems,
1249 OPENTYPE_TAG *pScriptTags, int *pcItems)
1250 {
1251
1252 #define Numeric_space 0x0020
1253 #define ZWNJ 0x200C
1254 #define ZWJ 0x200D
1255
1256 int cnt = 0, index = 0, str = 0;
1257 int New_Script = -1;
1258 int i;
1259 WORD *levels = NULL;
1260 WORD *layout_levels = NULL;
1261 WORD *overrides = NULL;
1262 WORD *strength = NULL;
1263 WORD *scripts = NULL;
1264 WORD baselevel = 0;
1265 WORD baselayout = 0;
1266 BOOL new_run;
1267 WORD last_indic = -1;
1268 WORD layoutRTL = 0;
1269 BOOL forceLevels = FALSE;
1270 INT consumed = 0;
1271 HRESULT res = E_OUTOFMEMORY;
1272
1273 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
1274 psControl, psState, pItems, pcItems);
1275
1276 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
1277 return E_INVALIDARG;
1278
1279 scripts = heap_alloc(cInChars * sizeof(WORD));
1280 if (!scripts)
1281 return E_OUTOFMEMORY;
1282
1283 for (i = 0; i < cInChars; i++)
1284 {
1285 if (consumed <= 0)
1286 {
1287 scripts[i] = get_char_script(pwcInChars,i,cInChars,&consumed);
1288 consumed --;
1289 }
1290 else
1291 {
1292 scripts[i] = scripts[i-1];
1293 consumed --;
1294 }
1295 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1296 all Indic scripts */
1297 if ((pwcInChars[i] == 0x964 || pwcInChars[i] ==0x965) && last_indic > 0)
1298 scripts[i] = last_indic;
1299 else if (is_indic(scripts[i]))
1300 last_indic = base_indic(scripts[i]);
1301
1302 /* Some unicode points :
1303 (Zero Width Space U+200B - Right-to-Left Mark U+200F)
1304 (Left Right Embed U+202A - Left Right Override U+202D)
1305 (Left Right Isolate U+2066 - Pop Directional Isolate U+2069)
1306 will force us into bidi mode */
1307 if (!forceLevels && ((pwcInChars[i] >= 0x200B && pwcInChars[i] <= 0x200F) ||
1308 (pwcInChars[i] >= 0x202A && pwcInChars[i] <= 0x202E) ||
1309 (pwcInChars[i] >= 0x2066 && pwcInChars[i] <= 0x2069)))
1310
1311 forceLevels = TRUE;
1312
1313 /* Diacritical marks merge with other scripts */
1314 if (scripts[i] == Script_Diacritical)
1315 {
1316 if (i > 0)
1317 {
1318 if (pScriptTags)
1319 scripts[i] = scripts[i-1];
1320 else
1321 {
1322 int j;
1323 BOOL asian = FALSE;
1324 WORD first_script = scripts[i-1];
1325 for (j = i-1; j >= 0 && scripts[j] == first_script && pwcInChars[j] != Numeric_space; j--)
1326 {
1327 WORD original = scripts[j];
1328 if (original == Script_Ideograph || original == Script_Kana || original == Script_Yi || original == Script_CJK_Han || original == Script_Bopomofo)
1329 {
1330 asian = TRUE;
1331 break;
1332 }
1333 if (original != Script_MathAlpha && scriptInformation[scripts[j]].props.fComplex)
1334 break;
1335 scripts[j] = scripts[i];
1336 if (original == Script_Punctuation2)
1337 break;
1338 }
1339 if (j >= 0 && (scriptInformation[scripts[j]].props.fComplex || asian))
1340 scripts[i] = scripts[j];
1341 }
1342 }
1343 }
1344 }
1345
1346 for (i = 0; i < cInChars; i++)
1347 {
1348 /* Joiners get merged preferencially right */
1349 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1350 {
1351 int j;
1352 if (i+1 == cInChars)
1353 scripts[i] = scripts[i-1];
1354 else
1355 {
1356 for (j = i+1; j < cInChars; j++)
1357 {
1358 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1359 {
1360 scripts[i] = scripts[j];
1361 break;
1362 }
1363 }
1364 }
1365 }
1366 }
1367
1368 if (psState && psControl)
1369 {
1370 levels = heap_alloc_zero(cInChars * sizeof(WORD));
1371 if (!levels)
1372 goto nomemory;
1373
1374 overrides = heap_alloc_zero(cInChars * sizeof(WORD));
1375 if (!overrides)
1376 goto nomemory;
1377
1378 layout_levels = heap_alloc_zero(cInChars * sizeof(WORD));
1379 if (!layout_levels)
1380 goto nomemory;
1381
1382 if (psState->fOverrideDirection)
1383 {
1384 if (!forceLevels)
1385 {
1386 SCRIPT_STATE s = *psState;
1387 s.fOverrideDirection = FALSE;
1388 BIDI_DetermineLevels(pwcInChars, cInChars, &s, psControl, layout_levels, overrides);
1389 if (odd(layout_levels[0]))
1390 forceLevels = TRUE;
1391 else for (i = 0; i < cInChars; i++)
1392 if (layout_levels[i]!=layout_levels[0])
1393 {
1394 forceLevels = TRUE;
1395 break;
1396 }
1397 }
1398
1399 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels, overrides);
1400 }
1401 else
1402 {
1403 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels, overrides);
1404 memcpy(layout_levels, levels, cInChars * sizeof(WORD));
1405 }
1406 baselevel = levels[0];
1407 baselayout = layout_levels[0];
1408 for (i = 0; i < cInChars; i++)
1409 if (levels[i]!=levels[0])
1410 break;
1411 if (i >= cInChars && !odd(baselevel) && !odd(psState->uBidiLevel) && !forceLevels)
1412 {
1413 heap_free(levels);
1414 heap_free(overrides);
1415 heap_free(layout_levels);
1416 overrides = NULL;
1417 levels = NULL;
1418 layout_levels = NULL;
1419 }
1420 else
1421 {
1422 static const WCHAR math_punc[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1423 static const WCHAR repeatable_math_punc[] = {'#','$','%','+','-','/',0x2212, 0x2044,0};
1424
1425 strength = heap_alloc_zero(cInChars * sizeof(WORD));
1426 if (!strength)
1427 goto nomemory;
1428 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
1429
1430 /* We currently mis-level leading Diacriticals */
1431 if (scripts[0] == Script_Diacritical)
1432 for (i = 0; i < cInChars && scripts[0] == Script_Diacritical; i++)
1433 {
1434 levels[i] = odd(levels[i])?levels[i]+1:levels[i];
1435 strength[i] = BIDI_STRONG;
1436 }
1437
1438 /* Math punctuation bordered on both sides by numbers can be
1439 merged into the number */
1440 for (i = 0; i < cInChars; i++)
1441 {
1442 if (i > 0 && i < cInChars-1 &&
1443 scripts[i-1] == Script_Numeric &&
1444 strchrW(math_punc, pwcInChars[i]))
1445 {
1446 if (scripts[i+1] == Script_Numeric)
1447 {
1448 scripts[i] = Script_Numeric;
1449 levels[i] = levels[i-1];
1450 strength[i] = strength[i-1];
1451 i++;
1452 }
1453 else if (strchrW(repeatable_math_punc, pwcInChars[i]))
1454 {
1455 int j;
1456 for (j = i+1; j < cInChars; j++)
1457 {
1458 if (scripts[j] == Script_Numeric)
1459 {
1460 for(;i<j; i++)
1461 {
1462 scripts[i] = Script_Numeric;
1463 levels[i] = levels[i-1];
1464 strength[i] = strength[i-1];
1465 }
1466 }
1467 else if (pwcInChars[i] != pwcInChars[j]) break;
1468 }
1469 }
1470 }
1471 }
1472
1473 for (i = 0; i < cInChars; i++)
1474 {
1475 /* Script_Numeric at level 0 get bumped to level 2 */
1476 if (!overrides[i] && (levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && scripts[i] == Script_Numeric)
1477 {
1478 levels[i] = 2;
1479 }
1480
1481 /* Joiners get merged preferencially right */
1482 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1483 {
1484 int j;
1485 if (i+1 == cInChars && levels[i-1] == levels[i])
1486 strength[i] = strength[i-1];
1487 else
1488 for (j = i+1; j < cInChars && levels[i] == levels[j]; j++)
1489 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1490 {
1491 strength[i] = strength[j];
1492 break;
1493 }
1494 }
1495 }
1496 if (psControl->fMergeNeutralItems)
1497 {
1498 /* Merge the neutrals */
1499 for (i = 0; i < cInChars; i++)
1500 {
1501 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1502 {
1503 int j;
1504 for (j = i; j > 0; j--)
1505 {
1506 if (levels[i] != levels[j])
1507 break;
1508 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1509 {
1510 scripts[i] = scripts[j];
1511 strength[i] = strength[j];
1512 break;
1513 }
1514 }
1515 }
1516 /* Try going the other way */
1517 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1518 {
1519 int j;
1520 for (j = i; j < cInChars; j++)
1521 {
1522 if (levels[i] != levels[j])
1523 break;
1524 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1525 {
1526 scripts[i] = scripts[j];
1527 strength[i] = strength[j];
1528 break;
1529 }
1530 }
1531 }
1532 }
1533 }
1534 }
1535 }
1536
1537 while ((!levels || (levels && cnt+1 < cInChars && levels[cnt+1] == levels[0]))
1538 && (cnt < cInChars && pwcInChars[cnt] == Numeric_space))
1539 cnt++;
1540
1541 if (cnt == cInChars) /* All Spaces */
1542 {
1543 cnt = 0;
1544 New_Script = scripts[cnt];
1545 }
1546
1547 pItems[index].iCharPos = 0;
1548 pItems[index].a = scriptInformation[scripts[cnt]].a;
1549 if (pScriptTags)
1550 pScriptTags[index] = scriptInformation[scripts[cnt]].scriptTag;
1551
1552 if (strength && strength[cnt] == BIDI_STRONG)
1553 str = strength[cnt];
1554 else if (strength)
1555 str = strength[0];
1556
1557 cnt = 0;
1558
1559 if (levels)
1560 {
1561 if (strength[cnt] == BIDI_STRONG)
1562 layoutRTL = odd(layout_levels[cnt]);
1563 else
1564 layoutRTL = (psState->uBidiLevel || odd(layout_levels[cnt]));
1565 if (overrides)
1566 pItems[index].a.s.fOverrideDirection = (overrides[cnt] != 0);
1567 pItems[index].a.fRTL = odd(levels[cnt]);
1568 if (pItems[index].a.eScript == Script_Numeric ||
1569 pItems[index].a.eScript == Script_Numeric2)
1570 pItems[index].a.fLayoutRTL = layoutRTL;
1571 else
1572 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1573 pItems[index].a.s.uBidiLevel = levels[cnt];
1574 }
1575 else if (!pItems[index].a.s.uBidiLevel || (overrides && overrides[cnt]))
1576 {
1577 if (pItems[index].a.s.uBidiLevel != baselevel)
1578 pItems[index].a.s.fOverrideDirection = TRUE;
1579 layoutRTL = odd(baselayout);
1580 pItems[index].a.s.uBidiLevel = baselevel;
1581 pItems[index].a.fRTL = odd(baselevel);
1582 if (pItems[index].a.eScript == Script_Numeric ||
1583 pItems[index].a.eScript == Script_Numeric2)
1584 pItems[index].a.fLayoutRTL = odd(baselayout);
1585 else
1586 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1587 }
1588
1589 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1590 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
1591 pItems[index].iCharPos);
1592
1593 for (cnt=1; cnt < cInChars; cnt++)
1594 {
1595 if(pwcInChars[cnt] != Numeric_space)
1596 New_Script = scripts[cnt];
1597 else if (levels)
1598 {
1599 int j = 1;
1600 while (cnt + j < cInChars - 1 && pwcInChars[cnt+j] == Numeric_space && levels[cnt] == levels[cnt+j])
1601 j++;
1602 if (cnt + j < cInChars && levels[cnt] == levels[cnt+j])
1603 New_Script = scripts[cnt+j];
1604 else
1605 New_Script = scripts[cnt];
1606 }
1607
1608 new_run = FALSE;
1609 /* merge space strengths*/
1610 if (strength && strength[cnt] == BIDI_STRONG && str != BIDI_STRONG && New_Script == pItems[index].a.eScript)
1611 str = BIDI_STRONG;
1612
1613 if (strength && strength[cnt] == BIDI_NEUTRAL && str == BIDI_STRONG && pwcInChars[cnt] != Numeric_space && New_Script == pItems[index].a.eScript)
1614 str = BIDI_NEUTRAL;
1615
1616 /* changes in level */
1617 if (levels && (levels[cnt] != pItems[index].a.s.uBidiLevel))
1618 {
1619 TRACE("Level break(%i/%i)\n",pItems[index].a.s.uBidiLevel,levels[cnt]);
1620 new_run = TRUE;
1621 }
1622 /* changes in strength */
1623 else if (strength && pwcInChars[cnt] != Numeric_space && str != strength[cnt])
1624 {
1625 TRACE("Strength break (%i/%i)\n",str,strength[cnt]);
1626 new_run = TRUE;
1627 }
1628 /* changes in script */
1629 else if (((pwcInChars[cnt] != Numeric_space) && (New_Script != -1) && (New_Script != pItems[index].a.eScript)) || (New_Script == Script_Control))
1630 {
1631 TRACE("Script break(%i/%i)\n",pItems[index].a.eScript,New_Script);
1632 new_run = TRUE;
1633 }
1634
1635 if (!new_run && strength && str == BIDI_STRONG)
1636 {
1637 layoutRTL = odd(layout_levels[cnt]);
1638 if (pItems[index].a.eScript == Script_Numeric ||
1639 pItems[index].a.eScript == Script_Numeric2)
1640 pItems[index].a.fLayoutRTL = layoutRTL;
1641 }
1642
1643 if (new_run)
1644 {
1645 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);
1646
1647 index++;
1648 if (index+1 > cMaxItems)
1649 goto nomemory;
1650
1651 if (strength)
1652 str = strength[cnt];
1653
1654 pItems[index].iCharPos = cnt;
1655 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1656
1657 pItems[index].a = scriptInformation[New_Script].a;
1658 if (pScriptTags)
1659 pScriptTags[index] = scriptInformation[New_Script].scriptTag;
1660 if (levels)
1661 {
1662 if (overrides)
1663 pItems[index].a.s.fOverrideDirection = (overrides[cnt] != 0);
1664 if (layout_levels[cnt] == 0)
1665 layoutRTL = 0;
1666 else
1667 layoutRTL = (layoutRTL || odd(layout_levels[cnt]));
1668 pItems[index].a.fRTL = odd(levels[cnt]);
1669 if (pItems[index].a.eScript == Script_Numeric ||
1670 pItems[index].a.eScript == Script_Numeric2)
1671 pItems[index].a.fLayoutRTL = layoutRTL;
1672 else
1673 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1674 pItems[index].a.s.uBidiLevel = levels[cnt];
1675 }
1676 else if (!pItems[index].a.s.uBidiLevel || (overrides && overrides[cnt]))
1677 {
1678 if (pItems[index].a.s.uBidiLevel != baselevel)
1679 pItems[index].a.s.fOverrideDirection = TRUE;
1680 pItems[index].a.s.uBidiLevel = baselevel;
1681 pItems[index].a.fRTL = odd(baselevel);
1682 if (pItems[index].a.eScript == Script_Numeric||
1683 pItems[index].a.eScript == Script_Numeric2)
1684 pItems[index].a.fLayoutRTL = layoutRTL;
1685 else
1686 pItems[index].a.fLayoutRTL = pItems[index].a.fRTL;
1687 }
1688
1689 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1690 }
1691 }
1692
1693 /* While not strictly necessary according to the spec, make sure the n+1
1694 * item is set up to prevent random behaviour if the caller erroneously
1695 * checks the n+1 structure */
1696 index++;
1697 if (index + 1 > cMaxItems) goto nomemory;
1698 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1699
1700 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1701
1702 /* Set one SCRIPT_STATE item being returned */
1703 if (pcItems) *pcItems = index;
1704
1705 /* Set SCRIPT_ITEM */
1706 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
1707 res = S_OK;
1708 nomemory:
1709 heap_free(levels);
1710 heap_free(overrides);
1711 heap_free(layout_levels);
1712 heap_free(strength);
1713 heap_free(scripts);
1714 return res;
1715 }
1716
1717 /***********************************************************************
1718 * ScriptItemizeOpenType (USP10.@)
1719 *
1720 * Split a Unicode string into shapeable parts.
1721 *
1722 * PARAMS
1723 * pwcInChars [I] String to split.
1724 * cInChars [I] Number of characters in pwcInChars.
1725 * cMaxItems [I] Maximum number of items to return.
1726 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1727 * psState [I] Pointer to a SCRIPT_STATE structure.
1728 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1729 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1730 * pcItems [O] Number of script items returned.
1731 *
1732 * RETURNS
1733 * Success: S_OK
1734 * Failure: Non-zero HRESULT value.
1735 */
1736 HRESULT WINAPI ScriptItemizeOpenType(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1737 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1738 SCRIPT_ITEM *pItems, OPENTYPE_TAG *pScriptTags, int *pcItems)
1739 {
1740 return _ItemizeInternal(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems);
1741 }
1742
1743 /***********************************************************************
1744 * ScriptItemize (USP10.@)
1745 *
1746 * Split a Unicode string into shapeable parts.
1747 *
1748 * PARAMS
1749 * pwcInChars [I] String to split.
1750 * cInChars [I] Number of characters in pwcInChars.
1751 * cMaxItems [I] Maximum number of items to return.
1752 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1753 * psState [I] Pointer to a SCRIPT_STATE structure.
1754 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1755 * pcItems [O] Number of script items returned.
1756 *
1757 * RETURNS
1758 * Success: S_OK
1759 * Failure: Non-zero HRESULT value.
1760 */
1761 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1762 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1763 SCRIPT_ITEM *pItems, int *pcItems)
1764 {
1765 return _ItemizeInternal(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, NULL, pcItems);
1766 }
1767
1768 static inline int getGivenTabWidth(ScriptCache *psc, SCRIPT_TABDEF *pTabdef, int charPos, int current_x)
1769 {
1770 int defWidth;
1771 int cTabStops=0;
1772 INT *lpTabPos = NULL;
1773 INT nTabOrg = 0;
1774 INT x = 0;
1775
1776 if (pTabdef)
1777 lpTabPos = pTabdef->pTabStops;
1778
1779 if (pTabdef && pTabdef->iTabOrigin)
1780 {
1781 if (pTabdef->iScale)
1782 nTabOrg = (pTabdef->iTabOrigin * pTabdef->iScale)/4;
1783 else
1784 nTabOrg = pTabdef->iTabOrigin * psc->tm.tmAveCharWidth;
1785 }
1786
1787 if (pTabdef)
1788 cTabStops = pTabdef->cTabStops;
1789
1790 if (cTabStops == 1)
1791 {
1792 if (pTabdef->iScale)
1793 defWidth = ((pTabdef->pTabStops[0])*pTabdef->iScale) / 4;
1794 else
1795 defWidth = (pTabdef->pTabStops[0])*psc->tm.tmAveCharWidth;
1796 cTabStops = 0;
1797 }
1798 else
1799 defWidth = 8 * psc->tm.tmAveCharWidth;
1800
1801 for (; cTabStops>0 ; lpTabPos++, cTabStops--)
1802 {
1803 int position = *lpTabPos;
1804 if (position < 0)
1805 position = -1 * position;
1806 if (pTabdef->iScale)
1807 position = (position * pTabdef->iScale) / 4;
1808 else
1809 position = position * psc->tm.tmAveCharWidth;
1810
1811 if( nTabOrg + position > current_x)
1812 {
1813 if( *lpTabPos >= 0)
1814 {
1815 /* a left aligned tab */
1816 x = (nTabOrg + *lpTabPos) - current_x;
1817 break;
1818 }
1819 else
1820 {
1821 FIXME("Negative tabstop\n");
1822 break;
1823 }
1824 }
1825 }
1826 if ((!cTabStops) && (defWidth > 0))
1827 x =((((current_x - nTabOrg) / defWidth)+1) * defWidth) - current_x;
1828 else if ((!cTabStops) && (defWidth < 0))
1829 FIXME("TODO: Negative defWidth\n");
1830
1831 return x;
1832 }
1833
1834 /***********************************************************************
1835 * Helper function for ScriptStringAnalyse
1836 */
1837 static BOOL requires_fallback(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
1838 const WCHAR *pwcInChars, int cChars )
1839 {
1840 /* FIXME: When to properly fallback is still a bit of a mystery */
1841 WORD *glyphs;
1842
1843 if (psa->fNoGlyphIndex)
1844 return FALSE;
1845
1846 if (init_script_cache(hdc, psc) != S_OK)
1847 return FALSE;
1848
1849 if (SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa) != S_OK)
1850 return TRUE;
1851
1852 glyphs = heap_alloc(sizeof(WORD) * cChars);
1853 if (!glyphs)
1854 return FALSE;
1855 if (ScriptGetCMap(hdc, psc, pwcInChars, cChars, 0, glyphs) != S_OK)
1856 {
1857 heap_free(glyphs);
1858 return TRUE;
1859 }
1860 heap_free(glyphs);
1861
1862 return FALSE;
1863 }
1864
1865 static void find_fallback_font(DWORD scriptid, LPWSTR FaceName)
1866 {
1867 HKEY hkey;
1868
1869 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Uniscribe\\Fallback", &hkey))
1870 {
1871 static const WCHAR szFmt[] = {'%','x',0};
1872 WCHAR value[10];
1873 DWORD count = LF_FACESIZE * sizeof(WCHAR);
1874 DWORD type;
1875
1876 sprintfW(value, szFmt, scriptInformation[scriptid].scriptTag);
1877 if (RegQueryValueExW(hkey, value, 0, &type, (LPBYTE)FaceName, &count))
1878 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1879 RegCloseKey(hkey);
1880 }
1881 else
1882 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1883 }
1884
1885 /***********************************************************************
1886 * ScriptStringAnalyse (USP10.@)
1887 *
1888 */
1889 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
1890 int cGlyphs, int iCharset, DWORD dwFlags,
1891 int iReqWidth, SCRIPT_CONTROL *psControl,
1892 SCRIPT_STATE *psState, const int *piDx,
1893 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
1894 SCRIPT_STRING_ANALYSIS *pssa)
1895 {
1896 HRESULT hr = E_OUTOFMEMORY;
1897 StringAnalysis *analysis = NULL;
1898 SCRIPT_CONTROL sControl;
1899 SCRIPT_STATE sState;
1900 int i, num_items = 255;
1901 BYTE *BidiLevel;
1902 WCHAR *iString = NULL;
1903
1904 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1905 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
1906 psControl, psState, piDx, pTabdef, pbInClass, pssa);
1907
1908 if (iCharset != -1)
1909 {
1910 FIXME("Only Unicode strings are supported\n");
1911 return E_INVALIDARG;
1912 }
1913 if (cString < 1 || !pString) return E_INVALIDARG;
1914 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
1915
1916 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
1917 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
1918
1919 /* FIXME: handle clipping */
1920 analysis->clip_len = cString;
1921 analysis->hdc = hdc;
1922 analysis->dwFlags = dwFlags;
1923
1924 if (psState)
1925 sState = *psState;
1926 else
1927 memset(&sState, 0, sizeof(SCRIPT_STATE));
1928
1929 if (psControl)
1930 sControl = *psControl;
1931 else
1932 memset(&sControl, 0, sizeof(SCRIPT_CONTROL));
1933
1934 if (dwFlags & SSA_PASSWORD)
1935 {
1936 iString = heap_alloc(sizeof(WCHAR)*cString);
1937 if (!iString)
1938 {
1939 hr = E_OUTOFMEMORY;
1940 goto error;
1941 }
1942 for (i = 0; i < cString; i++)
1943 iString[i] = *((const WCHAR *)pString);
1944 pString = iString;
1945 }
1946
1947 hr = ScriptItemize(pString, cString, num_items, &sControl, &sState, analysis->pItem,
1948 &analysis->numItems);
1949
1950 if (FAILED(hr))
1951 {
1952 if (hr == E_OUTOFMEMORY)
1953 hr = E_INVALIDARG;
1954 goto error;
1955 }
1956
1957 /* set back to out of memory for default goto error behaviour */
1958 hr = E_OUTOFMEMORY;
1959
1960 if (dwFlags & SSA_BREAK)
1961 {
1962 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
1963 {
1964 for (i = 0; i < analysis->numItems; i++)
1965 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]);
1966 }
1967 else
1968 goto error;
1969 }
1970
1971 if (!(analysis->logical2visual = heap_alloc_zero(sizeof(int) * analysis->numItems)))
1972 goto error;
1973 if (!(BidiLevel = heap_alloc_zero(analysis->numItems)))
1974 goto error;
1975
1976 if (dwFlags & SSA_GLYPHS)
1977 {
1978 int tab_x = 0;
1979 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
1980 {
1981 heap_free(BidiLevel);
1982 goto error;
1983 }
1984
1985 for (i = 0; i < analysis->numItems; i++)
1986 {
1987 SCRIPT_CACHE *sc = (SCRIPT_CACHE*)&analysis->glyphs[i].sc;
1988 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1989 int numGlyphs = 1.5 * cChar + 16;
1990 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
1991 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
1992 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
1993 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * numGlyphs);
1994 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
1995 ABC *abc = heap_alloc_zero(sizeof(ABC));
1996 int numGlyphsReturned;
1997 HFONT originalFont = 0x0;
1998
1999 /* FIXME: non unicode strings */
2000 const WCHAR* pStr = (const WCHAR*)pString;
2001 analysis->glyphs[i].fallbackFont = NULL;
2002
2003 if (!glyphs || !pwLogClust || !piAdvance || !psva || !pGoffset || !abc)
2004 {
2005 heap_free (BidiLevel);
2006 heap_free (glyphs);
2007 heap_free (pwLogClust);
2008 heap_free (piAdvance);
2009 heap_free (psva);
2010 heap_free (pGoffset);
2011 heap_free (abc);
2012 hr = E_OUTOFMEMORY;
2013 goto error;
2014 }
2015
2016 if ((dwFlags & SSA_FALLBACK) && requires_fallback(hdc, sc, &analysis->pItem[i].a, &pStr[analysis->pItem[i].iCharPos], cChar))
2017 {
2018 LOGFONTW lf;
2019 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), & lf);
2020 lf.lfCharSet = scriptInformation[analysis->pItem[i].a.eScript].props.bCharSet;
2021 lf.lfFaceName[0] = 0;
2022 find_fallback_font(analysis->pItem[i].a.eScript, lf.lfFaceName);
2023 if (lf.lfFaceName[0])
2024 {
2025 analysis->glyphs[i].fallbackFont = CreateFontIndirectW(&lf);
2026 if (analysis->glyphs[i].fallbackFont)
2027 {
2028 ScriptFreeCache(sc);
2029 originalFont = SelectObject(hdc, analysis->glyphs[i].fallbackFont);
2030 }
2031 }
2032 }
2033
2034 /* FIXME: When we properly shape Hangul remove this check */
2035 if ((dwFlags & SSA_LINK) && !analysis->glyphs[i].fallbackFont && analysis->pItem[i].a.eScript == Script_Hangul)
2036 analysis->pItem[i].a.fNoGlyphIndex = TRUE;
2037
2038 if ((dwFlags & SSA_LINK) && !analysis->glyphs[i].fallbackFont && !scriptInformation[analysis->pItem[i].a.eScript].props.fComplex && !analysis->pItem[i].a.fRTL)
2039 analysis->pItem[i].a.fNoGlyphIndex = TRUE;
2040
2041 ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos], cChar, numGlyphs,
2042 &analysis->pItem[i].a, glyphs, pwLogClust, psva, &numGlyphsReturned);
2043 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
2044 piAdvance, pGoffset, abc);
2045 if (originalFont)
2046 SelectObject(hdc,originalFont);
2047
2048 if (dwFlags & SSA_TAB)
2049 {
2050 int tabi = 0;
2051 for (tabi = 0; tabi < cChar; tabi++)
2052 {
2053 if (pStr[analysis->pItem[i].iCharPos+tabi] == 0x0009)
2054 piAdvance[tabi] = getGivenTabWidth(analysis->glyphs[i].sc, pTabdef, analysis->pItem[i].iCharPos+tabi, tab_x);
2055 tab_x+=piAdvance[tabi];
2056 }
2057 }
2058
2059 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
2060 analysis->glyphs[i].glyphs = glyphs;
2061 analysis->glyphs[i].pwLogClust = pwLogClust;
2062 analysis->glyphs[i].piAdvance = piAdvance;
2063 analysis->glyphs[i].psva = psva;
2064 analysis->glyphs[i].pGoffset = pGoffset;
2065 analysis->glyphs[i].abc = abc;
2066 analysis->glyphs[i].iMaxPosX= -1;
2067
2068 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
2069 }
2070 }
2071 else
2072 {
2073 for (i = 0; i < analysis->numItems; i++)
2074 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
2075 }
2076
2077 ScriptLayout(analysis->numItems, BidiLevel, NULL, analysis->logical2visual);
2078 heap_free(BidiLevel);
2079
2080 *pssa = analysis;
2081 heap_free(iString);
2082 return S_OK;
2083
2084 error:
2085 heap_free(iString);
2086 heap_free(analysis->glyphs);
2087 heap_free(analysis->logattrs);
2088 heap_free(analysis->pItem);
2089 heap_free(analysis->logical2visual);
2090 heap_free(analysis);
2091 return hr;
2092 }
2093
2094 static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
2095 {
2096 if (pva[glyph].fClusterStart)
2097 return TRUE;
2098 if (USP10_FindGlyphInLogClust(pwLogClust, cChars, glyph) >= 0)
2099 return TRUE;
2100
2101 return FALSE;
2102 }
2103
2104
2105 static HRESULT SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa,
2106 int iX,
2107 int iY,
2108 int iItem,
2109 int cStart,
2110 int cEnd,
2111 UINT uOptions,
2112 const RECT *prc,
2113 BOOL fSelected,
2114 BOOL fDisabled)
2115 {
2116 StringAnalysis *analysis;
2117 int off_x = 0;
2118 HRESULT hr;
2119 COLORREF BkColor = 0x0;
2120 COLORREF TextColor = 0x0;
2121 INT BkMode = 0;
2122 INT runStart, runEnd;
2123 INT iGlyph, cGlyphs;
2124 HFONT oldFont = 0x0;
2125 RECT crc;
2126 int i;
2127
2128 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
2129 ssa, iX, iY, iItem, cStart, cEnd, uOptions, fSelected, fDisabled);
2130
2131 if (!(analysis = ssa)) return E_INVALIDARG;
2132
2133 if ((cStart >= 0 && analysis->pItem[iItem+1].iCharPos <= cStart) ||
2134 (cEnd >= 0 && analysis->pItem[iItem].iCharPos >= cEnd))
2135 return S_OK;
2136
2137 CopyRect(&crc,prc);
2138 if (fSelected)
2139 {
2140 BkMode = GetBkMode(analysis->hdc);
2141 SetBkMode( analysis->hdc, OPAQUE);
2142 BkColor = GetBkColor(analysis->hdc);
2143 SetBkColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHT));
2144 if (!fDisabled)
2145 {
2146 TextColor = GetTextColor(analysis->hdc);
2147 SetTextColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2148 }
2149 }
2150 if (analysis->glyphs[iItem].fallbackFont)
2151 oldFont = SelectObject(analysis->hdc, analysis->glyphs[iItem].fallbackFont);
2152
2153 if (cStart >= 0 && analysis->pItem[iItem+1].iCharPos > cStart && analysis->pItem[iItem].iCharPos <= cStart)
2154 runStart = cStart - analysis->pItem[iItem].iCharPos;
2155 else
2156 runStart = 0;
2157 if (cEnd >= 0 && analysis->pItem[iItem+1].iCharPos > cEnd && analysis->pItem[iItem].iCharPos <= cEnd)
2158 runEnd = (cEnd-1) - analysis->pItem[iItem].iCharPos;
2159 else
2160 runEnd = (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos) - 1;
2161
2162 if (analysis->pItem[iItem].a.fRTL)
2163 {
2164 if (cEnd >= 0 && cEnd < analysis->pItem[iItem+1].iCharPos)
2165 ScriptStringCPtoX(ssa, cEnd, FALSE, &off_x);
2166 else
2167 ScriptStringCPtoX(ssa, analysis->pItem[iItem+1].iCharPos-1, TRUE, &off_x);
2168 crc.left = iX + off_x;
2169 }
2170 else
2171 {
2172 if (cStart >=0 && runStart)
2173 ScriptStringCPtoX(ssa, cStart, FALSE, &off_x);
2174 else
2175 ScriptStringCPtoX(ssa, analysis->pItem[iItem].iCharPos, FALSE, &off_x);
2176 crc.left = iX + off_x;
2177 }
2178
2179 if (analysis->pItem[iItem].a.fRTL)
2180 iGlyph = analysis->glyphs[iItem].pwLogClust[runEnd];
2181 else
2182 iGlyph = analysis->glyphs[iItem].pwLogClust[runStart];
2183
2184 if (analysis->pItem[iItem].a.fRTL)
2185 cGlyphs = analysis->glyphs[iItem].pwLogClust[runStart] - iGlyph;
2186 else
2187 cGlyphs = analysis->glyphs[iItem].pwLogClust[runEnd] - iGlyph;
2188
2189 cGlyphs++;
2190
2191 /* adjust for cluster glyphs when starting */
2192 if (analysis->pItem[iItem].a.fRTL)
2193 i = analysis->pItem[iItem+1].iCharPos - 1;
2194 else
2195 i = analysis->pItem[iItem].iCharPos;
2196
2197 for (; i >=analysis->pItem[iItem].iCharPos && i < analysis->pItem[iItem+1].iCharPos; (analysis->pItem[iItem].a.fRTL)?i--:i++)
2198 {
2199 if (analysis->glyphs[iItem].pwLogClust[i - analysis->pItem[iItem].iCharPos] == iGlyph)
2200 {
2201 if (analysis->pItem[iItem].a.fRTL)
2202 ScriptStringCPtoX(ssa, i, TRUE, &off_x);
2203 else
2204 ScriptStringCPtoX(ssa, i, FALSE, &off_x);
2205 break;
2206 }
2207 }
2208
2209 if (cEnd < 0 || scriptInformation[analysis->pItem[iItem].a.eScript].props.fNeedsCaretInfo)
2210 {
2211 INT direction;
2212 INT clust_glyph;
2213
2214 clust_glyph = iGlyph + cGlyphs;
2215 if (analysis->pItem[iItem].a.fRTL)
2216 direction = -1;
2217 else
2218 direction = 1;
2219
2220 while(clust_glyph < analysis->glyphs[iItem].numGlyphs &&
2221 !does_glyph_start_cluster(analysis->glyphs[iItem].psva, analysis->glyphs[iItem].pwLogClust, (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos), clust_glyph, direction))
2222 {
2223 cGlyphs++;
2224 clust_glyph++;
2225 }
2226 }
2227
2228 hr = ScriptTextOut(analysis->hdc,
2229 (SCRIPT_CACHE *)&analysis->glyphs[iItem].sc, iX + off_x,
2230 iY, uOptions, &crc, &analysis->pItem[iItem].a, NULL, 0,
2231 &analysis->glyphs[iItem].glyphs[iGlyph], cGlyphs,
2232 &analysis->glyphs[iItem].piAdvance[iGlyph], NULL,
2233 &analysis->glyphs[iItem].pGoffset[iGlyph]);
2234
2235 TRACE("ScriptTextOut hr=%08x\n", hr);
2236
2237 if (fSelected)
2238 {
2239 SetBkColor(analysis->hdc, BkColor);
2240 SetBkMode( analysis->hdc, BkMode);
2241 if (!fDisabled)
2242 SetTextColor(analysis->hdc, TextColor);
2243 }
2244 if (analysis->glyphs[iItem].fallbackFont)
2245 SelectObject(analysis->hdc, oldFont);
2246
2247 return hr;
2248 }
2249
2250 /***********************************************************************
2251 * ScriptStringOut (USP10.@)
2252 *
2253 * This function takes the output of ScriptStringAnalyse and joins the segments
2254 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
2255 * only processes glyphs.
2256 *
2257 * Parameters:
2258 * ssa [I] buffer to hold the analysed string components
2259 * iX [I] X axis displacement for output
2260 * iY [I] Y axis displacement for output
2261 * uOptions [I] flags controlling output processing
2262 * prc [I] rectangle coordinates
2263 * iMinSel [I] starting pos for substringing output string
2264 * iMaxSel [I] ending pos for substringing output string
2265 * fDisabled [I] controls text highlighting
2266 *
2267 * RETURNS
2268 * Success: S_OK
2269 * Failure: is the value returned by ScriptTextOut
2270 */
2271 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
2272 int iX,
2273 int iY,
2274 UINT uOptions,
2275 const RECT *prc,
2276 int iMinSel,
2277 int iMaxSel,
2278 BOOL fDisabled)
2279 {
2280 StringAnalysis *analysis;
2281 int item;
2282 HRESULT hr;
2283
2284 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
2285 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
2286
2287 if (!(analysis = ssa)) return E_INVALIDARG;
2288 if (!(analysis->dwFlags & SSA_GLYPHS)) return E_INVALIDARG;
2289
2290 for (item = 0; item < analysis->numItems; item++)
2291 {
2292 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], -1, -1, uOptions, prc, FALSE, fDisabled);
2293 if (FAILED(hr))
2294 return hr;
2295 }
2296
2297 if (iMinSel < iMaxSel && (iMinSel > 0 || iMaxSel > 0))
2298 {
2299 if (iMaxSel > 0 && iMinSel < 0)
2300 iMinSel = 0;
2301 for (item = 0; item < analysis->numItems; item++)
2302 {
2303 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], iMinSel, iMaxSel, uOptions, prc, TRUE, fDisabled);
2304 if (FAILED(hr))
2305 return hr;
2306 }
2307 }
2308
2309 return S_OK;
2310 }
2311
2312 /***********************************************************************
2313 * ScriptStringCPtoX (USP10.@)
2314 *
2315 */
2316 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
2317 {
2318 int item;
2319 int runningX = 0;
2320 StringAnalysis* analysis = ssa;
2321
2322 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
2323
2324 if (!ssa || !pX) return S_FALSE;
2325 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2326
2327 /* icp out of range */
2328 if(icp < 0)
2329 {
2330 analysis->invalid = TRUE;
2331 return E_INVALIDARG;
2332 }
2333
2334 for(item=0; item<analysis->numItems; item++)
2335 {
2336 int CP, i;
2337 int offset;
2338
2339 i = analysis->logical2visual[item];
2340 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2341 /* initialize max extents for uninitialized runs */