usp10: Add Ogham script.
[wine.git] / dlls / usp10 / usp10.c
blobc1f7967b95dd68aa5853387beee5c338da3fa88e
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
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.
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.
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
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.
27 #include <stdarg.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winnls.h"
34 #include "winreg.h"
35 #include "usp10.h"
37 #include "usp10_internal.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
44 typedef struct _scriptRange
46 WORD script;
47 WORD rangeFirst;
48 WORD rangeLast;
49 WORD numericScript;
50 WORD punctScript;
51 } scriptRange;
53 static const scriptRange scriptRanges[] = {
54 /* Basic Latin: U+0000–U+007A */
55 { Script_Latin, 0x00, 0x07a , Script_Numeric, Script_Punctuation},
56 /* Latin-1 Supplement: U+0080–U+00FF */
57 /* Latin Extended-A: U+0100–U+017F */
58 /* Latin Extended-B: U+0180–U+024F */
59 /* IPA Extensions: U+0250–U+02AF */
60 { Script_Latin, 0x80, 0x2af , Script_Numeric2, Script_Punctuation},
61 /* Combining Diacritical Marks : U+0300–U+036F */
62 { Script_Diacritical,0x300, 0x36f, 0, 0},
63 /* Greek: U+0370–U+03FF */
64 { Script_Greek, 0x370, 0x3ff, 0, 0},
65 /* Cyrillic: U+0400–U+04FF */
66 /* Cyrillic Supplement: U+0500–U+052F */
67 { Script_Cyrillic, 0x400, 0x52f, 0, 0},
68 /* Armenian: U+0530–U+058F */
69 { Script_Armenian, 0x530, 0x58f, 0, 0},
70 /* Hebrew: U+0590–U+05FF */
71 { Script_Hebrew, 0x590, 0x5ff, 0, 0},
72 /* Arabic: U+0600–U+06FF */
73 { Script_Arabic, 0x600, 0x6ef, Script_Arabic_Numeric, 0},
74 /* Defined by Windows */
75 { Script_Persian, 0x6f0, 0x6f9, 0, 0},
76 /* Continue Arabic: U+0600–U+06FF */
77 { Script_Arabic, 0x6fa, 0x6ff, 0, 0},
78 /* Syriac: U+0700–U+074F*/
79 { Script_Syriac, 0x700, 0x74f, 0, 0},
80 /* Arabic Supplement: U+0750–U+077F */
81 { Script_Arabic, 0x750, 0x77f, 0, 0},
82 /* Thaana: U+0780–U+07BF */
83 { Script_Thaana, 0x780, 0x7bf, 0, 0},
84 /* N’Ko: U+07C0–U+07FF */
85 { Script_NKo, 0x7c0, 0x7ff, 0, 0},
86 /* Devanagari: U+0900–U+097F */
87 { Script_Devanagari, 0x900, 0x97f, Script_Devanagari_Numeric, 0},
88 /* Bengali: U+0980–U+09FF */
89 { Script_Bengali, 0x980, 0x9ff, Script_Bengali_Numeric, 0},
90 /* Gurmukhi: U+0A00–U+0A7F*/
91 { Script_Gurmukhi, 0xa00, 0xa7f, Script_Gurmukhi_Numeric, 0},
92 /* Gujarati: U+0A80–U+0AFF*/
93 { Script_Gujarati, 0xa80, 0xaff, Script_Gujarati_Numeric, 0},
94 /* Oriya: U+0B00–U+0B7F */
95 { Script_Oriya, 0xb00, 0xb7f, Script_Oriya_Numeric, 0},
96 /* Tamil: U+0B80–U+0BFF */
97 { Script_Tamil, 0xb80, 0xbff, Script_Tamil_Numeric, 0},
98 /* Telugu: U+0C00–U+0C7F */
99 { Script_Telugu, 0xc00, 0xc7f, Script_Telugu_Numeric, 0},
100 /* Kannada: U+0C80–U+0CFF */
101 { Script_Kannada, 0xc80, 0xcff, Script_Kannada_Numeric, 0},
102 /* Malayalam: U+0D00–U+0D7F */
103 { Script_Malayalam, 0xd00, 0xd7f, Script_Malayalam_Numeric, 0},
104 /* Sinhala: U+0D80–U+0DFF */
105 { Script_Sinhala, 0xd80, 0xdff, 0, 0},
106 /* Thai: U+0E00–U+0E7F */
107 { Script_Thai, 0xe00, 0xe7f, Script_Thai_Numeric, 0},
108 /* Lao: U+0E80–U+0EFF */
109 { Script_Lao, 0xe80, 0xeff, Script_Lao_Numeric, 0},
110 /* Tibetan: U+0F00–U+0FFF */
111 { Script_Tibetan, 0xf00, 0xfff, 0, 0},
112 /* Myanmar: U+1000–U+109F */
113 { Script_Myanmar, 0x1000, 0x109f, Script_Myanmar_Numeric, 0},
114 /* Georgian: U+10A0–U+10FF */
115 { Script_Georgian, 0x10a0, 0x10ff, 0, 0},
116 /* Hangul Jamo: U+1100–U+11FF */
117 { Script_Hangul, 0x1100, 0x11ff, 0, 0},
118 /* Ethiopic: U+1200–U+137F */
119 /* Ethiopic Extensions: U+1380–U+139F */
120 { Script_Ethiopic, 0x1200, 0x139f, 0, 0},
121 /* Cherokee: U+13A0–U+13FF */
122 { Script_Cherokee, 0x13a0, 0x13ff, 0, 0},
123 /* Canadian Aboriginal Syllabics: U+1400–U+167F */
124 { Script_Canadian, 0x1400, 0x167f, 0, 0},
125 /* Ogham: U+1680–U+169F */
126 { Script_Ogham, 0x1680, 0x169f, 0, 0},
127 /* Khmer: U+1780–U+17FF */
128 { Script_Khmer, 0x1780, 0x17ff, Script_Khmer_Numeric, 0},
129 /* Mongolian: U+1800–U+18AF */
130 { Script_Mongolian, 0x1800, 0x18af, Script_Mongolian_Numeric, 0},
131 /* Canadian Aboriginal Syllabics Extended: U+18B0–U+18FF */
132 { Script_Canadian, 0x18b0, 0x18ff, 0, 0},
133 /* Tai Le: U+1950–U+197F */
134 { Script_Tai_Le, 0x1950, 0x197f, 0, 0},
135 /* New Tai Lue: U+1980–U+19DF */
136 { Script_New_Tai_Lue,0x1980, 0x19df, Script_New_Tai_Lue_Numeric, 0},
137 /* Khmer Symbols: U+19E0–U+19FF */
138 { Script_Khmer, 0x19e0, 0x19ff, Script_Khmer_Numeric, 0},
139 /* Vedic Extensions: U+1CD0-U+1CFF */
140 { Script_Devanagari, 0x1cd0, 0x1cff, Script_Devanagari_Numeric, 0},
141 /* Phonetic Extensions: U+1D00–U+1DBF */
142 { Script_Latin, 0x1d00, 0x1dbf, 0, 0},
143 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
144 { Script_Diacritical,0x1dc0, 0x1dff, 0, 0},
145 /* Latin Extended Additional: U+1E00–U+1EFF */
146 { Script_Latin, 0x1e00, 0x1eff, 0, 0},
147 /* Greek Extended: U+1F00–U+1FFF */
148 { Script_Greek, 0x1f00, 0x1fff, 0, 0},
149 /* General Punctuation: U+2000 –U+206f */
150 { Script_Latin, 0x2000, 0x206f, 0, 0},
151 /* Superscripts and Subscripts : U+2070 –U+209f */
152 /* Currency Symbols : U+20a0 –U+20cf */
153 { Script_Numeric2, 0x2070, 0x2070, 0, 0},
154 { Script_Latin, 0x2071, 0x2073, 0, 0},
155 { Script_Numeric2, 0x2074, 0x2079, 0, 0},
156 { Script_Latin, 0x207a, 0x207f, 0, 0},
157 { Script_Numeric2, 0x2080, 0x2089, 0, 0},
158 { Script_Latin, 0x208a, 0x20cf, 0, 0},
159 /* Letterlike Symbols : U+2100 –U+214f */
160 /* Number Forms : U+2150 –U+218f */
161 /* Arrows : U+2190 –U+21ff */
162 /* Mathematical Operators : U+2200 –U+22ff */
163 /* Miscellaneous Technical : U+2300 –U+23ff */
164 /* Control Pictures : U+2400 –U+243f */
165 /* Optical Character Recognition : U+2440 –U+245f */
166 /* Enclosed Alphanumerics : U+2460 –U+24ff */
167 /* Box Drawing : U+2500 –U+25ff */
168 /* Block Elements : U+2580 –U+259f */
169 /* Geometric Shapes : U+25a0 –U+25ff */
170 /* Miscellaneous Symbols : U+2600 –U+26ff */
171 /* Dingbats : U+2700 –U+27bf */
172 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
173 /* Supplemental Arrows-A : U+27f0 –U+27ff */
174 { Script_Latin, 0x2100, 0x27ff, 0, 0},
175 /* Supplemental Arrows-B : U+2900 –U+297f */
176 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
177 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
178 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
179 { Script_Latin, 0x2900, 0x2bff, 0, 0},
180 /* Latin Extended-C: U+2C60–U+2C7F */
181 { Script_Latin, 0x2c60, 0x2c7f, 0, 0},
182 /* Georgian: U+2D00–U+2D2F */
183 { Script_Georgian, 0x2d00, 0x2d2f, 0, 0},
184 /* Tifinagh: U+2D30–U+2D7F */
185 { Script_Tifinagh, 0x2d30, 0x2d7f, 0, 0},
186 /* Ethiopic Extensions: U+2D80–U+2DDF */
187 { Script_Ethiopic, 0x2d80, 0x2ddf, 0, 0},
188 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
189 { Script_Cyrillic, 0x2de0, 0x2dff, 0, 0},
190 /* CJK Radicals Supplement: U+2E80–U+2EFF */
191 /* Kangxi Radicals: U+2F00–U+2FDF */
192 { Script_CJK_Han, 0x2e80, 0x2fdf, 0, 0},
193 /* Ideographic Description Characters: U+2FF0–U+2FFF */
194 { Script_Ideograph ,0x2ff0, 0x2fff, 0, 0},
195 /* CJK Symbols and Punctuation: U+3000–U+303F */
196 { Script_Ideograph ,0x3000, 0x3004, 0, 0},
197 { Script_CJK_Han ,0x3005, 0x3005, 0, 0},
198 { Script_Ideograph ,0x3006, 0x3006, 0, 0},
199 { Script_CJK_Han ,0x3007, 0x3007, 0, 0},
200 { Script_Ideograph ,0x3008, 0x3020, 0, 0},
201 { Script_CJK_Han ,0x3021, 0x3029, 0, 0},
202 { Script_Ideograph ,0x302a, 0x3030, 0, 0},
203 /* Kana Marks: */
204 { Script_Kana ,0x3031, 0x3035, 0, 0},
205 { Script_Ideograph ,0x3036, 0x3037, 0, 0},
206 { Script_CJK_Han ,0x3038, 0x303b, 0, 0},
207 { Script_Ideograph ,0x303c, 0x303f, 0, 0},
208 /* Hiragana: U+3040–U+309F */
209 /* Katakana: U+30A0–U+30FF */
210 { Script_Kana ,0x3040, 0x30ff, 0, 0},
211 /* Bopomofo: U+3100–U+312F */
212 { Script_Bopomofo ,0x3100, 0x312f, 0, 0},
213 /* Hangul Compatibility Jamo: U+3130–U+318F */
214 { Script_Hangul ,0x3130, 0x318f, 0, 0},
215 /* Kanbun: U+3190–U+319F */
216 { Script_Ideograph ,0x3190, 0x319f, 0, 0},
217 /* Bopomofo Extended: U+31A0–U+31BF */
218 { Script_Bopomofo ,0x31a0, 0x31bf, 0, 0},
219 /* CJK Strokes: U+31C0–U+31EF */
220 { Script_Ideograph ,0x31c0, 0x31ef, 0, 0},
221 /* Katakana Phonetic Extensions: U+31F0–U+31FF */
222 { Script_Kana ,0x31f0, 0x31ff, 0, 0},
223 /* Enclosed CJK Letters and Months: U+3200–U+32FF */
224 { Script_Hangul ,0x3200, 0x321f, 0, 0},
225 { Script_Ideograph ,0x3220, 0x325f, 0, 0},
226 { Script_Hangul ,0x3260, 0x327f, 0, 0},
227 { Script_Ideograph ,0x3280, 0x32ef, 0, 0},
228 { Script_Kana ,0x32d0, 0x31ff, 0, 0},
229 /* CJK Compatibility: U+3300–U+33FF*/
230 { Script_Kana ,0x3300, 0x3357, 0, 0},
231 { Script_Ideograph ,0x3358, 0x33ff, 0, 0},
232 /* CJK Unified Ideographs Extension A: U+3400–U+4DBF */
233 { Script_CJK_Han ,0x3400, 0x4dbf, 0, 0},
234 /* CJK Unified Ideographs: U+4E00–U+9FFF */
235 { Script_CJK_Han ,0x4e00, 0x9fff, 0, 0},
236 /* Yi: U+A000–U+A4CF */
237 { Script_Yi ,0xa000, 0xa4cf, 0, 0},
238 /* Vai: U+A500–U+A63F */
239 { Script_Vai ,0xa500, 0xa63f, Script_Vai_Numeric, 0},
240 /* Cyrillic Extended-B: U+A640–U+A69F */
241 { Script_Cyrillic, 0xa640, 0xa69f, 0, 0},
242 /* Modifier Tone Letters: U+A700–U+A71F */
243 /* Latin Extended-D: U+A720–U+A7FF */
244 { Script_Latin, 0xa700, 0xa7ff, 0, 0},
245 /* Phags-pa: U+A840–U+A87F */
246 { Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
247 /* Devanagari Extended: U+A8E0-U+A8FF */
248 { Script_Devanagari, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric, 0},
249 /* Myanmar Extended-A: U+AA60–U+AA7F */
250 { Script_Myanmar, 0xaa60, 0xaa7f, Script_Myanmar_Numeric, 0},
251 /* Hangul Jamo Extended-A: U+A960–U+A97F */
252 { Script_Hangul, 0xa960, 0xa97f, 0, 0},
253 /* Hangul Syllables: U+AC00–U+D7A3 */
254 { Script_Hangul, 0xac00, 0xd7a3, 0, 0},
255 /* Hangul Jamo Extended-B: U+D7B0–U+D7FF */
256 { Script_Hangul, 0xd7b0, 0xd7ff, 0, 0},
257 /* CJK Compatibility Ideographs: U+F900–U+FAFF */
258 { Script_CJK_Han ,0xf900, 0xfaff, 0, 0},
259 /* Latin Ligatures: U+FB00–U+FB06 */
260 { Script_Latin, 0xfb00, 0xfb06, 0, 0},
261 /* Armenian ligatures U+FB13..U+FB17 */
262 { Script_Armenian, 0xfb13, 0xfb17, 0, 0},
263 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
264 { Script_Hebrew, 0xfb1d, 0xfb4f, 0, 0},
265 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
266 { Script_Arabic, 0xfb50, 0xfdff, 0, 0},
267 /* Vertical Forms: U+FE10–U+FE1F */
268 /* Combining Half Marks: U+FE20–U+FE2F */
269 /* CJK Compatibility Forms: U+FE30–U+FE4F */
270 /* Small Form Variants: U+FE50–U+FE6F */
271 { Script_Ideograph ,0xfe10, 0xfe6f, 0, 0},
272 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
273 { Script_Arabic, 0xfe70, 0xfeff, 0, 0},
274 /* Halfwidth and Fullwidth Forms: U+FF00–FFEF */
275 { Script_Ideograph ,0xff00, 0xff64, Script_Numeric2, 0},
276 { Script_Kana ,0xff65, 0xff9f, 0, 0},
277 { Script_Hangul ,0xffa0, 0xffdf, 0, 0},
278 { Script_Ideograph ,0xffe0, 0xffef, 0, 0},
279 /* END */
280 { SCRIPT_UNDEFINED, 0, 0, 0}
283 typedef struct _scriptData
285 SCRIPT_ANALYSIS a;
286 SCRIPT_PROPERTIES props;
287 OPENTYPE_TAG scriptTag;
288 WCHAR fallbackFont[LF_FACESIZE];
289 } scriptData;
291 /* the must be in order so that the index matches the Script value */
292 static const scriptData scriptInformation[] = {
293 {{SCRIPT_UNDEFINED, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
294 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
295 0x00000000,
296 {0}},
297 {{Script_Latin, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
299 MS_MAKE_TAG('l','a','t','n'),
300 {0}},
301 {{Script_CR, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
303 0x00000000,
304 {0}},
305 {{Script_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
306 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
307 0x00000000,
308 {0}},
309 {{Script_Control, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_ENGLISH, 0, 1, 0, 0, ANSI_CHARSET, 1, 0, 0, 0, 0, 0, 1, 0, 0},
311 0x00000000,
312 {0}},
313 {{Script_Punctuation, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 0x00000000,
316 {0}},
317 {{Script_Arabic, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_ARABIC, 0, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 1, 0},
319 MS_MAKE_TAG('a','r','a','b'),
320 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
321 {{Script_Arabic_Numeric, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_ARABIC, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
323 MS_MAKE_TAG('a','r','a','b'),
324 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
325 {{Script_Hebrew, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_HEBREW, 0, 1, 0, 1, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
327 MS_MAKE_TAG('h','e','b','r'),
328 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
329 {{Script_Syriac, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_SYRIAC, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 1, 0},
331 MS_MAKE_TAG('s','y','r','c'),
332 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
333 {{Script_Persian, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_PERSIAN, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
335 MS_MAKE_TAG('s','y','r','c'),
336 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
337 {{Script_Thaana, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_DIVEHI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
339 MS_MAKE_TAG('t','h','a','a'),
340 {'M','V',' ','B','o','l','i',0}},
341 {{Script_Greek, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_GREEK, 0, 0, 0, 0, GREEK_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
343 MS_MAKE_TAG('g','r','e','k'),
344 {0}},
345 {{Script_Cyrillic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_RUSSIAN, 0, 0, 0, 0, RUSSIAN_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 MS_MAKE_TAG('c','y','r','l'),
348 {0}},
349 {{Script_Armenian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_ARMENIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
351 MS_MAKE_TAG('a','r','m','n'),
352 {'S','y','l','f','a','e','n',0}},
353 {{Script_Georgian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_GEORGIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
355 MS_MAKE_TAG('g','e','o','r'),
356 {'S','y','l','f','a','e','n',0}},
357 {{Script_Sinhala, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
358 {LANG_SINHALESE, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
359 MS_MAKE_TAG('s','i','n','h'),
360 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
361 {{Script_Tibetan, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
362 {LANG_TIBETAN, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
363 MS_MAKE_TAG('t','i','b','t'),
364 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
365 {{Script_Tibetan_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
366 {LANG_TIBETAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
367 MS_MAKE_TAG('t','i','b','t'),
368 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
369 {{Script_Phags_pa, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
370 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
371 MS_MAKE_TAG('p','h','a','g'),
372 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
373 {{Script_Thai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
374 {LANG_THAI, 0, 1, 1, 1, THAI_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 1},
375 MS_MAKE_TAG('t','h','a','i'),
376 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
377 {{Script_Thai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
378 {LANG_THAI, 1, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
379 MS_MAKE_TAG('t','h','a','i'),
380 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
381 {{Script_Lao, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
382 {LANG_LAO, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
383 MS_MAKE_TAG('l','a','o',' '),
384 {'D','o','k','C','h','a','m','p','a',0}},
385 {{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
386 {LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
387 MS_MAKE_TAG('l','a','o',' '),
388 {'D','o','k','C','h','a','m','p','a',0}},
389 {{Script_Devanagari, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
390 {LANG_HINDI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
391 MS_MAKE_TAG('d','e','v','a'),
392 {'M','a','n','g','a','l',0}},
393 {{Script_Devanagari_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
394 {LANG_HINDI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
395 MS_MAKE_TAG('d','e','v','a'),
396 {'M','a','n','g','a','l',0}},
397 {{Script_Bengali, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
398 {LANG_BENGALI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
399 MS_MAKE_TAG('b','e','n','g'),
400 {'V','r','i','n','d','a',0}},
401 {{Script_Bengali_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
402 {LANG_BENGALI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
403 MS_MAKE_TAG('b','e','n','g'),
404 {'V','r','i','n','d','a',0}},
405 {{Script_Bengali_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
406 {LANG_BENGALI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
407 MS_MAKE_TAG('b','e','n','g'),
408 {'V','r','i','n','d','a',0}},
409 {{Script_Gurmukhi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
410 {LANG_PUNJABI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
411 MS_MAKE_TAG('g','u','r','u'),
412 {'R','a','a','v','i',0}},
413 {{Script_Gurmukhi_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
414 {LANG_PUNJABI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
415 MS_MAKE_TAG('g','u','r','u'),
416 {'R','a','a','v','i',0}},
417 {{Script_Gujarati, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
418 {LANG_GUJARATI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
419 MS_MAKE_TAG('g','u','j','r'),
420 {'S','h','r','u','t','i',0}},
421 {{Script_Gujarati_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
422 {LANG_GUJARATI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
423 MS_MAKE_TAG('g','u','j','r'),
424 {'S','h','r','u','t','i',0}},
425 {{Script_Gujarati_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
426 {LANG_GUJARATI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
427 MS_MAKE_TAG('g','u','j','r'),
428 {'S','h','r','u','t','i',0}},
429 {{Script_Oriya, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
430 {LANG_ORIYA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
431 MS_MAKE_TAG('o','r','y','a'),
432 {'K','a','l','i','n','g','a',0}},
433 {{Script_Oriya_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
434 {LANG_ORIYA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
435 MS_MAKE_TAG('o','r','y','a'),
436 {'K','a','l','i','n','g','a',0}},
437 {{Script_Tamil, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
438 {LANG_TAMIL, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
439 MS_MAKE_TAG('t','a','m','l'),
440 {'L','a','t','h','a',0}},
441 {{Script_Tamil_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
442 {LANG_TAMIL, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
443 MS_MAKE_TAG('t','a','m','l'),
444 {'L','a','t','h','a',0}},
445 {{Script_Telugu, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
446 {LANG_TELUGU, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
447 MS_MAKE_TAG('t','e','l','u'),
448 {'G','a','u','t','a','m','i',0}},
449 {{Script_Telugu_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
450 {LANG_TELUGU, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
451 MS_MAKE_TAG('t','e','l','u'),
452 {'G','a','u','t','a','m','i',0}},
453 {{Script_Kannada, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
454 {LANG_KANNADA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
455 MS_MAKE_TAG('k','n','d','a'),
456 {'T','u','n','g','a',0}},
457 {{Script_Kannada_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
458 {LANG_KANNADA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
459 MS_MAKE_TAG('k','n','d','a'),
460 {'T','u','n','g','a',0}},
461 {{Script_Malayalam, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
462 {LANG_MALAYALAM, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
463 MS_MAKE_TAG('m','l','y','m'),
464 {'K','a','r','t','i','k','a',0}},
465 {{Script_Malayalam_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
466 {LANG_MALAYALAM, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
467 MS_MAKE_TAG('m','l','y','m'),
468 {'K','a','r','t','i','k','a',0}},
469 {{Script_Diacritical, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
470 {LANG_ENGLISH, 0, 1, 0, 1, ANSI_CHARSET, 0, 0, 0, 0, 0, 1, 1, 0, 0},
471 0x00000000,
472 {0}},
473 {{Script_Punctuation2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
474 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
475 MS_MAKE_TAG('l','a','t','n'),
476 {0}},
477 {{Script_Numeric2, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
478 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
479 0x00000000,
480 {0}},
481 {{Script_Myanmar, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
482 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
483 MS_MAKE_TAG('m','y','m','r'),
484 {0}},
485 {{Script_Myanmar_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
486 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
487 MS_MAKE_TAG('m','y','m','r'),
488 {0}},
489 {{Script_Tai_Le, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
490 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
491 MS_MAKE_TAG('t','a','l','e'),
492 {'M','i','c','r','o','s','o','f','t',' ','T','a','i',' ','L','e'}},
493 {{Script_New_Tai_Lue, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
494 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
495 MS_MAKE_TAG('t','a','l','u'),
496 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
497 {{Script_New_Tai_Lue_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
498 {0, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
499 MS_MAKE_TAG('t','a','l','u'),
500 {'M','i','c','r','o','s','o','f','t',' ','N','e','w',' ','T','a','i',' ','L','u','e'}},
501 {{Script_Khmer, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
502 {0x53, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
503 MS_MAKE_TAG('k','h','m','r'),
504 {'D','a','u','n','P','e','n','h'}},
505 {{Script_Khmer, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
506 {0x53, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
507 MS_MAKE_TAG('k','h','m','r'),
508 {'D','a','u','n','P','e','n','h'}},
509 {{Script_CJK_Han, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
510 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
511 MS_MAKE_TAG('h','a','n','i'),
512 {0}},
513 {{Script_Ideograph, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
514 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
515 MS_MAKE_TAG('h','a','n','i'),
516 {0}},
517 {{Script_Bopomofo, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
518 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
519 MS_MAKE_TAG('b','o','p','o'),
520 {0}},
521 {{Script_Kana, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
522 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
523 MS_MAKE_TAG('k','a','n','a'),
524 {0}},
525 {{Script_Hangul, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
526 {LANG_KOREAN, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
527 MS_MAKE_TAG('h','a','n','g'),
528 {0}},
529 {{Script_Yi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
530 {LANG_ENGLISH, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
531 MS_MAKE_TAG('y','i',' ',' '),
532 {'M','i','c','r','o','s','o','f','t',' ','Y','i',' ','B','a','i','t','i'}},
533 {{Script_Ethiopic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
534 {0x5e, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
535 MS_MAKE_TAG('e','t','h','i'),
536 {'N','y','a','l','a'}},
537 {{Script_Ethiopic_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
538 {0x5e, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
539 MS_MAKE_TAG('e','t','h','i'),
540 {'N','y','a','l','a'}},
541 {{Script_Mongolian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
542 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
543 MS_MAKE_TAG('m','o','n','g'),
544 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
545 {{Script_Mongolian_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
546 {LANG_MONGOLIAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
547 MS_MAKE_TAG('m','o','n','g'),
548 {'M','o','n','g','o','l','i','a','n',' ','B','a','i','t','i'}},
549 {{Script_Tifinagh, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
550 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
551 MS_MAKE_TAG('t','f','n','g'),
552 {'E','b','r','i','m','a'}},
553 {{Script_NKo, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
554 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
555 MS_MAKE_TAG('n','k','o',' '),
556 {0}},
557 {{Script_Vai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
558 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
559 MS_MAKE_TAG('v','a','i',' '),
560 {'E','b','r','i','m','a'}},
561 {{Script_Vai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
562 {0, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
563 MS_MAKE_TAG('v','a','i',' '),
564 {'E','b','r','i','m','a'}},
565 {{Script_Cherokee, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
566 {0x5c, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
567 MS_MAKE_TAG('c','h','e','r'),
568 {'P','l','a','n','t','a','g','e','n','e','t',' ','C','h','e','r','o','k','e','e'}},
569 {{Script_Canadian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
570 {0x5d, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
571 MS_MAKE_TAG('c','a','n','s'),
572 {'E','u','p','h','e','m','i','a'}},
573 {{Script_Ogham, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
574 {0, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
575 MS_MAKE_TAG('o','g','a','m'),
576 {'S','e','g','o','e',' ','U','I',' ','S','y','m','b','o','l'}},
579 static const SCRIPT_PROPERTIES *script_props[] =
581 &scriptInformation[0].props, &scriptInformation[1].props,
582 &scriptInformation[2].props, &scriptInformation[3].props,
583 &scriptInformation[4].props, &scriptInformation[5].props,
584 &scriptInformation[6].props, &scriptInformation[7].props,
585 &scriptInformation[8].props, &scriptInformation[9].props,
586 &scriptInformation[10].props, &scriptInformation[11].props,
587 &scriptInformation[12].props, &scriptInformation[13].props,
588 &scriptInformation[14].props, &scriptInformation[15].props,
589 &scriptInformation[16].props, &scriptInformation[17].props,
590 &scriptInformation[18].props, &scriptInformation[19].props,
591 &scriptInformation[20].props, &scriptInformation[21].props,
592 &scriptInformation[22].props, &scriptInformation[23].props,
593 &scriptInformation[24].props, &scriptInformation[25].props,
594 &scriptInformation[26].props, &scriptInformation[27].props,
595 &scriptInformation[28].props, &scriptInformation[29].props,
596 &scriptInformation[30].props, &scriptInformation[31].props,
597 &scriptInformation[32].props, &scriptInformation[33].props,
598 &scriptInformation[34].props, &scriptInformation[35].props,
599 &scriptInformation[36].props, &scriptInformation[37].props,
600 &scriptInformation[38].props, &scriptInformation[39].props,
601 &scriptInformation[40].props, &scriptInformation[41].props,
602 &scriptInformation[42].props, &scriptInformation[43].props,
603 &scriptInformation[44].props, &scriptInformation[45].props,
604 &scriptInformation[46].props, &scriptInformation[47].props,
605 &scriptInformation[48].props, &scriptInformation[49].props,
606 &scriptInformation[50].props, &scriptInformation[51].props,
607 &scriptInformation[52].props, &scriptInformation[53].props,
608 &scriptInformation[54].props, &scriptInformation[55].props,
609 &scriptInformation[56].props, &scriptInformation[57].props,
610 &scriptInformation[58].props, &scriptInformation[59].props,
611 &scriptInformation[60].props, &scriptInformation[61].props,
612 &scriptInformation[62].props, &scriptInformation[63].props,
613 &scriptInformation[64].props, &scriptInformation[65].props,
614 &scriptInformation[66].props, &scriptInformation[67].props,
615 &scriptInformation[68].props, &scriptInformation[69].props,
616 &scriptInformation[70].props
619 typedef struct {
620 ScriptCache *sc;
621 int numGlyphs;
622 WORD* glyphs;
623 WORD* pwLogClust;
624 int* piAdvance;
625 SCRIPT_VISATTR* psva;
626 GOFFSET* pGoffset;
627 ABC* abc;
628 int iMaxPosX;
629 HFONT fallbackFont;
630 } StringGlyphs;
632 typedef struct {
633 HDC hdc;
634 DWORD dwFlags;
635 BOOL invalid;
636 int clip_len;
637 int cItems;
638 int cMaxGlyphs;
639 SCRIPT_ITEM* pItem;
640 int numItems;
641 StringGlyphs* glyphs;
642 SCRIPT_LOGATTR* logattrs;
643 SIZE* sz;
644 int* logical2visual;
645 } StringAnalysis;
647 static inline void *heap_alloc(SIZE_T size)
649 return HeapAlloc(GetProcessHeap(), 0, size);
652 static inline void *heap_alloc_zero(SIZE_T size)
654 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
657 static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size)
659 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
662 static inline BOOL heap_free(LPVOID mem)
664 return HeapFree(GetProcessHeap(), 0, mem);
667 static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
669 return ((ScriptCache *)*psc)->tm.tmDefaultChar;
672 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
674 return ((ScriptCache *)*psc)->tm.tmHeight;
677 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
679 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
682 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c)
684 WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
686 if (!block) return 0;
687 return block[c & GLYPH_BLOCK_MASK];
690 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
692 WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
694 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
695 return ((*block)[c & GLYPH_BLOCK_MASK] = glyph);
698 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
700 static const ABC nil;
701 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
703 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
704 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
705 return TRUE;
708 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
710 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
712 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
713 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
714 return TRUE;
717 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
719 ScriptCache *sc;
721 if (!psc) return E_INVALIDARG;
722 if (*psc) return S_OK;
723 if (!hdc) return E_PENDING;
725 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
726 if (!GetTextMetricsW(hdc, &sc->tm))
728 heap_free(sc);
729 return E_INVALIDARG;
731 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
733 heap_free(sc);
734 return E_INVALIDARG;
736 sc->sfnt = (GetFontData(hdc, MS_MAKE_TAG('h','e','a','d'), 0, NULL, 0)!=GDI_ERROR);
737 *psc = sc;
738 TRACE("<- %p\n", sc);
739 return S_OK;
742 static WCHAR mirror_char( WCHAR ch )
744 extern const WCHAR wine_mirror_map[];
745 return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)];
748 static WORD get_char_script( WCHAR ch)
750 static const WCHAR latin_punc[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
751 WORD type = 0;
752 int i;
754 if (ch == 0xc || ch == 0x20 || ch == 0x202f)
755 return Script_CR;
757 /* These punctuation are separated out as Latin punctuation */
758 if (strchrW(latin_punc,ch))
759 return Script_Punctuation2;
761 /* These chars are itemized as Punctuation by Windows */
762 if (ch == 0x2212 || ch == 0x2044)
763 return Script_Punctuation;
765 GetStringTypeW(CT_CTYPE1, &ch, 1, &type);
767 if (type == 0)
768 return SCRIPT_UNDEFINED;
770 if (type & C1_CNTRL)
771 return Script_Control;
773 i = 0;
776 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
777 break;
779 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
781 if (scriptRanges[i].numericScript && type & C1_DIGIT)
782 return scriptRanges[i].numericScript;
783 if (scriptRanges[i].punctScript && type & C1_PUNCT)
784 return scriptRanges[i].punctScript;
785 return scriptRanges[i].script;
787 i++;
788 } while (1);
790 return SCRIPT_UNDEFINED;
793 /***********************************************************************
794 * DllMain
797 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
799 switch(fdwReason)
801 case DLL_PROCESS_ATTACH:
802 DisableThreadLibraryCalls(hInstDLL);
803 break;
804 case DLL_PROCESS_DETACH:
805 break;
807 return TRUE;
810 /***********************************************************************
811 * ScriptFreeCache (USP10.@)
813 * Free a script cache.
815 * PARAMS
816 * psc [I/O] Script cache.
818 * RETURNS
819 * Success: S_OK
820 * Failure: Non-zero HRESULT value.
822 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
824 TRACE("%p\n", psc);
826 if (psc && *psc)
828 unsigned int i;
829 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
831 heap_free(((ScriptCache *)*psc)->glyphs[i]);
832 heap_free(((ScriptCache *)*psc)->widths[i]);
834 heap_free(((ScriptCache *)*psc)->GSUB_Table);
835 heap_free(((ScriptCache *)*psc)->GDEF_Table);
836 heap_free(((ScriptCache *)*psc)->features);
837 heap_free(*psc);
838 *psc = NULL;
840 return S_OK;
843 /***********************************************************************
844 * ScriptGetProperties (USP10.@)
846 * Retrieve a list of script properties.
848 * PARAMS
849 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
850 * num [I] Pointer to the number of scripts.
852 * RETURNS
853 * Success: S_OK
854 * Failure: Non-zero HRESULT value.
856 * NOTES
857 * Behaviour matches WinXP.
859 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
861 TRACE("(%p,%p)\n", props, num);
863 if (!props && !num) return E_INVALIDARG;
865 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
866 if (props) *props = script_props;
868 return S_OK;
871 /***********************************************************************
872 * ScriptGetFontProperties (USP10.@)
874 * Get information on special glyphs.
876 * PARAMS
877 * hdc [I] Device context.
878 * psc [I/O] Opaque pointer to a script cache.
879 * sfp [O] Font properties structure.
881 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
883 HRESULT hr;
885 TRACE("%p,%p,%p\n", hdc, psc, sfp);
887 if (!sfp) return E_INVALIDARG;
888 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
890 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
891 return E_INVALIDARG;
893 /* return something sensible? */
894 sfp->wgBlank = 0;
895 sfp->wgDefault = get_cache_default_char(psc);
896 sfp->wgInvalid = 0;
897 sfp->wgKashida = 0xffff;
898 sfp->iKashidaWidth = 0;
900 return S_OK;
903 /***********************************************************************
904 * ScriptRecordDigitSubstitution (USP10.@)
906 * Record digit substitution settings for a given locale.
908 * PARAMS
909 * locale [I] Locale identifier.
910 * sds [I] Structure to record substitution settings.
912 * RETURNS
913 * Success: S_OK
914 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
916 * SEE ALSO
917 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
919 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
921 DWORD plgid, sub;
923 TRACE("0x%x, %p\n", locale, sds);
925 /* This implementation appears to be correct for all languages, but it's
926 * not clear if sds->DigitSubstitute is ever set to anything except
927 * CONTEXT or NONE in reality */
929 if (!sds) return E_POINTER;
931 locale = ConvertDefaultLocale(locale);
933 if (!IsValidLocale(locale, LCID_INSTALLED))
934 return E_INVALIDARG;
936 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
937 sds->TraditionalDigitLanguage = plgid;
939 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
940 sds->NationalDigitLanguage = plgid;
941 else
942 sds->NationalDigitLanguage = LANG_ENGLISH;
944 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
945 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
947 switch (sub)
949 case 0:
950 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
951 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
952 else
953 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
954 break;
955 case 1:
956 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
957 break;
958 case 2:
959 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
960 break;
961 default:
962 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
963 break;
966 sds->dwReserved = 0;
967 return S_OK;
970 /***********************************************************************
971 * ScriptApplyDigitSubstitution (USP10.@)
973 * Apply digit substitution settings.
975 * PARAMS
976 * sds [I] Structure with recorded substitution settings.
977 * sc [I] Script control structure.
978 * ss [I] Script state structure.
980 * RETURNS
981 * Success: S_OK
982 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
984 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
985 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
987 SCRIPT_DIGITSUBSTITUTE psds;
989 TRACE("%p, %p, %p\n", sds, sc, ss);
991 if (!sc || !ss) return E_POINTER;
992 if (!sds)
994 sds = &psds;
995 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
996 return E_INVALIDARG;
999 sc->uDefaultLanguage = LANG_ENGLISH;
1000 sc->fContextDigits = 0;
1001 ss->fDigitSubstitute = 0;
1003 switch (sds->DigitSubstitute) {
1004 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
1005 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
1006 case SCRIPT_DIGITSUBSTITUTE_NONE:
1007 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
1008 return S_OK;
1009 default:
1010 return E_INVALIDARG;
1014 static inline BOOL is_indic(WORD script)
1016 return (script >= Script_Devanagari && script <= Script_Malayalam_Numeric);
1019 static inline WORD base_indic(WORD script)
1021 switch (script)
1023 case Script_Devanagari:
1024 case Script_Devanagari_Numeric: return Script_Devanagari;
1025 case Script_Bengali:
1026 case Script_Bengali_Numeric:
1027 case Script_Bengali_Currency: return Script_Bengali;
1028 case Script_Gurmukhi:
1029 case Script_Gurmukhi_Numeric: return Script_Gurmukhi;
1030 case Script_Gujarati:
1031 case Script_Gujarati_Numeric:
1032 case Script_Gujarati_Currency: return Script_Gujarati;
1033 case Script_Oriya:
1034 case Script_Oriya_Numeric: return Script_Oriya;
1035 case Script_Tamil:
1036 case Script_Tamil_Numeric: return Script_Tamil;
1037 case Script_Telugu:
1038 case Script_Telugu_Numeric: return Script_Telugu;
1039 case Script_Kannada:
1040 case Script_Kannada_Numeric: return Script_Kannada;
1041 case Script_Malayalam:
1042 case Script_Malayalam_Numeric: return Script_Malayalam;
1043 default:
1044 return -1;
1048 /***********************************************************************
1049 * ScriptItemizeOpenType (USP10.@)
1051 * Split a Unicode string into shapeable parts.
1053 * PARAMS
1054 * pwcInChars [I] String to split.
1055 * cInChars [I] Number of characters in pwcInChars.
1056 * cMaxItems [I] Maximum number of items to return.
1057 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1058 * psState [I] Pointer to a SCRIPT_STATE structure.
1059 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1060 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
1061 * pcItems [O] Number of script items returned.
1063 * RETURNS
1064 * Success: S_OK
1065 * Failure: Non-zero HRESULT value.
1067 HRESULT WINAPI ScriptItemizeOpenType(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1068 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1069 SCRIPT_ITEM *pItems, OPENTYPE_TAG *pScriptTags, int *pcItems)
1072 #define Numeric_space 0x0020
1073 #define ZWNJ 0x200C
1074 #define ZWJ 0x200D
1076 int cnt = 0, index = 0, str = 0;
1077 int New_Script = -1;
1078 int i;
1079 WORD *levels = NULL;
1080 WORD *strength = NULL;
1081 WORD *scripts = NULL;
1082 WORD baselevel = 0;
1083 BOOL new_run;
1084 WORD last_indic = -1;
1085 WORD layoutRTL = 0;
1086 BOOL forceLevels = FALSE;
1088 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
1089 psControl, psState, pItems, pcItems);
1091 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
1092 return E_INVALIDARG;
1094 scripts = heap_alloc(cInChars * sizeof(WORD));
1095 if (!scripts)
1096 return E_OUTOFMEMORY;
1098 for (i = 0; i < cInChars; i++)
1100 scripts[i] = get_char_script(pwcInChars[i]);
1101 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
1102 all Indic scripts */
1103 if ((pwcInChars[i] == 0x964 || pwcInChars[i] ==0x965) && last_indic > 0)
1104 scripts[i] = last_indic;
1105 else if (is_indic(scripts[i]))
1106 last_indic = base_indic(scripts[i]);
1108 /* Some unicode points (Zero Width Space U+200B -
1109 Right-to-Left Mark U+200F) will force us into bidi mode */
1110 if (!forceLevels && pwcInChars[i] >= 0x200B && pwcInChars[i] <= 0x200F)
1111 forceLevels = TRUE;
1113 /* Diacritical marks merge with other scripts */
1114 if (scripts[i] == Script_Diacritical && i > 0)
1115 scripts[i] = scripts[i-1];
1118 for (i = 0; i < cInChars; i++)
1120 /* Joiners get merged preferencially right */
1121 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1123 int j;
1124 if (i+1 == cInChars)
1125 scripts[i] = scripts[i-1];
1126 else
1128 for (j = i+1; j < cInChars; j++)
1130 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1132 scripts[i] = scripts[j];
1133 break;
1140 if (psState && psControl)
1142 levels = heap_alloc_zero(cInChars * sizeof(WORD));
1143 if (!levels)
1145 heap_free(scripts);
1146 return E_OUTOFMEMORY;
1149 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
1150 baselevel = levels[0];
1151 for (i = 0; i < cInChars; i++)
1152 if (levels[i]!=levels[0])
1153 break;
1154 if (i >= cInChars && !odd(baselevel) && !odd(psState->uBidiLevel) && !forceLevels)
1156 heap_free(levels);
1157 levels = NULL;
1159 else
1161 BOOL inNumber = FALSE;
1162 static WCHAR math_punc[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
1164 strength = heap_alloc_zero(cInChars * sizeof(WORD));
1165 if (!strength)
1167 heap_free(scripts);
1168 heap_free(levels);
1169 return E_OUTOFMEMORY;
1171 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
1173 /* We currently mis-level leading Diacriticals */
1174 if (scripts[0] == Script_Diacritical)
1175 for (i = 0; i < cInChars && scripts[0] == Script_Diacritical; i++)
1177 levels[i] = odd(levels[i])?levels[i]+1:levels[i];
1178 strength[i] = BIDI_STRONG;
1181 for (i = 0; i < cInChars; i++)
1183 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
1184 if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && inNumber && strchrW(math_punc,pwcInChars[i]))
1186 scripts[i] = Script_Numeric;
1187 levels[i] = 2;
1189 else if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && scripts[i] == Script_Numeric)
1191 levels[i] = 2;
1192 inNumber = TRUE;
1194 else
1195 inNumber = FALSE;
1197 /* Joiners get merged preferencially right */
1198 if (i > 0 && (pwcInChars[i] == ZWJ || pwcInChars[i] == ZWNJ))
1200 int j;
1201 if (i+1 == cInChars && levels[i-1] == levels[i])
1202 strength[i] = strength[i-1];
1203 else
1204 for (j = i+1; j < cInChars && levels[i] == levels[j]; j++)
1205 if (pwcInChars[j] != ZWJ && pwcInChars[j] != ZWNJ && pwcInChars[j] != Numeric_space)
1207 strength[i] = strength[j];
1208 break;
1212 if (psControl->fMergeNeutralItems)
1214 /* Merge the neutrals */
1215 for (i = 0; i < cInChars; i++)
1217 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1219 int j;
1220 for (j = i; j > 0; j--)
1222 if (levels[i] != levels[j])
1223 break;
1224 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1226 scripts[i] = scripts[j];
1227 strength[i] = strength[j];
1228 break;
1232 /* Try going the other way */
1233 if (strength[i] == BIDI_NEUTRAL || strength[i] == BIDI_WEAK)
1235 int j;
1236 for (j = i; j < cInChars; j++)
1238 if (levels[i] != levels[j])
1239 break;
1240 if ((strength[j] == BIDI_STRONG) || (strength[i] == BIDI_NEUTRAL && strength[j] == BIDI_WEAK))
1242 scripts[i] = scripts[j];
1243 strength[i] = strength[j];
1244 break;
1253 while ((!levels || (levels && levels[cnt+1] == levels[0])) && (pwcInChars[cnt] == Numeric_space) && cnt < cInChars)
1254 cnt++;
1256 if (cnt == cInChars) /* All Spaces */
1258 cnt = 0;
1259 New_Script = scripts[cnt];
1262 pItems[index].iCharPos = 0;
1263 pItems[index].a = scriptInformation[scripts[cnt]].a;
1264 pScriptTags[index] = scriptInformation[scripts[cnt]].scriptTag;
1266 if (strength && strength[cnt] == BIDI_STRONG)
1267 str = strength[cnt];
1268 else if (strength)
1269 str = strength[0];
1271 cnt = 0;
1273 if (levels)
1275 if (strength[cnt] == BIDI_STRONG)
1276 layoutRTL = (odd(levels[cnt]))?1:0;
1277 else
1278 layoutRTL = (psState->uBidiLevel || odd(levels[cnt]))?1:0;
1279 pItems[index].a.fRTL = odd(levels[cnt]);
1280 pItems[index].a.fLayoutRTL = layoutRTL;
1281 pItems[index].a.s.uBidiLevel = levels[cnt];
1283 else if (!pItems[index].a.s.uBidiLevel)
1285 layoutRTL = (odd(baselevel))?1:0;
1286 pItems[index].a.s.uBidiLevel = baselevel;
1287 pItems[index].a.fLayoutRTL = odd(baselevel);
1288 pItems[index].a.fRTL = odd(baselevel);
1291 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1292 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
1293 pItems[index].iCharPos);
1295 for (cnt=1; cnt < cInChars; cnt++)
1297 if(pwcInChars[cnt] != Numeric_space)
1298 New_Script = scripts[cnt];
1299 else if (levels)
1301 int j = 1;
1302 while (cnt + j < cInChars - 1 && pwcInChars[cnt+j] == Numeric_space && levels[cnt] == levels[cnt+j])
1303 j++;
1304 if (cnt + j < cInChars && levels[cnt] == levels[cnt+j])
1305 New_Script = scripts[cnt+j];
1306 else
1307 New_Script = scripts[cnt];
1310 new_run = FALSE;
1311 /* merge space strengths*/
1312 if (strength && strength[cnt] == BIDI_STRONG && str != BIDI_STRONG && New_Script == pItems[index].a.eScript)
1313 str = BIDI_STRONG;
1315 if (strength && strength[cnt] == BIDI_NEUTRAL && str == BIDI_STRONG && pwcInChars[cnt] != Numeric_space && New_Script == pItems[index].a.eScript)
1316 str = BIDI_NEUTRAL;
1318 /* changes in level */
1319 if (levels && (levels[cnt] != pItems[index].a.s.uBidiLevel))
1321 TRACE("Level break(%i/%i)\n",pItems[index].a.s.uBidiLevel,levels[cnt]);
1322 new_run = TRUE;
1324 /* changes in strength */
1325 else if (strength && pwcInChars[cnt] != Numeric_space && str != strength[cnt])
1327 TRACE("Strength break (%i/%i)\n",str,strength[cnt]);
1328 new_run = TRUE;
1330 /* changes in script */
1331 else if (((pwcInChars[cnt] != Numeric_space) && (New_Script != -1) && (New_Script != pItems[index].a.eScript)) || (New_Script == Script_Control))
1333 TRACE("Script break(%i/%i)\n",pItems[index].a.eScript,New_Script);
1334 new_run = TRUE;
1337 if (!new_run && strength && str == BIDI_STRONG)
1339 layoutRTL = odd(levels[cnt])?1:0;
1340 pItems[index].a.fLayoutRTL = layoutRTL;
1343 if (new_run)
1345 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);
1347 index++;
1348 if (index+1 > cMaxItems)
1349 return E_OUTOFMEMORY;
1351 if (strength)
1352 str = strength[cnt];
1354 pItems[index].iCharPos = cnt;
1355 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1357 pItems[index].a = scriptInformation[New_Script].a;
1358 pScriptTags[index] = scriptInformation[New_Script].scriptTag;
1359 if (levels)
1361 if (levels[cnt] == 0)
1362 layoutRTL = 0;
1363 else
1364 layoutRTL = (layoutRTL || odd(levels[cnt]))?1:0;
1365 pItems[index].a.fRTL = odd(levels[cnt]);
1366 pItems[index].a.fLayoutRTL = layoutRTL;
1367 pItems[index].a.s.uBidiLevel = levels[cnt];
1369 else if (!pItems[index].a.s.uBidiLevel)
1371 pItems[index].a.s.uBidiLevel = baselevel;
1372 pItems[index].a.fLayoutRTL = layoutRTL;
1373 pItems[index].a.fRTL = odd(baselevel);
1376 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1380 /* While not strictly necessary according to the spec, make sure the n+1
1381 * item is set up to prevent random behaviour if the caller erroneously
1382 * checks the n+1 structure */
1383 index++;
1384 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
1386 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
1388 /* Set one SCRIPT_STATE item being returned */
1389 if (index + 1 > cMaxItems) return E_OUTOFMEMORY;
1390 if (pcItems) *pcItems = index;
1392 /* Set SCRIPT_ITEM */
1393 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
1394 heap_free(levels);
1395 heap_free(strength);
1396 heap_free(scripts);
1397 return S_OK;
1400 /***********************************************************************
1401 * ScriptItemize (USP10.@)
1403 * Split a Unicode string into shapeable parts.
1405 * PARAMS
1406 * pwcInChars [I] String to split.
1407 * cInChars [I] Number of characters in pwcInChars.
1408 * cMaxItems [I] Maximum number of items to return.
1409 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1410 * psState [I] Pointer to a SCRIPT_STATE structure.
1411 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1412 * pcItems [O] Number of script items returned.
1414 * RETURNS
1415 * Success: S_OK
1416 * Failure: Non-zero HRESULT value.
1418 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1419 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1420 SCRIPT_ITEM *pItems, int *pcItems)
1422 OPENTYPE_TAG *discarded_tags;
1423 HRESULT res;
1425 discarded_tags = heap_alloc(cMaxItems * sizeof(OPENTYPE_TAG));
1426 if (!discarded_tags)
1427 return E_OUTOFMEMORY;
1428 res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, discarded_tags, pcItems);
1429 heap_free(discarded_tags);
1430 return res;
1433 static inline int getGivenTabWidth(ScriptCache *psc, SCRIPT_TABDEF *pTabdef, int charPos, int current_x)
1435 int defWidth;
1436 int cTabStops=0;
1437 INT *lpTabPos = NULL;
1438 INT nTabOrg = 0;
1439 INT x = 0;
1441 if (pTabdef)
1442 lpTabPos = pTabdef->pTabStops;
1444 if (pTabdef && pTabdef->iTabOrigin)
1446 if (pTabdef->iScale)
1447 nTabOrg = (pTabdef->iTabOrigin * pTabdef->iScale)/4;
1448 else
1449 nTabOrg = pTabdef->iTabOrigin * psc->tm.tmAveCharWidth;
1452 if (pTabdef)
1453 cTabStops = pTabdef->cTabStops;
1455 if (cTabStops == 1)
1457 if (pTabdef->iScale)
1458 defWidth = ((pTabdef->pTabStops[0])*pTabdef->iScale) / 4;
1459 else
1460 defWidth = (pTabdef->pTabStops[0])*psc->tm.tmAveCharWidth;
1461 cTabStops = 0;
1463 else
1464 defWidth = 8 * psc->tm.tmAveCharWidth;
1466 for (; cTabStops>0 ; lpTabPos++, cTabStops--)
1468 int position = *lpTabPos;
1469 if (position < 0)
1470 position = -1 * position;
1471 if (pTabdef->iScale)
1472 position = (position * pTabdef->iScale) / 4;
1473 else
1474 position = position * psc->tm.tmAveCharWidth;
1476 if( nTabOrg + position > current_x)
1478 if( *lpTabPos >= 0)
1480 /* a left aligned tab */
1481 x = (nTabOrg + *lpTabPos) - current_x;
1482 break;
1484 else
1486 FIXME("Negative tabstop\n");
1487 break;
1491 if ((!cTabStops) && (defWidth > 0))
1492 x =((((current_x - nTabOrg) / defWidth)+1) * defWidth) - current_x;
1493 else if ((!cTabStops) && (defWidth < 0))
1494 FIXME("TODO: Negative defWidth\n");
1496 return x;
1499 /***********************************************************************
1500 * Helper function for ScriptStringAnalyse
1502 static BOOL requires_fallback(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
1503 const WCHAR *pwcInChars, int cChars )
1505 /* FIXME: When to properly fallback is still a bit of a mystery */
1506 WORD *glyphs;
1508 if (psa->fNoGlyphIndex)
1509 return FALSE;
1511 if (init_script_cache(hdc, psc) != S_OK)
1512 return FALSE;
1514 if (SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa) != S_OK)
1515 return TRUE;
1517 glyphs = heap_alloc(sizeof(WORD) * cChars);
1518 if (!glyphs)
1519 return FALSE;
1520 if (ScriptGetCMap(hdc, psc, pwcInChars, cChars, 0, glyphs) != S_OK)
1522 heap_free(glyphs);
1523 return TRUE;
1525 heap_free(glyphs);
1527 return FALSE;
1530 static void find_fallback_font(DWORD scriptid, LPWSTR FaceName)
1532 HKEY hkey;
1534 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Uniscribe\\Fallback", &hkey))
1536 static const WCHAR szFmt[] = {'%','x',0};
1537 WCHAR value[10];
1538 DWORD count = LF_FACESIZE * sizeof(WCHAR);
1539 DWORD type;
1541 sprintfW(value, szFmt, scriptInformation[scriptid].scriptTag);
1542 if (RegQueryValueExW(hkey, value, 0, &type, (LPBYTE)FaceName, &count))
1543 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1544 RegCloseKey(hkey);
1546 else
1547 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1550 /***********************************************************************
1551 * ScriptStringAnalyse (USP10.@)
1554 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
1555 int cGlyphs, int iCharset, DWORD dwFlags,
1556 int iReqWidth, SCRIPT_CONTROL *psControl,
1557 SCRIPT_STATE *psState, const int *piDx,
1558 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
1559 SCRIPT_STRING_ANALYSIS *pssa)
1561 HRESULT hr = E_OUTOFMEMORY;
1562 StringAnalysis *analysis = NULL;
1563 SCRIPT_CONTROL sControl;
1564 SCRIPT_STATE sState;
1565 int i, num_items = 255;
1566 BYTE *BidiLevel;
1567 WCHAR *iString = NULL;
1569 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1570 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
1571 psControl, psState, piDx, pTabdef, pbInClass, pssa);
1573 if (iCharset != -1)
1575 FIXME("Only Unicode strings are supported\n");
1576 return E_INVALIDARG;
1578 if (cString < 1 || !pString) return E_INVALIDARG;
1579 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
1581 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
1582 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
1584 /* FIXME: handle clipping */
1585 analysis->clip_len = cString;
1586 analysis->hdc = hdc;
1587 analysis->dwFlags = dwFlags;
1589 if (psState)
1590 sState = *psState;
1591 else
1592 memset(&sState, 0, sizeof(SCRIPT_STATE));
1594 if (psControl)
1595 sControl = *psControl;
1596 else
1597 memset(&sControl, 0, sizeof(SCRIPT_CONTROL));
1599 if (dwFlags & SSA_PASSWORD)
1601 iString = heap_alloc(sizeof(WCHAR)*cString);
1602 if (!iString)
1604 hr = E_OUTOFMEMORY;
1605 goto error;
1607 for (i = 0; i < cString; i++)
1608 iString[i] = *((const WCHAR *)pString);
1609 pString = iString;
1612 hr = ScriptItemize(pString, cString, num_items, &sControl, &sState, analysis->pItem,
1613 &analysis->numItems);
1615 while (hr == E_OUTOFMEMORY)
1617 SCRIPT_ITEM *tmp;
1619 num_items *= 2;
1620 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
1621 goto error;
1623 analysis->pItem = tmp;
1624 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
1625 &analysis->numItems);
1627 if (hr != S_OK) goto error;
1629 /* set back to out of memory for default goto error behaviour */
1630 hr = E_OUTOFMEMORY;
1632 if (dwFlags & SSA_BREAK)
1634 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
1636 for (i = 0; i < analysis->numItems; i++)
1637 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]);
1639 else
1640 goto error;
1643 if (!(analysis->logical2visual = heap_alloc_zero(sizeof(int) * analysis->numItems)))
1644 goto error;
1645 if (!(BidiLevel = heap_alloc_zero(analysis->numItems)))
1646 goto error;
1648 if (dwFlags & SSA_GLYPHS)
1650 int tab_x = 0;
1651 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
1653 heap_free(BidiLevel);
1654 goto error;
1657 for (i = 0; i < analysis->numItems; i++)
1659 SCRIPT_CACHE *sc = (SCRIPT_CACHE*)&analysis->glyphs[i].sc;
1660 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1661 int numGlyphs = 1.5 * cChar + 16;
1662 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
1663 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
1664 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
1665 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * numGlyphs);
1666 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
1667 ABC *abc = heap_alloc_zero(sizeof(ABC));
1668 int numGlyphsReturned;
1669 HFONT originalFont = 0x0;
1671 /* FIXME: non unicode strings */
1672 const WCHAR* pStr = (const WCHAR*)pString;
1673 analysis->glyphs[i].fallbackFont = NULL;
1675 if (!glyphs || !pwLogClust || !piAdvance || !psva || !pGoffset || !abc)
1677 heap_free (BidiLevel);
1678 heap_free (glyphs);
1679 heap_free (pwLogClust);
1680 heap_free (piAdvance);
1681 heap_free (psva);
1682 heap_free (pGoffset);
1683 heap_free (abc);
1684 hr = E_OUTOFMEMORY;
1685 goto error;
1688 if ((dwFlags & SSA_FALLBACK) && requires_fallback(hdc, sc, &analysis->pItem[i].a, &pStr[analysis->pItem[i].iCharPos], cChar))
1690 LOGFONTW lf;
1691 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), & lf);
1692 lf.lfCharSet = scriptInformation[analysis->pItem[i].a.eScript].props.bCharSet;
1693 find_fallback_font(analysis->pItem[i].a.eScript, lf.lfFaceName);
1694 analysis->glyphs[i].fallbackFont = CreateFontIndirectW(&lf);
1695 if (analysis->glyphs[i].fallbackFont)
1697 ScriptFreeCache(sc);
1698 originalFont = SelectObject(hdc, analysis->glyphs[i].fallbackFont);
1702 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
1703 cChar, numGlyphs, &analysis->pItem[i].a,
1704 glyphs, pwLogClust, psva, &numGlyphsReturned);
1705 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
1706 piAdvance, pGoffset, abc);
1707 if (originalFont)
1708 SelectObject(hdc,originalFont);
1710 if (dwFlags & SSA_TAB)
1712 int tabi = 0;
1713 for (tabi = 0; tabi < cChar; tabi++)
1715 if (pStr[analysis->pItem[i].iCharPos+tabi] == 0x0009)
1716 piAdvance[tabi] = getGivenTabWidth(analysis->glyphs[i].sc, pTabdef, analysis->pItem[i].iCharPos+tabi, tab_x);
1717 tab_x+=piAdvance[tabi];
1721 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
1722 analysis->glyphs[i].glyphs = glyphs;
1723 analysis->glyphs[i].pwLogClust = pwLogClust;
1724 analysis->glyphs[i].piAdvance = piAdvance;
1725 analysis->glyphs[i].psva = psva;
1726 analysis->glyphs[i].pGoffset = pGoffset;
1727 analysis->glyphs[i].abc = abc;
1728 analysis->glyphs[i].iMaxPosX= -1;
1730 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1733 else
1735 for (i = 0; i < analysis->numItems; i++)
1736 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1739 ScriptLayout(analysis->numItems, BidiLevel, NULL, analysis->logical2visual);
1740 heap_free(BidiLevel);
1742 *pssa = analysis;
1743 heap_free(iString);
1744 return S_OK;
1746 error:
1747 heap_free(iString);
1748 heap_free(analysis->glyphs);
1749 heap_free(analysis->logattrs);
1750 heap_free(analysis->pItem);
1751 heap_free(analysis->logical2visual);
1752 heap_free(analysis);
1753 return hr;
1756 static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
1758 int i;
1760 if (pva[glyph].fClusterStart)
1761 return TRUE;
1762 for (i = 0; i < cChars; i++)
1763 if (pwLogClust[i] == glyph) break;
1764 if (i != cChars)
1765 return TRUE;
1767 return FALSE;
1771 static HRESULT SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa,
1772 int iX,
1773 int iY,
1774 int iItem,
1775 int cStart,
1776 int cEnd,
1777 UINT uOptions,
1778 const RECT *prc,
1779 BOOL fSelected,
1780 BOOL fDisabled)
1782 StringAnalysis *analysis;
1783 int off_x = 0;
1784 HRESULT hr;
1785 COLORREF BkColor = 0x0;
1786 COLORREF TextColor = 0x0;
1787 INT BkMode = 0;
1788 INT runStart, runEnd;
1789 INT iGlyph, cGlyphs;
1790 HFONT oldFont = 0x0;
1792 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1793 ssa, iX, iY, iItem, cStart, cEnd, uOptions, fSelected, fDisabled);
1795 if (!(analysis = ssa)) return E_INVALIDARG;
1797 if ((cStart >= 0 && analysis->pItem[iItem+1].iCharPos <= cStart) ||
1798 (cEnd >= 0 && analysis->pItem[iItem].iCharPos >= cEnd))
1799 return S_OK;
1801 if (fSelected)
1803 BkMode = GetBkMode(analysis->hdc);
1804 SetBkMode( analysis->hdc, OPAQUE);
1805 BkColor = GetBkColor(analysis->hdc);
1806 SetBkColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHT));
1807 if (!fDisabled)
1809 TextColor = GetTextColor(analysis->hdc);
1810 SetTextColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1813 if (analysis->glyphs[iItem].fallbackFont)
1814 oldFont = SelectObject(analysis->hdc, analysis->glyphs[iItem].fallbackFont);
1816 if (cStart >= 0 && analysis->pItem[iItem+1].iCharPos > cStart && analysis->pItem[iItem].iCharPos <= cStart)
1817 runStart = cStart - analysis->pItem[iItem].iCharPos;
1818 else
1819 runStart = 0;
1820 if (cEnd >= 0 && analysis->pItem[iItem+1].iCharPos > cEnd && analysis->pItem[iItem].iCharPos <= cEnd)
1821 runEnd = (cEnd-1) - analysis->pItem[iItem].iCharPos;
1822 else
1823 runEnd = (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos) - 1;
1825 if (analysis->pItem[iItem].a.fRTL)
1827 if (cEnd >= 0 && cEnd < analysis->pItem[iItem+1].iCharPos)
1828 ScriptStringCPtoX(ssa, cEnd, FALSE, &off_x);
1829 else
1830 ScriptStringCPtoX(ssa, analysis->pItem[iItem+1].iCharPos-1, TRUE, &off_x);
1832 else
1834 if (cStart >=0 && runStart)
1835 ScriptStringCPtoX(ssa, cStart, FALSE, &off_x);
1836 else
1837 ScriptStringCPtoX(ssa, analysis->pItem[iItem].iCharPos, FALSE, &off_x);
1840 if (analysis->pItem[iItem].a.fRTL)
1841 iGlyph = analysis->glyphs[iItem].pwLogClust[runEnd];
1842 else
1843 iGlyph = analysis->glyphs[iItem].pwLogClust[runStart];
1845 if (analysis->pItem[iItem].a.fRTL)
1846 cGlyphs = analysis->glyphs[iItem].pwLogClust[runStart] - iGlyph;
1847 else
1848 cGlyphs = analysis->glyphs[iItem].pwLogClust[runEnd] - iGlyph;
1850 cGlyphs++;
1852 if (cEnd < 0 || scriptInformation[analysis->pItem[iItem].a.eScript].props.fNeedsCaretInfo)
1854 INT direction;
1855 INT clust_glyph;
1857 clust_glyph = iGlyph + cGlyphs;
1858 if (analysis->pItem[iItem].a.fRTL)
1859 direction = -1;
1860 else
1861 direction = 1;
1863 while(clust_glyph < analysis->glyphs[iItem].numGlyphs &&
1864 !does_glyph_start_cluster(analysis->glyphs[iItem].psva, analysis->glyphs[iItem].pwLogClust, (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos), clust_glyph, direction))
1866 cGlyphs++;
1867 clust_glyph++;
1871 hr = ScriptTextOut(analysis->hdc,
1872 (SCRIPT_CACHE *)&analysis->glyphs[iItem].sc, iX + off_x,
1873 iY, uOptions, prc, &analysis->pItem[iItem].a, NULL, 0,
1874 &analysis->glyphs[iItem].glyphs[iGlyph], cGlyphs,
1875 &analysis->glyphs[iItem].piAdvance[iGlyph], NULL,
1876 &analysis->glyphs[iItem].pGoffset[iGlyph]);
1878 TRACE("ScriptTextOut hr=%08x\n", hr);
1880 if (fSelected)
1882 SetBkColor(analysis->hdc, BkColor);
1883 SetBkMode( analysis->hdc, BkMode);
1884 if (!fDisabled)
1885 SetTextColor(analysis->hdc, TextColor);
1887 if (analysis->glyphs[iItem].fallbackFont)
1888 SelectObject(analysis->hdc, oldFont);
1890 return hr;
1893 /***********************************************************************
1894 * ScriptStringOut (USP10.@)
1896 * This function takes the output of ScriptStringAnalyse and joins the segments
1897 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1898 * only processes glyphs.
1900 * Parameters:
1901 * ssa [I] buffer to hold the analysed string components
1902 * iX [I] X axis displacement for output
1903 * iY [I] Y axis displacement for output
1904 * uOptions [I] flags controling output processing
1905 * prc [I] rectangle coordinates
1906 * iMinSel [I] starting pos for substringing output string
1907 * iMaxSel [I] ending pos for substringing output string
1908 * fDisabled [I] controls text highlighting
1910 * RETURNS
1911 * Success: S_OK
1912 * Failure: is the value returned by ScriptTextOut
1914 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
1915 int iX,
1916 int iY,
1917 UINT uOptions,
1918 const RECT *prc,
1919 int iMinSel,
1920 int iMaxSel,
1921 BOOL fDisabled)
1923 StringAnalysis *analysis;
1924 int item;
1925 HRESULT hr;
1927 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1928 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
1930 if (!(analysis = ssa)) return E_INVALIDARG;
1931 if (!(analysis->dwFlags & SSA_GLYPHS)) return E_INVALIDARG;
1933 for (item = 0; item < analysis->numItems; item++)
1935 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], -1, -1, uOptions, prc, FALSE, fDisabled);
1936 if (FAILED(hr))
1937 return hr;
1940 if (iMinSel < iMaxSel && (iMinSel > 0 || iMaxSel > 0))
1942 if (iMaxSel > 0 && iMinSel < 0)
1943 iMinSel = 0;
1944 for (item = 0; item < analysis->numItems; item++)
1946 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], iMinSel, iMaxSel, uOptions, prc, TRUE, fDisabled);
1947 if (FAILED(hr))
1948 return hr;
1952 return S_OK;
1955 /***********************************************************************
1956 * ScriptStringCPtoX (USP10.@)
1959 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
1961 int item;
1962 int runningX = 0;
1963 StringAnalysis* analysis = ssa;
1965 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
1967 if (!ssa || !pX) return S_FALSE;
1968 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
1970 /* icp out of range */
1971 if(icp < 0)
1973 analysis->invalid = TRUE;
1974 return E_INVALIDARG;
1977 for(item=0; item<analysis->numItems; item++)
1979 int CP, i;
1980 int offset;
1982 i = analysis->logical2visual[item];
1983 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1984 /* initialize max extents for uninitialized runs */
1985 if (analysis->glyphs[i].iMaxPosX == -1)
1987 if (analysis->pItem[i].a.fRTL)
1988 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1989 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1990 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1991 else
1992 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1993 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1994 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1997 if (icp >= analysis->pItem[i+1].iCharPos || icp < analysis->pItem[i].iCharPos)
1999 runningX += analysis->glyphs[i].iMaxPosX;
2000 continue;
2003 icp -= analysis->pItem[i].iCharPos;
2004 ScriptCPtoX(icp, fTrailing, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2005 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2006 &analysis->pItem[i].a, &offset);
2007 runningX += offset;
2009 *pX = runningX;
2010 return S_OK;
2013 /* icp out of range */
2014 analysis->invalid = TRUE;
2015 return E_INVALIDARG;
2018 /***********************************************************************
2019 * ScriptStringXtoCP (USP10.@)
2022 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
2024 StringAnalysis* analysis = ssa;
2025 int item;
2027 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
2029 if (!ssa || !piCh || !piTrailing) return S_FALSE;
2030 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2032 /* out of range */
2033 if(iX < 0)
2035 if (analysis->pItem[0].a.fRTL)
2037 *piCh = 1;
2038 *piTrailing = FALSE;
2040 else
2042 *piCh = -1;
2043 *piTrailing = TRUE;
2045 return S_OK;
2048 for(item=0; item<analysis->numItems; item++)
2050 int i;
2051 int CP;
2053 for (i = 0; i < analysis->numItems && analysis->logical2visual[i] != item; i++)
2054 /* nothing */;
2056 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2057 /* initialize max extents for uninitialized runs */
2058 if (analysis->glyphs[i].iMaxPosX == -1)
2060 if (analysis->pItem[i].a.fRTL)
2061 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2062 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2063 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2064 else
2065 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2066 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2067 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
2070 if (iX > analysis->glyphs[i].iMaxPosX)
2072 iX -= analysis->glyphs[i].iMaxPosX;
2073 continue;
2076 ScriptXtoCP(iX, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
2077 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
2078 &analysis->pItem[i].a, piCh, piTrailing);
2079 *piCh += analysis->pItem[i].iCharPos;
2081 return S_OK;
2084 /* out of range */
2085 *piCh = analysis->pItem[analysis->numItems].iCharPos;
2086 *piTrailing = FALSE;
2088 return S_OK;
2092 /***********************************************************************
2093 * ScriptStringFree (USP10.@)
2095 * Free a string analysis.
2097 * PARAMS
2098 * pssa [I] string analysis.
2100 * RETURNS
2101 * Success: S_OK
2102 * Failure: Non-zero HRESULT value.
2104 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
2106 StringAnalysis* analysis;
2107 BOOL invalid;
2108 int i;
2110 TRACE("(%p)\n", pssa);
2112 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
2114 invalid = analysis->invalid;
2116 if (analysis->glyphs)
2118 for (i = 0; i < analysis->numItems; i++)
2120 heap_free(analysis->glyphs[i].glyphs);
2121 heap_free(analysis->glyphs[i].pwLogClust);
2122 heap_free(analysis->glyphs[i].piAdvance);
2123 heap_free(analysis->glyphs[i].psva);
2124 heap_free(analysis->glyphs[i].pGoffset);
2125 heap_free(analysis->glyphs[i].abc);
2126 if (analysis->glyphs[i].fallbackFont)
2127 DeleteObject(analysis->glyphs[i].fallbackFont);
2128 ScriptFreeCache((SCRIPT_CACHE *)&analysis->glyphs[i].sc);
2129 heap_free(analysis->glyphs[i].sc);
2131 heap_free(analysis->glyphs);
2134 heap_free(analysis->pItem);
2135 heap_free(analysis->logattrs);
2136 heap_free(analysis->sz);
2137 heap_free(analysis->logical2visual);
2138 heap_free(analysis);
2140 if (invalid) return E_INVALIDARG;
2141 return S_OK;
2144 static inline int get_cluster_size(const WORD *pwLogClust, int cChars, int item,
2145 int direction, int* iCluster, int *check_out)
2147 int clust_size = 1;
2148 int check;
2149 WORD clust = pwLogClust[item];
2151 for (check = item+direction; check < cChars && check >= 0; check+=direction)
2153 if (pwLogClust[check] == clust)
2155 clust_size ++;
2156 if (iCluster && *iCluster == -1)
2157 *iCluster = item;
2159 else break;
2162 if (check_out)
2163 *check_out = check;
2165 return clust_size;
2168 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)
2170 int advance;
2171 int log_clust_max = 0;
2172 int i;
2174 advance = piAdvance[glyph];
2176 for (i = 0; i < cChars; i++)
2178 if (pwLogClust[i] > log_clust_max)
2179 log_clust_max = pwLogClust[i];
2182 if (glyph > log_clust_max)
2183 return advance;
2185 for (glyph+=direction; glyph < cGlyphs && glyph >= 0; glyph +=direction)
2188 if (does_glyph_start_cluster(pva, pwLogClust, cChars, glyph, direction))
2189 break;
2190 if (glyph > log_clust_max)
2191 break;
2192 advance += piAdvance[glyph];
2195 return advance;
2198 /***********************************************************************
2199 * ScriptCPtoX (USP10.@)
2202 HRESULT WINAPI ScriptCPtoX(int iCP,
2203 BOOL fTrailing,
2204 int cChars,
2205 int cGlyphs,
2206 const WORD *pwLogClust,
2207 const SCRIPT_VISATTR *psva,
2208 const int *piAdvance,
2209 const SCRIPT_ANALYSIS *psa,
2210 int *piX)
2212 int item;
2213 float iPosX;
2214 int iSpecial = -1;
2215 int iCluster = -1;
2216 int clust_size = 1;
2217 float special_size = 0.0;
2218 int iMaxPos = 0;
2219 int advance = 0;
2220 BOOL rtl = FALSE;
2222 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2223 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
2224 psa, piX);
2226 if (psa->fRTL && ! psa->fLogicalOrder)
2227 rtl = TRUE;
2229 if (fTrailing)
2230 iCP++;
2232 if (rtl)
2234 int max_clust = pwLogClust[0];
2236 for (item=0; item < cGlyphs; item++)
2237 if (pwLogClust[item] > max_clust)
2239 ERR("We do not handle non reversed clusters properly\n");
2240 break;
2243 iMaxPos = 0;
2244 for (item = max_clust; item >=0; item --)
2245 iMaxPos += piAdvance[item];
2248 iPosX = 0.0;
2249 for (item=0; item < iCP && item < cChars; item++)
2251 if (iSpecial == -1 && (iCluster == -1 || (iCluster != -1 && iCluster+clust_size <= item)))
2253 int check;
2254 int clust = pwLogClust[item];
2256 iCluster = -1;
2257 clust_size = get_cluster_size(pwLogClust, cChars, item, 1, &iCluster,
2258 &check);
2260 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, 1);
2262 if (check >= cChars && !iMaxPos)
2264 for (check = clust; check < cChars; check++)
2265 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, 1);
2266 iSpecial = item;
2267 special_size /= (cChars - item);
2268 iPosX += special_size;
2270 else
2272 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2274 clust_size --;
2275 if (clust_size == 0)
2276 iPosX += advance;
2278 else
2279 iPosX += advance / (float)clust_size;
2282 else if (iSpecial != -1)
2283 iPosX += special_size;
2284 else /* (iCluster != -1) */
2286 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], 1);
2287 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2289 clust_size --;
2290 if (clust_size == 0)
2291 iPosX += adv;
2293 else
2294 iPosX += adv / (float)clust_size;
2298 if (iMaxPos > 0)
2300 iPosX = iMaxPos - iPosX;
2301 if (iPosX < 0)
2302 iPosX = 0;
2305 *piX = iPosX;
2306 TRACE("*piX=%d\n", *piX);
2307 return S_OK;
2310 /***********************************************************************
2311 * ScriptXtoCP (USP10.@)
2314 HRESULT WINAPI ScriptXtoCP(int iX,
2315 int cChars,
2316 int cGlyphs,
2317 const WORD *pwLogClust,
2318 const SCRIPT_VISATTR *psva,
2319 const int *piAdvance,
2320 const SCRIPT_ANALYSIS *psa,
2321 int *piCP,
2322 int *piTrailing)
2324 int item;
2325 float iPosX;
2326 float iLastPosX;
2327 int iSpecial = -1;
2328 int iCluster = -1;
2329 int clust_size = 1;
2330 int cjump = 0;
2331 int advance;
2332 float special_size = 0.0;
2333 int direction = 1;
2335 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2336 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
2337 psa, piCP, piTrailing);
2339 if (psa->fRTL && ! psa->fLogicalOrder)
2340 direction = -1;
2342 if (direction<0)
2344 int max_clust = pwLogClust[0];
2346 if (iX < 0)
2348 *piCP = cChars;
2349 *piTrailing = 0;
2350 return S_OK;
2353 for (item=0; item < cChars; item++)
2354 if (pwLogClust[item] > max_clust)
2356 ERR("We do not handle non reversed clusters properly\n");
2357 break;
2361 if (iX < 0)
2363 *piCP = -1;
2364 *piTrailing = 1;
2365 return S_OK;
2368 iPosX = iLastPosX = 0;
2369 if (direction > 0)
2370 item = 0;
2371 else
2372 item = cChars - 1;
2373 for (; iPosX <= iX && item < cChars && item >= 0; item+=direction)
2375 iLastPosX = iPosX;
2376 if (iSpecial == -1 &&
2377 (iCluster == -1 ||
2378 (iCluster != -1 &&
2379 ((direction > 0 && iCluster+clust_size <= item) ||
2380 (direction < 0 && iCluster-clust_size >= item))
2385 int check;
2386 int clust = pwLogClust[item];
2388 iCluster = -1;
2389 cjump = 0;
2390 clust_size = get_cluster_size(pwLogClust, cChars, item, direction,
2391 &iCluster, &check);
2392 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, direction);
2394 if (check >= cChars && direction > 0)
2396 for (check = clust; check < cChars; check++)
2397 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, direction);
2398 iSpecial = item;
2399 special_size /= (cChars - item);
2400 iPosX += special_size;
2402 else
2404 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2406 if (!cjump)
2407 iPosX += advance;
2408 cjump++;
2410 else
2411 iPosX += advance / (float)clust_size;
2414 else if (iSpecial != -1)
2415 iPosX += special_size;
2416 else /* (iCluster != -1) */
2418 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], direction);
2419 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2421 if (!cjump)
2422 iPosX += adv;
2423 cjump++;
2425 else
2426 iPosX += adv / (float)clust_size;
2430 if (direction > 0)
2432 if (iPosX > iX)
2433 item--;
2434 if (item < cChars && ((iPosX - iLastPosX) / 2.0) + iX >= iPosX)
2436 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2437 item+=(clust_size-1);
2438 *piTrailing = 1;
2440 else
2441 *piTrailing = 0;
2443 else
2445 if (iX == iLastPosX)
2446 item++;
2447 if (iX >= iLastPosX && iX <= iPosX)
2448 item++;
2450 if (iLastPosX == iX)
2451 *piTrailing = 0;
2452 else if (item < 0 || ((iLastPosX - iPosX) / 2.0) + iX <= iLastPosX)
2454 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2455 item-=(clust_size-1);
2456 *piTrailing = 1;
2458 else
2459 *piTrailing = 0;
2462 *piCP = item;
2464 TRACE("*piCP=%d\n", *piCP);
2465 TRACE("*piTrailing=%d\n", *piTrailing);
2466 return S_OK;
2469 /***********************************************************************
2470 * ScriptBreak (USP10.@)
2472 * Retrieve line break information.
2474 * PARAMS
2475 * chars [I] Array of characters.
2476 * sa [I] String analysis.
2477 * la [I] Array of logical attribute structures.
2479 * RETURNS
2480 * Success: S_OK
2481 * Failure: S_FALSE
2483 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
2485 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
2487 if (!la) return S_FALSE;
2489 BREAK_line(chars, count, sa, la);
2491 return S_OK;
2494 /***********************************************************************
2495 * ScriptIsComplex (USP10.@)
2497 * Determine if a string is complex.
2499 * PARAMS
2500 * chars [I] Array of characters to test.
2501 * len [I] Length in characters.
2502 * flag [I] Flag.
2504 * RETURNS
2505 * Success: S_OK
2506 * Failure: S_FALSE
2509 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
2511 int i;
2513 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
2515 for (i = 0; i < len; i++)
2517 int script;
2519 if ((flag & SIC_ASCIIDIGIT) && chars[i] >= 0x30 && chars[i] <= 0x39)
2520 return S_OK;
2522 script = get_char_script(chars[i]);
2523 if ((scriptInformation[script].props.fComplex && (flag & SIC_COMPLEX))||
2524 (!scriptInformation[script].props.fComplex && (flag & SIC_NEUTRAL)))
2525 return S_OK;
2527 return S_FALSE;
2530 /***********************************************************************
2531 * ScriptShapeOpenType (USP10.@)
2533 * Produce glyphs and visual attributes for a run.
2535 * PARAMS
2536 * hdc [I] Device context.
2537 * psc [I/O] Opaque pointer to a script cache.
2538 * psa [I/O] Script analysis.
2539 * tagScript [I] The OpenType tag for the Script
2540 * tagLangSys [I] The OpenType tag for the Language
2541 * rcRangeChars[I] Array of Character counts in each range
2542 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2543 * cRanges [I] Count of ranges
2544 * pwcChars [I] Array of characters specifying the run.
2545 * cChars [I] Number of characters in pwcChars.
2546 * cMaxGlyphs [I] Length of pwOutGlyphs.
2547 * pwLogClust [O] Array of logical cluster info.
2548 * pCharProps [O] Array of character property values
2549 * pwOutGlyphs [O] Array of glyphs.
2550 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2551 * pcGlyphs [O] Number of glyphs returned.
2553 * RETURNS
2554 * Success: S_OK
2555 * Failure: Non-zero HRESULT value.
2557 HRESULT WINAPI ScriptShapeOpenType( HDC hdc, SCRIPT_CACHE *psc,
2558 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
2559 OPENTYPE_TAG tagLangSys, int *rcRangeChars,
2560 TEXTRANGE_PROPERTIES **rpRangeProperties,
2561 int cRanges, const WCHAR *pwcChars, int cChars,
2562 int cMaxGlyphs, WORD *pwLogClust,
2563 SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs,
2564 SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs)
2566 HRESULT hr;
2567 unsigned int i;
2568 BOOL rtl;
2570 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2571 hdc, psc, psa,
2572 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2573 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2574 cChars, cMaxGlyphs, pwLogClust, pCharProps, pwOutGlyphs, pOutGlyphProps, pcGlyphs);
2576 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
2577 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
2579 if (!pOutGlyphProps || !pcGlyphs || !pCharProps) return E_INVALIDARG;
2580 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2582 if (cRanges)
2583 FIXME("Ranges not supported yet\n");
2585 rtl = (psa && !psa->fLogicalOrder && psa->fRTL);
2587 *pcGlyphs = cChars;
2588 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2589 if (!pwLogClust) return E_FAIL;
2591 ((ScriptCache *)*psc)->userScript = tagScript;
2592 ((ScriptCache *)*psc)->userLang = tagLangSys;
2594 /* set fNoGlyphIndex non truetype/opentype fonts */
2595 if (!psa->fNoGlyphIndex && !((ScriptCache *)*psc)->sfnt)
2596 psa->fNoGlyphIndex = TRUE;
2598 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2599 for (i = 0; i < cChars; i++)
2601 int idx = i;
2602 if (rtl) idx = cChars - 1 - i;
2603 /* FIXME: set to better values */
2604 pOutGlyphProps[i].sva.uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
2605 pOutGlyphProps[i].sva.fClusterStart = 1;
2606 pOutGlyphProps[i].sva.fDiacritic = 0;
2607 pOutGlyphProps[i].sva.fZeroWidth = 0;
2608 pOutGlyphProps[i].sva.fReserved = 0;
2609 pOutGlyphProps[i].sva.fShapeReserved = 0;
2611 /* FIXME: have the shaping engine set this */
2612 pCharProps[i].fCanGlyphAlone = 0;
2614 pwLogClust[i] = idx;
2617 if (psa && !psa->fNoGlyphIndex)
2619 WCHAR *rChars;
2620 if ((hr = SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa)) != S_OK) return hr;
2622 rChars = heap_alloc(sizeof(WCHAR) * cChars);
2623 if (!rChars) return E_OUTOFMEMORY;
2624 for (i = 0; i < cChars; i++)
2626 int idx = i;
2627 WCHAR chInput;
2628 if (rtl) idx = cChars - 1 - i;
2629 if (psa->fRTL)
2630 chInput = mirror_char(pwcChars[idx]);
2631 else
2632 chInput = pwcChars[idx];
2633 /* special case for tabs */
2634 if (chInput == 0x0009)
2635 chInput = 0x0020;
2636 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, chInput)))
2638 WORD glyph;
2639 if (!hdc)
2641 heap_free(rChars);
2642 return E_PENDING;
2644 if (GetGlyphIndicesW(hdc, &chInput, 1, &glyph, 0) == GDI_ERROR)
2646 heap_free(rChars);
2647 return S_FALSE;
2649 pwOutGlyphs[i] = set_cache_glyph(psc, chInput, glyph);
2651 rChars[i] = chInput;
2654 SHAPE_ContextualShaping(hdc, (ScriptCache *)*psc, psa, rChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
2655 SHAPE_ApplyDefaultOpentypeFeatures(hdc, (ScriptCache *)*psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, pwLogClust);
2656 SHAPE_CharGlyphProp(hdc, (ScriptCache *)*psc, psa, pwcChars, cChars, pwOutGlyphs, *pcGlyphs, pwLogClust, pCharProps, pOutGlyphProps);
2657 heap_free(rChars);
2659 else
2661 TRACE("no glyph translation\n");
2662 for (i = 0; i < cChars; i++)
2664 int idx = i;
2665 /* No mirroring done here */
2666 if (rtl) idx = cChars - 1 - i;
2667 pwOutGlyphs[i] = pwcChars[idx];
2671 return S_OK;
2675 /***********************************************************************
2676 * ScriptShape (USP10.@)
2678 * Produce glyphs and visual attributes for a run.
2680 * PARAMS
2681 * hdc [I] Device context.
2682 * psc [I/O] Opaque pointer to a script cache.
2683 * pwcChars [I] Array of characters specifying the run.
2684 * cChars [I] Number of characters in pwcChars.
2685 * cMaxGlyphs [I] Length of pwOutGlyphs.
2686 * psa [I/O] Script analysis.
2687 * pwOutGlyphs [O] Array of glyphs.
2688 * pwLogClust [O] Array of logical cluster info.
2689 * psva [O] Array of visual attributes.
2690 * pcGlyphs [O] Number of glyphs returned.
2692 * RETURNS
2693 * Success: S_OK
2694 * Failure: Non-zero HRESULT value.
2696 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
2697 int cChars, int cMaxGlyphs,
2698 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
2699 SCRIPT_VISATTR *psva, int *pcGlyphs)
2701 HRESULT hr;
2702 int i;
2703 SCRIPT_CHARPROP *charProps;
2704 SCRIPT_GLYPHPROP *glyphProps;
2706 if (!psva || !pcGlyphs) return E_INVALIDARG;
2707 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2709 charProps = heap_alloc_zero(sizeof(SCRIPT_CHARPROP)*cChars);
2710 if (!charProps) return E_OUTOFMEMORY;
2711 glyphProps = heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP)*cMaxGlyphs);
2712 if (!glyphProps)
2714 heap_free(charProps);
2715 return E_OUTOFMEMORY;
2718 hr = ScriptShapeOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, pwcChars, cChars, cMaxGlyphs, pwLogClust, charProps, pwOutGlyphs, glyphProps, pcGlyphs);
2720 if (SUCCEEDED(hr))
2722 for (i = 0; i < *pcGlyphs; i++)
2723 psva[i] = glyphProps[i].sva;
2726 heap_free(charProps);
2727 heap_free(glyphProps);
2729 return hr;
2732 /***********************************************************************
2733 * ScriptPlaceOpenType (USP10.@)
2735 * Produce advance widths for a run.
2737 * PARAMS
2738 * hdc [I] Device context.
2739 * psc [I/O] Opaque pointer to a script cache.
2740 * psa [I/O] String analysis.
2741 * tagScript [I] The OpenType tag for the Script
2742 * tagLangSys [I] The OpenType tag for the Language
2743 * rcRangeChars[I] Array of Character counts in each range
2744 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2745 * cRanges [I] Count of ranges
2746 * pwcChars [I] Array of characters specifying the run.
2747 * pwLogClust [I] Array of logical cluster info
2748 * pCharProps [I] Array of character property values
2749 * cChars [I] Number of characters in pwcChars.
2750 * pwGlyphs [I] Array of glyphs.
2751 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2752 * cGlyphs [I] Count of Glyphs
2753 * piAdvance [O] Array of advance widths.
2754 * pGoffset [O] Glyph offsets.
2755 * pABC [O] Combined ABC width.
2757 * RETURNS
2758 * Success: S_OK
2759 * Failure: Non-zero HRESULT value.
2762 HRESULT WINAPI ScriptPlaceOpenType( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
2763 OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys,
2764 int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties,
2765 int cRanges, const WCHAR *pwcChars, WORD *pwLogClust,
2766 SCRIPT_CHARPROP *pCharProps, int cChars,
2767 const WORD *pwGlyphs, const SCRIPT_GLYPHPROP *pGlyphProps,
2768 int cGlyphs, int *piAdvance,
2769 GOFFSET *pGoffset, ABC *pABC
2772 HRESULT hr;
2773 int i;
2775 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2776 hdc, psc, psa,
2777 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2778 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2779 pwLogClust, pCharProps, cChars, pwGlyphs, pGlyphProps, cGlyphs, piAdvance,
2780 pGoffset, pABC);
2782 if (!pGlyphProps) return E_INVALIDARG;
2783 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2784 if (!pGoffset) return E_FAIL;
2786 if (cRanges)
2787 FIXME("Ranges not supported yet\n");
2789 ((ScriptCache *)*psc)->userScript = tagScript;
2790 ((ScriptCache *)*psc)->userLang = tagLangSys;
2792 if (pABC) memset(pABC, 0, sizeof(ABC));
2793 for (i = 0; i < cGlyphs; i++)
2795 ABC abc;
2796 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
2798 if (!hdc) return E_PENDING;
2799 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
2801 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
2803 else
2805 INT width;
2806 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
2807 abc.abcB = width;
2808 abc.abcA = abc.abcC = 0;
2810 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
2812 if (pABC)
2814 pABC->abcA += abc.abcA;
2815 pABC->abcB += abc.abcB;
2816 pABC->abcC += abc.abcC;
2818 /* FIXME: set to more reasonable values */
2819 pGoffset[i].du = pGoffset[i].dv = 0;
2820 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
2823 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
2824 return S_OK;
2827 /***********************************************************************
2828 * ScriptPlace (USP10.@)
2830 * Produce advance widths for a run.
2832 * PARAMS
2833 * hdc [I] Device context.
2834 * psc [I/O] Opaque pointer to a script cache.
2835 * pwGlyphs [I] Array of glyphs.
2836 * cGlyphs [I] Number of glyphs in pwGlyphs.
2837 * psva [I] Array of visual attributes.
2838 * psa [I/O] String analysis.
2839 * piAdvance [O] Array of advance widths.
2840 * pGoffset [O] Glyph offsets.
2841 * pABC [O] Combined ABC width.
2843 * RETURNS
2844 * Success: S_OK
2845 * Failure: Non-zero HRESULT value.
2847 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
2848 int cGlyphs, const SCRIPT_VISATTR *psva,
2849 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
2851 HRESULT hr;
2852 SCRIPT_GLYPHPROP *glyphProps;
2853 int i;
2855 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
2856 piAdvance, pGoffset, pABC);
2858 if (!psva) return E_INVALIDARG;
2859 if (!pGoffset) return E_FAIL;
2861 glyphProps = heap_alloc(sizeof(SCRIPT_GLYPHPROP)*cGlyphs);
2862 if (!glyphProps) return E_OUTOFMEMORY;
2864 for (i = 0; i < cGlyphs; i++)
2865 glyphProps[i].sva = psva[i];
2867 hr = ScriptPlaceOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, NULL, NULL, NULL, 0, pwGlyphs, glyphProps, cGlyphs, piAdvance, pGoffset, pABC);
2869 heap_free(glyphProps);
2871 return hr;
2874 /***********************************************************************
2875 * ScriptGetCMap (USP10.@)
2877 * Retrieve glyph indices.
2879 * PARAMS
2880 * hdc [I] Device context.
2881 * psc [I/O] Opaque pointer to a script cache.
2882 * pwcInChars [I] Array of Unicode characters.
2883 * cChars [I] Number of characters in pwcInChars.
2884 * dwFlags [I] Flags.
2885 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2887 * RETURNS
2888 * Success: S_OK
2889 * Failure: Non-zero HRESULT value.
2891 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
2892 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
2894 HRESULT hr;
2895 int i;
2897 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
2898 cChars, dwFlags, pwOutGlyphs);
2900 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2902 hr = S_OK;
2904 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
2906 for (i = 0; i < cChars; i++)
2908 WCHAR inChar;
2909 if (dwFlags == SGCM_RTL)
2910 inChar = mirror_char(pwcInChars[i]);
2911 else
2912 inChar = pwcInChars[i];
2913 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, inChar)))
2915 WORD glyph;
2916 if (!hdc) return E_PENDING;
2917 if (GetGlyphIndicesW(hdc, &inChar, 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
2918 if (glyph == 0xffff)
2920 hr = S_FALSE;
2921 glyph = 0x0;
2923 pwOutGlyphs[i] = set_cache_glyph(psc, inChar, glyph);
2927 else
2929 TRACE("no glyph translation\n");
2930 for (i = 0; i < cChars; i++)
2932 WCHAR inChar;
2933 if (dwFlags == SGCM_RTL)
2934 inChar = mirror_char(pwcInChars[i]);
2935 else
2936 inChar = pwcInChars[i];
2937 pwOutGlyphs[i] = inChar;
2940 return hr;
2943 /***********************************************************************
2944 * ScriptTextOut (USP10.@)
2947 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
2948 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
2949 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
2950 const int *piJustify, const GOFFSET *pGoffset)
2952 HRESULT hr = S_OK;
2954 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2955 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
2956 piAdvance, piJustify, pGoffset);
2958 if (!hdc || !psc) return E_INVALIDARG;
2959 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
2961 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
2962 fuOptions |= ETO_IGNORELANGUAGE;
2963 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
2964 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
2966 if (psa->fRTL && psa->fLogicalOrder)
2968 int i;
2969 WORD *rtlGlyphs;
2971 rtlGlyphs = heap_alloc(cGlyphs * sizeof(WORD));
2972 if (!rtlGlyphs)
2973 return E_OUTOFMEMORY;
2975 for (i = 0; i < cGlyphs; i++)
2976 rtlGlyphs[i] = pwGlyphs[cGlyphs-1-i];
2978 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, rtlGlyphs, cGlyphs, NULL))
2979 hr = S_FALSE;
2980 heap_free(rtlGlyphs);
2982 else
2983 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
2984 hr = S_FALSE;
2986 return hr;
2989 /***********************************************************************
2990 * ScriptCacheGetHeight (USP10.@)
2992 * Retrieve the height of the font in the cache.
2994 * PARAMS
2995 * hdc [I] Device context.
2996 * psc [I/O] Opaque pointer to a script cache.
2997 * height [O] Receives font height.
2999 * RETURNS
3000 * Success: S_OK
3001 * Failure: Non-zero HRESULT value.
3003 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
3005 HRESULT hr;
3007 TRACE("(%p, %p, %p)\n", hdc, psc, height);
3009 if (!height) return E_INVALIDARG;
3010 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
3012 *height = get_cache_height(psc);
3013 return S_OK;
3016 /***********************************************************************
3017 * ScriptGetGlyphABCWidth (USP10.@)
3019 * Retrieve the width of a glyph.
3021 * PARAMS
3022 * hdc [I] Device context.
3023 * psc [I/O] Opaque pointer to a script cache.
3024 * glyph [I] Glyph to retrieve the width for.
3025 * abc [O] ABC widths of the glyph.
3027 * RETURNS
3028 * Success: S_OK
3029 * Failure: Non-zero HRESULT value.
3031 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
3033 HRESULT hr;
3035 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
3037 if (!abc) return E_INVALIDARG;
3038 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
3040 if (!get_cache_glyph_widths(psc, glyph, abc))
3042 if (!hdc) return E_PENDING;
3043 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
3045 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
3047 else
3049 INT width;
3050 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
3051 abc->abcB = width;
3052 abc->abcA = abc->abcC = 0;
3054 set_cache_glyph_widths(psc, glyph, abc);
3056 return S_OK;
3059 /***********************************************************************
3060 * ScriptLayout (USP10.@)
3062 * Map embedding levels to visual and/or logical order.
3064 * PARAMS
3065 * runs [I] Size of level array.
3066 * level [I] Array of embedding levels.
3067 * vistolog [O] Map of embedding levels from visual to logical order.
3068 * logtovis [O] Map of embedding levels from logical to visual order.
3070 * RETURNS
3071 * Success: S_OK
3072 * Failure: Non-zero HRESULT value.
3074 * BUGS
3075 * This stub works correctly for any sequence of a single
3076 * embedding level but not for sequences of different
3077 * embedding levels, i.e. mixtures of RTL and LTR scripts.
3079 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
3081 int* indexs;
3082 int ich;
3084 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
3086 if (!level || (!vistolog && !logtovis))
3087 return E_INVALIDARG;
3089 indexs = heap_alloc(sizeof(int) * runs);
3090 if (!indexs)
3091 return E_OUTOFMEMORY;
3094 if (vistolog)
3096 for( ich = 0; ich < runs; ich++)
3097 indexs[ich] = ich;
3099 ich = 0;
3100 while (ich < runs)
3101 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
3102 for (ich = 0; ich < runs; ich++)
3103 vistolog[ich] = indexs[ich];
3107 if (logtovis)
3109 for( ich = 0; ich < runs; ich++)
3110 indexs[ich] = ich;
3112 ich = 0;
3113 while (ich < runs)
3114 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
3115 for (ich = 0; ich < runs; ich++)
3116 logtovis[ich] = indexs[ich];
3118 heap_free(indexs);
3120 return S_OK;
3123 /***********************************************************************
3124 * ScriptStringGetLogicalWidths (USP10.@)
3126 * Returns logical widths from a string analysis.
3128 * PARAMS
3129 * ssa [I] string analysis.
3130 * piDx [O] logical widths returned.
3132 * RETURNS
3133 * Success: S_OK
3134 * Failure: a non-zero HRESULT.
3136 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
3138 int i, j, next = 0;
3139 StringAnalysis *analysis = ssa;
3141 TRACE("%p, %p\n", ssa, piDx);
3143 if (!analysis) return S_FALSE;
3144 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
3146 for (i = 0; i < analysis->numItems; i++)
3148 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
3149 int direction = 1;
3151 if (analysis->pItem[i].a.fRTL && ! analysis->pItem[i].a.fLogicalOrder)
3152 direction = -1;
3154 for (j = 0; j < cChar; j++)
3156 int k;
3157 int glyph = analysis->glyphs[i].pwLogClust[j];
3158 int clust_size = get_cluster_size(analysis->glyphs[i].pwLogClust,
3159 cChar, j, direction, NULL, NULL);
3160 int advance = get_glyph_cluster_advance(analysis->glyphs[i].piAdvance, analysis->glyphs[i].psva, analysis->glyphs[i].pwLogClust, analysis->glyphs[i].numGlyphs, cChar, glyph, direction);
3162 for (k = 0; k < clust_size; k++)
3164 piDx[next] = advance / clust_size;
3165 next++;
3166 if (k) j++;
3170 return S_OK;
3173 /***********************************************************************
3174 * ScriptStringValidate (USP10.@)
3176 * Validate a string analysis.
3178 * PARAMS
3179 * ssa [I] string analysis.
3181 * RETURNS
3182 * Success: S_OK
3183 * Failure: S_FALSE if invalid sequences are found
3184 * or a non-zero HRESULT if it fails.
3186 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
3188 StringAnalysis *analysis = ssa;
3190 TRACE("(%p)\n", ssa);
3192 if (!analysis) return E_INVALIDARG;
3193 return (analysis->invalid) ? S_FALSE : S_OK;
3196 /***********************************************************************
3197 * ScriptString_pSize (USP10.@)
3199 * Retrieve width and height of an analysed string.
3201 * PARAMS
3202 * ssa [I] string analysis.
3204 * RETURNS
3205 * Success: Pointer to a SIZE structure.
3206 * Failure: NULL
3208 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
3210 int i, j;
3211 StringAnalysis *analysis = ssa;
3213 TRACE("(%p)\n", ssa);
3215 if (!analysis) return NULL;
3216 if (!(analysis->dwFlags & SSA_GLYPHS)) return NULL;
3218 if (!analysis->sz)
3220 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
3221 analysis->sz->cy = analysis->glyphs[0].sc->tm.tmHeight;
3223 analysis->sz->cx = 0;
3224 for (i = 0; i < analysis->numItems; i++)
3226 if (analysis->glyphs[i].sc->tm.tmHeight > analysis->sz->cy)
3227 analysis->sz->cy = analysis->glyphs[i].sc->tm.tmHeight;
3228 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
3229 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
3232 return analysis->sz;
3235 /***********************************************************************
3236 * ScriptString_pLogAttr (USP10.@)
3238 * Retrieve logical attributes of an analysed string.
3240 * PARAMS
3241 * ssa [I] string analysis.
3243 * RETURNS
3244 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3245 * Failure: NULL
3247 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
3249 StringAnalysis *analysis = ssa;
3251 TRACE("(%p)\n", ssa);
3253 if (!analysis) return NULL;
3254 if (!(analysis->dwFlags & SSA_BREAK)) return NULL;
3255 return analysis->logattrs;
3258 /***********************************************************************
3259 * ScriptString_pcOutChars (USP10.@)
3261 * Retrieve the length of a string after clipping.
3263 * PARAMS
3264 * ssa [I] String analysis.
3266 * RETURNS
3267 * Success: Pointer to the length.
3268 * Failure: NULL
3270 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
3272 StringAnalysis *analysis = ssa;
3274 TRACE("(%p)\n", ssa);
3276 if (!analysis) return NULL;
3277 return &analysis->clip_len;
3280 /***********************************************************************
3281 * ScriptStringGetOrder (USP10.@)
3283 * Retrieve a glyph order map.
3285 * PARAMS
3286 * ssa [I] String analysis.
3287 * order [I/O] Array of glyph positions.
3289 * RETURNS
3290 * Success: S_OK
3291 * Failure: a non-zero HRESULT.
3293 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
3295 int i, j;
3296 unsigned int k;
3297 StringAnalysis *analysis = ssa;
3299 TRACE("(%p)\n", ssa);
3301 if (!analysis) return S_FALSE;
3302 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
3304 /* FIXME: handle RTL scripts */
3305 for (i = 0, k = 0; i < analysis->numItems; i++)
3306 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
3307 order[k] = k;
3309 return S_OK;
3312 /***********************************************************************
3313 * ScriptGetLogicalWidths (USP10.@)
3315 * Convert advance widths to logical widths.
3317 * PARAMS
3318 * sa [I] Script analysis.
3319 * nbchars [I] Number of characters.
3320 * nbglyphs [I] Number of glyphs.
3321 * glyph_width [I] Array of glyph widths.
3322 * log_clust [I] Array of logical clusters.
3323 * sva [I] Visual attributes.
3324 * widths [O] Array of logical widths.
3326 * RETURNS
3327 * Success: S_OK
3328 * Failure: a non-zero HRESULT.
3330 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
3331 const int *glyph_width, const WORD *log_clust,
3332 const SCRIPT_VISATTR *sva, int *widths)
3334 int i;
3336 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3337 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
3339 /* FIXME */
3340 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
3341 return S_OK;
3344 /***********************************************************************
3345 * ScriptApplyLogicalWidth (USP10.@)
3347 * Generate glyph advance widths.
3349 * PARAMS
3350 * dx [I] Array of logical advance widths.
3351 * num_chars [I] Number of characters.
3352 * num_glyphs [I] Number of glyphs.
3353 * log_clust [I] Array of logical clusters.
3354 * sva [I] Visual attributes.
3355 * advance [I] Array of glyph advance widths.
3356 * sa [I] Script analysis.
3357 * abc [I/O] Summed ABC widths.
3358 * justify [O] Array of glyph advance widths.
3360 * RETURNS
3361 * Success: S_OK
3362 * Failure: a non-zero HRESULT.
3364 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
3365 const WORD *log_clust, const SCRIPT_VISATTR *sva,
3366 const int *advance, const SCRIPT_ANALYSIS *sa,
3367 ABC *abc, int *justify)
3369 int i;
3371 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3372 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
3374 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
3375 return S_OK;
3378 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
3379 int num_glyphs, int dx, int min_kashida, int *justify)
3381 int i;
3383 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
3385 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
3386 return S_OK;