ups10: Reimplement ScriptLayout to properly handle mixed runs.
[wine.git] / dlls / usp10 / usp10.c
blob4f8a08be29e615d3cb9dadf9a744d0a70ec5417e
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 "usp10.h"
36 #include "usp10_internal.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
43 static const SCRIPT_PROPERTIES props[] =
45 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
46 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
47 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
48 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
50 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
51 { 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
52 { 8, 0, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
53 { 25, 0, 0, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
54 { 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
55 { 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
56 { 42, 0, 0, 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
57 { 9, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
58 { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0 },
59 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
60 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
61 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
62 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
63 { 18, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
64 { 18, 0, 1, 0, 1, 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 { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
68 { 9, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
69 { 13, 0, 1, 0, 1, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
70 { 13, 0, 1, 0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
71 { 1, 0, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 1, 0 },
72 { 1, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
73 { 41, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
74 { 32, 1, 1, 0, 0, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
75 { 90, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0 },
76 { 30, 0, 1, 1, 1, 222, 0, 0, 1, 0, 1, 0, 0, 0, 1 },
77 { 30, 1, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
78 { 30, 0, 1, 0, 0, 222, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
79 { 57, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
80 { 57, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
81 { 73, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
82 { 73, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
83 { 69, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
84 { 69, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
85 { 69, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
86 { 70, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
87 { 70, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
88 { 71, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
89 { 71, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
90 { 72, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
91 { 72, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
92 { 74, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
93 { 74, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
94 { 75, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
95 { 75, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
96 { 76, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
97 { 76, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
98 { 81, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 },
99 { 81, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
100 { 84, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 },
101 { 84, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
102 { 83, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
103 { 83, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
104 { 85, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
105 { 85, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
106 { 80, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
107 { 80, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
108 { 94, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
109 { 94, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
110 { 101, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
111 { 93, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
112 { 92, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
113 { 9, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
114 { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
115 { 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
116 { 91, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
117 { 9, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 },
118 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
121 static const SCRIPT_PROPERTIES *script_props[] =
123 &props[0], &props[1], &props[2], &props[3],
124 &props[4], &props[5], &props[6], &props[7],
125 &props[8], &props[9], &props[11], &props[12],
126 &props[13], &props[14], &props[15], &props[16],
127 &props[17], &props[18], &props[19], &props[20],
128 &props[21], &props[22], &props[23], &props[24],
129 &props[25], &props[26], &props[27], &props[28],
130 &props[29], &props[30], &props[31], &props[32],
131 &props[33], &props[34], &props[35], &props[36],
132 &props[37], &props[38], &props[39], &props[40],
133 &props[41], &props[42], &props[43], &props[44],
134 &props[45], &props[46], &props[47], &props[48],
135 &props[49], &props[50], &props[51], &props[52],
136 &props[53], &props[54], &props[55], &props[56],
137 &props[57], &props[58], &props[59], &props[60],
138 &props[61], &props[62], &props[63], &props[64],
139 &props[65], &props[66], &props[67], &props[68],
140 &props[69], &props[70], &props[71], &props[72],
141 &props[73]
144 #define GLYPH_BLOCK_SHIFT 8
145 #define GLYPH_BLOCK_SIZE (1UL << GLYPH_BLOCK_SHIFT)
146 #define GLYPH_BLOCK_MASK (GLYPH_BLOCK_SIZE - 1)
147 #define GLYPH_MAX 65536
149 typedef struct {
150 LOGFONTW lf;
151 TEXTMETRICW tm;
152 WORD *glyphs[GLYPH_MAX / GLYPH_BLOCK_SIZE];
153 ABC *widths[GLYPH_MAX / GLYPH_BLOCK_SIZE];
154 } ScriptCache;
156 typedef struct {
157 int numGlyphs;
158 WORD* glyphs;
159 WORD* pwLogClust;
160 int* piAdvance;
161 SCRIPT_VISATTR* psva;
162 GOFFSET* pGoffset;
163 ABC* abc;
164 } StringGlyphs;
166 typedef struct {
167 HDC hdc;
168 BOOL invalid;
169 int clip_len;
170 ScriptCache *sc;
171 int cItems;
172 int cMaxGlyphs;
173 SCRIPT_ITEM* pItem;
174 int numItems;
175 StringGlyphs* glyphs;
176 SCRIPT_LOGATTR* logattrs;
177 SIZE* sz;
178 } StringAnalysis;
180 static inline void *heap_alloc(SIZE_T size)
182 return HeapAlloc(GetProcessHeap(), 0, size);
185 static inline void *heap_alloc_zero(SIZE_T size)
187 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
190 static inline void *heap_realloc_zero(LPVOID mem, SIZE_T size)
192 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size);
195 static inline BOOL heap_free(LPVOID mem)
197 return HeapFree(GetProcessHeap(), 0, mem);
200 static inline WCHAR get_cache_default_char(SCRIPT_CACHE *psc)
202 return ((ScriptCache *)*psc)->tm.tmDefaultChar;
205 static inline LONG get_cache_height(SCRIPT_CACHE *psc)
207 return ((ScriptCache *)*psc)->tm.tmHeight;
210 static inline BYTE get_cache_pitch_family(SCRIPT_CACHE *psc)
212 return ((ScriptCache *)*psc)->tm.tmPitchAndFamily;
215 static inline WORD get_cache_glyph(SCRIPT_CACHE *psc, WCHAR c)
217 WORD *block = ((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
219 if (!block) return 0;
220 return block[c & GLYPH_BLOCK_MASK];
223 static inline WORD set_cache_glyph(SCRIPT_CACHE *psc, WCHAR c, WORD glyph)
225 WORD **block = &((ScriptCache *)*psc)->glyphs[c >> GLYPH_BLOCK_SHIFT];
227 if (!*block && !(*block = heap_alloc_zero(sizeof(WORD) * GLYPH_BLOCK_SIZE))) return 0;
228 return ((*block)[c & GLYPH_BLOCK_MASK] = glyph);
231 static inline BOOL get_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
233 static const ABC nil;
234 ABC *block = ((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
236 if (!block || !memcmp(&block[glyph & GLYPH_BLOCK_MASK], &nil, sizeof(ABC))) return FALSE;
237 memcpy(abc, &block[glyph & GLYPH_BLOCK_MASK], sizeof(ABC));
238 return TRUE;
241 static inline BOOL set_cache_glyph_widths(SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
243 ABC **block = &((ScriptCache *)*psc)->widths[glyph >> GLYPH_BLOCK_SHIFT];
245 if (!*block && !(*block = heap_alloc_zero(sizeof(ABC) * GLYPH_BLOCK_SIZE))) return FALSE;
246 memcpy(&(*block)[glyph & GLYPH_BLOCK_MASK], abc, sizeof(ABC));
247 return TRUE;
250 static HRESULT init_script_cache(const HDC hdc, SCRIPT_CACHE *psc)
252 ScriptCache *sc;
254 if (!psc) return E_INVALIDARG;
255 if (*psc) return S_OK;
256 if (!hdc) return E_PENDING;
258 if (!(sc = heap_alloc_zero(sizeof(ScriptCache)))) return E_OUTOFMEMORY;
259 if (!GetTextMetricsW(hdc, &sc->tm))
261 heap_free(sc);
262 return E_INVALIDARG;
264 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(LOGFONTW), &sc->lf))
266 heap_free(sc);
267 return E_INVALIDARG;
269 *psc = sc;
270 TRACE("<- %p\n", sc);
271 return S_OK;
274 /***********************************************************************
275 * DllMain
278 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
280 switch(fdwReason)
282 case DLL_PROCESS_ATTACH:
283 DisableThreadLibraryCalls(hInstDLL);
284 break;
285 case DLL_PROCESS_DETACH:
286 break;
288 return TRUE;
291 /***********************************************************************
292 * ScriptFreeCache (USP10.@)
294 * Free a script cache.
296 * PARAMS
297 * psc [I/O] Script cache.
299 * RETURNS
300 * Success: S_OK
301 * Failure: Non-zero HRESULT value.
303 HRESULT WINAPI ScriptFreeCache(SCRIPT_CACHE *psc)
305 TRACE("%p\n", psc);
307 if (psc && *psc)
309 unsigned int i;
310 for (i = 0; i < GLYPH_MAX / GLYPH_BLOCK_SIZE; i++)
312 heap_free(((ScriptCache *)*psc)->glyphs[i]);
313 heap_free(((ScriptCache *)*psc)->widths[i]);
315 heap_free(*psc);
316 *psc = NULL;
318 return S_OK;
321 /***********************************************************************
322 * ScriptGetProperties (USP10.@)
324 * Retrieve a list of script properties.
326 * PARAMS
327 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
328 * num [I] Pointer to the number of scripts.
330 * RETURNS
331 * Success: S_OK
332 * Failure: Non-zero HRESULT value.
334 * NOTES
335 * Behaviour matches WinXP.
337 HRESULT WINAPI ScriptGetProperties(const SCRIPT_PROPERTIES ***props, int *num)
339 TRACE("(%p,%p)\n", props, num);
341 if (!props && !num) return E_INVALIDARG;
343 if (num) *num = sizeof(script_props)/sizeof(script_props[0]);
344 if (props) *props = script_props;
346 return S_OK;
349 /***********************************************************************
350 * ScriptGetFontProperties (USP10.@)
352 * Get information on special glyphs.
354 * PARAMS
355 * hdc [I] Device context.
356 * psc [I/O] Opaque pointer to a script cache.
357 * sfp [O] Font properties structure.
359 HRESULT WINAPI ScriptGetFontProperties(HDC hdc, SCRIPT_CACHE *psc, SCRIPT_FONTPROPERTIES *sfp)
361 HRESULT hr;
363 TRACE("%p,%p,%p\n", hdc, psc, sfp);
365 if (!sfp) return E_INVALIDARG;
366 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
368 if (sfp->cBytes != sizeof(SCRIPT_FONTPROPERTIES))
369 return E_INVALIDARG;
371 /* return something sensible? */
372 sfp->wgBlank = 0;
373 sfp->wgDefault = get_cache_default_char(psc);
374 sfp->wgInvalid = 0;
375 sfp->wgKashida = 0xffff;
376 sfp->iKashidaWidth = 0;
378 return S_OK;
381 /***********************************************************************
382 * ScriptRecordDigitSubstitution (USP10.@)
384 * Record digit substitution settings for a given locale.
386 * PARAMS
387 * locale [I] Locale identifier.
388 * sds [I] Structure to record substitution settings.
390 * RETURNS
391 * Success: S_OK
392 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
394 * SEE ALSO
395 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
397 HRESULT WINAPI ScriptRecordDigitSubstitution(LCID locale, SCRIPT_DIGITSUBSTITUTE *sds)
399 DWORD plgid, sub;
401 TRACE("0x%x, %p\n", locale, sds);
403 /* This implementation appears to be correct for all languages, but it's
404 * not clear if sds->DigitSubstitute is ever set to anything except
405 * CONTEXT or NONE in reality */
407 if (!sds) return E_POINTER;
409 locale = ConvertDefaultLocale(locale);
411 if (!IsValidLocale(locale, LCID_INSTALLED))
412 return E_INVALIDARG;
414 plgid = PRIMARYLANGID(LANGIDFROMLCID(locale));
415 sds->TraditionalDigitLanguage = plgid;
417 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
418 sds->NationalDigitLanguage = plgid;
419 else
420 sds->NationalDigitLanguage = LANG_ENGLISH;
422 if (!GetLocaleInfoW(locale, LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
423 (LPWSTR)&sub, sizeof(sub)/sizeof(WCHAR))) return E_INVALIDARG;
425 switch (sub)
427 case 0:
428 if (plgid == LANG_ARABIC || plgid == LANG_FARSI)
429 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_CONTEXT;
430 else
431 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
432 break;
433 case 1:
434 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NONE;
435 break;
436 case 2:
437 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_NATIONAL;
438 break;
439 default:
440 sds->DigitSubstitute = SCRIPT_DIGITSUBSTITUTE_TRADITIONAL;
441 break;
444 sds->dwReserved = 0;
445 return S_OK;
448 /***********************************************************************
449 * ScriptApplyDigitSubstitution (USP10.@)
451 * Apply digit substitution settings.
453 * PARAMS
454 * sds [I] Structure with recorded substitution settings.
455 * sc [I] Script control structure.
456 * ss [I] Script state structure.
458 * RETURNS
459 * Success: S_OK
460 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
462 HRESULT WINAPI ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE *sds,
463 SCRIPT_CONTROL *sc, SCRIPT_STATE *ss)
465 SCRIPT_DIGITSUBSTITUTE psds;
467 TRACE("%p, %p, %p\n", sds, sc, ss);
469 if (!sc || !ss) return E_POINTER;
470 if (!sds)
472 sds = &psds;
473 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT, &psds) != S_OK)
474 return E_INVALIDARG;
477 sc->uDefaultLanguage = LANG_ENGLISH;
478 sc->fContextDigits = 0;
479 ss->fDigitSubstitute = 0;
481 switch (sds->DigitSubstitute) {
482 case SCRIPT_DIGITSUBSTITUTE_CONTEXT:
483 case SCRIPT_DIGITSUBSTITUTE_NATIONAL:
484 case SCRIPT_DIGITSUBSTITUTE_NONE:
485 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL:
486 return S_OK;
487 default:
488 return E_INVALIDARG;
492 /***********************************************************************
493 * ScriptItemize (USP10.@)
495 * Split a Unicode string into shapeable parts.
497 * PARAMS
498 * pwcInChars [I] String to split.
499 * cInChars [I] Number of characters in pwcInChars.
500 * cMaxItems [I] Maximum number of items to return.
501 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
502 * psState [I] Pointer to a SCRIPT_STATE structure.
503 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
504 * pcItems [O] Number of script items returned.
506 * RETURNS
507 * Success: S_OK
508 * Failure: Non-zero HRESULT value.
510 HRESULT WINAPI ScriptItemize(const WCHAR *pwcInChars, int cInChars, int cMaxItems,
511 const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState,
512 SCRIPT_ITEM *pItems, int *pcItems)
515 #define Numeric_start 0x0030
516 #define Numeric_stop 0x0039
517 #define Numeric_space 0x0020
518 #define Arabic_start 0x0600
519 #define Arabic_stop 0x06ff
520 #define Latin_start 0x0001
521 #define Latin_stop 0x024f
522 #define Script_Arabic 6
523 #define Script_Latin 1
524 #define Script_Numeric 5
525 #define Script_CR 22
526 #define Script_LF 23
528 int cnt = 0, index = 0;
529 int New_Script = SCRIPT_UNDEFINED;
530 WORD *levels = NULL;
532 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
533 psControl, psState, pItems, pcItems);
535 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
536 return E_INVALIDARG;
538 if (psState && psControl)
540 int i;
541 levels = heap_alloc_zero(cInChars * sizeof(WORD));
542 if (!levels)
543 return E_OUTOFMEMORY;
545 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
546 for (i = 0; i < cInChars; i++)
547 if (levels[i]!=levels[0])
548 break;
549 if (i >= cInChars)
551 heap_free(levels);
552 levels = NULL;
556 pItems[index].iCharPos = 0;
557 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
559 if (pwcInChars[cnt] == '\r')
560 pItems[index].a.eScript = Script_CR;
561 else
562 if (pwcInChars[cnt] == '\n')
563 pItems[index].a.eScript = Script_LF;
564 else
565 if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
566 pItems[index].a.eScript = Script_Numeric;
567 else
568 if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
569 pItems[index].a.eScript = Script_Arabic;
570 else
571 if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
572 pItems[index].a.eScript = Script_Latin;
574 if (levels)
576 pItems[index].a.fRTL = odd(levels[cnt]);
577 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
578 pItems[index].a.s.uBidiLevel = levels[cnt];
580 else if (pItems[index].a.eScript == Script_Arabic)
582 pItems[index].a.s.uBidiLevel = 1;
583 pItems[index].a.fRTL = 1;
584 pItems[index].a.fLayoutRTL = 1;
588 TRACE("New_Level=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
589 levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript, index, cnt,
590 pItems[index].iCharPos);
592 for (cnt=1; cnt < cInChars; cnt++)
594 if (levels && (levels[cnt] == pItems[index].a.s.uBidiLevel))
595 continue;
597 if (pwcInChars[cnt] == '\r')
598 New_Script = Script_CR;
599 else
600 if (pwcInChars[cnt] == '\n')
601 New_Script = Script_LF;
602 else
603 if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
604 || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space))
605 New_Script = Script_Numeric;
606 else
607 if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
608 || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space))
609 New_Script = Script_Arabic;
610 else
611 if ((pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
612 || (New_Script == Script_Latin && pwcInChars[cnt] == Numeric_space))
613 New_Script = Script_Latin;
614 else
615 New_Script = SCRIPT_UNDEFINED;
617 if ((levels && (levels[cnt] != pItems[index].a.s.uBidiLevel)) || New_Script != pItems[index].a.eScript)
619 TRACE("New_Level = %i, New_Script=%d, eScript=%d ", levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript);
620 index++;
621 if (index+1 > cMaxItems)
622 return E_OUTOFMEMORY;
624 pItems[index].iCharPos = cnt;
625 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
627 if (levels)
629 pItems[index].a.fRTL = odd(levels[cnt]);
630 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
631 pItems[index].a.s.uBidiLevel = levels[cnt];
633 else if (New_Script == Script_Arabic)
635 pItems[index].a.s.uBidiLevel = 1;
636 pItems[index].a.fRTL = 1;
637 pItems[index].a.fLayoutRTL = 1;
639 pItems[index].a.eScript = New_Script;
641 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
645 /* While not strictly necessary according to the spec, make sure the n+1
646 * item is set up to prevent random behaviour if the caller erroneously
647 * checks the n+1 structure */
648 memset(&pItems[index+1].a, 0, sizeof(SCRIPT_ANALYSIS));
650 TRACE("index=%d cnt=%d iCharPos=%d\n", index+1, cnt, pItems[index+1].iCharPos);
652 /* Set one SCRIPT_STATE item being returned */
653 if (pcItems) *pcItems = index + 1;
655 /* Set SCRIPT_ITEM */
656 pItems[index+1].iCharPos = cnt; /* the last + 1 item
657 contains the ptr to the lastchar */
658 heap_free(levels);
659 return S_OK;
662 /***********************************************************************
663 * ScriptStringAnalyse (USP10.@)
666 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
667 int cGlyphs, int iCharset, DWORD dwFlags,
668 int iReqWidth, SCRIPT_CONTROL *psControl,
669 SCRIPT_STATE *psState, const int *piDx,
670 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
671 SCRIPT_STRING_ANALYSIS *pssa)
673 HRESULT hr = E_OUTOFMEMORY;
674 StringAnalysis *analysis = NULL;
675 int i, num_items = 255;
677 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
678 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
679 psControl, psState, piDx, pTabdef, pbInClass, pssa);
681 if (iCharset != -1)
683 FIXME("Only Unicode strings are supported\n");
684 return E_INVALIDARG;
686 if (cString < 1 || !pString) return E_INVALIDARG;
687 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
689 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
690 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
692 /* FIXME: handle clipping */
693 analysis->clip_len = cString;
694 analysis->hdc = hdc;
696 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
697 &analysis->numItems);
699 while (hr == E_OUTOFMEMORY)
701 SCRIPT_ITEM *tmp;
703 num_items *= 2;
704 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
705 goto error;
707 analysis->pItem = tmp;
708 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
709 &analysis->numItems);
711 if (hr != S_OK) goto error;
713 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
714 ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs);
715 else
716 goto error;
718 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
719 goto error;
721 for (i = 0; i < analysis->numItems; i++)
723 SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc;
724 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
725 int numGlyphs = 1.5 * cChar + 16;
726 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
727 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
728 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
729 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * cChar);
730 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
731 ABC *abc = heap_alloc_zero(sizeof(ABC));
732 int numGlyphsReturned;
734 /* FIXME: non unicode strings */
735 const WCHAR* pStr = (const WCHAR*)pString;
736 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
737 cChar, numGlyphs, &analysis->pItem[i].a,
738 glyphs, pwLogClust, psva, &numGlyphsReturned);
739 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
740 piAdvance, pGoffset, abc);
742 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
743 analysis->glyphs[i].glyphs = glyphs;
744 analysis->glyphs[i].pwLogClust = pwLogClust;
745 analysis->glyphs[i].piAdvance = piAdvance;
746 analysis->glyphs[i].psva = psva;
747 analysis->glyphs[i].pGoffset = pGoffset;
748 analysis->glyphs[i].abc = abc;
751 *pssa = analysis;
752 return S_OK;
754 error:
755 heap_free(analysis->glyphs);
756 heap_free(analysis->logattrs);
757 heap_free(analysis->pItem);
758 heap_free(analysis->sc);
759 heap_free(analysis);
760 return hr;
763 /***********************************************************************
764 * ScriptStringOut (USP10.@)
766 * This function takes the output of ScriptStringAnalyse and joins the segments
767 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
768 * only processes glyphs.
770 * Parameters:
771 * ssa [I] buffer to hold the analysed string components
772 * iX [I] X axis displacement for output
773 * iY [I] Y axis displacement for output
774 * uOptions [I] flags controling output processing
775 * prc [I] rectangle coordinates
776 * iMinSel [I] starting pos for substringing output string
777 * iMaxSel [I] ending pos for substringing output string
778 * fDisabled [I] controls text highlighting
780 * RETURNS
781 * Success: S_OK
782 * Failure: is the value returned by ScriptTextOut
784 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
785 int iX,
786 int iY,
787 UINT uOptions,
788 const RECT *prc,
789 int iMinSel,
790 int iMaxSel,
791 BOOL fDisabled)
793 StringAnalysis *analysis;
794 WORD *glyphs;
795 int item, cnt, x;
796 HRESULT hr;
798 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
799 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
801 if (!(analysis = ssa)) return E_INVALIDARG;
804 * Get storage for the output buffer for the consolidated strings
806 cnt = 0;
807 for (item = 0; item < analysis->numItems; item++)
809 cnt += analysis->glyphs[item].numGlyphs;
811 if (!(glyphs = heap_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY;
814 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
816 uOptions |= ETO_GLYPH_INDEX;
817 analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */
820 * Copy the string items into the output buffer
823 TRACE("numItems %d\n", analysis->numItems);
825 cnt = 0;
826 for (item = 0; item < analysis->numItems; item++)
828 memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs,
829 sizeof(WCHAR) * analysis->glyphs[item].numGlyphs);
831 TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs);
832 for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++)
833 TRACE("%04x", glyphs[x]);
834 TRACE("\n");
836 cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */
839 hr = ScriptTextOut(analysis->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY,
840 uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt,
841 analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset);
842 TRACE("ScriptTextOut hr=%08x\n", hr);
845 * Free the output buffer and script cache
847 heap_free(glyphs);
848 return hr;
851 /***********************************************************************
852 * ScriptStringCPtoX (USP10.@)
855 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
857 int i, j;
858 int runningX = 0;
859 int runningCp = 0;
860 StringAnalysis* analysis = ssa;
862 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
864 if (!ssa || !pX) return S_FALSE;
866 /* icp out of range */
867 if(icp < 0)
869 analysis->invalid = TRUE;
870 return E_INVALIDARG;
873 for(i=0; i<analysis->numItems; i++)
875 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
877 if(runningCp == icp && fTrailing == FALSE)
879 *pX = runningX;
880 return S_OK;
882 runningX += analysis->glyphs[i].piAdvance[j];
883 if(runningCp == icp && fTrailing == TRUE)
885 *pX = runningX;
886 return S_OK;
888 runningCp++;
892 /* icp out of range */
893 analysis->invalid = TRUE;
894 return E_INVALIDARG;
897 /***********************************************************************
898 * ScriptStringXtoCP (USP10.@)
901 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
903 StringAnalysis* analysis = ssa;
904 int i;
905 int j;
906 int runningX = 0;
907 int runningCp = 0;
908 int width;
910 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
912 if (!ssa || !piCh || !piTrailing) return S_FALSE;
914 /* out of range */
915 if(iX < 0)
917 *piCh = -1;
918 *piTrailing = TRUE;
919 return S_OK;
922 for(i=0; i<analysis->numItems; i++)
924 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
926 width = analysis->glyphs[i].piAdvance[j];
927 if(iX < (runningX + width))
929 *piCh = runningCp;
930 if((iX - runningX) > width/2)
931 *piTrailing = TRUE;
932 else
933 *piTrailing = FALSE;
934 return S_OK;
936 runningX += width;
937 runningCp++;
941 /* out of range */
942 *piCh = analysis->pItem[analysis->numItems].iCharPos;
943 *piTrailing = FALSE;
945 return S_OK;
949 /***********************************************************************
950 * ScriptStringFree (USP10.@)
952 * Free a string analysis.
954 * PARAMS
955 * pssa [I] string analysis.
957 * RETURNS
958 * Success: S_OK
959 * Failure: Non-zero HRESULT value.
961 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
963 StringAnalysis* analysis;
964 BOOL invalid;
965 int i;
967 TRACE("(%p)\n", pssa);
969 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
971 invalid = analysis->invalid;
972 ScriptFreeCache((SCRIPT_CACHE *)&analysis->sc);
974 for (i = 0; i < analysis->numItems; i++)
976 heap_free(analysis->glyphs[i].glyphs);
977 heap_free(analysis->glyphs[i].pwLogClust);
978 heap_free(analysis->glyphs[i].piAdvance);
979 heap_free(analysis->glyphs[i].psva);
980 heap_free(analysis->glyphs[i].pGoffset);
981 heap_free(analysis->glyphs[i].abc);
984 heap_free(analysis->glyphs);
985 heap_free(analysis->pItem);
986 heap_free(analysis->logattrs);
987 heap_free(analysis->sz);
988 heap_free(analysis->sc);
989 heap_free(analysis);
991 if (invalid) return E_INVALIDARG;
992 return S_OK;
995 /***********************************************************************
996 * ScriptCPtoX (USP10.@)
999 HRESULT WINAPI ScriptCPtoX(int iCP,
1000 BOOL fTrailing,
1001 int cChars,
1002 int cGlyphs,
1003 const WORD *pwLogClust,
1004 const SCRIPT_VISATTR *psva,
1005 const int *piAdvance,
1006 const SCRIPT_ANALYSIS *psa,
1007 int *piX)
1009 int item;
1010 int iPosX;
1011 float fMaxPosX = 0;
1012 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1013 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1014 psa, piX);
1015 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1016 fMaxPosX += piAdvance[item];
1017 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
1018 if (iPosX > fMaxPosX)
1019 iPosX = fMaxPosX;
1020 *piX = iPosX; /* Return something in range */
1022 TRACE("*piX=%d\n", *piX);
1023 return S_OK;
1026 /***********************************************************************
1027 * ScriptXtoCP (USP10.@)
1030 HRESULT WINAPI ScriptXtoCP(int iX,
1031 int cChars,
1032 int cGlyphs,
1033 const WORD *pwLogClust,
1034 const SCRIPT_VISATTR *psva,
1035 const int *piAdvance,
1036 const SCRIPT_ANALYSIS *psa,
1037 int *piCP,
1038 int *piTrailing)
1040 int item;
1041 int iPosX;
1042 float fMaxPosX = 1;
1043 float fAvePosX;
1044 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1045 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1046 psa, piCP, piTrailing);
1047 if (iX < 0) /* iX is before start of run */
1049 *piCP = -1;
1050 *piTrailing = TRUE;
1051 return S_OK;
1054 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1055 fMaxPosX += piAdvance[item];
1057 if (iX >= fMaxPosX) /* iX too large */
1059 *piCP = cChars;
1060 *piTrailing = FALSE;
1061 return S_OK;
1064 fAvePosX = fMaxPosX / cGlyphs;
1065 iPosX = fAvePosX;
1066 for (item = 1; item < cGlyphs && iPosX < iX; item++)
1067 iPosX += fAvePosX;
1068 if (iPosX - iX > fAvePosX/2)
1069 *piTrailing = 0;
1070 else
1071 *piTrailing = 1; /* yep we are over halfway */
1073 *piCP = item -1; /* Return character position */
1074 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
1075 return S_OK;
1078 /***********************************************************************
1079 * ScriptBreak (USP10.@)
1081 * Retrieve line break information.
1083 * PARAMS
1084 * chars [I] Array of characters.
1085 * sa [I] String analysis.
1086 * la [I] Array of logical attribute structures.
1088 * RETURNS
1089 * Success: S_OK
1090 * Failure: S_FALSE
1092 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
1094 int i;
1096 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
1098 if (!la) return S_FALSE;
1100 for (i = 0; i < count; i++)
1102 memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
1104 /* FIXME: set the other flags */
1105 la[i].fWhiteSpace = (chars[i] == ' ');
1106 la[i].fCharStop = 1;
1108 if (i > 0 && la[i - 1].fWhiteSpace)
1110 la[i].fSoftBreak = 1;
1111 la[i].fWordStop = 1;
1114 return S_OK;
1117 static const struct
1119 WCHAR start;
1120 WCHAR end;
1121 DWORD flag;
1123 complex_ranges[] =
1125 { 0, 0x0b, SIC_COMPLEX },
1126 { 0x0c, 0x0c, SIC_NEUTRAL },
1127 { 0x0d, 0x1f, SIC_COMPLEX },
1128 { 0x20, 0x2f, SIC_NEUTRAL },
1129 { 0x30, 0x39, SIC_ASCIIDIGIT },
1130 { 0x3a, 0x40, SIC_NEUTRAL },
1131 { 0x5b, 0x60, SIC_NEUTRAL },
1132 { 0x7b, 0x7e, SIC_NEUTRAL },
1133 { 0x7f, 0x9f, SIC_COMPLEX },
1134 { 0xa0, 0xa5, SIC_NEUTRAL },
1135 { 0xa7, 0xa8, SIC_NEUTRAL },
1136 { 0xab, 0xab, SIC_NEUTRAL },
1137 { 0xad, 0xad, SIC_NEUTRAL },
1138 { 0xaf, 0xaf, SIC_NEUTRAL },
1139 { 0xb0, 0xb1, SIC_NEUTRAL },
1140 { 0xb4, 0xb4, SIC_NEUTRAL },
1141 { 0xb6, 0xb8, SIC_NEUTRAL },
1142 { 0xbb, 0xbf, SIC_NEUTRAL },
1143 { 0xd7, 0xd7, SIC_NEUTRAL },
1144 { 0xf7, 0xf7, SIC_NEUTRAL },
1145 { 0x2b9, 0x2ba, SIC_NEUTRAL },
1146 { 0x2c2, 0x2cf, SIC_NEUTRAL },
1147 { 0x2d2, 0x2df, SIC_NEUTRAL },
1148 { 0x2e5, 0x2e9, SIC_COMPLEX },
1149 { 0x2ea, 0x2ed, SIC_NEUTRAL },
1150 { 0x300, 0x362, SIC_COMPLEX },
1151 { 0x530, 0x60b, SIC_COMPLEX },
1152 { 0x60c, 0x60d, SIC_NEUTRAL },
1153 { 0x60e, 0x669, SIC_COMPLEX },
1154 { 0x66a, 0x66a, SIC_NEUTRAL },
1155 { 0x66b, 0x6e8, SIC_COMPLEX },
1156 { 0x6e9, 0x6e9, SIC_NEUTRAL },
1157 { 0x6ea, 0x7bf, SIC_COMPLEX },
1158 { 0x900, 0x1360, SIC_COMPLEX },
1159 { 0x137d, 0x137f, SIC_COMPLEX },
1160 { 0x1680, 0x1680, SIC_NEUTRAL },
1161 { 0x1780, 0x18af, SIC_COMPLEX },
1162 { 0x2000, 0x200a, SIC_NEUTRAL },
1163 { 0x200b, 0x200f, SIC_COMPLEX },
1164 { 0x2010, 0x2016, SIC_NEUTRAL },
1165 { 0x2018, 0x2022, SIC_NEUTRAL },
1166 { 0x2024, 0x2028, SIC_NEUTRAL },
1167 { 0x2029, 0x202e, SIC_COMPLEX },
1168 { 0x202f, 0x2037, SIC_NEUTRAL },
1169 { 0x2039, 0x203c, SIC_NEUTRAL },
1170 { 0x2044, 0x2046, SIC_NEUTRAL },
1171 { 0x206a, 0x206f, SIC_COMPLEX },
1172 { 0x207a, 0x207e, SIC_NEUTRAL },
1173 { 0x208a, 0x20aa, SIC_NEUTRAL },
1174 { 0x20ac, 0x20cf, SIC_NEUTRAL },
1175 { 0x20d0, 0x20ff, SIC_COMPLEX },
1176 { 0x2103, 0x2103, SIC_NEUTRAL },
1177 { 0x2105, 0x2105, SIC_NEUTRAL },
1178 { 0x2109, 0x2109, SIC_NEUTRAL },
1179 { 0x2116, 0x2116, SIC_NEUTRAL },
1180 { 0x2121, 0x2122, SIC_NEUTRAL },
1181 { 0x212e, 0x212e, SIC_NEUTRAL },
1182 { 0x2153, 0x2154, SIC_NEUTRAL },
1183 { 0x215b, 0x215e, SIC_NEUTRAL },
1184 { 0x2190, 0x2199, SIC_NEUTRAL },
1185 { 0x21b8, 0x21b9, SIC_NEUTRAL },
1186 { 0x21d2, 0x21d2, SIC_NEUTRAL },
1187 { 0x21d4, 0x21d4, SIC_NEUTRAL },
1188 { 0x21e7, 0x21e7, SIC_NEUTRAL },
1189 { 0x2200, 0x2200, SIC_NEUTRAL },
1190 { 0x2202, 0x2203, SIC_NEUTRAL },
1191 { 0x2207, 0x2208, SIC_NEUTRAL },
1192 { 0x220b, 0x220b, SIC_NEUTRAL },
1193 { 0x220f, 0x220f, SIC_NEUTRAL },
1194 { 0x2211, 0x2213, SIC_NEUTRAL },
1195 { 0x2215, 0x2215, SIC_NEUTRAL },
1196 { 0x221a, 0x221a, SIC_NEUTRAL },
1197 { 0x221d, 0x2220, SIC_NEUTRAL },
1198 { 0x2223, 0x2223, SIC_NEUTRAL },
1199 { 0x2225, 0x2225, SIC_NEUTRAL },
1200 { 0x2227, 0x222c, SIC_NEUTRAL },
1201 { 0x222e, 0x222e, SIC_NEUTRAL },
1202 { 0x2234, 0x2237, SIC_NEUTRAL },
1203 { 0x223c, 0x223d, SIC_NEUTRAL },
1204 { 0x2248, 0x2248, SIC_NEUTRAL },
1205 { 0x224c, 0x224c, SIC_NEUTRAL },
1206 { 0x2252, 0x2252, SIC_NEUTRAL },
1207 { 0x2260, 0x2261, SIC_NEUTRAL },
1208 { 0x2264, 0x2267, SIC_NEUTRAL },
1209 { 0x226a, 0x226b, SIC_NEUTRAL },
1210 { 0x226e, 0x226f, SIC_NEUTRAL },
1211 { 0x2282, 0x2283, SIC_NEUTRAL },
1212 { 0x2286, 0x2287, SIC_NEUTRAL },
1213 { 0x2295, 0x2295, SIC_NEUTRAL },
1214 { 0x2299, 0x2299, SIC_NEUTRAL },
1215 { 0x22a5, 0x22a5, SIC_NEUTRAL },
1216 { 0x22bf, 0x22bf, SIC_NEUTRAL },
1217 { 0x2312, 0x2312, SIC_NEUTRAL },
1218 { 0x24ea, 0x24ea, SIC_COMPLEX },
1219 { 0x2500, 0x254b, SIC_NEUTRAL },
1220 { 0x2550, 0x256d, SIC_NEUTRAL },
1221 { 0x256e, 0x2574, SIC_NEUTRAL },
1222 { 0x2581, 0x258f, SIC_NEUTRAL },
1223 { 0x2592, 0x2595, SIC_NEUTRAL },
1224 { 0x25a0, 0x25a1, SIC_NEUTRAL },
1225 { 0x25a3, 0x25a9, SIC_NEUTRAL },
1226 { 0x25b2, 0x25b3, SIC_NEUTRAL },
1227 { 0x25b6, 0x25b7, SIC_NEUTRAL },
1228 { 0x25bc, 0x25bd, SIC_NEUTRAL },
1229 { 0x25c0, 0x25c1, SIC_NEUTRAL },
1230 { 0x25c6, 0x25c8, SIC_NEUTRAL },
1231 { 0x25cb, 0x25cb, SIC_NEUTRAL },
1232 { 0x25ce, 0x25d1, SIC_NEUTRAL },
1233 { 0x25e2, 0x25e5, SIC_NEUTRAL },
1234 { 0x25ef, 0x25ef, SIC_NEUTRAL },
1235 { 0x2605, 0x2606, SIC_NEUTRAL },
1236 { 0x2609, 0x2609, SIC_NEUTRAL },
1237 { 0x260e, 0x260f, SIC_NEUTRAL },
1238 { 0x261c, 0x261c, SIC_NEUTRAL },
1239 { 0x261e, 0x261e, SIC_NEUTRAL },
1240 { 0x2640, 0x2640, SIC_NEUTRAL },
1241 { 0x2642, 0x2642, SIC_NEUTRAL },
1242 { 0x2660, 0x2661, SIC_NEUTRAL },
1243 { 0x2663, 0x2665, SIC_NEUTRAL },
1244 { 0x2667, 0x266a, SIC_NEUTRAL },
1245 { 0x266c, 0x266d, SIC_NEUTRAL },
1246 { 0x266f, 0x266f, SIC_NEUTRAL },
1247 { 0x273d, 0x273d, SIC_NEUTRAL },
1248 { 0x2e80, 0x312f, SIC_COMPLEX },
1249 { 0x3190, 0x31bf, SIC_COMPLEX },
1250 { 0x31f0, 0x31ff, SIC_COMPLEX },
1251 { 0x3220, 0x325f, SIC_COMPLEX },
1252 { 0x3280, 0xa4ff, SIC_COMPLEX },
1253 { 0xd800, 0xdfff, SIC_COMPLEX },
1254 { 0xe000, 0xf8ff, SIC_NEUTRAL },
1255 { 0xf900, 0xfaff, SIC_COMPLEX },
1256 { 0xfb13, 0xfb28, SIC_COMPLEX },
1257 { 0xfb29, 0xfb29, SIC_NEUTRAL },
1258 { 0xfb2a, 0xfb4f, SIC_COMPLEX },
1259 { 0xfd3e, 0xfd3f, SIC_NEUTRAL },
1260 { 0xfdd0, 0xfdef, SIC_COMPLEX },
1261 { 0xfe20, 0xfe6f, SIC_COMPLEX },
1262 { 0xfeff, 0xfeff, SIC_COMPLEX },
1263 { 0xff01, 0xff5e, SIC_COMPLEX },
1264 { 0xff61, 0xff9f, SIC_COMPLEX },
1265 { 0xffe0, 0xffe6, SIC_COMPLEX },
1266 { 0xffe8, 0xffee, SIC_COMPLEX },
1267 { 0xfff9, 0xfffb, SIC_COMPLEX },
1268 { 0xfffe, 0xfffe, SIC_COMPLEX }
1271 /***********************************************************************
1272 * ScriptIsComplex (USP10.@)
1274 * Determine if a string is complex.
1276 * PARAMS
1277 * chars [I] Array of characters to test.
1278 * len [I] Length in characters.
1279 * flag [I] Flag.
1281 * RETURNS
1282 * Success: S_OK
1283 * Failure: S_FALSE
1285 * NOTES
1286 * Behaviour matches that of WinXP.
1288 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
1290 int i;
1291 unsigned int j;
1293 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
1295 for (i = 0; i < len; i++)
1297 for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
1299 if (chars[i] >= complex_ranges[j].start &&
1300 chars[i] <= complex_ranges[j].end &&
1301 (flag & complex_ranges[j].flag)) return S_OK;
1304 return S_FALSE;
1307 /***********************************************************************
1308 * ScriptShape (USP10.@)
1310 * Produce glyphs and visual attributes for a run.
1312 * PARAMS
1313 * hdc [I] Device context.
1314 * psc [I/O] Opaque pointer to a script cache.
1315 * pwcChars [I] Array of characters specifying the run.
1316 * cChars [I] Number of characters in pwcChars.
1317 * cMaxGlyphs [I] Length of pwOutGlyphs.
1318 * psa [I/O] Script analysis.
1319 * pwOutGlyphs [O] Array of glyphs.
1320 * pwLogClust [O] Array of logical cluster info.
1321 * psva [O] Array of visual attributes.
1322 * pcGlyphs [O] Number of glyphs returned.
1324 * RETURNS
1325 * Success: S_OK
1326 * Failure: Non-zero HRESULT value.
1328 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
1329 int cChars, int cMaxGlyphs,
1330 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
1331 SCRIPT_VISATTR *psva, int *pcGlyphs)
1333 HRESULT hr;
1334 unsigned int i;
1336 TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc, psc, debugstr_wn(pwcChars, cChars),
1337 cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs);
1339 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
1340 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
1342 if (!psva || !pcGlyphs) return E_INVALIDARG;
1343 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
1345 *pcGlyphs = cChars;
1346 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1347 if (!pwLogClust) return E_FAIL;
1349 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1351 for (i = 0; i < cChars; i++)
1353 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcChars[i])))
1355 WORD glyph;
1356 if (!hdc) return E_PENDING;
1357 if (GetGlyphIndicesW(hdc, &pwcChars[i], 1, &glyph, 0) == GDI_ERROR) return S_FALSE;
1358 pwOutGlyphs[i] = set_cache_glyph(psc, pwcChars[i], glyph);
1362 else
1364 TRACE("no glyph translation\n");
1365 for (i = 0; i < cChars; i++) pwOutGlyphs[i] = pwcChars[i];
1368 /* set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1369 for (i = 0; i < cChars; i++)
1371 /* FIXME: set to better values */
1372 psva[i].uJustification = (pwcChars[i] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
1373 psva[i].fClusterStart = 1;
1374 psva[i].fDiacritic = 0;
1375 psva[i].fZeroWidth = 0;
1376 psva[i].fReserved = 0;
1377 psva[i].fShapeReserved = 0;
1379 pwLogClust[i] = i;
1381 return S_OK;
1384 /***********************************************************************
1385 * ScriptPlace (USP10.@)
1387 * Produce advance widths for a run.
1389 * PARAMS
1390 * hdc [I] Device context.
1391 * psc [I/O] Opaque pointer to a script cache.
1392 * pwGlyphs [I] Array of glyphs.
1393 * cGlyphs [I] Number of glyphs in pwGlyphs.
1394 * psva [I] Array of visual attributes.
1395 * psa [I/O] String analysis.
1396 * piAdvance [O] Array of advance widths.
1397 * pGoffset [O] Glyph offsets.
1398 * pABC [O] Combined ABC width.
1400 * RETURNS
1401 * Success: S_OK
1402 * Failure: Non-zero HRESULT value.
1404 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
1405 int cGlyphs, const SCRIPT_VISATTR *psva,
1406 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1408 HRESULT hr;
1409 int i;
1411 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
1412 piAdvance, pGoffset, pABC);
1414 if (!psva) return E_INVALIDARG;
1415 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1416 if (!pGoffset) return E_FAIL;
1418 if (pABC) memset(pABC, 0, sizeof(ABC));
1419 for (i = 0; i < cGlyphs; i++)
1421 ABC abc;
1422 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
1424 if (!hdc) return E_PENDING;
1425 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1427 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
1429 else
1431 INT width;
1432 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
1433 abc.abcB = width;
1434 abc.abcA = abc.abcC = 0;
1436 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
1438 if (pABC)
1440 pABC->abcA += abc.abcA;
1441 pABC->abcB += abc.abcB;
1442 pABC->abcC += abc.abcC;
1444 /* FIXME: set to more reasonable values */
1445 pGoffset[i].du = pGoffset[i].dv = 0;
1446 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
1449 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1450 return S_OK;
1453 /***********************************************************************
1454 * ScriptGetCMap (USP10.@)
1456 * Retrieve glyph indices.
1458 * PARAMS
1459 * hdc [I] Device context.
1460 * psc [I/O] Opaque pointer to a script cache.
1461 * pwcInChars [I] Array of Unicode characters.
1462 * cChars [I] Number of characters in pwcInChars.
1463 * dwFlags [I] Flags.
1464 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1466 * RETURNS
1467 * Success: S_OK
1468 * Failure: Non-zero HRESULT value.
1470 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1471 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1473 HRESULT hr;
1474 int i;
1476 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
1477 cChars, dwFlags, pwOutGlyphs);
1479 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1481 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1483 for (i = 0; i < cChars; i++)
1485 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcInChars[i])))
1487 WORD glyph;
1488 if (!hdc) return E_PENDING;
1489 if (GetGlyphIndicesW(hdc, &pwcInChars[i], 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
1490 pwOutGlyphs[i] = set_cache_glyph(psc, pwcInChars[i], glyph);
1494 else
1496 TRACE("no glyph translation\n");
1497 for (i = 0; i < cChars; i++) pwOutGlyphs[i] = pwcInChars[i];
1499 return S_OK;
1502 /***********************************************************************
1503 * ScriptTextOut (USP10.@)
1506 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1507 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1508 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1509 const int *piJustify, const GOFFSET *pGoffset)
1511 HRESULT hr = S_OK;
1513 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1514 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1515 piAdvance, piJustify, pGoffset);
1517 if (!hdc || !psc) return E_INVALIDARG;
1518 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
1520 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1521 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1522 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1524 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
1525 hr = S_FALSE;
1527 return hr;
1530 /***********************************************************************
1531 * ScriptCacheGetHeight (USP10.@)
1533 * Retrieve the height of the font in the cache.
1535 * PARAMS
1536 * hdc [I] Device context.
1537 * psc [I/O] Opaque pointer to a script cache.
1538 * height [O] Receives font height.
1540 * RETURNS
1541 * Success: S_OK
1542 * Failure: Non-zero HRESULT value.
1544 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
1546 HRESULT hr;
1548 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1550 if (!height) return E_INVALIDARG;
1551 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1553 *height = get_cache_height(psc);
1554 return S_OK;
1557 /***********************************************************************
1558 * ScriptGetGlyphABCWidth (USP10.@)
1560 * Retrieve the width of a glyph.
1562 * PARAMS
1563 * hdc [I] Device context.
1564 * psc [I/O] Opaque pointer to a script cache.
1565 * glyph [I] Glyph to retrieve the width for.
1566 * abc [O] ABC widths of the glyph.
1568 * RETURNS
1569 * Success: S_OK
1570 * Failure: Non-zero HRESULT value.
1572 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1574 HRESULT hr;
1576 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1578 if (!abc) return E_INVALIDARG;
1579 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1581 if (!get_cache_glyph_widths(psc, glyph, abc))
1583 if (!hdc) return E_PENDING;
1584 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1586 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
1588 else
1590 INT width;
1591 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
1592 abc->abcB = width;
1593 abc->abcA = abc->abcC = 0;
1595 set_cache_glyph_widths(psc, glyph, abc);
1597 return S_OK;
1600 /***********************************************************************
1601 * ScriptLayout (USP10.@)
1603 * Map embedding levels to visual and/or logical order.
1605 * PARAMS
1606 * runs [I] Size of level array.
1607 * level [I] Array of embedding levels.
1608 * vistolog [O] Map of embedding levels from visual to logical order.
1609 * logtovis [O] Map of embedding levels from logical to visual order.
1611 * RETURNS
1612 * Success: S_OK
1613 * Failure: Non-zero HRESULT value.
1615 * BUGS
1616 * This stub works correctly for any sequence of a single
1617 * embedding level but not for sequences of different
1618 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1620 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1622 int* indexs;
1623 int ich;
1625 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
1627 if (!level || (!vistolog && !logtovis))
1628 return E_INVALIDARG;
1630 indexs = heap_alloc(sizeof(int) * runs);
1631 if (!indexs)
1632 return E_OUTOFMEMORY;
1635 if (vistolog)
1637 for( ich = 0; ich < runs; ich++)
1638 indexs[ich] = ich;
1640 ich = 0;
1641 while (ich < runs)
1642 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1643 for (ich = 0; ich < runs; ich++)
1644 vistolog[ich] = indexs[ich];
1648 if (logtovis)
1650 for( ich = 0; ich < runs; ich++)
1651 indexs[ich] = ich;
1653 ich = 0;
1654 while (ich < runs)
1655 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1656 for (ich = 0; ich < runs; ich++)
1657 logtovis[ich] = indexs[ich];
1659 heap_free(indexs);
1661 return S_OK;
1664 /***********************************************************************
1665 * ScriptStringGetLogicalWidths (USP10.@)
1667 * Returns logical widths from a string analysis.
1669 * PARAMS
1670 * ssa [I] string analysis.
1671 * piDx [O] logical widths returned.
1673 * RETURNS
1674 * Success: S_OK
1675 * Failure: a non-zero HRESULT.
1677 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
1679 int i, j, next = 0;
1680 StringAnalysis *analysis = ssa;
1682 TRACE("%p, %p\n", ssa, piDx);
1684 if (!analysis) return S_FALSE;
1686 for (i = 0; i < analysis->numItems; i++)
1688 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1690 piDx[next] = analysis->glyphs[i].piAdvance[j];
1691 next++;
1694 return S_OK;
1697 /***********************************************************************
1698 * ScriptStringValidate (USP10.@)
1700 * Validate a string analysis.
1702 * PARAMS
1703 * ssa [I] string analysis.
1705 * RETURNS
1706 * Success: S_OK
1707 * Failure: S_FALSE if invalid sequences are found
1708 * or a non-zero HRESULT if it fails.
1710 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1712 StringAnalysis *analysis = ssa;
1714 TRACE("(%p)\n", ssa);
1716 if (!analysis) return E_INVALIDARG;
1717 return (analysis->invalid) ? S_FALSE : S_OK;
1720 /***********************************************************************
1721 * ScriptString_pSize (USP10.@)
1723 * Retrieve width and height of an analysed string.
1725 * PARAMS
1726 * ssa [I] string analysis.
1728 * RETURNS
1729 * Success: Pointer to a SIZE structure.
1730 * Failure: NULL
1732 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
1734 int i, j;
1735 StringAnalysis *analysis = ssa;
1737 TRACE("(%p)\n", ssa);
1739 if (!analysis) return NULL;
1741 if (!analysis->sz)
1743 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
1744 analysis->sz->cy = analysis->sc->tm.tmHeight;
1746 analysis->sz->cx = 0;
1747 for (i = 0; i < analysis->numItems; i++)
1748 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1749 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
1751 return analysis->sz;
1754 /***********************************************************************
1755 * ScriptString_pLogAttr (USP10.@)
1757 * Retrieve logical attributes of an analysed string.
1759 * PARAMS
1760 * ssa [I] string analysis.
1762 * RETURNS
1763 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1764 * Failure: NULL
1766 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
1768 StringAnalysis *analysis = ssa;
1770 TRACE("(%p)\n", ssa);
1772 if (!analysis) return NULL;
1773 return analysis->logattrs;
1776 /***********************************************************************
1777 * ScriptString_pcOutChars (USP10.@)
1779 * Retrieve the length of a string after clipping.
1781 * PARAMS
1782 * ssa [I] String analysis.
1784 * RETURNS
1785 * Success: Pointer to the length.
1786 * Failure: NULL
1788 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
1790 StringAnalysis *analysis = ssa;
1792 TRACE("(%p)\n", ssa);
1794 if (!analysis) return NULL;
1795 return &analysis->clip_len;
1798 /***********************************************************************
1799 * ScriptStringGetOrder (USP10.@)
1801 * Retrieve a glyph order map.
1803 * PARAMS
1804 * ssa [I] String analysis.
1805 * order [I/O] Array of glyph positions.
1807 * RETURNS
1808 * Success: S_OK
1809 * Failure: a non-zero HRESULT.
1811 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
1813 int i, j;
1814 unsigned int k;
1815 StringAnalysis *analysis = ssa;
1817 TRACE("(%p)\n", ssa);
1819 if (!analysis) return S_FALSE;
1821 /* FIXME: handle RTL scripts */
1822 for (i = 0, k = 0; i < analysis->numItems; i++)
1823 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
1824 order[k] = k;
1826 return S_OK;
1829 /***********************************************************************
1830 * ScriptGetLogicalWidths (USP10.@)
1832 * Convert advance widths to logical widths.
1834 * PARAMS
1835 * sa [I] Script analysis.
1836 * nbchars [I] Number of characters.
1837 * nbglyphs [I] Number of glyphs.
1838 * glyph_width [I] Array of glyph widths.
1839 * log_clust [I] Array of logical clusters.
1840 * sva [I] Visual attributes.
1841 * widths [O] Array of logical widths.
1843 * RETURNS
1844 * Success: S_OK
1845 * Failure: a non-zero HRESULT.
1847 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
1848 const int *glyph_width, const WORD *log_clust,
1849 const SCRIPT_VISATTR *sva, int *widths)
1851 int i;
1853 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
1854 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
1856 /* FIXME */
1857 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
1858 return S_OK;
1861 /***********************************************************************
1862 * ScriptApplyLogicalWidth (USP10.@)
1864 * Generate glyph advance widths.
1866 * PARAMS
1867 * dx [I] Array of logical advance widths.
1868 * num_chars [I] Number of characters.
1869 * num_glyphs [I] Number of glyphs.
1870 * log_clust [I] Array of logical clusters.
1871 * sva [I] Visual attributes.
1872 * advance [I] Array of glyph advance widths.
1873 * sa [I] Script analysis.
1874 * abc [I/O] Summed ABC widths.
1875 * justify [O] Array of glyph advance widths.
1877 * RETURNS
1878 * Success: S_OK
1879 * Failure: a non-zero HRESULT.
1881 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
1882 const WORD *log_clust, const SCRIPT_VISATTR *sva,
1883 const int *advance, const SCRIPT_ANALYSIS *sa,
1884 ABC *abc, int *justify)
1886 int i;
1888 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
1889 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
1891 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
1892 return S_OK;
1895 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
1896 int num_glyphs, int dx, int min_kashida, int *justify)
1898 int i;
1900 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
1902 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
1903 return S_OK;