- Move NCI generated files to arch-specific directories
[reactos.git] / reactos / dll / win32 / usp10 / usp10.c
1 /*
2 * Implementation of Uniscribe Script Processor (usp10.dll)
3 *
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * Notes:
22 * Uniscribe allows for processing of complex scripts such as joining
23 * and filtering characters and bi-directional text with custom line breaks.
24 */
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "usp10.h"
34
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
37
38 DWORD STDCALL GetGlyphIndicesW( HDC hdc, LPCWSTR lpstr, int c, LPWORD pgi, DWORD fl);
39 BOOL STDCALL GetCharABCWidthsI(HDC hdc, UINT giFirst, UINT cgi, LPWORD pgi, LPABC lpabc);
40 /**
41 * some documentation here:
42 * http://www.microsoft.com/typography/developers/uniscribe/uniscribe.htm
43 */
44
45 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
46
47 static const SCRIPT_PROPERTIES props[] =
48 {
49 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
50 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
51 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
52 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
53 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
54 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
55 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
56 { 8, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
57 { 25, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
58 { 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
59 { 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
60 { 42, 0, 0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
61 { 9, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
62 { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0 },
63 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
64 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
65 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
66 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
67 { 18, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
68 { 18, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
69 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
70 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
71 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
72 { 9, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
73 { 13, 0, 1, 0, 1, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
74 { 13, 0, 1, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
75 { 1, 0, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
76 { 1, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
77 { 41, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
78 { 32, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
79 { 90, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0 },
80 { 30, 0, 1, 1, 1, 222, 0, 0, 1, 0, 1, 0, 0, 0, 1 },
81 { 30, 1, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
82 { 30, 0, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
83 { 57, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
84 { 57, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
85 { 73, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
86 { 73, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
87 { 69, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
88 { 69, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
89 { 69, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
90 { 70, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
91 { 70, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
92 { 71, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
93 { 71, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
94 { 72, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
95 { 72, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
96 { 74, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
97 { 74, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
98 { 75, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
99 { 75, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
100 { 76, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
101 { 76, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
102 { 81, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 },
103 { 81, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
104 { 84, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 },
105 { 84, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
106 { 83, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
107 { 83, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
108 { 85, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
109 { 85, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
110 { 80, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
111 { 80, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
112 { 94, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
113 { 94, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
114 { 101, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
115 { 93, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
116 { 92, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
117 { 9, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
118 { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
119 { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
120 { 91, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
121 { 9, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
122 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
123 };
124
125 static const SCRIPT_PROPERTIES *script_props[] =
126 {
127 &props[0], &props[1], &props[2], &props[3],
128 &props[4], &props[5], &props[6], &props[7],
129 &props[8], &props[9], &props[11], &props[12],
130 &props[13], &props[14], &props[15], &props[16],
131 &props[17], &props[18], &props[19], &props[20],
132 &props[21], &props[22], &props[23], &props[24],
133 &props[25], &props[26], &props[27], &props[28],
134 &props[29], &props[30], &props[31], &props[32],
135 &props[33], &props[34], &props[35], &props[36],
136 &props[37], &props[38], &props[39], &props[40],
137 &props[41], &props[42], &props[43], &props[44],
138 &props[45], &props[46], &props[47], &props[48],
139 &props[49], &props[50], &props[51], &props[52],
140 &props[53], &props[54], &props[55], &props[56],
141 &props[57], &props[58], &props[59], &props[60],
142 &props[61], &props[62], &props[63], &props[64],
143 &props[65], &props[66], &props[67], &props[68],
144 &props[69], &props[70], &props[71], &props[72],
145 &props[73]
146 };
147
148 typedef struct {
149 HDC hdc;
150 LONG height;
151 WCHAR default_char;
152 } ScriptCache;
153
154 typedef struct {
155 int numGlyphs;
156 WORD* glyphs;
157 WORD* pwLogClust;
158 int* piAdvance;
159 SCRIPT_VISATTR* psva;
160 GOFFSET* pGoffset;
161 ABC* abc;
162 } StringGlyphs;
163
164 typedef struct {
165 BOOL invalid;
166 int clip_len;
167 ScriptCache *sc;
168 int cItems;
169 int cMaxGlyphs;
170 SCRIPT_ITEM* pItem;
171 int numItems;
172 StringGlyphs* glyphs;
173 SCRIPT_LOGATTR* logattrs;
174 SIZE* sz;
175 } StringAnalysis;
176
177 static inline void *usp_alloc(SIZE_T size)
178 {
179 return HeapAlloc(GetProcessHeap(), 0, size);
180 }
181
182 static inline void *usp_zero_alloc(SIZE_T size)
183 {
184 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
185 }
186
187 static inline void *usp_zero_realloc(LPVOID mem, SIZE_T size)
188 {
189 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
190 }
191
192 static inline void usp_free(LPVOID mem)
193 {
194 HeapFree(GetProcessHeap(), 0, mem);
195 }
196
197 static HDC get_cache_hdc(SCRIPT_CACHE *psc)
198 {
199 return ((ScriptCache *)*psc)->hdc;
200 }
201
202 static WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
203 {
204 return ((ScriptCache *)*psc)->default_char;
205 }
206
207 static LONG get_cache_height(SCRIPT_CACHE *psc)
208 {
209 return ((ScriptCache *)*psc)->height;
210 }
211
212 static HRESULT init_script_cache(const HDC hdc, ScriptCache *sc)
213 {
214 TEXTMETRICW metric;
215
216 if (!GetTextMetricsW(hdc, &metric)) return E_INVALIDARG;
217 sc->height = metric.tmHeight;
218 sc->default_char = metric.tmDefaultChar;
219 sc->hdc = hdc;
220 return S_OK;
221 }
222
223 static HRESULT get_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
224 {
225 if (!psc) return E_INVALIDARG;
226 if (!*psc)
227 {
228 HRESULT ret;
229 ScriptCache *sc;
230
231 if (!hdc) return E_PENDING;
232 if (!(sc = usp_zero_alloc(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
233 if ((ret = init_script_cache(hdc, sc)))
234 {
235 usp_free(sc);
236 return ret;
237 }
238 *psc = sc;
239 }
240 TRACE("<- %p\n", *psc);
241 return S_OK;
242 }
243
244 /***********************************************************************
245 * DllMain
246 *
247 */
248 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
249 {
250 switch(fdwReason)
251 {
252 case DLL_PROCESS_ATTACH:
253 DisableThreadLibraryCalls(hInstDLL);
254 break;
255 case DLL_PROCESS_DETACH:
256 break;
257 }
258 return TRUE;
259 }
260
261 /***********************************************************************
262 * ScriptFreeCache (USP10.@)
263 *
264 * Free a script cache.
265 *
266 * PARAMS
267 * psc [I/O] Script cache.
268 *
269 * RETURNS
270 * Success: S_OK
271 * Failure: Non-zero HRESULT value.
272 */
273 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
274 {
275 TRACE("%p\n", psc);
276
277 if (psc)
278 {
279 usp_free(*psc);
280 *psc = NULL;
281 }
282 return S_OK;
283 }
284
285 /***********************************************************************
286 * ScriptGetProperties (USP10.@)
287 *
288 * Retrieve a list of script properties.
289 *
290 * PARAMS
291 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
292 * num [I] Pointer to the number of scripts.
293 *
294 * RETURNS
295 * Success: S_OK
296 * Failure: Non-zero HRESULT value.
297 *
298 * NOTES
299 * Behaviour matches WinXP.
300 */
301 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
302 {
303 TRACE("(%p,%p)\n", props, num);
304
305 if (!props && !num) return E_INVALIDARG;
306
307 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
308 if (props) *props = script_props;
309
310 return S_OK;
311 }
312
313 /***********************************************************************
314 * ScriptGetFontProperties (USP10.@)
315 *
316 * Get information on special glyphs.
317 *
318 * PARAMS
319 * hdc [I] Device context.
320 * psc [I/O] Opaque pointer to a script cache.
321 * sfp [O] Font properties structure.
322 */
323 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
324 {
325 HRESULT hr;
326
327 TRACE("%p,%p,%p\n", hdc, psc, sfp);
328
329 if (!sfp) return E_INVALIDARG;
330 if ((hr = get_script_cache(hdc, psc))) return hr;
331
332 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
333 return E_INVALIDARG;
334
335 /* return something sensible? */
336 sfp->wgBlank = 0;
337 sfp->wgDefault = get_cache_default_char(psc);
338 sfp->wgInvalid = 0;
339 sfp->wgKashida = 0xffff;
340 sfp->iKashidaWidth = 0;
341
342 return S_OK;
343 }
344
345 /***********************************************************************
346 * ScriptRecordDigitSubstitution (USP10.@)
347 *
348 * Record digit substitution settings for a given locale.
349 *
350 * PARAMS
351 * locale [I] Locale identifier.
352 * sds [I] Structure to record substitution settings.
353 *
354 * RETURNS
355 * Success: S_OK
356 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
357 *
358 * SEE ALSO
359 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
360 */
361 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
362 {
363 DWORD plgid, sub;
364
365 TRACE("0x%x, %p\n", locale, sds);
366
367 /* This implementation appears to be correct for all languages, but it's
368 * not clear if sds->DigitSubstitute is ever set to anything except
369 * CONTEXT or NONE in reality */
370
371 if (!sds) return E_POINTER;
372
373 locale = ConvertDefaultLocale(locale);
374
375 if (!IsValidLocale(locale, LCID_INSTALLED))
376 return E_INVALIDARG;
377
378 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
379 sds->TraditionalDigitLanguage = plgid;
380
381 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
382 sds->NationalDigitLanguage = plgid;
383 else
384 sds->NationalDigitLanguage = LANG_ENGLISH;
385
386 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
387 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
388
389 switch (sub)
390 {
391 case 0:
392 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
393 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
394 else
395 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
396 break;
397 case 1:
398 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
399 break;
400 case 2:
401 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
402 break;
403 default:
404 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
405 break;
406 }
407
408 sds->dwReserved = 0;
409 return S_OK;
410 }
411
412 /***********************************************************************
413 * ScriptApplyDigitSubstitution (USP10.@)
414 *
415 * Apply digit substitution settings.
416 *
417 * PARAMS
418 * sds [I] Structure with recorded substitution settings.
419 * sc [I] Script control structure.
420 * ss [I] Script state structure.
421 *
422 * RETURNS
423 * Success: S_OK
424 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
425 */
426 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
427 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
428 {
429 SCRIPT_DIGITSUBSTITUTE psds;
430
431 TRACE("%p, %p, %p\n", sds, sc, ss);
432
433 if (!sc || !ss) return E_POINTER;
434 if (!sds)
435 {
436 sds = &psds;
437 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
438 return E_INVALIDARG;
439 }
440
441 sc->uDefaultLanguage = LANG_ENGLISH;
442 sc->fContextDigits = 0;
443 ss->fDigitSubstitute = 0;
444
445 switch (sds->DigitSubstitute) {
446 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
447 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
448 case SCRIPT_DIGITSUBSTITUTE_NONE:
449 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
450 return S_OK;
451 default:
452 return E_INVALIDARG;
453 }
454 }
455
456 /***********************************************************************
457 * ScriptItemize (USP10.@)
458 *
459 * Split a Unicode string into shapeable parts.
460 *
461 * PARAMS
462 * pwcInChars [I] String to split.
463 * cInChars [I] Number of characters in pwcInChars.
464 * cMaxItems [I] Maximum number of items to return.
465 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
466 * psState [I] Pointer to a SCRIPT_STATE structure.
467 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
468 * pcItems [O] Number of script items returned.
469 *
470 * RETURNS
471 * Success: S_OK
472 * Failure: Non-zero HRESULT value.
473 */
474 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
475 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
476 SCRIPT_ITEM *pItems, int *pcItems)
477 {
478
479 #define Numeric_start 0x0030
480 #define Numeric_stop 0x0039
481 #define Numeric_space 0x0020
482 #define Arabic_start 0x0600
483 #define Arabic_stop 0x06ff
484 #define Latin_start 0x0001
485 #define Latin_stop 0x024f
486 #define Script_Arabic 6
487 #define Script_Latin 1
488 #define Script_Numeric 5
489
490 int cnt = 0, index = 0;
491 int New_Script = SCRIPT_UNDEFINED;
492
493 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
494 psControl, psState, pItems, pcItems);
495
496 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
497 return E_INVALIDARG;
498
499 pItems[index].iCharPos = 0;
500 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
501
502 if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
503 pItems[index].a.eScript = Script_Numeric;
504 else
505 if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
506 pItems[index].a.eScript = Script_Arabic;
507 else
508 if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
509 pItems[index].a.eScript = Script_Latin;
510
511 if (pItems[index].a.eScript == Script_Arabic)
512 pItems[index].a.s.uBidiLevel = 1;
513
514 TRACE("New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
515 New_Script, pItems[index].a.eScript, index, cnt,
516 pItems[index].iCharPos = cnt);
517
518 for (cnt=0; cnt < cInChars; cnt++)
519 {
520 if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
521 || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space))
522 New_Script = Script_Numeric;
523 else
524 if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
525 || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space))
526 New_Script = Script_Arabic;
527 else
528 if ((WCHAR) pwcInChars[cnt] >= Latin_start && (WCHAR) pwcInChars[cnt] <= Latin_stop)
529 New_Script = Script_Latin;
530 else
531 New_Script = SCRIPT_UNDEFINED;
532
533 if (New_Script != pItems[index].a.eScript)
534 {
535 TRACE("New_Script=%d, eScript=%d ", New_Script, pItems[index].a.eScript);
536 index++;
537 if (index+1 > cMaxItems)
538 return E_OUTOFMEMORY;
539
540 pItems[index].iCharPos = cnt;
541 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
542
543 if (New_Script == Script_Arabic)
544 pItems[index].a.s.uBidiLevel = 1;
545
546 pItems[index].a.eScript = New_Script;
547 if (New_Script == Script_Arabic)
548 pItems[index].a.s.uBidiLevel = 1;
549
550 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos = cnt);
551 }
552 }
553
554 /* While not strictly necessary according to the spec, make sure the n+1
555 * item is set up to prevent random behaviour if the caller erroneously
556 * checks the n+1 structure */
557 memset(&pItems[index+1].a, 0, sizeof(SCRIPT_ANALYSIS));
558
559 TRACE("index=%d cnt=%d iCharPos=%d\n", index+1, cnt, pItems[index+1].iCharPos = cnt);
560
561 /* Set one SCRIPT_STATE item being returned */
562 *pcItems = index + 1;
563
564 /* Set SCRIPT_ITEM */
565 pItems[index+1].iCharPos = cnt; /* the last + 1 item
566 contains the ptr to the lastchar */
567 return S_OK;
568 }
569
570 /***********************************************************************
571 * ScriptStringAnalyse (USP10.@)
572 *
573 */
574 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
575 int cGlyphs, int iCharset, DWORD dwFlags,
576 int iReqWidth, SCRIPT_CONTROL *psControl,
577 SCRIPT_STATE *psState, const int *piDx,
578 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
579 SCRIPT_STRING_ANALYSIS *pssa)
580 {
581 HRESULT hr = E_OUTOFMEMORY;
582 StringAnalysis *analysis = NULL;
583 int i, num_items = 255;
584
585 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
586 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
587 psControl, psState, piDx, pTabdef, pbInClass, pssa);
588
589 if (iCharset != -1)
590 {
591 FIXME("Only Unicode strings are supported\n");
592 return E_INVALIDARG;
593 }
594 if (cString < 1 || !pString) return E_INVALIDARG;
595 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
596
597 if (!(analysis = usp_zero_alloc(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
598 if (!(analysis->pItem = usp_zero_alloc(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
599
600 /* FIXME: handle clipping */
601 analysis->clip_len = cString;
602
603 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
604 &analysis->numItems);
605
606 while (hr == E_OUTOFMEMORY)
607 {
608 SCRIPT_ITEM *tmp;
609
610 num_items *= 2;
611 if (!(tmp = usp_zero_realloc(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
612 goto error;
613
614 analysis->pItem = tmp;
615 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
616 &analysis->numItems);
617 }
618 if (hr) goto error;
619
620 if ((analysis->logattrs = usp_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
621 ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs);
622 else
623 goto error;
624
625 if (!(analysis->glyphs = usp_zero_alloc(sizeof(StringGlyphs) * analysis->numItems)))
626 goto error;
627
628 for (i = 0; i < analysis->numItems; i++)
629 {
630 SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc;
631 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
632 int numGlyphs = 1.5 * cChar + 16;
633 WORD *glyphs = usp_zero_alloc(sizeof(WORD) * numGlyphs);
634 WORD *pwLogClust = usp_zero_alloc(sizeof(WORD) * cChar);
635 int *piAdvance = usp_zero_alloc(sizeof(int) * numGlyphs);
636 SCRIPT_VISATTR *psva = usp_zero_alloc(sizeof(SCRIPT_VISATTR) * cChar);
637 GOFFSET *pGoffset = usp_zero_alloc(sizeof(GOFFSET) * numGlyphs);
638 ABC *abc = usp_zero_alloc(sizeof(ABC));
639 int numGlyphsReturned;
640
641 /* FIXME: non unicode strings */
642 WCHAR* pStr = (WCHAR*)pString;
643 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
644 cChar, numGlyphs, &analysis->pItem[i].a,
645 glyphs, pwLogClust, psva, &numGlyphsReturned);
646 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
647 piAdvance, pGoffset, abc);
648
649 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
650 analysis->glyphs[i].glyphs = glyphs;
651 analysis->glyphs[i].pwLogClust = pwLogClust;
652 analysis->glyphs[i].piAdvance = piAdvance;
653 analysis->glyphs[i].psva = psva;
654 analysis->glyphs[i].pGoffset = pGoffset;
655 analysis->glyphs[i].abc = abc;
656 }
657
658 *pssa = analysis;
659 return S_OK;
660
661 error:
662 usp_free(analysis->glyphs);
663 usp_free(analysis->logattrs);
664 usp_free(analysis->pItem);
665 usp_free(analysis);
666 return hr;
667 }
668
669 /***********************************************************************
670 * ScriptStringOut (USP10.@)
671 *
672 * This function takes the output of ScriptStringAnalyse and joins the segments
673 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
674 * only processes glyphs.
675 *
676 * Parameters:
677 * ssa [I] buffer to hold the analysed string components
678 * iX [I] X axis displacement for output
679 * iY [I] Y axis displacement for output
680 * uOptions [I] flags controling output processing
681 * prc [I] rectangle coordinates
682 * iMinSel [I] starting pos for substringing output string
683 * iMaxSel [I] ending pos for substringing output string
684 * fDisabled [I] controls text highlighting
685 *
686 * RETURNS
687 * Success: S_OK
688 * Failure: is the value returned by ScriptTextOut
689 */
690 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
691 int iX,
692 int iY,
693 UINT uOptions,
694 const RECT *prc,
695 int iMinSel,
696 int iMaxSel,
697 BOOL fDisabled)
698 {
699 StringAnalysis *analysis;
700 WORD *glyphs;
701 int item, cnt, x;
702 HRESULT hr;
703
704 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
705 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
706
707 if (!(analysis = ssa)) return E_INVALIDARG;
708
709 /*
710 * Get storage for the output buffer for the consolidated strings
711 */
712 cnt = 0;
713 for (item = 0; item < analysis->numItems; item++)
714 {
715 cnt += analysis->glyphs[item].numGlyphs;
716 }
717 if (!(glyphs = usp_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY;
718
719 /*
720 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
721 */
722 uOptions |= ETO_GLYPH_INDEX;
723 analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */
724
725 /*
726 * Copy the string items into the output buffer
727 */
728
729 TRACE("numItems %d\n", analysis->numItems);
730
731 cnt = 0;
732 for (item = 0; item < analysis->numItems; item++)
733 {
734 memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs,
735 sizeof(WCHAR) * analysis->glyphs[item].numGlyphs);
736
737 TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs);
738 for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++)
739 TRACE("%04x", glyphs[x]);
740 TRACE("\n");
741
742 cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */
743 }
744
745 hr = ScriptTextOut(analysis->sc->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY,
746 uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt,
747 analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset);
748 TRACE("ScriptTextOut hr=%08x\n", hr);
749
750 /*
751 * Free the output buffer and script cache
752 */
753 usp_free(glyphs);
754 return hr;
755 }
756
757 /***********************************************************************
758 * ScriptStringCPtoX (USP10.@)
759 *
760 */
761 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
762 {
763 int i, j;
764 int runningX = 0;
765 int runningCp = 0;
766 StringAnalysis* analysis = ssa;
767
768 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
769
770 if (!ssa || !pX) return S_FALSE;
771
772 /* icp out of range */
773 if(icp < 0)
774 {
775 analysis->invalid = TRUE;
776 return E_INVALIDARG;
777 }
778
779 for(i=0; i<analysis->numItems; i++)
780 {
781 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
782 {
783 if(runningCp == icp && fTrailing == FALSE)
784 {
785 *pX = runningX;
786 return S_OK;
787 }
788 runningX += analysis->glyphs[i].piAdvance[j];
789 if(runningCp == icp && fTrailing == TRUE)
790 {
791 *pX = runningX;
792 return S_OK;
793 }
794 runningCp++;
795 }
796 }
797
798 /* icp out of range */
799 analysis->invalid = TRUE;
800 return E_INVALIDARG;
801 }
802
803 /***********************************************************************
804 * ScriptStringXtoCP (USP10.@)
805 *
806 */
807 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
808 {
809 StringAnalysis* analysis = ssa;
810 int i;
811 int j;
812 int runningX = 0;
813 int runningCp = 0;
814 int width;
815
816 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
817
818 if (!ssa || !piCh || !piTrailing) return S_FALSE;
819
820 /* out of range */
821 if(iX < 0)
822 {
823 *piCh = -1;
824 *piTrailing = TRUE;
825 return S_OK;
826 }
827
828 for(i=0; i<analysis->numItems; i++)
829 {
830 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
831 {
832 width = analysis->glyphs[i].piAdvance[j];
833 if(iX < (runningX + width))
834 {
835 *piCh = runningCp;
836 if((iX - runningX) > width/2)
837 *piTrailing = TRUE;
838 else
839 *piTrailing = FALSE;
840 return S_OK;
841 }
842 runningX += width;
843 runningCp++;
844 }
845 }
846
847 /* out of range */
848 *piCh = analysis->pItem[analysis->numItems].iCharPos;
849 *piTrailing = FALSE;
850
851 return S_OK;
852 }
853
854
855 /***********************************************************************
856 * ScriptStringFree (USP10.@)
857 *
858 * Free a string analysis.
859 *
860 * PARAMS
861 * pssa [I] string analysis.
862 *
863 * RETURNS
864 * Success: S_OK
865 * Failure: Non-zero HRESULT value.
866 */
867 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
868 {
869 StringAnalysis* analysis;
870 BOOL invalid;
871 int i;
872
873 TRACE("(%p)\n", pssa);
874
875 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
876 invalid = analysis->invalid;
877
878 for (i = 0; i < analysis->numItems; i++)
879 {
880 usp_free(analysis->glyphs[i].glyphs);
881 usp_free(analysis->glyphs[i].pwLogClust);
882 usp_free(analysis->glyphs[i].piAdvance);
883 usp_free(analysis->glyphs[i].psva);
884 usp_free(analysis->glyphs[i].pGoffset);
885 usp_free(analysis->glyphs[i].abc);
886 }
887
888 usp_free(analysis->glyphs);
889 usp_free(analysis->pItem);
890 usp_free(analysis->logattrs);
891 usp_free(analysis->sz);
892 usp_free(analysis);
893
894 if (invalid) return E_INVALIDARG;
895 return S_OK;
896 }
897
898 /***********************************************************************
899 * ScriptCPtoX (USP10.@)
900 *
901 */
902 HRESULT WINAPI ScriptCPtoX(int iCP,
903 BOOL fTrailing,
904 int cChars,
905 int cGlyphs,
906 const WORD *pwLogClust,
907 const SCRIPT_VISATTR *psva,
908 const int *piAdvance,
909 const SCRIPT_ANALYSIS *psa,
910 int *piX)
911 {
912 int item;
913 int iPosX;
914 float fMaxPosX = 0;
915 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
916 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
917 psa, piX);
918 for (item=0; item < cGlyphs; item++) /* total piAdvance */
919 fMaxPosX += piAdvance[item];
920 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
921 if (iPosX > fMaxPosX)
922 iPosX = fMaxPosX;
923 *piX = iPosX; /* Return something in range */
924
925 TRACE("*piX=%d\n", *piX);
926 return S_OK;
927 }
928
929 /***********************************************************************
930 * ScriptXtoCP (USP10.@)
931 *
932 */
933 HRESULT WINAPI ScriptXtoCP(int iX,
934 int cChars,
935 int cGlyphs,
936 const WORD *pwLogClust,
937 const SCRIPT_VISATTR *psva,
938 const int *piAdvance,
939 const SCRIPT_ANALYSIS *psa,
940 int *piCP,
941 int *piTrailing)
942 {
943 int item;
944 int iPosX;
945 float fMaxPosX = 1;
946 float fAvePosX;
947 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
948 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
949 psa, piCP, piTrailing);
950 if (iX < 0) /* iX is before start of run */
951 {
952 *piCP = -1;
953 *piTrailing = TRUE;
954 return S_OK;
955 }
956
957 for (item=0; item < cGlyphs; item++) /* total piAdvance */
958 fMaxPosX += piAdvance[item];
959
960 if (iX >= fMaxPosX) /* iX too large */
961 {
962 *piCP = cChars;
963 *piTrailing = FALSE;
964 return S_OK;
965 }
966
967 fAvePosX = fMaxPosX / cGlyphs;
968 iPosX = fAvePosX;
969 for (item = 1; item < cGlyphs && iPosX < iX; item++)
970 iPosX += fAvePosX;
971 if (iPosX - iX > fAvePosX/2)
972 *piTrailing = 0;
973 else
974 *piTrailing = 1; /* yep we are over halfway */
975
976 *piCP = item -1; /* Return character position */
977 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
978 return S_OK;
979 }
980
981 /***********************************************************************
982 * ScriptBreak (USP10.@)
983 *
984 * Retrieve line break information.
985 *
986 * PARAMS
987 * chars [I] Array of characters.
988 * sa [I] String analysis.
989 * la [I] Array of logical attribute structures.
990 *
991 * RETURNS
992 * Success: S_OK
993 * Failure: S_FALSE
994 */
995 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
996 {
997 unsigned int i;
998
999 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
1000
1001 if (!la) return S_FALSE;
1002
1003 for (i = 0; i < count; i++)
1004 {
1005 memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
1006
1007 /* FIXME: set the other flags */
1008 la[i].fWhiteSpace = isspaceW(chars[i]);
1009 la[i].fCharStop = 1;
1010 }
1011 return S_OK;
1012 }
1013
1014 static const struct
1015 {
1016 WCHAR start;
1017 WCHAR end;
1018 DWORD flag;
1019 }
1020 complex_ranges[] =
1021 {
1022 { 0, 0x0b, SIC_COMPLEX },
1023 { 0x0c, 0x0c, SIC_NEUTRAL },
1024 { 0x0d, 0x1f, SIC_COMPLEX },
1025 { 0x20, 0x2f, SIC_NEUTRAL },
1026 { 0x30, 0x39, SIC_ASCIIDIGIT },
1027 { 0x3a, 0x40, SIC_NEUTRAL },
1028 { 0x5b, 0x60, SIC_NEUTRAL },
1029 { 0x7b, 0x7e, SIC_NEUTRAL },
1030 { 0x7f, 0x9f, SIC_COMPLEX },
1031 { 0xa0, 0xa5, SIC_NEUTRAL },
1032 { 0xa7, 0xa8, SIC_NEUTRAL },
1033 { 0xab, 0xab, SIC_NEUTRAL },
1034 { 0xad, 0xad, SIC_NEUTRAL },
1035 { 0xaf, 0xaf, SIC_NEUTRAL },
1036 { 0xb0, 0xb1, SIC_NEUTRAL },
1037 { 0xb4, 0xb4, SIC_NEUTRAL },
1038 { 0xb6, 0xb8, SIC_NEUTRAL },
1039 { 0xbb, 0xbf, SIC_NEUTRAL },
1040 { 0xd7, 0xd7, SIC_NEUTRAL },
1041 { 0xf7, 0xf7, SIC_NEUTRAL },
1042 { 0x2b9, 0x2ba, SIC_NEUTRAL },
1043 { 0x2c2, 0x2cf, SIC_NEUTRAL },
1044 { 0x2d2, 0x2df, SIC_NEUTRAL },
1045 { 0x2e5, 0x2e9, SIC_COMPLEX },
1046 { 0x2ea, 0x2ed, SIC_NEUTRAL },
1047 { 0x300, 0x362, SIC_COMPLEX },
1048 { 0x530, 0x60b, SIC_COMPLEX },
1049 { 0x60c, 0x60d, SIC_NEUTRAL },
1050 { 0x60e, 0x669, SIC_COMPLEX },
1051 { 0x66a, 0x66a, SIC_NEUTRAL },
1052 { 0x66b, 0x6e8, SIC_COMPLEX },
1053 { 0x6e9, 0x6e9, SIC_NEUTRAL },
1054 { 0x6ea, 0x7bf, SIC_COMPLEX },
1055 { 0x900, 0x1360, SIC_COMPLEX },
1056 { 0x137d, 0x137f, SIC_COMPLEX },
1057 { 0x1680, 0x1680, SIC_NEUTRAL },
1058 { 0x1780, 0x18af, SIC_COMPLEX },
1059 { 0x2000, 0x200a, SIC_NEUTRAL },
1060 { 0x200b, 0x200f, SIC_COMPLEX },
1061 { 0x2010, 0x2016, SIC_NEUTRAL },
1062 { 0x2018, 0x2022, SIC_NEUTRAL },
1063 { 0x2024, 0x2028, SIC_NEUTRAL },
1064 { 0x2029, 0x202e, SIC_COMPLEX },
1065 { 0x202f, 0x2037, SIC_NEUTRAL },
1066 { 0x2039, 0x203c, SIC_NEUTRAL },
1067 { 0x2044, 0x2046, SIC_NEUTRAL },
1068 { 0x206a, 0x206f, SIC_COMPLEX },
1069 { 0x207a, 0x207e, SIC_NEUTRAL },
1070 { 0x208a, 0x20aa, SIC_NEUTRAL },
1071 { 0x20ac, 0x20cf, SIC_NEUTRAL },
1072 { 0x20d0, 0x20ff, SIC_COMPLEX },
1073 { 0x2103, 0x2103, SIC_NEUTRAL },
1074 { 0x2105, 0x2105, SIC_NEUTRAL },
1075 { 0x2109, 0x2109, SIC_NEUTRAL },
1076 { 0x2116, 0x2116, SIC_NEUTRAL },
1077 { 0x2121, 0x2122, SIC_NEUTRAL },
1078 { 0x212e, 0x212e, SIC_NEUTRAL },
1079 { 0x2153, 0x2154, SIC_NEUTRAL },
1080 { 0x215b, 0x215e, SIC_NEUTRAL },
1081 { 0x2190, 0x2199, SIC_NEUTRAL },
1082 { 0x21b8, 0x21b9, SIC_NEUTRAL },
1083 { 0x21d2, 0x21d2, SIC_NEUTRAL },
1084 { 0x21d4, 0x21d4, SIC_NEUTRAL },
1085 { 0x21e7, 0x21e7, SIC_NEUTRAL },
1086 { 0x2200, 0x2200, SIC_NEUTRAL },
1087 { 0x2202, 0x2203, SIC_NEUTRAL },
1088 { 0x2207, 0x2208, SIC_NEUTRAL },
1089 { 0x220b, 0x220b, SIC_NEUTRAL },
1090 { 0x220f, 0x220f, SIC_NEUTRAL },
1091 { 0x2211, 0x2213, SIC_NEUTRAL },
1092 { 0x2215, 0x2215, SIC_NEUTRAL },
1093 { 0x221a, 0x221a, SIC_NEUTRAL },
1094 { 0x221d, 0x2220, SIC_NEUTRAL },
1095 { 0x2223, 0x2223, SIC_NEUTRAL },
1096 { 0x2225, 0x2225, SIC_NEUTRAL },
1097 { 0x2227, 0x222c, SIC_NEUTRAL },
1098 { 0x222e, 0x222e, SIC_NEUTRAL },
1099 { 0x2234, 0x2237, SIC_NEUTRAL },
1100 { 0x223c, 0x223d, SIC_NEUTRAL },
1101 { 0x2248, 0x2248, SIC_NEUTRAL },
1102 { 0x224c, 0x224c, SIC_NEUTRAL },
1103 { 0x2252, 0x2252, SIC_NEUTRAL },
1104 { 0x2260, 0x2261, SIC_NEUTRAL },
1105 { 0x2264, 0x2267, SIC_NEUTRAL },
1106 { 0x226a, 0x226b, SIC_NEUTRAL },
1107 { 0x226e, 0x226f, SIC_NEUTRAL },
1108 { 0x2282, 0x2283, SIC_NEUTRAL },
1109 { 0x2286, 0x2287, SIC_NEUTRAL },
1110 { 0x2295, 0x2295, SIC_NEUTRAL },
1111 { 0x2299, 0x2299, SIC_NEUTRAL },
1112 { 0x22a5, 0x22a5, SIC_NEUTRAL },
1113 { 0x22bf, 0x22bf, SIC_NEUTRAL },
1114 { 0x2312, 0x2312, SIC_NEUTRAL },
1115 { 0x24ea, 0x24ea, SIC_COMPLEX },
1116 { 0x2500, 0x254b, SIC_NEUTRAL },
1117 { 0x2550, 0x256d, SIC_NEUTRAL },
1118 { 0x256e, 0x2574, SIC_NEUTRAL },
1119 { 0x2581, 0x258f, SIC_NEUTRAL },
1120 { 0x2592, 0x2595, SIC_NEUTRAL },
1121 { 0x25a0, 0x25a1, SIC_NEUTRAL },
1122 { 0x25a3, 0x25a9, SIC_NEUTRAL },
1123 { 0x25b2, 0x25b3, SIC_NEUTRAL },
1124 { 0x25b6, 0x25b7, SIC_NEUTRAL },
1125 { 0x25bc, 0x25bd, SIC_NEUTRAL },
1126 { 0x25c0, 0x25c1, SIC_NEUTRAL },
1127 { 0x25c6, 0x25c8, SIC_NEUTRAL },
1128 { 0x25cb, 0x25cb, SIC_NEUTRAL },
1129 { 0x25ce, 0x25d1, SIC_NEUTRAL },
1130 { 0x25e2, 0x25e5, SIC_NEUTRAL },
1131 { 0x25ef, 0x25ef, SIC_NEUTRAL },
1132 { 0x2605, 0x2606, SIC_NEUTRAL },
1133 { 0x2609, 0x2609, SIC_NEUTRAL },
1134 { 0x260e, 0x260f, SIC_NEUTRAL },
1135 { 0x261c, 0x261c, SIC_NEUTRAL },
1136 { 0x261e, 0x261e, SIC_NEUTRAL },
1137 { 0x2640, 0x2640, SIC_NEUTRAL },
1138 { 0x2642, 0x2642, SIC_NEUTRAL },
1139 { 0x2660, 0x2661, SIC_NEUTRAL },
1140 { 0x2663, 0x2665, SIC_NEUTRAL },
1141 { 0x2667, 0x266a, SIC_NEUTRAL },
1142 { 0x266c, 0x266d, SIC_NEUTRAL },
1143 { 0x266f, 0x266f, SIC_NEUTRAL },
1144 { 0x273d, 0x273d, SIC_NEUTRAL },
1145 { 0x2e80, 0x312f, SIC_COMPLEX },
1146 { 0x3190, 0x31bf, SIC_COMPLEX },
1147 { 0x31f0, 0x31ff, SIC_COMPLEX },
1148 { 0x3220, 0x325f, SIC_COMPLEX },
1149 { 0x3280, 0xa4ff, SIC_COMPLEX },
1150 { 0xd800, 0xdfff, SIC_COMPLEX },
1151 { 0xe000, 0xf8ff, SIC_NEUTRAL },
1152 { 0xf900, 0xfaff, SIC_COMPLEX },
1153 { 0xfb13, 0xfb28, SIC_COMPLEX },
1154 { 0xfb29, 0xfb29, SIC_NEUTRAL },
1155 { 0xfb2a, 0xfb4f, SIC_COMPLEX },
1156 { 0xfd3e, 0xfd3f, SIC_NEUTRAL },
1157 { 0xfdd0, 0xfdef, SIC_COMPLEX },
1158 { 0xfe20, 0xfe6f, SIC_COMPLEX },
1159 { 0xfeff, 0xfeff, SIC_COMPLEX },
1160 { 0xff01, 0xff5e, SIC_COMPLEX },
1161 { 0xff61, 0xff9f, SIC_COMPLEX },
1162 { 0xffe0, 0xffe6, SIC_COMPLEX },
1163 { 0xffe8, 0xffee, SIC_COMPLEX },
1164 { 0xfff9, 0xfffb, SIC_COMPLEX },
1165 { 0xfffe, 0xfffe, SIC_COMPLEX }
1166 };
1167
1168 /***********************************************************************
1169 * ScriptIsComplex (USP10.@)
1170 *
1171 * Determine if a string is complex.
1172 *
1173 * PARAMS
1174 * chars [I] Array of characters to test.
1175 * len [I] Length in characters.
1176 * flag [I] Flag.
1177 *
1178 * RETURNS
1179 * Success: S_OK
1180 * Failure: S_FALSE
1181 *
1182 * NOTES
1183 * Behaviour matches that of WinXP.
1184 */
1185 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
1186 {
1187 unsigned int i, j;
1188
1189 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
1190
1191 for (i = 0; i < len; i++)
1192 {
1193 for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
1194 {
1195 if (chars[i] >= complex_ranges[j].start &&
1196 chars[i] <= complex_ranges[j].end &&
1197 (flag & complex_ranges[j].flag)) return S_OK;
1198 }
1199 }
1200 return S_FALSE;
1201 }
1202
1203 /***********************************************************************
1204 * ScriptShape (USP10.@)
1205 *
1206 * Produce glyphs and visual attributes for a run.
1207 *
1208 * PARAMS
1209 * hdc [I] Device context.
1210 * psc [I/O] Opaque pointer to a script cache.
1211 * pwcChars [I] Array of characters specifying the run.
1212 * cChars [I] Number of characters in pwcChars.
1213 * cMaxGlyphs [I] Length of pwOutGlyphs.
1214 * psa [I/O] String analysis.
1215 * pwOutGlyphs [O] Array of glyphs.
1216 * pwLogClust [O] Array of logical cluster info.
1217 * psva [O] Array of visual attributes.
1218 * pcGlyphs [O] Number of glyphs returned.
1219 *
1220 * RETURNS
1221 * Success: S_OK
1222 * Failure: Non-zero HRESULT value.
1223 */
1224 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
1225 int cChars, int cMaxGlyphs,
1226 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
1227 SCRIPT_VISATTR *psva, int *pcGlyphs)
1228 {
1229 int cnt;
1230 HRESULT hr;
1231 *pcGlyphs = cChars;
1232
1233 TRACE("(%p, %p, %p, %d, %d, %p)\n", hdc, psc, pwcChars, cChars, cMaxGlyphs, psa);
1234 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
1235 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
1236
1237 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
1238 if ((hr = get_script_cache(hdc, psc))) return hr;
1239
1240 TRACE("Before: ");
1241 for (cnt = 0; cnt < cChars; cnt++)
1242 TRACE("%4x",pwcChars[cnt]);
1243 TRACE("\n");
1244
1245 if (!psa->fNoGlyphIndex) { /* Glyph translate */
1246 if (!(GetGlyphIndicesW((HDC)get_cache_hdc(psc), (LPCWSTR) pwcChars, (int)cChars, (LPWORD) pwOutGlyphs,(DWORD) 0)))
1247 return S_FALSE;
1248
1249 TRACE("After: ");
1250 for (cnt = 0; cnt < cChars; cnt++) {
1251 TRACE("%04x",pwOutGlyphs[cnt]);
1252 }
1253 TRACE("\n");
1254 }
1255 else {
1256 TRACE("After: ");
1257 for (cnt = 0; cnt < cChars; cnt++) { /* no translate so set up */
1258 pwOutGlyphs[cnt] = pwcChars[cnt]; /* copy in to out and */
1259 TRACE("%04x",pwOutGlyphs[cnt]);
1260 }
1261 TRACE("\n");
1262 }
1263
1264 /* Set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1265 for (cnt = 0; cnt < cChars; cnt++) {
1266 /* FIXME: set to better values */
1267 psva[cnt].uJustification = 2;
1268 psva[cnt].fClusterStart = 1;
1269 psva[cnt].fDiacritic = 0;
1270 psva[cnt].fZeroWidth = 0;
1271 pwLogClust[cnt] = cnt;
1272 }
1273 return S_OK;
1274 }
1275
1276 /***********************************************************************
1277 * ScriptPlace (USP10.@)
1278 *
1279 * Produce advance widths for a run.
1280 *
1281 * PARAMS
1282 * hdc [I] Device context.
1283 * psc [I/O] Opaque pointer to a script cache.
1284 * pwGlyphs [I] Array of glyphs.
1285 * cGlyphs [I] Number of glyphs in pwGlyphs.
1286 * psva [I] Array of visual attributes.
1287 * psa [I/O] String analysis.
1288 * piAdvance [O] Array of advance widths.
1289 * pGoffset [O] Glyph offsets.
1290 * pABC [O] Combined ABC width.
1291 *
1292 * RETURNS
1293 * Success: S_OK
1294 * Failure: Non-zero HRESULT value.
1295 */
1296 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
1297 int cGlyphs, const SCRIPT_VISATTR *psva,
1298 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1299 {
1300 int wcnt;
1301 HRESULT hr;
1302 LPABC lpABC;
1303
1304 TRACE("(%p, %p, %p, %s, %d, %p, %p, %p)\n", hdc, psc, pwGlyphs,
1305 debugstr_wn(pwGlyphs, cGlyphs), cGlyphs, psva, psa, piAdvance);
1306
1307 if ((hr = get_script_cache(hdc, psc))) return hr;
1308
1309 /* Here we need to calculate the width of the run unit. At this point the input string
1310 * has been converted to glyphs and we still need to translate back to the original chars
1311 * to get the correct ABC widths. */
1312
1313 if (!(lpABC = usp_zero_alloc(sizeof(ABC) * cGlyphs))) return E_OUTOFMEMORY;
1314
1315 memset(pABC, 0, sizeof(ABC));
1316
1317 /* FIXME: set pGoffset to more reasonable values */
1318 if (!GetCharABCWidthsI(get_cache_hdc(psc), 0, cGlyphs, (WORD *) pwGlyphs, lpABC ))
1319 {
1320 WARN("Could not get ABC values\n");
1321 for (wcnt = 0; wcnt < cGlyphs; wcnt++) {
1322 piAdvance[wcnt] = 0;
1323 pGoffset[wcnt].du = 0;
1324 pGoffset[wcnt].dv = 0;
1325 }
1326 }
1327 else
1328 {
1329 for (wcnt = 0; wcnt < cGlyphs ; wcnt++) { /* add up the char lengths */
1330 TRACE(" Glyph=%04x, abcA=%d, abcB=%d, abcC=%d wcnt=%d\n",
1331 pwGlyphs[wcnt],
1332 lpABC[wcnt].abcA,
1333 lpABC[wcnt].abcB,
1334 lpABC[wcnt].abcC, wcnt);
1335 pABC->abcA += lpABC[wcnt].abcA;
1336 pABC->abcB += lpABC[wcnt].abcB;
1337 pABC->abcC += lpABC[wcnt].abcC;
1338 piAdvance[wcnt] = lpABC[wcnt].abcA + lpABC[wcnt].abcB + lpABC[wcnt].abcC;
1339 pGoffset[wcnt].du = 0;
1340 pGoffset[wcnt].dv = 0;
1341 }
1342 }
1343 TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1344
1345 usp_free(lpABC);
1346 return S_OK;
1347 }
1348
1349 /***********************************************************************
1350 * ScriptGetCMap (USP10.@)
1351 *
1352 * Retrieve glyph indices.
1353 *
1354 * PARAMS
1355 * hdc [I] Device context.
1356 * psc [I/O] Opaque pointer to a script cache.
1357 * pwcInChars [I] Array of Unicode characters.
1358 * cChars [I] Number of characters in pwcInChars.
1359 * dwFlags [I] Flags.
1360 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1361 *
1362 * RETURNS
1363 * Success: S_OK
1364 * Failure: Non-zero HRESULT value.
1365 */
1366 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1367 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1368 {
1369 int cnt;
1370 HRESULT hr;
1371
1372 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
1373 cChars, dwFlags, pwOutGlyphs);
1374
1375 if ((hr = get_script_cache(hdc, psc))) return hr;
1376
1377 TRACE("Before: ");
1378 for (cnt = 0; cnt < cChars; cnt++)
1379 TRACE("%4x",pwcInChars[cnt]);
1380 TRACE("\n");
1381
1382 GetGlyphIndicesW(get_cache_hdc(psc), pwcInChars, cChars, pwOutGlyphs, 0);
1383
1384 TRACE("After: ");
1385 for (cnt = 0; cnt < cChars; cnt++) {
1386 TRACE("%04x",pwOutGlyphs[cnt]);
1387 }
1388 TRACE("\n");
1389
1390 return S_OK;
1391 }
1392
1393 /***********************************************************************
1394 * ScriptTextOut (USP10.@)
1395 *
1396 */
1397 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1398 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1399 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1400 const int *piJustify, const GOFFSET *pGoffset)
1401 {
1402 HRESULT hr;
1403
1404 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1405 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1406 piAdvance, piJustify, pGoffset);
1407
1408 if (!hdc && psc && !*psc) return E_INVALIDARG;
1409 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
1410 if ((hr = get_script_cache(hdc, psc))) return hr;
1411
1412 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1413 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1414 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1415
1416 if (!ExtTextOutW(get_cache_hdc(psc), x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
1417 return S_FALSE;
1418
1419 return S_OK;
1420 }
1421
1422 /***********************************************************************
1423 * ScriptCacheGetHeight (USP10.@)
1424 *
1425 * Retrieve the height of the font in the cache.
1426 *
1427 * PARAMS
1428 * hdc [I] Device context.
1429 * psc [I/O] Opaque pointer to a script cache.
1430 * height [O] Receives font height.
1431 *
1432 * RETURNS
1433 * Success: S_OK
1434 * Failure: Non-zero HRESULT value.
1435 */
1436 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
1437 {
1438 HRESULT hr;
1439
1440 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1441
1442 if (!height) return E_INVALIDARG;
1443 if ((hr = get_script_cache(hdc, psc))) return hr;
1444
1445 *height = get_cache_height(psc);
1446 return S_OK;
1447 }
1448
1449 /***********************************************************************
1450 * ScriptGetGlyphABCWidth (USP10.@)
1451 *
1452 * Retrieve the width of a glyph.
1453 *
1454 * PARAMS
1455 * hdc [I] Device context.
1456 * psc [I/O] Opaque pointer to a script cache.
1457 * glyph [I] Glyph to retrieve the width for.
1458 * abc [O] ABC widths of the glyph.
1459 *
1460 * RETURNS
1461 * Success: S_OK
1462 * Failure: Non-zero HRESULT value.
1463 */
1464 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1465 {
1466 HRESULT hr;
1467
1468 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1469
1470 if ((hr = get_script_cache(hdc, psc))) return hr;
1471
1472 /* FIXME: get this from the cache */
1473 if (!GetCharABCWidthsW(get_cache_hdc(psc), glyph, glyph, abc)) return E_HANDLE;
1474 return S_OK;
1475 }
1476
1477 /***********************************************************************
1478 * ScriptLayout (USP10.@)
1479 *
1480 * Map embedding levels to visual and/or logical order.
1481 *
1482 * PARAMS
1483 * runs [I] Size of level array.
1484 * level [I] Array of embedding levels.
1485 * vistolog [O] Map of embedding levels from visual to logical order.
1486 * logtovis [O] Map of embedding levels from logical to visual order.
1487 *
1488 * RETURNS
1489 * Success: S_OK
1490 * Failure: Non-zero HRESULT value.
1491 *
1492 * BUGS
1493 * This stub works correctly for any sequence of a single
1494 * embedding level but not for sequences of different
1495 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1496 */
1497 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1498 {
1499 int i, j = runs - 1, k = 0;
1500
1501 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
1502
1503 if (!level || (!vistolog && !logtovis))
1504 return E_INVALIDARG;
1505
1506 for (i = 0; i < runs; i++)
1507 {
1508 if (level[i] % 2)
1509 {
1510 if (vistolog) *vistolog++ = j;
1511 if (logtovis) *logtovis++ = j;
1512 j--;
1513 }
1514 else
1515 {
1516 if (vistolog) *vistolog++ = k;
1517 if (logtovis) *logtovis++ = k;
1518 k++;
1519 }
1520 }
1521 return S_OK;
1522 }
1523
1524 /***********************************************************************
1525 * ScriptStringGetLogicalWidths (USP10.@)
1526 *
1527 * Returns logical widths from a string analysis.
1528 *
1529 * PARAMS
1530 * ssa [I] string analysis.
1531 * piDx [O] logical widths returned.
1532 *
1533 * RETURNS
1534 * Success: S_OK
1535 * Failure: a non-zero HRESULT.
1536 */
1537 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
1538 {
1539 int i, j, next = 0;
1540 StringAnalysis *analysis = ssa;
1541
1542 TRACE("%p, %p\n", ssa, piDx);
1543
1544 if (!analysis) return S_FALSE;
1545
1546 for (i = 0; i < analysis->numItems; i++)
1547 {
1548 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1549 {
1550 piDx[next] = analysis->glyphs[i].piAdvance[j];
1551 next++;
1552 }
1553 }
1554 return S_OK;
1555 }
1556
1557 /***********************************************************************
1558 * ScriptStringValidate (USP10.@)
1559 *
1560 * Validate a string analysis.
1561 *
1562 * PARAMS
1563 * ssa [I] string analysis.
1564 *
1565 * RETURNS
1566 * Success: S_OK
1567 * Failure: S_FALSE if invalid sequences are found
1568 * or a non-zero HRESULT if it fails.
1569 */
1570 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1571 {
1572 StringAnalysis *analysis = ssa;
1573
1574 TRACE("(%p)\n", ssa);
1575
1576 if (!analysis) return E_INVALIDARG;
1577 return (analysis->invalid) ? S_FALSE : S_OK;
1578 }
1579
1580 /***********************************************************************
1581 * ScriptString_pSize (USP10.@)
1582 *
1583 * Retrieve width and height of an analysed string.
1584 *
1585 * PARAMS
1586 * ssa [I] string analysis.
1587 *
1588 * RETURNS
1589 * Success: Pointer to a SIZE structure.
1590 * Failure: NULL
1591 */
1592 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
1593 {
1594 unsigned int i, j;
1595 StringAnalysis *analysis = ssa;
1596
1597 TRACE("(%p)\n", ssa);
1598
1599 if (!analysis) return NULL;
1600
1601 if (!analysis->sz)
1602 {
1603 if (!(analysis->sz = usp_alloc(sizeof(SIZE)))) return NULL;
1604 analysis->sz->cy = analysis->sc->height;
1605
1606 analysis->sz->cx = 0;
1607 for (i = 0; i < analysis->numItems; i++)
1608 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1609 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
1610 }
1611 return analysis->sz;
1612 }
1613
1614 /***********************************************************************
1615 * ScriptString_pLogAttr (USP10.@)
1616 *
1617 * Retrieve logical attributes of an analysed string.
1618 *
1619 * PARAMS
1620 * ssa [I] string analysis.
1621 *
1622 * RETURNS
1623 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1624 * Failure: NULL
1625 */
1626 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
1627 {
1628 StringAnalysis *analysis = ssa;
1629
1630 TRACE("(%p)\n", ssa);
1631
1632 if (!analysis) return NULL;
1633 return analysis->logattrs;
1634 }
1635
1636 /***********************************************************************
1637 * ScriptString_pcOutChars (USP10.@)
1638 *
1639 * Retrieve the length of a string after clipping.
1640 *
1641 * PARAMS
1642 * ssa [I] String analysis.
1643 *
1644 * RETURNS
1645 * Success: Pointer to the length.
1646 * Failure: NULL
1647 */
1648 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
1649 {
1650 StringAnalysis *analysis = ssa;
1651
1652 TRACE("(%p)\n", ssa);
1653
1654 if (!analysis) return NULL;
1655 return &analysis->clip_len;
1656 }
1657
1658 /***********************************************************************
1659 * ScriptStringGetOrder (USP10.@)
1660 *
1661 * Retrieve a glyph order map.
1662 *
1663 * PARAMS
1664 * ssa [I] String analysis.
1665 * order [I/O] Array of glyph positions.
1666 *
1667 * RETURNS
1668 * Success: S_OK
1669 * Failure: a non-zero HRESULT.
1670 */
1671 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
1672 {
1673 unsigned int i, j, k;
1674 StringAnalysis *analysis = ssa;
1675
1676 TRACE("(%p)\n", ssa);
1677
1678 if (!analysis) return S_FALSE;
1679
1680 /* FIXME: handle RTL scripts */
1681 for (i = 0, k = 0; i < analysis->numItems; i++)
1682 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
1683 order[k] = k;
1684
1685 return S_OK;
1686 }