usp10/tests: Add Bengali shaping test.
[wine.git] / dlls / usp10 / tests / usp10.c
blobe0e6e3e8352379dfe2ee5560ec9e3338230311c5
1 /*
2 * Tests for usp10 dll
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
22 * Notes:
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
27 #include <assert.h>
28 #include <stdio.h>
30 #include <wine/test.h>
31 #include <windows.h>
32 #include <usp10.h>
34 typedef struct _itemTest {
35 char todo_flag[5];
36 int iCharPos;
37 int fRTL;
38 int fLayoutRTL;
39 int uBidiLevel;
40 ULONG scriptTag;
41 } itemTest;
43 typedef struct _shapeTest_char {
44 WORD wLogClust;
45 SCRIPT_CHARPROP CharProp;
46 } shapeTest_char;
48 typedef struct _shapeTest_glyph {
49 int Glyph;
50 SCRIPT_GLYPHPROP GlyphProp;
51 } shapeTest_glyph;
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,
63 INT nItemsBroken)
65 HRESULT hr;
66 int x, outnItems;
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);
72 else
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");
79 return;
81 if (nItemsToDo)
82 todo_wine winetest_ok(outnItems == nItems, "Wrong number of items\n");
83 else
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);
89 else
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);
94 else
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);
98 else
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);
102 else
103 winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
104 if (x != outnItems)
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);
110 else
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 ) | \
122 (ULONG)_x1 )
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')
131 #define guru_tag MS_MAKE_TAG('g','u','r','u')
132 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
133 #define orya_tag MS_MAKE_TAG('o','r','y','a')
134 #define taml_tag MS_MAKE_TAG('t','a','m','l')
135 #define telu_tag MS_MAKE_TAG('t','e','l','u')
136 #define knda_tag MS_MAKE_TAG('k','n','d','a')
137 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
139 static void test_ScriptItemize( void )
141 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
142 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}};
143 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}};
145 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
146 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}};
147 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}};
149 /* Arabic, English*/
150 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
151 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}};
152 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}};
153 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}};
155 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
156 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}};
157 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}};
158 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}};
160 /* leading space */
161 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
162 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}};
163 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}};
164 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}};
165 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}};
167 /* trailing space */
168 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
169 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}};
170 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}};
171 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}};
172 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}};
174 /* Thai */
175 static const WCHAR test3[] =
176 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
177 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
178 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
179 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
181 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}};
182 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}};
184 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
186 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}};
187 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}};
188 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}};
190 /* Arabic */
191 static const WCHAR test5[] =
192 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
193 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
194 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
195 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
196 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}};
198 /* Hebrew */
199 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
200 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}};
201 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}};
202 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}};
203 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};
204 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}};
205 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}};
206 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}};
207 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
208 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}};
210 /* Syriac (Like Arabic )*/
211 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
212 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}};
213 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}};
214 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}};
216 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
217 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}};
219 /* Devanagari */
220 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
221 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}};
222 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}};
224 /* Bengali */
225 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
226 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}};
227 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}};
229 /* Gurmukhi */
230 static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
231 static const itemTest t131[2] = {{{0,0,0,0,0},0,0,0,0,guru_tag},{{0,0,0,0,0},7,0,0,0,-1}};
232 static const itemTest t132[2] = {{{0,0,0,0,0},0,0,0,2,guru_tag},{{0,0,0,0,0},7,0,0,0,-1}};
234 /* Gujarati */
235 static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
236 static const itemTest t141[2] = {{{0,0,0,0,0},0,0,0,0,gujr_tag},{{0,0,0,0,0},7,0,0,0,-1}};
237 static const itemTest t142[2] = {{{0,0,0,0,0},0,0,0,2,gujr_tag},{{0,0,0,0,0},7,0,0,0,-1}};
239 /* Oriya */
240 static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
241 static const itemTest t151[2] = {{{0,0,0,0,0},0,0,0,0,orya_tag},{{0,0,0,0,0},5,0,0,0,-1}};
242 static const itemTest t152[2] = {{{0,0,0,0,0},0,0,0,2,orya_tag},{{0,0,0,0,0},5,0,0,0,-1}};
244 /* Tamil */
245 static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
246 static const itemTest t161[2] = {{{0,0,0,0,0},0,0,0,0,taml_tag},{{0,0,0,0,0},5,0,0,0,-1}};
247 static const itemTest t162[2] = {{{0,0,0,0,0},0,0,0,2,taml_tag},{{0,0,0,0,0},5,0,0,0,-1}};
249 /* Telugu */
250 static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
251 static const itemTest t171[2] = {{{0,0,0,0,0},0,0,0,0,telu_tag},{{0,0,0,0,0},6,0,0,0,-1}};
252 static const itemTest t172[2] = {{{0,0,0,0,0},0,0,0,2,telu_tag},{{0,0,0,0,0},6,0,0,0,-1}};
254 /* Kannada */
255 static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
256 static const itemTest t181[2] = {{{0,0,0,0,0},0,0,0,0,knda_tag},{{0,0,0,0,0},5,0,0,0,-1}};
257 static const itemTest t182[2] = {{{0,0,0,0,0},0,0,0,2,knda_tag},{{0,0,0,0,0},5,0,0,0,-1}};
259 /* Malayalam */
260 static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
261 static const itemTest t191[2] = {{{0,0,0,0,0},0,0,0,0,mlym_tag},{{0,0,0,0,0},6,0,0,0,-1}};
262 static const itemTest t192[2] = {{{0,0,0,0,0},0,0,0,2,mlym_tag},{{0,0,0,0,0},6,0,0,0,-1}};
264 SCRIPT_ITEM items[15];
265 SCRIPT_CONTROL Control;
266 SCRIPT_STATE State;
267 HRESULT hr;
268 HMODULE usp10;
269 int nItems;
271 usp10 = LoadLibraryA("usp10.dll");
272 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
273 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
274 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
275 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
277 memset(&Control, 0, sizeof(Control));
278 memset(&State, 0, sizeof(State));
280 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
281 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
283 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
284 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
286 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
287 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
289 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
290 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
292 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
293 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
294 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
295 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
296 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
297 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
298 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
299 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
300 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
301 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
302 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
303 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
304 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
305 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
306 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
307 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
308 test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
309 test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
310 test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
311 test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
312 test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
313 test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
314 test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
316 State.uBidiLevel = 0;
317 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
318 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
319 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
320 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
321 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
322 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
323 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
324 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
325 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
326 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
327 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
328 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
329 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
330 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
331 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
332 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
333 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
334 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
335 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
336 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
337 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
338 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
339 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
341 State.uBidiLevel = 1;
342 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
343 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
344 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
345 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
346 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
347 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
348 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
349 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
350 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
351 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
352 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
353 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
354 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
355 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
356 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
357 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
358 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
359 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
360 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
361 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
362 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
363 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
364 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
366 State.uBidiLevel = 1;
367 Control.fMergeNeutralItems = TRUE;
368 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
369 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
370 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
371 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,4);
372 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,4);
373 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,4);
374 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
375 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,4);
376 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
377 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,2);
378 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
379 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
380 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,2);
381 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
382 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
383 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
384 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
385 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
386 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
387 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
388 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
389 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
390 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
393 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
394 DWORD cchString, SCRIPT_CONTROL *Control,
395 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
396 const shapeTest_char* charItems,
397 const shapeTest_glyph* glyphItems)
399 HRESULT hr;
400 int x, outnItems=0, outnGlyphs=0;
401 SCRIPT_ITEM outpItems[15];
402 SCRIPT_CACHE sc = NULL;
403 WORD *glyphs;
404 WORD *logclust;
405 int maxGlyphs = cchString * 1.5;
406 SCRIPT_GLYPHPROP *glyphProp;
407 SCRIPT_CHARPROP *charProp;
408 ULONG tags[15];
410 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
411 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
413 if (valid > 0)
414 winetest_win_skip("Select font does not support script\n");
415 else
416 winetest_trace("Select font does not support script\n");
417 return;
419 if (valid > 0)
420 winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
421 else if (hr)
422 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
425 if (outnItems <= item)
427 if (valid > 0)
428 winetest_win_skip("Did not get enough items\n");
429 else
430 winetest_trace("Did not get enough items\n");
431 return;
434 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
435 memset(logclust,'a',sizeof(WORD) * cchString);
436 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
437 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
438 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
439 memset(glyphs,'a',sizeof(WORD) * cchString);
440 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
441 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
443 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
444 if (valid > 0)
445 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
446 else if (hr != S_OK)
447 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
448 if (FAILED(hr))
449 return;
451 for (x = 0; x < cchString; x++)
453 if (valid > 0)
454 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
455 else if (logclust[x] != charItems[x].wLogClust)
456 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
457 if (valid > 0)
458 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
459 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
460 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
463 if (valid > 0)
464 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
465 else if (nGlyphs != outnGlyphs)
466 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
467 for (x = 0; x < outnGlyphs; x++)
469 if (glyphItems[x].Glyph)
471 if (valid > 0)
472 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
473 else if (glyphs[x]==0)
474 winetest_trace("%i: Glyph not present when it should be\n",x);
476 else
478 if (valid > 0)
479 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
480 else if (glyphs[x]!=0)
481 winetest_trace("%i: Glyph present when it should not be\n",x);
483 if (valid > 0)
484 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
485 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
486 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
487 if (valid > 0)
488 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
489 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
490 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
491 if (valid > 0)
492 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
493 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
494 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
495 if (valid > 0)
496 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
497 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
498 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
501 HeapFree(GetProcessHeap(),0,logclust);
502 HeapFree(GetProcessHeap(),0,charProp);
503 HeapFree(GetProcessHeap(),0,glyphs);
504 HeapFree(GetProcessHeap(),0,glyphProp);
505 ScriptFreeCache(&sc);
508 #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)
510 #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)
512 typedef struct tagRangeP {
513 BYTE range;
514 LOGFONTA lf;
515 } fontEnumParam;
517 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
518 DWORD FontType, LPARAM lParam)
520 NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
521 fontEnumParam *rp = (fontEnumParam*) lParam;
522 int idx = 0;
523 DWORD i;
524 DWORD mask = 0;
526 if (FontType != TRUETYPE_FONTTYPE)
527 return 1;
529 i = rp->range;
530 while (i > sizeof(DWORD)*8)
532 idx++;
533 i -= (sizeof(DWORD)*8);
535 if (idx > 3)
536 return 0;
538 mask = 1 << i;
540 if (ntme->ntmFontSig.fsUsb[idx] & mask)
542 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
543 return 0;
545 return 1;
548 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
550 int rc = 0;
551 fontEnumParam lParam;
553 lParam.range = range;
554 memset(&lParam.lf,0,sizeof(LOGFONT));
555 *hfont = NULL;
557 if (recommended)
559 lstrcpyA(lParam.lf.lfFaceName, recommended);
560 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
562 *hfont = CreateFontIndirectA(&lParam.lf);
563 if (*hfont)
565 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
566 rc = 1;
571 if (!*hfont)
573 memset(&lParam.lf,0,sizeof(LOGFONT));
574 lParam.lf.lfCharSet = DEFAULT_CHARSET;
576 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
578 *hfont = CreateFontIndirectA(&lParam.lf);
579 if (*hfont)
580 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
584 if (*hfont)
586 WORD glyph = 0;
588 *origFont = SelectObject(hdc,*hfont);
589 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
591 winetest_trace(" Font fails to contain required glyphs\n");
592 SelectObject(hdc,*origFont);
593 DeleteObject(*hfont);
594 *hfont=NULL;
595 rc = 0;
597 else if (!rc)
598 rc = -1;
600 else
601 winetest_trace("Failed to find usable font\n");
603 return rc;
606 #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)
608 static void test_ScriptShapeOpenType(HDC hdc)
610 HRESULT hr;
611 SCRIPT_CACHE sc = NULL;
612 WORD glyphs[4], logclust[4];
613 SCRIPT_GLYPHPROP glyphProp[4];
614 SCRIPT_ITEM items[2];
615 ULONG tags[2];
616 SCRIPT_CONTROL Control;
617 SCRIPT_STATE State;
618 int nb, outnItems;
619 HFONT hfont, hfont_orig;
620 int test_valid;
622 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
623 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
624 static const shapeTest_glyph t1_g[] = {
625 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
626 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
627 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
628 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
630 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
631 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
632 static const shapeTest_glyph t2_g[] = {
633 {0,{{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 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
638 /* Hebrew */
639 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
640 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
641 static const shapeTest_glyph hebrew_g[] = {
642 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
643 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
644 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
645 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
647 /* Arabic */
648 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
649 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
650 static const shapeTest_glyph arabic_g[] = {
651 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
652 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
653 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
655 /* Thai */
656 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
657 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}}};
658 static const shapeTest_glyph thai_g[] = {
659 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
660 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
661 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
662 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
663 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
664 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
665 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
666 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
667 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
668 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
670 /* Syriac */
671 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
672 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
673 static const shapeTest_glyph syriac_g[] = {
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,1,0,0,0,0},0}},
679 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
681 /* Thaana */
682 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
683 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}}};
684 static const shapeTest_glyph thaana_g[] = {
685 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
686 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
687 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
688 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
689 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
690 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
691 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
692 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
693 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
694 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
695 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
696 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
697 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
699 /* Phags-pa */
700 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
701 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}}};
702 static const shapeTest_glyph phagspa_g[] = {
703 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
704 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
705 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
706 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
707 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
708 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
709 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
710 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
711 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
712 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
713 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
715 /* Lao */
716 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
717 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}}};
718 static const shapeTest_glyph lao_g[] = {
719 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
720 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
721 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
722 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
723 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
724 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
725 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
726 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
727 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
729 /* Tibetan */
730 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
731 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}}};
732 static const shapeTest_glyph tibetan_g[] = {
733 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
734 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
735 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
736 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
737 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
738 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
739 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
740 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
741 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
742 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
743 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
744 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
745 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
746 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
747 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
748 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
749 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
751 /* Devanagari */
752 static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
753 static const shapeTest_char devanagari_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{6,{0,0}},{6,{0,0}}};
754 static const shapeTest_glyph devanagari_g[] = {
755 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
756 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
757 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
758 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
759 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
760 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
761 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
762 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
764 /* Bengali */
765 static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
766 static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
767 static const shapeTest_glyph bengali_g[] = {
768 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
769 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
770 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
771 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
772 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
774 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
776 win_skip("ScriptShapeOpenType not available on this platform\n");
777 return;
780 memset(&Control, 0 , sizeof(Control));
781 memset(&State, 0 , sizeof(State));
783 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
784 ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
785 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
787 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
788 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
790 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
791 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
793 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
794 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
796 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
797 ok( hr == E_INVALIDARG,
798 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
799 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
800 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
802 ScriptFreeCache(&sc);
804 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
805 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
807 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
808 if (hfont != NULL)
810 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
811 SelectObject(hdc, hfont_orig);
812 DeleteObject(hfont);
815 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
816 if (hfont != NULL)
818 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
819 SelectObject(hdc, hfont_orig);
820 DeleteObject(hfont);
823 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
824 if (hfont != NULL)
826 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
827 SelectObject(hdc, hfont_orig);
828 DeleteObject(hfont);
831 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
832 if (hfont != NULL)
834 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
835 SelectObject(hdc, hfont_orig);
836 DeleteObject(hfont);
839 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
840 if (hfont != NULL)
842 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
843 SelectObject(hdc, hfont_orig);
844 DeleteObject(hfont);
847 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
848 if (hfont != NULL)
850 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
851 SelectObject(hdc, hfont_orig);
852 DeleteObject(hfont);
855 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
856 if (hfont != NULL)
858 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
859 SelectObject(hdc, hfont_orig);
860 DeleteObject(hfont);
863 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
864 if (hfont != NULL)
866 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
867 SelectObject(hdc, hfont_orig);
868 DeleteObject(hfont);
871 test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
872 if (hfont != NULL)
874 test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
875 SelectObject(hdc, hfont_orig);
876 DeleteObject(hfont);
879 test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
880 if (hfont != NULL)
882 test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
883 SelectObject(hdc, hfont_orig);
884 DeleteObject(hfont);
888 static void test_ScriptShape(HDC hdc)
890 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
891 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
892 HRESULT hr;
893 SCRIPT_CACHE sc = NULL;
894 WORD glyphs[4], glyphs2[4], logclust[4];
895 SCRIPT_VISATTR attrs[4];
896 SCRIPT_ITEM items[2];
897 int nb;
899 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
900 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
901 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
903 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
904 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
906 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
907 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
909 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
910 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
912 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
913 ok(broken(hr == S_OK) ||
914 hr == E_INVALIDARG || /* Vista, W2K8 */
915 hr == E_FAIL, /* WIN7 */
916 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
917 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
919 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
920 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
921 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
924 memset(glyphs,-1,sizeof(glyphs));
925 memset(logclust,-1,sizeof(logclust));
926 memset(attrs,-1,sizeof(attrs));
927 hr = ScriptShape(NULL, &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(nb == 4, "Wrong number of items\n");
930 ok(logclust[0] == 0, "clusters out of order\n");
931 ok(logclust[1] == 1, "clusters out of order\n");
932 ok(logclust[2] == 2, "clusters out of order\n");
933 ok(logclust[3] == 3, "clusters out of order\n");
934 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
935 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
936 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
937 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
938 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
939 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
940 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
941 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
942 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
943 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
944 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
945 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
946 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
947 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
948 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
949 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
951 ScriptFreeCache(&sc);
952 sc = NULL;
954 memset(glyphs2,-1,sizeof(glyphs2));
955 memset(logclust,-1,sizeof(logclust));
956 memset(attrs,-1,sizeof(attrs));
957 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
958 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
959 ok(nb == 4, "Wrong number of items\n");
960 ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
961 ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
962 ok(logclust[0] == 0, "clusters out of order\n");
963 ok(logclust[1] == 1, "clusters out of order\n");
964 ok(logclust[2] == 2, "clusters out of order\n");
965 ok(logclust[3] == 3, "clusters out of order\n");
966 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
967 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
968 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
969 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
970 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
971 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
972 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
973 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
974 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
975 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
976 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
977 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
978 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
979 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
980 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
981 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
983 /* modify LTR to RTL */
984 items[0].a.fRTL = 1;
985 memset(glyphs2,-1,sizeof(glyphs2));
986 memset(logclust,-1,sizeof(logclust));
987 memset(attrs,-1,sizeof(attrs));
988 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
989 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
990 ok(nb == 4, "Wrong number of items\n");
991 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
992 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
993 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
994 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
995 ok(logclust[0] == 3, "clusters out of order\n");
996 ok(logclust[1] == 2, "clusters out of order\n");
997 ok(logclust[2] == 1, "clusters out of order\n");
998 ok(logclust[3] == 0, "clusters out of order\n");
999 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1000 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1001 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1002 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1003 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1004 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1005 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1006 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1007 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1008 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1009 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1010 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1011 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1012 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1013 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1014 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1016 ScriptFreeCache(&sc);
1019 static void test_ScriptPlace(HDC hdc)
1021 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1022 BOOL ret;
1023 HRESULT hr;
1024 SCRIPT_CACHE sc = NULL;
1025 WORD glyphs[4], logclust[4];
1026 SCRIPT_VISATTR attrs[4];
1027 SCRIPT_ITEM items[2];
1028 int nb, widths[4];
1029 GOFFSET offset[4];
1030 ABC abc[4];
1032 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1033 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1034 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1036 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1037 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1038 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1040 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1041 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1043 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1044 ok(broken(hr == E_PENDING) ||
1045 hr == E_INVALIDARG || /* Vista, W2K8 */
1046 hr == E_FAIL, /* WIN7 */
1047 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1049 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1050 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1052 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1053 ok(broken(hr == E_PENDING) ||
1054 hr == E_INVALIDARG || /* Vista, W2K8 */
1055 hr == E_FAIL, /* WIN7 */
1056 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1058 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1059 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
1060 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1062 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1063 ok(ret, "ExtTextOutW should return TRUE\n");
1065 ScriptFreeCache(&sc);
1068 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1070 HRESULT hr;
1071 int iMaxProps;
1072 const SCRIPT_PROPERTIES **ppSp;
1074 int cInChars;
1075 int cMaxItems;
1076 SCRIPT_ITEM pItem[255];
1077 int pcItems;
1078 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1079 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
1080 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1081 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1082 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1083 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1085 SCRIPT_CACHE psc;
1086 int cChars;
1087 int cMaxGlyphs;
1088 unsigned short pwOutGlyphs1[256];
1089 unsigned short pwOutGlyphs2[256];
1090 unsigned short pwLogClust[256];
1091 SCRIPT_VISATTR psva[256];
1092 int pcGlyphs;
1093 int piAdvance[256];
1094 GOFFSET pGoffset[256];
1095 ABC pABC[256];
1096 int cnt;
1098 /* Start testing usp10 functions */
1099 /* This test determines that the pointer returned by ScriptGetProperties is valid
1100 * by checking a known value in the table */
1101 hr = ScriptGetProperties(&ppSp, &iMaxProps);
1102 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1103 trace("number of script properties %d\n", iMaxProps);
1104 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1105 if (iMaxProps > 0)
1106 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1107 /* ptrs work */
1109 /* This is a valid test that will cause parsing to take place */
1110 cInChars = 5;
1111 cMaxItems = 255;
1112 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1113 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1114 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1115 * returned. */
1116 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1117 if (pcItems > 0)
1118 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1119 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1120 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1122 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1123 * ie. ScriptItemize has succeeded and that pItem has been set */
1124 cInChars = 5;
1125 if (hr == 0) {
1126 psc = NULL; /* must be null on first call */
1127 cChars = cInChars;
1128 cMaxGlyphs = cInChars;
1129 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1130 cMaxGlyphs, &pItem[0].a,
1131 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1132 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1133 cMaxGlyphs = 4;
1134 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1135 cMaxGlyphs, &pItem[0].a,
1136 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1137 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1138 "(%d) but not E_OUTOFMEMORY\n",
1139 cChars, cMaxGlyphs);
1140 cMaxGlyphs = 256;
1141 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1142 cMaxGlyphs, &pItem[0].a,
1143 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1144 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1145 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1146 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1147 if (hr ==0) {
1148 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1149 pGoffset, pABC);
1150 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1151 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1152 pGoffset, pABC);
1153 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1154 for (cnt=0; cnt < pcGlyphs; cnt++)
1155 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1158 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1159 * takes place if fNoGlyphIndex is set. */
1161 cInChars = 5;
1162 cMaxItems = 255;
1163 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1164 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1165 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1166 * returned. */
1167 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1168 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1169 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1170 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1171 if (hr == 0) {
1172 cChars = cInChars;
1173 cMaxGlyphs = 256;
1174 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1175 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1176 cMaxGlyphs, &pItem[0].a,
1177 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1178 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1179 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1180 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1181 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1182 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1183 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1184 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1185 if (hr ==0) {
1186 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1187 pGoffset, pABC);
1188 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1191 ScriptFreeCache( &psc);
1192 ok (!psc, "psc is not null after ScriptFreeCache\n");
1196 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1197 cInChars = (sizeof(TestItem3)/2)-1;
1198 cMaxItems = 255;
1199 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1200 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1201 if (hr == 0)
1203 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1204 if (pcItems > 2)
1206 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1207 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1208 pItem[0].iCharPos, pItem[1].iCharPos);
1209 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1210 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1211 pItem[1].iCharPos, pItem[2].iCharPos);
1212 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1213 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1214 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1218 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1219 cInChars = (sizeof(TestItem4)/2)-1;
1220 cMaxItems = 255;
1221 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1222 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1223 if (hr == 0)
1225 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1226 if (pcItems > 4)
1228 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1229 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1230 pItem[0].iCharPos, pItem[1].iCharPos);
1231 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1232 pItem[0].a.s.uBidiLevel);
1233 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1234 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1235 pItem[1].iCharPos, pItem[2].iCharPos);
1236 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1237 pItem[1].a.s.uBidiLevel);
1238 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1239 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1240 pItem[2].iCharPos, pItem[3].iCharPos);
1241 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1242 pItem[2].a.s.uBidiLevel);
1243 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1244 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1245 pItem[3].iCharPos, pItem[4].iCharPos);
1246 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1247 pItem[3].a.s.uBidiLevel);
1248 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1249 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1250 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1255 * This test is for when the first unicode character requires bidi support
1257 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1258 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1259 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1260 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1261 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1262 pItem[0].a.s.uBidiLevel);
1264 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
1265 * the pointer to the last char works. Note that windows often needs a greater number of *
1266 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
1267 cInChars = (sizeof(TestItem6)/2)-1;
1268 cMaxItems = 4;
1269 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1270 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1274 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1276 HRESULT hr;
1277 SCRIPT_CACHE psc = NULL;
1278 int cInChars;
1279 int cChars;
1280 unsigned short pwOutGlyphs2[256];
1281 unsigned short pwOutGlyphs3[256];
1282 DWORD dwFlags;
1283 int cnt;
1285 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1286 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1287 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1288 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1290 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
1291 dwFlags = 0;
1292 cInChars = cChars = 5;
1293 /* Some sanity checks for ScriptGetCMap */
1295 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1296 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1297 "expected E_INVALIDARG, got %08x\n", hr);
1299 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1300 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1301 "expected E_INVALIDARG, got %08x\n", hr);
1303 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1304 psc = NULL;
1305 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1306 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1307 "got %08x\n", hr);
1308 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1310 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1311 psc = NULL;
1312 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1313 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1314 "got %08x\n", hr);
1315 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1316 ScriptFreeCache( &psc);
1318 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1319 psc = NULL;
1320 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1321 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1322 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1323 /* Check to see if the results are the same as those returned by ScriptShape */
1324 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1325 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1326 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1327 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1328 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1329 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1331 ScriptFreeCache( &psc);
1332 ok (!psc, "psc is not null after ScriptFreeCache\n");
1334 cInChars = cChars = 4;
1335 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1336 ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1337 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1338 ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1339 ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1342 cInChars = cChars = 9;
1343 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1344 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1345 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1347 cInChars = cChars = 9;
1348 dwFlags = SGCM_RTL;
1349 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1350 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1351 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1352 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1353 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1354 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1355 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1356 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1357 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1358 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1359 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1360 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1362 ScriptFreeCache( &psc);
1363 ok (!psc, "psc is not null after ScriptFreeCache\n");
1366 static void test_ScriptGetFontProperties(HDC hdc)
1368 HRESULT hr;
1369 SCRIPT_CACHE psc,old_psc;
1370 SCRIPT_FONTPROPERTIES sfp;
1372 /* Some sanity checks for ScriptGetFontProperties */
1374 hr = ScriptGetFontProperties(NULL,NULL,NULL);
1375 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1377 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1378 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1380 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1381 psc = NULL;
1382 hr = ScriptGetFontProperties(NULL,&psc,NULL);
1383 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1384 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1386 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1387 psc = NULL;
1388 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1389 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1390 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1392 hr = ScriptGetFontProperties(hdc,NULL,NULL);
1393 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1395 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1396 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1398 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1399 psc = NULL;
1400 hr = ScriptGetFontProperties(hdc,&psc,NULL);
1401 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1402 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1404 /* Pass an invalid sfp */
1405 psc = NULL;
1406 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1407 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1408 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1409 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1410 ScriptFreeCache(&psc);
1411 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1413 /* Give it the correct cBytes, we don't care about what's coming back */
1414 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1415 psc = NULL;
1416 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1417 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1418 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1420 /* Save the psc pointer */
1421 old_psc = psc;
1422 /* Now a NULL hdc again */
1423 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1424 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1425 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1426 ScriptFreeCache(&psc);
1427 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1430 static void test_ScriptTextOut(HDC hdc)
1432 HRESULT hr;
1434 int cInChars;
1435 int cMaxItems;
1436 SCRIPT_ITEM pItem[255];
1437 int pcItems;
1438 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1440 SCRIPT_CACHE psc;
1441 int cChars;
1442 int cMaxGlyphs;
1443 unsigned short pwOutGlyphs1[256];
1444 WORD pwLogClust[256];
1445 SCRIPT_VISATTR psva[256];
1446 int pcGlyphs;
1447 int piAdvance[256];
1448 GOFFSET pGoffset[256];
1449 ABC pABC[256];
1450 RECT rect;
1451 int piX;
1452 int iCP = 1;
1453 BOOL fTrailing = FALSE;
1454 SCRIPT_LOGATTR *psla;
1455 SCRIPT_LOGATTR sla[256];
1457 /* This is a valid test that will cause parsing to take place */
1458 cInChars = 5;
1459 cMaxItems = 255;
1460 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1461 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1462 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1463 * returned. */
1464 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1465 if (pcItems > 0)
1466 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1467 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1468 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1470 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1471 * ie. ScriptItemize has succeeded and that pItem has been set */
1472 cInChars = 5;
1473 if (hr == 0) {
1474 psc = NULL; /* must be null on first call */
1475 cChars = cInChars;
1476 cMaxGlyphs = 256;
1477 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1478 cMaxGlyphs, &pItem[0].a,
1479 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1480 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1481 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1482 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1483 if (hr ==0) {
1484 /* Note hdc is needed as glyph info is not yet in psc */
1485 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1486 pGoffset, pABC);
1487 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1488 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
1489 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1491 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1492 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1494 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1495 piAdvance, NULL, pGoffset);
1496 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1497 "expected E_INVALIDARG, got %08x\n", hr);
1499 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1500 psc = NULL;
1501 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1502 NULL, NULL, NULL);
1503 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1504 "got %08x\n", hr);
1505 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1507 /* hdc is required for this one rather than the usual optional */
1508 psc = NULL;
1509 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1510 piAdvance, NULL, pGoffset);
1511 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1512 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1514 /* Set that it returns 0 status */
1515 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1516 piAdvance, NULL, pGoffset);
1517 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1519 /* Test Rect Rgn is acceptable */
1520 rect.top = 10;
1521 rect.bottom = 20;
1522 rect.left = 10;
1523 rect.right = 40;
1524 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1525 piAdvance, NULL, pGoffset);
1526 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1528 iCP = 1;
1529 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1530 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1531 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1533 psla = (SCRIPT_LOGATTR *)&sla;
1534 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1535 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1537 /* Clean up and go */
1538 ScriptFreeCache(&psc);
1539 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1544 static void test_ScriptTextOut2(HDC hdc)
1546 /* Intent is to validate that the HDC passed into ScriptTextOut is
1547 * used instead of the (possibly) invalid cached one
1549 HRESULT hr;
1551 HDC hdc1, hdc2;
1552 int cInChars;
1553 int cMaxItems;
1554 SCRIPT_ITEM pItem[255];
1555 int pcItems;
1556 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1558 SCRIPT_CACHE psc;
1559 int cChars;
1560 int cMaxGlyphs;
1561 unsigned short pwOutGlyphs1[256];
1562 WORD pwLogClust[256];
1563 SCRIPT_VISATTR psva[256];
1564 int pcGlyphs;
1565 int piAdvance[256];
1566 GOFFSET pGoffset[256];
1567 ABC pABC[256];
1569 /* Create an extra DC that will be used until the ScriptTextOut */
1570 hdc1 = CreateCompatibleDC(hdc);
1571 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1572 hdc2 = CreateCompatibleDC(hdc);
1573 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1575 /* This is a valid test that will cause parsing to take place */
1576 cInChars = 5;
1577 cMaxItems = 255;
1578 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1579 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1580 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1581 * returned. */
1582 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1583 if (pcItems > 0)
1584 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1585 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1586 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1588 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1589 * ie. ScriptItemize has succeeded and that pItem has been set */
1590 cInChars = 5;
1591 if (hr == 0) {
1592 psc = NULL; /* must be null on first call */
1593 cChars = cInChars;
1594 cMaxGlyphs = 256;
1595 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1596 cMaxGlyphs, &pItem[0].a,
1597 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1598 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1599 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1600 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1601 if (hr ==0) {
1602 /* Note hdc is needed as glyph info is not yet in psc */
1603 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1604 pGoffset, pABC);
1605 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1607 /* key part!!! cached dc is being deleted */
1608 hr = DeleteDC(hdc2);
1609 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1611 /* At this point the cached hdc (hdc2) has been destroyed,
1612 * however, we are passing in a *real* hdc (the original hdc).
1613 * The text should be written to that DC
1615 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1616 piAdvance, NULL, pGoffset);
1617 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1618 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1620 DeleteDC(hdc1);
1622 /* Clean up and go */
1623 ScriptFreeCache(&psc);
1624 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1629 static void test_ScriptTextOut3(HDC hdc)
1631 HRESULT hr;
1633 int cInChars;
1634 int cMaxItems;
1635 SCRIPT_ITEM pItem[255];
1636 int pcItems;
1637 WCHAR TestItem1[] = {' ','\r', 0};
1639 SCRIPT_CACHE psc;
1640 int cChars;
1641 int cMaxGlyphs;
1642 unsigned short pwOutGlyphs1[256];
1643 WORD pwLogClust[256];
1644 SCRIPT_VISATTR psva[256];
1645 int pcGlyphs;
1646 int piAdvance[256];
1647 GOFFSET pGoffset[256];
1648 ABC pABC[256];
1649 RECT rect;
1651 /* This is to ensure that non exisiting glyphs are translated into a valid glyph number */
1652 cInChars = 2;
1653 cMaxItems = 255;
1654 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1655 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1656 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1657 * returned. */
1658 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1659 if (pcItems > 0)
1660 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
1661 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1662 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
1664 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1665 * ie. ScriptItemize has succeeded and that pItem has been set */
1666 cInChars = 2;
1667 if (hr == 0) {
1668 psc = NULL; /* must be null on first call */
1669 cChars = cInChars;
1670 cMaxGlyphs = 256;
1671 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1672 cMaxGlyphs, &pItem[0].a,
1673 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1674 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1675 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1676 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1677 if (hr ==0) {
1678 /* Note hdc is needed as glyph info is not yet in psc */
1679 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1680 pGoffset, pABC);
1681 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1683 /* Test Rect Rgn is acceptable */
1684 rect.top = 10;
1685 rect.bottom = 20;
1686 rect.left = 10;
1687 rect.right = 40;
1688 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1689 piAdvance, NULL, pGoffset);
1690 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1693 /* Clean up and go */
1694 ScriptFreeCache(&psc);
1695 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1699 static void test_ScriptXtoX(void)
1700 /****************************************************************************************
1701 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
1702 ****************************************************************************************/
1704 static const WCHAR test[] = {'t', 'e', 's', 't',0};
1705 SCRIPT_ITEM items[2];
1706 int iX, iCP;
1707 int cChars;
1708 int cGlyphs;
1709 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
1710 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
1711 SCRIPT_VISATTR psva[10];
1712 int piAdvance[10] = {200, 190, 210, 180, 170, 204, 189, 195, 212, 203};
1713 int piCP, piX;
1714 int piTrailing;
1715 BOOL fTrailing;
1716 HRESULT hr;
1717 static const int offsets[13] = {0, 66, 133, 200, 295, 390, 495, 600, 1051, 1502, 1953, 1953, 1953};
1718 static const int offsets_RTL[13] = {780, 720, 660, 600, 495, 390, 295, 200, 133, 66, 0, 0, 0};
1720 hr = ScriptItemize(test, lstrlenW(test), sizeof(items)/sizeof(items[0]), NULL, NULL, items, NULL);
1721 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1723 iX = -1;
1724 cChars = 10;
1725 cGlyphs = 10;
1726 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1727 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1728 if (piTrailing)
1729 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1730 else /* win2k3 */
1731 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1733 for(iCP = 0; iCP < 10; iCP++)
1735 iX = offsets[iCP]+1;
1736 cChars = 10;
1737 cGlyphs = 10;
1738 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1739 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1740 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1741 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1744 for(iCP = 0; iCP < 10; iCP++)
1746 iX = offsets[iCP+1]-1;
1747 cChars = 10;
1748 cGlyphs = 10;
1749 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1750 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1751 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1752 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1755 /* 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 */
1756 for(iCP = 3; iCP < 10; iCP++)
1758 iX = offsets[iCP];
1759 cChars = 10;
1760 cGlyphs = 10;
1761 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1762 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1763 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1764 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1767 items[0].a.fRTL = TRUE;
1769 iX = -1;
1770 cChars = 10;
1771 cGlyphs = 10;
1772 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1773 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1774 if (piTrailing)
1775 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1776 else /* win2k3 */
1777 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1779 iX = 1954;
1780 cChars = 10;
1781 cGlyphs = 10;
1782 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1783 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1784 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
1785 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1787 for(iCP = 0; iCP < 10; iCP++)
1789 iX = offsets_RTL[iCP]-1;
1790 cChars = 10;
1791 cGlyphs = 10;
1792 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1793 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1794 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1795 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1798 for(iCP = 0; iCP < 10; iCP++)
1800 iX = offsets_RTL[iCP+1]+1;
1801 cChars = 10;
1802 cGlyphs = 10;
1803 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1804 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1805 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1806 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1809 for(iCP = 0; iCP < 10; iCP++)
1811 iX = offsets_RTL[iCP];
1812 cChars = 10;
1813 cGlyphs = 10;
1814 hr = ScriptXtoCP(iX, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piCP, &piTrailing);
1815 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1816 ok(piCP == iCP, "iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1817 ok(piTrailing == 0, "iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1820 items[0].a.fRTL = FALSE;
1822 for(iCP = 0; iCP <= 11; iCP++)
1824 fTrailing = FALSE;
1825 cChars = 10;
1826 cGlyphs = 10;
1827 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1828 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1829 ok(piX == offsets[iCP],
1830 "iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
1833 for(iCP = 0; iCP <= 11; iCP++)
1835 fTrailing = TRUE;
1836 cChars = 10;
1837 cGlyphs = 10;
1838 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust, psva, piAdvance, &items[0].a, &piX);
1839 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1840 ok(piX == offsets[iCP+1],
1841 "iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
1844 items[0].a.fRTL = TRUE;
1846 for(iCP = 0; iCP <= 11; iCP++)
1848 fTrailing = FALSE;
1849 cChars = 10;
1850 cGlyphs = 10;
1851 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piX);
1852 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1853 ok(piX == offsets_RTL[iCP],
1854 "iCP=%d should return piX=%d not %d\n", iCP, offsets_RTL[iCP], piX);
1857 for(iCP = 0; iCP <= 11; iCP++)
1859 fTrailing = TRUE;
1860 cChars = 10;
1861 cGlyphs = 10;
1862 hr = ScriptCPtoX(iCP, fTrailing, cChars, cGlyphs, pwLogClust_RTL, psva, piAdvance, &items[0].a, &piX);
1863 ok(hr == S_OK, "ScriptCPtoX should return S_OK not %08x\n", hr);
1864 ok(piX == offsets_RTL[iCP+1],
1865 "iCP=%d should return piX=%d not %d\n", iCP, offsets_RTL[iCP+1], piX);
1869 static void test_ScriptString(HDC hdc)
1871 /*******************************************************************************************
1873 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
1874 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
1875 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
1876 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
1880 HRESULT hr;
1881 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
1882 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
1883 int Glyphs = len * 2 + 16;
1884 int Charset;
1885 DWORD Flags = SSA_GLYPHS;
1886 int ReqWidth = 100;
1887 const int Dx[5] = {10, 10, 10, 10, 10};
1888 const BYTE InClass = 0;
1889 SCRIPT_STRING_ANALYSIS ssa = NULL;
1891 int X = 10;
1892 int Y = 100;
1893 UINT Options = 0;
1894 const RECT rc = {0, 50, 100, 100};
1895 int MinSel = 0;
1896 int MaxSel = 0;
1897 BOOL Disabled = FALSE;
1898 const int *clip_len;
1899 int i;
1900 UINT *order;
1903 Charset = -1; /* this flag indicates unicode input */
1904 /* Test without hdc to get E_PENDING */
1905 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
1906 ReqWidth, NULL, NULL, Dx, NULL,
1907 &InClass, &ssa);
1908 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
1910 /* test with hdc, this should be a valid test */
1911 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1912 ReqWidth, NULL, NULL, Dx, NULL,
1913 &InClass, &ssa);
1914 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1915 ScriptStringFree(&ssa);
1917 /* test makes sure that a call with a valid pssa still works */
1918 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
1919 ReqWidth, NULL, NULL, Dx, NULL,
1920 &InClass, &ssa);
1921 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
1922 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
1924 if (hr == S_OK)
1926 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
1927 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
1930 clip_len = ScriptString_pcOutChars(ssa);
1931 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
1933 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
1934 hr = ScriptStringGetOrder(ssa, order);
1935 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
1937 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
1938 HeapFree(GetProcessHeap(), 0, order);
1940 hr = ScriptStringFree(&ssa);
1941 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
1944 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
1946 /*****************************************************************************************
1948 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
1949 * nature of the fonts between Windows and Wine, the test is implemented by generating
1950 * values using one one function then checking the output of the second. In this way
1951 * the validity of the functions is established using Windows as a base and confirming
1952 * similar behaviour in wine.
1955 HRESULT hr;
1956 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
1957 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
1958 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
1959 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
1960 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
1961 int Charset = -1; /* unicode */
1962 DWORD Flags = SSA_GLYPHS;
1963 int ReqWidth = 100;
1964 const BYTE InClass = 0;
1965 SCRIPT_STRING_ANALYSIS ssa = NULL;
1967 int Ch; /* Character position in string */
1968 int iTrailing;
1969 int Cp; /* Character position in string */
1970 int X;
1971 int trail,lead;
1972 BOOL fTrailing;
1974 /* Test with hdc, this should be a valid test
1975 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
1976 * following character positions to X and X to character position functions.
1979 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
1980 ReqWidth, NULL, NULL, NULL, NULL,
1981 &InClass, &ssa);
1982 ok(hr == S_OK ||
1983 hr == E_INVALIDARG, /* NT */
1984 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
1986 if (hr == S_OK)
1988 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
1991 * Loop to generate character positions to provide starting positions for the
1992 * ScriptStringCPtoX and ScriptStringXtoCP functions
1994 for (Cp = 0; Cp < String_len; Cp++)
1996 /* The fTrailing flag is used to indicate whether the X being returned is at
1997 * the beginning or the end of the character. What happens here is that if
1998 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
1999 * returns the beginning of the next character and iTrailing is FALSE. So for this
2000 * loop iTrailing will be FALSE in both cases.
2002 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
2003 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2004 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
2005 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2006 if (rtl[Cp])
2007 ok(lead > trail, "Leading values should be after trialing for rtl chracters(%i)\n",Cp);
2008 else
2009 ok(lead < trail, "Trailing values should be after leading for ltr chracters(%i)\n",Cp);
2011 /* move by 1 pixel so that we are not inbetween 2 characters. That could result in being the lead of a rtl and
2012 at the same time the trail of an ltr */
2014 /* inside the leading edge */
2015 X = lead;
2016 if (rtl[Cp]) X--; else X++;
2017 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2018 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2019 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2020 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2021 iTrailing, X);
2023 /* inside the trailing edge */
2024 X = trail;
2025 if (rtl[Cp]) X++; else X--;
2026 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2027 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2028 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2029 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2030 iTrailing, X);
2032 /* outside the "trailing" edge */
2033 if (Cp < String_len-1)
2035 if (rtl[Cp]) X = lead; else X = trail;
2036 X++;
2037 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2038 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2039 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
2040 if (rtl[Cp+1])
2041 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2042 iTrailing, X);
2043 else
2044 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2045 iTrailing, X);
2048 /* outside the "leading" edge */
2049 if (Cp != 0)
2051 if (rtl[Cp]) X = trail; else X = lead;
2052 X--;
2053 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2054 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2055 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
2056 if (Cp != 0 && rtl[Cp-1])
2057 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2058 iTrailing, X);
2059 else
2060 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2061 iTrailing, X);
2065 /* Check beyond the leading boundary of the whole string */
2066 if (rtl[0])
2068 /* having a leading rtl character seems to confuse usp */
2069 /* this looks to be a windows bug we should emulate */
2070 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
2071 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2072 X--;
2073 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2074 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2075 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
2076 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
2077 iTrailing);
2079 else
2081 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
2082 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2083 X--;
2084 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2085 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2086 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
2087 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
2088 iTrailing);
2091 /* Check beyond the end boundary of the whole string */
2092 if (rtl[String_len-1])
2094 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
2095 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2097 else
2099 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
2100 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2102 X++;
2103 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2104 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2105 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
2106 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside traling edge\n",
2107 iTrailing);
2110 * Cleanup the SSA for the next round of tests
2112 hr = ScriptStringFree(&ssa);
2113 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2116 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
2117 * generate an SSA for the subsequent tests.
2119 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2120 ReqWidth, NULL, NULL, NULL, NULL,
2121 &InClass, &ssa);
2122 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2125 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2126 * string length, return E_INVALIDARG. This also invalidates the ssa so a
2127 * ScriptStringFree should also fail.
2129 fTrailing = FALSE;
2130 Cp = String_len + 1;
2131 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2132 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2134 ScriptStringFree(&ssa);
2138 static void test_ScriptCacheGetHeight(HDC hdc)
2140 HRESULT hr;
2141 SCRIPT_CACHE sc = NULL;
2142 LONG height;
2144 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2145 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2147 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2148 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2150 hr = ScriptCacheGetHeight(NULL, &sc, &height);
2151 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2153 height = 0;
2155 hr = ScriptCacheGetHeight(hdc, &sc, &height);
2156 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2157 ok(height > 0, "expected height > 0\n");
2159 ScriptFreeCache(&sc);
2162 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2164 HRESULT hr;
2165 SCRIPT_CACHE sc = NULL;
2166 ABC abc;
2168 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2169 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2171 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2172 ok(broken(hr == E_PENDING) ||
2173 hr == E_INVALIDARG, /* WIN7 */
2174 "expected E_INVALIDARG, got 0x%08x\n", hr);
2176 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2177 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2179 if (0) { /* crashes on WinXP */
2180 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2181 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2184 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2185 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2187 ScriptFreeCache(&sc);
2190 static void test_ScriptLayout(void)
2192 HRESULT hr;
2193 static const BYTE levels[][10] =
2195 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2196 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2197 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2198 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2200 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2201 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2202 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2203 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2204 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2206 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2207 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2209 static const int expect_l2v[][10] =
2211 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2212 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2213 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2214 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2216 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2217 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2218 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2219 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2220 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2222 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2223 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2225 static const int expect_v2l[][10] =
2227 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2228 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2229 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2230 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2232 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2233 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2234 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2235 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2236 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2238 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2239 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2242 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2244 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2245 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2247 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2248 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2250 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2252 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2253 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2255 for (j = 0; j < sizeof(levels[i]); j++)
2257 ok(expect_v2l[i][j] == vistolog[j],
2258 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2259 i, j, levels[i][j], j, vistolog[j] );
2262 for (j = 0; j < sizeof(levels[i]); j++)
2264 ok(expect_l2v[i][j] == logtovis[j],
2265 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2266 i, j, levels[i][j], j, logtovis[j] );
2271 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2273 HRESULT hr;
2274 SCRIPT_DIGITSUBSTITUTE sds;
2275 SCRIPT_CONTROL sc;
2276 SCRIPT_STATE ss;
2277 LCID lcid_old;
2279 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2281 memset(&sds, 0, sizeof(sds));
2282 memset(&sc, 0, sizeof(sc));
2283 memset(&ss, 0, sizeof(ss));
2285 lcid_old = GetThreadLocale();
2286 if (!SetThreadLocale(lcid)) return TRUE;
2288 hr = ScriptRecordDigitSubstitution(lcid, &sds);
2289 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2291 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2292 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2294 SetThreadLocale(lcid_old);
2295 return TRUE;
2298 static void test_digit_substitution(void)
2300 BOOL ret;
2301 unsigned int i;
2302 static const LGRPID groups[] =
2304 LGRPID_WESTERN_EUROPE,
2305 LGRPID_CENTRAL_EUROPE,
2306 LGRPID_BALTIC,
2307 LGRPID_GREEK,
2308 LGRPID_CYRILLIC,
2309 LGRPID_TURKISH,
2310 LGRPID_JAPANESE,
2311 LGRPID_KOREAN,
2312 LGRPID_TRADITIONAL_CHINESE,
2313 LGRPID_SIMPLIFIED_CHINESE,
2314 LGRPID_THAI,
2315 LGRPID_HEBREW,
2316 LGRPID_ARABIC,
2317 LGRPID_VIETNAMESE,
2318 LGRPID_INDIC,
2319 LGRPID_GEORGIAN,
2320 LGRPID_ARMENIAN
2322 HMODULE hKernel32;
2323 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2325 hKernel32 = GetModuleHandleA("kernel32.dll");
2326 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2328 if (!pEnumLanguageGroupLocalesA)
2330 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2331 return;
2334 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2336 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2337 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2339 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2340 break;
2343 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2347 static void test_ScriptGetProperties(void)
2349 const SCRIPT_PROPERTIES **props;
2350 HRESULT hr;
2351 int num;
2353 hr = ScriptGetProperties(NULL, NULL);
2354 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2356 hr = ScriptGetProperties(NULL, &num);
2357 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2359 hr = ScriptGetProperties(&props, NULL);
2360 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2362 hr = ScriptGetProperties(&props, &num);
2363 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2366 static void test_ScriptBreak(void)
2368 static const WCHAR test[] = {' ','\r','\n',0};
2369 SCRIPT_ITEM items[4];
2370 SCRIPT_LOGATTR la;
2371 HRESULT hr;
2373 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2374 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2376 memset(&la, 0, sizeof(la));
2377 hr = ScriptBreak(test, 1, &items[0].a, &la);
2378 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2380 ok(!la.fSoftBreak, "fSoftBreak set\n");
2381 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2382 ok(la.fCharStop, "fCharStop not set\n");
2383 ok(!la.fWordStop, "fWordStop set\n");
2384 ok(!la.fInvalid, "fInvalid set\n");
2385 ok(!la.fReserved, "fReserved set\n");
2387 memset(&la, 0, sizeof(la));
2388 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2389 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2391 ok(!la.fSoftBreak, "fSoftBreak set\n");
2392 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2393 ok(la.fCharStop, "fCharStop not set\n");
2394 ok(!la.fWordStop, "fWordStop set\n");
2395 ok(!la.fInvalid, "fInvalid set\n");
2396 ok(!la.fReserved, "fReserved set\n");
2398 memset(&la, 0, sizeof(la));
2399 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2400 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2402 ok(!la.fSoftBreak, "fSoftBreak set\n");
2403 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2404 ok(la.fCharStop, "fCharStop not set\n");
2405 ok(!la.fWordStop, "fWordStop set\n");
2406 ok(!la.fInvalid, "fInvalid set\n");
2407 ok(!la.fReserved, "fReserved set\n");
2410 static void test_newlines(void)
2412 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2413 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2414 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2415 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2416 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2417 SCRIPT_ITEM items[5];
2418 HRESULT hr;
2419 int count;
2421 count = 0;
2422 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2423 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2424 ok(count == 3, "got %d expected 3\n", count);
2426 count = 0;
2427 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2428 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2429 ok(count == 3, "got %d expected 3\n", count);
2431 count = 0;
2432 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2433 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2434 ok(count == 4, "got %d expected 4\n", count);
2436 count = 0;
2437 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2438 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2439 ok(count == 4, "got %d expected 4\n", count);
2441 count = 0;
2442 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2443 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2444 ok(count == 4, "got %d expected 4\n", count);
2447 START_TEST(usp10)
2449 HWND hwnd;
2450 HDC hdc;
2451 LOGFONTA lf;
2452 HFONT hfont;
2454 unsigned short pwOutGlyphs[256];
2456 /* We need a valid HDC to drive a lot of Script functions which requires the following *
2457 * to set up for the tests. */
2458 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2459 0, 0, 0, NULL);
2460 assert(hwnd != 0);
2461 ShowWindow(hwnd, SW_SHOW);
2462 UpdateWindow(hwnd);
2464 hdc = GetDC(hwnd); /* We now have a hdc */
2465 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2467 memset(&lf, 0, sizeof(LOGFONTA));
2468 lstrcpyA(lf.lfFaceName, "Tahoma");
2469 lf.lfHeight = 10;
2470 lf.lfWeight = 3;
2471 lf.lfWidth = 10;
2473 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2474 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2476 test_ScriptItemize();
2477 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2478 test_ScriptGetCMap(hdc, pwOutGlyphs);
2479 test_ScriptCacheGetHeight(hdc);
2480 test_ScriptGetGlyphABCWidth(hdc);
2481 test_ScriptShape(hdc);
2482 test_ScriptShapeOpenType(hdc);
2483 test_ScriptPlace(hdc);
2485 test_ScriptGetFontProperties(hdc);
2486 test_ScriptTextOut(hdc);
2487 test_ScriptTextOut2(hdc);
2488 test_ScriptTextOut3(hdc);
2489 test_ScriptXtoX();
2490 test_ScriptString(hdc);
2491 test_ScriptStringXtoCP_CPtoX(hdc);
2493 test_ScriptLayout();
2494 test_digit_substitution();
2495 test_ScriptGetProperties();
2496 test_ScriptBreak();
2497 test_newlines();
2499 ReleaseDC(hwnd, hdc);
2500 DestroyWindow(hwnd);