usp10: Break with a better understanding on the handling of bidi strengths.
[wine.git] / dlls / usp10 / usp10.c
blob0496a561ff928d094fe2d4a40ccae40fac2817e4
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 /* Latin-1 Supplement: U+0080–U+00FF */
56 /* Latin Extended-A: U+0100–U+017F */
57 /* Latin Extended-B: U+0180–U+024F */
58 /* IPA Extensions: U+0250–U+02AF */
59 { Script_Latin, 0x00, 0x2af , Script_Numeric, Script_Punctuation},
60 /* Greek: U+0370–U+03FF */
61 { Script_Greek, 0x370, 0x3ff, 0, 0},
62 /* Cyrillic: U+0400–U+04FF */
63 /* Cyrillic Supplement: U+0500–U+052F */
64 { Script_Cyrillic, 0x400, 0x52f, 0, 0},
65 /* Armenian: U+0530–U+058F */
66 { Script_Armenian, 0x530, 0x58f, 0, 0},
67 /* Hebrew: U+0590–U+05FF */
68 { Script_Hebrew, 0x590, 0x5ff, 0, 0},
69 /* Arabic: U+0600–U+06FF */
70 { Script_Arabic, 0x600, 0x6ef, Script_Arabic_Numeric, 0},
71 /* Defined by Windows */
72 { Script_Persian, 0x6f0, 0x6f9, 0, 0},
73 /* Continue Arabic: U+0600–U+06FF */
74 { Script_Arabic, 0x6fa, 0x6ff, 0, 0},
75 /* Syriac: U+0700–U+074F*/
76 { Script_Syriac, 0x700, 0x74f, 0, 0},
77 /* Arabic Supplement: U+0750–U+077F */
78 { Script_Arabic, 0x750, 0x77f, 0, 0},
79 /* Thaana: U+0780–U+07BF */
80 { Script_Thaana, 0x780, 0x7bf, 0, 0},
81 /* Devanagari: U+0900–U+097F */
82 { Script_Devanagari, 0x900, 0x97f, Script_Devanagari_Numeric, 0},
83 /* Bengali: U+0980–U+09FF */
84 { Script_Bengali, 0x980, 0x9ff, Script_Bengali_Numeric, 0},
85 /* Gurmukhi: U+0A00–U+0A7F*/
86 { Script_Gurmukhi, 0xa00, 0xa7f, Script_Gurmukhi_Numeric, 0},
87 /* Gujarati: U+0A80–U+0AFF*/
88 { Script_Gujarati, 0xa80, 0xaff, Script_Gujarati_Numeric, 0},
89 /* Oriya: U+0B00–U+0B7F */
90 { Script_Oriya, 0xb00, 0xb7f, Script_Oriya_Numeric, 0},
91 /* Tamil: U+0B80–U+0BFF */
92 { Script_Tamil, 0xb80, 0xbff, Script_Tamil_Numeric, 0},
93 /* Telugu: U+0C00–U+0C7F */
94 { Script_Telugu, 0xc00, 0xc7f, Script_Telugu_Numeric, 0},
95 /* Kannada: U+0C80–U+0CFF */
96 { Script_Kannada, 0xc80, 0xcff, Script_Kannada_Numeric, 0},
97 /* Malayalam: U+0D00–U+0D7F */
98 { Script_Malayalam, 0xd00, 0xd7f, Script_Malayalam_Numeric, 0},
99 /* Sinhala: U+0D80–U+0DFF */
100 { Script_Sinhala, 0xd80, 0xdff, 0, 0},
101 /* Thai: U+0E00–U+0E7F */
102 { Script_Thai, 0xe00, 0xe7f, Script_Thai_Numeric, 0},
103 /* Lao: U+0E80–U+0EFF */
104 { Script_Lao, 0xe80, 0xeff, Script_Lao_Numeric, 0},
105 /* Tibetan: U+0F00–U+0FFF */
106 { Script_Tibetan, 0xf00, 0xfff, Script_Tibetan_Numeric, 0},
107 /* Georgian: U+10A0–U+10FF */
108 { Script_Georgian, 0x10a0, 0x10ff, 0, 0},
109 /* Vedic Extensions: U+1CD0-U+1CFF */
110 { Script_Devanagari, 0x1cd0, 0x1cff, Script_Devanagari_Numeric, 0},
111 /* Phonetic Extensions: U+1D00–U+1DBF */
112 { Script_Latin, 0x1d00, 0x1dbf, 0, 0},
113 /* Latin Extended Additional: U+1E00–U+1EFF */
114 { Script_Latin, 0x1e00, 0x1eff, 0, 0},
115 /* Greek Extended: U+1F00–U+1FFF */
116 { Script_Greek, 0x1f00, 0x1fff, 0, 0},
117 /* General Punctuation: U+2000 –U+206f */
118 /* Superscripts and Subscripts : U+2070 –U+209f */
119 /* Currency Symbols : U+20a0 –U+20cf */
120 { Script_Latin, 0x2000, 0x20cf, 0, 0},
121 /* Letterlike Symbols : U+2100 –U+214f */
122 /* Number Forms : U+2150 –U+218f */
123 /* Arrows : U+2190 –U+21ff */
124 /* Mathematical Operators : U+2200 –U+22ff */
125 /* Miscellaneous Technical : U+2300 –U+23ff */
126 /* Control Pictures : U+2400 –U+243f */
127 /* Optical Character Recognition : U+2440 –U+245f */
128 /* Enclosed Alphanumerics : U+2460 –U+24ff */
129 /* Box Drawing : U+2500 –U+25ff */
130 /* Block Elements : U+2580 –U+259f */
131 /* Geometric Shapes : U+25a0 –U+25ff */
132 /* Miscellaneous Symbols : U+2600 –U+26ff */
133 /* Dingbats : U+2700 –U+27bf */
134 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
135 /* Supplemental Arrows-A : U+27f0 –U+27ff */
136 { Script_Latin, 0x2100, 0x27ff, 0, 0},
137 /* Supplemental Arrows-B : U+2900 –U+297f */
138 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
139 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
140 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
141 { Script_Latin, 0x2900, 0x2bff, 0, 0},
142 /* Latin Extended-C: U+2C60–U+2C7F */
143 { Script_Latin, 0x2c60, 0x2c7f, 0, 0},
144 /* Georgian: U+2D00–U+2D2F */
145 { Script_Georgian, 0x2d00, 0x2d2f, 0, 0},
146 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
147 { Script_Cyrillic, 0x2de0, 0x2dff, 0, 0},
148 /* Cyrillic Extended-B: U+A640–U+A69F */
149 { Script_Cyrillic, 0xa640, 0xa69f, 0, 0},
150 /* Modifier Tone Letters: U+A700–U+A71F */
151 /* Latin Extended-D: U+A720–U+A7FF */
152 { Script_Latin, 0xa700, 0xa7ff, 0, 0},
153 /* Phags-pa: U+A840–U+A87F */
154 { Script_Phags_pa, 0xa840, 0xa87f, 0, 0},
155 /* Devanagari Extended: U+A8E0-U+A8FF */
156 { Script_Devanagari, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric, 0},
157 /* Latin Ligatures: U+FB00–U+FB06 */
158 { Script_Latin, 0xfb00, 0xfb06, 0, 0},
159 /* Armenian ligatures U+FB13..U+FB17 */
160 { Script_Armenian, 0xfb13, 0xfb17, 0, 0},
161 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
162 { Script_Hebrew, 0xfb1d, 0xfb4f, 0, 0},
163 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
164 { Script_Arabic, 0xfb50, 0xfdff, 0, 0},
165 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
166 { Script_Arabic, 0xfe70, 0xfeff, 0, 0},
167 /* END */
168 { SCRIPT_UNDEFINED, 0, 0, 0}
171 typedef struct _scriptData
173 SCRIPT_ANALYSIS a;
174 SCRIPT_PROPERTIES props;
175 OPENTYPE_TAG scriptTag;
176 WCHAR fallbackFont[LF_FACESIZE];
177 } scriptData;
179 /* the must be in order so that the index matches the Script value */
180 static const scriptData scriptInformation[] = {
181 {{SCRIPT_UNDEFINED, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
182 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
183 0x00000000,
184 {0}},
185 {{Script_Latin, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
186 {LANG_ENGLISH, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
187 MS_MAKE_TAG('l','a','t','n'),
188 {0}},
189 {{Script_CR, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
190 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
191 0x00000000,
192 {0}},
193 {{Script_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
194 {LANG_ENGLISH, 1, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
195 0x00000000,
196 {0}},
197 {{Script_Control, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
198 {LANG_ENGLISH, 0, 1, 0, 0, ANSI_CHARSET, 1, 0, 0, 0, 0, 0, 1, 0, 0},
199 0x00000000,
200 {0}},
201 {{Script_Punctuation, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
202 {LANG_NEUTRAL, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
203 0x00000000,
204 {0}},
205 {{Script_Arabic, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
206 {LANG_ARABIC, 0, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 1, 0},
207 MS_MAKE_TAG('a','r','a','b'),
208 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
209 {{Script_Arabic_Numeric, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
210 {LANG_ARABIC, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
211 MS_MAKE_TAG('a','r','a','b'),
212 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
213 {{Script_Hebrew, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
214 {LANG_HEBREW, 0, 1, 0, 1, HEBREW_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
215 MS_MAKE_TAG('h','e','b','r'),
216 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
217 {{Script_Syriac, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
218 {LANG_SYRIAC, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 1, 0},
219 MS_MAKE_TAG('s','y','r','c'),
220 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
221 {{Script_Persian, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
222 {LANG_PERSIAN, 1, 1, 0, 0, ARABIC_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
223 MS_MAKE_TAG('s','y','r','c'),
224 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
225 {{Script_Thaana, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
226 {LANG_DIVEHI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
227 MS_MAKE_TAG('t','h','a','a'),
228 {'M','V',' ','B','o','l','i',0}},
229 {{Script_Greek, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
230 {LANG_GREEK, 0, 0, 0, 0, GREEK_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
231 MS_MAKE_TAG('g','r','e','k'),
232 {0}},
233 {{Script_Cyrillic, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
234 {LANG_RUSSIAN, 0, 0, 0, 0, RUSSIAN_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
235 MS_MAKE_TAG('c','y','r','l'),
236 {0}},
237 {{Script_Armenian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
238 {LANG_ARMENIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
239 MS_MAKE_TAG('a','r','m','n'),
240 {'S','y','l','f','a','e','n',0}},
241 {{Script_Georgian, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
242 {LANG_GEORGIAN, 0, 0, 0, 0, ANSI_CHARSET, 0, 0, 0, 0, 0, 0, 1, 0, 0},
243 MS_MAKE_TAG('g','e','o','r'),
244 {'S','y','l','f','a','e','n',0}},
245 {{Script_Sinhala, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
246 {LANG_SINHALESE, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
247 MS_MAKE_TAG('s','i','n','h'),
248 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
249 {{Script_Tibetan, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
250 {LANG_TIBETAN, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
251 MS_MAKE_TAG('t','i','b','t'),
252 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
253 {{Script_Tibetan_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
254 {LANG_TIBETAN, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
255 MS_MAKE_TAG('t','i','b','t'),
256 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
257 {{Script_Phags_pa, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
258 {LANG_MONGOLIAN, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
259 MS_MAKE_TAG('p','h','a','g'),
260 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
261 {{Script_Thai, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
262 {LANG_THAI, 0, 1, 1, 1, THAI_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 1},
263 MS_MAKE_TAG('t','h','a','i'),
264 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
265 {{Script_Thai_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
266 {LANG_THAI, 1, 1, 0, 0, THAI_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
267 MS_MAKE_TAG('t','h','a','i'),
268 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
269 {{Script_Lao, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
270 {LANG_LAO, 0, 1, 1, 1, DEFAULT_CHARSET, 0, 0, 1, 0, 1, 0, 0, 0, 0},
271 MS_MAKE_TAG('l','a','o',' '),
272 {'D','o','k','C','h','a','m','p','a',0}},
273 {{Script_Lao_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
274 {LANG_LAO, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
275 MS_MAKE_TAG('l','a','o',' '),
276 {'D','o','k','C','h','a','m','p','a',0}},
277 {{Script_Devanagari, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
278 {LANG_HINDI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
279 MS_MAKE_TAG('d','e','v','a'),
280 {'M','a','n','g','a','l',0}},
281 {{Script_Devanagari_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
282 {LANG_HINDI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
283 MS_MAKE_TAG('d','e','v','a'),
284 {'M','a','n','g','a','l',0}},
285 {{Script_Bengali, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
286 {LANG_BENGALI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
287 MS_MAKE_TAG('b','e','n','g'),
288 {'V','r','i','n','d','a',0}},
289 {{Script_Bengali_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
290 {LANG_BENGALI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
291 MS_MAKE_TAG('b','e','n','g'),
292 {'V','r','i','n','d','a',0}},
293 {{Script_Bengali_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
294 {LANG_BENGALI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
295 MS_MAKE_TAG('b','e','n','g'),
296 {'V','r','i','n','d','a',0}},
297 {{Script_Gurmukhi, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_PUNJABI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
299 MS_MAKE_TAG('g','u','r','u'),
300 {'R','a','a','v','i',0}},
301 {{Script_Gurmukhi_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_PUNJABI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
303 MS_MAKE_TAG('g','u','r','u'),
304 {'R','a','a','v','i',0}},
305 {{Script_Gujarati, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
306 {LANG_GUJARATI, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
307 MS_MAKE_TAG('g','u','j','r'),
308 {'S','h','r','u','t','i',0}},
309 {{Script_Gujarati_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_GUJARATI, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
311 MS_MAKE_TAG('g','u','j','r'),
312 {'S','h','r','u','t','i',0}},
313 {{Script_Gujarati_Currency, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_GUJARATI, 0, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 MS_MAKE_TAG('g','u','j','r'),
316 {'S','h','r','u','t','i',0}},
317 {{Script_Oriya, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_ORIYA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
319 MS_MAKE_TAG('o','r','y','a'),
320 {'K','a','l','i','n','g','a',0}},
321 {{Script_Oriya_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_ORIYA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
323 MS_MAKE_TAG('o','r','y','a'),
324 {'K','a','l','i','n','g','a',0}},
325 {{Script_Tamil, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_TAMIL, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
327 MS_MAKE_TAG('t','a','m','l'),
328 {'L','a','t','h','a',0}},
329 {{Script_Tamil_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_TAMIL, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
331 MS_MAKE_TAG('t','a','m','l'),
332 {'L','a','t','h','a',0}},
333 {{Script_Telugu, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_TELUGU, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
335 MS_MAKE_TAG('t','e','l','u'),
336 {'G','a','u','t','a','m','i',0}},
337 {{Script_Telugu_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_TELUGU, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
339 MS_MAKE_TAG('t','e','l','u'),
340 {'G','a','u','t','a','m','i',0}},
341 {{Script_Kannada, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_KANNADA, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
343 MS_MAKE_TAG('k','n','d','a'),
344 {'T','u','n','g','a',0}},
345 {{Script_Kannada_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_KANNADA, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 MS_MAKE_TAG('k','n','d','a'),
348 {'T','u','n','g','a',0}},
349 {{Script_Malayalam, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_MALAYALAM, 0, 1, 0, 1, DEFAULT_CHARSET, 0, 0, 0, 0, 1, 0, 0, 0, 0},
351 MS_MAKE_TAG('m','l','y','m'),
352 {'K','a','r','t','i','k','a',0}},
353 {{Script_Malayalam_Numeric, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_MALAYALAM, 1, 1, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 0, 0, 0, 0, 0},
355 MS_MAKE_TAG('m','l','y','m'),
356 {'K','a','r','t','i','k','a',0}},
359 static const SCRIPT_PROPERTIES *script_props[] =
361 &scriptInformation[0].props, &scriptInformation[1].props,
362 &scriptInformation[2].props, &scriptInformation[3].props,
363 &scriptInformation[4].props, &scriptInformation[5].props,
364 &scriptInformation[6].props, &scriptInformation[7].props,
365 &scriptInformation[8].props, &scriptInformation[9].props,
366 &scriptInformation[10].props, &scriptInformation[11].props,
367 &scriptInformation[12].props, &scriptInformation[13].props,
368 &scriptInformation[14].props, &scriptInformation[15].props,
369 &scriptInformation[16].props, &scriptInformation[17].props,
370 &scriptInformation[18].props, &scriptInformation[19].props,
371 &scriptInformation[20].props, &scriptInformation[21].props,
372 &scriptInformation[22].props, &scriptInformation[23].props,
373 &scriptInformation[24].props, &scriptInformation[25].props,
374 &scriptInformation[26].props, &scriptInformation[27].props,
375 &scriptInformation[28].props, &scriptInformation[29].props,
376 &scriptInformation[30].props, &scriptInformation[31].props,
377 &scriptInformation[32].props, &scriptInformation[33].props,
378 &scriptInformation[34].props, &scriptInformation[35].props,
379 &scriptInformation[36].props, &scriptInformation[37].props,
380 &scriptInformation[38].props, &scriptInformation[39].props,
381 &scriptInformation[40].props, &scriptInformation[41].props,
382 &scriptInformation[42].props, &scriptInformation[43].props
385 typedef struct {
386 ScriptCache *sc;
387 int numGlyphs;
388 WORD* glyphs;
389 WORD* pwLogClust;
390 int* piAdvance;
391 SCRIPT_VISATTR* psva;
392 GOFFSET* pGoffset;
393 ABC* abc;
394 int iMaxPosX;
395 HFONT fallbackFont;
396 } StringGlyphs;
398 typedef struct {
399 HDC hdc;
400 DWORD dwFlags;
401 BOOL invalid;
402 int clip_len;
403 int cItems;
404 int cMaxGlyphs;
405 SCRIPT_ITEM* pItem;
406 int numItems;
407 StringGlyphs* glyphs;
408 SCRIPT_LOGATTR* logattrs;
409 SIZE* sz;
410 int* logical2visual;
411 } StringAnalysis;
413 static inline void *heap_alloc(SIZE_T size)
415 return HeapAlloc(GetProcessHeap(), 0, size);
418 static inline void *heap_alloc_zero(SIZE_T size)
420 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
423 static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size)
425 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
428 static inline BOOL heap_free(LPVOID mem)
430 return HeapFree(GetProcessHeap(), 0, mem);
433 static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
435 return ((ScriptCache *)*psc)->tm.tmDefaultChar;
438 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
440 return ((ScriptCache *)*psc)->tm.tmHeight;
443 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
445 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
448 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c)
450 WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
452 if (!block) return 0;
453 return block[c & GLYPH_BLOCK_MASK];
456 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
458 WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
460 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
461 return ((*block)[c & GLYPH_BLOCK_MASK] = glyph);
464 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
466 static const ABC nil;
467 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
469 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
470 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
471 return TRUE;
474 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
476 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
478 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
479 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
480 return TRUE;
483 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
485 ScriptCache *sc;
487 if (!psc) return E_INVALIDARG;
488 if (*psc) return S_OK;
489 if (!hdc) return E_PENDING;
491 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
492 if (!GetTextMetricsW(hdc, &sc->tm))
494 heap_free(sc);
495 return E_INVALIDARG;
497 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
499 heap_free(sc);
500 return E_INVALIDARG;
502 sc->sfnt = (GetFontData(hdc, MS_MAKE_TAG('h','e','a','d'), 0, NULL, 0)!=GDI_ERROR);
503 *psc = sc;
504 TRACE("<- %p\n", sc);
505 return S_OK;
508 static WCHAR mirror_char( WCHAR ch )
510 extern const WCHAR wine_mirror_map[];
511 return ch + wine_mirror_map[wine_mirror_map[ch >> 8] + (ch & 0xff)];
514 static WORD get_char_script( WCHAR ch)
516 WORD type = 0;
517 int i;
519 if (ch == 0xc || ch == 0x20 || ch == 0x202f)
520 return Script_CR;
522 /* These chars are itemized as Punctuation by Windows */
523 if (ch == 0x2212 || ch == 0x2044 || ch == 0x00a0)
524 return Script_Punctuation;
526 GetStringTypeW(CT_CTYPE1, &ch, 1, &type);
528 if (type == 0)
529 return SCRIPT_UNDEFINED;
531 if (type & C1_CNTRL)
532 return Script_Control;
534 i = 0;
537 if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
538 break;
540 if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
542 if (scriptRanges[i].numericScript && type & C1_DIGIT)
543 return scriptRanges[i].numericScript;
544 if (scriptRanges[i].punctScript && type & C1_PUNCT)
545 return scriptRanges[i].punctScript;
546 return scriptRanges[i].script;
548 i++;
549 } while (1);
551 return SCRIPT_UNDEFINED;
554 /***********************************************************************
555 * DllMain
558 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
560 switch(fdwReason)
562 case DLL_PROCESS_ATTACH:
563 DisableThreadLibraryCalls(hInstDLL);
564 break;
565 case DLL_PROCESS_DETACH:
566 break;
568 return TRUE;
571 /***********************************************************************
572 * ScriptFreeCache (USP10.@)
574 * Free a script cache.
576 * PARAMS
577 * psc [I/O] Script cache.
579 * RETURNS
580 * Success: S_OK
581 * Failure: Non-zero HRESULT value.
583 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
585 TRACE("%p\n", psc);
587 if (psc && *psc)
589 unsigned int i;
590 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
592 heap_free(((ScriptCache *)*psc)->glyphs[i]);
593 heap_free(((ScriptCache *)*psc)->widths[i]);
595 heap_free(((ScriptCache *)*psc)->GSUB_Table);
596 heap_free(((ScriptCache *)*psc)->GDEF_Table);
597 heap_free(((ScriptCache *)*psc)->features);
598 heap_free(*psc);
599 *psc = NULL;
601 return S_OK;
604 /***********************************************************************
605 * ScriptGetProperties (USP10.@)
607 * Retrieve a list of script properties.
609 * PARAMS
610 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
611 * num [I] Pointer to the number of scripts.
613 * RETURNS
614 * Success: S_OK
615 * Failure: Non-zero HRESULT value.
617 * NOTES
618 * Behaviour matches WinXP.
620 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
622 TRACE("(%p,%p)\n", props, num);
624 if (!props && !num) return E_INVALIDARG;
626 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
627 if (props) *props = script_props;
629 return S_OK;
632 /***********************************************************************
633 * ScriptGetFontProperties (USP10.@)
635 * Get information on special glyphs.
637 * PARAMS
638 * hdc [I] Device context.
639 * psc [I/O] Opaque pointer to a script cache.
640 * sfp [O] Font properties structure.
642 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
644 HRESULT hr;
646 TRACE("%p,%p,%p\n", hdc, psc, sfp);
648 if (!sfp) return E_INVALIDARG;
649 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
651 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
652 return E_INVALIDARG;
654 /* return something sensible? */
655 sfp->wgBlank = 0;
656 sfp->wgDefault = get_cache_default_char(psc);
657 sfp->wgInvalid = 0;
658 sfp->wgKashida = 0xffff;
659 sfp->iKashidaWidth = 0;
661 return S_OK;
664 /***********************************************************************
665 * ScriptRecordDigitSubstitution (USP10.@)
667 * Record digit substitution settings for a given locale.
669 * PARAMS
670 * locale [I] Locale identifier.
671 * sds [I] Structure to record substitution settings.
673 * RETURNS
674 * Success: S_OK
675 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
677 * SEE ALSO
678 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
680 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
682 DWORD plgid, sub;
684 TRACE("0x%x, %p\n", locale, sds);
686 /* This implementation appears to be correct for all languages, but it's
687 * not clear if sds->DigitSubstitute is ever set to anything except
688 * CONTEXT or NONE in reality */
690 if (!sds) return E_POINTER;
692 locale = ConvertDefaultLocale(locale);
694 if (!IsValidLocale(locale, LCID_INSTALLED))
695 return E_INVALIDARG;
697 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
698 sds->TraditionalDigitLanguage = plgid;
700 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
701 sds->NationalDigitLanguage = plgid;
702 else
703 sds->NationalDigitLanguage = LANG_ENGLISH;
705 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
706 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
708 switch (sub)
710 case 0:
711 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
712 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
713 else
714 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
715 break;
716 case 1:
717 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
718 break;
719 case 2:
720 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
721 break;
722 default:
723 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
724 break;
727 sds->dwReserved = 0;
728 return S_OK;
731 /***********************************************************************
732 * ScriptApplyDigitSubstitution (USP10.@)
734 * Apply digit substitution settings.
736 * PARAMS
737 * sds [I] Structure with recorded substitution settings.
738 * sc [I] Script control structure.
739 * ss [I] Script state structure.
741 * RETURNS
742 * Success: S_OK
743 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
745 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
746 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
748 SCRIPT_DIGITSUBSTITUTE psds;
750 TRACE("%p, %p, %p\n", sds, sc, ss);
752 if (!sc || !ss) return E_POINTER;
753 if (!sds)
755 sds = &psds;
756 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
757 return E_INVALIDARG;
760 sc->uDefaultLanguage = LANG_ENGLISH;
761 sc->fContextDigits = 0;
762 ss->fDigitSubstitute = 0;
764 switch (sds->DigitSubstitute) {
765 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
766 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
767 case SCRIPT_DIGITSUBSTITUTE_NONE:
768 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
769 return S_OK;
770 default:
771 return E_INVALIDARG;
775 /***********************************************************************
776 * ScriptItemizeOpenType (USP10.@)
778 * Split a Unicode string into shapeable parts.
780 * PARAMS
781 * pwcInChars [I] String to split.
782 * cInChars [I] Number of characters in pwcInChars.
783 * cMaxItems [I] Maximum number of items to return.
784 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
785 * psState [I] Pointer to a SCRIPT_STATE structure.
786 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
787 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
788 * pcItems [O] Number of script items returned.
790 * RETURNS
791 * Success: S_OK
792 * Failure: Non-zero HRESULT value.
794 HRESULT WINAPI ScriptItemizeOpenType(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
795 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
796 SCRIPT_ITEM *pItems, OPENTYPE_TAG *pScriptTags, int *pcItems)
799 #define Numeric_space 0x0020
800 #define ZWNJ 0x200C
801 #define ZWJ 0x200D
803 int cnt = 0, index = 0, str = 0;
804 int New_Script = -1;
805 WORD *levels = NULL;
806 WORD *strength = NULL;
807 WORD baselevel = 0;
808 BOOL new_run;
810 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
811 psControl, psState, pItems, pcItems);
813 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
814 return E_INVALIDARG;
816 if (psState && psControl)
818 int i;
819 levels = heap_alloc_zero(cInChars * sizeof(WORD));
820 if (!levels)
821 return E_OUTOFMEMORY;
823 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
824 baselevel = levels[0];
825 for (i = 0; i < cInChars; i++)
826 if (levels[i]!=levels[0])
827 break;
828 if (i >= cInChars && !odd(baselevel))
830 heap_free(levels);
831 levels = NULL;
833 else
835 BOOL inNumber = FALSE;
836 static WCHAR math_punc[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
838 strength = heap_alloc_zero(cInChars * sizeof(WORD));
839 if (!strength)
841 heap_free(levels);
842 return E_OUTOFMEMORY;
844 BIDI_GetStrengths(pwcInChars, cInChars, psControl, strength);
846 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
847 for (i = 0; i < cInChars; i++)
849 if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && inNumber && strchrW(math_punc,pwcInChars[i]))
850 levels[i] = 2;
851 else if ((levels[i] == 0 || (odd(psState->uBidiLevel) && levels[i] == psState->uBidiLevel+1)) && get_char_script(pwcInChars[i]) == Script_Numeric)
853 levels[i] = 2;
854 inNumber = TRUE;
856 else
857 inNumber = FALSE;
859 if (psControl->fMergeNeutralItems)
861 HeapFree(GetProcessHeap(),0,strength);
862 strength = NULL;
867 while ((!levels || (levels && levels[cnt+1] == levels[0])) && (pwcInChars[cnt] == Numeric_space || pwcInChars[cnt] == ZWJ || pwcInChars[cnt] == ZWNJ) && cnt < cInChars)
868 cnt++;
870 if (cnt == cInChars) /* All Spaces */
872 cnt = 0;
873 New_Script = get_char_script(pwcInChars[cnt]);
876 pItems[index].iCharPos = 0;
877 pItems[index].a = scriptInformation[get_char_script(pwcInChars[cnt])].a;
878 pScriptTags[index] = scriptInformation[get_char_script(pwcInChars[cnt])].scriptTag;
880 if (strength && strength[cnt] == BIDI_STRONG)
881 str = strength[cnt];
882 else if (strength)
883 str = strength[0];
885 cnt = 0;
887 if (levels)
889 pItems[index].a.fRTL = odd(levels[cnt]);
890 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
891 pItems[index].a.s.uBidiLevel = levels[cnt];
893 else if (!pItems[index].a.s.uBidiLevel)
895 pItems[index].a.s.uBidiLevel = baselevel;
896 pItems[index].a.fLayoutRTL = odd(baselevel);
897 pItems[index].a.fRTL = odd(baselevel);
900 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
901 levels?levels[cnt]:-1, str, New_Script, pItems[index].a.eScript, index, cnt,
902 pItems[index].iCharPos);
904 for (cnt=1; cnt < cInChars; cnt++)
906 if(pwcInChars[cnt] != Numeric_space && pwcInChars[cnt] != ZWJ && pwcInChars[cnt] != ZWNJ)
907 New_Script = get_char_script(pwcInChars[cnt]);
908 else if (levels)
910 int j = 1;
911 while (cnt + j < cInChars - 1 && (pwcInChars[cnt+j] == Numeric_space || pwcInChars[cnt+j] == ZWJ || pwcInChars[cnt+j] == ZWNJ) && levels[cnt] == levels[cnt+j])
912 j++;
913 if (cnt + j < cInChars && levels[cnt] == levels[cnt+j])
914 New_Script = get_char_script(pwcInChars[cnt+j]);
915 else
916 New_Script = get_char_script(pwcInChars[cnt]);
919 new_run = FALSE;
920 /* merge space strengths*/
921 if (strength && strength[cnt] == BIDI_STRONG && str != BIDI_STRONG && New_Script == pItems[index].a.eScript)
922 str = BIDI_STRONG;
924 if (strength && strength[cnt] == BIDI_NEUTRAL && str == BIDI_STRONG && pwcInChars[cnt] != Numeric_space && New_Script == pItems[index].a.eScript)
925 str = BIDI_NEUTRAL;
927 /* changes in level */
928 if (levels && (levels[cnt] != pItems[index].a.s.uBidiLevel))
930 TRACE("Level break(%i/%i)\n",pItems[index].a.s.uBidiLevel,levels[cnt]);
931 new_run = TRUE;
933 /* changes in strength */
934 else if (strength && pwcInChars[cnt] != Numeric_space && str != strength[cnt])
936 TRACE("Strength break (%i/%i)\n",str,strength[cnt]);
937 new_run = TRUE;
939 /* changes in script */
940 else if ((!levels) && (((pwcInChars[cnt] != Numeric_space) && (New_Script != -1) && (New_Script != pItems[index].a.eScript)) || (New_Script == Script_Control)))
942 TRACE("Script break(%i/%i)\n",pItems[index].a.eScript,New_Script);
943 new_run = TRUE;
946 if (new_run)
948 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);
950 index++;
951 if (index+1 > cMaxItems)
952 return E_OUTOFMEMORY;
954 if (strength)
955 str = strength[cnt];
957 pItems[index].iCharPos = cnt;
958 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
960 pItems[index].a = scriptInformation[New_Script].a;
961 pScriptTags[index] = scriptInformation[New_Script].scriptTag;
962 if (levels)
964 pItems[index].a.fRTL = odd(levels[cnt]);
965 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
966 pItems[index].a.s.uBidiLevel = levels[cnt];
968 else if (!pItems[index].a.s.uBidiLevel)
970 pItems[index].a.s.uBidiLevel = baselevel;
971 pItems[index].a.fLayoutRTL = odd(baselevel);
972 pItems[index].a.fRTL = odd(baselevel);
975 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
979 /* While not strictly necessary according to the spec, make sure the n+1
980 * item is set up to prevent random behaviour if the caller erroneously
981 * checks the n+1 structure */
982 index++;
983 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
985 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
987 /* Set one SCRIPT_STATE item being returned */
988 if (index + 1 > cMaxItems) return E_OUTOFMEMORY;
989 if (pcItems) *pcItems = index;
991 /* Set SCRIPT_ITEM */
992 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
993 heap_free(levels);
994 heap_free(strength);
995 return S_OK;
998 /***********************************************************************
999 * ScriptItemize (USP10.@)
1001 * Split a Unicode string into shapeable parts.
1003 * PARAMS
1004 * pwcInChars [I] String to split.
1005 * cInChars [I] Number of characters in pwcInChars.
1006 * cMaxItems [I] Maximum number of items to return.
1007 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1008 * psState [I] Pointer to a SCRIPT_STATE structure.
1009 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1010 * pcItems [O] Number of script items returned.
1012 * RETURNS
1013 * Success: S_OK
1014 * Failure: Non-zero HRESULT value.
1016 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
1017 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
1018 SCRIPT_ITEM *pItems, int *pcItems)
1020 OPENTYPE_TAG *discarded_tags;
1021 HRESULT res;
1023 discarded_tags = heap_alloc(cMaxItems * sizeof(OPENTYPE_TAG));
1024 if (!discarded_tags)
1025 return E_OUTOFMEMORY;
1026 res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, discarded_tags, pcItems);
1027 heap_free(discarded_tags);
1028 return res;
1031 static inline int getGivenTabWidth(ScriptCache *psc, SCRIPT_TABDEF *pTabdef, int charPos, int current_x)
1033 int defWidth;
1034 int cTabStops=0;
1035 INT *lpTabPos = NULL;
1036 INT nTabOrg = 0;
1037 INT x = 0;
1039 if (pTabdef)
1040 lpTabPos = pTabdef->pTabStops;
1042 if (pTabdef && pTabdef->iTabOrigin)
1044 if (pTabdef->iScale)
1045 nTabOrg = (pTabdef->iTabOrigin * pTabdef->iScale)/4;
1046 else
1047 nTabOrg = pTabdef->iTabOrigin * psc->tm.tmAveCharWidth;
1050 if (pTabdef)
1051 cTabStops = pTabdef->cTabStops;
1053 if (cTabStops == 1)
1055 if (pTabdef->iScale)
1056 defWidth = ((pTabdef->pTabStops[0])*pTabdef->iScale) / 4;
1057 else
1058 defWidth = (pTabdef->pTabStops[0])*psc->tm.tmAveCharWidth;
1059 cTabStops = 0;
1061 else
1062 defWidth = 8 * psc->tm.tmAveCharWidth;
1064 for (; cTabStops>0 ; lpTabPos++, cTabStops--)
1066 int position = *lpTabPos;
1067 if (position < 0)
1068 position = -1 * position;
1069 if (pTabdef->iScale)
1070 position = (position * pTabdef->iScale) / 4;
1071 else
1072 position = position * psc->tm.tmAveCharWidth;
1074 if( nTabOrg + position > current_x)
1076 if( *lpTabPos >= 0)
1078 /* a left aligned tab */
1079 x = (nTabOrg + *lpTabPos) - current_x;
1080 break;
1082 else
1084 FIXME("Negative tabstop\n");
1085 break;
1089 if ((!cTabStops) && (defWidth > 0))
1090 x =((((current_x - nTabOrg) / defWidth)+1) * defWidth) - current_x;
1091 else if ((!cTabStops) && (defWidth < 0))
1092 FIXME("TODO: Negative defWidth\n");
1094 return x;
1097 /***********************************************************************
1098 * Helper function for ScriptStringAnalyse
1100 static BOOL requires_fallback(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
1101 const WCHAR *pwcInChars, int cChars )
1103 /* FIXME: When to properly fallback is still a bit of a mystery */
1104 WORD *glyphs;
1106 if (psa->fNoGlyphIndex)
1107 return FALSE;
1109 if (init_script_cache(hdc, psc) != S_OK)
1110 return FALSE;
1112 if (SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa) != S_OK)
1113 return TRUE;
1115 glyphs = heap_alloc(sizeof(WORD) * cChars);
1116 if (!glyphs)
1117 return FALSE;
1118 if (ScriptGetCMap(hdc, psc, pwcInChars, cChars, 0, glyphs) != S_OK)
1120 heap_free(glyphs);
1121 return TRUE;
1123 heap_free(glyphs);
1125 return FALSE;
1128 static void find_fallback_font(DWORD scriptid, LPWSTR FaceName)
1130 HKEY hkey;
1132 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Uniscribe\\Fallback", &hkey))
1134 static const WCHAR szFmt[] = {'%','x',0};
1135 WCHAR value[10];
1136 DWORD count = LF_FACESIZE * sizeof(WCHAR);
1137 DWORD type;
1139 sprintfW(value, szFmt, scriptInformation[scriptid].scriptTag);
1140 if (RegQueryValueExW(hkey, value, 0, &type, (LPBYTE)FaceName, &count))
1141 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1142 RegCloseKey(hkey);
1144 else
1145 lstrcpyW(FaceName,scriptInformation[scriptid].fallbackFont);
1148 /***********************************************************************
1149 * ScriptStringAnalyse (USP10.@)
1152 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
1153 int cGlyphs, int iCharset, DWORD dwFlags,
1154 int iReqWidth, SCRIPT_CONTROL *psControl,
1155 SCRIPT_STATE *psState, const int *piDx,
1156 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
1157 SCRIPT_STRING_ANALYSIS *pssa)
1159 HRESULT hr = E_OUTOFMEMORY;
1160 StringAnalysis *analysis = NULL;
1161 SCRIPT_CONTROL sControl;
1162 SCRIPT_STATE sState;
1163 int i, num_items = 255;
1164 BYTE *BidiLevel;
1165 WCHAR *iString = NULL;
1167 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1168 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
1169 psControl, psState, piDx, pTabdef, pbInClass, pssa);
1171 if (iCharset != -1)
1173 FIXME("Only Unicode strings are supported\n");
1174 return E_INVALIDARG;
1176 if (cString < 1 || !pString) return E_INVALIDARG;
1177 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
1179 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
1180 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
1182 /* FIXME: handle clipping */
1183 analysis->clip_len = cString;
1184 analysis->hdc = hdc;
1185 analysis->dwFlags = dwFlags;
1187 if (psState)
1188 sState = *psState;
1189 else
1190 memset(&sState, 0, sizeof(SCRIPT_STATE));
1192 if (psControl)
1193 sControl = *psControl;
1194 else
1195 memset(&sControl, 0, sizeof(SCRIPT_CONTROL));
1197 if (dwFlags & SSA_PASSWORD)
1199 iString = heap_alloc(sizeof(WCHAR)*cString);
1200 if (!iString)
1202 hr = E_OUTOFMEMORY;
1203 goto error;
1205 for (i = 0; i < cString; i++)
1206 iString[i] = *((const WCHAR *)pString);
1207 pString = iString;
1210 hr = ScriptItemize(pString, cString, num_items, &sControl, &sState, analysis->pItem,
1211 &analysis->numItems);
1213 while (hr == E_OUTOFMEMORY)
1215 SCRIPT_ITEM *tmp;
1217 num_items *= 2;
1218 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
1219 goto error;
1221 analysis->pItem = tmp;
1222 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
1223 &analysis->numItems);
1225 if (hr != S_OK) goto error;
1227 /* set back to out of memory for default goto error behaviour */
1228 hr = E_OUTOFMEMORY;
1230 if (dwFlags & SSA_BREAK)
1232 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
1234 for (i = 0; i < analysis->numItems; i++)
1235 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]);
1237 else
1238 goto error;
1241 if (!(analysis->logical2visual = heap_alloc_zero(sizeof(int) * analysis->numItems)))
1242 goto error;
1243 if (!(BidiLevel = heap_alloc_zero(analysis->numItems)))
1244 goto error;
1246 if (dwFlags & SSA_GLYPHS)
1248 int tab_x = 0;
1249 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
1250 goto error;
1252 for (i = 0; i < analysis->numItems; i++)
1254 SCRIPT_CACHE *sc = (SCRIPT_CACHE*)&analysis->glyphs[i].sc;
1255 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1256 int numGlyphs = 1.5 * cChar + 16;
1257 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
1258 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
1259 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
1260 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * numGlyphs);
1261 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
1262 ABC *abc = heap_alloc_zero(sizeof(ABC));
1263 int numGlyphsReturned;
1264 HFONT originalFont = 0x0;
1266 /* FIXME: non unicode strings */
1267 const WCHAR* pStr = (const WCHAR*)pString;
1268 analysis->glyphs[i].fallbackFont = NULL;
1270 if (!glyphs || !pwLogClust || !piAdvance || !psva || !pGoffset || !abc)
1272 heap_free (glyphs);
1273 heap_free (pwLogClust);
1274 heap_free (piAdvance);
1275 heap_free (psva);
1276 heap_free (pGoffset);
1277 heap_free (abc);
1278 hr = E_OUTOFMEMORY;
1279 goto error;
1282 if ((dwFlags & SSA_FALLBACK) && requires_fallback(hdc, sc, &analysis->pItem[i].a, &pStr[analysis->pItem[i].iCharPos], cChar))
1284 LOGFONTW lf;
1285 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), & lf);
1286 lf.lfCharSet = scriptInformation[analysis->pItem[i].a.eScript].props.bCharSet;
1287 find_fallback_font(analysis->pItem[i].a.eScript, lf.lfFaceName);
1288 analysis->glyphs[i].fallbackFont = CreateFontIndirectW(&lf);
1289 if (analysis->glyphs[i].fallbackFont)
1291 ScriptFreeCache(sc);
1292 originalFont = SelectObject(hdc, analysis->glyphs[i].fallbackFont);
1296 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
1297 cChar, numGlyphs, &analysis->pItem[i].a,
1298 glyphs, pwLogClust, psva, &numGlyphsReturned);
1299 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
1300 piAdvance, pGoffset, abc);
1301 if (originalFont)
1302 SelectObject(hdc,originalFont);
1304 if (dwFlags & SSA_TAB)
1306 int tabi = 0;
1307 for (tabi = 0; tabi < cChar; tabi++)
1309 if (pStr[analysis->pItem[i].iCharPos+tabi] == 0x0009)
1310 piAdvance[tabi] = getGivenTabWidth(analysis->glyphs[i].sc, pTabdef, analysis->pItem[i].iCharPos+tabi, tab_x);
1311 tab_x+=piAdvance[tabi];
1315 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
1316 analysis->glyphs[i].glyphs = glyphs;
1317 analysis->glyphs[i].pwLogClust = pwLogClust;
1318 analysis->glyphs[i].piAdvance = piAdvance;
1319 analysis->glyphs[i].psva = psva;
1320 analysis->glyphs[i].pGoffset = pGoffset;
1321 analysis->glyphs[i].abc = abc;
1322 analysis->glyphs[i].iMaxPosX= -1;
1324 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1327 else
1329 for (i = 0; i < analysis->numItems; i++)
1330 BidiLevel[i] = analysis->pItem[i].a.s.uBidiLevel;
1333 ScriptLayout(analysis->numItems, BidiLevel, NULL, analysis->logical2visual);
1334 heap_free(BidiLevel);
1336 *pssa = analysis;
1337 heap_free(iString);
1338 return S_OK;
1340 error:
1341 heap_free(iString);
1342 heap_free(analysis->glyphs);
1343 heap_free(analysis->logattrs);
1344 heap_free(analysis->pItem);
1345 heap_free(analysis->logical2visual);
1346 heap_free(analysis);
1347 return hr;
1350 static inline BOOL does_glyph_start_cluster(const SCRIPT_VISATTR *pva, const WORD *pwLogClust, int cChars, int glyph, int direction)
1352 int i;
1354 if (pva[glyph].fClusterStart)
1355 return TRUE;
1356 for (i = 0; i < cChars; i++)
1357 if (pwLogClust[i] == glyph) break;
1358 if (i != cChars)
1359 return TRUE;
1361 return FALSE;
1365 static HRESULT SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa,
1366 int iX,
1367 int iY,
1368 int iItem,
1369 int cStart,
1370 int cEnd,
1371 UINT uOptions,
1372 const RECT *prc,
1373 BOOL fSelected,
1374 BOOL fDisabled)
1376 StringAnalysis *analysis;
1377 int off_x = 0;
1378 HRESULT hr;
1379 COLORREF BkColor = 0x0;
1380 COLORREF TextColor = 0x0;
1381 INT BkMode = 0;
1382 INT runStart, runEnd;
1383 INT iGlyph, cGlyphs;
1384 HFONT oldFont = 0x0;
1386 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1387 ssa, iX, iY, iItem, cStart, cEnd, uOptions, fSelected, fDisabled);
1389 if (!(analysis = ssa)) return E_INVALIDARG;
1391 if ((cStart >= 0 && analysis->pItem[iItem+1].iCharPos <= cStart) ||
1392 (cEnd >= 0 && analysis->pItem[iItem].iCharPos >= cEnd))
1393 return S_OK;
1395 if (fSelected)
1397 BkMode = GetBkMode(analysis->hdc);
1398 SetBkMode( analysis->hdc, OPAQUE);
1399 BkColor = GetBkColor(analysis->hdc);
1400 SetBkColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHT));
1401 if (!fDisabled)
1403 TextColor = GetTextColor(analysis->hdc);
1404 SetTextColor(analysis->hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1407 if (analysis->glyphs[iItem].fallbackFont)
1408 oldFont = SelectObject(analysis->hdc, analysis->glyphs[iItem].fallbackFont);
1410 if (cStart >= 0 && analysis->pItem[iItem+1].iCharPos > cStart && analysis->pItem[iItem].iCharPos <= cStart)
1411 runStart = cStart - analysis->pItem[iItem].iCharPos;
1412 else
1413 runStart = 0;
1414 if (cEnd >= 0 && analysis->pItem[iItem+1].iCharPos > cEnd && analysis->pItem[iItem].iCharPos <= cEnd)
1415 runEnd = (cEnd-1) - analysis->pItem[iItem].iCharPos;
1416 else
1417 runEnd = (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos) - 1;
1419 if (analysis->pItem[iItem].a.fRTL)
1421 if (cEnd >= 0 && cEnd < analysis->pItem[iItem+1].iCharPos)
1422 ScriptStringCPtoX(ssa, cEnd, FALSE, &off_x);
1423 else
1424 ScriptStringCPtoX(ssa, analysis->pItem[iItem+1].iCharPos-1, TRUE, &off_x);
1426 else
1428 if (cStart >=0 && runStart)
1429 ScriptStringCPtoX(ssa, cStart, FALSE, &off_x);
1430 else
1431 ScriptStringCPtoX(ssa, analysis->pItem[iItem].iCharPos, FALSE, &off_x);
1434 if (analysis->pItem[iItem].a.fRTL)
1435 iGlyph = analysis->glyphs[iItem].pwLogClust[runEnd];
1436 else
1437 iGlyph = analysis->glyphs[iItem].pwLogClust[runStart];
1439 if (analysis->pItem[iItem].a.fRTL)
1440 cGlyphs = analysis->glyphs[iItem].pwLogClust[runStart] - iGlyph;
1441 else
1442 cGlyphs = analysis->glyphs[iItem].pwLogClust[runEnd] - iGlyph;
1444 cGlyphs++;
1446 if (cEnd < 0 || scriptInformation[analysis->pItem[iItem].a.eScript].props.fNeedsCaretInfo)
1448 INT direction;
1449 INT clust_glyph;
1451 clust_glyph = iGlyph + cGlyphs;
1452 if (analysis->pItem[iItem].a.fRTL)
1453 direction = -1;
1454 else
1455 direction = 1;
1457 while(clust_glyph < analysis->glyphs[iItem].numGlyphs &&
1458 !does_glyph_start_cluster(analysis->glyphs[iItem].psva, analysis->glyphs[iItem].pwLogClust, (analysis->pItem[iItem+1].iCharPos - analysis->pItem[iItem].iCharPos), clust_glyph, direction))
1460 cGlyphs++;
1461 clust_glyph++;
1465 hr = ScriptTextOut(analysis->hdc,
1466 (SCRIPT_CACHE *)&analysis->glyphs[iItem].sc, iX + off_x,
1467 iY, uOptions, prc, &analysis->pItem[iItem].a, NULL, 0,
1468 &analysis->glyphs[iItem].glyphs[iGlyph], cGlyphs,
1469 &analysis->glyphs[iItem].piAdvance[iGlyph], NULL,
1470 &analysis->glyphs[iItem].pGoffset[iGlyph]);
1472 TRACE("ScriptTextOut hr=%08x\n", hr);
1474 if (fSelected)
1476 SetBkColor(analysis->hdc, BkColor);
1477 SetBkMode( analysis->hdc, BkMode);
1478 if (!fDisabled)
1479 SetTextColor(analysis->hdc, TextColor);
1481 if (analysis->glyphs[iItem].fallbackFont)
1482 SelectObject(analysis->hdc, oldFont);
1484 return hr;
1487 /***********************************************************************
1488 * ScriptStringOut (USP10.@)
1490 * This function takes the output of ScriptStringAnalyse and joins the segments
1491 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1492 * only processes glyphs.
1494 * Parameters:
1495 * ssa [I] buffer to hold the analysed string components
1496 * iX [I] X axis displacement for output
1497 * iY [I] Y axis displacement for output
1498 * uOptions [I] flags controling output processing
1499 * prc [I] rectangle coordinates
1500 * iMinSel [I] starting pos for substringing output string
1501 * iMaxSel [I] ending pos for substringing output string
1502 * fDisabled [I] controls text highlighting
1504 * RETURNS
1505 * Success: S_OK
1506 * Failure: is the value returned by ScriptTextOut
1508 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
1509 int iX,
1510 int iY,
1511 UINT uOptions,
1512 const RECT *prc,
1513 int iMinSel,
1514 int iMaxSel,
1515 BOOL fDisabled)
1517 StringAnalysis *analysis;
1518 int item;
1519 HRESULT hr;
1521 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1522 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
1524 if (!(analysis = ssa)) return E_INVALIDARG;
1525 if (!(analysis->dwFlags & SSA_GLYPHS)) return E_INVALIDARG;
1527 for (item = 0; item < analysis->numItems; item++)
1529 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], -1, -1, uOptions, prc, FALSE, fDisabled);
1530 if (FAILED(hr))
1531 return hr;
1534 if (iMinSel < iMaxSel && (iMinSel > 0 || iMaxSel > 0))
1536 if (iMaxSel > 0 && iMinSel < 0)
1537 iMinSel = 0;
1538 for (item = 0; item < analysis->numItems; item++)
1540 hr = SS_ItemOut( ssa, iX, iY, analysis->logical2visual[item], iMinSel, iMaxSel, uOptions, prc, TRUE, fDisabled);
1541 if (FAILED(hr))
1542 return hr;
1546 return S_OK;
1549 /***********************************************************************
1550 * ScriptStringCPtoX (USP10.@)
1553 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
1555 int item;
1556 int runningX = 0;
1557 StringAnalysis* analysis = ssa;
1559 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
1561 if (!ssa || !pX) return S_FALSE;
1562 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
1564 /* icp out of range */
1565 if(icp < 0)
1567 analysis->invalid = TRUE;
1568 return E_INVALIDARG;
1571 for(item=0; item<analysis->numItems; item++)
1573 int CP, i;
1574 int offset;
1576 i = analysis->logical2visual[item];
1577 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1578 /* initialize max extents for uninitialized runs */
1579 if (analysis->glyphs[i].iMaxPosX == -1)
1581 if (analysis->pItem[i].a.fRTL)
1582 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1583 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1584 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1585 else
1586 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1587 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1588 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1591 if (icp >= analysis->pItem[i+1].iCharPos || icp < analysis->pItem[i].iCharPos)
1593 runningX += analysis->glyphs[i].iMaxPosX;
1594 continue;
1597 icp -= analysis->pItem[i].iCharPos;
1598 ScriptCPtoX(icp, fTrailing, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1599 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1600 &analysis->pItem[i].a, &offset);
1601 runningX += offset;
1603 *pX = runningX;
1604 return S_OK;
1607 /* icp out of range */
1608 analysis->invalid = TRUE;
1609 return E_INVALIDARG;
1612 /***********************************************************************
1613 * ScriptStringXtoCP (USP10.@)
1616 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
1618 StringAnalysis* analysis = ssa;
1619 int item;
1621 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
1623 if (!ssa || !piCh || !piTrailing) return S_FALSE;
1624 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
1626 /* out of range */
1627 if(iX < 0)
1629 if (analysis->pItem[0].a.fRTL)
1631 *piCh = 1;
1632 *piTrailing = FALSE;
1634 else
1636 *piCh = -1;
1637 *piTrailing = TRUE;
1639 return S_OK;
1642 for(item=0; item<analysis->numItems; item++)
1644 int i;
1645 int CP;
1647 for (i = 0; i < analysis->numItems && analysis->logical2visual[i] != item; i++)
1648 /* nothing */;
1650 CP = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
1651 /* initialize max extents for uninitialized runs */
1652 if (analysis->glyphs[i].iMaxPosX == -1)
1654 if (analysis->pItem[i].a.fRTL)
1655 ScriptCPtoX(0, FALSE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1656 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1657 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1658 else
1659 ScriptCPtoX(CP, TRUE, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1660 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1661 &analysis->pItem[i].a, &analysis->glyphs[i].iMaxPosX);
1664 if (iX > analysis->glyphs[i].iMaxPosX)
1666 iX -= analysis->glyphs[i].iMaxPosX;
1667 continue;
1670 ScriptXtoCP(iX, CP, analysis->glyphs[i].numGlyphs, analysis->glyphs[i].pwLogClust,
1671 analysis->glyphs[i].psva, analysis->glyphs[i].piAdvance,
1672 &analysis->pItem[i].a, piCh, piTrailing);
1673 *piCh += analysis->pItem[i].iCharPos;
1675 return S_OK;
1678 /* out of range */
1679 *piCh = analysis->pItem[analysis->numItems].iCharPos;
1680 *piTrailing = FALSE;
1682 return S_OK;
1686 /***********************************************************************
1687 * ScriptStringFree (USP10.@)
1689 * Free a string analysis.
1691 * PARAMS
1692 * pssa [I] string analysis.
1694 * RETURNS
1695 * Success: S_OK
1696 * Failure: Non-zero HRESULT value.
1698 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
1700 StringAnalysis* analysis;
1701 BOOL invalid;
1702 int i;
1704 TRACE("(%p)\n", pssa);
1706 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
1708 invalid = analysis->invalid;
1710 if (analysis->glyphs)
1712 for (i = 0; i < analysis->numItems; i++)
1714 heap_free(analysis->glyphs[i].glyphs);
1715 heap_free(analysis->glyphs[i].pwLogClust);
1716 heap_free(analysis->glyphs[i].piAdvance);
1717 heap_free(analysis->glyphs[i].psva);
1718 heap_free(analysis->glyphs[i].pGoffset);
1719 heap_free(analysis->glyphs[i].abc);
1720 if (analysis->glyphs[i].fallbackFont)
1721 DeleteObject(analysis->glyphs[i].fallbackFont);
1722 ScriptFreeCache((SCRIPT_CACHE *)&analysis->glyphs[i].sc);
1723 heap_free(analysis->glyphs[i].sc);
1725 heap_free(analysis->glyphs);
1728 heap_free(analysis->pItem);
1729 heap_free(analysis->logattrs);
1730 heap_free(analysis->sz);
1731 heap_free(analysis->logical2visual);
1732 heap_free(analysis);
1734 if (invalid) return E_INVALIDARG;
1735 return S_OK;
1738 static inline int get_cluster_size(const WORD *pwLogClust, int cChars, int item,
1739 int direction, int* iCluster, int *check_out)
1741 int clust_size = 1;
1742 int check;
1743 WORD clust = pwLogClust[item];
1745 for (check = item+direction; check < cChars && check >= 0; check+=direction)
1747 if (pwLogClust[check] == clust)
1749 clust_size ++;
1750 if (iCluster && *iCluster == -1)
1751 *iCluster = item;
1753 else break;
1756 if (check_out)
1757 *check_out = check;
1759 return clust_size;
1762 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)
1764 int advance;
1765 int log_clust_max = 0;
1766 int i;
1768 advance = piAdvance[glyph];
1770 for (i = 0; i < cChars; i++)
1772 if (pwLogClust[i] > log_clust_max)
1773 log_clust_max = pwLogClust[i];
1776 if (glyph > log_clust_max)
1777 return advance;
1779 for (glyph+=direction; glyph < cGlyphs && glyph >= 0; glyph +=direction)
1782 if (does_glyph_start_cluster(pva, pwLogClust, cChars, glyph, direction))
1783 break;
1784 if (glyph > log_clust_max)
1785 break;
1786 advance += piAdvance[glyph];
1789 return advance;
1792 /***********************************************************************
1793 * ScriptCPtoX (USP10.@)
1796 HRESULT WINAPI ScriptCPtoX(int iCP,
1797 BOOL fTrailing,
1798 int cChars,
1799 int cGlyphs,
1800 const WORD *pwLogClust,
1801 const SCRIPT_VISATTR *psva,
1802 const int *piAdvance,
1803 const SCRIPT_ANALYSIS *psa,
1804 int *piX)
1806 int item;
1807 float iPosX;
1808 int iSpecial = -1;
1809 int iCluster = -1;
1810 int clust_size = 1;
1811 float special_size = 0.0;
1812 int iMaxPos = 0;
1813 int advance = 0;
1814 BOOL rtl = FALSE;
1816 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1817 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1818 psa, piX);
1820 if (psa->fRTL && ! psa->fLogicalOrder)
1821 rtl = TRUE;
1823 if (fTrailing)
1824 iCP++;
1826 if (rtl)
1828 int max_clust = pwLogClust[0];
1830 for (item=0; item < cGlyphs; item++)
1831 if (pwLogClust[item] > max_clust)
1833 ERR("We do not handle non reversed clusters properly\n");
1834 break;
1837 iMaxPos = 0;
1838 for (item = max_clust; item >=0; item --)
1839 iMaxPos += piAdvance[item];
1842 iPosX = 0.0;
1843 for (item=0; item < iCP && item < cChars; item++)
1845 if (iSpecial == -1 && (iCluster == -1 || (iCluster != -1 && iCluster+clust_size <= item)))
1847 int check;
1848 int clust = pwLogClust[item];
1850 iCluster = -1;
1851 clust_size = get_cluster_size(pwLogClust, cChars, item, 1, &iCluster,
1852 &check);
1854 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, 1);
1856 if (check >= cChars && !iMaxPos)
1858 for (check = clust; check < cChars; check++)
1859 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, 1);
1860 iSpecial = item;
1861 special_size /= (cChars - item);
1862 iPosX += special_size;
1864 else
1866 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
1868 clust_size --;
1869 if (clust_size == 0)
1870 iPosX += advance;
1872 else
1873 iPosX += advance / (float)clust_size;
1876 else if (iSpecial != -1)
1877 iPosX += special_size;
1878 else /* (iCluster != -1) */
1880 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], 1);
1881 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
1883 clust_size --;
1884 if (clust_size == 0)
1885 iPosX += adv;
1887 else
1888 iPosX += adv / (float)clust_size;
1892 if (iMaxPos > 0)
1894 iPosX = iMaxPos - iPosX;
1895 if (iPosX < 0)
1896 iPosX = 0;
1899 *piX = iPosX;
1900 TRACE("*piX=%d\n", *piX);
1901 return S_OK;
1904 /***********************************************************************
1905 * ScriptXtoCP (USP10.@)
1908 HRESULT WINAPI ScriptXtoCP(int iX,
1909 int cChars,
1910 int cGlyphs,
1911 const WORD *pwLogClust,
1912 const SCRIPT_VISATTR *psva,
1913 const int *piAdvance,
1914 const SCRIPT_ANALYSIS *psa,
1915 int *piCP,
1916 int *piTrailing)
1918 int item;
1919 float iPosX;
1920 float iLastPosX;
1921 int iSpecial = -1;
1922 int iCluster = -1;
1923 int clust_size = 1;
1924 int cjump = 0;
1925 int advance;
1926 float special_size = 0.0;
1927 int direction = 1;
1929 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1930 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1931 psa, piCP, piTrailing);
1933 if (psa->fRTL && ! psa->fLogicalOrder)
1934 direction = -1;
1936 if (direction<0)
1938 int max_clust = pwLogClust[0];
1940 if (iX < 0)
1942 *piCP = cChars;
1943 *piTrailing = 0;
1944 return S_OK;
1947 for (item=0; item < cChars; item++)
1948 if (pwLogClust[item] > max_clust)
1950 ERR("We do not handle non reversed clusters properly\n");
1951 break;
1955 if (iX < 0)
1957 *piCP = -1;
1958 *piTrailing = 1;
1959 return S_OK;
1962 iPosX = iLastPosX = 0;
1963 if (direction > 0)
1964 item = 0;
1965 else
1966 item = cChars - 1;
1967 for (; iPosX <= iX && item < cChars && item >= 0; item+=direction)
1969 iLastPosX = iPosX;
1970 if (iSpecial == -1 &&
1971 (iCluster == -1 ||
1972 (iCluster != -1 &&
1973 ((direction > 0 && iCluster+clust_size <= item) ||
1974 (direction < 0 && iCluster-clust_size >= item))
1979 int check;
1980 int clust = pwLogClust[item];
1982 iCluster = -1;
1983 cjump = 0;
1984 clust_size = get_cluster_size(pwLogClust, cChars, item, direction,
1985 &iCluster, &check);
1986 advance = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, clust, direction);
1988 if (check >= cChars && direction > 0)
1990 for (check = clust; check < cChars; check++)
1991 special_size += get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, check, direction);
1992 iSpecial = item;
1993 special_size /= (cChars - item);
1994 iPosX += special_size;
1996 else
1998 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2000 if (!cjump)
2001 iPosX += advance;
2002 cjump++;
2004 else
2005 iPosX += advance / (float)clust_size;
2008 else if (iSpecial != -1)
2009 iPosX += special_size;
2010 else /* (iCluster != -1) */
2012 int adv = get_glyph_cluster_advance(piAdvance, psva, pwLogClust, cGlyphs, cChars, pwLogClust[iCluster], direction);
2013 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo)
2015 if (!cjump)
2016 iPosX += adv;
2017 cjump++;
2019 else
2020 iPosX += adv / (float)clust_size;
2024 if (direction > 0)
2026 if (iPosX > iX)
2027 item--;
2028 if (item < cChars && ((iPosX - iLastPosX) / 2.0) + iX >= iPosX)
2030 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2031 item+=(clust_size-1);
2032 *piTrailing = 1;
2034 else
2035 *piTrailing = 0;
2037 else
2039 if (iX == iLastPosX)
2040 item++;
2041 if (iX >= iLastPosX && iX <= iPosX)
2042 item++;
2044 if (iLastPosX == iX)
2045 *piTrailing = 0;
2046 else if (item < 0 || ((iLastPosX - iPosX) / 2.0) + iX <= iLastPosX)
2048 if (scriptInformation[psa->eScript].props.fNeedsCaretInfo && clust_size > 1)
2049 item-=(clust_size-1);
2050 *piTrailing = 1;
2052 else
2053 *piTrailing = 0;
2056 *piCP = item;
2058 TRACE("*piCP=%d\n", *piCP);
2059 TRACE("*piTrailing=%d\n", *piTrailing);
2060 return S_OK;
2063 /***********************************************************************
2064 * ScriptBreak (USP10.@)
2066 * Retrieve line break information.
2068 * PARAMS
2069 * chars [I] Array of characters.
2070 * sa [I] String analysis.
2071 * la [I] Array of logical attribute structures.
2073 * RETURNS
2074 * Success: S_OK
2075 * Failure: S_FALSE
2077 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
2079 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
2081 if (!la) return S_FALSE;
2083 BREAK_line(chars, count, sa, la);
2085 return S_OK;
2088 /***********************************************************************
2089 * ScriptIsComplex (USP10.@)
2091 * Determine if a string is complex.
2093 * PARAMS
2094 * chars [I] Array of characters to test.
2095 * len [I] Length in characters.
2096 * flag [I] Flag.
2098 * RETURNS
2099 * Success: S_OK
2100 * Failure: S_FALSE
2103 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
2105 int i;
2107 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
2109 for (i = 0; i < len; i++)
2111 int script;
2113 if ((flag & SIC_ASCIIDIGIT) && chars[i] >= 0x30 && chars[i] <= 0x39)
2114 return S_OK;
2116 script = get_char_script(chars[i]);
2117 if ((scriptInformation[script].props.fComplex && (flag & SIC_COMPLEX))||
2118 (!scriptInformation[script].props.fComplex && (flag & SIC_NEUTRAL)))
2119 return S_OK;
2121 return S_FALSE;
2124 /***********************************************************************
2125 * ScriptShapeOpenType (USP10.@)
2127 * Produce glyphs and visual attributes for a run.
2129 * PARAMS
2130 * hdc [I] Device context.
2131 * psc [I/O] Opaque pointer to a script cache.
2132 * psa [I/O] Script analysis.
2133 * tagScript [I] The OpenType tag for the Script
2134 * tagLangSys [I] The OpenType tag for the Language
2135 * rcRangeChars[I] Array of Character counts in each range
2136 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2137 * cRanges [I] Count of ranges
2138 * pwcChars [I] Array of characters specifying the run.
2139 * cChars [I] Number of characters in pwcChars.
2140 * cMaxGlyphs [I] Length of pwOutGlyphs.
2141 * pwLogClust [O] Array of logical cluster info.
2142 * pCharProps [O] Array of character property values
2143 * pwOutGlyphs [O] Array of glyphs.
2144 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2145 * pcGlyphs [O] Number of glyphs returned.
2147 * RETURNS
2148 * Success: S_OK
2149 * Failure: Non-zero HRESULT value.
2151 HRESULT WINAPI ScriptShapeOpenType( HDC hdc, SCRIPT_CACHE *psc,
2152 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
2153 OPENTYPE_TAG tagLangSys, int *rcRangeChars,
2154 TEXTRANGE_PROPERTIES **rpRangeProperties,
2155 int cRanges, const WCHAR *pwcChars, int cChars,
2156 int cMaxGlyphs, WORD *pwLogClust,
2157 SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs,
2158 SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs)
2160 HRESULT hr;
2161 unsigned int i;
2162 BOOL rtl;
2164 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2165 hdc, psc, psa,
2166 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2167 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2168 cChars, cMaxGlyphs, pwLogClust, pCharProps, pwOutGlyphs, pOutGlyphProps, pcGlyphs);
2170 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
2171 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
2173 if (!pOutGlyphProps || !pcGlyphs || !pCharProps) return E_INVALIDARG;
2174 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2176 if (cRanges)
2177 FIXME("Ranges not supported yet\n");
2179 rtl = (psa && !psa->fLogicalOrder && psa->fRTL);
2181 *pcGlyphs = cChars;
2182 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2183 if (!pwLogClust) return E_FAIL;
2185 ((ScriptCache *)*psc)->userScript = tagScript;
2186 ((ScriptCache *)*psc)->userLang = tagLangSys;
2188 /* set fNoGlyphIndex non truetype/opentype fonts */
2189 if (!psa->fNoGlyphIndex && !((ScriptCache *)*psc)->sfnt)
2190 psa->fNoGlyphIndex = TRUE;
2192 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2193 for (i = 0; i < cChars; i++)
2195 int idx = i;
2196 if (rtl) idx = cChars - 1 - i;
2197 /* FIXME: set to better values */
2198 pOutGlyphProps[i].sva.uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
2199 pOutGlyphProps[i].sva.fClusterStart = 1;
2200 pOutGlyphProps[i].sva.fDiacritic = 0;
2201 pOutGlyphProps[i].sva.fZeroWidth = 0;
2202 pOutGlyphProps[i].sva.fReserved = 0;
2203 pOutGlyphProps[i].sva.fShapeReserved = 0;
2205 /* FIXME: have the shaping engine set this */
2206 pCharProps[i].fCanGlyphAlone = 0;
2208 pwLogClust[i] = idx;
2211 if (psa && !psa->fNoGlyphIndex)
2213 WCHAR *rChars;
2214 if ((hr = SHAPE_CheckFontForRequiredFeatures(hdc, (ScriptCache *)*psc, psa)) != S_OK) return hr;
2216 rChars = heap_alloc(sizeof(WCHAR) * cChars);
2217 if (!rChars) return E_OUTOFMEMORY;
2218 for (i = 0; i < cChars; i++)
2220 int idx = i;
2221 WCHAR chInput;
2222 if (rtl) idx = cChars - 1 - i;
2223 if (psa->fRTL)
2224 chInput = mirror_char(pwcChars[idx]);
2225 else
2226 chInput = pwcChars[idx];
2227 /* special case for tabs */
2228 if (chInput == 0x0009)
2229 chInput = 0x0020;
2230 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, chInput)))
2232 WORD glyph;
2233 if (!hdc) return E_PENDING;
2234 if (GetGlyphIndicesW(hdc, &chInput, 1, &glyph, 0) == GDI_ERROR) return S_FALSE;
2235 pwOutGlyphs[i] = set_cache_glyph(psc, chInput, glyph);
2237 rChars[i] = chInput;
2240 SHAPE_ContextualShaping(hdc, (ScriptCache *)*psc, psa, rChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
2241 SHAPE_ApplyDefaultOpentypeFeatures(hdc, (ScriptCache *)*psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, pwLogClust);
2242 SHAPE_CharGlyphProp(hdc, (ScriptCache *)*psc, psa, pwcChars, cChars, pwOutGlyphs, *pcGlyphs, pwLogClust, pCharProps, pOutGlyphProps);
2243 heap_free(rChars);
2245 else
2247 TRACE("no glyph translation\n");
2248 for (i = 0; i < cChars; i++)
2250 int idx = i;
2251 /* No mirroring done here */
2252 if (rtl) idx = cChars - 1 - i;
2253 pwOutGlyphs[i] = pwcChars[idx];
2257 return S_OK;
2261 /***********************************************************************
2262 * ScriptShape (USP10.@)
2264 * Produce glyphs and visual attributes for a run.
2266 * PARAMS
2267 * hdc [I] Device context.
2268 * psc [I/O] Opaque pointer to a script cache.
2269 * pwcChars [I] Array of characters specifying the run.
2270 * cChars [I] Number of characters in pwcChars.
2271 * cMaxGlyphs [I] Length of pwOutGlyphs.
2272 * psa [I/O] Script analysis.
2273 * pwOutGlyphs [O] Array of glyphs.
2274 * pwLogClust [O] Array of logical cluster info.
2275 * psva [O] Array of visual attributes.
2276 * pcGlyphs [O] Number of glyphs returned.
2278 * RETURNS
2279 * Success: S_OK
2280 * Failure: Non-zero HRESULT value.
2282 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
2283 int cChars, int cMaxGlyphs,
2284 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
2285 SCRIPT_VISATTR *psva, int *pcGlyphs)
2287 HRESULT hr;
2288 int i;
2289 SCRIPT_CHARPROP *charProps;
2290 SCRIPT_GLYPHPROP *glyphProps;
2292 if (!psva || !pcGlyphs) return E_INVALIDARG;
2293 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
2295 charProps = heap_alloc_zero(sizeof(SCRIPT_CHARPROP)*cChars);
2296 if (!charProps) return E_OUTOFMEMORY;
2297 glyphProps = heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP)*cMaxGlyphs);
2298 if (!glyphProps) return E_OUTOFMEMORY;
2300 hr = ScriptShapeOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, pwcChars, cChars, cMaxGlyphs, pwLogClust, charProps, pwOutGlyphs, glyphProps, pcGlyphs);
2302 if (SUCCEEDED(hr))
2304 for (i = 0; i < *pcGlyphs; i++)
2305 psva[i] = glyphProps[i].sva;
2308 heap_free(charProps);
2309 heap_free(glyphProps);
2311 return hr;
2314 /***********************************************************************
2315 * ScriptPlaceOpenType (USP10.@)
2317 * Produce advance widths for a run.
2319 * PARAMS
2320 * hdc [I] Device context.
2321 * psc [I/O] Opaque pointer to a script cache.
2322 * psa [I/O] String analysis.
2323 * tagScript [I] The OpenType tag for the Script
2324 * tagLangSys [I] The OpenType tag for the Language
2325 * rcRangeChars[I] Array of Character counts in each range
2326 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2327 * cRanges [I] Count of ranges
2328 * pwcChars [I] Array of characters specifying the run.
2329 * pwLogClust [I] Array of logical cluster info
2330 * pCharProps [I] Array of character property values
2331 * cChars [I] Number of characters in pwcChars.
2332 * pwGlyphs [I] Array of glyphs.
2333 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2334 * cGlyphs [I] Count of Glyphs
2335 * piAdvance [O] Array of advance widths.
2336 * pGoffset [O] Glyph offsets.
2337 * pABC [O] Combined ABC width.
2339 * RETURNS
2340 * Success: S_OK
2341 * Failure: Non-zero HRESULT value.
2344 HRESULT WINAPI ScriptPlaceOpenType( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa,
2345 OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys,
2346 int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties,
2347 int cRanges, const WCHAR *pwcChars, WORD *pwLogClust,
2348 SCRIPT_CHARPROP *pCharProps, int cChars,
2349 const WORD *pwGlyphs, const SCRIPT_GLYPHPROP *pGlyphProps,
2350 int cGlyphs, int *piAdvance,
2351 GOFFSET *pGoffset, ABC *pABC
2354 HRESULT hr;
2355 int i;
2357 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2358 hdc, psc, psa,
2359 debugstr_an((char*)&tagScript,4), debugstr_an((char*)&tagLangSys,4),
2360 rcRangeChars, rpRangeProperties, cRanges, debugstr_wn(pwcChars, cChars),
2361 pwLogClust, pCharProps, cChars, pwGlyphs, pGlyphProps, cGlyphs, piAdvance,
2362 pGoffset, pABC);
2364 if (!pGlyphProps) return E_INVALIDARG;
2365 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2366 if (!pGoffset) return E_FAIL;
2368 if (cRanges)
2369 FIXME("Ranges not supported yet\n");
2371 ((ScriptCache *)*psc)->userScript = tagScript;
2372 ((ScriptCache *)*psc)->userLang = tagLangSys;
2374 if (pABC) memset(pABC, 0, sizeof(ABC));
2375 for (i = 0; i < cGlyphs; i++)
2377 ABC abc;
2378 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
2380 if (!hdc) return E_PENDING;
2381 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
2383 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
2385 else
2387 INT width;
2388 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
2389 abc.abcB = width;
2390 abc.abcA = abc.abcC = 0;
2392 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
2394 if (pABC)
2396 pABC->abcA += abc.abcA;
2397 pABC->abcB += abc.abcB;
2398 pABC->abcC += abc.abcC;
2400 /* FIXME: set to more reasonable values */
2401 pGoffset[i].du = pGoffset[i].dv = 0;
2402 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
2405 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
2406 return S_OK;
2409 /***********************************************************************
2410 * ScriptPlace (USP10.@)
2412 * Produce advance widths for a run.
2414 * PARAMS
2415 * hdc [I] Device context.
2416 * psc [I/O] Opaque pointer to a script cache.
2417 * pwGlyphs [I] Array of glyphs.
2418 * cGlyphs [I] Number of glyphs in pwGlyphs.
2419 * psva [I] Array of visual attributes.
2420 * psa [I/O] String analysis.
2421 * piAdvance [O] Array of advance widths.
2422 * pGoffset [O] Glyph offsets.
2423 * pABC [O] Combined ABC width.
2425 * RETURNS
2426 * Success: S_OK
2427 * Failure: Non-zero HRESULT value.
2429 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
2430 int cGlyphs, const SCRIPT_VISATTR *psva,
2431 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
2433 HRESULT hr;
2434 SCRIPT_GLYPHPROP *glyphProps;
2435 int i;
2437 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
2438 piAdvance, pGoffset, pABC);
2440 if (!psva) return E_INVALIDARG;
2441 if (!pGoffset) return E_FAIL;
2443 glyphProps = heap_alloc(sizeof(SCRIPT_GLYPHPROP)*cGlyphs);
2444 if (!glyphProps) return E_OUTOFMEMORY;
2446 for (i = 0; i < cGlyphs; i++)
2447 glyphProps[i].sva = psva[i];
2449 hr = ScriptPlaceOpenType(hdc, psc, psa, scriptInformation[psa->eScript].scriptTag, 0, NULL, NULL, 0, NULL, NULL, NULL, 0, pwGlyphs, glyphProps, cGlyphs, piAdvance, pGoffset, pABC);
2451 heap_free(glyphProps);
2453 return hr;
2456 /***********************************************************************
2457 * ScriptGetCMap (USP10.@)
2459 * Retrieve glyph indices.
2461 * PARAMS
2462 * hdc [I] Device context.
2463 * psc [I/O] Opaque pointer to a script cache.
2464 * pwcInChars [I] Array of Unicode characters.
2465 * cChars [I] Number of characters in pwcInChars.
2466 * dwFlags [I] Flags.
2467 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2469 * RETURNS
2470 * Success: S_OK
2471 * Failure: Non-zero HRESULT value.
2473 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
2474 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
2476 HRESULT hr;
2477 int i;
2479 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
2480 cChars, dwFlags, pwOutGlyphs);
2482 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2484 hr = S_OK;
2486 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
2488 for (i = 0; i < cChars; i++)
2490 WCHAR inChar;
2491 if (dwFlags == SGCM_RTL)
2492 inChar = mirror_char(pwcInChars[i]);
2493 else
2494 inChar = pwcInChars[i];
2495 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, inChar)))
2497 WORD glyph;
2498 if (!hdc) return E_PENDING;
2499 if (GetGlyphIndicesW(hdc, &inChar, 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
2500 if (glyph == 0xffff)
2502 hr = S_FALSE;
2503 glyph = 0x0;
2505 pwOutGlyphs[i] = set_cache_glyph(psc, inChar, glyph);
2509 else
2511 TRACE("no glyph translation\n");
2512 for (i = 0; i < cChars; i++)
2514 WCHAR inChar;
2515 if (dwFlags == SGCM_RTL)
2516 inChar = mirror_char(pwcInChars[i]);
2517 else
2518 inChar = pwcInChars[i];
2519 pwOutGlyphs[i] = inChar;
2522 return hr;
2525 /***********************************************************************
2526 * ScriptTextOut (USP10.@)
2529 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
2530 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
2531 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
2532 const int *piJustify, const GOFFSET *pGoffset)
2534 HRESULT hr = S_OK;
2536 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2537 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
2538 piAdvance, piJustify, pGoffset);
2540 if (!hdc || !psc) return E_INVALIDARG;
2541 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
2543 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
2544 fuOptions |= ETO_IGNORELANGUAGE;
2545 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
2546 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
2548 if (psa->fRTL && psa->fLogicalOrder)
2550 int i;
2551 WORD *rtlGlyphs;
2553 rtlGlyphs = heap_alloc(cGlyphs * sizeof(WORD));
2554 if (!rtlGlyphs)
2555 return E_OUTOFMEMORY;
2557 for (i = 0; i < cGlyphs; i++)
2558 rtlGlyphs[i] = pwGlyphs[cGlyphs-1-i];
2560 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, rtlGlyphs, cGlyphs, NULL))
2561 hr = S_FALSE;
2562 heap_free(rtlGlyphs);
2564 else
2565 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
2566 hr = S_FALSE;
2568 return hr;
2571 /***********************************************************************
2572 * ScriptCacheGetHeight (USP10.@)
2574 * Retrieve the height of the font in the cache.
2576 * PARAMS
2577 * hdc [I] Device context.
2578 * psc [I/O] Opaque pointer to a script cache.
2579 * height [O] Receives font height.
2581 * RETURNS
2582 * Success: S_OK
2583 * Failure: Non-zero HRESULT value.
2585 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
2587 HRESULT hr;
2589 TRACE("(%p, %p, %p)\n", hdc, psc, height);
2591 if (!height) return E_INVALIDARG;
2592 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2594 *height = get_cache_height(psc);
2595 return S_OK;
2598 /***********************************************************************
2599 * ScriptGetGlyphABCWidth (USP10.@)
2601 * Retrieve the width of a glyph.
2603 * PARAMS
2604 * hdc [I] Device context.
2605 * psc [I/O] Opaque pointer to a script cache.
2606 * glyph [I] Glyph to retrieve the width for.
2607 * abc [O] ABC widths of the glyph.
2609 * RETURNS
2610 * Success: S_OK
2611 * Failure: Non-zero HRESULT value.
2613 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
2615 HRESULT hr;
2617 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
2619 if (!abc) return E_INVALIDARG;
2620 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
2622 if (!get_cache_glyph_widths(psc, glyph, abc))
2624 if (!hdc) return E_PENDING;
2625 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
2627 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
2629 else
2631 INT width;
2632 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
2633 abc->abcB = width;
2634 abc->abcA = abc->abcC = 0;
2636 set_cache_glyph_widths(psc, glyph, abc);
2638 return S_OK;
2641 /***********************************************************************
2642 * ScriptLayout (USP10.@)
2644 * Map embedding levels to visual and/or logical order.
2646 * PARAMS
2647 * runs [I] Size of level array.
2648 * level [I] Array of embedding levels.
2649 * vistolog [O] Map of embedding levels from visual to logical order.
2650 * logtovis [O] Map of embedding levels from logical to visual order.
2652 * RETURNS
2653 * Success: S_OK
2654 * Failure: Non-zero HRESULT value.
2656 * BUGS
2657 * This stub works correctly for any sequence of a single
2658 * embedding level but not for sequences of different
2659 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2661 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
2663 int* indexs;
2664 int ich;
2666 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
2668 if (!level || (!vistolog && !logtovis))
2669 return E_INVALIDARG;
2671 indexs = heap_alloc(sizeof(int) * runs);
2672 if (!indexs)
2673 return E_OUTOFMEMORY;
2676 if (vistolog)
2678 for( ich = 0; ich < runs; ich++)
2679 indexs[ich] = ich;
2681 ich = 0;
2682 while (ich < runs)
2683 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
2684 for (ich = 0; ich < runs; ich++)
2685 vistolog[ich] = indexs[ich];
2689 if (logtovis)
2691 for( ich = 0; ich < runs; ich++)
2692 indexs[ich] = ich;
2694 ich = 0;
2695 while (ich < runs)
2696 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
2697 for (ich = 0; ich < runs; ich++)
2698 logtovis[ich] = indexs[ich];
2700 heap_free(indexs);
2702 return S_OK;
2705 /***********************************************************************
2706 * ScriptStringGetLogicalWidths (USP10.@)
2708 * Returns logical widths from a string analysis.
2710 * PARAMS
2711 * ssa [I] string analysis.
2712 * piDx [O] logical widths returned.
2714 * RETURNS
2715 * Success: S_OK
2716 * Failure: a non-zero HRESULT.
2718 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
2720 int i, j, next = 0;
2721 StringAnalysis *analysis = ssa;
2723 TRACE("%p, %p\n", ssa, piDx);
2725 if (!analysis) return S_FALSE;
2726 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2728 for (i = 0; i < analysis->numItems; i++)
2730 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
2731 int direction = 1;
2733 if (analysis->pItem[i].a.fRTL && ! analysis->pItem[i].a.fLogicalOrder)
2734 direction = -1;
2736 for (j = 0; j < cChar; j++)
2738 int k;
2739 int glyph = analysis->glyphs[i].pwLogClust[j];
2740 int clust_size = get_cluster_size(analysis->glyphs[i].pwLogClust,
2741 cChar, j, direction, NULL, NULL);
2742 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);
2744 for (k = 0; k < clust_size; k++)
2746 piDx[next] = advance / clust_size;
2747 next++;
2748 if (k) j++;
2752 return S_OK;
2755 /***********************************************************************
2756 * ScriptStringValidate (USP10.@)
2758 * Validate a string analysis.
2760 * PARAMS
2761 * ssa [I] string analysis.
2763 * RETURNS
2764 * Success: S_OK
2765 * Failure: S_FALSE if invalid sequences are found
2766 * or a non-zero HRESULT if it fails.
2768 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
2770 StringAnalysis *analysis = ssa;
2772 TRACE("(%p)\n", ssa);
2774 if (!analysis) return E_INVALIDARG;
2775 return (analysis->invalid) ? S_FALSE : S_OK;
2778 /***********************************************************************
2779 * ScriptString_pSize (USP10.@)
2781 * Retrieve width and height of an analysed string.
2783 * PARAMS
2784 * ssa [I] string analysis.
2786 * RETURNS
2787 * Success: Pointer to a SIZE structure.
2788 * Failure: NULL
2790 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
2792 int i, j;
2793 StringAnalysis *analysis = ssa;
2795 TRACE("(%p)\n", ssa);
2797 if (!analysis) return NULL;
2798 if (!(analysis->dwFlags & SSA_GLYPHS)) return NULL;
2800 if (!analysis->sz)
2802 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
2803 analysis->sz->cy = analysis->glyphs[0].sc->tm.tmHeight;
2805 analysis->sz->cx = 0;
2806 for (i = 0; i < analysis->numItems; i++)
2808 if (analysis->glyphs[i].sc->tm.tmHeight > analysis->sz->cy)
2809 analysis->sz->cy = analysis->glyphs[i].sc->tm.tmHeight;
2810 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
2811 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
2814 return analysis->sz;
2817 /***********************************************************************
2818 * ScriptString_pLogAttr (USP10.@)
2820 * Retrieve logical attributes of an analysed string.
2822 * PARAMS
2823 * ssa [I] string analysis.
2825 * RETURNS
2826 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
2827 * Failure: NULL
2829 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
2831 StringAnalysis *analysis = ssa;
2833 TRACE("(%p)\n", ssa);
2835 if (!analysis) return NULL;
2836 if (!(analysis->dwFlags & SSA_BREAK)) return NULL;
2837 return analysis->logattrs;
2840 /***********************************************************************
2841 * ScriptString_pcOutChars (USP10.@)
2843 * Retrieve the length of a string after clipping.
2845 * PARAMS
2846 * ssa [I] String analysis.
2848 * RETURNS
2849 * Success: Pointer to the length.
2850 * Failure: NULL
2852 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
2854 StringAnalysis *analysis = ssa;
2856 TRACE("(%p)\n", ssa);
2858 if (!analysis) return NULL;
2859 return &analysis->clip_len;
2862 /***********************************************************************
2863 * ScriptStringGetOrder (USP10.@)
2865 * Retrieve a glyph order map.
2867 * PARAMS
2868 * ssa [I] String analysis.
2869 * order [I/O] Array of glyph positions.
2871 * RETURNS
2872 * Success: S_OK
2873 * Failure: a non-zero HRESULT.
2875 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
2877 int i, j;
2878 unsigned int k;
2879 StringAnalysis *analysis = ssa;
2881 TRACE("(%p)\n", ssa);
2883 if (!analysis) return S_FALSE;
2884 if (!(analysis->dwFlags & SSA_GLYPHS)) return S_FALSE;
2886 /* FIXME: handle RTL scripts */
2887 for (i = 0, k = 0; i < analysis->numItems; i++)
2888 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
2889 order[k] = k;
2891 return S_OK;
2894 /***********************************************************************
2895 * ScriptGetLogicalWidths (USP10.@)
2897 * Convert advance widths to logical widths.
2899 * PARAMS
2900 * sa [I] Script analysis.
2901 * nbchars [I] Number of characters.
2902 * nbglyphs [I] Number of glyphs.
2903 * glyph_width [I] Array of glyph widths.
2904 * log_clust [I] Array of logical clusters.
2905 * sva [I] Visual attributes.
2906 * widths [O] Array of logical widths.
2908 * RETURNS
2909 * Success: S_OK
2910 * Failure: a non-zero HRESULT.
2912 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
2913 const int *glyph_width, const WORD *log_clust,
2914 const SCRIPT_VISATTR *sva, int *widths)
2916 int i;
2918 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
2919 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
2921 /* FIXME */
2922 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
2923 return S_OK;
2926 /***********************************************************************
2927 * ScriptApplyLogicalWidth (USP10.@)
2929 * Generate glyph advance widths.
2931 * PARAMS
2932 * dx [I] Array of logical advance widths.
2933 * num_chars [I] Number of characters.
2934 * num_glyphs [I] Number of glyphs.
2935 * log_clust [I] Array of logical clusters.
2936 * sva [I] Visual attributes.
2937 * advance [I] Array of glyph advance widths.
2938 * sa [I] Script analysis.
2939 * abc [I/O] Summed ABC widths.
2940 * justify [O] Array of glyph advance widths.
2942 * RETURNS
2943 * Success: S_OK
2944 * Failure: a non-zero HRESULT.
2946 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
2947 const WORD *log_clust, const SCRIPT_VISATTR *sva,
2948 const int *advance, const SCRIPT_ANALYSIS *sa,
2949 ABC *abc, int *justify)
2951 int i;
2953 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
2954 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
2956 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
2957 return S_OK;
2960 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
2961 int num_glyphs, int dx, int min_kashida, int *justify)
2963 int i;
2965 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
2967 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
2968 return S_OK;