81e24bb4782848779a39ca4c126983d0be6461e3
[reactos.git] / rostests / winetests / usp10 / usp10.c
1 /*
2 * Tests for usp10 dll
3 *
4 * Copyright 2006 Jeff Latimer
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
7 *
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.
12 *
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.
17 *
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
21 *
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.
25 */
26
27 #include <assert.h>
28 #include <stdio.h>
29
30 #include <wine/test.h>
31 #include <winnls.h>
32 #include <wingdi.h>
33 #include <winuser.h>
34 //#include <windows.h>
35 #include <usp10.h>
36
37 typedef struct _itemTest {
38 char todo_flag[6];
39 int iCharPos;
40 int fRTL;
41 int fLayoutRTL;
42 int uBidiLevel;
43 int fOverrideDirection;
44 ULONG scriptTag;
45 BOOL isBroken;
46 int broken_value[6];
47 } itemTest;
48
49 typedef struct _shapeTest_char {
50 WORD wLogClust;
51 SCRIPT_CHARPROP CharProp;
52 } shapeTest_char;
53
54 typedef struct _shapeTest_glyph {
55 int Glyph;
56 SCRIPT_GLYPHPROP GlyphProp;
57 } shapeTest_glyph;
58
59 /* Uniscribe 1.6 calls */
60 static HRESULT (WINAPI *pScriptItemizeOpenType)( const WCHAR *pwcInChars, int cInChars, int cMaxItems, const SCRIPT_CONTROL *psControl, const SCRIPT_STATE *psState, SCRIPT_ITEM *pItems, ULONG *pScriptTags, int *pcItems);
61
62 static HRESULT (WINAPI *pScriptShapeOpenType)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int *rcRangeChars, TEXTRANGE_PROPERTIES **rpRangeProperties, int cRanges, const WCHAR *pwcChars, int cChars, int cMaxGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProps, WORD *pwOutGlyphs, SCRIPT_GLYPHPROP *pOutGlyphProps, int *pcGlyphs);
63
64 static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
65
66 static HRESULT (WINAPI *pScriptGetFontScriptTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags);
67 static HRESULT (WINAPI *pScriptGetFontLanguageTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, int cMaxTags, OPENTYPE_TAG *pLangSysTags, int *pcTags);
68 static HRESULT (WINAPI *pScriptGetFontFeatureTags)( HDC hdc, SCRIPT_CACHE *psc, SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript, OPENTYPE_TAG tagLangSys, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags);
69
70 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
71 SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
72 DWORD nItems, const itemTest* items, BOOL nItemsToDo,
73 const INT nItemsBroken[2])
74 {
75 HRESULT hr;
76 int x, outnItems;
77 SCRIPT_ITEM outpItems[15];
78 ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
79
80 if (pScriptItemizeOpenType)
81 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
82 else
83 hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
84
85 winetest_ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
86 if (nItemsBroken && (broken(nItemsBroken[0] == outnItems) || broken(nItemsBroken[1] == outnItems)))
87 {
88 winetest_win_skip("This test broken on this platform\n");
89 return;
90 }
91 todo_wine_if (nItemsToDo)
92 winetest_ok(outnItems == nItems, "Wrong number of items (%u)\n", outnItems);
93 outnItems = min(outnItems, nItems);
94 for (x = 0; x <= outnItems; x++)
95 {
96 if (items[x].isBroken && broken(outpItems[x].iCharPos == items[x].broken_value[0]))
97 winetest_win_skip("This test broken on this platform\n");
98 else todo_wine_if (items[x].todo_flag[0])
99 winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
100
101 if (items[x].isBroken && broken(outpItems[x].a.fRTL== items[x].broken_value[1]))
102 winetest_win_skip("This test broken on this platform\n");
103 else todo_wine_if (items[x].todo_flag[1])
104 winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
105
106 if (items[x].isBroken && broken(outpItems[x].a.fLayoutRTL == items[x].broken_value[2]))
107 winetest_win_skip("This test broken on this platform\n");
108 else todo_wine_if (items[x].todo_flag[2])
109 winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
110
111 if (items[x].isBroken && broken(outpItems[x].a.s.uBidiLevel == items[x].broken_value[3]))
112 winetest_win_skip("This test broken on this platform\n");
113 else todo_wine_if (items[x].todo_flag[3])
114 winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
115 if (x != outnItems)
116 winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
117 if (pScriptItemizeOpenType)
118 {
119 if (items[x].isBroken && broken(tags[x] == items[x].broken_value[4]))
120 winetest_win_skip("This test broken on this platform\n");
121 else todo_wine_if (items[x].todo_flag[4])
122 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
123 }
124
125 if (items[x].isBroken && broken(outpItems[x].a.s.fOverrideDirection == items[x].broken_value[5]))
126 winetest_win_skip("This test broken on this platform\n");
127 else todo_wine_if (items[x].todo_flag[5])
128 winetest_ok(outpItems[x].a.s.fOverrideDirection == items[x].fOverrideDirection, "%i:Wrong fOverrideDirection(%i)\n",x,outpItems[x].a.s.fOverrideDirection);
129 }
130 }
131
132 #define test_items_ok(a,b,c,d,e,f,g,h) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_items_ok(a,b,c,d,e,f,g,h)
133
134 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
135 ( ( (ULONG)_x4 << 24 ) | \
136 ( (ULONG)_x3 << 16 ) | \
137 ( (ULONG)_x2 << 8 ) | \
138 (ULONG)_x1 )
139
140 #define latn_tag MS_MAKE_TAG('l','a','t','n')
141 #define arab_tag MS_MAKE_TAG('a','r','a','b')
142 #define thai_tag MS_MAKE_TAG('t','h','a','i')
143 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
144 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
145 #define deva_tag MS_MAKE_TAG('d','e','v','a')
146 #define beng_tag MS_MAKE_TAG('b','e','n','g')
147 #define guru_tag MS_MAKE_TAG('g','u','r','u')
148 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
149 #define orya_tag MS_MAKE_TAG('o','r','y','a')
150 #define taml_tag MS_MAKE_TAG('t','a','m','l')
151 #define telu_tag MS_MAKE_TAG('t','e','l','u')
152 #define knda_tag MS_MAKE_TAG('k','n','d','a')
153 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
154 #define mymr_tag MS_MAKE_TAG('m','y','m','r')
155 #define tale_tag MS_MAKE_TAG('t','a','l','e')
156 #define talu_tag MS_MAKE_TAG('t','a','l','u')
157 #define khmr_tag MS_MAKE_TAG('k','h','m','r')
158 #define hani_tag MS_MAKE_TAG('h','a','n','i')
159 #define bopo_tag MS_MAKE_TAG('b','o','p','o')
160 #define kana_tag MS_MAKE_TAG('k','a','n','a')
161 #define hang_tag MS_MAKE_TAG('h','a','n','g')
162 #define yi_tag MS_MAKE_TAG('y','i',' ',' ')
163 #define ethi_tag MS_MAKE_TAG('e','t','h','i')
164 #define mong_tag MS_MAKE_TAG('m','o','n','g')
165 #define tfng_tag MS_MAKE_TAG('t','f','n','g')
166 #define nko_tag MS_MAKE_TAG('n','k','o',' ')
167 #define vai_tag MS_MAKE_TAG('v','a','i',' ')
168 #define cher_tag MS_MAKE_TAG('c','h','e','r')
169 #define cans_tag MS_MAKE_TAG('c','a','n','s')
170 #define ogam_tag MS_MAKE_TAG('o','g','a','m')
171 #define runr_tag MS_MAKE_TAG('r','u','n','r')
172 #define brai_tag MS_MAKE_TAG('b','r','a','i')
173 #define dsrt_tag MS_MAKE_TAG('d','s','r','t')
174 #define osma_tag MS_MAKE_TAG('o','s','m','a')
175 #define math_tag MS_MAKE_TAG('m','a','t','h')
176
177 static void test_ScriptItemize( void )
178 {
179 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
180 static const itemTest t11[2] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1}};
181 static const itemTest t12[2] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
182
183 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
184 static const itemTest t1b1[2] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
185 static const itemTest t1b2[2] = {{{0,0,0,0,0,0},0,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
186
187 static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
188 static const itemTest t1c1[2] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
189 static const itemTest t1c2[4] = {{{0,0,0,0,0,0},0,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},3,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},5,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
190
191 /* Arabic, English*/
192 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
193 static const itemTest t21[7] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},15,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
194 static const itemTest t22[5] = {{{0,0,0,0,0,0},0,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},15,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
195 static const itemTest t23[5] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},15,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
196 static const itemTest t24[5] = {{{0,0,0,0,0,0},0,0,0,0,1,0,FALSE},
197 {{0,0,0,0,0,0},6,0,0,0,1,arab_tag,FALSE},
198 {{0,0,0,0,0,0},13,0,1,0,1,0,FALSE},
199 {{0,0,0,0,0,0},15,0,0,0,1,0,FALSE},
200 {{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
201
202 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
203 static const itemTest t2b1[5] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},8,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
204 static const itemTest t2b2[5] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
205 static const itemTest t2b3[3] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
206 static const itemTest t2b4[5] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
207 {{0,0,0,0,0,0},3,0,0,0,1,0,FALSE},
208 {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
209 {{0,0,0,0,0,0},8,0,0,0,1,arab_tag,FALSE},
210 {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
211 static const int b2[2] = {4,4};
212
213 /* leading space */
214 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
215 static const itemTest t2c1[5] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
216 static const itemTest t2c2[6] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},1,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
217 static const itemTest t2c3[5] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},8,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
218 static const itemTest t2c4[3] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
219 static const itemTest t2c5[5] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
220 {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
221 {{0,0,0,0,0,0},7,0,0,0,1,0,FALSE},
222 {{0,0,0,0,0,0},8,0,0,0,1,latn_tag,FALSE},
223 {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
224
225 /* trailing space */
226 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
227 static const itemTest t2d1[5] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
228 static const itemTest t2d2[6] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
229 static const itemTest t2d3[5] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
230 static const itemTest t2d4[3] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},7,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
231 static const itemTest t2d5[5] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
232 {{0,0,0,0,0,0},3,0,0,0,1,0,FALSE},
233 {{0,0,0,0,0,0},4,0,0,0,1,latn_tag,FALSE},
234 {{0,0,0,0,0,0},7,0,0,0,1,arab_tag,FALSE},
235 {{0,0,0,0,0,0},11,0,0,0,0,-1,FALSE}};
236
237 /* Thai */
238 static const WCHAR test3[] =
239 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
240 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
241 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
242 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
243
244 static const itemTest t31[2] = {{{0,0,0,0,0,0},0,0,0,0,0,thai_tag,FALSE},{{0,0,0,0,0,0},41,0,0,0,0,-1,FALSE}};
245 static const itemTest t32[2] = {{{0,0,0,0,0,0},0,0,0,2,0,thai_tag,FALSE},{{0,0,0,0,0,0},41,0,0,0,0,-1,FALSE}};
246
247 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
248
249 static const itemTest t41[6] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
250 static const itemTest t42[5] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},10,0,0,2,0,0,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
251 static const itemTest t43[4] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},7,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
252 static const int b43[2] = {4,4};
253
254 /* Arabic */
255 static const WCHAR test5[] =
256 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
257 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
258 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
259 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
260 static const itemTest t51[2] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},38,0,0,0,0,-1,FALSE}};
261 static const itemTest t52[2] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
262 {{0,0,0,0,0,0},38,0,0,0,0,-1,FALSE}};
263
264
265 /* Hebrew */
266 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
267 static const itemTest t61[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,TRUE,{-1,0,0,0,-1}},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
268 static const itemTest t62[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},4,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
269 static const itemTest t63[2] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
270 static const itemTest t64[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
271 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
272 {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
273
274 static const int b63[2] = {2,2};
275 static const WCHAR test7[] = {'p','a','r','t',' ','o','n','e',' ',0x05d7, 0x05dc, 0x05e7, ' ', 0x05e9, 0x05ea, 0x05d9, 0x05d9, 0x05dd, ' ','p','a','r','t',' ','t','h','r','e','e', 0};
276 static const itemTest t71[4] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},9,1,1,1,0,hebr_tag,TRUE,{-1,0,0,0,-1}},{{0,0,0,0,0,0},19,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
277 static const itemTest t72[4] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},9,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},18,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
278 static const itemTest t73[4] = {{{0,0,0,0,0,0},0,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},8,1,1,1,0,hebr_tag,FALSE},{{0,0,0,0,0,0},19,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
279 static const itemTest t74[4] = {{{0,0,0,0,0,0},0,0,0,0,1,latn_tag,FALSE},
280 {{0,0,0,0,0,0},9,0,0,0,1,hebr_tag,FALSE},
281 {{0,0,0,0,0,0},19,0,0,0,1,latn_tag,FALSE},
282 {{0,0,0,0,0,0},29,0,0,0,0,-1,FALSE}};
283
284 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
285 static const itemTest t81[2] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
286 static const itemTest t82[2] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},
287 {{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
288
289 /* Syriac (Like Arabic )*/
290 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
291 static const itemTest t91[3] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
292 static const itemTest t92[3] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag},{{0,0,0,0,0,0},4,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
293 static const itemTest t93[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
294 static const itemTest t94[3] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
295 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
296 {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
297 static const int b93[2] = {2,2};
298
299 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
300 static const itemTest t101[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
301 static const itemTest t102[2] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
302 {{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
303
304 /* Devanagari */
305 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
306 static const itemTest t111[2] = {{{0,0,0,0,0,0},0,0,0,0,0,deva_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
307 static const itemTest t112[2] = {{{0,0,0,0,0,0},0,0,0,2,0,deva_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
308
309 /* Bengali */
310 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
311 static const itemTest t121[2] = {{{0,0,0,0,0,0},0,0,0,0,0,beng_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
312 static const itemTest t122[2] = {{{0,0,0,0,0,0},0,0,0,2,0,beng_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
313
314 /* Gurmukhi */
315 static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
316 static const itemTest t131[2] = {{{0,0,0,0,0,0},0,0,0,0,0,guru_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
317 static const itemTest t132[2] = {{{0,0,0,0,0,0},0,0,0,2,0,guru_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
318
319 /* Gujarati */
320 static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
321 static const itemTest t141[2] = {{{0,0,0,0,0,0},0,0,0,0,0,gujr_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
322 static const itemTest t142[2] = {{{0,0,0,0,0,0},0,0,0,2,0,gujr_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
323
324 /* Oriya */
325 static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
326 static const itemTest t151[2] = {{{0,0,0,0,0,0},0,0,0,0,0,orya_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
327 static const itemTest t152[2] = {{{0,0,0,0,0,0},0,0,0,2,0,orya_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
328
329 /* Tamil */
330 static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
331 static const itemTest t161[2] = {{{0,0,0,0,0,0},0,0,0,0,0,taml_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
332 static const itemTest t162[2] = {{{0,0,0,0,0,0},0,0,0,2,0,taml_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
333
334 /* Telugu */
335 static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
336 static const itemTest t171[2] = {{{0,0,0,0,0,0},0,0,0,0,0,telu_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
337 static const itemTest t172[2] = {{{0,0,0,0,0,0},0,0,0,2,0,telu_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
338
339 /* Kannada */
340 static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
341 static const itemTest t181[2] = {{{0,0,0,0,0,0},0,0,0,0,0,knda_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
342 static const itemTest t182[2] = {{{0,0,0,0,0,0},0,0,0,2,0,knda_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
343
344 /* Malayalam */
345 static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
346 static const itemTest t191[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mlym_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
347 static const itemTest t192[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mlym_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
348
349 /* Diacritical */
350 static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
351 static const itemTest t201[3] = {{{0,0,0,0,0,0},0,0,0,0,0x0,0,FALSE},{{0,0,0,0,0,0},1,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
352 static const itemTest t202[3] = {{{0,0,0,0,0,0},0,0,0,2,0,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},1,0,0,2,0,latn_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
353
354 static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
355 static const itemTest t211[2] = {{{0,0,0,0,0,0},0,1,1,1,0,syrc_tag,FALSE},{{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
356 static const itemTest t212[2] = {{{0,0,0,0,0,0},0,0,0,0,1,syrc_tag,FALSE},
357 {{0,0,0,0,0,0},5,0,0,0,0,-1,FALSE}};
358
359 /* Latin Punctuation */
360 static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
361 static const itemTest t221[3] = {{{0,0,0,0,0,0},0,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
362 static const itemTest t222[3] = {{{0,0,0,0,0,0},0,1,1,1,0,latn_tag,FALSE},{{0,0,0,0,0,0},3,1,1,1,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
363 static const itemTest t223[2] = {{{0,0,0,0,0,0},0,1,1,1,0,latn_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
364 static const int b222[2] = {1,1};
365 static const int b223[2] = {2,2};
366
367 /* Number 2*/
368 static const WCHAR test23[] = {'1','2','3',0x00b2,0x00b3,0x2070,0};
369 static const itemTest t231[3] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
370 static const itemTest t232[3] = {{{0,0,0,0,0,0},0,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},3,0,1,2,0,0,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
371
372 /* Myanmar */
373 static const WCHAR test24[] = {0x1019,0x103c,0x1014,0x103a,0x1019,0x102c,0x1021,0x1000,0x1039,0x1001,0x101b,0x102c};
374 static const itemTest t241[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mymr_tag,FALSE},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
375 static const itemTest t242[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mymr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},12,0,0,0,0,-1,FALSE}};
376
377 /* Tai Le */
378 static const WCHAR test25[] = {0x1956,0x196d,0x1970,0x1956,0x196c,0x1973,0x1951,0x1968,0x1952,0x1970};
379 static const itemTest t251[2] = {{{0,0,0,0,0,0},0,0,0,0,0,tale_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
380 static const itemTest t252[2] = {{{0,0,0,0,0,0},0,0,0,2,0,tale_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
381
382 /* New Tai Lue */
383 static const WCHAR test26[] = {0x1992,0x19c4};
384 static const itemTest t261[2] = {{{0,0,0,0,0,0},0,0,0,0,0,talu_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
385 static const itemTest t262[2] = {{{0,0,0,0,0,0},0,0,0,2,0,talu_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
386
387 /* Khmer */
388 static const WCHAR test27[] = {0x1781,0x17c1,0x1798,0x179a,0x1797,0x17b6,0x179f,0x17b6};
389 static const itemTest t271[2] = {{{0,0,0,0,0,0},0,0,0,0,0,khmr_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
390 static const itemTest t272[2] = {{{0,0,0,0,0,0},0,0,0,2,0,khmr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
391
392 /* CJK Han */
393 static const WCHAR test28[] = {0x8bed,0x7d20,0x6587,0x5b57};
394 static const itemTest t281[2] = {{{0,0,0,0,0,0},0,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
395 static const itemTest t282[2] = {{{0,0,0,0,0,0},0,0,0,2,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
396
397 /* Ideographic */
398 static const WCHAR test29[] = {0x2ff0,0x2ff3,0x2ffb,0x2ff0,0x65e5,0x65e5,0x5de5,0x7f51,0x4e02,0x4e5e};
399 static const itemTest t291[3] = {{{0,0,0,0,0,0},0,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,hani_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
400 static const itemTest t292[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hani_tag,FALSE},{{0,0,0,0,0,0},4,0,0,2,0,hani_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
401
402 /* Bopomofo */
403 static const WCHAR test30[] = {0x3113,0x3128,0x3127,0x3123,0x3108,0x3128,0x310f,0x3120};
404 static const itemTest t301[2] = {{{0,0,0,0,0,0},0,0,0,0,0,bopo_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
405 static const itemTest t302[2] = {{{0,0,0,0,0,0},0,0,0,2,0,bopo_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
406
407 /* Kana */
408 static const WCHAR test31[] = {0x3072,0x3089,0x304b,0x306a,0x30ab,0x30bf,0x30ab,0x30ca};
409 static const itemTest t311[2] = {{{0,0,0,0,0,0},0,0,0,0,0,kana_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
410 static const itemTest t312[2] = {{{0,0,0,0,0,0},0,0,0,2,0,kana_tag,FALSE},{{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
411 static const int b311[2] = {2,2};
412 static const int b312[2] = {2,2};
413
414 /* Hangul */
415 static const WCHAR test32[] = {0xd55c,0xad6d,0xc5b4};
416 static const itemTest t321[2] = {{{0,0,0,0,0,0},0,0,0,0,0,hang_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
417 static const itemTest t322[2] = {{{0,0,0,0,0,0},0,0,0,2,0,hang_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
418
419 /* Yi */
420 static const WCHAR test33[] = {0xa188,0xa320,0xa071,0xa0b7};
421 static const itemTest t331[2] = {{{0,0,0,0,0,0},0,0,0,0,0,yi_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
422 static const itemTest t332[2] = {{{0,0,0,0,0,0},0,0,0,2,0,yi_tag,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
423
424 /* Ethiopic */
425 static const WCHAR test34[] = {0x130d,0x12d5,0x12dd};
426 static const itemTest t341[2] = {{{0,0,0,0,0,0},0,0,0,0,0,ethi_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
427 static const itemTest t342[2] = {{{0,0,0,0,0,0},0,0,0,2,0,ethi_tag,FALSE},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
428 static const int b342[2] = {2,2};
429
430 /* Mongolian */
431 static const WCHAR test35[] = {0x182e,0x1823,0x1829,0x182d,0x1823,0x182f,0x0020,0x182a,0x1822,0x1834,0x1822,0x182d,0x180c};
432 static const itemTest t351[2] = {{{0,0,0,0,0,0},0,0,0,0,0,mong_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
433 static const int b351[2] = {2,2};
434 static const itemTest t352[2] = {{{0,0,0,0,0,0},0,0,0,2,0,mong_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
435 static const int b352[2] = {2,3};
436 static const itemTest t353[2] = {{{0,0,0,0,0,1},0,0,0,0,1,mong_tag,TRUE,{0,0,0,0,0}},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
437
438 /* Tifinagh */
439 static const WCHAR test36[] = {0x2d5c,0x2d49,0x2d3c,0x2d49,0x2d4f,0x2d30,0x2d56};
440 static const itemTest t361[2] = {{{0,0,0,0,0,0},0,0,0,0,0,tfng_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
441 static const itemTest t362[2] = {{{0,0,0,0,0,0},0,0,0,2,0,tfng_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
442
443 /* N'Ko */
444 static const WCHAR test37[] = {0x07d2,0x07de,0x07cf};
445 static const itemTest t371[2] = {{{0,0,0,0,0,0},0,1,1,1,0,nko_tag,TRUE,{-1,0,0,0,arab_tag,0}},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
446 static const itemTest t372[2] = {{{0,0,0,0,0,0},0,1,1,1,0,nko_tag,TRUE,{-1,0,0,2,arab_tag,0}},{{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
447 static const itemTest t373[2] = {{{0,0,0,0,0,0},0,0,0,0,1,nko_tag,TRUE,{-1,0,0,2,arab_tag,0}}, {{0,0,0,0,0,0},3,0,0,0,0,-1,FALSE}};
448
449 /* Vai */
450 static const WCHAR test38[] = {0xa559,0xa524};
451 static const itemTest t381[2] = {{{0,0,0,0,0,0},0,0,0,0,0,vai_tag,TRUE,{-1,-1,-1,-1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
452 static const itemTest t382[2] = {{{0,0,0,0,0,0},0,0,0,2,0,vai_tag,TRUE,{-1,1,1,1,latn_tag}},{{0,0,0,0,0,0},2,0,0,0,0,-1,FALSE}};
453
454 /* Cherokee */
455 static const WCHAR test39[] = {0x13e3,0x13b3,0x13a9,0x0020,0x13a6,0x13ec,0x13c2,0x13af,0x13cd,0x13d7};
456 static const itemTest t391[2] = {{{0,0,0,0,0,0},0,0,0,0,0,cher_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
457 static const itemTest t392[2] = {{{0,0,0,0,0,0},0,0,0,2,0,cher_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},10,0,0,0,0,-1,FALSE}};
458
459 /* Canadian Aboriginal Syllabics */
460 static const WCHAR test40[] = {0x1403,0x14c4,0x1483,0x144e,0x1450,0x1466};
461 static const itemTest t401[2] = {{{0,0,0,0,0,0},0,0,0,0,0,cans_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
462 static const itemTest t402[2] = {{{0,0,0,0,0,0},0,0,0,2,0,cans_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
463
464 /* Ogham */
465 static const WCHAR test41[] = {0x169b,0x1691,0x168c,0x1690,0x168b,0x169c};
466 static const itemTest t411[2] = {{{0,0,0,0,0,0},0,0,0,0,0,ogam_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
467 static const itemTest t412[4] = {{{0,0,0,0,0,0},0,1,1,1,0,ogam_tag,FALSE},{{0,0,0,0,0,0},1,0,0,2,0,ogam_tag,FALSE},{{0,0,0,0,0,0},5,1,1,1,0,ogam_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
468 static const int b412[2] = {1,1};
469
470 /* Runic */
471 static const WCHAR test42[] = {0x16a0,0x16a1,0x16a2,0x16a3,0x16a4,0x16a5};
472 static const itemTest t421[2] = {{{0,0,0,0,0,0},0,0,0,0,0,runr_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
473 static const itemTest t422[4] = {{{0,0,0,0,0,0},0,0,0,2,0,runr_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
474
475 /* Braille */
476 static const WCHAR test43[] = {0x280f,0x2817,0x2811,0x280d,0x280a,0x2811,0x2817};
477 static const itemTest t431[2] = {{{0,0,0,0,0,0},0,0,0,0,0,brai_tag,FALSE},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
478 static const itemTest t432[4] = {{{0,0,0,0,0,0},0,0,0,2,0,brai_tag,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
479
480 /* Private and Surrogates Area */
481 static const WCHAR test44[] = {0xe000, 0xe001, 0xd800, 0xd801};
482 static const itemTest t441[3] = {{{0,0,0,0,0,0},0,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},2,0,0,0,0,0,FALSE},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
483 static const itemTest t442[4] = {{{0,0,0,0,0,0},0,0,0,2,0,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},2,0,0,2,0,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0,0},4,0,0,0,0,-1,FALSE}};
484
485 /* Deseret */
486 static const WCHAR test45[] = {0xd801,0xdc19,0xd801,0xdc32,0xd801,0xdc4c,0xd801,0xdc3c,0xd801,0xdc32,0xd801,0xdc4b,0xd801,0xdc2f,0xd801,0xdc4c,0xd801,0xdc3b,0xd801,0xdc32,0xd801,0xdc4a,0xd801,0xdc28};
487 static const itemTest t451[2] = {{{0,0,0,0,0,0},0,0,0,0,0,dsrt_tag,TRUE,{-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},24,0,0,0,0,-1,FALSE}};
488 static const itemTest t452[2] = {{{0,0,0,0,0,0},0,0,0,2,0,dsrt_tag,TRUE,{-1,1,1,1,0x0}},{{0,0,0,0,0,0},24,0,0,0,0,-1,FALSE}};
489
490 /* Osmanya */
491 static const WCHAR test46[] = {0xd801,0xdc8b,0xd801,0xdc98,0xd801,0xdc88,0xd801,0xdc91,0xd801,0xdc9b,0xd801,0xdc92,0xd801,0xdc95,0xd801,0xdc80};
492 static const itemTest t461[2] = {{{0,0,0,0,0,0},0,0,0,0,0,osma_tag,TRUE,{-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
493 static const itemTest t462[2] = {{{0,0,0,0,0,0},0,0,0,2,0,osma_tag,TRUE,{-1,1,1,1,0x0}},{{0,0,0,0,0,0},16,0,0,0,0,-1,FALSE}};
494
495 /* Mathematical Alphanumeric Symbols */
496 static const WCHAR test47[] = {0xd835,0xdc00,0xd835,0xdc35,0xd835,0xdc6a,0xd835,0xdc9f,0xd835,0xdcd4,0xd835,0xdd09,0xd835,0xdd3e,0xd835,0xdd73,0xd835,0xdda8,0xd835,0xdddd,0xd835,0xde12,0xd835,0xde47,0xd835,0xde7c};
497 static const itemTest t471[2] = {{{0,0,0,0,0,0},0,0,0,0,0,math_tag,TRUE,{-1,-1,-1,-1,0x0}},{{0,0,0,0,0,0},26,0,0,0,0,-1,FALSE}};
498 static const itemTest t472[2] = {{{0,0,0,0,0,0},0,0,0,2,0,math_tag,TRUE,{-1,1,1,1,0x0}},{{0,0,0,0,0,0},26,0,0,0,0,-1,FALSE}};
499
500 /* Mathematical and Numeric combinations */
501 /* These have a leading hebrew character to force complicated itemization */
502 static const WCHAR test48[] = {0x05e9,' ','1','2','3','.'};
503 static const itemTest t481[4] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
504 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,0,0,FALSE},
505 {{0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
506 static const itemTest t482[4] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
507 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
508 {{0,0,0,0,0,0},5,0,0,0,1,0,FALSE},
509 {{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
510
511 static const WCHAR test49[] = {0x05e9,' ','1','2','.','1','2'};
512 static const itemTest t491[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
513 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
514 static const itemTest t492[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
515 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
516 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
517
518 static const WCHAR test50[] = {0x05e9,' ','.','1','2','3'};
519 static const itemTest t501[4] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
520 {{0,0,0,0,0},2,1,1,1,0,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,0,FALSE},
521 {{0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
522 static const itemTest t502[4] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
523 {{0,0,0,0,0,0},2,0,0,0,1,0,FALSE},
524 {{0,0,0,0,0,0},3,0,1,0,1,0,FALSE},
525 {{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
526
527 static const WCHAR test51[] = {0x05e9,' ','a','b','.','1','2'};
528 static const itemTest t511[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
529 {{0,0,0,0,0},1,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,0,FALSE},
530 {{0,0,0,0,0},5,0,0,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
531 static const itemTest t512[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
532 {{0,0,0,0,0,0},2,0,0,0,1,latn_tag,FALSE},
533 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
534 {{0,0,0,0,0,0},5,0,0,0,1,0,FALSE},
535 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
536
537 static const WCHAR test52[] = {0x05e9,' ','1','2','.','a','b'};
538 static const itemTest t521[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
539 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,0,FALSE},
540 {{0,0,0,0,0},5,0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
541 static const itemTest t522[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
542 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
543 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
544 {{0,0,0,0,0,0},5,0,0,0,1,latn_tag,FALSE},
545 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
546
547 static const WCHAR test53[] = {0x05e9,' ','1','2','.','.','1','2'};
548 static const itemTest t531[5] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
549 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},4,1,1,1,0,0,FALSE},
550 {{0,0,0,0,0},6,0,1,2,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
551 static const itemTest t532[5] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
552 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
553 {{0,0,0,0,0,0},4,0,0,0,1,0,FALSE},
554 {{0,0,0,0,0,0},6,0,1,0,1,0,FALSE},
555 {{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
556
557 static const WCHAR test54[] = {0x05e9,' ','1','2','+','1','2'};
558 static const itemTest t541[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
559 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
560 static const itemTest t542[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
561 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
562 {{0,0,0,0,0,0},7,0,0,0,0,-1,FALSE}};
563 static const WCHAR test55[] = {0x05e9,' ','1','2','+','+','1','2'};
564 static const itemTest t551[3] = {{{0,0,0,0,0,0},0,1,1,1,0,hebr_tag,FALSE},
565 {{0,0,0,0,0},2,0,1,2,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
566 static const itemTest t552[3] = {{{0,0,0,0,0,0},0,0,0,0,1,hebr_tag,FALSE},
567 {{0,0,0,0,0,0},2,0,1,0,1,0,FALSE},
568 {{0,0,0,0,0,0},8,0,0,0,0,-1,FALSE}};
569
570 /* ZWNJ */
571 static const WCHAR test56[] = {0x0645, 0x06cc, 0x200c, 0x06a9, 0x0646, 0x0645}; /* می‌کنم */
572 static const itemTest t561[] = {{{0,0,0,0,0,0},0,1,1,1,0,arab_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
573 static const itemTest t562[] = {{{0,0,0,0,0,0},0,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},6,0,0,0,0,-1,FALSE}};
574
575 /* Persian numerals and punctuation. */
576 static const WCHAR test57[] = {0x06f1, 0x06f2, 0x066c, 0x06f3, 0x06f4, 0x06f5, 0x066c, /* Û±Û²Ù¬Û³Û´ÛµÙ¬ */
577 0x06f6, 0x06f7, 0x06f8, 0x066b, 0x06f9, 0x06f0}; /* Û¶Û·Û¸Ù«Û¹Û° */
578 static const itemTest t571[] = {{{0,0,0,0,0,0}, 0,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0}, 2,0,1,2,0,arab_tag,FALSE},
579 {{0,0,0,0,0,0}, 3,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0}, 6,0,1,2,0,arab_tag,FALSE},
580 {{0,0,0,0,0,0}, 7,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,1,2,0,arab_tag,FALSE},
581 {{0,0,0,0,0,0},11,0,1,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
582 static const itemTest t572[] = {{{0,0,0,0,0,0}, 0,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0}, 2,0,1,2,0,arab_tag,FALSE},
583 {{0,0,0,0,0,0}, 3,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0}, 6,0,1,2,0,arab_tag,FALSE},
584 {{0,0,0,0,0,0}, 7,0,0,2,0,arab_tag,FALSE},{{0,0,1,0,0,0},10,0,1,2,0,arab_tag,FALSE},
585 {{0,0,0,0,0,0},11,0,0,2,0,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
586 static const itemTest t573[] = {{{0,0,0,0,0,0}, 0,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0}, 2,0,0,0,1,arab_tag,FALSE},
587 {{0,0,0,0,0,0}, 3,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0}, 6,0,0,0,1,arab_tag,FALSE},
588 {{0,0,0,0,0,0}, 7,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},10,0,0,0,1,arab_tag,FALSE},
589 {{0,0,0,0,0,0},11,0,0,0,1,arab_tag,FALSE},{{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
590 /* Arabic numerals and punctuation. */
591 static const WCHAR test58[] = {0x0661, 0x0662, 0x066c, 0x0663, 0x0664, 0x0665, 0x066c, /* ١٢٬٣٤٥٬ */
592 0x0666, 0x0667, 0x0668, 0x066b, 0x0669, 0x0660}; /* ٦٧٨٫٩٠ */
593 static const itemTest t581[] = {{{0,0,0,0,0,0}, 0,0,1,2,0,arab_tag,FALSE},
594 {{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
595 static const itemTest t582[] = {{{0,0,1,1,0,1}, 0,0,0,0,1,arab_tag,FALSE},
596 {{0,0,0,0,0,0},13,0,0,0,0,-1,FALSE}};
597
598 SCRIPT_ITEM items[15];
599 SCRIPT_CONTROL Control;
600 SCRIPT_STATE State;
601 HRESULT hr;
602 HMODULE usp10;
603 int nItems;
604
605 usp10 = LoadLibraryA("usp10.dll");
606 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
607 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
608 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
609 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
610
611 memset(&Control, 0, sizeof(Control));
612 memset(&State, 0, sizeof(State));
613
614 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
615 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
616
617 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
618 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
619
620 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
621 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
622
623 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
624 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
625
626 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
627 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
628 test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
629 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
630 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
631 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
632 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
633 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
634 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
635 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
636 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
637 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
638 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
639 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
640 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
641 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
642 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
643 test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
644 test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
645 test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
646 test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
647 test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
648 test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
649 test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
650 test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
651 test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
652 test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
653 test_items_ok(test23,6,NULL,NULL,2,t231,FALSE,0);
654 test_items_ok(test24,12,NULL,NULL,1,t241,FALSE,0);
655 test_items_ok(test25,10,NULL,NULL,1,t251,FALSE,0);
656 test_items_ok(test26,2,NULL,NULL,1,t261,FALSE,0);
657 test_items_ok(test27,8,NULL,NULL,1,t271,FALSE,0);
658 test_items_ok(test28,4,NULL,NULL,1,t281,FALSE,0);
659 test_items_ok(test29,10,NULL,NULL,2,t291,FALSE,0);
660 test_items_ok(test30,8,NULL,NULL,1,t301,FALSE,0);
661 test_items_ok(test31,8,NULL,NULL,1,t311,FALSE,b311);
662 test_items_ok(test32,3,NULL,NULL,1,t321,FALSE,0);
663 test_items_ok(test33,4,NULL,NULL,1,t331,FALSE,0);
664 test_items_ok(test34,3,NULL,NULL,1,t341,FALSE,0);
665 test_items_ok(test35,13,NULL,NULL,1,t351,FALSE,b351);
666 test_items_ok(test36,7,NULL,NULL,1,t361,FALSE,0);
667 test_items_ok(test37,3,NULL,NULL,1,t371,FALSE,0);
668 test_items_ok(test38,2,NULL,NULL,1,t381,FALSE,0);
669 test_items_ok(test39,10,NULL,NULL,1,t391,FALSE,0);
670 test_items_ok(test40,6,NULL,NULL,1,t401,FALSE,0);
671 test_items_ok(test41,6,NULL,NULL,1,t411,FALSE,0);
672 test_items_ok(test42,6,NULL,NULL,1,t421,FALSE,0);
673 test_items_ok(test43,7,NULL,NULL,1,t431,FALSE,0);
674 test_items_ok(test44,4,NULL,NULL,2,t441,FALSE,0);
675 test_items_ok(test45,24,NULL,NULL,1,t451,FALSE,0);
676 test_items_ok(test46,16,NULL,NULL,1,t461,FALSE,0);
677 test_items_ok(test47,26,NULL,NULL,1,t471,FALSE,0);
678 test_items_ok(test56,6,NULL,NULL,1,t561,FALSE,0);
679 test_items_ok(test57,13,NULL,NULL,7,t571,FALSE,0);
680 test_items_ok(test58,13,NULL,NULL,1,t581,FALSE,0);
681
682 State.uBidiLevel = 0;
683 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
684 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
685 test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
686 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
687 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
688 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
689 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
690 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
691 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
692 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
693 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
694 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
695 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
696 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
697 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
698 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
699 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
700 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
701 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
702 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
703 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
704 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
705 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
706 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
707 test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
708 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
709 test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
710 test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
711 test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
712 test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
713 test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
714 test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
715 test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
716 test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
717 test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
718 test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
719 test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
720 test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
721 test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
722 test_items_ok(test35,13,&Control,&State,1,t351,FALSE,b351);
723 test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
724 test_items_ok(test37,3,&Control,&State,1,t371,FALSE,0);
725 test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
726 test_items_ok(test39,10,&Control,&State,1,t391,FALSE,0);
727 test_items_ok(test40,6,&Control,&State,1,t401,FALSE,0);
728 test_items_ok(test41,6,&Control,&State,1,t411,FALSE,0);
729 test_items_ok(test42,6,&Control,&State,1,t421,FALSE,0);
730 test_items_ok(test43,7,&Control,&State,1,t431,FALSE,0);
731 test_items_ok(test44,4,&Control,&State,2,t441,FALSE,0);
732 test_items_ok(test45,24,&Control,&State,1,t451,FALSE,0);
733 test_items_ok(test46,16,&Control,&State,1,t461,FALSE,0);
734 test_items_ok(test47,26,&Control,&State,1,t471,FALSE,0);
735 test_items_ok(test48,6,&Control,&State,3,t481,FALSE,0);
736 test_items_ok(test49,7,&Control,&State,2,t491,FALSE,0);
737 test_items_ok(test50,6,&Control,&State,3,t501,FALSE,0);
738 test_items_ok(test51,7,&Control,&State,4,t511,FALSE,0);
739 test_items_ok(test52,7,&Control,&State,4,t521,FALSE,0);
740 test_items_ok(test53,8,&Control,&State,4,t531,FALSE,0);
741 test_items_ok(test54,7,&Control,&State,2,t541,FALSE,0);
742 test_items_ok(test55,8,&Control,&State,2,t551,FALSE,0);
743 test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
744 test_items_ok(test57,13,&Control,&State,7,t572,FALSE,0);
745 test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
746
747 State.uBidiLevel = 1;
748 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
749 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
750 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
751 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
752 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
753 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
754 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
755 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
756 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
757 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
758 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
759 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
760 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
761 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
762 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
763 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
764 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
765 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
766 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
767 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
768 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
769 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
770 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
771 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
772 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
773 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
774 test_items_ok(test22,6,&Control,&State,2,t222,FALSE,b222);
775 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
776 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
777 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
778 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
779 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
780 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
781 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
782 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
783 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
784 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
785 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
786 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
787 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
788 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
789 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
790 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
791 test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
792 test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
793 test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
794 test_items_ok(test42,6,&Control,&State,1,t422,FALSE,0);
795 test_items_ok(test43,7,&Control,&State,1,t432,FALSE,0);
796 test_items_ok(test44,4,&Control,&State,2,t442,FALSE,0);
797 test_items_ok(test45,24,&Control,&State,1,t452,FALSE,0);
798 test_items_ok(test46,16,&Control,&State,1,t462,FALSE,0);
799 test_items_ok(test47,26,&Control,&State,1,t472,FALSE,0);
800 test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
801 test_items_ok(test57,13,&Control,&State,7,t571,FALSE,0);
802 test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
803
804 State.uBidiLevel = 1;
805 Control.fMergeNeutralItems = TRUE;
806 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
807 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
808 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
809 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
810 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,b2);
811 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,b2);
812 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,b2);
813 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
814 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,b43);
815 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
816 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,b63);
817 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
818 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
819 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,b93);
820 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
821 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
822 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
823 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
824 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
825 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
826 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
827 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
828 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
829 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
830 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
831 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
832 test_items_ok(test22,6,&Control,&State,1,t223,FALSE,b223);
833 test_items_ok(test23,6,&Control,&State,2,t232,FALSE,0);
834 test_items_ok(test24,12,&Control,&State,1,t242,FALSE,0);
835 test_items_ok(test25,10,&Control,&State,1,t252,FALSE,0);
836 test_items_ok(test26,2,&Control,&State,1,t262,FALSE,0);
837 test_items_ok(test27,8,&Control,&State,1,t272,FALSE,0);
838 test_items_ok(test28,4,&Control,&State,1,t282,FALSE,0);
839 test_items_ok(test29,10,&Control,&State,2,t292,FALSE,0);
840 test_items_ok(test30,8,&Control,&State,1,t302,FALSE,0);
841 test_items_ok(test31,8,&Control,&State,1,t312,FALSE,b312);
842 test_items_ok(test32,3,&Control,&State,1,t322,FALSE,0);
843 test_items_ok(test33,4,&Control,&State,1,t332,FALSE,0);
844 test_items_ok(test34,3,&Control,&State,1,t342,FALSE,b342);
845 test_items_ok(test35,13,&Control,&State,1,t352,FALSE,b352);
846 test_items_ok(test36,7,&Control,&State,1,t362,FALSE,0);
847 test_items_ok(test37,3,&Control,&State,1,t372,FALSE,0);
848 test_items_ok(test38,2,&Control,&State,1,t382,FALSE,0);
849 test_items_ok(test39,10,&Control,&State,1,t392,FALSE,0);
850 test_items_ok(test40,6,&Control,&State,1,t402,FALSE,0);
851 test_items_ok(test41,6,&Control,&State,3,t412,FALSE,b412);
852 test_items_ok(test42,6,&Control,&State,1,t422,FALSE,0);
853 test_items_ok(test43,7,&Control,&State,1,t432,FALSE,0);
854 test_items_ok(test44,4,&Control,&State,2,t442,FALSE,0);
855 test_items_ok(test45,24,&Control,&State,1,t452,FALSE,0);
856 test_items_ok(test46,16,&Control,&State,1,t462,FALSE,0);
857 test_items_ok(test47,26,&Control,&State,1,t472,FALSE,0);
858 test_items_ok(test56,6,&Control,&State,1,t561,FALSE,0);
859 test_items_ok(test57,13,&Control,&State,7,t571,FALSE,0);
860 test_items_ok(test58,13,&Control,&State,1,t581,FALSE,0);
861
862 State.uBidiLevel = 0;
863 Control.fMergeNeutralItems = FALSE;
864 State.fOverrideDirection = 1;
865 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
866 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
867 test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
868 test_items_ok(test2,16,&Control,&State,4,t24,FALSE,0);
869 test_items_ok(test2b,11,&Control,&State,4,t2b4,FALSE,0);
870 test_items_ok(test2c,11,&Control,&State,4,t2c5,FALSE,0);
871 test_items_ok(test2d,11,&Control,&State,4,t2d5,FALSE,0);
872 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
873 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
874 test_items_ok(test5,38,&Control,&State,1,t52,FALSE,0);
875 test_items_ok(test6,5,&Control,&State,2,t64,FALSE,0);
876 test_items_ok(test7,29,&Control,&State,3,t74,FALSE,0);
877 test_items_ok(test8,4,&Control,&State,1,t82,FALSE,0);
878 test_items_ok(test9,5,&Control,&State,2,t94,FALSE,0);
879 test_items_ok(test10,4,&Control,&State,1,t102,FALSE,0);
880 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
881 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
882 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
883 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
884 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
885 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
886 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
887 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
888 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
889 test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
890 test_items_ok(test21,5,&Control,&State,1,t212,FALSE,0);
891 test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
892 test_items_ok(test23,6,&Control,&State,2,t231,FALSE,0);
893 test_items_ok(test24,12,&Control,&State,1,t241,FALSE,0);
894 test_items_ok(test25,10,&Control,&State,1,t251,FALSE,0);
895 test_items_ok(test26,2,&Control,&State,1,t261,FALSE,0);
896 test_items_ok(test27,8,&Control,&State,1,t271,FALSE,0);
897 test_items_ok(test28,4,&Control,&State,1,t281,FALSE,0);
898 test_items_ok(test29,10,&Control,&State,2,t291,FALSE,0);
899 test_items_ok(test30,8,&Control,&State,1,t301,FALSE,0);
900 test_items_ok(test31,8,&Control,&State,1,t311,FALSE,b311);
901 test_items_ok(test32,3,&Control,&State,1,t321,FALSE,0);
902 test_items_ok(test33,4,&Control,&State,1,t331,FALSE,0);
903 test_items_ok(test34,3,&Control,&State,1,t341,FALSE,0);
904 test_items_ok(test35,13,&Control,&State,1,t353,FALSE,b351);
905 test_items_ok(test36,7,&Control,&State,1,t361,FALSE,0);
906 test_items_ok(test37,3,&Control,&State,1,t373,FALSE,0);
907 test_items_ok(test38,2,&Control,&State,1,t381,FALSE,0);
908 test_items_ok(test39,10,&Control,&State,1,t391,FALSE,0);
909 test_items_ok(test40,6,&Control,&State,1,t401,FALSE,0);
910 test_items_ok(test41,6,&Control,&State,1,t411,FALSE,0);
911 test_items_ok(test42,6,&Control,&State,1,t421,FALSE,0);
912 test_items_ok(test43,7,&Control,&State,1,t431,FALSE,0);
913 test_items_ok(test44,4,&Control,&State,2,t441,FALSE,0);
914 test_items_ok(test45,24,&Control,&State,1,t451,FALSE,0);
915 test_items_ok(test46,16,&Control,&State,1,t461,FALSE,0);
916 test_items_ok(test47,26,&Control,&State,1,t471,FALSE,0);
917 test_items_ok(test48,6,&Control,&State,3,t482,FALSE,0);
918 test_items_ok(test49,7,&Control,&State,2,t492,FALSE,0);
919 test_items_ok(test50,6,&Control,&State,3,t502,FALSE,0);
920 test_items_ok(test51,7,&Control,&State,4,t512,FALSE,0);
921 test_items_ok(test52,7,&Control,&State,4,t522,FALSE,0);
922 test_items_ok(test53,8,&Control,&State,4,t532,FALSE,0);
923 test_items_ok(test54,7,&Control,&State,2,t542,FALSE,0);
924 test_items_ok(test55,8,&Control,&State,2,t552,FALSE,0);
925 test_items_ok(test56,6,&Control,&State,1,t562,FALSE,0);
926 test_items_ok(test57,13,&Control,&State,7,t573,FALSE,0);
927 test_items_ok(test58,13,&Control,&State,1,t582,FALSE,0);
928 }
929
930 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
931 DWORD cchString, SCRIPT_CONTROL *Control,
932 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
933 const shapeTest_char* charItems,
934 const shapeTest_glyph* glyphItems)
935 {
936 HRESULT hr;
937 int x, outnItems=0, outnGlyphs=0;
938 SCRIPT_ITEM outpItems[15];
939 SCRIPT_CACHE sc = NULL;
940 WORD *glyphs;
941 WORD *logclust;
942 int maxGlyphs = cchString * 1.5;
943 SCRIPT_GLYPHPROP *glyphProp;
944 SCRIPT_CHARPROP *charProp;
945 ULONG tags[15];
946
947 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
948 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
949 {
950 if (valid > 0)
951 winetest_win_skip("Select font does not support script\n");
952 else
953 winetest_trace("Select font does not support script\n");
954 return;
955 }
956 if (valid > 0)
957 winetest_ok(hr == S_OK, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
958 else if (hr != S_OK)
959 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
960
961 if (outnItems <= item)
962 {
963 if (valid > 0)
964 winetest_win_skip("Did not get enough items\n");
965 else
966 winetest_trace("Did not get enough items\n");
967 return;
968 }
969
970 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
971 memset(logclust,'a',sizeof(WORD) * cchString);
972 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
973 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
974 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
975 memset(glyphs,'a',sizeof(WORD) * cchString);
976 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
977 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
978
979 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
980 if (valid > 0)
981 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
982 else if (hr != S_OK)
983 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
984 if (FAILED(hr))
985 goto cleanup;
986
987 for (x = 0; x < cchString; x++)
988 {
989 if (valid > 0)
990 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
991 else if (logclust[x] != charItems[x].wLogClust)
992 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
993 if (valid > 0)
994 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
995 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
996 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
997 }
998
999 if (valid > 0)
1000 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
1001 else if (nGlyphs != outnGlyphs)
1002 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
1003 for (x = 0; x < outnGlyphs; x++)
1004 {
1005 if (glyphItems[x].Glyph)
1006 {
1007 if (valid > 0)
1008 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
1009 else if (glyphs[x]==0)
1010 winetest_trace("%i: Glyph not present when it should be\n",x);
1011 }
1012 else
1013 {
1014 if (valid > 0)
1015 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
1016 else if (glyphs[x]!=0)
1017 winetest_trace("%i: Glyph present when it should not be\n",x);
1018 }
1019 if (valid > 0)
1020 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
1021 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
1022 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
1023 if (valid > 0)
1024 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
1025 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
1026 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
1027 if (valid > 0)
1028 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
1029 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
1030 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
1031 if (valid > 0)
1032 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
1033 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
1034 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
1035 }
1036
1037 cleanup:
1038 HeapFree(GetProcessHeap(),0,logclust);
1039 HeapFree(GetProcessHeap(),0,charProp);
1040 HeapFree(GetProcessHeap(),0,glyphs);
1041 HeapFree(GetProcessHeap(),0,glyphProp);
1042 ScriptFreeCache(&sc);
1043 }
1044
1045 #define test_shape_ok(a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(1,a,b,c,d,e,f,g,h,i)
1046
1047 #define test_shape_ok_valid(v,a,b,c,d,e,f,g,h,i) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_shape_ok(v,a,b,c,d,e,f,g,h,i)
1048
1049 typedef struct tagRangeP {
1050 BYTE range;
1051 LOGFONTA lf;
1052 } fontEnumParam;
1053
1054 static int CALLBACK enumFontProc( const LOGFONTA *lpelfe, const TEXTMETRICA *lpntme, DWORD FontType, LPARAM lParam )
1055 {
1056 NEWTEXTMETRICEXA *ntme = (NEWTEXTMETRICEXA*)lpntme;
1057 fontEnumParam *rp = (fontEnumParam*) lParam;
1058 int idx = 0;
1059 DWORD i;
1060 DWORD mask = 0;
1061
1062 if (FontType != TRUETYPE_FONTTYPE)
1063 return 1;
1064
1065 i = rp->range;
1066 while (i >= sizeof(DWORD)*8)
1067 {
1068 idx++;
1069 i -= (sizeof(DWORD)*8);
1070 }
1071 if (idx > 3)
1072 return 0;
1073
1074 mask = 1 << i;
1075
1076 if (ntme->ntmFontSig.fsUsb[idx] & mask)
1077 {
1078 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONTA));
1079 return 0;
1080 }
1081 return 1;
1082 }
1083
1084 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
1085 {
1086 int rc = 0;
1087 fontEnumParam lParam;
1088
1089 lParam.range = range;
1090 memset(&lParam.lf,0,sizeof(LOGFONTA));
1091 *hfont = NULL;
1092
1093 if (recommended)
1094 {
1095 lstrcpyA(lParam.lf.lfFaceName, recommended);
1096 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
1097 {
1098 *hfont = CreateFontIndirectA(&lParam.lf);
1099 if (*hfont)
1100 {
1101 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
1102 rc = 1;
1103 }
1104 }
1105 }
1106
1107 if (!*hfont)
1108 {
1109 memset(&lParam.lf,0,sizeof(LOGFONTA));
1110 lParam.lf.lfCharSet = DEFAULT_CHARSET;
1111
1112 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
1113 {
1114 *hfont = CreateFontIndirectA(&lParam.lf);
1115 if (*hfont)
1116 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
1117 }
1118 }
1119
1120 if (*hfont)
1121 {
1122 WORD glyph = 0;
1123
1124 *origFont = SelectObject(hdc,*hfont);
1125 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
1126 {
1127 winetest_trace(" Font fails to contain required glyphs\n");
1128 SelectObject(hdc,*origFont);
1129 DeleteObject(*hfont);
1130 *hfont=NULL;
1131 rc = 0;
1132 }
1133 else if (!rc)
1134 rc = -1;
1135 }
1136 else
1137 winetest_trace("Failed to find usable font\n");
1138
1139 return rc;
1140 }
1141
1142 #define find_font_for_range(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _find_font_for_range(a,b,c,d,e,f)
1143
1144 static void test_ScriptShapeOpenType(HDC hdc)
1145 {
1146 HRESULT hr;
1147 SCRIPT_CACHE sc = NULL;
1148 WORD glyphs[4], logclust[4];
1149 SCRIPT_GLYPHPROP glyphProp[4];
1150 SCRIPT_ITEM items[2];
1151 ULONG tags[2];
1152 SCRIPT_CONTROL Control;
1153 SCRIPT_STATE State;
1154 int nb, outnItems;
1155 HFONT hfont, hfont_orig;
1156 int test_valid;
1157 shapeTest_glyph glyph_test[4];
1158
1159 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1160 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
1161 static const shapeTest_glyph t1_g[] = {
1162 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1163 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1164 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1165 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1166
1167 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1168 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
1169 static const shapeTest_glyph t2_g[] = {
1170 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1171 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1172 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1173 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1174
1175 /* Hebrew */
1176 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
1177 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
1178 static const shapeTest_glyph hebrew_g[] = {
1179 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1180 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1181 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1182 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
1183
1184 /* Arabic */
1185 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
1186 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
1187 static const shapeTest_glyph arabic_g[] = {
1188 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1189 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
1190 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
1191
1192 /* Thai */
1193 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
1194 static const shapeTest_char thai_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{5,{0,0}},{5,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}}};
1195 static const shapeTest_glyph thai_g[] = {
1196 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1197 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1198 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1199 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1200 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1201 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1202 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1203 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1204 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1205 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
1206
1207 /* Syriac */
1208 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
1209 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
1210 static const shapeTest_glyph syriac_g[] = {
1211 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1212 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1213 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1214 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1215 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1216 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1217
1218 /* Thaana */
1219 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
1220 static const shapeTest_char thaana_c[] = {{12,{0,0}},{12,{0,0}},{10,{0,0}},{10,{0,0}},{8,{1,0}},{7,{0,0}},{7,{0,0}},{5,{0,0}},{5,{0,0}},{3,{0,0}},{3,{0,0}},{1,{0,0}},{1,{0,0}}};
1221 static const shapeTest_glyph thaana_g[] = {
1222 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1223 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1224 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1225 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1226 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1227 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1228 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1229 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1230 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1231 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1232 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1233 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
1234 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1235
1236 /* Phags-pa */
1237 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
1238 static const shapeTest_char phagspa_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{1,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}}};
1239 static const shapeTest_glyph phagspa_g[] = {
1240 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1241 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1242 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1243 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1244 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1245 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1246 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1247 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1248 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1249 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1250 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1251
1252 /* Lao */
1253 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
1254 static const shapeTest_char lao_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{4,{0,0}},{5,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}}};
1255 static const shapeTest_glyph lao_g[] = {
1256 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1257 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
1258 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1259 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1260 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1261 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1262 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1263 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
1264 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1265
1266 /* Tibetan */
1267 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
1268 static const shapeTest_char tibetan_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{1,0}},{4,{0,0}},{4,{0,0}},{6,{0,0}},{7,{0,0}},{8,{0,0}},{9,{0,0}},{10,{0,0}},{11,{0,0}},{12,{0,0}},{13,{0,0}},{14,{0,0}},{14,{0,0}},{16,{0,0}}};
1269 static const shapeTest_glyph tibetan_g[] = {
1270 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1271 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1272 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1273 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
1274 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1275 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1276 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1277 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1278 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1279 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1280 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1281 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1282 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1283 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1284 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1285 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1286 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1287
1288 /* Devanagari */
1289 static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
1290 static const shapeTest_char devanagari_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{6,{0,0}},{6,{0,0}}};
1291 static const shapeTest_glyph devanagari_g[] = {
1292 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1293 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1294 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1295 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1296 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1297 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1298 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1299 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1300
1301 /* Bengali */
1302 static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
1303 static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
1304 static const shapeTest_glyph bengali_g[] = {
1305 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1306 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1307 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1308 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1309 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1310
1311 /* Gurmukhi */
1312 static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
1313 static const shapeTest_char gurmukhi_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
1314 static const shapeTest_glyph gurmukhi_g[] = {
1315 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1316 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1317 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1318 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1319 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1320 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1321 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1322
1323 /* Gujarati */
1324 static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
1325 static const shapeTest_char gujarati_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
1326 static const shapeTest_glyph gujarati_g[] = {
1327 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1328 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1329 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1330 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1331 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1332 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1333 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1334
1335 /* Oriya */
1336 static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
1337 static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1338 static const shapeTest_glyph oriya_g[] = {
1339 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1340 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1341 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1342 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1343
1344 /* Tamil */
1345 static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
1346 static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
1347 static const shapeTest_glyph tamil_g[] = {
1348 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1349 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1350 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1351 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
1352
1353 /* Telugu */
1354 static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
1355 static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1356 static const shapeTest_glyph telugu_g[] = {
1357 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1358 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1359 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1360 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1361 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1362 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1363
1364 /* Malayalam */
1365 static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
1366 static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
1367 static const shapeTest_glyph malayalam_g[] = {
1368 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1369 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1370 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1371 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1372 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1373 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1374
1375 /* Kannada */
1376 static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
1377 static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
1378 static const shapeTest_glyph kannada_g[] = {
1379 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1380 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1381 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
1382 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
1383 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
1384
1385 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
1386 {
1387 win_skip("ScriptShapeOpenType not available on this platform\n");
1388 return;
1389 }
1390
1391 memset(&Control, 0 , sizeof(Control));
1392 memset(&State, 0 , sizeof(State));
1393
1394 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
1395 ok(hr == S_OK, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
1396 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1397
1398 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
1399 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1400
1401 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
1402 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1403
1404 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1405 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
1406
1407 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
1408 ok( hr == E_INVALIDARG,
1409 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1410 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
1411 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
1412
1413 ScriptFreeCache(&sc);
1414
1415 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
1416
1417 /* newer Tahoma has zerowidth space glyphs for 0x202b and 0x202c */
1418 memcpy(glyph_test, t2_g, sizeof(glyph_test));
1419 GetGlyphIndicesW(hdc, test2, 4, glyphs, 0);
1420 if (glyphs[0] != 0)
1421 glyph_test[0].Glyph = 1;
1422 if (glyphs[3] != 0)
1423 glyph_test[3].Glyph = 1;
1424
1425 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, glyph_test);
1426
1427 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
1428 if (hfont != NULL)
1429 {
1430 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
1431 SelectObject(hdc, hfont_orig);
1432 DeleteObject(hfont);
1433 }
1434
1435 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
1436 if (hfont != NULL)
1437 {
1438 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
1439 SelectObject(hdc, hfont_orig);
1440 DeleteObject(hfont);
1441 }
1442
1443 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
1444 if (hfont != NULL)
1445 {
1446 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
1447 SelectObject(hdc, hfont_orig);
1448 DeleteObject(hfont);
1449 }
1450
1451 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
1452 if (hfont != NULL)
1453 {
1454 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
1455 SelectObject(hdc, hfont_orig);
1456 DeleteObject(hfont);
1457 }
1458
1459 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
1460 if (hfont != NULL)
1461 {
1462 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
1463 SelectObject(hdc, hfont_orig);
1464 DeleteObject(hfont);
1465 }
1466
1467 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
1468 if (hfont != NULL)
1469 {
1470 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
1471 SelectObject(hdc, hfont_orig);
1472 DeleteObject(hfont);
1473 }
1474
1475 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
1476 if (hfont != NULL)
1477 {
1478 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
1479 SelectObject(hdc, hfont_orig);
1480 DeleteObject(hfont);
1481 }
1482
1483 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
1484 if (hfont != NULL)
1485 {
1486 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
1487 SelectObject(hdc, hfont_orig);
1488 DeleteObject(hfont);
1489 }
1490
1491 test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
1492 if (hfont != NULL)
1493 {
1494 test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
1495 SelectObject(hdc, hfont_orig);
1496 DeleteObject(hfont);
1497 }
1498
1499 test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
1500 if (hfont != NULL)
1501 {
1502 test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1503 SelectObject(hdc, hfont_orig);
1504 DeleteObject(hfont);
1505 }
1506
1507 test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig);
1508 if (hfont != NULL)
1509 {
1510 test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1511 SelectObject(hdc, hfont_orig);
1512 DeleteObject(hfont);
1513 }
1514
1515 test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig);
1516 if (hfont != NULL)
1517 {
1518 test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1519 SelectObject(hdc, hfont_orig);
1520 DeleteObject(hfont);
1521 }
1522
1523 test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig);
1524 if (hfont != NULL)
1525 {
1526 test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1527 SelectObject(hdc, hfont_orig);
1528 DeleteObject(hfont);
1529 }
1530
1531 test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig);
1532 if (hfont != NULL)
1533 {
1534 test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1535 SelectObject(hdc, hfont_orig);
1536 DeleteObject(hfont);
1537 }
1538
1539 test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig);
1540 if (hfont != NULL)
1541 {
1542 test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1543 SelectObject(hdc, hfont_orig);
1544 DeleteObject(hfont);
1545 }
1546
1547 test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig);
1548 if (hfont != NULL)
1549 {
1550 test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1551 SelectObject(hdc, hfont_orig);
1552 DeleteObject(hfont);
1553 }
1554
1555 test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig);
1556 if (hfont != NULL)
1557 {
1558 test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1559 SelectObject(hdc, hfont_orig);
1560 DeleteObject(hfont);
1561 }
1562 }
1563
1564 static void test_ScriptShape(HDC hdc)
1565 {
1566 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1567 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1568 HRESULT hr;
1569 SCRIPT_CACHE sc = NULL;
1570 WORD glyphs[4], glyphs2[4], logclust[4], glyphs3[4];
1571 SCRIPT_VISATTR attrs[4];
1572 SCRIPT_ITEM items[2];
1573 int nb, i, j;
1574
1575 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1576 ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
1577 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1578
1579 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1580 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1581
1582 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1583 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1584
1585 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1586 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1587
1588 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1589 ok(broken(hr == S_OK) ||
1590 hr == E_INVALIDARG || /* Vista, W2K8 */
1591 hr == E_FAIL, /* WIN7 */
1592 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1593 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1594
1595 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1596 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1597 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1598
1599
1600 memset(glyphs,-1,sizeof(glyphs));
1601 memset(logclust,-1,sizeof(logclust));
1602 memset(attrs,-1,sizeof(attrs));
1603 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1604 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1605 ok(nb == 4, "Wrong number of items\n");
1606 ok(logclust[0] == 0, "clusters out of order\n");
1607 ok(logclust[1] == 1, "clusters out of order\n");
1608 ok(logclust[2] == 2, "clusters out of order\n");
1609 ok(logclust[3] == 3, "clusters out of order\n");
1610 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1611 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1612 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1613 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1614 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1615 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1616 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1617 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1618 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1619 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1620 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1621 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1622 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1623 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1624 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1625 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1626
1627 ScriptFreeCache(&sc);
1628 sc = NULL;
1629
1630 memset(glyphs2,-1,sizeof(glyphs2));
1631 memset(glyphs3,-1,sizeof(glyphs3));
1632 memset(logclust,-1,sizeof(logclust));
1633 memset(attrs,-1,sizeof(attrs));
1634
1635 GetGlyphIndicesW(hdc, test2, 4, glyphs3, 0);
1636
1637 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1638 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1639 ok(nb == 4, "Wrong number of items\n");
1640 ok(glyphs2[0] == glyphs3[0], "Incorrect glyph for 0x202B\n");
1641 ok(glyphs2[3] == glyphs3[3], "Incorrect glyph for 0x202C\n");
1642 ok(logclust[0] == 0, "clusters out of order\n");
1643 ok(logclust[1] == 1, "clusters out of order\n");
1644 ok(logclust[2] == 2, "clusters out of order\n");
1645 ok(logclust[3] == 3, "clusters out of order\n");
1646 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1647 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1648 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1649 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1650 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1651 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1652 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1653 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1654 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1655 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1656 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1657 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1658 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1659 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1660 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1661 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1662
1663 /* modify LTR to RTL */
1664 items[0].a.fRTL = 1;
1665 memset(glyphs2,-1,sizeof(glyphs2));
1666 memset(logclust,-1,sizeof(logclust));
1667 memset(attrs,-1,sizeof(attrs));
1668 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1669 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1670 ok(nb == 4, "Wrong number of items\n");
1671 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1672 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1673 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1674 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1675 ok(logclust[0] == 3, "clusters out of order\n");
1676 ok(logclust[1] == 2, "clusters out of order\n");
1677 ok(logclust[2] == 1, "clusters out of order\n");
1678 ok(logclust[3] == 0, "clusters out of order\n");
1679 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1680 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1681 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1682 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1683 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1684 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1685 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1686 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1687 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1688 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1689 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1690 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1691 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1692 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1693 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1694 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1695
1696 ScriptFreeCache(&sc);
1697
1698 /* some control characters are shown as blank */
1699 for (i = 0; i < 2; i++)
1700 {
1701 static const WCHAR space[] = {' ', 0};
1702 static const WCHAR blanks[] = {'\t', '\r', '\n', 0x001c, 0x001d, 0x001e, 0x001f,
1703 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, /* ZWSP, ZWNJ, ZWJ, LRM, RLM */
1704 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0}; /* LRE, RLE, PDF, LRO, RLO */
1705 HFONT font, oldfont = NULL;
1706 LOGFONTA lf;
1707
1708 font = GetCurrentObject(hdc, OBJ_FONT);
1709 GetObjectA(font, sizeof(lf), &lf);
1710 if (i == 1) {
1711 lstrcpyA(lf.lfFaceName, "MS Sans Serif");
1712 font = CreateFontIndirectA(&lf);
1713 oldfont = SelectObject(hdc, font);
1714 }
1715
1716 hr = ScriptItemize(space, 1, 2, NULL, NULL, items, NULL);
1717 ok(hr == S_OK, "%s: expected S_OK, got %08x\n", lf.lfFaceName, hr);
1718
1719 hr = ScriptShape(hdc, &sc, space, 1, 1, &items[0].a, glyphs, logclust, attrs, &nb);
1720 ok(hr == S_OK, "%s: expected S_OK, got %08x\n", lf.lfFaceName, hr);
1721 ok(nb == 1, "%s: expected 1, got %d\n", lf.lfFaceName, nb);
1722
1723 for (j = 0; blanks[j]; j++)
1724 {
1725 hr = ScriptItemize(&blanks[j], 1, 2, NULL, NULL, items, NULL);
1726 ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, blanks[j], hr);
1727
1728 ok(!items[0].a.fNoGlyphIndex, "%s: [%02x] got unexpected fNoGlyphIndex %#x.\n",
1729 lf.lfFaceName, blanks[j], items[0].a.fNoGlyphIndex);
1730 hr = ScriptShape(hdc, &sc, &blanks[j], 1, 1, &items[0].a, glyphs2, logclust, attrs, &nb);
1731 ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, blanks[j], hr);
1732 ok(nb == 1, "%s: [%02x] expected 1, got %d\n", lf.lfFaceName, blanks[j], nb);
1733 ok(!items[0].a.fNoGlyphIndex, "%s: [%02x] got unexpected fNoGlyphIndex %#x.\n",
1734 lf.lfFaceName, blanks[j], items[0].a.fNoGlyphIndex);
1735
1736 ok(glyphs[0] == glyphs2[0] ||
1737 broken(glyphs2[0] == blanks[j] && (blanks[j] < 0x10)),
1738 "%s: [%02x] expected %04x, got %04x\n", lf.lfFaceName, blanks[j], glyphs[0], glyphs2[0]);
1739 ok(attrs[0].fZeroWidth || broken(!attrs[0].fZeroWidth && (blanks[j] < 0x10) /* Vista */),
1740 "%s: [%02x] got unexpected fZeroWidth %#x.\n", lf.lfFaceName, blanks[j], attrs[0].fZeroWidth);
1741
1742 items[0].a.fNoGlyphIndex = 1;
1743 hr = ScriptShape(hdc, &sc, &blanks[j], 1, 1, &items[0].a, glyphs2, logclust, attrs, &nb);
1744 ok(hr == S_OK, "%s: [%02x] expected S_OK, got %08x\n", lf.lfFaceName, blanks[j], hr);
1745 ok(nb == 1, "%s: [%02x] expected 1, got %d\n", lf.lfFaceName, blanks[j], nb);
1746
1747 if (blanks[j] == 0x200b || blanks[j] == 0x200c || blanks[j] == 0x200d)
1748 {
1749 ok(glyphs2[0] == 0x0020,
1750 "%s: [%02x] got unexpected %04x.\n", lf.lfFaceName, blanks[j], glyphs2[0]);
1751 ok(attrs[0].fZeroWidth, "%s: [%02x] got unexpected fZeroWidth %#x.\n",
1752 lf.lfFaceName, blanks[j], attrs[0].fZeroWidth);
1753 }
1754 else
1755 {
1756 ok(glyphs2[0] == blanks[j],
1757 "%s: [%02x] got unexpected %04x.\n", lf.lfFaceName, blanks[j], glyphs2[0]);
1758 ok(!attrs[0].fZeroWidth, "%s: [%02x] got unexpected fZeroWidth %#x.\n",
1759 lf.lfFaceName, blanks[j], attrs[0].fZeroWidth);
1760 }
1761 }
1762 if (oldfont)
1763 DeleteObject(SelectObject(hdc, oldfont));
1764 ScriptFreeCache(&sc);
1765 }
1766 }
1767
1768 static void test_ScriptPlace(HDC hdc)
1769 {
1770 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1771 BOOL ret;
1772 HRESULT hr;
1773 SCRIPT_CACHE sc = NULL;
1774 WORD glyphs[4], logclust[4];
1775 SCRIPT_VISATTR attrs[4];
1776 SCRIPT_ITEM items[2];
1777 int nb, widths[4];
1778 GOFFSET offset[4];
1779 ABC abc[4];
1780
1781 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1782 ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
1783 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1784
1785 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1786 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1787 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1788
1789 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1790 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1791
1792 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1793 ok(broken(hr == E_PENDING) ||
1794 hr == E_INVALIDARG || /* Vista, W2K8 */
1795 hr == E_FAIL, /* WIN7 */
1796 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1797
1798 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1799 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1800
1801 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1802 ok(broken(hr == E_PENDING) ||
1803 hr == E_INVALIDARG || /* Vista, W2K8 */
1804 hr == E_FAIL, /* WIN7 */
1805 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1806
1807 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1808 ok(hr == S_OK, "ScriptPlace should return S_OK not %08x\n", hr);
1809 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1810
1811 if (widths[0] != 0)
1812 {
1813 int old_width = widths[0];
1814 attrs[0].fZeroWidth = 1;
1815
1816 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1817 ok(hr == S_OK, "ScriptPlace should return S_OK not %08x\n", hr);
1818 ok(widths[0] == 0, "got width %d\n", widths[0]);
1819 widths[0] = old_width;
1820 }
1821 else
1822 skip("Glyph already has zero-width - skipping fZeroWidth test\n");
1823
1824 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1825 ok(ret, "ExtTextOutW should return TRUE\n");
1826
1827 ScriptFreeCache(&sc);
1828 }
1829
1830 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1831 {
1832 HRESULT hr;
1833 int iMaxProps;
1834 const SCRIPT_PROPERTIES **ppSp;
1835
1836 int cInChars;
1837 int cMaxItems;
1838 SCRIPT_ITEM pItem[255];
1839 int pcItems;
1840 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1841 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
1842 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1843 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1844 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1845 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1846
1847 SCRIPT_CACHE psc;
1848 int cChars;
1849 int cMaxGlyphs;
1850 unsigned short pwOutGlyphs1[256];
1851 unsigned short pwOutGlyphs2[256];
1852 unsigned short pwLogClust[256];
1853 SCRIPT_VISATTR psva[256];
1854 int pcGlyphs;
1855 int piAdvance[256];
1856 GOFFSET pGoffset[256];
1857 ABC pABC[256];
1858 int cnt;
1859
1860 /* Start testing usp10 functions */
1861 /* This test determines that the pointer returned by ScriptGetProperties is valid
1862 * by checking a known value in the table */
1863 hr = ScriptGetProperties(&ppSp, &iMaxProps);
1864 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1865 trace("number of script properties %d\n", iMaxProps);
1866 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1867 if (iMaxProps > 0)
1868 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1869 /* ptrs work */
1870
1871 /* This is a valid test that will cause parsing to take place */
1872 cInChars = 5;
1873 cMaxItems = 255;
1874 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1875 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
1876 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1877 * returned. */
1878 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1879 if (pcItems > 0)
1880 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1881 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1882 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1883
1884 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1885 * ie. ScriptItemize has succeeded and that pItem has been set */
1886 cInChars = 5;
1887 if (hr == S_OK) {
1888 psc = NULL; /* must be null on first call */
1889 cChars = cInChars;
1890 cMaxGlyphs = cInChars;
1891 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1892 cMaxGlyphs, &pItem[0].a,
1893 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1894 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1895 cMaxGlyphs = 4;
1896 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1897 cMaxGlyphs, &pItem[0].a,
1898 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1899 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1900 "(%d) but not E_OUTOFMEMORY\n",
1901 cChars, cMaxGlyphs);
1902 cMaxGlyphs = 256;
1903 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1904 cMaxGlyphs, &pItem[0].a,
1905 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1906 ok (hr == S_OK, "ScriptShape should return S_OK not (%08x)\n", hr);
1907 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1908 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1909 if (hr ==0) {
1910 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1911 pGoffset, pABC);
1912 ok (hr == S_OK, "ScriptPlace should return S_OK not (%08x)\n", hr);
1913 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1914 pGoffset, pABC);
1915 ok (hr == S_OK, "ScriptPlace should return S_OK not (%08x)\n", hr);
1916 for (cnt=0; cnt < pcGlyphs; cnt++)
1917 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1918 }
1919
1920 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1921 * takes place if fNoGlyphIndex is set. */
1922
1923 cInChars = 5;
1924 cMaxItems = 255;
1925 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1926 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
1927 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1928 * returned. */
1929 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1930 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1931 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1932 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1933 if (hr == S_OK) {
1934 cChars = cInChars;
1935 cMaxGlyphs = 256;
1936 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1937 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1938 cMaxGlyphs, &pItem[0].a,
1939 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1940 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1941 ok (hr == S_OK, "ScriptShape should return S_OK not (%08x)\n", hr);
1942 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1943 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1944 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1945 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1946 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1947 if (hr == S_OK) {
1948 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1949 pGoffset, pABC);
1950 ok (hr == S_OK, "ScriptPlace should return S_OK not (%08x)\n", hr);
1951 }
1952 }
1953 ScriptFreeCache( &psc);
1954 ok (!psc, "psc is not null after ScriptFreeCache\n");
1955
1956 }
1957
1958 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1959 cInChars = (sizeof(TestItem3)/2)-1;
1960 cMaxItems = 255;
1961 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1962 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
1963 if (hr == S_OK)
1964 {
1965 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1966 if (pcItems > 2)
1967 {
1968 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1969 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1970 pItem[0].iCharPos, pItem[1].iCharPos);
1971 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1972 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1973 pItem[1].iCharPos, pItem[2].iCharPos);
1974 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1975 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1976 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1977 }
1978 }
1979
1980 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1981 cInChars = (sizeof(TestItem4)/2)-1;
1982 cMaxItems = 255;
1983 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1984 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
1985 if (hr == S_OK)
1986 {
1987 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1988 if (pcItems > 4)
1989 {
1990 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1991 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1992 pItem[0].iCharPos, pItem[1].iCharPos);
1993 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1994 pItem[0].a.s.uBidiLevel);
1995 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1996 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1997 pItem[1].iCharPos, pItem[2].iCharPos);
1998 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1999 pItem[1].a.s.uBidiLevel);
2000 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
2001 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
2002 pItem[2].iCharPos, pItem[3].iCharPos);
2003 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
2004 pItem[2].a.s.uBidiLevel);
2005 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
2006 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
2007 pItem[3].iCharPos, pItem[4].iCharPos);
2008 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
2009 pItem[3].a.s.uBidiLevel);
2010 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
2011 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
2012 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
2013 }
2014 }
2015
2016 /*
2017 * This test is for when the first unicode character requires bidi support
2018 */
2019 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
2020 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2021 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
2022 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
2023 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
2024 pItem[0].a.s.uBidiLevel);
2025
2026 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
2027 * the pointer to the last char works. Note that windows often needs a greater number of *
2028 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
2029 cInChars = (sizeof(TestItem6)/2)-1;
2030 cMaxItems = 4;
2031 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2032 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
2033
2034 }
2035
2036 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
2037 {
2038 HRESULT hr;
2039 SCRIPT_CACHE psc = NULL;
2040 int cInChars;
2041 int cChars;
2042 unsigned short pwOutGlyphs2[256];
2043 unsigned short pwOutGlyphs3[256];
2044 DWORD dwFlags;
2045 int cnt;
2046
2047 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2048 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
2049 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
2050 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
2051
2052 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
2053 dwFlags = 0;
2054 cInChars = cChars = 5;
2055 /* Some sanity checks for ScriptGetCMap */
2056
2057 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
2058 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
2059 "expected E_INVALIDARG, got %08x\n", hr);
2060
2061 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2062 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
2063 "expected E_INVALIDARG, got %08x\n", hr);
2064
2065 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2066 psc = NULL;
2067 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
2068 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
2069 "got %08x\n", hr);
2070 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2071
2072 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
2073 psc = NULL;
2074 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
2075 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
2076 "got %08x\n", hr);
2077 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
2078 ScriptFreeCache( &psc);
2079
2080 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2081 psc = NULL;
2082 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2083 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
2084 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2085 /* Check to see if the results are the same as those returned by ScriptShape */
2086 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
2087 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2088 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2089 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
2090 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
2091 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
2092
2093 ScriptFreeCache( &psc);
2094 ok (!psc, "psc is not null after ScriptFreeCache\n");
2095
2096 /* ScriptGetCMap returns whatever font defines, no special treatment for control chars */
2097 cInChars = cChars = 4;
2098 GetGlyphIndicesW(hdc, TestItem2, cInChars, pwOutGlyphs2, 0);
2099
2100 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
2101 if (pwOutGlyphs3[0] == 0 || pwOutGlyphs3[3] == 0)
2102 ok(hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
2103 else
2104 ok(hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2105
2106 ok(psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2107 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "expected glyph %d, got %d\n", pwOutGlyphs2[0], pwOutGlyphs3[0]);
2108 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "expected glyph %d, got %d\n", pwOutGlyphs2[3], pwOutGlyphs3[3]);
2109
2110 cInChars = cChars = 9;
2111 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
2112 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2113 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2114
2115 cInChars = cChars = 9;
2116 dwFlags = SGCM_RTL;
2117 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
2118 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
2119 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2120 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
2121 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorrectly altered\n");
2122 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorrectly altered\n");
2123 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorrectly altered\n");
2124 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
2125 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
2126 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
2127 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
2128 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
2129
2130 ScriptFreeCache( &psc);
2131 ok (!psc, "psc is not null after ScriptFreeCache\n");
2132 }
2133
2134 #define MAX_ENUM_FONTS 4096
2135
2136 struct enum_font_data
2137 {
2138 int total;
2139 ENUMLOGFONTA elf[MAX_ENUM_FONTS];
2140 };
2141
2142 static INT CALLBACK enum_bitmap_font_proc(const LOGFONTA *lf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
2143 {
2144 struct enum_font_data *efnd = (struct enum_font_data *)lParam;
2145
2146 if (type & (TRUETYPE_FONTTYPE | DEVICE_FONTTYPE)) return 1;
2147
2148 if (efnd->total < MAX_ENUM_FONTS)
2149 {
2150 efnd->elf[efnd->total++] = *(ENUMLOGFONTA*)lf;
2151 }
2152 else
2153 trace("enum tests invalid; you have more than %d fonts\n", MAX_ENUM_FONTS);
2154
2155 return 1;
2156 }
2157
2158 static INT CALLBACK enum_truetype_proc(const LOGFONTA *lf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)
2159 {
2160 struct enum_font_data *efnd = (struct enum_font_data *)lParam;
2161
2162 if (!(type & (TRUETYPE_FONTTYPE | DEVICE_FONTTYPE))) return 1;
2163
2164 if (efnd->total < MAX_ENUM_FONTS)
2165 {
2166 efnd->elf[efnd->total++] = *(ENUMLOGFONTA*)lf;
2167 }
2168 else
2169 trace("enum tests invalid; you have more than %d fonts\n", MAX_ENUM_FONTS);
2170
2171 return 1;
2172 }
2173
2174 static void test_ScriptGetFontProperties(HDC hdc)
2175 {
2176 HRESULT hr;
2177 SCRIPT_CACHE psc,old_psc;
2178 SCRIPT_FONTPROPERTIES sfp;
2179 HFONT font, oldfont;
2180 LOGFONTA lf;
2181 struct enum_font_data efnd;
2182 TEXTMETRICA tmA;
2183 WORD gi[3];
2184 WCHAR str[3];
2185 DWORD i, ret;
2186 WORD system_lang_id = PRIMARYLANGID(GetSystemDefaultLangID());
2187 static const WCHAR invalids[] = {0x0020, 0x200B, 0xF71B};
2188 /* U+0020: numeric space
2189 U+200B: zero width space
2190 U+F71B: unknown, found by black box testing */
2191 BOOL is_arial, is_times_new_roman, is_arabic = (system_lang_id == LANG_ARABIC);
2192
2193 /* Some sanity checks for ScriptGetFontProperties */
2194
2195 hr = ScriptGetFontProperties(NULL,NULL,NULL);
2196 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
2197
2198 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
2199 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
2200
2201 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2202 psc = NULL;
2203 hr = ScriptGetFontProperties(NULL,&psc,NULL);
2204 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
2205 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2206
2207 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2208 psc = NULL;
2209 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
2210 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
2211 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2212
2213 hr = ScriptGetFontProperties(hdc,NULL,NULL);
2214 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
2215
2216 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
2217 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
2218
2219 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2220 psc = NULL;
2221 hr = ScriptGetFontProperties(hdc,&psc,NULL);
2222 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
2223 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2224
2225 /* Pass an invalid sfp */
2226 psc = NULL;
2227 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
2228 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
2229 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
2230 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
2231 ScriptFreeCache(&psc);
2232 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2233
2234 /* Give it the correct cBytes, we don't care about what's coming back */
2235 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2236 psc = NULL;
2237 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
2238 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
2239 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
2240
2241 /* Save the psc pointer */
2242 old_psc = psc;
2243 /* Now a NULL hdc again */
2244 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
2245 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
2246 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
2247 ScriptFreeCache(&psc);
2248 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2249
2250 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
2251 if (!pGetGlyphIndicesW)
2252 {
2253 win_skip("Skip on WINNT4\n");
2254 return;
2255 }
2256 memset(&lf, 0, sizeof(lf));
2257 lf.lfCharSet = DEFAULT_CHARSET;
2258 efnd.total = 0;
2259 EnumFontFamiliesA(hdc, NULL, enum_bitmap_font_proc, (LPARAM)&efnd);
2260
2261 for (i = 0; i < efnd.total; i++)
2262 {
2263 if (strlen((char *)efnd.elf[i].elfFullName) >= LF_FACESIZE)
2264 {
2265 trace("Font name to long to test: %s\n",(char *)efnd.elf[i].elfFullName);
2266 continue;
2267 }
2268 lstrcpyA(lf.lfFaceName, (char *)efnd.elf[i].elfFullName);
2269 font = CreateFontIndirectA(&lf);
2270 oldfont = SelectObject(hdc, font);
2271
2272 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2273 psc = NULL;
2274 hr = ScriptGetFontProperties(hdc, &psc, &sfp);
2275 ok(hr == S_OK, "ScriptGetFontProperties expected S_OK, got %08x\n", hr);
2276 if (winetest_interactive)
2277 {
2278 trace("bitmap font %s\n", lf.lfFaceName);
2279 trace("wgBlank %04x\n", sfp.wgBlank);
2280 trace("wgDefault %04x\n", sfp.wgDefault);
2281 trace("wgInvalid %04x\n", sfp.wgInvalid);
2282 trace("wgKashida %04x\n", sfp.wgKashida);
2283 trace("iKashidaWidth %d\n", sfp.iKashidaWidth);
2284 }
2285
2286 ret = GetTextMetricsA(hdc, &tmA);
2287 ok(ret != 0, "GetTextMetricsA failed!\n");
2288
2289 ret = pGetGlyphIndicesW(hdc, invalids, 1, gi, GGI_MARK_NONEXISTING_GLYPHS);
2290 ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2291
2292 ok(sfp.wgBlank == tmA.tmBreakChar || sfp.wgBlank == gi[0], "bitmap font %s wgBlank %04x tmBreakChar %04x Space %04x\n", lf.lfFaceName, sfp.wgBlank, tmA.tmBreakChar, gi[0]);
2293
2294 ok(sfp.wgDefault == 0 || sfp.wgDefault == tmA.tmDefaultChar || broken(sfp.wgDefault == (0x100 | tmA.tmDefaultChar)), "bitmap font %s wgDefault %04x, tmDefaultChar %04x\n", lf.lfFaceName, sfp.wgDefault, tmA.tmDefaultChar);
2295
2296 ok(sfp.wgInvalid == sfp.wgBlank || broken(is_arabic), "bitmap font %s wgInvalid %02x wgBlank %02x\n", lf.lfFaceName, sfp.wgInvalid, sfp.wgBlank);
2297
2298 ok(sfp.wgKashida == 0xFFFF || broken(is_arabic), "bitmap font %s wgKashida %02x\n", lf.lfFaceName, sfp.wgKashida);
2299
2300 ScriptFreeCache(&psc);
2301
2302 SelectObject(hdc, oldfont);
2303 DeleteObject(font);
2304 }
2305
2306 efnd.total = 0;
2307 EnumFontFamiliesA(hdc, NULL, enum_truetype_proc, (LPARAM)&efnd);
2308
2309 for (i = 0; i < efnd.total; i++)
2310 {
2311 if (strlen((char *)efnd.elf[i].elfFullName) >= LF_FACESIZE)
2312 {
2313 trace("Font name to long to test: %s\n",(char *)efnd.elf[i].elfFullName);
2314 continue;
2315 }
2316 lstrcpyA(lf.lfFaceName, (char *)efnd.elf[i].elfFullName);
2317 font = CreateFontIndirectA(&lf);
2318 oldfont = SelectObject(hdc, font);
2319
2320 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
2321 psc = NULL;
2322 hr = ScriptGetFontProperties(hdc, &psc, &sfp);
2323 ok(hr == S_OK, "ScriptGetFontProperties expected S_OK, got %08x\n", hr);
2324 if (winetest_interactive)
2325 {
2326 trace("truetype font %s\n", lf.lfFaceName);
2327 trace("wgBlank %04x\n", sfp.wgBlank);
2328 trace("wgDefault %04x\n", sfp.wgDefault);
2329 trace("wgInvalid %04x\n", sfp.wgInvalid);
2330 trace("wgKashida %04x\n", sfp.wgKashida);
2331 trace("iKashidaWidth %d\n", sfp.iKashidaWidth);
2332 }
2333
2334 str[0] = 0x0020; /* U+0020: numeric space */
2335 ret = pGetGlyphIndicesW(hdc, str, 1, gi, 0);
2336 ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2337 ok(sfp.wgBlank == gi[0], "truetype font %s wgBlank %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgBlank, gi[0]);
2338
2339 ok(sfp.wgDefault == 0 || broken(is_arabic), "truetype font %s wgDefault %04x\n", lf.lfFaceName, sfp.wgDefault);
2340
2341 ret = pGetGlyphIndicesW(hdc, invalids, 3, gi, GGI_MARK_NONEXISTING_GLYPHS);
2342 ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2343 if (gi[2] != 0xFFFF) /* index of default non exist char */
2344 ok(sfp.wgInvalid == gi[2], "truetype font %s wgInvalid %04x gi[2] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[2]);
2345 else if (gi[1] != 0xFFFF)
2346 ok(sfp.wgInvalid == gi[1], "truetype font %s wgInvalid %04x gi[1] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[1]);
2347 else if (gi[0] != 0xFFFF)
2348 ok(sfp.wgInvalid == gi[0], "truetype font %s wgInvalid %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgInvalid, gi[0]);
2349 else
2350 ok(sfp.wgInvalid == 0, "truetype font %s wgInvalid %04x expect 0\n", lf.lfFaceName, sfp.wgInvalid);
2351
2352 str[0] = 0x0640; /* U+0640: kashida */
2353 ret = pGetGlyphIndicesW(hdc, str, 1, gi, GGI_MARK_NONEXISTING_GLYPHS);
2354 ok(ret != GDI_ERROR, "GetGlyphIndicesW failed!\n");
2355 is_arial = !lstrcmpA(lf.lfFaceName, "Arial");
2356 is_times_new_roman= !lstrcmpA(lf.lfFaceName, "Times New Roman");
2357 ok(sfp.wgKashida == gi[0] || broken(is_arial || is_times_new_roman) || broken(is_arabic), "truetype font %s wgKashida %04x gi[0] %04x\n", lf.lfFaceName, sfp.wgKashida, gi[0]);
2358
2359 ScriptFreeCache(&psc);
2360
2361 SelectObject(hdc, oldfont);
2362 DeleteObject(font);
2363 }
2364 }
2365
2366 static void test_ScriptTextOut(HDC hdc)
2367 {
2368 HRESULT hr;
2369
2370 int cInChars;
2371 int cMaxItems;
2372 SCRIPT_ITEM pItem[255];
2373 int pcItems;
2374 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2375
2376 SCRIPT_CACHE psc;
2377 int cChars;
2378 int cMaxGlyphs;
2379 unsigned short pwOutGlyphs1[256];
2380 WORD pwLogClust[256];
2381 SCRIPT_VISATTR psva[256];
2382 int pcGlyphs;
2383 int piAdvance[256];
2384 GOFFSET pGoffset[256];
2385 ABC pABC[256];
2386 RECT rect;
2387 int piX;
2388 int iCP = 1;
2389 BOOL fTrailing = FALSE;
2390 SCRIPT_LOGATTR *psla;
2391 SCRIPT_LOGATTR sla[256];
2392
2393 /* This is a valid test that will cause parsing to take place */
2394 cInChars = 5;
2395 cMaxItems = 255;
2396 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2397 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
2398 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
2399 * returned. */
2400 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
2401 if (pcItems > 0)
2402 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
2403 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
2404 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
2405
2406 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
2407 * ie. ScriptItemize has succeeded and that pItem has been set */
2408 cInChars = 5;
2409 if (hr == S_OK) {
2410 psc = NULL; /* must be null on first call */
2411 cChars = cInChars;
2412 cMaxGlyphs = 256;
2413 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
2414 cMaxGlyphs, &pItem[0].a,
2415 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2416 ok (hr == S_OK, "ScriptShape should return S_OK not (%08x)\n", hr);
2417 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2418 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
2419 if (hr == S_OK) {
2420 /* Note hdc is needed as glyph info is not yet in psc */
2421 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
2422 pGoffset, pABC);
2423 ok (hr == S_OK, "Should return S_OK not (%08x)\n", hr);
2424 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
2425 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2426
2427 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
2428 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
2429
2430 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2431 piAdvance, NULL, pGoffset);
2432 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
2433 "expected E_INVALIDARG, got %08x\n", hr);
2434
2435 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
2436 psc = NULL;
2437 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
2438 NULL, NULL, NULL);
2439 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
2440 "got %08x\n", hr);
2441 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2442
2443 /* hdc is required for this one rather than the usual optional */
2444 psc = NULL;
2445 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2446 piAdvance, NULL, pGoffset);
2447 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
2448 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2449
2450 /* Set that it returns 0 status */
2451 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2452 piAdvance, NULL, pGoffset);
2453 ok (hr == S_OK, "ScriptTextOut should return S_OK not (%08x)\n", hr);
2454
2455 /* Test Rect Rgn is acceptable */
2456 SetRect(&rect, 10, 10, 40, 20);
2457 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2458 piAdvance, NULL, pGoffset);
2459 ok (hr == S_OK, "ScriptTextOut should return S_OK not (%08x)\n", hr);
2460
2461 iCP = 1;
2462 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
2463 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
2464 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
2465
2466 psla = (SCRIPT_LOGATTR *)&sla;
2467 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
2468 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
2469
2470 /* Clean up and go */
2471 ScriptFreeCache(&psc);
2472 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2473 }
2474 }
2475 }
2476
2477 static void test_ScriptTextOut2(HDC hdc)
2478 {
2479 /* Intent is to validate that the HDC passed into ScriptTextOut is
2480 * used instead of the (possibly) invalid cached one
2481 */
2482 HRESULT hr;
2483
2484 HDC hdc1, hdc2;
2485 int cInChars;
2486 int cMaxItems;
2487 SCRIPT_ITEM pItem[255];
2488 int pcItems;
2489 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
2490
2491 SCRIPT_CACHE psc;
2492 int cChars;
2493 int cMaxGlyphs;
2494 unsigned short pwOutGlyphs1[256];
2495 WORD pwLogClust[256];
2496 SCRIPT_VISATTR psva[256];
2497 int pcGlyphs;
2498 int piAdvance[256];
2499 GOFFSET pGoffset[256];
2500 ABC pABC[256];
2501
2502 /* Create an extra DC that will be used until the ScriptTextOut */
2503 hdc1 = CreateCompatibleDC(hdc);
2504 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
2505 hdc2 = CreateCompatibleDC(hdc);
2506 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
2507
2508 /* This is a valid test that will cause parsing to take place */
2509 cInChars = 5;
2510 cMaxItems = 255;
2511 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2512 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
2513 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
2514 * returned. */
2515 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
2516 if (pcItems > 0)
2517 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
2518 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
2519 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
2520
2521 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
2522 * ie. ScriptItemize has succeeded and that pItem has been set */
2523 cInChars = 5;
2524 if (hr == S_OK) {
2525 psc = NULL; /* must be null on first call */
2526 cChars = cInChars;
2527 cMaxGlyphs = 256;
2528 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
2529 cMaxGlyphs, &pItem[0].a,
2530 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2531 ok (hr == S_OK, "ScriptShape should return S_OK not (%08x)\n", hr);
2532 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2533 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
2534 if (hr == S_OK) {
2535 BOOL ret;
2536
2537 /* Note hdc is needed as glyph info is not yet in psc */
2538 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
2539 pGoffset, pABC);
2540 ok (hr == S_OK, "Should return S_OK not (%08x)\n", hr);
2541
2542 /* key part!!! cached dc is being deleted */
2543 ret = DeleteDC(hdc2);
2544 ok(ret, "DeleteDC should return 1 not %d\n", ret);
2545
2546 /* At this point the cached hdc (hdc2) has been destroyed,
2547 * however, we are passing in a *real* hdc (the original hdc).
2548 * The text should be written to that DC
2549 */
2550 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2551 piAdvance, NULL, pGoffset);
2552 ok (hr == S_OK, "ScriptTextOut should return S_OK not (%08x)\n", hr);
2553 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2554
2555 DeleteDC(hdc1);
2556
2557 /* Clean up and go */
2558 ScriptFreeCache(&psc);
2559 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2560 }
2561 }
2562 }
2563
2564 static void test_ScriptTextOut3(HDC hdc)
2565 {
2566 HRESULT hr;
2567
2568 int cInChars;
2569 int cMaxItems;
2570 SCRIPT_ITEM pItem[255];
2571 int pcItems;
2572 WCHAR TestItem1[] = {' ','\r', 0};
2573
2574 SCRIPT_CACHE psc;
2575 int cChars;
2576 int cMaxGlyphs;
2577 unsigned short pwOutGlyphs1[256];
2578 WORD pwLogClust[256];
2579 SCRIPT_VISATTR psva[256];
2580 int pcGlyphs;
2581 int piAdvance[256];
2582 GOFFSET pGoffset[256];
2583 ABC pABC[256];
2584 RECT rect;
2585
2586 /* This is to ensure that nonexistent glyphs are translated into a valid glyph number */
2587 cInChars = 2;
2588 cMaxItems = 255;
2589 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
2590 ok (hr == S_OK, "ScriptItemize should return S_OK, returned %08x\n", hr);
2591 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
2592 * returned. */
2593 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
2594 if (pcItems > 0)
2595 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
2596 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
2597 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
2598
2599 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
2600 * ie. ScriptItemize has succeeded and that pItem has been set */
2601 cInChars = 2;
2602 if (hr == S_OK) {
2603 psc = NULL; /* must be null on first call */
2604 cChars = cInChars;
2605 cMaxGlyphs = 256;
2606 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
2607 cMaxGlyphs, &pItem[0].a,
2608 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
2609 ok (hr == S_OK, "ScriptShape should return S_OK not (%08x)\n", hr);
2610 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
2611 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
2612 if (hr ==0) {
2613 /* Note hdc is needed as glyph info is not yet in psc */
2614 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
2615 pGoffset, pABC);
2616 ok (hr == S_OK, "Should return S_OK not (%08x)\n", hr);
2617
2618 /* Test Rect Rgn is acceptable */
2619 SetRect(&rect, 10, 10, 40, 20);
2620 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
2621 piAdvance, NULL, pGoffset);
2622 ok (hr == S_OK, "ScriptTextOut should return S_OK not (%08x)\n", hr);
2623 }
2624 /* Clean up and go */
2625 ScriptFreeCache(&psc);
2626 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
2627 }
2628 }
2629
2630 #define test_item_ScriptXtoX(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_item_ScriptXtoX(a,b,c,d,e,f)
2631
2632 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2633 {
2634 int iX, iCP;
2635 int icChars, icGlyphs;
2636 int piCP, piX;
2637 HRESULT hr;
2638 SCRIPT_VISATTR psva[10];
2639 int piTrailing;
2640 BOOL fTrailing;
2641 int direction;
2642
2643 memset(psva,0,sizeof(psva));
2644 direction = (psa->fRTL)?-1:+1;
2645
2646 for(iCP = 0; iCP < cChars; iCP++)
2647 {
2648 iX = offsets[iCP];
2649 icChars = cChars;
2650 icGlyphs = cGlyphs;
2651 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2652 winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2653 winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2654 winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2655 }
2656
2657 for(iCP = 0; iCP < cChars; iCP++)
2658 {
2659 iX = offsets[iCP]+direction;
2660 icChars = cChars;
2661 icGlyphs = cGlyphs;
2662 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2663 winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2664 winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2665 winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2666 }
2667
2668 for(iCP = 0; iCP < cChars; iCP++)
2669 {
2670 iX = offsets[iCP+1]-direction;
2671 icChars = cChars;
2672 icGlyphs = cGlyphs;
2673 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2674 winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2675 winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2676 winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2677 }
2678
2679 for(iCP = 0; iCP <= cChars+1; iCP++)
2680 {
2681 fTrailing = FALSE;
2682 icChars = cChars;
2683 icGlyphs = cGlyphs;
2684 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2685 winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
2686 winetest_ok(piX == offsets[iCP],
2687 "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
2688 }
2689
2690 for(iCP = 0; iCP <= cChars+1; iCP++)
2691 {
2692 fTrailing = TRUE;
2693 icChars = cChars;
2694 icGlyphs = cGlyphs;
2695 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
2696 winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
2697 winetest_ok(piX == offsets[iCP+1],
2698 "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
2699 }
2700 }
2701
2702 #define test_caret_item_ScriptXtoCP(a,b,c,d,e,f) _test_caret_item_ScriptXtoCP(__LINE__,a,b,c,d,e,f)
2703
2704 static void _test_caret_item_ScriptXtoCP(int line, SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
2705 {
2706 int iX, iCP, i;
2707 int icChars, icGlyphs;
2708 int piCP;
2709 int clusterSize;
2710 HRESULT hr;
2711 SCRIPT_VISATTR psva[10];
2712 int piTrailing;
2713 int direction;
2714
2715 memset(psva,0,sizeof(psva));
2716 direction = (psa->fRTL)?-1:+1;
2717
2718 for(iX = -1, i = iCP = 0; i < cChars; i++)
2719 {
2720 if (offsets[i] != iX)
2721 {
2722 iX = offsets[i];
2723 iCP = i;
2724 }
2725 icChars = cChars;
2726 icGlyphs = cGlyphs;
2727 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2728 ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2729 ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2730 ok_(__FILE__,line)(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2731 }
2732
2733 for(iX = -2, i = 0; i < cChars; i++)
2734 {
2735 if (offsets[i]+direction != iX)
2736 {
2737 iX = offsets[i] + direction;
2738 iCP = i;
2739 }
2740 icChars = cChars;
2741 icGlyphs = cGlyphs;
2742 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2743 ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
2744 ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2745 ok_(__FILE__,line)(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
2746 }
2747
2748 for(clusterSize = 0, iCP = 0, iX = -2, i = 0; i < cChars; i++)
2749 {
2750 clusterSize++;
2751 if (offsets[i] != offsets[i+1])
2752 {
2753 iX = offsets[i+1]-direction;
2754 icChars = cChars;
2755 icGlyphs = cGlyphs;
2756 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
2757 ok_(__FILE__,line)(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
2758 ok_(__FILE__,line)(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
2759 ok_(__FILE__,line)(piTrailing == clusterSize, "ScriptXtoCP trailing: iX=%d should return piTrailing=%d not %d\n", iX, clusterSize, piTrailing);
2760 iCP = i+1;
2761 clusterSize = 0;
2762 }
2763 }
2764 }
2765
2766 static void test_ScriptXtoX(void)
2767 /****************************************************************************************
2768 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
2769 ****************************************************************************************/
2770 {
2771 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
2772 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
2773 WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
2774 WORD pwLogClust_3[17] = {0, 1, 1, 1, 1, 4, 5, 6, 6, 8, 8, 8, 8, 11, 11, 13, 13};
2775 WORD pwLogClust_3_RTL[17] = {13, 13, 11, 11, 8, 8, 8, 8, 6, 6, 5, 4, 1, 1, 1, 1, 0};
2776 int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
2777 int piAdvance_2[5] = {39, 26, 19, 17, 11};
2778 int piAdvance_3[15] = {6, 6, 0, 0, 10, 5, 10, 0, 12, 0, 0, 9, 0, 10, 0};
2779 static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
2780 static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
2781 static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
2782
2783 static const int offsets_3[19] = {0, 6, 6, 6, 6, 12, 22, 27, 27, 37, 37, 37, 37, 49, 49, 58, 58, 68, 68};
2784 static const int offsets_3_RTL[19] = {68, 68, 58, 58, 49, 49, 49, 49, 37, 37, 27, 22, 12, 12, 12, 12, 6, 6};
2785
2786 SCRIPT_VISATTR psva[15];
2787 SCRIPT_ANALYSIS sa;
2788 SCRIPT_ITEM items[2];
2789 int iX, i;
2790 int piCP;
2791 int piTrailing;
2792 HRESULT hr;
2793 static const WCHAR hebrW[] = { 0x5be, 0};
2794 static const WCHAR thaiW[] = { 0xe2a, 0};
2795 const SCRIPT_PROPERTIES **ppScriptProperties;
2796
2797 memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
2798 memset(psva, 0, sizeof(psva));
2799
2800 sa.fRTL = FALSE;
2801 hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
2802 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2803 if (piTrailing)
2804 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2805 else /* win2k3 */
2806 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2807
2808 for (iX = 0; iX <= 7; iX++)
2809 {
2810 WORD clust = 0;
2811 INT advance = 16;
2812 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2813 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
2814 }
2815 for (iX = 8; iX < 16; iX++)
2816 {
2817 WORD clust = 0;
2818 INT advance = 16;
2819 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2820 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
2821 }
2822
2823 sa.fRTL = TRUE;
2824 hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2825 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2826 if (piTrailing)
2827 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
2828 else /* win2k3 */
2829 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2830
2831 iX = 1954;
2832 hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2833 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2834 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
2835 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2836
2837 for (iX = 1; iX <= 8; iX++)
2838 {
2839 WORD clust = 0;
2840 INT advance = 16;
2841 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2842 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
2843 }
2844 for (iX = 9; iX < 16; iX++)
2845 {
2846 WORD clust = 0;
2847 INT advance = 16;
2848 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2849 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
2850 }
2851
2852 sa.fRTL = FALSE;
2853 test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
2854 sa.fRTL = TRUE;
2855 test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
2856 test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
2857
2858 /* Get thai eScript, This will do LTR and fNeedsCaretInfo */
2859 hr = ScriptItemize(thaiW, 1, 2, NULL, NULL, items, &i);
2860 ok(hr == S_OK, "got %08x\n", hr);
2861 ok(i == 1, "got %d\n", i);
2862 sa = items[0].a;
2863
2864 test_caret_item_ScriptXtoCP(&sa, 17, 15, offsets_3, pwLogClust_3, piAdvance_3);
2865
2866 /* Get hebrew eScript, This will do RTL and fNeedsCaretInfo */
2867 hr = ScriptItemize(hebrW, 1, 2, NULL, NULL, items, &i);
2868 ok(hr == S_OK, "got %08x\n", hr);
2869 ok(i == 1, "got %d\n", i);
2870 sa = items[0].a;
2871
2872 /* Note: This behavior CHANGED in uniscribe versions...
2873 * so we only want to test if fNeedsCaretInfo is set */
2874 hr = ScriptGetProperties(&ppScriptProperties, &i);
2875 if (ppScriptProperties[sa.eScript]->fNeedsCaretInfo)
2876 {
2877 test_caret_item_ScriptXtoCP(&sa, 17, 15, offsets_3_RTL, pwLogClust_3_RTL, piAdvance_3);
2878 hr = ScriptXtoCP(0, 17, 15, pwLogClust_3_RTL, psva, piAdvance_3, &sa, &piCP, &piTrailing);
2879 ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
2880 ok(piCP == 16, "ScriptXtoCP: iX=0 should return piCP=16 not %d\n", piCP);
2881 ok(piTrailing == 1, "ScriptXtoCP: iX=0 should return piTrailing=1 not %d\n", piTrailing);
2882 }
2883 else
2884 win_skip("Uniscribe version too old to test Hebrew clusters\n");
2885 }
2886
2887 static void test_ScriptString(HDC hdc)
2888 {
2889 /*******************************************************************************************
2890 *
2891 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
2892 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
2893 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
2894 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
2895 *
2896 */
2897
2898 HRESULT hr;
2899 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
2900 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
2901 int Glyphs = len * 2 + 16;
2902 int Charset;
2903 DWORD Flags = SSA_GLYPHS;
2904 int ReqWidth = 100;
2905 static const int Dx[(sizeof(teststr) / sizeof(WCHAR)) - 1];
2906 static const BYTE InClass[(sizeof(teststr) / sizeof(WCHAR)) - 1];
2907 SCRIPT_STRING_ANALYSIS ssa = NULL;
2908
2909 int X = 10;
2910 int Y = 100;
2911 UINT Options = 0;
2912 const RECT rc = {0, 50, 100, 100};
2913 int MinSel = 0;
2914 int MaxSel = 0;
2915 BOOL Disabled = FALSE;
2916 const int *clip_len;
2917 int i;
2918 UINT *order;
2919
2920
2921 Charset = -1; /* this flag indicates unicode input */
2922 /* Test without hdc to get E_PENDING */
2923 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
2924 ReqWidth, NULL, NULL, Dx, NULL,
2925 InClass, &ssa);
2926 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
2927
2928 /* Test that 0 length string returns E_INVALIDARG */
2929 hr = ScriptStringAnalyse( hdc, teststr, 0, Glyphs, Charset, Flags,
2930 ReqWidth, NULL, NULL, Dx, NULL,
2931 InClass, &ssa);
2932 ok(hr == E_INVALIDARG, "ScriptStringAnalyse should return E_INVALIDARG not %08x\n", hr);
2933
2934 /* test with hdc, this should be a valid test */
2935 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2936 ReqWidth, NULL, NULL, Dx, NULL,
2937 InClass, &ssa);
2938 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2939 ScriptStringFree(&ssa);
2940
2941 /* test makes sure that a call with a valid pssa still works */
2942 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2943 ReqWidth, NULL, NULL, Dx, NULL,
2944 InClass, &ssa);
2945 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2946 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
2947
2948 if (hr == S_OK)
2949 {
2950 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
2951 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
2952 }
2953
2954 clip_len = ScriptString_pcOutChars(ssa);
2955 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
2956
2957 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
2958 hr = ScriptStringGetOrder(ssa, order);
2959 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
2960
2961 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
2962 HeapFree(GetProcessHeap(), 0, order);
2963
2964 hr = ScriptStringFree(&ssa);
2965 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2966 }
2967
2968 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
2969 {
2970 /*****************************************************************************************
2971 *
2972 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
2973 * nature of the fonts between Windows and Wine, the test is implemented by generating
2974 * values using one one function then checking the output of the second. In this way
2975 * the validity of the functions is established using Windows as a base and confirming
2976 * similar behaviour in wine.
2977 */
2978
2979 HRESULT hr;
2980 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
2981 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
2982 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
2983 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
2984 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
2985 int Charset = -1; /* unicode */
2986 DWORD Flags = SSA_GLYPHS;
2987 int ReqWidth = 100;
2988 static const BYTE InClass[(sizeof(teststr1)/sizeof(WCHAR))-1];
2989 SCRIPT_STRING_ANALYSIS ssa = NULL;
2990
2991 int Ch; /* Character position in string */
2992 int iTrailing;
2993 int Cp; /* Character position in string */
2994 int X;
2995 int trail,lead;
2996 BOOL fTrailing;
2997
2998 /* Test with hdc, this should be a valid test
2999 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
3000 * following character positions to X and X to character position functions.
3001 */
3002
3003 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
3004 ReqWidth, NULL, NULL, NULL, NULL,
3005 InClass, &ssa);
3006 ok(hr == S_OK ||
3007 hr == E_INVALIDARG, /* NT */
3008 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
3009
3010 if (hr == S_OK)
3011 {
3012 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
3013
3014 /*
3015 * Loop to generate character positions to provide starting positions for the
3016 * ScriptStringCPtoX and ScriptStringXtoCP functions
3017 */
3018 for (Cp = 0; Cp < String_len; Cp++)
3019 {
3020 /* The fTrailing flag is used to indicate whether the X being returned is at
3021 * the beginning or the end of the character. What happens here is that if
3022 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
3023 * returns the beginning of the next character and iTrailing is FALSE. So for this
3024 * loop iTrailing will be FALSE in both cases.
3025 */
3026 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
3027 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3028 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
3029 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3030 if (rtl[Cp])
3031 ok(lead > trail, "Leading values should be after trailing for rtl characters(%i)\n",Cp);
3032 else
3033 ok(lead < trail, "Trailing values should be after leading for ltr characters(%i)\n",Cp);
3034
3035 /* move by 1 pixel so that we are not between 2 characters. That could result in being the lead of a rtl and
3036 at the same time the trail of an ltr */
3037
3038 /* inside the leading edge */
3039 X = lead;
3040 if (rtl[Cp]) X--; else X++;
3041 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3042 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3043 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
3044 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
3045 iTrailing, X);
3046
3047 /* inside the trailing edge */
3048 X = trail;
3049 if (rtl[Cp]) X++; else X--;
3050 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3051 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3052 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
3053 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
3054 iTrailing, X);
3055
3056 /* outside the "trailing" edge */
3057 if (Cp < String_len-1)
3058 {
3059 if (rtl[Cp]) X = lead; else X = trail;
3060 X++;
3061 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3062 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3063 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
3064 if (rtl[Cp+1])
3065 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
3066 iTrailing, X);
3067 else
3068 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
3069 iTrailing, X);
3070 }
3071
3072 /* outside the "leading" edge */
3073 if (Cp != 0)
3074 {
3075 if (rtl[Cp]) X = trail; else X = lead;
3076 X--;
3077 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3078 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3079 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
3080 if (Cp != 0 && rtl[Cp-1])
3081 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
3082 iTrailing, X);
3083 else
3084 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
3085 iTrailing, X);
3086 }
3087 }
3088
3089 /* Check beyond the leading boundary of the whole string */
3090 if (rtl[0])
3091 {
3092 /* having a leading rtl character seems to confuse usp */
3093 /* this looks to be a windows bug we should emulate */
3094 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
3095 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3096 X--;
3097 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3098 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3099 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
3100 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
3101 iTrailing);
3102 }
3103 else
3104 {
3105 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
3106 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3107 X--;
3108 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3109 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3110 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
3111 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
3112 iTrailing);
3113 }
3114
3115 /* Check beyond the end boundary of the whole string */
3116 if (rtl[String_len-1])
3117 {
3118 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
3119 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3120 }
3121 else
3122 {
3123 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
3124 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
3125 }
3126 X++;
3127 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
3128 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
3129 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
3130 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside trailing edge\n",
3131 iTrailing);
3132
3133 /*
3134 * Cleanup the SSA for the next round of tests
3135 */
3136 hr = ScriptStringFree(&ssa);
3137 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
3138
3139 /*
3140 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
3141 * generate an SSA for the subsequent tests.
3142 */
3143 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
3144 ReqWidth, NULL, NULL, NULL, NULL,
3145 InClass, &ssa);
3146 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
3147
3148 /*
3149 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
3150 * string length, return E_INVALIDARG. This also invalidates the ssa so a
3151 * ScriptStringFree should also fail.
3152 */
3153 fTrailing = FALSE;
3154 Cp = String_len + 1;
3155 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
3156 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
3157
3158 ScriptStringFree(&ssa);
3159 }
3160 }
3161
3162 static void test_ScriptCacheGetHeight(HDC hdc)
3163 {
3164 HRESULT hr;
3165 SCRIPT_CACHE sc = NULL;
3166 LONG height;
3167
3168 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
3169 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3170
3171 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
3172 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3173
3174 hr = ScriptCacheGetHeight(NULL, &sc, &height);
3175 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
3176
3177 height = 0;
3178
3179 hr = ScriptCacheGetHeight(hdc, &sc, &height);
3180 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3181 ok(height > 0, "expected height > 0\n");
3182
3183 ScriptFreeCache(&sc);
3184 }
3185
3186 static void test_ScriptGetGlyphABCWidth(HDC hdc)
3187 {
3188 HRESULT hr;
3189 SCRIPT_CACHE sc = NULL;
3190 ABC abc;
3191
3192 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
3193 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3194
3195 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
3196 ok(broken(hr == E_PENDING) ||
3197 hr == E_INVALIDARG, /* WIN7 */
3198 "expected E_INVALIDARG, got 0x%08x\n", hr);
3199
3200 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
3201 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
3202
3203 if (0) { /* crashes on WinXP */
3204 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
3205 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3206 }
3207
3208 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
3209 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3210
3211 ScriptFreeCache(&sc);
3212 }
3213
3214 static void test_ScriptLayout(void)
3215 {
3216 HRESULT hr;
3217 static const BYTE levels[][10] =
3218 {
3219 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
3220 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
3221 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
3222 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
3223
3224 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
3225 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
3226 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
3227 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
3228 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
3229
3230 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
3231 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
3232
3233 { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
3234 { 2, 2, 2, 0, 0, 0, 0, 0, 0, 0 },
3235 { 2, 2, 2, 4, 4, 4, 1, 1, 0, 0 },
3236 { 1, 2, 3, 0, 3, 2, 1, 0, 0, 0 }
3237 };
3238 static const int expect_l2v[][10] =
3239 {
3240 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3241 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3242 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3243 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3244
3245 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
3246 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
3247 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
3248 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3249 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
3250
3251 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3252 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
3253
3254 { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9},
3255 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
3256 { 2, 3, 4, 5, 6, 7, 1, 0, 8, 9},
3257 { 2, 0, 1, 3, 5, 6, 4, 7, 8, 9}
3258 };
3259 static const int expect_v2l[][10] =
3260 {
3261 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3262 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3263 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
3264 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
3265
3266 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
3267 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
3268 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
3269 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3270 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
3271
3272 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
3273 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
3274
3275 { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9},
3276 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
3277 { 7, 6, 0, 1, 2, 3, 4, 5, 8, 9},
3278 { 1, 2, 0, 3, 6, 4, 5, 7, 8, 9}
3279 };
3280
3281 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
3282
3283 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
3284 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3285
3286 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
3287 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
3288
3289 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
3290 {
3291 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
3292 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
3293
3294 for (j = 0; j < sizeof(levels[i]); j++)
3295 {
3296 ok(expect_v2l[i][j] == vistolog[j],
3297 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
3298 i, j, levels[i][j], j, vistolog[j] );
3299 }
3300
3301 for (j = 0; j < sizeof(levels[i]); j++)
3302 {
3303 ok(expect_l2v[i][j] == logtovis[j],
3304 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
3305 i, j, levels[i][j], j, logtovis[j] );
3306 }
3307 }
3308 }
3309
3310 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
3311 {
3312 HRESULT hr;
3313 SCRIPT_DIGITSUBSTITUTE sds;
3314 SCRIPT_CONTROL sc;
3315 SCRIPT_STATE ss;
3316 LCID lcid_old;
3317
3318 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
3319
3320 memset(&sds, 0, sizeof(sds));
3321 memset(&sc, 0, sizeof(sc));
3322 memset(&ss, 0, sizeof(ss));
3323
3324 lcid_old = GetThreadLocale();
3325 if (!SetThreadLocale(lcid)) return TRUE;
3326
3327 hr = ScriptRecordDigitSubstitution(lcid, &sds);
3328 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
3329
3330 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
3331 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
3332
3333 SetThreadLocale(lcid_old);
3334 return TRUE;
3335 }
3336
3337 static void test_digit_substitution(void)
3338 {
3339 BOOL ret;
3340 unsigned int i;
3341 static const LGRPID groups[] =
3342 {
3343 LGRPID_WESTERN_EUROPE,
3344 LGRPID_CENTRAL_EUROPE,
3345 LGRPID_BALTIC,
3346 LGRPID_GREEK,
3347 LGRPID_CYRILLIC,
3348 LGRPID_TURKISH,
3349 LGRPID_JAPANESE,
3350 LGRPID_KOREAN,
3351 LGRPID_TRADITIONAL_CHINESE,
3352 LGRPID_SIMPLIFIED_CHINESE,
3353 LGRPID_THAI,
3354 LGRPID_HEBREW,
3355 LGRPID_ARABIC,
3356 LGRPID_VIETNAMESE,
3357 LGRPID_INDIC,
3358 LGRPID_GEORGIAN,
3359 LGRPID_ARMENIAN
3360 };
3361 HMODULE hKernel32;
3362 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
3363
3364 hKernel32 = GetModuleHandleA("kernel32.dll");
3365 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
3366
3367 if (!pEnumLanguageGroupLocalesA)
3368 {
3369 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
3370 return;
3371 }
3372
3373 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
3374 {
3375 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
3376 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
3377 {
3378 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
3379 break;
3380 }
3381
3382 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
3383 }
3384 }
3385
3386 static void test_ScriptGetProperties(void)
3387 {
3388 const SCRIPT_PROPERTIES **props;
3389 HRESULT hr;
3390 int num;
3391
3392 hr = ScriptGetProperties(NULL, NULL);
3393 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
3394
3395 hr = ScriptGetProperties(NULL, &num);
3396 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3397
3398 hr = ScriptGetProperties(&props, NULL);
3399 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3400
3401 hr = ScriptGetProperties(&props, &num);
3402 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
3403 }
3404
3405 static void test_ScriptBreak(void)
3406 {
3407 static const WCHAR test[] = {' ','\r','\n',0};
3408 SCRIPT_ITEM items[4];
3409 SCRIPT_LOGATTR la;
3410 HRESULT hr;
3411
3412 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
3413 ok(hr == S_OK, "ScriptItemize should return S_OK not %08x\n", hr);
3414
3415 /*
3416 * This Test crashes pre Vista.
3417
3418 hr = ScriptBreak(test, 1, &items[0].a, NULL);
3419 ok(hr == E_INVALIDARG, "ScriptBreak should return E_INVALIDARG not %08x\n", hr);
3420 */
3421
3422 hr = ScriptBreak(test, 0, &items[0].a, &la);
3423 ok(hr == E_FAIL || broken(hr == S_OK), "ScriptBreak should return E_FAIL not %08x\n", hr);
3424
3425 hr = ScriptBreak(test, -1, &items[0].a, &la);
3426 ok(hr == E_INVALIDARG || broken(hr == S_OK), "ScriptBreak should return E_INVALIDARG not %08x\n", hr);
3427
3428 memset(&la, 0, sizeof(la));
3429 hr = ScriptBreak(test, 1, &items[0].a, &la);
3430 ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3431
3432 ok(!la.fSoftBreak, "fSoftBreak set\n");
3433 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
3434 ok(la.fCharStop, "fCharStop not set\n");
3435 ok(!la.fWordStop, "fWordStop set\n");
3436 ok(!la.fInvalid, "fInvalid set\n");
3437 ok(!la.fReserved, "fReserved set\n");
3438
3439 memset(&la, 0, sizeof(la));
3440 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
3441 ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3442
3443 ok(!la.fSoftBreak, "fSoftBreak set\n");
3444 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
3445 ok(la.fCharStop, "fCharStop not set\n");
3446 ok(!la.fWordStop, "fWordStop set\n");
3447 ok(!la.fInvalid, "fInvalid set\n");
3448 ok(!la.fReserved, "fReserved set\n");
3449
3450 memset(&la, 0, sizeof(la));
3451 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
3452 ok(hr == S_OK, "ScriptBreak should return S_OK not %08x\n", hr);
3453
3454 ok(!la.fSoftBreak, "fSoftBreak set\n");
3455 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
3456 ok(la.fCharStop, "fCharStop not set\n");
3457 ok(!la.fWordStop, "fWordStop set\n");
3458 ok(!la.fInvalid, "fInvalid set\n");
3459 ok(!la.fReserved, "fReserved set\n");
3460 }
3461
3462 static void test_newlines(void)
3463 {
3464 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
3465 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
3466 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
3467 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
3468 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
3469 SCRIPT_ITEM items[5];
3470 HRESULT hr;
3471 int count;
3472
3473 count = 0;
3474 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
3475 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3476 ok(count == 3, "got %d expected 3\n", count);
3477
3478 count = 0;
3479 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
3480 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3481 ok(count == 3, "got %d expected 3\n", count);
3482
3483 count = 0;
3484 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
3485 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3486 ok(count == 4, "got %d expected 4\n", count);
3487
3488 count = 0;
3489 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
3490 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3491 ok(count == 4, "got %d expected 4\n", count);
3492
3493 count = 0;
3494 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
3495 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3496 ok(count == 4, "got %d expected 4\n", count);
3497 }
3498
3499 static void test_ScriptGetFontFunctions(HDC hdc)
3500 {
3501 HRESULT hr;
3502 pScriptGetFontScriptTags = (void*)GetProcAddress(GetModuleHandleA("usp10.dll"), "ScriptGetFontScriptTags");
3503 pScriptGetFontLanguageTags = (void*)GetProcAddress(GetModuleHandleA("usp10.dll"), "ScriptGetFontLanguageTags");
3504 pScriptGetFontFeatureTags = (void*)GetProcAddress(GetModuleHandleA("usp10.dll"), "ScriptGetFontFeatureTags");
3505 if (!pScriptGetFontScriptTags || !pScriptGetFontLanguageTags || !pScriptGetFontFeatureTags)
3506 {
3507 win_skip("ScriptGetFontScriptTags,ScriptGetFontLanguageTags or ScriptGetFontFeatureTags not available on this platform\n");
3508 }
3509 else
3510 {
3511 SCRIPT_CACHE sc = NULL;
3512 OPENTYPE_TAG tags[5];
3513 int count = 0;
3514 int outnItems=0;
3515 SCRIPT_ITEM outpItems[15];
3516 SCRIPT_CONTROL Control;
3517 SCRIPT_STATE State;
3518 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
3519
3520 hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, NULL, NULL);
3521 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3522 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3523 hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, NULL, &count);
3524 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3525 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3526 hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 5, tags, NULL);
3527 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3528 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3529 hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 0, tags, &count);
3530 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3531 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3532 hr = pScriptGetFontScriptTags(NULL, &sc, NULL, 5, tags, &count);
3533 ok(hr == E_PENDING,"Incorrect return code\n");
3534 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3535 hr = pScriptGetFontScriptTags(hdc, &sc, NULL, 5, tags, &count);
3536 ok((hr == S_OK || hr == E_OUTOFMEMORY),"Incorrect return code\n");
3537 if (hr == S_OK)
3538 ok(count <= 5, "Count should be less or equal to 5 with S_OK return\n");
3539 else if (hr == E_OUTOFMEMORY)
3540 ok(count == 0, "Count should be 0 with E_OUTOFMEMORY return\n");
3541 ok(sc != NULL, "ScriptCache should be initialized\n");
3542
3543 ScriptFreeCache(&sc);
3544 sc = NULL;
3545
3546 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, NULL, NULL);
3547 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3548 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3549 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, NULL, &count);
3550 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3551 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3552 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 5, tags, NULL);
3553 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3554 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3555 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 0, tags, &count);
3556 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3557 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3558 hr = pScriptGetFontLanguageTags(NULL, &sc, NULL, latn_tag, 5, tags, &count);
3559 ok(hr == E_PENDING,"Incorrect return code\n");
3560 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3561 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, latn_tag, 5, tags, &count);
3562 ok((hr == S_OK || hr == E_OUTOFMEMORY),"Incorrect return code\n");
3563 if (hr == S_OK)
3564 ok(count <= 5, "Count should be less or equal to 5 with S_OK return\n");
3565 else if (hr == E_OUTOFMEMORY)
3566 ok(count == 0, "Count should be 0 with E_OUTOFMEMORY return\n");
3567
3568 ScriptFreeCache(&sc);
3569 sc = NULL;
3570
3571 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, NULL, NULL);
3572 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3573 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3574 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, NULL, &count);
3575 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3576 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3577 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 5, tags, NULL);
3578 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3579 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3580 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 0, tags, &count);
3581 ok(hr == E_INVALIDARG,"Incorrect return code\n");
3582 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3583 hr = pScriptGetFontFeatureTags(NULL, &sc, NULL, latn_tag, 0x0, 5, tags, &count);
3584 ok(hr == E_PENDING,"Incorrect return code\n");
3585 ok(sc == NULL, "ScriptCache should remain uninitialized\n");
3586 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, latn_tag, 0x0, 5, tags, &count);
3587 ok((hr == S_OK || hr == E_OUTOFMEMORY),"Incorrect return code\n");
3588 if (hr == S_OK)
3589 ok(count <= 5, "Count should be less or equal to 5 with S_OK return\n");
3590 else if (hr == E_OUTOFMEMORY)
3591 ok(count == 0, "Count should be 0 with E_OUTOFMEMORY return\n");
3592
3593 memset(&Control, 0, sizeof(Control));
3594 memset(&State, 0, sizeof(State));
3595
3596 hr = ScriptItemize(test_phagspa, 10, 15, &Control, &State, outpItems, &outnItems);
3597 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
3598 memset(tags,0,sizeof(tags));
3599 hr = pScriptGetFontScriptTags(hdc, &sc, &outpItems[0].a, 5, tags, &count);
3600 ok( hr == USP_E_SCRIPT_NOT_IN_FONT || broken(hr == S_OK), "wrong return code\n");
3601
3602 hr = pScriptGetFontLanguageTags(hdc, &sc, NULL, dsrt_tag, 5, tags, &count);
3603 ok( hr == S_OK, "wrong return code\n");
3604 hr = pScriptGetFontLanguageTags(hdc, &sc, &outpItems[0].a, dsrt_tag, 5, tags, &count);
3605 ok( hr == E_INVALIDARG || broken(hr == S_OK), "wrong return code\n");
3606
3607 hr = pScriptGetFontFeatureTags(hdc, &sc, NULL, dsrt_tag, 0x0, 5, tags, &count);
3608 ok( hr == S_OK, "wrong return code\n");
3609 hr = pScriptGetFontFeatureTags(hdc, &sc, &outpItems[0].a, dsrt_tag, 0x0, 5, tags, &count);
3610 ok( hr == E_INVALIDARG || broken(hr == S_OK), "wrong return code\n");
3611
3612 ScriptFreeCache(&sc);
3613 }
3614 }
3615
3616 struct logical_width_test
3617 {
3618 int char_count;
3619 int glyph_count;
3620 int advances[3];
3621 WORD map[3];
3622 int widths[3];
3623 BOOL clusterstart[3];
3624 BOOL diacritic[3];
3625 BOOL zerowidth[3];
3626 BOOL todo;
3627 };
3628
3629 static const struct logical_width_test logical_width_tests[] =
3630 {
3631 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 6, 9, 12 }, { 1, 1, 1 } },
3632 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 6, 9, 12 }, { 1, 1, 1 }, { 1, 0, 0 } },
3633 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 6, 9, 12 }, { 1, 1, 1 }, { 0 }, { 1, 1, 1 } },
3634 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 27, 21, 12 }, { 0, 0, 0 }, { 0 }, { 0 }, TRUE },
3635 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 6, 21, 12 }, { 0, 1, 0 }, { 0 }, { 0 }, TRUE },
3636 { 3, 3, { 6, 9, 12 }, { 0, 1, 2 }, { 6, 21, 12 }, { 1, 1, 0 }, { 0 }, { 0 }, TRUE },
3637 { 3, 3, { 6, 9, 12 }, { 0, 2, 2 }, { 15, 6, 6 }, { 1, 0, 1 } },
3638 };
3639
3640 static void test_ScriptGetLogicalWidths(void)
3641 {
3642 SCRIPT_ANALYSIS sa = { 0 };
3643 unsigned int i, j;
3644
3645 for (i = 0; i < sizeof(logical_width_tests)/sizeof(logical_width_tests[0]); i++)
3646 {
3647 const struct logical_width_test *ptr = logical_width_tests + i;
3648 SCRIPT_VISATTR attrs[3];
3649 int widths[3];
3650 HRESULT hr;
3651
3652 memset(attrs, 0, sizeof(attrs));
3653 for (j = 0; j < ptr->glyph_count; j++)
3654 {
3655 attrs[j].fClusterStart = ptr->clusterstart[j];
3656 attrs[j].fDiacritic = ptr->diacritic[j];
3657 attrs[j].fZeroWidth = ptr->zerowidth[j];
3658 }
3659
3660 hr = ScriptGetLogicalWidths(&sa, ptr->char_count, ptr->glyph_count, ptr->advances, ptr->map, attrs, widths);
3661 ok(hr == S_OK, "got 0x%08x\n", hr);
3662
3663 todo_wine_if(ptr->todo)
3664 ok(!memcmp(ptr->widths, widths, sizeof(widths)), "test %u: got wrong widths\n", i);
3665 }
3666 }
3667
3668 START_TEST(usp10)
3669 {
3670 HWND hwnd;
3671 HDC hdc;
3672 LOGFONTA lf;
3673 HFONT hfont;
3674
3675 unsigned short pwOutGlyphs[256];
3676
3677 /* We need a valid HDC to drive a lot of Script functions which requires the following *
3678 * to set up for the tests. */
3679 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
3680 0, 0, 0, NULL);
3681 assert(hwnd != 0);
3682 ShowWindow(hwnd, SW_SHOW);
3683 UpdateWindow(hwnd);
3684
3685 hdc = GetDC(hwnd); /* We now have a hdc */
3686 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
3687
3688 memset(&lf, 0, sizeof(LOGFONTA));
3689 lstrcpyA(lf.lfFaceName, "Tahoma");
3690 lf.lfHeight = 10;
3691 lf.lfWeight = 3;
3692 lf.lfWidth = 10;
3693
3694 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
3695 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
3696
3697 test_ScriptItemize();
3698 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
3699 test_ScriptGetCMap(hdc, pwOutGlyphs);
3700 test_ScriptCacheGetHeight(hdc);
3701 test_ScriptGetGlyphABCWidth(hdc);
3702 test_ScriptShape(hdc);
3703 test_ScriptShapeOpenType(hdc);
3704 test_ScriptPlace(hdc);
3705
3706 test_ScriptGetFontProperties(hdc);
3707 test_ScriptTextOut(hdc);
3708 test_ScriptTextOut2(hdc);
3709 test_ScriptTextOut3(hdc);
3710 test_ScriptXtoX();
3711 test_ScriptString(hdc);
3712 test_ScriptStringXtoCP_CPtoX(hdc);
3713
3714 test_ScriptLayout();
3715 test_digit_substitution();
3716 test_ScriptGetProperties();
3717 test_ScriptBreak();
3718 test_newlines();
3719
3720 test_ScriptGetFontFunctions(hdc);
3721 test_ScriptGetLogicalWidths();
3722
3723 ReleaseDC(hwnd, hdc);
3724 DestroyWindow(hwnd);
3725 }