usp10: Improve Hebrew support in ScriptItemize.
[wine.git] / dlls / usp10 / usp10.c
bloba1af271c4caf9760c8c6884702a58a9376508e26
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 Latin_start 0x0001
523 #define Latin_stop 0x024f
524 #define Script_Hebrew 7
525 #define Script_Arabic 6
526 #define Script_Latin 1
527 #define Script_Numeric 5
528 #define Script_CR 22
529 #define Script_LF 23
531 int cnt = 0, index = 0;
532 int New_Script = SCRIPT_UNDEFINED;
533 WORD *levels = NULL;
535 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars, cInChars), cInChars, cMaxItems,
536 psControl, psState, pItems, pcItems);
538 if (!pwcInChars || !cInChars || !pItems || cMaxItems < 2)
539 return E_INVALIDARG;
541 if (psState && psControl)
543 int i;
544 levels = heap_alloc_zero(cInChars * sizeof(WORD));
545 if (!levels)
546 return E_OUTOFMEMORY;
548 BIDI_DetermineLevels(pwcInChars, cInChars, psState, psControl, levels);
549 for (i = 0; i < cInChars; i++)
550 if (levels[i]!=levels[0])
551 break;
552 if (i >= cInChars)
554 heap_free(levels);
555 levels = NULL;
559 pItems[index].iCharPos = 0;
560 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
562 if (pwcInChars[cnt] == '\r')
563 pItems[index].a.eScript = Script_CR;
564 else
565 if (pwcInChars[cnt] == '\n')
566 pItems[index].a.eScript = Script_LF;
567 else
568 if (pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
569 pItems[index].a.eScript = Script_Numeric;
570 else
571 if (pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
572 pItems[index].a.eScript = Script_Arabic;
573 else
574 if (pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop)
575 pItems[index].a.eScript = Script_Hebrew;
576 else
577 if (pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
578 pItems[index].a.eScript = Script_Latin;
580 if (levels)
582 pItems[index].a.fRTL = odd(levels[cnt]);
583 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
584 pItems[index].a.s.uBidiLevel = levels[cnt];
586 else if ((pItems[index].a.eScript == Script_Arabic) ||
587 (pItems[index].a.eScript == Script_Hebrew))
589 pItems[index].a.s.uBidiLevel = 1;
590 pItems[index].a.fRTL = 1;
591 pItems[index].a.fLayoutRTL = 1;
595 TRACE("New_Level=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
596 levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript, index, cnt,
597 pItems[index].iCharPos);
599 for (cnt=1; cnt < cInChars; cnt++)
601 if (levels && (levels[cnt] == pItems[index].a.s.uBidiLevel))
602 continue;
604 if (pwcInChars[cnt] == '\r')
605 New_Script = Script_CR;
606 else
607 if (pwcInChars[cnt] == '\n')
608 New_Script = Script_LF;
609 else
610 if ((pwcInChars[cnt] >= Numeric_start && pwcInChars[cnt] <= Numeric_stop)
611 || (New_Script == Script_Numeric && pwcInChars[cnt] == Numeric_space))
612 New_Script = Script_Numeric;
613 else
614 if ((pwcInChars[cnt] >= Arabic_start && pwcInChars[cnt] <= Arabic_stop)
615 || (New_Script == Script_Arabic && pwcInChars[cnt] == Numeric_space))
616 New_Script = Script_Arabic;
617 else
618 if ((pwcInChars[cnt] >= Hebrew_start && pwcInChars[cnt] <= Hebrew_stop)
619 || (New_Script == Script_Hebrew && pwcInChars[cnt] == Numeric_space))
620 New_Script = Script_Hebrew;
621 else
622 if ((pwcInChars[cnt] >= Latin_start && pwcInChars[cnt] <= Latin_stop)
623 || (New_Script == Script_Latin && pwcInChars[cnt] == Numeric_space))
624 New_Script = Script_Latin;
625 else
626 New_Script = SCRIPT_UNDEFINED;
628 if ((levels && (levels[cnt] != pItems[index].a.s.uBidiLevel)) || New_Script != pItems[index].a.eScript)
630 TRACE("New_Level = %i, New_Script=%d, eScript=%d ", levels?levels[cnt]:-1, New_Script, pItems[index].a.eScript);
631 index++;
632 if (index+1 > cMaxItems)
633 return E_OUTOFMEMORY;
635 pItems[index].iCharPos = cnt;
636 memset(&pItems[index].a, 0, sizeof(SCRIPT_ANALYSIS));
638 if (levels)
640 pItems[index].a.fRTL = odd(levels[cnt]);
641 pItems[index].a.fLayoutRTL = odd(levels[cnt]);
642 pItems[index].a.s.uBidiLevel = levels[cnt];
644 else if ((New_Script == Script_Arabic) ||
645 (New_Script == Script_Hebrew))
647 pItems[index].a.s.uBidiLevel = 1;
648 pItems[index].a.fRTL = 1;
649 pItems[index].a.fLayoutRTL = 1;
651 pItems[index].a.eScript = New_Script;
653 TRACE("index=%d cnt=%d iCharPos=%d\n", index, cnt, pItems[index].iCharPos);
657 /* While not strictly necessary according to the spec, make sure the n+1
658 * item is set up to prevent random behaviour if the caller erroneously
659 * checks the n+1 structure */
660 memset(&pItems[index+1].a, 0, sizeof(SCRIPT_ANALYSIS));
662 TRACE("index=%d cnt=%d iCharPos=%d\n", index+1, cnt, pItems[index+1].iCharPos);
664 /* Set one SCRIPT_STATE item being returned */
665 if (pcItems) *pcItems = index + 1;
667 /* Set SCRIPT_ITEM */
668 pItems[index+1].iCharPos = cnt; /* the last + 1 item
669 contains the ptr to the lastchar */
670 heap_free(levels);
671 return S_OK;
674 /***********************************************************************
675 * ScriptStringAnalyse (USP10.@)
678 HRESULT WINAPI ScriptStringAnalyse(HDC hdc, const void *pString, int cString,
679 int cGlyphs, int iCharset, DWORD dwFlags,
680 int iReqWidth, SCRIPT_CONTROL *psControl,
681 SCRIPT_STATE *psState, const int *piDx,
682 SCRIPT_TABDEF *pTabdef, const BYTE *pbInClass,
683 SCRIPT_STRING_ANALYSIS *pssa)
685 HRESULT hr = E_OUTOFMEMORY;
686 StringAnalysis *analysis = NULL;
687 int i, num_items = 255;
689 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
690 hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth,
691 psControl, psState, piDx, pTabdef, pbInClass, pssa);
693 if (iCharset != -1)
695 FIXME("Only Unicode strings are supported\n");
696 return E_INVALIDARG;
698 if (cString < 1 || !pString) return E_INVALIDARG;
699 if ((dwFlags & SSA_GLYPHS) && !hdc) return E_PENDING;
701 if (!(analysis = heap_alloc_zero(sizeof(StringAnalysis)))) return E_OUTOFMEMORY;
702 if (!(analysis->pItem = heap_alloc_zero(num_items * sizeof(SCRIPT_ITEM) + 1))) goto error;
704 /* FIXME: handle clipping */
705 analysis->clip_len = cString;
706 analysis->hdc = hdc;
708 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
709 &analysis->numItems);
711 while (hr == E_OUTOFMEMORY)
713 SCRIPT_ITEM *tmp;
715 num_items *= 2;
716 if (!(tmp = heap_realloc_zero(analysis->pItem, num_items * sizeof(SCRIPT_ITEM) + 1)))
717 goto error;
719 analysis->pItem = tmp;
720 hr = ScriptItemize(pString, cString, num_items, psControl, psState, analysis->pItem,
721 &analysis->numItems);
723 if (hr != S_OK) goto error;
725 if ((analysis->logattrs = heap_alloc(sizeof(SCRIPT_LOGATTR) * cString)))
726 ScriptBreak(pString, cString, (SCRIPT_STRING_ANALYSIS)analysis, analysis->logattrs);
727 else
728 goto error;
730 if (!(analysis->glyphs = heap_alloc_zero(sizeof(StringGlyphs) * analysis->numItems)))
731 goto error;
733 for (i = 0; i < analysis->numItems; i++)
735 SCRIPT_CACHE *sc = (SCRIPT_CACHE *)&analysis->sc;
736 int cChar = analysis->pItem[i+1].iCharPos - analysis->pItem[i].iCharPos;
737 int numGlyphs = 1.5 * cChar + 16;
738 WORD *glyphs = heap_alloc_zero(sizeof(WORD) * numGlyphs);
739 WORD *pwLogClust = heap_alloc_zero(sizeof(WORD) * cChar);
740 int *piAdvance = heap_alloc_zero(sizeof(int) * numGlyphs);
741 SCRIPT_VISATTR *psva = heap_alloc_zero(sizeof(SCRIPT_VISATTR) * cChar);
742 GOFFSET *pGoffset = heap_alloc_zero(sizeof(GOFFSET) * numGlyphs);
743 ABC *abc = heap_alloc_zero(sizeof(ABC));
744 int numGlyphsReturned;
746 /* FIXME: non unicode strings */
747 const WCHAR* pStr = (const WCHAR*)pString;
748 hr = ScriptShape(hdc, sc, &pStr[analysis->pItem[i].iCharPos],
749 cChar, numGlyphs, &analysis->pItem[i].a,
750 glyphs, pwLogClust, psva, &numGlyphsReturned);
751 hr = ScriptPlace(hdc, sc, glyphs, numGlyphsReturned, psva, &analysis->pItem[i].a,
752 piAdvance, pGoffset, abc);
754 analysis->glyphs[i].numGlyphs = numGlyphsReturned;
755 analysis->glyphs[i].glyphs = glyphs;
756 analysis->glyphs[i].pwLogClust = pwLogClust;
757 analysis->glyphs[i].piAdvance = piAdvance;
758 analysis->glyphs[i].psva = psva;
759 analysis->glyphs[i].pGoffset = pGoffset;
760 analysis->glyphs[i].abc = abc;
763 *pssa = analysis;
764 return S_OK;
766 error:
767 heap_free(analysis->glyphs);
768 heap_free(analysis->logattrs);
769 heap_free(analysis->pItem);
770 heap_free(analysis->sc);
771 heap_free(analysis);
772 return hr;
775 /***********************************************************************
776 * ScriptStringOut (USP10.@)
778 * This function takes the output of ScriptStringAnalyse and joins the segments
779 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
780 * only processes glyphs.
782 * Parameters:
783 * ssa [I] buffer to hold the analysed string components
784 * iX [I] X axis displacement for output
785 * iY [I] Y axis displacement for output
786 * uOptions [I] flags controling output processing
787 * prc [I] rectangle coordinates
788 * iMinSel [I] starting pos for substringing output string
789 * iMaxSel [I] ending pos for substringing output string
790 * fDisabled [I] controls text highlighting
792 * RETURNS
793 * Success: S_OK
794 * Failure: is the value returned by ScriptTextOut
796 HRESULT WINAPI ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa,
797 int iX,
798 int iY,
799 UINT uOptions,
800 const RECT *prc,
801 int iMinSel,
802 int iMaxSel,
803 BOOL fDisabled)
805 StringAnalysis *analysis;
806 WORD *glyphs;
807 int item, cnt, x;
808 HRESULT hr;
810 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
811 ssa, iX, iY, uOptions, prc, iMinSel, iMaxSel, fDisabled);
813 if (!(analysis = ssa)) return E_INVALIDARG;
816 * Get storage for the output buffer for the consolidated strings
818 cnt = 0;
819 for (item = 0; item < analysis->numItems; item++)
821 cnt += analysis->glyphs[item].numGlyphs;
823 if (!(glyphs = heap_alloc(sizeof(WCHAR) * cnt))) return E_OUTOFMEMORY;
826 * ScriptStringOut only processes glyphs hence set ETO_GLYPH_INDEX
828 uOptions |= ETO_GLYPH_INDEX;
829 analysis->pItem[0].a.fNoGlyphIndex = FALSE; /* say that we have glyphs */
832 * Copy the string items into the output buffer
835 TRACE("numItems %d\n", analysis->numItems);
837 cnt = 0;
838 for (item = 0; item < analysis->numItems; item++)
840 memcpy(&glyphs[cnt], analysis->glyphs[item].glyphs,
841 sizeof(WCHAR) * analysis->glyphs[item].numGlyphs);
843 TRACE("Item %d, Glyphs %d ", item, analysis->glyphs[item].numGlyphs);
844 for (x = cnt; x < analysis->glyphs[item].numGlyphs + cnt; x ++)
845 TRACE("%04x", glyphs[x]);
846 TRACE("\n");
848 cnt += analysis->glyphs[item].numGlyphs; /* point to the end of the copied text */
851 hr = ScriptTextOut(analysis->hdc, (SCRIPT_CACHE *)&analysis->sc, iX, iY,
852 uOptions, prc, &analysis->pItem->a, NULL, 0, glyphs, cnt,
853 analysis->glyphs->piAdvance, NULL, analysis->glyphs->pGoffset);
854 TRACE("ScriptTextOut hr=%08x\n", hr);
857 * Free the output buffer and script cache
859 heap_free(glyphs);
860 return hr;
863 /***********************************************************************
864 * ScriptStringCPtoX (USP10.@)
867 HRESULT WINAPI ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa, int icp, BOOL fTrailing, int* pX)
869 int i, j;
870 int runningX = 0;
871 int runningCp = 0;
872 StringAnalysis* analysis = ssa;
874 TRACE("(%p), %d, %d, (%p)\n", ssa, icp, fTrailing, pX);
876 if (!ssa || !pX) return S_FALSE;
878 /* icp out of range */
879 if(icp < 0)
881 analysis->invalid = TRUE;
882 return E_INVALIDARG;
885 for(i=0; i<analysis->numItems; i++)
887 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
889 if(runningCp == icp && fTrailing == FALSE)
891 *pX = runningX;
892 return S_OK;
894 runningX += analysis->glyphs[i].piAdvance[j];
895 if(runningCp == icp && fTrailing == TRUE)
897 *pX = runningX;
898 return S_OK;
900 runningCp++;
904 /* icp out of range */
905 analysis->invalid = TRUE;
906 return E_INVALIDARG;
909 /***********************************************************************
910 * ScriptStringXtoCP (USP10.@)
913 HRESULT WINAPI ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa, int iX, int* piCh, int* piTrailing)
915 StringAnalysis* analysis = ssa;
916 int i;
917 int j;
918 int runningX = 0;
919 int runningCp = 0;
920 int width;
922 TRACE("(%p), %d, (%p), (%p)\n", ssa, iX, piCh, piTrailing);
924 if (!ssa || !piCh || !piTrailing) return S_FALSE;
926 /* out of range */
927 if(iX < 0)
929 *piCh = -1;
930 *piTrailing = TRUE;
931 return S_OK;
934 for(i=0; i<analysis->numItems; i++)
936 for(j=0; j<analysis->glyphs[i].numGlyphs; j++)
938 width = analysis->glyphs[i].piAdvance[j];
939 if(iX < (runningX + width))
941 *piCh = runningCp;
942 if((iX - runningX) > width/2)
943 *piTrailing = TRUE;
944 else
945 *piTrailing = FALSE;
946 return S_OK;
948 runningX += width;
949 runningCp++;
953 /* out of range */
954 *piCh = analysis->pItem[analysis->numItems].iCharPos;
955 *piTrailing = FALSE;
957 return S_OK;
961 /***********************************************************************
962 * ScriptStringFree (USP10.@)
964 * Free a string analysis.
966 * PARAMS
967 * pssa [I] string analysis.
969 * RETURNS
970 * Success: S_OK
971 * Failure: Non-zero HRESULT value.
973 HRESULT WINAPI ScriptStringFree(SCRIPT_STRING_ANALYSIS *pssa)
975 StringAnalysis* analysis;
976 BOOL invalid;
977 int i;
979 TRACE("(%p)\n", pssa);
981 if (!pssa || !(analysis = *pssa)) return E_INVALIDARG;
983 invalid = analysis->invalid;
984 ScriptFreeCache((SCRIPT_CACHE *)&analysis->sc);
986 for (i = 0; i < analysis->numItems; i++)
988 heap_free(analysis->glyphs[i].glyphs);
989 heap_free(analysis->glyphs[i].pwLogClust);
990 heap_free(analysis->glyphs[i].piAdvance);
991 heap_free(analysis->glyphs[i].psva);
992 heap_free(analysis->glyphs[i].pGoffset);
993 heap_free(analysis->glyphs[i].abc);
996 heap_free(analysis->glyphs);
997 heap_free(analysis->pItem);
998 heap_free(analysis->logattrs);
999 heap_free(analysis->sz);
1000 heap_free(analysis->sc);
1001 heap_free(analysis);
1003 if (invalid) return E_INVALIDARG;
1004 return S_OK;
1007 /***********************************************************************
1008 * ScriptCPtoX (USP10.@)
1011 HRESULT WINAPI ScriptCPtoX(int iCP,
1012 BOOL fTrailing,
1013 int cChars,
1014 int cGlyphs,
1015 const WORD *pwLogClust,
1016 const SCRIPT_VISATTR *psva,
1017 const int *piAdvance,
1018 const SCRIPT_ANALYSIS *psa,
1019 int *piX)
1021 int item;
1022 int iPosX;
1023 float fMaxPosX = 0;
1024 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1025 iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1026 psa, piX);
1027 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1028 fMaxPosX += piAdvance[item];
1029 iPosX = (fMaxPosX/cGlyphs)*(iCP+fTrailing);
1030 if (iPosX > fMaxPosX)
1031 iPosX = fMaxPosX;
1032 *piX = iPosX; /* Return something in range */
1034 TRACE("*piX=%d\n", *piX);
1035 return S_OK;
1038 /***********************************************************************
1039 * ScriptXtoCP (USP10.@)
1042 HRESULT WINAPI ScriptXtoCP(int iX,
1043 int cChars,
1044 int cGlyphs,
1045 const WORD *pwLogClust,
1046 const SCRIPT_VISATTR *psva,
1047 const int *piAdvance,
1048 const SCRIPT_ANALYSIS *psa,
1049 int *piCP,
1050 int *piTrailing)
1052 int item;
1053 int iPosX;
1054 float fMaxPosX = 1;
1055 float fAvePosX;
1056 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1057 iX, cChars, cGlyphs, pwLogClust, psva, piAdvance,
1058 psa, piCP, piTrailing);
1059 if (iX < 0) /* iX is before start of run */
1061 *piCP = -1;
1062 *piTrailing = TRUE;
1063 return S_OK;
1066 for (item=0; item < cGlyphs; item++) /* total piAdvance */
1067 fMaxPosX += piAdvance[item];
1069 if (iX >= fMaxPosX) /* iX too large */
1071 *piCP = cChars;
1072 *piTrailing = FALSE;
1073 return S_OK;
1076 fAvePosX = fMaxPosX / cGlyphs;
1077 iPosX = fAvePosX;
1078 for (item = 1; item < cGlyphs && iPosX < iX; item++)
1079 iPosX += fAvePosX;
1080 if (iPosX - iX > fAvePosX/2)
1081 *piTrailing = 0;
1082 else
1083 *piTrailing = 1; /* yep we are over halfway */
1085 *piCP = item -1; /* Return character position */
1086 TRACE("*piCP=%d iPposX=%d\n", *piCP, iPosX);
1087 return S_OK;
1090 /***********************************************************************
1091 * ScriptBreak (USP10.@)
1093 * Retrieve line break information.
1095 * PARAMS
1096 * chars [I] Array of characters.
1097 * sa [I] String analysis.
1098 * la [I] Array of logical attribute structures.
1100 * RETURNS
1101 * Success: S_OK
1102 * Failure: S_FALSE
1104 HRESULT WINAPI ScriptBreak(const WCHAR *chars, int count, const SCRIPT_ANALYSIS *sa, SCRIPT_LOGATTR *la)
1106 int i;
1108 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars, count), count, sa, la);
1110 if (!la) return S_FALSE;
1112 for (i = 0; i < count; i++)
1114 memset(&la[i], 0, sizeof(SCRIPT_LOGATTR));
1116 /* FIXME: set the other flags */
1117 la[i].fWhiteSpace = (chars[i] == ' ');
1118 la[i].fCharStop = 1;
1120 if (i > 0 && la[i - 1].fWhiteSpace)
1122 la[i].fSoftBreak = 1;
1123 la[i].fWordStop = 1;
1126 return S_OK;
1129 static const struct
1131 WCHAR start;
1132 WCHAR end;
1133 DWORD flag;
1135 complex_ranges[] =
1137 { 0, 0x0b, SIC_COMPLEX },
1138 { 0x0c, 0x0c, SIC_NEUTRAL },
1139 { 0x0d, 0x1f, SIC_COMPLEX },
1140 { 0x20, 0x2f, SIC_NEUTRAL },
1141 { 0x30, 0x39, SIC_ASCIIDIGIT },
1142 { 0x3a, 0x40, SIC_NEUTRAL },
1143 { 0x5b, 0x60, SIC_NEUTRAL },
1144 { 0x7b, 0x7e, SIC_NEUTRAL },
1145 { 0x7f, 0x9f, SIC_COMPLEX },
1146 { 0xa0, 0xa5, SIC_NEUTRAL },
1147 { 0xa7, 0xa8, SIC_NEUTRAL },
1148 { 0xab, 0xab, SIC_NEUTRAL },
1149 { 0xad, 0xad, SIC_NEUTRAL },
1150 { 0xaf, 0xaf, SIC_NEUTRAL },
1151 { 0xb0, 0xb1, SIC_NEUTRAL },
1152 { 0xb4, 0xb4, SIC_NEUTRAL },
1153 { 0xb6, 0xb8, SIC_NEUTRAL },
1154 { 0xbb, 0xbf, SIC_NEUTRAL },
1155 { 0xd7, 0xd7, SIC_NEUTRAL },
1156 { 0xf7, 0xf7, SIC_NEUTRAL },
1157 { 0x2b9, 0x2ba, SIC_NEUTRAL },
1158 { 0x2c2, 0x2cf, SIC_NEUTRAL },
1159 { 0x2d2, 0x2df, SIC_NEUTRAL },
1160 { 0x2e5, 0x2e9, SIC_COMPLEX },
1161 { 0x2ea, 0x2ed, SIC_NEUTRAL },
1162 { 0x300, 0x362, SIC_COMPLEX },
1163 { 0x530, 0x60b, SIC_COMPLEX },
1164 { 0x60c, 0x60d, SIC_NEUTRAL },
1165 { 0x60e, 0x669, SIC_COMPLEX },
1166 { 0x66a, 0x66a, SIC_NEUTRAL },
1167 { 0x66b, 0x6e8, SIC_COMPLEX },
1168 { 0x6e9, 0x6e9, SIC_NEUTRAL },
1169 { 0x6ea, 0x7bf, SIC_COMPLEX },
1170 { 0x900, 0x1360, SIC_COMPLEX },
1171 { 0x137d, 0x137f, SIC_COMPLEX },
1172 { 0x1680, 0x1680, SIC_NEUTRAL },
1173 { 0x1780, 0x18af, SIC_COMPLEX },
1174 { 0x2000, 0x200a, SIC_NEUTRAL },
1175 { 0x200b, 0x200f, SIC_COMPLEX },
1176 { 0x2010, 0x2016, SIC_NEUTRAL },
1177 { 0x2018, 0x2022, SIC_NEUTRAL },
1178 { 0x2024, 0x2028, SIC_NEUTRAL },
1179 { 0x2029, 0x202e, SIC_COMPLEX },
1180 { 0x202f, 0x2037, SIC_NEUTRAL },
1181 { 0x2039, 0x203c, SIC_NEUTRAL },
1182 { 0x2044, 0x2046, SIC_NEUTRAL },
1183 { 0x206a, 0x206f, SIC_COMPLEX },
1184 { 0x207a, 0x207e, SIC_NEUTRAL },
1185 { 0x208a, 0x20aa, SIC_NEUTRAL },
1186 { 0x20ac, 0x20cf, SIC_NEUTRAL },
1187 { 0x20d0, 0x20ff, SIC_COMPLEX },
1188 { 0x2103, 0x2103, SIC_NEUTRAL },
1189 { 0x2105, 0x2105, SIC_NEUTRAL },
1190 { 0x2109, 0x2109, SIC_NEUTRAL },
1191 { 0x2116, 0x2116, SIC_NEUTRAL },
1192 { 0x2121, 0x2122, SIC_NEUTRAL },
1193 { 0x212e, 0x212e, SIC_NEUTRAL },
1194 { 0x2153, 0x2154, SIC_NEUTRAL },
1195 { 0x215b, 0x215e, SIC_NEUTRAL },
1196 { 0x2190, 0x2199, SIC_NEUTRAL },
1197 { 0x21b8, 0x21b9, SIC_NEUTRAL },
1198 { 0x21d2, 0x21d2, SIC_NEUTRAL },
1199 { 0x21d4, 0x21d4, SIC_NEUTRAL },
1200 { 0x21e7, 0x21e7, SIC_NEUTRAL },
1201 { 0x2200, 0x2200, SIC_NEUTRAL },
1202 { 0x2202, 0x2203, SIC_NEUTRAL },
1203 { 0x2207, 0x2208, SIC_NEUTRAL },
1204 { 0x220b, 0x220b, SIC_NEUTRAL },
1205 { 0x220f, 0x220f, SIC_NEUTRAL },
1206 { 0x2211, 0x2213, SIC_NEUTRAL },
1207 { 0x2215, 0x2215, SIC_NEUTRAL },
1208 { 0x221a, 0x221a, SIC_NEUTRAL },
1209 { 0x221d, 0x2220, SIC_NEUTRAL },
1210 { 0x2223, 0x2223, SIC_NEUTRAL },
1211 { 0x2225, 0x2225, SIC_NEUTRAL },
1212 { 0x2227, 0x222c, SIC_NEUTRAL },
1213 { 0x222e, 0x222e, SIC_NEUTRAL },
1214 { 0x2234, 0x2237, SIC_NEUTRAL },
1215 { 0x223c, 0x223d, SIC_NEUTRAL },
1216 { 0x2248, 0x2248, SIC_NEUTRAL },
1217 { 0x224c, 0x224c, SIC_NEUTRAL },
1218 { 0x2252, 0x2252, SIC_NEUTRAL },
1219 { 0x2260, 0x2261, SIC_NEUTRAL },
1220 { 0x2264, 0x2267, SIC_NEUTRAL },
1221 { 0x226a, 0x226b, SIC_NEUTRAL },
1222 { 0x226e, 0x226f, SIC_NEUTRAL },
1223 { 0x2282, 0x2283, SIC_NEUTRAL },
1224 { 0x2286, 0x2287, SIC_NEUTRAL },
1225 { 0x2295, 0x2295, SIC_NEUTRAL },
1226 { 0x2299, 0x2299, SIC_NEUTRAL },
1227 { 0x22a5, 0x22a5, SIC_NEUTRAL },
1228 { 0x22bf, 0x22bf, SIC_NEUTRAL },
1229 { 0x2312, 0x2312, SIC_NEUTRAL },
1230 { 0x24ea, 0x24ea, SIC_COMPLEX },
1231 { 0x2500, 0x254b, SIC_NEUTRAL },
1232 { 0x2550, 0x256d, SIC_NEUTRAL },
1233 { 0x256e, 0x2574, SIC_NEUTRAL },
1234 { 0x2581, 0x258f, SIC_NEUTRAL },
1235 { 0x2592, 0x2595, SIC_NEUTRAL },
1236 { 0x25a0, 0x25a1, SIC_NEUTRAL },
1237 { 0x25a3, 0x25a9, SIC_NEUTRAL },
1238 { 0x25b2, 0x25b3, SIC_NEUTRAL },
1239 { 0x25b6, 0x25b7, SIC_NEUTRAL },
1240 { 0x25bc, 0x25bd, SIC_NEUTRAL },
1241 { 0x25c0, 0x25c1, SIC_NEUTRAL },
1242 { 0x25c6, 0x25c8, SIC_NEUTRAL },
1243 { 0x25cb, 0x25cb, SIC_NEUTRAL },
1244 { 0x25ce, 0x25d1, SIC_NEUTRAL },
1245 { 0x25e2, 0x25e5, SIC_NEUTRAL },
1246 { 0x25ef, 0x25ef, SIC_NEUTRAL },
1247 { 0x2605, 0x2606, SIC_NEUTRAL },
1248 { 0x2609, 0x2609, SIC_NEUTRAL },
1249 { 0x260e, 0x260f, SIC_NEUTRAL },
1250 { 0x261c, 0x261c, SIC_NEUTRAL },
1251 { 0x261e, 0x261e, SIC_NEUTRAL },
1252 { 0x2640, 0x2640, SIC_NEUTRAL },
1253 { 0x2642, 0x2642, SIC_NEUTRAL },
1254 { 0x2660, 0x2661, SIC_NEUTRAL },
1255 { 0x2663, 0x2665, SIC_NEUTRAL },
1256 { 0x2667, 0x266a, SIC_NEUTRAL },
1257 { 0x266c, 0x266d, SIC_NEUTRAL },
1258 { 0x266f, 0x266f, SIC_NEUTRAL },
1259 { 0x273d, 0x273d, SIC_NEUTRAL },
1260 { 0x2e80, 0x312f, SIC_COMPLEX },
1261 { 0x3190, 0x31bf, SIC_COMPLEX },
1262 { 0x31f0, 0x31ff, SIC_COMPLEX },
1263 { 0x3220, 0x325f, SIC_COMPLEX },
1264 { 0x3280, 0xa4ff, SIC_COMPLEX },
1265 { 0xd800, 0xdfff, SIC_COMPLEX },
1266 { 0xe000, 0xf8ff, SIC_NEUTRAL },
1267 { 0xf900, 0xfaff, SIC_COMPLEX },
1268 { 0xfb13, 0xfb28, SIC_COMPLEX },
1269 { 0xfb29, 0xfb29, SIC_NEUTRAL },
1270 { 0xfb2a, 0xfb4f, SIC_COMPLEX },
1271 { 0xfd3e, 0xfd3f, SIC_NEUTRAL },
1272 { 0xfdd0, 0xfdef, SIC_COMPLEX },
1273 { 0xfe20, 0xfe6f, SIC_COMPLEX },
1274 { 0xfeff, 0xfeff, SIC_COMPLEX },
1275 { 0xff01, 0xff5e, SIC_COMPLEX },
1276 { 0xff61, 0xff9f, SIC_COMPLEX },
1277 { 0xffe0, 0xffe6, SIC_COMPLEX },
1278 { 0xffe8, 0xffee, SIC_COMPLEX },
1279 { 0xfff9, 0xfffb, SIC_COMPLEX },
1280 { 0xfffe, 0xfffe, SIC_COMPLEX }
1283 /***********************************************************************
1284 * ScriptIsComplex (USP10.@)
1286 * Determine if a string is complex.
1288 * PARAMS
1289 * chars [I] Array of characters to test.
1290 * len [I] Length in characters.
1291 * flag [I] Flag.
1293 * RETURNS
1294 * Success: S_OK
1295 * Failure: S_FALSE
1297 * NOTES
1298 * Behaviour matches that of WinXP.
1300 HRESULT WINAPI ScriptIsComplex(const WCHAR *chars, int len, DWORD flag)
1302 int i;
1303 unsigned int j;
1305 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars, len), len, flag);
1307 for (i = 0; i < len; i++)
1309 for (j = 0; j < sizeof(complex_ranges)/sizeof(complex_ranges[0]); j++)
1311 if (chars[i] >= complex_ranges[j].start &&
1312 chars[i] <= complex_ranges[j].end &&
1313 (flag & complex_ranges[j].flag)) return S_OK;
1316 return S_FALSE;
1319 /***********************************************************************
1320 * ScriptShape (USP10.@)
1322 * Produce glyphs and visual attributes for a run.
1324 * PARAMS
1325 * hdc [I] Device context.
1326 * psc [I/O] Opaque pointer to a script cache.
1327 * pwcChars [I] Array of characters specifying the run.
1328 * cChars [I] Number of characters in pwcChars.
1329 * cMaxGlyphs [I] Length of pwOutGlyphs.
1330 * psa [I/O] Script analysis.
1331 * pwOutGlyphs [O] Array of glyphs.
1332 * pwLogClust [O] Array of logical cluster info.
1333 * psva [O] Array of visual attributes.
1334 * pcGlyphs [O] Number of glyphs returned.
1336 * RETURNS
1337 * Success: S_OK
1338 * Failure: Non-zero HRESULT value.
1340 HRESULT WINAPI ScriptShape(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcChars,
1341 int cChars, int cMaxGlyphs,
1342 SCRIPT_ANALYSIS *psa, WORD *pwOutGlyphs, WORD *pwLogClust,
1343 SCRIPT_VISATTR *psva, int *pcGlyphs)
1345 HRESULT hr;
1346 unsigned int i;
1347 BOOL rtl;
1349 TRACE("(%p, %p, %s, %d, %d, %p, %p, %p, %p, %p)\n", hdc, psc, debugstr_wn(pwcChars, cChars),
1350 cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs);
1352 if (psa) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa->eScript, psa->fRTL, psa->fLayoutRTL,
1353 psa->fLinkBefore, psa->fLinkAfter, psa->fLogicalOrder, psa->fNoGlyphIndex);
1355 if (!psva || !pcGlyphs) return E_INVALIDARG;
1356 if (cChars > cMaxGlyphs) return E_OUTOFMEMORY;
1357 rtl = (!psa->fLogicalOrder && psa->fRTL);
1359 *pcGlyphs = cChars;
1360 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1361 if (!pwLogClust) return E_FAIL;
1363 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1365 for (i = 0; i < cChars; i++)
1367 int idx = i;
1368 if (rtl) idx = cChars - 1 - i;
1369 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcChars[idx])))
1371 WORD glyph;
1372 if (!hdc) return E_PENDING;
1373 if (GetGlyphIndicesW(hdc, &pwcChars[idx], 1, &glyph, 0) == GDI_ERROR) return S_FALSE;
1374 pwOutGlyphs[i] = set_cache_glyph(psc, pwcChars[idx], glyph);
1378 else
1380 TRACE("no glyph translation\n");
1381 for (i = 0; i < cChars; i++)
1383 int idx = i;
1384 if (rtl) idx = cChars - 1 - i;
1385 pwOutGlyphs[i] = pwcChars[idx];
1389 /* set up a valid SCRIPT_VISATTR and LogClust for each char in this run */
1390 for (i = 0; i < cChars; i++)
1392 int idx = i;
1393 if (rtl) idx = cChars - 1 - i;
1394 /* FIXME: set to better values */
1395 psva[i].uJustification = (pwcChars[idx] == ' ') ? SCRIPT_JUSTIFY_BLANK : SCRIPT_JUSTIFY_CHARACTER;
1396 psva[i].fClusterStart = 1;
1397 psva[i].fDiacritic = 0;
1398 psva[i].fZeroWidth = 0;
1399 psva[i].fReserved = 0;
1400 psva[i].fShapeReserved = 0;
1402 pwLogClust[i] = idx;
1404 return S_OK;
1407 /***********************************************************************
1408 * ScriptPlace (USP10.@)
1410 * Produce advance widths for a run.
1412 * PARAMS
1413 * hdc [I] Device context.
1414 * psc [I/O] Opaque pointer to a script cache.
1415 * pwGlyphs [I] Array of glyphs.
1416 * cGlyphs [I] Number of glyphs in pwGlyphs.
1417 * psva [I] Array of visual attributes.
1418 * psa [I/O] String analysis.
1419 * piAdvance [O] Array of advance widths.
1420 * pGoffset [O] Glyph offsets.
1421 * pABC [O] Combined ABC width.
1423 * RETURNS
1424 * Success: S_OK
1425 * Failure: Non-zero HRESULT value.
1427 HRESULT WINAPI ScriptPlace(HDC hdc, SCRIPT_CACHE *psc, const WORD *pwGlyphs,
1428 int cGlyphs, const SCRIPT_VISATTR *psva,
1429 SCRIPT_ANALYSIS *psa, int *piAdvance, GOFFSET *pGoffset, ABC *pABC )
1431 HRESULT hr;
1432 int i;
1434 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc, psc, pwGlyphs, cGlyphs, psva, psa,
1435 piAdvance, pGoffset, pABC);
1437 if (!psva) return E_INVALIDARG;
1438 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1439 if (!pGoffset) return E_FAIL;
1441 if (pABC) memset(pABC, 0, sizeof(ABC));
1442 for (i = 0; i < cGlyphs; i++)
1444 ABC abc;
1445 if (!get_cache_glyph_widths(psc, pwGlyphs[i], &abc))
1447 if (!hdc) return E_PENDING;
1448 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE) && !psa->fNoGlyphIndex)
1450 if (!GetCharABCWidthsI(hdc, 0, 1, (WORD *)&pwGlyphs[i], &abc)) return S_FALSE;
1452 else
1454 INT width;
1455 if (!GetCharWidth32W(hdc, pwGlyphs[i], pwGlyphs[i], &width)) return S_FALSE;
1456 abc.abcB = width;
1457 abc.abcA = abc.abcC = 0;
1459 set_cache_glyph_widths(psc, pwGlyphs[i], &abc);
1461 if (pABC)
1463 pABC->abcA += abc.abcA;
1464 pABC->abcB += abc.abcB;
1465 pABC->abcC += abc.abcC;
1467 /* FIXME: set to more reasonable values */
1468 pGoffset[i].du = pGoffset[i].dv = 0;
1469 if (piAdvance) piAdvance[i] = abc.abcA + abc.abcB + abc.abcC;
1472 if (pABC) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC->abcA, pABC->abcB, pABC->abcC);
1473 return S_OK;
1476 /***********************************************************************
1477 * ScriptGetCMap (USP10.@)
1479 * Retrieve glyph indices.
1481 * PARAMS
1482 * hdc [I] Device context.
1483 * psc [I/O] Opaque pointer to a script cache.
1484 * pwcInChars [I] Array of Unicode characters.
1485 * cChars [I] Number of characters in pwcInChars.
1486 * dwFlags [I] Flags.
1487 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
1489 * RETURNS
1490 * Success: S_OK
1491 * Failure: Non-zero HRESULT value.
1493 HRESULT WINAPI ScriptGetCMap(HDC hdc, SCRIPT_CACHE *psc, const WCHAR *pwcInChars,
1494 int cChars, DWORD dwFlags, WORD *pwOutGlyphs)
1496 HRESULT hr;
1497 int i;
1499 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc, psc, debugstr_wn(pwcInChars, cChars),
1500 cChars, dwFlags, pwOutGlyphs);
1502 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1504 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1506 for (i = 0; i < cChars; i++)
1508 if (!(pwOutGlyphs[i] = get_cache_glyph(psc, pwcInChars[i])))
1510 WORD glyph;
1511 if (!hdc) return E_PENDING;
1512 if (GetGlyphIndicesW(hdc, &pwcInChars[i], 1, &glyph, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) return S_FALSE;
1513 pwOutGlyphs[i] = set_cache_glyph(psc, pwcInChars[i], glyph);
1517 else
1519 TRACE("no glyph translation\n");
1520 for (i = 0; i < cChars; i++) pwOutGlyphs[i] = pwcInChars[i];
1522 return S_OK;
1525 /***********************************************************************
1526 * ScriptTextOut (USP10.@)
1529 HRESULT WINAPI ScriptTextOut(const HDC hdc, SCRIPT_CACHE *psc, int x, int y, UINT fuOptions,
1530 const RECT *lprc, const SCRIPT_ANALYSIS *psa, const WCHAR *pwcReserved,
1531 int iReserved, const WORD *pwGlyphs, int cGlyphs, const int *piAdvance,
1532 const int *piJustify, const GOFFSET *pGoffset)
1534 HRESULT hr = S_OK;
1536 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
1537 hdc, psc, x, y, fuOptions, lprc, psa, pwcReserved, iReserved, pwGlyphs, cGlyphs,
1538 piAdvance, piJustify, pGoffset);
1540 if (!hdc || !psc) return E_INVALIDARG;
1541 if (!piAdvance || !psa || !pwGlyphs) return E_INVALIDARG;
1543 fuOptions &= ETO_CLIPPED + ETO_OPAQUE;
1544 if (!psa->fNoGlyphIndex) /* Have Glyphs? */
1545 fuOptions |= ETO_GLYPH_INDEX; /* Say don't do translation to glyph */
1547 if (!ExtTextOutW(hdc, x, y, fuOptions, lprc, pwGlyphs, cGlyphs, NULL))
1548 hr = S_FALSE;
1550 return hr;
1553 /***********************************************************************
1554 * ScriptCacheGetHeight (USP10.@)
1556 * Retrieve the height of the font in the cache.
1558 * PARAMS
1559 * hdc [I] Device context.
1560 * psc [I/O] Opaque pointer to a script cache.
1561 * height [O] Receives font height.
1563 * RETURNS
1564 * Success: S_OK
1565 * Failure: Non-zero HRESULT value.
1567 HRESULT WINAPI ScriptCacheGetHeight(HDC hdc, SCRIPT_CACHE *psc, LONG *height)
1569 HRESULT hr;
1571 TRACE("(%p, %p, %p)\n", hdc, psc, height);
1573 if (!height) return E_INVALIDARG;
1574 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1576 *height = get_cache_height(psc);
1577 return S_OK;
1580 /***********************************************************************
1581 * ScriptGetGlyphABCWidth (USP10.@)
1583 * Retrieve the width of a glyph.
1585 * PARAMS
1586 * hdc [I] Device context.
1587 * psc [I/O] Opaque pointer to a script cache.
1588 * glyph [I] Glyph to retrieve the width for.
1589 * abc [O] ABC widths of the glyph.
1591 * RETURNS
1592 * Success: S_OK
1593 * Failure: Non-zero HRESULT value.
1595 HRESULT WINAPI ScriptGetGlyphABCWidth(HDC hdc, SCRIPT_CACHE *psc, WORD glyph, ABC *abc)
1597 HRESULT hr;
1599 TRACE("(%p, %p, 0x%04x, %p)\n", hdc, psc, glyph, abc);
1601 if (!abc) return E_INVALIDARG;
1602 if ((hr = init_script_cache(hdc, psc)) != S_OK) return hr;
1604 if (!get_cache_glyph_widths(psc, glyph, abc))
1606 if (!hdc) return E_PENDING;
1607 if ((get_cache_pitch_family(psc) & TMPF_TRUETYPE))
1609 if (!GetCharABCWidthsI(hdc, 0, 1, &glyph, abc)) return S_FALSE;
1611 else
1613 INT width;
1614 if (!GetCharWidth32W(hdc, glyph, glyph, &width)) return S_FALSE;
1615 abc->abcB = width;
1616 abc->abcA = abc->abcC = 0;
1618 set_cache_glyph_widths(psc, glyph, abc);
1620 return S_OK;
1623 /***********************************************************************
1624 * ScriptLayout (USP10.@)
1626 * Map embedding levels to visual and/or logical order.
1628 * PARAMS
1629 * runs [I] Size of level array.
1630 * level [I] Array of embedding levels.
1631 * vistolog [O] Map of embedding levels from visual to logical order.
1632 * logtovis [O] Map of embedding levels from logical to visual order.
1634 * RETURNS
1635 * Success: S_OK
1636 * Failure: Non-zero HRESULT value.
1638 * BUGS
1639 * This stub works correctly for any sequence of a single
1640 * embedding level but not for sequences of different
1641 * embedding levels, i.e. mixtures of RTL and LTR scripts.
1643 HRESULT WINAPI ScriptLayout(int runs, const BYTE *level, int *vistolog, int *logtovis)
1645 int* indexs;
1646 int ich;
1648 TRACE("(%d, %p, %p, %p)\n", runs, level, vistolog, logtovis);
1650 if (!level || (!vistolog && !logtovis))
1651 return E_INVALIDARG;
1653 indexs = heap_alloc(sizeof(int) * runs);
1654 if (!indexs)
1655 return E_OUTOFMEMORY;
1658 if (vistolog)
1660 for( ich = 0; ich < runs; ich++)
1661 indexs[ich] = ich;
1663 ich = 0;
1664 while (ich < runs)
1665 ich += BIDI_ReorderV2lLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1666 for (ich = 0; ich < runs; ich++)
1667 vistolog[ich] = indexs[ich];
1671 if (logtovis)
1673 for( ich = 0; ich < runs; ich++)
1674 indexs[ich] = ich;
1676 ich = 0;
1677 while (ich < runs)
1678 ich += BIDI_ReorderL2vLevel(0, indexs+ich, level+ich, runs - ich, FALSE);
1679 for (ich = 0; ich < runs; ich++)
1680 logtovis[ich] = indexs[ich];
1682 heap_free(indexs);
1684 return S_OK;
1687 /***********************************************************************
1688 * ScriptStringGetLogicalWidths (USP10.@)
1690 * Returns logical widths from a string analysis.
1692 * PARAMS
1693 * ssa [I] string analysis.
1694 * piDx [O] logical widths returned.
1696 * RETURNS
1697 * Success: S_OK
1698 * Failure: a non-zero HRESULT.
1700 HRESULT WINAPI ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa, int *piDx)
1702 int i, j, next = 0;
1703 StringAnalysis *analysis = ssa;
1705 TRACE("%p, %p\n", ssa, piDx);
1707 if (!analysis) return S_FALSE;
1709 for (i = 0; i < analysis->numItems; i++)
1711 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1713 piDx[next] = analysis->glyphs[i].piAdvance[j];
1714 next++;
1717 return S_OK;
1720 /***********************************************************************
1721 * ScriptStringValidate (USP10.@)
1723 * Validate a string analysis.
1725 * PARAMS
1726 * ssa [I] string analysis.
1728 * RETURNS
1729 * Success: S_OK
1730 * Failure: S_FALSE if invalid sequences are found
1731 * or a non-zero HRESULT if it fails.
1733 HRESULT WINAPI ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa)
1735 StringAnalysis *analysis = ssa;
1737 TRACE("(%p)\n", ssa);
1739 if (!analysis) return E_INVALIDARG;
1740 return (analysis->invalid) ? S_FALSE : S_OK;
1743 /***********************************************************************
1744 * ScriptString_pSize (USP10.@)
1746 * Retrieve width and height of an analysed string.
1748 * PARAMS
1749 * ssa [I] string analysis.
1751 * RETURNS
1752 * Success: Pointer to a SIZE structure.
1753 * Failure: NULL
1755 const SIZE * WINAPI ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa)
1757 int i, j;
1758 StringAnalysis *analysis = ssa;
1760 TRACE("(%p)\n", ssa);
1762 if (!analysis) return NULL;
1764 if (!analysis->sz)
1766 if (!(analysis->sz = heap_alloc(sizeof(SIZE)))) return NULL;
1767 analysis->sz->cy = analysis->sc->tm.tmHeight;
1769 analysis->sz->cx = 0;
1770 for (i = 0; i < analysis->numItems; i++)
1771 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++)
1772 analysis->sz->cx += analysis->glyphs[i].piAdvance[j];
1774 return analysis->sz;
1777 /***********************************************************************
1778 * ScriptString_pLogAttr (USP10.@)
1780 * Retrieve logical attributes of an analysed string.
1782 * PARAMS
1783 * ssa [I] string analysis.
1785 * RETURNS
1786 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
1787 * Failure: NULL
1789 const SCRIPT_LOGATTR * WINAPI ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa)
1791 StringAnalysis *analysis = ssa;
1793 TRACE("(%p)\n", ssa);
1795 if (!analysis) return NULL;
1796 return analysis->logattrs;
1799 /***********************************************************************
1800 * ScriptString_pcOutChars (USP10.@)
1802 * Retrieve the length of a string after clipping.
1804 * PARAMS
1805 * ssa [I] String analysis.
1807 * RETURNS
1808 * Success: Pointer to the length.
1809 * Failure: NULL
1811 const int * WINAPI ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa)
1813 StringAnalysis *analysis = ssa;
1815 TRACE("(%p)\n", ssa);
1817 if (!analysis) return NULL;
1818 return &analysis->clip_len;
1821 /***********************************************************************
1822 * ScriptStringGetOrder (USP10.@)
1824 * Retrieve a glyph order map.
1826 * PARAMS
1827 * ssa [I] String analysis.
1828 * order [I/O] Array of glyph positions.
1830 * RETURNS
1831 * Success: S_OK
1832 * Failure: a non-zero HRESULT.
1834 HRESULT WINAPI ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa, UINT *order)
1836 int i, j;
1837 unsigned int k;
1838 StringAnalysis *analysis = ssa;
1840 TRACE("(%p)\n", ssa);
1842 if (!analysis) return S_FALSE;
1844 /* FIXME: handle RTL scripts */
1845 for (i = 0, k = 0; i < analysis->numItems; i++)
1846 for (j = 0; j < analysis->glyphs[i].numGlyphs; j++, k++)
1847 order[k] = k;
1849 return S_OK;
1852 /***********************************************************************
1853 * ScriptGetLogicalWidths (USP10.@)
1855 * Convert advance widths to logical widths.
1857 * PARAMS
1858 * sa [I] Script analysis.
1859 * nbchars [I] Number of characters.
1860 * nbglyphs [I] Number of glyphs.
1861 * glyph_width [I] Array of glyph widths.
1862 * log_clust [I] Array of logical clusters.
1863 * sva [I] Visual attributes.
1864 * widths [O] Array of logical widths.
1866 * RETURNS
1867 * Success: S_OK
1868 * Failure: a non-zero HRESULT.
1870 HRESULT WINAPI ScriptGetLogicalWidths(const SCRIPT_ANALYSIS *sa, int nbchars, int nbglyphs,
1871 const int *glyph_width, const WORD *log_clust,
1872 const SCRIPT_VISATTR *sva, int *widths)
1874 int i;
1876 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
1877 sa, nbchars, nbglyphs, glyph_width, log_clust, sva, widths);
1879 /* FIXME */
1880 for (i = 0; i < nbchars; i++) widths[i] = glyph_width[i];
1881 return S_OK;
1884 /***********************************************************************
1885 * ScriptApplyLogicalWidth (USP10.@)
1887 * Generate glyph advance widths.
1889 * PARAMS
1890 * dx [I] Array of logical advance widths.
1891 * num_chars [I] Number of characters.
1892 * num_glyphs [I] Number of glyphs.
1893 * log_clust [I] Array of logical clusters.
1894 * sva [I] Visual attributes.
1895 * advance [I] Array of glyph advance widths.
1896 * sa [I] Script analysis.
1897 * abc [I/O] Summed ABC widths.
1898 * justify [O] Array of glyph advance widths.
1900 * RETURNS
1901 * Success: S_OK
1902 * Failure: a non-zero HRESULT.
1904 HRESULT WINAPI ScriptApplyLogicalWidth(const int *dx, int num_chars, int num_glyphs,
1905 const WORD *log_clust, const SCRIPT_VISATTR *sva,
1906 const int *advance, const SCRIPT_ANALYSIS *sa,
1907 ABC *abc, int *justify)
1909 int i;
1911 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
1912 dx, num_chars, num_glyphs, log_clust, sva, advance, sa, abc, justify);
1914 for (i = 0; i < num_chars; i++) justify[i] = advance[i];
1915 return S_OK;
1918 HRESULT WINAPI ScriptJustify(const SCRIPT_VISATTR *sva, const int *advance,
1919 int num_glyphs, int dx, int min_kashida, int *justify)
1921 int i;
1923 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva, advance, num_glyphs, dx, min_kashida, justify);
1925 for (i = 0; i < num_glyphs; i++) justify[i] = advance[i];
1926 return S_OK;