4 * Copyright 2006 Jeff Latimer
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
30 #include <wine/test.h>
34 typedef struct _itemTest {
43 typedef struct _shapeTest_char {
45 SCRIPT_CHARPROP CharProp;
48 typedef struct _shapeTest_glyph {
50 SCRIPT_GLYPHPROP GlyphProp;
53 /* Uniscribe 1.6 calls */
54 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);
56 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);
58 static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
60 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
61 SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
62 DWORD nItems, const itemTest* items, BOOL nItemsToDo,
67 SCRIPT_ITEM outpItems[15];
68 ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
70 if (pScriptItemizeOpenType)
71 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
73 hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
75 winetest_ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
76 if (nItemsBroken && broken(nItemsBroken == outnItems))
78 winetest_win_skip("This test broken on this platform\n");
82 todo_wine winetest_ok(outnItems == nItems, "Wrong number of items\n");
84 winetest_ok(outnItems == nItems, "Wrong number of items\n");
85 for (x = 0; x <= outnItems; x++)
87 if (items[x].todo_flag[0])
88 todo_wine winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos\n",x);
90 winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
92 if (items[x].todo_flag[1])
93 todo_wine winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL\n",x);
95 winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
96 if (items[x].todo_flag[2])
97 todo_wine winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL\n",x);
99 winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
100 if (items[x].todo_flag[3])
101 todo_wine winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel\n",x);
103 winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
105 winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
106 if (pScriptItemizeOpenType)
108 if (items[x].todo_flag[4])
109 todo_wine winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
111 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
116 #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)
118 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
119 ( ( (ULONG)_x4 << 24 ) | \
120 ( (ULONG)_x3 << 16 ) | \
121 ( (ULONG)_x2 << 8 ) | \
124 #define latn_tag MS_MAKE_TAG('l','a','t','n')
125 #define arab_tag MS_MAKE_TAG('a','r','a','b')
126 #define thai_tag MS_MAKE_TAG('t','h','a','i')
127 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
128 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
129 #define deva_tag MS_MAKE_TAG('d','e','v','a')
130 #define beng_tag MS_MAKE_TAG('b','e','n','g')
132 static void test_ScriptItemize( void )
134 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
135 static const itemTest t11[2] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},4,0,0,0,-1}};
136 static const itemTest t12[2] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},4,0,0,0,-1}};
138 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
139 static const itemTest t1b1[2] = {{{0,0,0,0,0},0,0,0,0,0},{{0,0,0,0,0},4,0,0,0,-1}};
140 static const itemTest t1b2[2] = {{{0,0,0,0,0},0,1,1,1,0},{{0,0,0,0,0},4,0,0,0,-1}};
143 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
144 static const itemTest t21[7] = {{{0,0,0,0,0},0,0,0,0,0},{{0,0,0,0,0},3,0,0,0,0},{{0,0,0,0,0},4,0,0,0,0},{{0,0,0,0,0},6,1,1,1,arab_tag},{{0,0,0,0,0},13,0,0,0,0},{{0,0,0,0,0},15,0,0,0,0},{{0,0,0,0,0},16,0,0,0,-1}};
145 static const itemTest t22[5] = {{{0,0,0,1,0},0,0,0,2,0},{{0,0,0,0,0},6,1,1,1,arab_tag},{{0,0,1,0,0},13,0,1,2,0},{{0,0,0,0,0},15,0,0,0,0},{{0,0,0,0,0},16,0,0,0,-1}};
146 static const itemTest t23[5] = {{{0,0,1,0,0},0,0,1,2,0},{{0,0,0,0,0},6,1,1,1,arab_tag},{{0,0,1,0,0},13,0,1,2,0},{{0,0,0,0,0},15,1,1,1,0},{{0,0,0,0,0},16,0,0,0,-1}};
148 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
149 static const itemTest t2b1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},3,0,0,0,0},{{0,0,0,0,0},4,0,0,0,latn_tag},{{0,0,0,0,0},8,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
150 static const itemTest t2b2[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},3,0,0,2,0},{{0,0,0,0,0},4,0,0,2,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
151 static const itemTest t2b3[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
154 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
155 static const itemTest t2c1[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag},{{0,0,0,0,0},4,0,0,0,latn_tag},{{0,0,0,0,0},7,0,0,0,0},{{0,0,0,0,0},8,0,0,0,latn_tag},{{0,0,0,0,0},11,0,0,0,-1}};
156 static const itemTest t2c2[6] = {{{0,0,0,0,1},0,0,0,0,0},{{0,0,0,0,0},1,1,1,1,arab_tag},{{0,0,0,0,0},4,0,0,0,latn_tag},{{0,0,0,0,0},7,0,0,0,0},{{0,0,0,0,0},8,0,0,0,latn_tag},{{0,0,0,0,0},11,0,0,0,-1}};
157 static const itemTest t2c3[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag},{{0,0,0,0,0},4,0,0,2,latn_tag},{{0,0,0,0,0},7,0,0,2,0},{{0,0,0,0,0},8,0,0,2,latn_tag},{{0,0,0,0,0},11,0,0,0,-1}};
158 static const itemTest t2c4[3] = {{{0,0,0,0,0},0,1,1,1,arab_tag},{{0,0,0,0,0},4,0,0,2,latn_tag},{{0,0,0,0,0},11,0,0,0,-1}};
161 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
162 static const itemTest t2d1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},3,0,0,0,0},{{0,0,0,0,0},4,0,0,0,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
163 static const itemTest t2d2[6] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},3,0,0,0,0},{{0,0,0,0,0},4,0,0,0,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},10,0,0,0,0},{{0,0,0,0,0},11,0,0,0,-1}};
164 static const itemTest t2d3[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},3,0,0,2,0},{{0,0,0,0,0},4,0,0,2,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
165 static const itemTest t2d4[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},7,1,1,1,arab_tag},{{0,0,0,0,0},11,0,0,0,-1}};
168 static const WCHAR test3[] =
169 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
170 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
171 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
172 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
174 static const itemTest t31[2] = {{{0,0,0,0,0},0,0,0,0,thai_tag},{{0,0,0,0,0},41,0,0,0,-1}};
175 static const itemTest t32[2] = {{{0,0,0,0,0},0,0,0,2,thai_tag},{{0,0,0,0,0},41,0,0,0,-1}};
177 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
179 static const itemTest t41[6] = {{{0,0,0,0,0},0,0,0,0,0},{{0,0,0,0,0},3,0,0,0,0},{{0,0,0,0,0},4,0,0,0,0},{{0,0,0,0,0},7,0,0,0,latn_tag},{{0,0,0,0,0},10,0,0,0,0},{{0,0,0,0,0},12,0,0,0,-1}};
180 static const itemTest t42[5] = {{{0,0,1,0,0},0,0,1,2,0},{{0,0,0,0,1},6,1,1,1,0},{{0,0,0,0,0},7,0,0,2,latn_tag},{{0,0,0,0,0},10,0,0,2,0},{{0,0,0,0,0},12,0,0,0,-1}};
181 static const itemTest t43[4] = {{{0,0,1,0,0},0,0,1,2,0},{{0,0,0,0,1},6,1,1,1,0},{{0,0,0,0,0},7,0,0,2,latn_tag},{{0,0,0,0,0},12,0,0,0,-1}};
184 static const WCHAR test5[] =
185 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
186 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
187 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
188 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
189 static const itemTest t51[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag},{{0,0,0,0,0},38,0,0,0,-1}};
192 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
193 static const itemTest t61[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag},{{0,0,0,0,0},4,0,0,0,0},{{0,0,0,0,0},5,0,0,0,-1}};
194 static const itemTest t62[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag},{{0,0,0,0,0},4,1,1,1,0},{{0,0,0,0,0},5,0,0,0,-1}};
195 static const itemTest t63[2] = {{{0,0,0,0,0},0,1,1,1,hebr_tag},{{0,0,0,0,0},5,0,0,0,-1}};
196 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};
197 static const itemTest t71[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},9,1,1,1,hebr_tag},{{0,0,0,0,0},19,0,0,0,latn_tag},{{0,0,0,0,0},29,0,0,0,-1}};
198 static const itemTest t72[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag},{{0,0,0,0,0},9,1,1,1,hebr_tag},{{0,0,0,0,0},18,0,0,0,latn_tag},{{0,0,0,0,0},29,0,0,0,-1}};
199 static const itemTest t73[4] = {{{0,0,0,0,0},0,0,0,2,latn_tag},{{0,0,0,0,0},8,1,1,1,hebr_tag},{{0,0,0,0,0},19,0,0,2,latn_tag},{{0,0,0,0,0},29,0,0,0,-1}};
200 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
201 static const itemTest t81[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag},{{0,0,0,0,0},4,0,0,0,-1}};
203 /* Syriac (Like Arabic )*/
204 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
205 static const itemTest t91[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,0,0,0,0},{{0,0,0,0,0},5,0,0,0,-1}};
206 static const itemTest t92[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,1,1,1,0},{{0,0,0,0,0},5,0,0,0,-1}};
207 static const itemTest t93[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},5,0,0,0,-1}};
209 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
210 static const itemTest t101[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag},{{0,0,0,0,0},4,0,0,0,-1}};
213 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
214 static const itemTest t111[2] = {{{0,0,0,0,0},0,0,0,0,deva_tag},{{0,0,0,0,0},8,0,0,0,-1}};
215 static const itemTest t112[2] = {{{0,0,0,0,0},0,0,0,2,deva_tag},{{0,0,0,0,0},8,0,0,0,-1}};
218 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
219 static const itemTest t121[2] = {{{0,0,0,0,0},0,0,0,0,beng_tag},{{0,0,0,0,0},5,0,0,0,-1}};
220 static const itemTest t122[2] = {{{0,0,0,0,0},0,0,0,2,beng_tag},{{0,0,0,0,0},5,0,0,0,-1}};
222 SCRIPT_ITEM items[15];
223 SCRIPT_CONTROL Control;
229 usp10 = LoadLibraryA("usp10.dll");
230 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
231 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
232 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
233 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
235 memset(&Control, 0, sizeof(Control));
236 memset(&State, 0, sizeof(State));
238 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
239 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
241 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
242 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
244 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
245 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
247 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
248 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
250 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
251 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
252 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
253 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
254 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
255 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
256 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
257 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
258 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
259 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
260 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
261 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
262 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
263 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
264 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
265 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
267 State.uBidiLevel = 0;
268 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
269 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
270 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
271 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
272 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
273 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
274 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
275 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
276 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
277 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
278 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
279 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
280 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
281 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
282 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
283 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
285 State.uBidiLevel = 1;
286 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
287 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
288 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
289 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
290 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
291 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
292 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
293 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
294 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
295 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
296 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
297 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
298 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
299 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
300 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
301 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
303 State.uBidiLevel = 1;
304 Control.fMergeNeutralItems = TRUE;
305 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
306 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
307 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
308 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,4);
309 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,4);
310 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,4);
311 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
312 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,4);
313 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
314 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,2);
315 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
316 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
317 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,2);
318 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
319 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
320 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
323 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
324 DWORD cchString, SCRIPT_CONTROL *Control,
325 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
326 const shapeTest_char* charItems,
327 const shapeTest_glyph* glyphItems)
330 int x, outnItems=0, outnGlyphs=0;
331 SCRIPT_ITEM outpItems[15];
332 SCRIPT_CACHE sc = NULL;
335 int maxGlyphs = cchString * 1.5;
336 SCRIPT_GLYPHPROP *glyphProp;
337 SCRIPT_CHARPROP *charProp;
340 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
341 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
344 winetest_win_skip("Select font does not support script\n");
346 winetest_trace("Select font does not support script\n");
350 winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
352 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
355 if (outnItems <= item)
358 winetest_win_skip("Did not get enough items\n");
360 winetest_trace("Did not get enough items\n");
364 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
365 memset(logclust,'a',sizeof(WORD) * cchString);
366 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
367 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
368 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
369 memset(glyphs,'a',sizeof(WORD) * cchString);
370 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
371 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
373 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
375 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
377 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
381 for (x = 0; x < cchString; x++)
384 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
385 else if (logclust[x] != charItems[x].wLogClust)
386 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
388 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
389 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
390 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
394 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
395 else if (nGlyphs != outnGlyphs)
396 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
397 for (x = 0; x < outnGlyphs; x++)
399 if (glyphItems[x].Glyph)
402 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
403 else if (glyphs[x]==0)
404 winetest_trace("%i: Glyph not present when it should be\n",x);
409 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
410 else if (glyphs[x]!=0)
411 winetest_trace("%i: Glyph present when it should not be\n",x);
414 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
415 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
416 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
418 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
419 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
420 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
422 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
423 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
424 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
426 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
427 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
428 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
431 HeapFree(GetProcessHeap(),0,logclust);
432 HeapFree(GetProcessHeap(),0,charProp);
433 HeapFree(GetProcessHeap(),0,glyphs);
434 HeapFree(GetProcessHeap(),0,glyphProp);
435 ScriptFreeCache(&sc);
438 #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)
440 #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)
442 typedef struct tagRangeP {
447 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
448 DWORD FontType, LPARAM lParam)
450 NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
451 fontEnumParam *rp = (fontEnumParam*) lParam;
456 if (FontType != TRUETYPE_FONTTYPE)
460 while (i > sizeof(DWORD)*8)
463 i -= (sizeof(DWORD)*8);
470 if (ntme->ntmFontSig.fsUsb[idx] & mask)
472 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
478 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
481 fontEnumParam lParam;
483 lParam.range = range;
484 memset(&lParam.lf,0,sizeof(LOGFONT));
489 lstrcpyA(lParam.lf.lfFaceName, recommended);
490 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
492 *hfont = CreateFontIndirectA(&lParam.lf);
495 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
503 memset(&lParam.lf,0,sizeof(LOGFONT));
504 lParam.lf.lfCharSet = DEFAULT_CHARSET;
506 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
508 *hfont = CreateFontIndirectA(&lParam.lf);
510 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
518 *origFont = SelectObject(hdc,*hfont);
519 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
521 winetest_trace(" Font fails to contain required glyphs\n");
522 SelectObject(hdc,*origFont);
523 DeleteObject(*hfont);
531 winetest_trace("Failed to find usable font\n");
536 #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)
538 static void test_ScriptShapeOpenType(HDC hdc)
541 SCRIPT_CACHE sc = NULL;
542 WORD glyphs[4], logclust[4];
543 SCRIPT_GLYPHPROP glyphProp[4];
544 SCRIPT_ITEM items[2];
546 SCRIPT_CONTROL Control;
549 HFONT hfont, hfont_orig;
552 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
553 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
554 static const shapeTest_glyph t1_g[] = {
555 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
556 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
557 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
558 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
560 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
561 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
562 static const shapeTest_glyph t2_g[] = {
563 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
564 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
565 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
566 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
569 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
570 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
571 static const shapeTest_glyph hebrew_g[] = {
572 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
573 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
574 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
575 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
578 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
579 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
580 static const shapeTest_glyph arabic_g[] = {
581 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
582 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
583 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
586 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
587 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}}};
588 static const shapeTest_glyph thai_g[] = {
589 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
590 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
591 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
592 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
593 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
594 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
595 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
596 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
597 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
598 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
601 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
602 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
603 static const shapeTest_glyph syriac_g[] = {
604 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
605 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
606 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
607 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
608 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
609 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
612 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
613 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}}};
614 static const shapeTest_glyph thaana_g[] = {
615 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
616 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
617 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
618 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
619 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
620 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
621 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
622 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
623 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
624 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
625 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
626 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
627 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
630 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
631 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}}};
632 static const shapeTest_glyph phagspa_g[] = {
633 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
634 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
635 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
636 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
637 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
638 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
639 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
640 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
641 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
642 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
643 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
646 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
647 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}}};
648 static const shapeTest_glyph lao_g[] = {
649 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
650 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
651 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
652 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
653 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
654 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
655 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
656 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
657 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
660 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
661 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}}};
662 static const shapeTest_glyph tibetan_g[] = {
663 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
664 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
665 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
666 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
667 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
668 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
669 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
670 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
671 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
672 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
673 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
674 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
675 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
676 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
677 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
678 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
679 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
681 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
683 win_skip("ScriptShapeOpenType not available on this platform\n");
687 memset(&Control, 0 , sizeof(Control));
688 memset(&State, 0 , sizeof(State));
690 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
691 ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
692 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
694 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
695 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
697 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
698 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
700 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
701 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
703 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
704 ok( hr == E_INVALIDARG,
705 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
706 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
707 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
709 ScriptFreeCache(&sc);
711 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
712 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
714 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
717 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
718 SelectObject(hdc, hfont_orig);
722 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
725 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
726 SelectObject(hdc, hfont_orig);
730 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
733 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
734 SelectObject(hdc, hfont_orig);
738 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
741 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
742 SelectObject(hdc, hfont_orig);
746 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
749 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
750 SelectObject(hdc, hfont_orig);
754 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
757 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
758 SelectObject(hdc, hfont_orig);
762 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
765 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
766 SelectObject(hdc, hfont_orig);
770 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
773 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
774 SelectObject(hdc, hfont_orig);
779 static void test_ScriptShape(HDC hdc)
781 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
782 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
784 SCRIPT_CACHE sc = NULL;
785 WORD glyphs[4], glyphs2[4], logclust[4];
786 SCRIPT_VISATTR attrs[4];
787 SCRIPT_ITEM items[2];
790 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
791 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
792 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
794 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
795 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
797 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
798 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
800 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
801 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
803 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
804 ok(broken(hr == S_OK) ||
805 hr == E_INVALIDARG || /* Vista, W2K8 */
806 hr == E_FAIL, /* WIN7 */
807 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
808 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
810 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
811 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
812 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
815 memset(glyphs,-1,sizeof(glyphs));
816 memset(logclust,-1,sizeof(logclust));
817 memset(attrs,-1,sizeof(attrs));
818 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
819 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
820 ok(nb == 4, "Wrong number of items\n");
821 ok(logclust[0] == 0, "clusters out of order\n");
822 ok(logclust[1] == 1, "clusters out of order\n");
823 ok(logclust[2] == 2, "clusters out of order\n");
824 ok(logclust[3] == 3, "clusters out of order\n");
825 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
826 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
827 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
828 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
829 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
830 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
831 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
832 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
833 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
834 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
835 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
836 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
837 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
838 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
839 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
840 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
842 ScriptFreeCache(&sc);
845 memset(glyphs2,-1,sizeof(glyphs2));
846 memset(logclust,-1,sizeof(logclust));
847 memset(attrs,-1,sizeof(attrs));
848 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
849 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
850 ok(nb == 4, "Wrong number of items\n");
851 ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
852 ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
853 ok(logclust[0] == 0, "clusters out of order\n");
854 ok(logclust[1] == 1, "clusters out of order\n");
855 ok(logclust[2] == 2, "clusters out of order\n");
856 ok(logclust[3] == 3, "clusters out of order\n");
857 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
858 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
859 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
860 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
861 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
862 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
863 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
864 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
865 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
866 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
867 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
868 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
869 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
870 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
871 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
872 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
874 /* modify LTR to RTL */
876 memset(glyphs2,-1,sizeof(glyphs2));
877 memset(logclust,-1,sizeof(logclust));
878 memset(attrs,-1,sizeof(attrs));
879 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
880 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
881 ok(nb == 4, "Wrong number of items\n");
882 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
883 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
884 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
885 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
886 ok(logclust[0] == 3, "clusters out of order\n");
887 ok(logclust[1] == 2, "clusters out of order\n");
888 ok(logclust[2] == 1, "clusters out of order\n");
889 ok(logclust[3] == 0, "clusters out of order\n");
890 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
891 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
892 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
893 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
894 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
895 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
896 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
897 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
898 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
899 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
900 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
901 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
902 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
903 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
904 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
905 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
907 ScriptFreeCache(&sc);
910 static void test_ScriptPlace(HDC hdc)
912 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
915 SCRIPT_CACHE sc = NULL;
916 WORD glyphs[4], logclust[4];
917 SCRIPT_VISATTR attrs[4];
918 SCRIPT_ITEM items[2];
923 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
924 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
925 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
927 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
928 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
929 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
931 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
932 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
934 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
935 ok(broken(hr == E_PENDING) ||
936 hr == E_INVALIDARG || /* Vista, W2K8 */
937 hr == E_FAIL, /* WIN7 */
938 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
940 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
941 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
943 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
944 ok(broken(hr == E_PENDING) ||
945 hr == E_INVALIDARG || /* Vista, W2K8 */
946 hr == E_FAIL, /* WIN7 */
947 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
949 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
950 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
951 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
953 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
954 ok(ret, "ExtTextOutW should return TRUE\n");
956 ScriptFreeCache(&sc);
959 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
963 const SCRIPT_PROPERTIES **ppSp;
967 SCRIPT_ITEM pItem[255];
969 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
970 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
971 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
972 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
973 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
974 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
979 unsigned short pwOutGlyphs1[256];
980 unsigned short pwOutGlyphs2[256];
981 unsigned short pwLogClust[256];
982 SCRIPT_VISATTR psva[256];
985 GOFFSET pGoffset[256];
989 /* Start testing usp10 functions */
990 /* This test determines that the pointer returned by ScriptGetProperties is valid
991 * by checking a known value in the table */
992 hr = ScriptGetProperties(&ppSp, &iMaxProps);
993 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
994 trace("number of script properties %d\n", iMaxProps);
995 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
997 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1000 /* This is a valid test that will cause parsing to take place */
1003 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1004 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1005 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1007 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1009 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1010 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1011 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1013 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1014 * ie. ScriptItemize has succeeded and that pItem has been set */
1017 psc = NULL; /* must be null on first call */
1019 cMaxGlyphs = cInChars;
1020 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1021 cMaxGlyphs, &pItem[0].a,
1022 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1023 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1025 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1026 cMaxGlyphs, &pItem[0].a,
1027 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1028 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1029 "(%d) but not E_OUTOFMEMORY\n",
1030 cChars, cMaxGlyphs);
1032 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1033 cMaxGlyphs, &pItem[0].a,
1034 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1035 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1036 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1037 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1039 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1041 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1042 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1044 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1045 for (cnt=0; cnt < pcGlyphs; cnt++)
1046 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1049 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1050 * takes place if fNoGlyphIndex is set. */
1054 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1055 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1056 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1058 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1059 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1060 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1061 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1065 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1066 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1067 cMaxGlyphs, &pItem[0].a,
1068 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1069 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1070 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1071 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1072 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1073 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1074 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1075 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1077 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1079 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1082 ScriptFreeCache( &psc);
1083 ok (!psc, "psc is not null after ScriptFreeCache\n");
1087 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1088 cInChars = (sizeof(TestItem3)/2)-1;
1090 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1091 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1094 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1097 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1098 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1099 pItem[0].iCharPos, pItem[1].iCharPos);
1100 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1101 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1102 pItem[1].iCharPos, pItem[2].iCharPos);
1103 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1104 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1105 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1109 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1110 cInChars = (sizeof(TestItem4)/2)-1;
1112 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1113 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1116 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1119 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1120 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1121 pItem[0].iCharPos, pItem[1].iCharPos);
1122 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1123 pItem[0].a.s.uBidiLevel);
1124 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1125 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1126 pItem[1].iCharPos, pItem[2].iCharPos);
1127 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1128 pItem[1].a.s.uBidiLevel);
1129 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1130 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1131 pItem[2].iCharPos, pItem[3].iCharPos);
1132 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1133 pItem[2].a.s.uBidiLevel);
1134 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1135 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1136 pItem[3].iCharPos, pItem[4].iCharPos);
1137 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1138 pItem[3].a.s.uBidiLevel);
1139 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1140 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1141 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1146 * This test is for when the first unicode character requires bidi support
1148 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1149 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1150 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1151 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1152 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1153 pItem[0].a.s.uBidiLevel);
1155 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
1156 * the pointer to the last char works. Note that windows often needs a greater number of *
1157 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
1158 cInChars = (sizeof(TestItem6)/2)-1;
1160 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1161 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1165 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1168 SCRIPT_CACHE psc = NULL;
1171 unsigned short pwOutGlyphs2[256];
1172 unsigned short pwOutGlyphs3[256];
1176 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1177 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1178 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1179 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1181 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
1183 cInChars = cChars = 5;
1184 /* Some sanity checks for ScriptGetCMap */
1186 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1187 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1188 "expected E_INVALIDARG, got %08x\n", hr);
1190 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1191 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1192 "expected E_INVALIDARG, got %08x\n", hr);
1194 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1196 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1197 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1199 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1201 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1203 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1204 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1206 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1207 ScriptFreeCache( &psc);
1209 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1211 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1212 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1213 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1214 /* Check to see if the results are the same as those returned by ScriptShape */
1215 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1216 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1217 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1218 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1219 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1220 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1222 ScriptFreeCache( &psc);
1223 ok (!psc, "psc is not null after ScriptFreeCache\n");
1225 cInChars = cChars = 4;
1226 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1227 ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1228 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1229 ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1230 ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1233 cInChars = cChars = 9;
1234 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1235 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1236 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1238 cInChars = cChars = 9;
1240 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1241 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1242 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1243 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1244 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1245 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1246 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1247 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1248 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1249 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1250 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1251 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1253 ScriptFreeCache( &psc);
1254 ok (!psc, "psc is not null after ScriptFreeCache\n");
1257 static void test_ScriptGetFontProperties(HDC hdc)
1260 SCRIPT_CACHE psc,old_psc;
1261 SCRIPT_FONTPROPERTIES sfp;
1263 /* Some sanity checks for ScriptGetFontProperties */
1265 hr = ScriptGetFontProperties(NULL,NULL,NULL);
1266 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1268 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1269 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1271 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1273 hr = ScriptGetFontProperties(NULL,&psc,NULL);
1274 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1275 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1277 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1279 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1280 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1281 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1283 hr = ScriptGetFontProperties(hdc,NULL,NULL);
1284 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1286 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1287 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1289 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1291 hr = ScriptGetFontProperties(hdc,&psc,NULL);
1292 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1293 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1295 /* Pass an invalid sfp */
1297 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1298 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1299 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1300 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1301 ScriptFreeCache(&psc);
1302 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1304 /* Give it the correct cBytes, we don't care about what's coming back */
1305 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1307 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1308 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1309 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1311 /* Save the psc pointer */
1313 /* Now a NULL hdc again */
1314 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1315 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1316 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1317 ScriptFreeCache(&psc);
1318 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1321 static void test_ScriptTextOut(HDC hdc)
1327 SCRIPT_ITEM pItem[255];
1329 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1334 unsigned short pwOutGlyphs1[256];
1335 WORD pwLogClust[256];
1336 SCRIPT_VISATTR psva[256];
1339 GOFFSET pGoffset[256];
1344 BOOL fTrailing = FALSE;
1345 SCRIPT_LOGATTR *psla;
1346 SCRIPT_LOGATTR sla[256];
1348 /* This is a valid test that will cause parsing to take place */
1351 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1352 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1353 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1355 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1357 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1358 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1359 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1361 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1362 * ie. ScriptItemize has succeeded and that pItem has been set */
1365 psc = NULL; /* must be null on first call */
1368 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1369 cMaxGlyphs, &pItem[0].a,
1370 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1371 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1372 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1373 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1375 /* Note hdc is needed as glyph info is not yet in psc */
1376 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1378 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1379 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
1380 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1382 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1383 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1385 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1386 piAdvance, NULL, pGoffset);
1387 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1388 "expected E_INVALIDARG, got %08x\n", hr);
1390 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1392 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1394 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1396 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1398 /* hdc is required for this one rather than the usual optional */
1400 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1401 piAdvance, NULL, pGoffset);
1402 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1403 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1405 /* Set that it returns 0 status */
1406 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1407 piAdvance, NULL, pGoffset);
1408 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1410 /* Test Rect Rgn is acceptable */
1415 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1416 piAdvance, NULL, pGoffset);
1417 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1420 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1421 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1422 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1424 psla = (SCRIPT_LOGATTR *)&sla;
1425 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1426 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1428 /* Clean up and go */
1429 ScriptFreeCache(&psc);
1430 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1435 static void test_ScriptTextOut2(HDC hdc)
1437 /* Intent is to validate that the HDC passed into ScriptTextOut is
1438 * used instead of the (possibly) invalid cached one
1445 SCRIPT_ITEM pItem[255];
1447 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1452 unsigned short pwOutGlyphs1[256];
1453 WORD pwLogClust[256];
1454 SCRIPT_VISATTR psva[256];
1457 GOFFSET pGoffset[256];
1460 /* Create an extra DC that will be used until the ScriptTextOut */
1461 hdc1 = CreateCompatibleDC(hdc);
1462 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1463 hdc2 = CreateCompatibleDC(hdc);
1464 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1466 /* This is a valid test that will cause parsing to take place */
1469 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1470 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1471 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1473 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1475 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1476 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1477 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1479 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1480 * ie. ScriptItemize has succeeded and that pItem has been set */
1483 psc = NULL; /* must be null on first call */
1486 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1487 cMaxGlyphs, &pItem[0].a,
1488 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1489 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1490 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1491 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1493 /* Note hdc is needed as glyph info is not yet in psc */
1494 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1496 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1498 /* key part!!! cached dc is being deleted */
1499 hr = DeleteDC(hdc2);
1500 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1502 /* At this point the cached hdc (hdc2) has been destroyed,
1503 * however, we are passing in a *real* hdc (the original hdc).
1504 * The text should be written to that DC
1506 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1507 piAdvance, NULL, pGoffset);
1508 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1509 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1513 /* Clean up and go */
1514 ScriptFreeCache(&psc);
1515 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1520 static void test_ScriptTextOut3(HDC hdc)
1526 SCRIPT_ITEM pItem[255];
1528 WCHAR TestItem1[] = {' ','\r', 0};
1533 unsigned short pwOutGlyphs1[256];
1534 WORD pwLogClust[256];
1535 SCRIPT_VISATTR psva[256];
1538 GOFFSET pGoffset[256];
1542 /* This is to ensure that non exisiting glyphs are translated into a valid glyph number */
1545 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1546 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1547 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1549 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1551 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
1552 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1553 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
1555 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1556 * ie. ScriptItemize has succeeded and that pItem has been set */
1559 psc = NULL; /* must be null on first call */
1562 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1563 cMaxGlyphs, &pItem[0].a,
1564 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1565 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1566 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1567 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1569 /* Note hdc is needed as glyph info is not yet in psc */
1570 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1572 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1574 /* Test Rect Rgn is acceptable */
1579 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1580 piAdvance, NULL, pGoffset);
1581 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1584 /* Clean up and go */
1585 ScriptFreeCache(&psc);
1586 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1590 static void test_ScriptXtoX(void)
1591 /****************************************************************************************
1592 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
1593 ****************************************************************************************/
1595 static const WCHAR test[] = {'t', 'e', 's', 't',0};
1596 SCRIPT_ITEM items[2];
1600 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
1601 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
1602 SCRIPT_VISATTR psva[10];
1603 int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
1608 static const int offsets[13] = {0, 66, 133, 200, 295, 390, 495, 600, 1051, 1502, 1953, 1953, 1953};
1609 static const int offsets_RTL[13] = {780, 720, 660, 600, 495, 390, 295, 200, 133, 66, 0, 0, 0};
1611 hr = ScriptItemize(test, lstrlenW(test), sizeof(items)/sizeof(items[0]), NULL, NULL, items, NULL);
1612 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1617 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1618 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1620 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1622 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1624 for(iCP = 0; iCP < 10; iCP++)
1626 iX = offsets[iCP]+1;
1629 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1630 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1631 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1632 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1635 for(iCP = 0; iCP < 10; iCP++)
1637 iX = offsets[iCP+1]-1;
1640 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1641 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1642 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1643 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1646 /* 0,1,2 are actually fractional offsets meaning that they will not be reporting the same iCP as comes in so don't test those */
1647 for(iCP = 3; iCP < 10; iCP++)
1652 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1653 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1654 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1655 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1658 items[0].a.fRTL = TRUE;
1663 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1664 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1666 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1668 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1673 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1674 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1675 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
1676 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1678 for(iCP = 0; iCP < 10; iCP++)
1680 iX = offsets_RTL[iCP]-1;
1683 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1684 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1685 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1686 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1689 for(iCP = 0; iCP < 10; iCP++)
1691 iX = offsets_RTL[iCP+1]+1;
1694 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1695 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1696 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1697 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1700 for(iCP = 0; iCP < 10; iCP++)
1702 iX = offsets_RTL[iCP];
1705 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1706 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1707 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1708 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1711 items[0].a.fRTL = FALSE;
1713 for(iCP = 0; iCP <= 11; iCP++)
1718 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1719 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1720 ok(piX == offsets[iCP],
1721 "iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
1724 for(iCP = 0; iCP <= 11; iCP++)
1729 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1730 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1731 ok(piX == offsets[iCP+1],
1732 "iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
1735 items[0].a.fRTL = TRUE;
1737 for(iCP = 0; iCP <= 11; iCP++)
1742 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piX);
1743 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1744 ok(piX == offsets_RTL[iCP],
1745 "iCP=%d should return piX=%d not %d\n", iCP, offsets_RTL[iCP], piX);
1748 for(iCP = 0; iCP <= 11; iCP++)
1753 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piX);
1754 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1755 ok(piX == offsets_RTL[iCP+1],
1756 "iCP=%d should return piX=%d not %d\n", iCP, offsets_RTL[iCP+1], piX);
1760 static void test_ScriptString(HDC hdc)
1762 /*******************************************************************************************
1764 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
1765 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
1766 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
1767 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
1772 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
1773 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
1774 int Glyphs = len * 2 + 16;
1776 DWORD Flags = SSA_GLYPHS;
1778 const int Dx[5] = {10, 10, 10, 10, 10};
1779 const BYTE InClass = 0;
1780 SCRIPT_STRING_ANALYSIS ssa = NULL;
1785 const RECT rc = {0, 50, 100, 100};
1788 BOOL Disabled = FALSE;
1789 const int *clip_len;
1794 Charset = -1; /* this flag indicates unicode input */
1795 /* Test without hdc to get E_PENDING */
1796 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
1797 ReqWidth, NULL, NULL, Dx, NULL,
1799 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
1801 /* test with hdc, this should be a valid test */
1802 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1803 ReqWidth, NULL, NULL, Dx, NULL,
1805 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1806 ScriptStringFree(&ssa);
1808 /* test makes sure that a call with a valid pssa still works */
1809 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1810 ReqWidth, NULL, NULL, Dx, NULL,
1812 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1813 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
1817 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
1818 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
1821 clip_len = ScriptString_pcOutChars(ssa);
1822 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
1824 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
1825 hr = ScriptStringGetOrder(ssa, order);
1826 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
1828 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
1829 HeapFree(GetProcessHeap(), 0, order);
1831 hr = ScriptStringFree(&ssa);
1832 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1835 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
1837 /*****************************************************************************************
1839 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
1840 * nature of the fonts between Windows and Wine, the test is implemented by generating
1841 * values using one one function then checking the output of the second. In this way
1842 * the validity of the functions is established using Windows as a base and confirming
1843 * similar behaviour in wine.
1847 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
1848 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
1849 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
1850 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
1851 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
1852 int Charset = -1; /* unicode */
1853 DWORD Flags = SSA_GLYPHS;
1855 const BYTE InClass = 0;
1856 SCRIPT_STRING_ANALYSIS ssa = NULL;
1858 int Ch; /* Character position in string */
1860 int Cp; /* Character position in string */
1865 /* Test with hdc, this should be a valid test
1866 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
1867 * following character positions to X and X to character position functions.
1870 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1871 ReqWidth, NULL, NULL, NULL, NULL,
1874 hr == E_INVALIDARG, /* NT */
1875 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
1879 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
1882 * Loop to generate character positions to provide starting positions for the
1883 * ScriptStringCPtoX and ScriptStringXtoCP functions
1885 for (Cp = 0; Cp < String_len; Cp++)
1887 /* The fTrailing flag is used to indicate whether the X being returned is at
1888 * the beginning or the end of the character. What happens here is that if
1889 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
1890 * returns the beginning of the next character and iTrailing is FALSE. So for this
1891 * loop iTrailing will be FALSE in both cases.
1893 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
1894 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1895 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
1896 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1898 ok(lead > trail, "Leading values should be after trialing for rtl chracters(%i)\n",Cp);
1900 ok(lead < trail, "Trailing values should be after leading for ltr chracters(%i)\n",Cp);
1902 /* move by 1 pixel so that we are not inbetween 2 characters. That could result in being the lead of a rtl and
1903 at the same time the trail of an ltr */
1905 /* inside the leading edge */
1907 if (rtl[Cp]) X--; else X++;
1908 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1909 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1910 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
1911 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1914 /* inside the trailing edge */
1916 if (rtl[Cp]) X++; else X--;
1917 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1918 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1919 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
1920 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
1923 /* outside the "trailing" edge */
1924 if (Cp < String_len-1)
1926 if (rtl[Cp]) X = lead; else X = trail;
1928 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1929 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1930 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
1932 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
1935 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1939 /* outside the "leading" edge */
1942 if (rtl[Cp]) X = trail; else X = lead;
1944 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1945 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1946 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
1947 if (Cp != 0 && rtl[Cp-1])
1948 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
1951 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
1956 /* Check beyond the leading boundary of the whole string */
1959 /* having a leading rtl character seems to confuse usp */
1960 /* this looks to be a windows bug we should emulate */
1961 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
1962 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1964 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1965 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1966 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
1967 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
1972 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
1973 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1975 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1976 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1977 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
1978 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
1982 /* Check beyond the end boundary of the whole string */
1983 if (rtl[String_len-1])
1985 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
1986 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1990 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
1991 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
1994 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
1995 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
1996 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
1997 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside traling edge\n",
2001 * Cleanup the SSA for the next round of tests
2003 hr = ScriptStringFree(&ssa);
2004 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2007 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
2008 * generate an SSA for the subsequent tests.
2010 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2011 ReqWidth, NULL, NULL, NULL, NULL,
2013 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2016 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2017 * string length, return E_INVALIDARG. This also invalidates the ssa so a
2018 * ScriptStringFree should also fail.
2021 Cp = String_len + 1;
2022 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2023 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2025 ScriptStringFree(&ssa);
2029 static void test_ScriptCacheGetHeight(HDC hdc)
2032 SCRIPT_CACHE sc = NULL;
2035 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2036 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2038 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2039 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2041 hr = ScriptCacheGetHeight(NULL, &sc, &height);
2042 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2046 hr = ScriptCacheGetHeight(hdc, &sc, &height);
2047 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2048 ok(height > 0, "expected height > 0\n");
2050 ScriptFreeCache(&sc);
2053 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2056 SCRIPT_CACHE sc = NULL;
2059 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2060 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2062 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2063 ok(broken(hr == E_PENDING) ||
2064 hr == E_INVALIDARG, /* WIN7 */
2065 "expected E_INVALIDARG, got 0x%08x\n", hr);
2067 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2068 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2070 if (0) { /* crashes on WinXP */
2071 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2072 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2075 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2076 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2078 ScriptFreeCache(&sc);
2081 static void test_ScriptLayout(void)
2084 static const BYTE levels[][10] =
2086 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2087 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2088 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2089 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2091 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2092 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2093 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2094 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2095 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2097 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2098 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2100 static const int expect_l2v[][10] =
2102 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2103 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2104 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2105 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2107 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2108 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2109 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2110 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2111 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2113 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2114 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2116 static const int expect_v2l[][10] =
2118 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2119 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2120 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2121 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2123 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2124 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2125 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2126 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2127 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2129 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2130 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2133 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2135 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2136 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2138 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2139 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2141 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2143 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2144 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2146 for (j = 0; j < sizeof(levels[i]); j++)
2148 ok(expect_v2l[i][j] == vistolog[j],
2149 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2150 i, j, levels[i][j], j, vistolog[j] );
2153 for (j = 0; j < sizeof(levels[i]); j++)
2155 ok(expect_l2v[i][j] == logtovis[j],
2156 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2157 i, j, levels[i][j], j, logtovis[j] );
2162 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2165 SCRIPT_DIGITSUBSTITUTE sds;
2170 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2172 memset(&sds, 0, sizeof(sds));
2173 memset(&sc, 0, sizeof(sc));
2174 memset(&ss, 0, sizeof(ss));
2176 lcid_old = GetThreadLocale();
2177 if (!SetThreadLocale(lcid)) return TRUE;
2179 hr = ScriptRecordDigitSubstitution(lcid, &sds);
2180 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2182 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2183 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2185 SetThreadLocale(lcid_old);
2189 static void test_digit_substitution(void)
2193 static const LGRPID groups[] =
2195 LGRPID_WESTERN_EUROPE,
2196 LGRPID_CENTRAL_EUROPE,
2203 LGRPID_TRADITIONAL_CHINESE,
2204 LGRPID_SIMPLIFIED_CHINESE,
2214 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2216 hKernel32 = GetModuleHandleA("kernel32.dll");
2217 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2219 if (!pEnumLanguageGroupLocalesA)
2221 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2225 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2227 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2228 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2230 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2234 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2238 static void test_ScriptGetProperties(void)
2240 const SCRIPT_PROPERTIES **props;
2244 hr = ScriptGetProperties(NULL, NULL);
2245 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2247 hr = ScriptGetProperties(NULL, &num);
2248 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2250 hr = ScriptGetProperties(&props, NULL);
2251 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2253 hr = ScriptGetProperties(&props, &num);
2254 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2257 static void test_ScriptBreak(void)
2259 static const WCHAR test[] = {' ','\r','\n',0};
2260 SCRIPT_ITEM items[4];
2264 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2265 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2267 memset(&la, 0, sizeof(la));
2268 hr = ScriptBreak(test, 1, &items[0].a, &la);
2269 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2271 ok(!la.fSoftBreak, "fSoftBreak set\n");
2272 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2273 ok(la.fCharStop, "fCharStop not set\n");
2274 ok(!la.fWordStop, "fWordStop set\n");
2275 ok(!la.fInvalid, "fInvalid set\n");
2276 ok(!la.fReserved, "fReserved set\n");
2278 memset(&la, 0, sizeof(la));
2279 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2280 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2282 ok(!la.fSoftBreak, "fSoftBreak set\n");
2283 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2284 ok(la.fCharStop, "fCharStop not set\n");
2285 ok(!la.fWordStop, "fWordStop set\n");
2286 ok(!la.fInvalid, "fInvalid set\n");
2287 ok(!la.fReserved, "fReserved set\n");
2289 memset(&la, 0, sizeof(la));
2290 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2291 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2293 ok(!la.fSoftBreak, "fSoftBreak set\n");
2294 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2295 ok(la.fCharStop, "fCharStop not set\n");
2296 ok(!la.fWordStop, "fWordStop set\n");
2297 ok(!la.fInvalid, "fInvalid set\n");
2298 ok(!la.fReserved, "fReserved set\n");
2301 static void test_newlines(void)
2303 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2304 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2305 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2306 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2307 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2308 SCRIPT_ITEM items[5];
2313 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2314 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2315 ok(count == 3, "got %d expected 3\n", count);
2318 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2319 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2320 ok(count == 3, "got %d expected 3\n", count);
2323 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2324 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2325 ok(count == 4, "got %d expected 4\n", count);
2328 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2329 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2330 ok(count == 4, "got %d expected 4\n", count);
2333 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2334 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2335 ok(count == 4, "got %d expected 4\n", count);
2345 unsigned short pwOutGlyphs[256];
2347 /* We need a valid HDC to drive a lot of Script functions which requires the following *
2348 * to set up for the tests. */
2349 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2352 ShowWindow(hwnd, SW_SHOW);
2355 hdc = GetDC(hwnd); /* We now have a hdc */
2356 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2358 memset(&lf, 0, sizeof(LOGFONTA));
2359 lstrcpyA(lf.lfFaceName, "Tahoma");
2364 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2365 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2367 test_ScriptItemize();
2368 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2369 test_ScriptGetCMap(hdc, pwOutGlyphs);
2370 test_ScriptCacheGetHeight(hdc);
2371 test_ScriptGetGlyphABCWidth(hdc);
2372 test_ScriptShape(hdc);
2373 test_ScriptShapeOpenType(hdc);
2374 test_ScriptPlace(hdc);
2376 test_ScriptGetFontProperties(hdc);
2377 test_ScriptTextOut(hdc);
2378 test_ScriptTextOut2(hdc);
2379 test_ScriptTextOut3(hdc);
2381 test_ScriptString(hdc);
2382 test_ScriptStringXtoCP_CPtoX(hdc);
2384 test_ScriptLayout();
2385 test_digit_substitution();
2386 test_ScriptGetProperties();
2390 ReleaseDC(hwnd, hdc);
2391 DestroyWindow(hwnd);