usp10: Fix ScriptGetCMap handling of unsupported glyphs.
[wine/hacks.git] / dlls / usp10 / usp10.c
blobb736966006d1287f85239fca674986cf8f9ec450
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 Hebrew_start 0x0590
521 #define Hebrew_stop 0x05ff
522 #define Syriac_start 0x0700
523 #define Syriac_stop 0x074f
524 #define Latin_start 0x0001
525 #define Latin_stop 0x024f
526 #define Script_Syriac 8
527 #define Script_Hebrew 7
528 #define Script_Arabic 6
529 #define Script_Latin 1
530 #define Script_Numeric 5
531 #define Script_CR 22
532 #define Script_LF 23
534 int cnt = 0, index = 0;
535 int New_Script = SCRIPT_UNDEFINED;
536 WORD *levels = NULL;
537 WORD baselevel = 0;
539 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
540 psControl, psState, pItems, pcItems);
542 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
543 return E_INVALIDARG;
545 if (psState && psControl)
547 int i;
548 levels = heap_alloc_zero(cInChars * sizeof(WORD));
549 if (!levels)
550 return E_OUTOFMEMORY;
552 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
553 baselevel = levels[0];
554 for (i = 0; i < cInChars; i++)
555 if (levels[i]!=levels[0])
556 break;
557 if (i >= cInChars)
559 heap_free(levels);
560 levels = NULL;
564 pItems[index].iCharPos = 0;
565 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
567 if (pwcInChars[cnt] == '\r')
568 pItems[index].a.eScript = Script_CR;
569 else
570 if (pwcInChars[cnt] == '\n')
571 pItems[index].a.eScript = Script_LF;
572 else
573 if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
574 pItems[index].a.eScript = Script_Numeric;
575 else
576 if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
577 pItems[index].a.eScript = Script_Arabic;
578 else
579 if (pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop)
580 pItems[index].a.eScript = Script_Hebrew;
581 else
582 if (pwcInChars[cnt] >= Syriac_start && pwcInChars[cnt] <= Syriac_stop)
583 pItems[index].a.eScript = Script_Syriac;
584 else
585 if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
586 pItems[index].a.eScript = Script_Latin;
588 if (levels)
590 pItems[index].a.fRTL = odd(levels[cnt]);
591 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
592 pItems[index].a.s.uBidiLevel = levels[cnt];
594 else if ((pItems[index].a.eScript == Script_Arabic) ||
595 (pItems[index].a.eScript == Script_Hebrew) ||
596 (pItems[index].a.eScript == Script_Syriac))
598 pItems[index].a.s.uBidiLevel = 1;
599 pItems[index].a.fRTL = 1;
600 pItems[index].a.fLayoutRTL = 1;
602 else
604 pItems[index].a.s.uBidiLevel = baselevel;
605 pItems[index].a.fLayoutRTL = odd(baselevel);
606 pItems[index].a.fRTL = odd(baselevel);
609 TRACE("New_Level=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
610 levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript, index, cnt,
611 pItems[index].iCharPos);
613 for (cnt=1; cnt < cInChars; cnt++)
615 if (levels && (levels[cnt] == pItems[index].a.s.uBidiLevel))
616 continue;
618 if (pwcInChars[cnt] == '\r')
619 New_Script = Script_CR;
620 else
621 if (pwcInChars[cnt] == '\n')
622 New_Script = Script_LF;
623 else
624 if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
625 || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space))
626 New_Script = Script_Numeric;
627 else
628 if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
629 || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space))
630 New_Script = Script_Arabic;
631 else
632 if ((pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop)
633 || (New_Script == Script_Hebrew && pwcInChars[cnt] == Numeric_space))
634 New_Script = Script_Hebrew;
635 else
636 if ((pwcInChars[cnt] >= Syriac_start && pwcInChars[cnt] <= Syriac_stop)
637 || (New_Script == Script_Syriac && pwcInChars[cnt] == Numeric_space))
638 New_Script = Script_Syriac;
639 else
640 if ((pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
641 || (New_Script == Script_Latin && pwcInChars[cnt] == Numeric_space))
642 New_Script = Script_Latin;
643 else
644 New_Script = SCRIPT_UNDEFINED;
646 if ((levels && (levels[cnt] != pItems[index].a.s.uBidiLevel)) || New_Script != pItems[index].a.eScript)
648 TRACE("New_Level = %i, New_Script=%d, eScript=%d ", levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript);
649 index++;
650 if (index+1 > cMaxItems)
651 return E_OUTOFMEMORY;
653 pItems[index].iCharPos = cnt;
654 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
656 if (levels)
658 pItems[index].a.fRTL = odd(levels[cnt]);
659 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
660 pItems[index].a.s.uBidiLevel = levels[cnt];
662 else if ((New_Script == Script_Arabic) ||
663 (New_Script == Script_Hebrew) ||
664 (New_Script == Script_Syriac))
666 pItems[index].a.s.uBidiLevel = 1;
667 pItems[index].a.fRTL = 1;
668 pItems[index].a.fLayoutRTL = 1;
670 else
672 pItems[index].a.s.uBidiLevel = baselevel;
673 pItems[index].a.fLayoutRTL = odd(baselevel);
674 pItems[index].a.fRTL = odd(baselevel);
677 pItems[index].a.eScript = New_Script;
679 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
683 /* While not strictly necessary according to the spec, make sure the n+1
684 * item is set up to prevent random behaviour if the caller erroneously
685 * checks the n+1 structure */
686 index++;
687 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
689 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
691 /* Set one SCRIPT_STATE item being returned */
692 if (index + 1 > cMaxItems) return E_OUTOFMEMORY;
693 if (pcItems) *pcItems = index;
695 /* Set SCRIPT_ITEM */
696 pItems[index].iCharPos = cnt; /* the last item contains the ptr to the lastchar */
697 heap_free(levels);
698 return S_OK;
701 /***********************************************************************
702 * ScriptStringAnalyse (USP10.@)
705 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
706 int cGlyphs, int iCharset, DWORD dwFlags,
707 int iReqWidth, SCRIPT_CONTROL *psControl,
708 SCRIPT_STATE *psState, const int *piDx,
709 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
710 SCRIPT_STRING_ANALYSIS *pssa)
712 HRESULT hr = E_OUTOFMEMORY;
713 StringAnalysis *analysis = NULL;
714 int i, num_items = 255;
716 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
717 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
718 psControl, psState, piDx, pTabdef, pbInClass, pssa);
720 if (iCharset != -1)
722 FIXME("Only Unicode strings are supported\n");
723 return E_INVALIDARG;
725 if (cString < 1 || !pString) return E_INVALIDARG;
726 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
728 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
729 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
731 /* FIXME: handle clipping */
732 analysis->clip_len = cString;
733 analysis->hdc = hdc;
735 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
736 &analysis->numItems);
738 while (hr == E_OUTOFMEMORY)
740 SCRIPT_ITEM *tmp;
742 num_items *= 2;
743 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
744 goto error;
746 analysis->pItem = tmp;
747 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
748 &analysis->numItems);
750 if (hr != S_OK) goto error;
752 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
753 ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs);
754 else
755 goto error;
757 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
758 goto error;
760 for (i = 0; i < analysis->numItems; i++)
762 SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc;
763 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
764 int numGlyphs = 1.5 * cChar + 16;
765 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
766 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
767 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
768 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * cChar);
769 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
770 ABC *abc = heap_alloc_zero(sizeof(ABC));
771 int numGlyphsReturned;
773 /* FIXME: non unicode strings */
774 const WCHAR* pStr = (const WCHAR*)pString;
775 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
776 cChar, numGlyphs, &analysis->pItem[i].a,
777 glyphs, pwLogClust, psva, &numGlyphsReturned);
778 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
779 piAdvance, pGoffset, abc);
781 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
782 analysis->glyphs[i].glyphs = glyphs;
783 analysis->glyphs[i].pwLogClust = pwLogClust;
784 analysis->glyphs[i].piAdvance = piAdvance;
785 analysis->glyphs[i].psva = psva;
786 analysis->glyphs[i].pGoffset = pGoffset;
787 analysis->glyphs[i].abc = abc;
790 *pssa = analysis;
791 return S_OK;
793 error:
794 heap_free(analysis->glyphs);
795 heap_free(analysis->logattrs);
796 heap_free(analysis->pItem);
797 heap_free(analysis->sc);
798 heap_free(analysis);
799 return hr;
802 /***********************************************************************
803 * ScriptStringOut (USP10.@)
805 * This function takes the output of ScriptStringAnalyse and joins the segments
806 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
807 * only processes glyphs.
809 * Parameters:
810 * ssa [I] buffer to hold the analysed string components
811 * iX [I] X axis displacement for output
812 * iY [I] Y axis displacement for output
813 * uOptions [I] flags controling output processing
814 * prc [I] rectangle coordinates
815 * iMinSel [I] starting pos for substringing output string
816 * iMaxSel [I] ending pos for substringing output string
817 * fDisabled [I] controls text highlighting
819 * RETURNS
820 * Success: S_OK
821 * Failure: is the value returned by ScriptTextOut
823 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
824 int iX,
825 int iY,
826 UINT uOptions,
827 const RECT *prc,
828 int iMinSel,
829 int iMaxSel,
830 BOOL fDisabled)
832 StringAnalysis *analysis;
833 WORD *glyphs;
834 int item, cnt, x;
835 HRESULT hr;
837 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
838 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
840 if (!(analysis = ssa)) return E_INVALIDARG;
843 * Get storage for the output buffer for the consolidated strings
845 cnt = 0;
846 for (item = 0; item < analysis->numItems; item++)
848 cnt += analysis->glyphs[item].numGlyphs;
850 if (!(glyphs = heap_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY;
853 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
855 uOptions |= ETO_GLYPH_INDEX;
856 analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */
859 * Copy the string items into the output buffer
862 TRACE("numItems %d\n", analysis->numItems);
864 cnt = 0;
865 for (item = 0; item < analysis->numItems; item++)
867 memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs,
868 sizeof(WCHAR) * analysis->glyphs[item].numGlyphs);
870 TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs);
871 for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++)
872 TRACE("%04x", glyphs[x]);
873 TRACE("\n");
875 cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */
878 hr = ScriptTextOut(analysis->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY,
879 uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt,
880 analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset);
881 TRACE("ScriptTextOut hr=%08x\n", hr);
884 * Free the output buffer and script cache
886 heap_free(glyphs);
887 return hr;
890 /***********************************************************************
891 * ScriptStringCPtoX (USP10.@)
894 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
896 int i, j;
897 int runningX = 0;
898 int runningCp = 0;
899 StringAnalysis* analysis = ssa;
901 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
903 if (!ssa || !pX) return S_FALSE;
905 /* icp out of range */
906 if(icp < 0)
908 analysis->invalid = TRUE;
909 return E_INVALIDARG;
912 for(i=0; i<analysis->numItems; i++)
914 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
916 if(runningCp == icp && fTrailing == FALSE)
918 *pX = runningX;
919 return S_OK;
921 runningX += analysis->glyphs[i].piAdvance[j];
922 if(runningCp == icp && fTrailing == TRUE)
924 *pX = runningX;
925 return S_OK;
927 runningCp++;
931 /* icp out of range */
932 analysis->invalid = TRUE;
933 return E_INVALIDARG;
936 /***********************************************************************
937 * ScriptStringXtoCP (USP10.@)
940 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
942 StringAnalysis* analysis = ssa;
943 int i;
944 int j;
945 int runningX = 0;
946 int runningCp = 0;
947 int width;
949 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
951 if (!ssa || !piCh || !piTrailing) return S_FALSE;
953 /* out of range */
954 if(iX < 0)
956 *piCh = -1;
957 *piTrailing = TRUE;
958 return S_OK;
961 for(i=0; i<analysis->numItems; i++)
963 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
965 width = analysis->glyphs[i].piAdvance[j];
966 if(iX < (runningX + width))
968 *piCh = runningCp;
969 if((iX - runningX) > width/2)
970 *piTrailing = TRUE;
971 else
972 *piTrailing = FALSE;
973 return S_OK;
975 runningX += width;
976 runningCp++;
980 /* out of range */
981 *piCh = analysis->pItem[analysis->numItems].iCharPos;
982 *piTrailing = FALSE;
984 return S_OK;
988 /***********************************************************************
989 * ScriptStringFree (USP10.@)
991 * Free a string analysis.
993 * PARAMS
994 * pssa [I] string analysis.
996 * RETURNS
997 * Success: S_OK
998 * Failure: Non-zero HRESULT value.
1000 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
1002 StringAnalysis* analysis;
1003 BOOL invalid;
1004 int i;
1006 TRACE("(%p)\n", pssa);
1008 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
1010 invalid = analysis->invalid;
1011 ScriptFreeCache((SCRIPT_CACHE *)&analysis->sc);
1013 for (i = 0; i < analysis->numItems; i++)
1015 heap_free(analysis->glyphs[i].glyphs);
1016 heap_free(analysis->glyphs[i].pwLogClust);
1017 heap_free(analysis->glyphs[i].piAdvance);
1018 heap_free(analysis->glyphs[i].psva);
1019 heap_free(analysis->glyphs[i].pGoffset);
1020 heap_free(analysis->glyphs[i].abc);
1023 heap_free(analysis->glyphs);
1024 heap_free(analysis->pItem);
1025 heap_free(analysis->logattrs);
1026 heap_free(analysis->sz);
1027 heap_free(analysis->sc);
1028 heap_free(analysis);
1030 if (invalid) return E_INVALIDARG;
1031 return S_OK;
1034 /***********************************************************************
1035 * ScriptCPtoX (USP10.@)
1038 HRESULT WINAPI ScriptCPtoX(int iCP,
1039 BOOL fTrailing,
1040 int cChars,
1041 int cGlyphs,
1042 const WORD *pwLogClust,
1043 const SCRIPT_VISATTR *psva,
1044 const int *piAdvance,
1045 const SCRIPT_ANALYSIS *psa,
1046 int *piX)
1048 int item;
1049 int iPosX;
1050 float fMaxPosX = 0;
1051 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1052 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1053 psa, piX);
1054 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1055 fMaxPosX += piAdvance[item];
1056 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
1057 if (iPosX > fMaxPosX)
1058 iPosX = fMaxPosX;
1059 *piX = iPosX; /* Return something in range */
1061 TRACE("*piX=%d\n", *piX);
1062 return S_OK;
1065 /***********************************************************************
1066 * ScriptXtoCP (USP10.@)
1069 HRESULT WINAPI ScriptXtoCP(int iX,
1070 int cChars,
1071 int cGlyphs,
1072 const WORD *pwLogClust,
1073 const SCRIPT_VISATTR *psva,
1074 const int *piAdvance,
1075 const SCRIPT_ANALYSIS *psa,
1076 int *piCP,
1077 int *piTrailing)
1079 int item;
1080 int iPosX;
1081 float fMaxPosX = 1;
1082 float fAvePosX;
1083 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1084 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1085 psa, piCP, piTrailing);
1086 if (iX < 0) /* iX is before start of run */
1088 *piCP = -1;
1089 *piTrailing = TRUE;
1090 return S_OK;
1093 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1094 fMaxPosX += piAdvance[item];
1096 if (iX >= fMaxPosX) /* iX too large */
1098 *piCP = cChars;
1099 *piTrailing = FALSE;
1100 return S_OK;
1103 fAvePosX = fMaxPosX / cGlyphs;
1104 iPosX = fAvePosX;
1105 for (item = 1; item < cGlyphs && iPosX < iX; item++)
1106 iPosX += fAvePosX;
1107 if (iPosX - iX > fAvePosX/2)
1108 *piTrailing = 0;
1109 else
1110 *piTrailing = 1; /* yep we are over halfway */
1112 *piCP = item -1; /* Return character position */
1113 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
1114 return S_OK;
1117 /***********************************************************************
1118 * ScriptBreak (USP10.@)
1120 * Retrieve line break information.
1122 * PARAMS
1123 * chars [I] Array of characters.
1124 * sa [I] String analysis.
1125 * la [I] Array of logical attribute structures.
1127 * RETURNS
1128 * Success: S_OK
1129 * Failure: S_FALSE
1131 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
1133 int i;
1135 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
1137 if (!la) return S_FALSE;
1139 for (i = 0; i < count; i++)
1141 memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
1143 /* FIXME: set the other flags */
1144 la[i].fWhiteSpace = (chars[i] == ' ');
1145 la[i].fCharStop = 1;
1147 if (i > 0 && la[i - 1].fWhiteSpace)
1149 la[i].fSoftBreak = 1;
1150 la[i].fWordStop = 1;
1153 return S_OK;
1156 static const struct
1158 WCHAR start;
1159 WCHAR end;
1160 DWORD flag;
1162 complex_ranges[] =
1164 { 0, 0x0b, SIC_COMPLEX },
1165 { 0x0c, 0x0c, SIC_NEUTRAL },
1166 { 0x0d, 0x1f, SIC_COMPLEX },
1167 { 0x20, 0x2f, SIC_NEUTRAL },
1168 { 0x30, 0x39, SIC_ASCIIDIGIT },
1169 { 0x3a, 0x40, SIC_NEUTRAL },
1170 { 0x5b, 0x60, SIC_NEUTRAL },
1171 { 0x7b, 0x7e, SIC_NEUTRAL },
1172 { 0x7f, 0x9f, SIC_COMPLEX },
1173 { 0xa0, 0xa5, SIC_NEUTRAL },
1174 { 0xa7, 0xa8, SIC_NEUTRAL },
1175 { 0xab, 0xab, SIC_NEUTRAL },
1176 { 0xad, 0xad, SIC_NEUTRAL },
1177 { 0xaf, 0xaf, SIC_NEUTRAL },
1178 { 0xb0, 0xb1, SIC_NEUTRAL },
1179 { 0xb4, 0xb4, SIC_NEUTRAL },
1180 { 0xb6, 0xb8, SIC_NEUTRAL },
1181 { 0xbb, 0xbf, SIC_NEUTRAL },
1182 { 0xd7, 0xd7, SIC_NEUTRAL },
1183 { 0xf7, 0xf7, SIC_NEUTRAL },
1184 { 0x2b9, 0x2ba, SIC_NEUTRAL },
1185 { 0x2c2, 0x2cf, SIC_NEUTRAL },
1186 { 0x2d2, 0x2df, SIC_NEUTRAL },
1187 { 0x2e5, 0x2e9, SIC_COMPLEX },
1188 { 0x2ea, 0x2ed, SIC_NEUTRAL },
1189 { 0x300, 0x362, SIC_COMPLEX },
1190 { 0x530, 0x60b, SIC_COMPLEX },
1191 { 0x60c, 0x60d, SIC_NEUTRAL },
1192 { 0x60e, 0x669, SIC_COMPLEX },
1193 { 0x66a, 0x66a, SIC_NEUTRAL },
1194 { 0x66b, 0x6e8, SIC_COMPLEX },
1195 { 0x6e9, 0x6e9, SIC_NEUTRAL },
1196 { 0x6ea, 0x7bf, SIC_COMPLEX },
1197 { 0x900, 0x1360, SIC_COMPLEX },
1198 { 0x137d, 0x137f, SIC_COMPLEX },
1199 { 0x1680, 0x1680, SIC_NEUTRAL },
1200 { 0x1780, 0x18af, SIC_COMPLEX },
1201 { 0x2000, 0x200a, SIC_NEUTRAL },
1202 { 0x200b, 0x200f, SIC_COMPLEX },
1203 { 0x2010, 0x2016, SIC_NEUTRAL },
1204 { 0x2018, 0x2022, SIC_NEUTRAL },
1205 { 0x2024, 0x2028, SIC_NEUTRAL },
1206 { 0x2029, 0x202e, SIC_COMPLEX },
1207 { 0x202f, 0x2037, SIC_NEUTRAL },
1208 { 0x2039, 0x203c, SIC_NEUTRAL },
1209 { 0x2044, 0x2046, SIC_NEUTRAL },
1210 { 0x206a, 0x206f, SIC_COMPLEX },
1211 { 0x207a, 0x207e, SIC_NEUTRAL },
1212 { 0x208a, 0x20aa, SIC_NEUTRAL },
1213 { 0x20ac, 0x20cf, SIC_NEUTRAL },
1214 { 0x20d0, 0x20ff, SIC_COMPLEX },
1215 { 0x2103, 0x2103, SIC_NEUTRAL },
1216 { 0x2105, 0x2105, SIC_NEUTRAL },
1217 { 0x2109, 0x2109, SIC_NEUTRAL },
1218 { 0x2116, 0x2116, SIC_NEUTRAL },
1219 { 0x2121, 0x2122, SIC_NEUTRAL },
1220 { 0x212e, 0x212e, SIC_NEUTRAL },
1221 { 0x2153, 0x2154, SIC_NEUTRAL },
1222 { 0x215b, 0x215e, SIC_NEUTRAL },
1223 { 0x2190, 0x2199, SIC_NEUTRAL },
1224 { 0x21b8, 0x21b9, SIC_NEUTRAL },
1225 { 0x21d2, 0x21d2, SIC_NEUTRAL },
1226 { 0x21d4, 0x21d4, SIC_NEUTRAL },
1227 { 0x21e7, 0x21e7, SIC_NEUTRAL },
1228 { 0x2200, 0x2200, SIC_NEUTRAL },
1229 { 0x2202, 0x2203, SIC_NEUTRAL },
1230 { 0x2207, 0x2208, SIC_NEUTRAL },
1231 { 0x220b, 0x220b, SIC_NEUTRAL },
1232 { 0x220f, 0x220f, SIC_NEUTRAL },
1233 { 0x2211, 0x2213, SIC_NEUTRAL },
1234 { 0x2215, 0x2215, SIC_NEUTRAL },
1235 { 0x221a, 0x221a, SIC_NEUTRAL },
1236 { 0x221d, 0x2220, SIC_NEUTRAL },
1237 { 0x2223, 0x2223, SIC_NEUTRAL },
1238 { 0x2225, 0x2225, SIC_NEUTRAL },
1239 { 0x2227, 0x222c, SIC_NEUTRAL },
1240 { 0x222e, 0x222e, SIC_NEUTRAL },
1241 { 0x2234, 0x2237, SIC_NEUTRAL },
1242 { 0x223c, 0x223d, SIC_NEUTRAL },
1243 { 0x2248, 0x2248, SIC_NEUTRAL },
1244 { 0x224c, 0x224c, SIC_NEUTRAL },
1245 { 0x2252, 0x2252, SIC_NEUTRAL },
1246 { 0x2260, 0x2261, SIC_NEUTRAL },
1247 { 0x2264, 0x2267, SIC_NEUTRAL },
1248 { 0x226a, 0x226b, SIC_NEUTRAL },
1249 { 0x226e, 0x226f, SIC_NEUTRAL },
1250 { 0x2282, 0x2283, SIC_NEUTRAL },
1251 { 0x2286, 0x2287, SIC_NEUTRAL },
1252 { 0x2295, 0x2295, SIC_NEUTRAL },
1253 { 0x2299, 0x2299, SIC_NEUTRAL },
1254 { 0x22a5, 0x22a5, SIC_NEUTRAL },
1255 { 0x22bf, 0x22bf, SIC_NEUTRAL },
1256 { 0x2312, 0x2312, SIC_NEUTRAL },
1257 { 0x24ea, 0x24ea, SIC_COMPLEX },
1258 { 0x2500, 0x254b, SIC_NEUTRAL },
1259 { 0x2550, 0x256d, SIC_NEUTRAL },
1260 { 0x256e, 0x2574, SIC_NEUTRAL },
1261 { 0x2581, 0x258f, SIC_NEUTRAL },
1262 { 0x2592, 0x2595, SIC_NEUTRAL },
1263 { 0x25a0, 0x25a1, SIC_NEUTRAL },
1264 { 0x25a3, 0x25a9, SIC_NEUTRAL },
1265 { 0x25b2, 0x25b3, SIC_NEUTRAL },
1266 { 0x25b6, 0x25b7, SIC_NEUTRAL },
1267 { 0x25bc, 0x25bd, SIC_NEUTRAL },
1268 { 0x25c0, 0x25c1, SIC_NEUTRAL },
1269 { 0x25c6, 0x25c8, SIC_NEUTRAL },
1270 { 0x25cb, 0x25cb, SIC_NEUTRAL },
1271 { 0x25ce, 0x25d1, SIC_NEUTRAL },
1272 { 0x25e2, 0x25e5, SIC_NEUTRAL },
1273 { 0x25ef, 0x25ef, SIC_NEUTRAL },
1274 { 0x2605, 0x2606, SIC_NEUTRAL },
1275 { 0x2609, 0x2609, SIC_NEUTRAL },
1276 { 0x260e, 0x260f, SIC_NEUTRAL },
1277 { 0x261c, 0x261c, SIC_NEUTRAL },
1278 { 0x261e, 0x261e, SIC_NEUTRAL },
1279 { 0x2640, 0x2640, SIC_NEUTRAL },
1280 { 0x2642, 0x2642, SIC_NEUTRAL },
1281 { 0x2660, 0x2661, SIC_NEUTRAL },
1282 { 0x2663, 0x2665, SIC_NEUTRAL },
1283 { 0x2667, 0x266a, SIC_NEUTRAL },
1284 { 0x266c, 0x266d, SIC_NEUTRAL },
1285 { 0x266f, 0x266f, SIC_NEUTRAL },
1286 { 0x273d, 0x273d, SIC_NEUTRAL },
1287 { 0x2e80, 0x312f, SIC_COMPLEX },
1288 { 0x3190, 0x31bf, SIC_COMPLEX },
1289 { 0x31f0, 0x31ff, SIC_COMPLEX },
1290 { 0x3220, 0x325f, SIC_COMPLEX },
1291 { 0x3280, 0xa4ff, SIC_COMPLEX },
1292 { 0xd800, 0xdfff, SIC_COMPLEX },
1293 { 0xe000, 0xf8ff, SIC_NEUTRAL },
1294 { 0xf900, 0xfaff, SIC_COMPLEX },
1295 { 0xfb13, 0xfb28, SIC_COMPLEX },
1296 { 0xfb29, 0xfb29, SIC_NEUTRAL },
1297 { 0xfb2a, 0xfb4f, SIC_COMPLEX },
1298 { 0xfd3e, 0xfd3f, SIC_NEUTRAL },
1299 { 0xfdd0, 0xfdef, SIC_COMPLEX },
1300 { 0xfe20, 0xfe6f, SIC_COMPLEX },
1301 { 0xfeff, 0xfeff, SIC_COMPLEX },
1302 { 0xff01, 0xff5e, SIC_COMPLEX },
1303 { 0xff61, 0xff9f, SIC_COMPLEX },
1304 { 0xffe0, 0xffe6, SIC_COMPLEX },
1305 { 0xffe8, 0xffee, SIC_COMPLEX },
1306 { 0xfff9, 0xfffb, SIC_COMPLEX },
1307 { 0xfffe, 0xfffe, SIC_COMPLEX }
1310 /***********************************************************************
1311 * ScriptIsComplex (USP10.@)
1313 * Determine if a string is complex.
1315 * PARAMS
1316 * chars [I] Array of characters to test.
1317 * len [I] Length in characters.
1318 * flag [I] Flag.
1320 * RETURNS
1321 * Success: S_OK
1322 * Failure: S_FALSE
1324 * NOTES
1325 * Behaviour matches that of WinXP.
1327 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
1329 int i;
1330 unsigned int j;
1332 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
1334 for (i = 0; i < len; i++)
1336 for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
1338 if (chars[i] >= complex_ranges[j].start &&
1339 chars[i] <= complex_ranges[j].end &&
1340 (flag & complex_ranges[j].flag)) return S_OK;
1343 return S_FALSE;
1346 /***********************************************************************
1347 * ScriptShape (USP10.@)
1349 * Produce glyphs and visual attributes for a run.
1351 * PARAMS
1352 * hdc [I] Device context.
1353 * psc [I/O] Opaque pointer to a script cache.
1354 * pwcChars [I] Array of characters specifying the run.
1355 * cChars [I] Number of characters in pwcChars.
1356 * cMaxGlyphs [I] Length of pwOutGlyphs.
1357 * psa [I/O] Script analysis.
1358 * pwOutGlyphs [O] Array of glyphs.
1359 * pwLogClust [O] Array of logical cluster info.
1360 * psva [O] Array of visual attributes.
1361 * pcGlyphs [O] Number of glyphs returned.
1363 * RETURNS
1364 * Success: S_OK
1365 * Failure: Non-zero HRESULT value.
1367 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
1368 int cChars, int cMaxGlyphs,
1369 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
1370 SCRIPT_VISATTR *psva, int *pcGlyphs)
1372 HRESULT hr;
1373 unsigned int i;
1374 BOOL rtl;
1376 TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc, psc, debugstr_wn(pwcChars, cChars),
1377 cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs);
1379 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
1380 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
1382 if (!psva || !pcGlyphs) return E_INVALIDARG;
1383 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
1384 rtl = (!psa->fLogicalOrder && psa->fRTL);
1386 *pcGlyphs = cChars;
1387 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1388 if (!pwLogClust) return E_FAIL;
1390 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1392 for (i = 0; i < cChars; i++)
1394 int idx = i;
1395 if (rtl) idx = cChars - 1 - i;
1396 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcChars[idx])))
1398 WORD glyph;
1399 if (!hdc) return E_PENDING;
1400 if (GetGlyphIndicesW(hdc, &pwcChars[idx], 1, &glyph, 0) == GDI_ERROR) return S_FALSE;
1401 pwOutGlyphs[i] = set_cache_glyph(psc, pwcChars[idx], glyph);
1405 else
1407 TRACE("no glyph translation\n");
1408 for (i = 0; i < cChars; i++)
1410 int idx = i;
1411 if (rtl) idx = cChars - 1 - i;
1412 pwOutGlyphs[i] = pwcChars[idx];
1416 /* set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1417 for (i = 0; i < cChars; i++)
1419 int idx = i;
1420 if (rtl) idx = cChars - 1 - i;
1421 /* FIXME: set to better values */
1422 psva[i].uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
1423 psva[i].fClusterStart = 1;
1424 psva[i].fDiacritic = 0;
1425 psva[i].fZeroWidth = 0;
1426 psva[i].fReserved = 0;
1427 psva[i].fShapeReserved = 0;
1429 pwLogClust[i] = idx;
1431 return S_OK;
1434 /***********************************************************************
1435 * ScriptPlace (USP10.@)
1437 * Produce advance widths for a run.
1439 * PARAMS
1440 * hdc [I] Device context.
1441 * psc [I/O] Opaque pointer to a script cache.
1442 * pwGlyphs [I] Array of glyphs.
1443 * cGlyphs [I] Number of glyphs in pwGlyphs.
1444 * psva [I] Array of visual attributes.
1445 * psa [I/O] String analysis.
1446 * piAdvance [O] Array of advance widths.
1447 * pGoffset [O] Glyph offsets.
1448 * pABC [O] Combined ABC width.
1450 * RETURNS
1451 * Success: S_OK
1452 * Failure: Non-zero HRESULT value.
1454 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
1455 int cGlyphs, const SCRIPT_VISATTR *psva,
1456 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1458 HRESULT hr;
1459 int i;
1461 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
1462 piAdvance, pGoffset, pABC);
1464 if (!psva) return E_INVALIDARG;
1465 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1466 if (!pGoffset) return E_FAIL;
1468 if (pABC) memset(pABC, 0, sizeof(ABC));
1469 for (i = 0; i < cGlyphs; i++)
1471 ABC abc;
1472 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
1474 if (!hdc) return E_PENDING;
1475 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1477 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
1479 else
1481 INT width;
1482 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
1483 abc.abcB = width;
1484 abc.abcA = abc.abcC = 0;
1486 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
1488 if (pABC)
1490 pABC->abcA += abc.abcA;
1491 pABC->abcB += abc.abcB;
1492 pABC->abcC += abc.abcC;
1494 /* FIXME: set to more reasonable values */
1495 pGoffset[i].du = pGoffset[i].dv = 0;
1496 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
1499 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1500 return S_OK;
1503 /***********************************************************************
1504 * ScriptGetCMap (USP10.@)
1506 * Retrieve glyph indices.
1508 * PARAMS
1509 * hdc [I] Device context.
1510 * psc [I/O] Opaque pointer to a script cache.
1511 * pwcInChars [I] Array of Unicode characters.
1512 * cChars [I] Number of characters in pwcInChars.
1513 * dwFlags [I] Flags.
1514 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1516 * RETURNS
1517 * Success: S_OK
1518 * Failure: Non-zero HRESULT value.
1520 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1521 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1523 HRESULT hr;
1524 int i;
1526 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
1527 cChars, dwFlags, pwOutGlyphs);
1529 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1531 hr = S_OK;
1533 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1535 for (i = 0; i < cChars; i++)
1537 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcInChars[i])))
1539 WORD glyph;
1540 if (!hdc) return E_PENDING;
1541 if (GetGlyphIndicesW(hdc, &pwcInChars[i], 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
1542 if (glyph == 0xffff)
1544 hr = S_FALSE;
1545 glyph = 0x0;
1547 pwOutGlyphs[i] = set_cache_glyph(psc, pwcInChars[i], glyph);
1551 else
1553 TRACE("no glyph translation\n");
1554 for (i = 0; i < cChars; i++) pwOutGlyphs[i] = pwcInChars[i];
1556 return hr;
1559 /***********************************************************************
1560 * ScriptTextOut (USP10.@)
1563 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1564 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1565 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1566 const int *piJustify, const GOFFSET *pGoffset)
1568 HRESULT hr = S_OK;
1570 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1571 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1572 piAdvance, piJustify, pGoffset);
1574 if (!hdc || !psc) return E_INVALIDARG;
1575 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
1577 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1578 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1579 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1581 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
1582 hr = S_FALSE;
1584 return hr;
1587 /***********************************************************************
1588 * ScriptCacheGetHeight (USP10.@)
1590 * Retrieve the height of the font in the cache.
1592 * PARAMS
1593 * hdc [I] Device context.
1594 * psc [I/O] Opaque pointer to a script cache.
1595 * height [O] Receives font height.
1597 * RETURNS
1598 * Success: S_OK
1599 * Failure: Non-zero HRESULT value.
1601 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
1603 HRESULT hr;
1605 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1607 if (!height) return E_INVALIDARG;
1608 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1610 *height = get_cache_height(psc);
1611 return S_OK;
1614 /***********************************************************************
1615 * ScriptGetGlyphABCWidth (USP10.@)
1617 * Retrieve the width of a glyph.
1619 * PARAMS
1620 * hdc [I] Device context.
1621 * psc [I/O] Opaque pointer to a script cache.
1622 * glyph [I] Glyph to retrieve the width for.
1623 * abc [O] ABC widths of the glyph.
1625 * RETURNS
1626 * Success: S_OK
1627 * Failure: Non-zero HRESULT value.
1629 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1631 HRESULT hr;
1633 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1635 if (!abc) return E_INVALIDARG;
1636 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1638 if (!get_cache_glyph_widths(psc, glyph, abc))
1640 if (!hdc) return E_PENDING;
1641 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1643 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
1645 else
1647 INT width;
1648 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
1649 abc->abcB = width;
1650 abc->abcA = abc->abcC = 0;
1652 set_cache_glyph_widths(psc, glyph, abc);
1654 return S_OK;
1657 /***********************************************************************
1658 * ScriptLayout (USP10.@)
1660 * Map embedding levels to visual and/or logical order.
1662 * PARAMS
1663 * runs [I] Size of level array.
1664 * level [I] Array of embedding levels.
1665 * vistolog [O] Map of embedding levels from visual to logical order.
1666 * logtovis [O] Map of embedding levels from logical to visual order.
1668 * RETURNS
1669 * Success: S_OK
1670 * Failure: Non-zero HRESULT value.
1672 * BUGS
1673 * This stub works correctly for any sequence of a single
1674 * embedding level but not for sequences of different
1675 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1677 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1679 int* indexs;
1680 int ich;
1682 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
1684 if (!level || (!vistolog && !logtovis))
1685 return E_INVALIDARG;
1687 indexs = heap_alloc(sizeof(int) * runs);
1688 if (!indexs)
1689 return E_OUTOFMEMORY;
1692 if (vistolog)
1694 for( ich = 0; ich < runs; ich++)
1695 indexs[ich] = ich;
1697 ich = 0;
1698 while (ich < runs)
1699 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1700 for (ich = 0; ich < runs; ich++)
1701 vistolog[ich] = indexs[ich];
1705 if (logtovis)
1707 for( ich = 0; ich < runs; ich++)
1708 indexs[ich] = ich;
1710 ich = 0;
1711 while (ich < runs)
1712 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1713 for (ich = 0; ich < runs; ich++)
1714 logtovis[ich] = indexs[ich];
1716 heap_free(indexs);
1718 return S_OK;
1721 /***********************************************************************
1722 * ScriptStringGetLogicalWidths (USP10.@)
1724 * Returns logical widths from a string analysis.
1726 * PARAMS
1727 * ssa [I] string analysis.
1728 * piDx [O] logical widths returned.
1730 * RETURNS
1731 * Success: S_OK
1732 * Failure: a non-zero HRESULT.
1734 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
1736 int i, j, next = 0;
1737 StringAnalysis *analysis = ssa;
1739 TRACE("%p, %p\n", ssa, piDx);
1741 if (!analysis) return S_FALSE;
1743 for (i = 0; i < analysis->numItems; i++)
1745 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1747 piDx[next] = analysis->glyphs[i].piAdvance[j];
1748 next++;
1751 return S_OK;
1754 /***********************************************************************
1755 * ScriptStringValidate (USP10.@)
1757 * Validate a string analysis.
1759 * PARAMS
1760 * ssa [I] string analysis.
1762 * RETURNS
1763 * Success: S_OK
1764 * Failure: S_FALSE if invalid sequences are found
1765 * or a non-zero HRESULT if it fails.
1767 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1769 StringAnalysis *analysis = ssa;
1771 TRACE("(%p)\n", ssa);
1773 if (!analysis) return E_INVALIDARG;
1774 return (analysis->invalid) ? S_FALSE : S_OK;
1777 /***********************************************************************
1778 * ScriptString_pSize (USP10.@)
1780 * Retrieve width and height of an analysed string.
1782 * PARAMS
1783 * ssa [I] string analysis.
1785 * RETURNS
1786 * Success: Pointer to a SIZE structure.
1787 * Failure: NULL
1789 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
1791 int i, j;
1792 StringAnalysis *analysis = ssa;
1794 TRACE("(%p)\n", ssa);
1796 if (!analysis) return NULL;
1798 if (!analysis->sz)
1800 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
1801 analysis->sz->cy = analysis->sc->tm.tmHeight;
1803 analysis->sz->cx = 0;
1804 for (i = 0; i < analysis->numItems; i++)
1805 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1806 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
1808 return analysis->sz;
1811 /***********************************************************************
1812 * ScriptString_pLogAttr (USP10.@)
1814 * Retrieve logical attributes of an analysed string.
1816 * PARAMS
1817 * ssa [I] string analysis.
1819 * RETURNS
1820 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1821 * Failure: NULL
1823 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
1825 StringAnalysis *analysis = ssa;
1827 TRACE("(%p)\n", ssa);
1829 if (!analysis) return NULL;
1830 return analysis->logattrs;
1833 /***********************************************************************
1834 * ScriptString_pcOutChars (USP10.@)
1836 * Retrieve the length of a string after clipping.
1838 * PARAMS
1839 * ssa [I] String analysis.
1841 * RETURNS
1842 * Success: Pointer to the length.
1843 * Failure: NULL
1845 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
1847 StringAnalysis *analysis = ssa;
1849 TRACE("(%p)\n", ssa);
1851 if (!analysis) return NULL;
1852 return &analysis->clip_len;
1855 /***********************************************************************
1856 * ScriptStringGetOrder (USP10.@)
1858 * Retrieve a glyph order map.
1860 * PARAMS
1861 * ssa [I] String analysis.
1862 * order [I/O] Array of glyph positions.
1864 * RETURNS
1865 * Success: S_OK
1866 * Failure: a non-zero HRESULT.
1868 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
1870 int i, j;
1871 unsigned int k;
1872 StringAnalysis *analysis = ssa;
1874 TRACE("(%p)\n", ssa);
1876 if (!analysis) return S_FALSE;
1878 /* FIXME: handle RTL scripts */
1879 for (i = 0, k = 0; i < analysis->numItems; i++)
1880 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
1881 order[k] = k;
1883 return S_OK;
1886 /***********************************************************************
1887 * ScriptGetLogicalWidths (USP10.@)
1889 * Convert advance widths to logical widths.
1891 * PARAMS
1892 * sa [I] Script analysis.
1893 * nbchars [I] Number of characters.
1894 * nbglyphs [I] Number of glyphs.
1895 * glyph_width [I] Array of glyph widths.
1896 * log_clust [I] Array of logical clusters.
1897 * sva [I] Visual attributes.
1898 * widths [O] Array of logical widths.
1900 * RETURNS
1901 * Success: S_OK
1902 * Failure: a non-zero HRESULT.
1904 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
1905 const int *glyph_width, const WORD *log_clust,
1906 const SCRIPT_VISATTR *sva, int *widths)
1908 int i;
1910 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
1911 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
1913 /* FIXME */
1914 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
1915 return S_OK;
1918 /***********************************************************************
1919 * ScriptApplyLogicalWidth (USP10.@)
1921 * Generate glyph advance widths.
1923 * PARAMS
1924 * dx [I] Array of logical advance widths.
1925 * num_chars [I] Number of characters.
1926 * num_glyphs [I] Number of glyphs.
1927 * log_clust [I] Array of logical clusters.
1928 * sva [I] Visual attributes.
1929 * advance [I] Array of glyph advance widths.
1930 * sa [I] Script analysis.
1931 * abc [I/O] Summed ABC widths.
1932 * justify [O] Array of glyph advance widths.
1934 * RETURNS
1935 * Success: S_OK
1936 * Failure: a non-zero HRESULT.
1938 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
1939 const WORD *log_clust, const SCRIPT_VISATTR *sva,
1940 const int *advance, const SCRIPT_ANALYSIS *sa,
1941 ABC *abc, int *justify)
1943 int i;
1945 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
1946 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
1948 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
1949 return S_OK;
1952 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
1953 int num_glyphs, int dx, int min_kashida, int *justify)
1955 int i;
1957 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
1959 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
1960 return S_OK;