usp10: Windows breaks punctuation into 2 different script types.
[wine.git] / dlls / usp10 / tests / usp10.c
blobb29f592e8dc91f12e8b3fac60a9af8631200097b
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 BOOL isBroken;
42 int broken_value[5];
43 } itemTest;
45 typedef struct _shapeTest_char {
46 WORD wLogClust;
47 SCRIPT_CHARPROP CharProp;
48 } shapeTest_char;
50 typedef struct _shapeTest_glyph {
51 int Glyph;
52 SCRIPT_GLYPHPROP GlyphProp;
53 } shapeTest_glyph;
55 /* Uniscribe 1.6 calls */
56 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);
58 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);
60 static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
62 static inline void _test_items_ok(LPCWSTR string, DWORD cchString,
63 SCRIPT_CONTROL *Control, SCRIPT_STATE *State,
64 DWORD nItems, const itemTest* items, BOOL nItemsToDo,
65 INT nItemsBroken)
67 HRESULT hr;
68 int x, outnItems;
69 SCRIPT_ITEM outpItems[15];
70 ULONG tags[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
72 if (pScriptItemizeOpenType)
73 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
74 else
75 hr = ScriptItemize(string, cchString, 15, Control, State, outpItems, &outnItems);
77 winetest_ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
78 if (nItemsBroken && broken(nItemsBroken == outnItems))
80 winetest_win_skip("This test broken on this platform\n");
81 return;
83 if (nItemsToDo)
84 todo_wine winetest_ok(outnItems == nItems, "Wrong number of items\n");
85 else
86 winetest_ok(outnItems == nItems, "Wrong number of items\n");
87 for (x = 0; x <= outnItems; x++)
89 if (items[x].isBroken && broken(outpItems[x].iCharPos == items[x].broken_value[0]))
90 winetest_win_skip("This test broken on this platform\n");
91 else if (items[x].todo_flag[0])
92 todo_wine winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos\n",x);
93 else
94 winetest_ok(outpItems[x].iCharPos == items[x].iCharPos, "%i:Wrong CharPos (%i)\n",x,outpItems[x].iCharPos);
96 if (items[x].isBroken && broken(outpItems[x].a.fRTL== items[x].broken_value[1]))
97 winetest_win_skip("This test broken on this platform\n");
98 else if (items[x].todo_flag[1])
99 todo_wine winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL\n",x);
100 else
101 winetest_ok(outpItems[x].a.fRTL == items[x].fRTL, "%i:Wrong fRTL(%i)\n",x,outpItems[x].a.fRTL);
103 if (items[x].isBroken && broken(outpItems[x].a.fLayoutRTL == items[x].broken_value[2]))
104 winetest_win_skip("This test broken on this platform\n");
105 else if (items[x].todo_flag[2])
106 todo_wine winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL\n",x);
107 else
108 winetest_ok(outpItems[x].a.fLayoutRTL == items[x].fLayoutRTL, "%i:Wrong fLayoutRTL(%i)\n",x,outpItems[x].a.fLayoutRTL);
110 if (items[x].isBroken && broken(outpItems[x].a.s.uBidiLevel == items[x].broken_value[3]))
111 winetest_win_skip("This test broken on this platform\n");
112 else if (items[x].todo_flag[3])
113 todo_wine winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel\n",x);
114 else
115 winetest_ok(outpItems[x].a.s.uBidiLevel == items[x].uBidiLevel, "%i:Wrong BidiLevel(%i)\n",x,outpItems[x].a.s.uBidiLevel);
116 if (x != outnItems)
117 winetest_ok(outpItems[x].a.eScript != SCRIPT_UNDEFINED, "%i: Undefined script\n",x);
118 if (pScriptItemizeOpenType)
120 if (items[x].todo_flag[4])
121 todo_wine winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
122 else
123 winetest_ok(tags[x] == items[x].scriptTag,"%i:Incorrect Script Tag %x != %x\n",x,tags[x],items[x].scriptTag);
128 #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)
130 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
131 ( ( (ULONG)_x4 << 24 ) | \
132 ( (ULONG)_x3 << 16 ) | \
133 ( (ULONG)_x2 << 8 ) | \
134 (ULONG)_x1 )
136 #define latn_tag MS_MAKE_TAG('l','a','t','n')
137 #define arab_tag MS_MAKE_TAG('a','r','a','b')
138 #define thai_tag MS_MAKE_TAG('t','h','a','i')
139 #define hebr_tag MS_MAKE_TAG('h','e','b','r')
140 #define syrc_tag MS_MAKE_TAG('s','y','r','c')
141 #define deva_tag MS_MAKE_TAG('d','e','v','a')
142 #define beng_tag MS_MAKE_TAG('b','e','n','g')
143 #define guru_tag MS_MAKE_TAG('g','u','r','u')
144 #define gujr_tag MS_MAKE_TAG('g','u','j','r')
145 #define orya_tag MS_MAKE_TAG('o','r','y','a')
146 #define taml_tag MS_MAKE_TAG('t','a','m','l')
147 #define telu_tag MS_MAKE_TAG('t','e','l','u')
148 #define knda_tag MS_MAKE_TAG('k','n','d','a')
149 #define mlym_tag MS_MAKE_TAG('m','l','y','m')
151 static void test_ScriptItemize( void )
153 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
154 static const itemTest t11[2] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1}};
155 static const itemTest t12[2] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
157 static const WCHAR test1b[] = {' ', ' ', ' ', ' ',0};
158 static const itemTest t1b1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
159 static const itemTest t1b2[2] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
161 static const WCHAR test1c[] = {' ', ' ', ' ', '1', '2', ' ',0};
162 static const itemTest t1c1[2] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
163 static const itemTest t1c2[4] = {{{0,0,0,0,0},0,1,1,1,0,FALSE},{{0,0,0,0,0},3,0,1,2,0,FALSE},{{0,0,0,0,0},5,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
165 /* Arabic, English*/
166 static const WCHAR test2[] = {'1','2','3','-','5','2',0x064a,0x064f,0x0633,0x0627,0x0648,0x0650,0x064a,'7','1','.',0};
167 static const itemTest t21[7] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,0,0,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
168 static const itemTest t22[5] = {{{0,0,0,0,0},0,0,0,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,0,0,0,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
169 static const itemTest t23[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},13,0,1,2,0,FALSE},{{0,0,0,0,0},15,1,1,1,0,FALSE},{{0,0,0,0,0},16,0,0,0,-1,FALSE}};
171 static const WCHAR test2b[] = {'A','B','C','-','D','E','F',' ',0x0621,0x0623,0x0624,0};
172 static const itemTest t2b1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
173 static const itemTest t2b2[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
174 static const itemTest t2b3[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
176 /* leading space */
177 static const WCHAR test2c[] = {' ',0x0621,0x0623,0x0624,'A','B','C','-','D','E','F',0};
178 static const itemTest t2c1[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
179 static const itemTest t2c2[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},1,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,0,0,FALSE},{{0,0,0,0,0},8,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
180 static const itemTest t2c3[5] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,0,0,2,0,FALSE},{{0,0,0,0,0},8,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
181 static const itemTest t2c4[3] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
183 /* trailing space */
184 static const WCHAR test2d[] = {'A','B','C','-','D','E','F',0x0621,0x0623,0x0624,' ',0};
185 static const itemTest t2d1[5] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
186 static const itemTest t2d2[6] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
187 static const itemTest t2d3[5] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,2,0,FALSE},{{0,0,0,0,0},4,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
188 static const itemTest t2d4[3] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},7,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},11,0,0,0,-1,FALSE}};
190 /* Thai */
191 static const WCHAR test3[] =
192 {0x0e04,0x0e27,0x0e32,0x0e21,0x0e1e,0x0e22,0x0e32,0x0e22,0x0e32, 0x0e21
193 ,0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e44,0x0e2b,0x0e19
194 ,0x0e04,0x0e27,0x0e32,0x0e21,0x0e2a, 0x0e33,0x0e40,0x0e23,0x0e47,0x0e08,
195 0x0e2d,0x0e22,0x0e39,0x0e48,0x0e17,0x0e35,0x0e48,0x0e19,0x0e31,0x0e48,0x0e19,0};
197 static const itemTest t31[2] = {{{0,0,0,0,0},0,0,0,0,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
198 static const itemTest t32[2] = {{{0,0,0,0,0},0,0,0,2,thai_tag,FALSE},{{0,0,0,0,0},41,0,0,0,-1,FALSE}};
200 static const WCHAR test4[] = {'1','2','3','-','5','2',' ','i','s',' ','7','1','.',0};
202 static const itemTest t41[6] = {{{0,0,0,0,0},0,0,0,0,0,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},7,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,0,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
203 static const itemTest t42[5] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},10,0,0,2,0,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
204 static const itemTest t43[4] = {{{0,0,0,0,0},0,0,1,2,0,FALSE},{{0,0,0,0,0},6,1,1,1,0,FALSE},{{0,0,0,0,0},7,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},12,0,0,0,-1,FALSE}};
206 /* Arabic */
207 static const WCHAR test5[] =
208 {0x0627,0x0644,0x0635,0x0651,0x0650,0x062d,0x0629,0x064f,' ',0x062a,0x064e,
209 0x0627,0x062c,0x064c,' ',0x0639,0x064e,0x0644,0x0649,' ',
210 0x0631,0x064f,0x0624,0x0648,0x0633,0x0650,' ',0x0627,0x0644
211 ,0x0623,0x0635,0x0650,0x062d,0x0651,0x064e,0x0627,0x0621,0x0650,0};
212 static const itemTest t51[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},38,0,0,0,-1,FALSE}};
214 /* Hebrew */
215 static const WCHAR test6[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd, '.',0};
216 static const itemTest t61[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
217 static const itemTest t62[3] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},4,1,1,1,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
218 static const itemTest t63[2] = {{{0,0,0,0,0},0,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
219 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};
220 static const itemTest t71[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
221 static const itemTest t72[4] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},9,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},18,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
222 static const itemTest t73[4] = {{{0,0,0,0,0},0,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},8,1,1,1,hebr_tag,FALSE},{{0,0,0,0,0},19,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},29,0,0,0,-1,FALSE}};
223 static const WCHAR test8[] = {0x0633, 0x0644, 0x0627, 0x0645,0};
224 static const itemTest t81[2] = {{{0,0,0,0,0},0,1,1,1,arab_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
226 /* Syriac (Like Arabic )*/
227 static const WCHAR test9[] = {0x0710, 0x0712, 0x0712, 0x0714, '.',0};
228 static const itemTest t91[3] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,0,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
229 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,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
230 static const itemTest t93[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
232 static const WCHAR test10[] = {0x0717, 0x0718, 0x071a, 0x071b,0};
233 static const itemTest t101[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},4,0,0,0,-1,FALSE}};
235 /* Devanagari */
236 static const WCHAR test11[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
237 static const itemTest t111[2] = {{{0,0,0,0,0},0,0,0,0,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
238 static const itemTest t112[2] = {{{0,0,0,0,0},0,0,0,2,deva_tag,FALSE},{{0,0,0,0,0},8,0,0,0,-1,FALSE}};
240 /* Bengali */
241 static const WCHAR test12[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
242 static const itemTest t121[2] = {{{0,0,0,0,0},0,0,0,0,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
243 static const itemTest t122[2] = {{{0,0,0,0,0},0,0,0,2,beng_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
245 /* Gurmukhi */
246 static const WCHAR test13[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
247 static const itemTest t131[2] = {{{0,0,0,0,0},0,0,0,0,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
248 static const itemTest t132[2] = {{{0,0,0,0,0},0,0,0,2,guru_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
250 /* Gujarati */
251 static const WCHAR test14[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
252 static const itemTest t141[2] = {{{0,0,0,0,0},0,0,0,0,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
253 static const itemTest t142[2] = {{{0,0,0,0,0},0,0,0,2,gujr_tag,FALSE},{{0,0,0,0,0},7,0,0,0,-1,FALSE}};
255 /* Oriya */
256 static const WCHAR test15[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
257 static const itemTest t151[2] = {{{0,0,0,0,0},0,0,0,0,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
258 static const itemTest t152[2] = {{{0,0,0,0,0},0,0,0,2,orya_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
260 /* Tamil */
261 static const WCHAR test16[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
262 static const itemTest t161[2] = {{{0,0,0,0,0},0,0,0,0,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
263 static const itemTest t162[2] = {{{0,0,0,0,0},0,0,0,2,taml_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
265 /* Telugu */
266 static const WCHAR test17[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
267 static const itemTest t171[2] = {{{0,0,0,0,0},0,0,0,0,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
268 static const itemTest t172[2] = {{{0,0,0,0,0},0,0,0,2,telu_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
270 /* Kannada */
271 static const WCHAR test18[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
272 static const itemTest t181[2] = {{{0,0,0,0,0},0,0,0,0,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
273 static const itemTest t182[2] = {{{0,0,0,0,0},0,0,0,2,knda_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
275 /* Malayalam */
276 static const WCHAR test19[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
277 static const itemTest t191[2] = {{{0,0,0,0,0},0,0,0,0,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
278 static const itemTest t192[2] = {{{0,0,0,0,0},0,0,0,2,mlym_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
280 /* Diacritical */
281 static const WCHAR test20[] = {0x0309,'a','b','c','d',0};
282 static const itemTest t201[3] = {{{0,0,0,0,0},0,0,0,0,0x0,FALSE},{{0,0,0,0,0},1,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
283 static const itemTest t202[3] = {{{0,0,0,0,0},0,0,0,2,0,TRUE,{-1,1,1,1,-1}},{{0,0,0,0,0},1,0,0,2,latn_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
285 static const WCHAR test21[] = {0x0710, 0x0712, 0x0308, 0x0712, 0x0714,0};
286 static const itemTest t211[2] = {{{0,0,0,0,0},0,1,1,1,syrc_tag,FALSE},{{0,0,0,0,0},5,0,0,0,-1,FALSE}};
288 /* Latin Punctuation */
289 static const WCHAR test22[] = {'#','$',',','!','\"','*',0};
290 static const itemTest t221[3] = {{{0,0,0,0,0},0,0,0,0,latn_tag,FALSE},{{0,0,0,0,0},3,0,0,0,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
291 static const itemTest t222[3] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},3,1,1,1,0,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
292 static const itemTest t223[2] = {{{0,0,0,0,0},0,1,1,1,latn_tag,FALSE},{{0,0,0,0,0},6,0,0,0,-1,FALSE}};
295 SCRIPT_ITEM items[15];
296 SCRIPT_CONTROL Control;
297 SCRIPT_STATE State;
298 HRESULT hr;
299 HMODULE usp10;
300 int nItems;
302 usp10 = LoadLibraryA("usp10.dll");
303 ok (usp10 != 0,"Unable to LoadLibrary on usp10.dll\n");
304 pScriptItemizeOpenType = (void*)GetProcAddress(usp10, "ScriptItemizeOpenType");
305 pScriptShapeOpenType = (void*)GetProcAddress(usp10, "ScriptShapeOpenType");
306 pGetGlyphIndicesW = (void*)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetGlyphIndicesW");
308 memset(&Control, 0, sizeof(Control));
309 memset(&State, 0, sizeof(State));
311 hr = ScriptItemize(NULL, 4, 10, &Control, &State, items, NULL);
312 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pwcInChars is NULL\n");
314 hr = ScriptItemize(test1, 4, 10, &Control, &State, NULL, NULL);
315 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if pItems is NULL\n");
317 hr = ScriptItemize(test1, 4, 1, &Control, &State, items, NULL);
318 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cMaxItems < 2.\n");
320 hr = ScriptItemize(test1, 0, 10, NULL, NULL, items, &nItems);
321 ok (hr == E_INVALIDARG, "ScriptItemize should return E_INVALIDARG if cInChars is 0\n");
323 test_items_ok(test1,4,NULL,NULL,1,t11,FALSE,0);
324 test_items_ok(test1b,4,NULL,NULL,1,t1b1,FALSE,0);
325 test_items_ok(test1c,6,NULL,NULL,1,t1c1,FALSE,0);
326 test_items_ok(test2,16,NULL,NULL,6,t21,FALSE,0);
327 test_items_ok(test2b,11,NULL,NULL,4,t2b1,FALSE,0);
328 test_items_ok(test2c,11,NULL,NULL,4,t2c1,FALSE,0);
329 test_items_ok(test2d,11,NULL,NULL,4,t2d1,FALSE,0);
330 test_items_ok(test3,41,NULL,NULL,1,t31,FALSE,0);
331 test_items_ok(test4,12,NULL,NULL,5,t41,FALSE,0);
332 test_items_ok(test5,38,NULL,NULL,1,t51,FALSE,0);
333 test_items_ok(test6,5,NULL,NULL,2,t61,FALSE,0);
334 test_items_ok(test7,29,NULL,NULL,3,t71,FALSE,0);
335 test_items_ok(test8,4,NULL,NULL,1,t81,FALSE,0);
336 test_items_ok(test9,5,NULL,NULL,2,t91,FALSE,0);
337 test_items_ok(test10,4,NULL,NULL,1,t101,FALSE,0);
338 test_items_ok(test11,8,NULL,NULL,1,t111,FALSE,0);
339 test_items_ok(test12,5,NULL,NULL,1,t121,FALSE,0);
340 test_items_ok(test13,7,NULL,NULL,1,t131,FALSE,0);
341 test_items_ok(test14,7,NULL,NULL,1,t141,FALSE,0);
342 test_items_ok(test15,5,NULL,NULL,1,t151,FALSE,0);
343 test_items_ok(test16,5,NULL,NULL,1,t161,FALSE,0);
344 test_items_ok(test17,6,NULL,NULL,1,t171,FALSE,0);
345 test_items_ok(test18,5,NULL,NULL,1,t181,FALSE,0);
346 test_items_ok(test19,6,NULL,NULL,1,t191,FALSE,0);
347 test_items_ok(test20,5,NULL,NULL,2,t201,FALSE,0);
348 test_items_ok(test21,5,NULL,NULL,1,t211,FALSE,0);
349 test_items_ok(test22,6,NULL,NULL,2,t221,FALSE,0);
351 State.uBidiLevel = 0;
352 test_items_ok(test1,4,&Control,&State,1,t11,FALSE,0);
353 test_items_ok(test1b,4,&Control,&State,1,t1b1,FALSE,0);
354 test_items_ok(test1c,6,&Control,&State,1,t1c1,FALSE,0);
355 test_items_ok(test2,16,&Control,&State,4,t22,FALSE,0);
356 test_items_ok(test2b,11,&Control,&State,4,t2b1,FALSE,0);
357 test_items_ok(test2c,11,&Control,&State,5,t2c2,FALSE,0);
358 test_items_ok(test2d,11,&Control,&State,5,t2d2,FALSE,0);
359 test_items_ok(test3,41,&Control,&State,1,t31,FALSE,0);
360 test_items_ok(test4,12,&Control,&State,5,t41,FALSE,0);
361 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
362 test_items_ok(test6,5,&Control,&State,2,t61,FALSE,0);
363 test_items_ok(test7,29,&Control,&State,3,t72,FALSE,0);
364 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
365 test_items_ok(test9,5,&Control,&State,2,t91,FALSE,0);
366 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
367 test_items_ok(test11,8,&Control,&State,1,t111,FALSE,0);
368 test_items_ok(test12,5,&Control,&State,1,t121,FALSE,0);
369 test_items_ok(test13,7,&Control,&State,1,t131,FALSE,0);
370 test_items_ok(test14,7,&Control,&State,1,t141,FALSE,0);
371 test_items_ok(test15,5,&Control,&State,1,t151,FALSE,0);
372 test_items_ok(test16,5,&Control,&State,1,t161,FALSE,0);
373 test_items_ok(test17,6,&Control,&State,1,t171,FALSE,0);
374 test_items_ok(test18,5,&Control,&State,1,t181,FALSE,0);
375 test_items_ok(test19,6,&Control,&State,1,t191,FALSE,0);
376 test_items_ok(test20,5,&Control,&State,2,t201,FALSE,0);
377 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
378 test_items_ok(test22,6,&Control,&State,2,t221,FALSE,0);
380 State.uBidiLevel = 1;
381 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
382 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
383 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
384 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
385 test_items_ok(test2b,11,&Control,&State,4,t2b2,FALSE,0);
386 test_items_ok(test2c,11,&Control,&State,4,t2c3,FALSE,0);
387 test_items_ok(test2d,11,&Control,&State,4,t2d3,FALSE,0);
388 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
389 test_items_ok(test4,12,&Control,&State,4,t42,FALSE,0);
390 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
391 test_items_ok(test6,5,&Control,&State,2,t62,FALSE,0);
392 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
393 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
394 test_items_ok(test9,5,&Control,&State,2,t92,FALSE,0);
395 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
396 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
397 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
398 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
399 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
400 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
401 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
402 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
403 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
404 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
405 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
406 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
407 test_items_ok(test22,6,&Control,&State,2,t222,FALSE,1);
409 State.uBidiLevel = 1;
410 Control.fMergeNeutralItems = TRUE;
411 test_items_ok(test1,4,&Control,&State,1,t12,FALSE,0);
412 test_items_ok(test1b,4,&Control,&State,1,t1b2,FALSE,0);
413 test_items_ok(test1c,6,&Control,&State,3,t1c2,FALSE,0);
414 test_items_ok(test2,16,&Control,&State,4,t23,FALSE,0);
415 test_items_ok(test2b,11,&Control,&State,2,t2b3,FALSE,4);
416 test_items_ok(test2c,11,&Control,&State,2,t2c4,FALSE,4);
417 test_items_ok(test2d,11,&Control,&State,2,t2d4,FALSE,4);
418 test_items_ok(test3,41,&Control,&State,1,t32,FALSE,0);
419 test_items_ok(test4,12,&Control,&State,3,t43,FALSE,4);
420 test_items_ok(test5,38,&Control,&State,1,t51,FALSE,0);
421 test_items_ok(test6,5,&Control,&State,1,t63,FALSE,2);
422 test_items_ok(test7,29,&Control,&State,3,t73,FALSE,0);
423 test_items_ok(test8,4,&Control,&State,1,t81,FALSE,0);
424 test_items_ok(test9,5,&Control,&State,1,t93,FALSE,2);
425 test_items_ok(test10,4,&Control,&State,1,t101,FALSE,0);
426 test_items_ok(test11,8,&Control,&State,1,t112,FALSE,0);
427 test_items_ok(test12,5,&Control,&State,1,t122,FALSE,0);
428 test_items_ok(test13,7,&Control,&State,1,t132,FALSE,0);
429 test_items_ok(test14,7,&Control,&State,1,t142,FALSE,0);
430 test_items_ok(test15,5,&Control,&State,1,t152,FALSE,0);
431 test_items_ok(test16,5,&Control,&State,1,t162,FALSE,0);
432 test_items_ok(test17,6,&Control,&State,1,t172,FALSE,0);
433 test_items_ok(test18,5,&Control,&State,1,t182,FALSE,0);
434 test_items_ok(test19,6,&Control,&State,1,t192,FALSE,0);
435 test_items_ok(test20,5,&Control,&State,2,t202,FALSE,0);
436 test_items_ok(test21,5,&Control,&State,1,t211,FALSE,0);
437 test_items_ok(test22,6,&Control,&State,1,t223,FALSE,2);
440 static inline void _test_shape_ok(int valid, HDC hdc, LPCWSTR string,
441 DWORD cchString, SCRIPT_CONTROL *Control,
442 SCRIPT_STATE *State, DWORD item, DWORD nGlyphs,
443 const shapeTest_char* charItems,
444 const shapeTest_glyph* glyphItems)
446 HRESULT hr;
447 int x, outnItems=0, outnGlyphs=0;
448 SCRIPT_ITEM outpItems[15];
449 SCRIPT_CACHE sc = NULL;
450 WORD *glyphs;
451 WORD *logclust;
452 int maxGlyphs = cchString * 1.5;
453 SCRIPT_GLYPHPROP *glyphProp;
454 SCRIPT_CHARPROP *charProp;
455 ULONG tags[15];
457 hr = pScriptItemizeOpenType(string, cchString, 15, Control, State, outpItems, tags, &outnItems);
458 if (hr == USP_E_SCRIPT_NOT_IN_FONT)
460 if (valid > 0)
461 winetest_win_skip("Select font does not support script\n");
462 else
463 winetest_trace("Select font does not support script\n");
464 return;
466 if (valid > 0)
467 winetest_ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
468 else if (hr)
469 winetest_trace("ScriptItemizeOpenType should return S_OK not %08x\n", hr);
472 if (outnItems <= item)
474 if (valid > 0)
475 winetest_win_skip("Did not get enough items\n");
476 else
477 winetest_trace("Did not get enough items\n");
478 return;
481 logclust = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * cchString);
482 memset(logclust,'a',sizeof(WORD) * cchString);
483 charProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_CHARPROP) * cchString);
484 memset(charProp,'a',sizeof(SCRIPT_CHARPROP) * cchString);
485 glyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * maxGlyphs);
486 memset(glyphs,'a',sizeof(WORD) * cchString);
487 glyphProp = HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_GLYPHPROP) * maxGlyphs);
488 memset(glyphProp,'a',sizeof(SCRIPT_GLYPHPROP) * cchString);
490 hr = pScriptShapeOpenType(hdc, &sc, &outpItems[item].a, tags[item], 0x00000000, NULL, NULL, 0, string, cchString, maxGlyphs, logclust, charProp, glyphs, glyphProp, &outnGlyphs);
491 if (valid > 0)
492 winetest_ok(hr == S_OK, "ScriptShapeOpenType failed (%x)\n",hr);
493 else if (hr != S_OK)
494 winetest_trace("ScriptShapeOpenType failed (%x)\n",hr);
495 if (FAILED(hr))
496 return;
498 for (x = 0; x < cchString; x++)
500 if (valid > 0)
501 winetest_ok(logclust[x] == charItems[x].wLogClust, "%i: invalid LogClust(%i)\n",x,logclust[x]);
502 else if (logclust[x] != charItems[x].wLogClust)
503 winetest_trace("%i: invalid LogClust(%i)\n",x,logclust[x]);
504 if (valid > 0)
505 winetest_ok(charProp[x].fCanGlyphAlone == charItems[x].CharProp.fCanGlyphAlone, "%i: invalid fCanGlyphAlone\n",x);
506 else if (charProp[x].fCanGlyphAlone != charItems[x].CharProp.fCanGlyphAlone)
507 winetest_trace("%i: invalid fCanGlyphAlone\n",x);
510 if (valid > 0)
511 winetest_ok(nGlyphs == outnGlyphs, "got incorrect number of glyphs (%i)\n",outnGlyphs);
512 else if (nGlyphs != outnGlyphs)
513 winetest_trace("got incorrect number of glyphs (%i)\n",outnGlyphs);
514 for (x = 0; x < outnGlyphs; x++)
516 if (glyphItems[x].Glyph)
518 if (valid > 0)
519 winetest_ok(glyphs[x]!=0, "%i: Glyph not present when it should be\n",x);
520 else if (glyphs[x]==0)
521 winetest_trace("%i: Glyph not present when it should be\n",x);
523 else
525 if (valid > 0)
526 winetest_ok(glyphs[x]==0, "%i: Glyph present when it should not be\n",x);
527 else if (glyphs[x]!=0)
528 winetest_trace("%i: Glyph present when it should not be\n",x);
530 if (valid > 0)
531 winetest_ok(glyphProp[x].sva.uJustification == glyphItems[x].GlyphProp.sva.uJustification, "%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
532 else if (glyphProp[x].sva.uJustification != glyphItems[x].GlyphProp.sva.uJustification)
533 winetest_trace("%i: uJustification incorrect (%i)\n",x,glyphProp[x].sva.uJustification);
534 if (valid > 0)
535 winetest_ok(glyphProp[x].sva.fClusterStart == glyphItems[x].GlyphProp.sva.fClusterStart, "%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
536 else if (glyphProp[x].sva.fClusterStart != glyphItems[x].GlyphProp.sva.fClusterStart)
537 winetest_trace("%i: fClusterStart incorrect (%i)\n",x,glyphProp[x].sva.fClusterStart);
538 if (valid > 0)
539 winetest_ok(glyphProp[x].sva.fDiacritic == glyphItems[x].GlyphProp.sva.fDiacritic, "%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
540 else if (glyphProp[x].sva.fDiacritic != glyphItems[x].GlyphProp.sva.fDiacritic)
541 winetest_trace("%i: fDiacritic incorrect (%i)\n",x,glyphProp[x].sva.fDiacritic);
542 if (valid > 0)
543 winetest_ok(glyphProp[x].sva.fZeroWidth == glyphItems[x].GlyphProp.sva.fZeroWidth, "%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
544 else if (glyphProp[x].sva.fZeroWidth != glyphItems[x].GlyphProp.sva.fZeroWidth)
545 winetest_trace("%i: fZeroWidth incorrect (%i)\n",x,glyphProp[x].sva.fZeroWidth);
548 HeapFree(GetProcessHeap(),0,logclust);
549 HeapFree(GetProcessHeap(),0,charProp);
550 HeapFree(GetProcessHeap(),0,glyphs);
551 HeapFree(GetProcessHeap(),0,glyphProp);
552 ScriptFreeCache(&sc);
555 #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)
557 #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)
559 typedef struct tagRangeP {
560 BYTE range;
561 LOGFONTA lf;
562 } fontEnumParam;
564 static int CALLBACK enumFontProc( const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
565 DWORD FontType, LPARAM lParam)
567 NEWTEXTMETRICEX *ntme = (NEWTEXTMETRICEX*)lpntme;
568 fontEnumParam *rp = (fontEnumParam*) lParam;
569 int idx = 0;
570 DWORD i;
571 DWORD mask = 0;
573 if (FontType != TRUETYPE_FONTTYPE)
574 return 1;
576 i = rp->range;
577 while (i > sizeof(DWORD)*8)
579 idx++;
580 i -= (sizeof(DWORD)*8);
582 if (idx > 3)
583 return 0;
585 mask = 1 << i;
587 if (ntme->ntmFontSig.fsUsb[idx] & mask)
589 memcpy(&(rp->lf),lpelfe,sizeof(LOGFONT));
590 return 0;
592 return 1;
595 static int _find_font_for_range(HDC hdc, const CHAR *recommended, BYTE range, const WCHAR check, HFONT *hfont, HFONT *origFont)
597 int rc = 0;
598 fontEnumParam lParam;
600 lParam.range = range;
601 memset(&lParam.lf,0,sizeof(LOGFONT));
602 *hfont = NULL;
604 if (recommended)
606 lstrcpyA(lParam.lf.lfFaceName, recommended);
607 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0))
609 *hfont = CreateFontIndirectA(&lParam.lf);
610 if (*hfont)
612 winetest_trace("using font %s\n",lParam.lf.lfFaceName);
613 rc = 1;
618 if (!*hfont)
620 memset(&lParam.lf,0,sizeof(LOGFONT));
621 lParam.lf.lfCharSet = DEFAULT_CHARSET;
623 if (!EnumFontFamiliesExA(hdc, &lParam.lf, enumFontProc, (LPARAM)&lParam, 0) && lParam.lf.lfFaceName[0])
625 *hfont = CreateFontIndirectA(&lParam.lf);
626 if (*hfont)
627 winetest_trace("trying font %s: failures will only be warnings\n",lParam.lf.lfFaceName);
631 if (*hfont)
633 WORD glyph = 0;
635 *origFont = SelectObject(hdc,*hfont);
636 if (pGetGlyphIndicesW && (pGetGlyphIndicesW(hdc, &check, 1, &glyph, 0) == GDI_ERROR || glyph ==0))
638 winetest_trace(" Font fails to contain required glyphs\n");
639 SelectObject(hdc,*origFont);
640 DeleteObject(*hfont);
641 *hfont=NULL;
642 rc = 0;
644 else if (!rc)
645 rc = -1;
647 else
648 winetest_trace("Failed to find usable font\n");
650 return rc;
653 #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)
655 static void test_ScriptShapeOpenType(HDC hdc)
657 HRESULT hr;
658 SCRIPT_CACHE sc = NULL;
659 WORD glyphs[4], logclust[4];
660 SCRIPT_GLYPHPROP glyphProp[4];
661 SCRIPT_ITEM items[2];
662 ULONG tags[2];
663 SCRIPT_CONTROL Control;
664 SCRIPT_STATE State;
665 int nb, outnItems;
666 HFONT hfont, hfont_orig;
667 int test_valid;
669 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
670 static const shapeTest_char t1_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
671 static const shapeTest_glyph t1_g[] = {
672 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
673 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
674 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
675 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
677 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
678 static const shapeTest_char t2_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{3,{0,0}}};
679 static const shapeTest_glyph t2_g[] = {
680 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
681 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
682 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
683 {0,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
685 /* Hebrew */
686 static const WCHAR test_hebrew[] = {0x05e9, 0x05dc, 0x05d5, 0x05dd,0};
687 static const shapeTest_char hebrew_c[] = {{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
688 static const shapeTest_glyph hebrew_g[] = {
689 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
690 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
691 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
692 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}} };
694 /* Arabic */
695 static const WCHAR test_arabic[] = {0x0633,0x0644,0x0627,0x0645,0};
696 static const shapeTest_char arabic_c[] = {{2,{0,0}},{1,{0,0}},{1,{0,0}},{0,{0,0}}};
697 static const shapeTest_glyph arabic_g[] = {
698 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
699 {1,{{SCRIPT_JUSTIFY_ARABIC_NORMAL,1,0,0,0,0},0}},
700 {1,{{SCRIPT_JUSTIFY_ARABIC_SEEN,1,0,0,0,0},0}} };
702 /* Thai */
703 static const WCHAR test_thai[] = {0x0e2a, 0x0e04, 0x0e23, 0x0e34, 0x0e1b, 0x0e15, 0x0e4c, 0x0e44, 0x0e17, 0x0e22,};
704 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}}};
705 static const shapeTest_glyph thai_g[] = {
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_NONE,1,0,0,0,0},0}},
709 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
710 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
711 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
712 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
713 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
714 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
715 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}}};
717 /* Syriac */
718 static const WCHAR test_syriac[] = {0x0710, 0x0710, 0x0710, 0x0728, 0x0718, 0x0723,0};
719 static const shapeTest_char syriac_c[] = {{5,{0,0}},{4,{0,0}},{3,{0,0}},{2,{0,0}},{1,{0,0}},{0,{0,0}}};
720 static const shapeTest_glyph syriac_g[] = {
721 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
722 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
723 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
724 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
725 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
726 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
728 /* Thaana */
729 static const WCHAR test_thaana[] = {0x078a, 0x07ae, 0x0792, 0x07b0, 0x0020, 0x0796, 0x07aa, 0x0789, 0x07b0, 0x0795, 0x07ac, 0x0791, 0x07b0};
730 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}}};
731 static const shapeTest_glyph thaana_g[] = {
732 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
733 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
734 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
735 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
736 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
737 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
738 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
739 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
740 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
741 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
742 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
743 {1,{{SCRIPT_JUSTIFY_NONE,0,1,1,0,0},0}},
744 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
746 /* Phags-pa */
747 static const WCHAR test_phagspa[] = {0xa84f, 0xa861, 0xa843, 0x0020, 0xa863, 0xa861, 0xa859, 0x0020, 0xa850, 0xa85c, 0xa85e};
748 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}}};
749 static const shapeTest_glyph phagspa_g[] = {
750 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
751 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
752 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
753 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
754 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
755 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
756 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
757 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
758 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
759 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
760 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
762 /* Lao */
763 static const WCHAR test_lao[] = {0x0ead, 0x0eb1, 0x0e81, 0x0eaa, 0x0ead, 0x0e99, 0x0ea5, 0x0eb2, 0x0ea7, 0};
764 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}}};
765 static const shapeTest_glyph lao_g[] = {
766 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
767 {1,{{SCRIPT_JUSTIFY_CHARACTER,0,1,1,0,0},0}},
768 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
769 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
770 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
771 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
772 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
773 {1,{{SCRIPT_JUSTIFY_CHARACTER,1,0,0,0,0},0}},
774 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
776 /* Tibetan */
777 static const WCHAR test_tibetan[] = {0x0f04, 0x0f05, 0x0f0e, 0x0020, 0x0f51, 0x0f7c, 0x0f53, 0x0f0b, 0x0f5a, 0x0f53, 0x0f0b, 0x0f51, 0x0f44, 0x0f0b, 0x0f54, 0x0f7c, 0x0f0d};
778 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}}};
779 static const shapeTest_glyph tibetan_g[] = {
780 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
781 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
782 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
783 {1,{{SCRIPT_JUSTIFY_BLANK,1,0,0,0,0},0}},
784 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
785 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
786 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
787 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
788 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
789 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
790 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
791 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
792 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
793 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
794 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
795 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
796 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
798 /* Devanagari */
799 static const WCHAR test_devanagari[] = {0x0926, 0x0947, 0x0935, 0x0928, 0x093e, 0x0917, 0x0930, 0x0940};
800 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}}};
801 static const shapeTest_glyph devanagari_g[] = {
802 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
803 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
804 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
805 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
806 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
807 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
808 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
809 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
811 /* Bengali */
812 static const WCHAR test_bengali[] = {0x09ac, 0x09be, 0x0982, 0x09b2, 0x09be};
813 static const shapeTest_char bengali_c[] = {{0,{0,0}},{0,{0,0}},{0,{0,0}},{3,{0,0}},{3,{0,0}}};
814 static const shapeTest_glyph bengali_g[] = {
815 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
816 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
817 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
818 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
819 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
821 /* Gurmukhi */
822 static const WCHAR test_gurmukhi[] = {0x0a17, 0x0a41, 0x0a30, 0x0a2e, 0x0a41, 0x0a16, 0x0a40};
823 static const shapeTest_char gurmukhi_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
824 static const shapeTest_glyph gurmukhi_g[] = {
825 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
826 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
827 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
828 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
829 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
830 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
831 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
833 /* Gujarati */
834 static const WCHAR test_gujarati[] = {0x0a97, 0x0ac1, 0x0a9c, 0x0ab0, 0x0abe, 0x0aa4, 0x0ac0};
835 static const shapeTest_char gujarati_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{3,{0,0}},{3,{0,0}},{5,{0,0}},{5,{0,0}}};
836 static const shapeTest_glyph gujarati_g[] = {
837 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
838 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
839 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
840 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
841 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
842 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
843 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
845 /* Oriya */
846 static const WCHAR test_oriya[] = {0x0b13, 0x0b21, 0x0b3c, 0x0b3f, 0x0b06};
847 static const shapeTest_char oriya_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
848 static const shapeTest_glyph oriya_g[] = {
849 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
850 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
851 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
852 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
854 /* Tamil */
855 static const WCHAR test_tamil[] = {0x0ba4, 0x0bae, 0x0bbf, 0x0bb4, 0x0bcd};
856 static const shapeTest_char tamil_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}},{3,{0,0}}};
857 static const shapeTest_glyph tamil_g[] = {
858 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
859 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
860 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
861 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}} };
863 /* Telugu */
864 static const WCHAR test_telugu[] = {0x0c24, 0x0c46, 0x0c32, 0x0c41, 0x0c17, 0x0c41};
865 static const shapeTest_char telugu_c[] = {{0,{0,0}},{0,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
866 static const shapeTest_glyph telugu_g[] = {
867 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
868 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
869 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
870 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
871 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
872 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
874 /* Malayalam */
875 static const WCHAR test_malayalam[] = {0x0d2e, 0x0d32, 0x0d2f, 0x0d3e, 0x0d33, 0x0d02};
876 static const shapeTest_char malayalam_c[] = {{0,{0,0}},{1,{0,0}},{2,{0,0}},{2,{0,0}},{4,{0,0}},{4,{0,0}}};
877 static const shapeTest_glyph malayalam_g[] = {
878 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
879 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
880 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
881 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
882 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
883 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
885 /* Kannada */
886 static const WCHAR test_kannada[] = {0x0c95, 0x0ca8, 0x0ccd, 0x0ca8, 0x0ca1};
887 static const shapeTest_char kannada_c[] = {{0,{0,0}},{1,{0,0}},{1,{0,0}},{1,{0,0}},{3,{0,0}}};
888 static const shapeTest_glyph kannada_g[] = {
889 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
890 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
891 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}},
892 {1,{{SCRIPT_JUSTIFY_NONE,1,0,0,0,0},0}},
893 {1,{{SCRIPT_JUSTIFY_NONE,0,0,0,0,0},0}} };
895 if (!pScriptItemizeOpenType || !pScriptShapeOpenType)
897 win_skip("ScriptShapeOpenType not available on this platform\n");
898 return;
901 memset(&Control, 0 , sizeof(Control));
902 memset(&State, 0 , sizeof(State));
904 hr = pScriptItemizeOpenType(test1, 4, 2, &Control, &State, items, tags, &outnItems);
905 ok(!hr, "ScriptItemizeOpenType should return S_OK not %08x\n", hr);
906 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
908 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, NULL, &nb);
909 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
911 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, NULL);
912 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
914 hr = pScriptShapeOpenType(NULL, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
915 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_PENDING not %08x\n", hr);
917 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, NULL, NULL, glyphs, glyphProp, &nb);
918 ok( hr == E_INVALIDARG,
919 "ScriptShapeOpenType should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
920 hr = pScriptShapeOpenType(hdc, &sc, &items[0].a, tags[0], 0x00000000, NULL, NULL, 0, test1, 4, 4, logclust, NULL, glyphs, glyphProp, &nb);
921 ok(hr == E_INVALIDARG, "ScriptShapeOpenType should return E_INVALIDARG not %08x\n", hr);
923 ScriptFreeCache(&sc);
925 test_shape_ok(hdc, test1, 4, &Control, &State, 0, 4, t1_c, t1_g);
926 test_shape_ok(hdc, test2, 4, &Control, &State, 1, 4, t2_c, t2_g);
928 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 11, test_hebrew[0], &hfont, &hfont_orig);
929 if (hfont != NULL)
931 test_shape_ok_valid(test_valid, hdc, test_hebrew, 4, &Control, &State, 0, 4, hebrew_c, hebrew_g);
932 SelectObject(hdc, hfont_orig);
933 DeleteObject(hfont);
936 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 13, test_arabic[0], &hfont, &hfont_orig);
937 if (hfont != NULL)
939 test_shape_ok_valid(test_valid, hdc, test_arabic, 4, &Control, &State, 0, 3, arabic_c, arabic_g);
940 SelectObject(hdc, hfont_orig);
941 DeleteObject(hfont);
944 test_valid = find_font_for_range(hdc, "Microsoft Sans Serif", 24, test_thai[0], &hfont, &hfont_orig);
945 if (hfont != NULL)
947 test_shape_ok_valid(test_valid, hdc, test_thai, 10, &Control, &State, 0, 10, thai_c, thai_g);
948 SelectObject(hdc, hfont_orig);
949 DeleteObject(hfont);
952 test_valid = find_font_for_range(hdc, "Estrangelo Edessa", 71, test_syriac[0], &hfont, &hfont_orig);
953 if (hfont != NULL)
955 test_shape_ok_valid(test_valid, hdc, test_syriac, 6, &Control, &State, 0, 6, syriac_c, syriac_g);
956 SelectObject(hdc, hfont_orig);
957 DeleteObject(hfont);
960 test_valid = find_font_for_range(hdc, "MV Boli", 72, test_thaana[0], &hfont, &hfont_orig);
961 if (hfont != NULL)
963 test_shape_ok_valid(test_valid, hdc, test_thaana, 13, &Control, &State, 0, 13, thaana_c, thaana_g);
964 SelectObject(hdc, hfont_orig);
965 DeleteObject(hfont);
968 test_valid = find_font_for_range(hdc, "Microsoft PhagsPa", 53, test_phagspa[0], &hfont, &hfont_orig);
969 if (hfont != NULL)
971 test_shape_ok_valid(test_valid, hdc, test_phagspa, 11, &Control, &State, 0, 11, phagspa_c, phagspa_g);
972 SelectObject(hdc, hfont_orig);
973 DeleteObject(hfont);
976 test_valid = find_font_for_range(hdc, "DokChampa", 25, test_lao[0], &hfont, &hfont_orig);
977 if (hfont != NULL)
979 test_shape_ok_valid(test_valid, hdc, test_lao, 9, &Control, &State, 0, 9, lao_c, lao_g);
980 SelectObject(hdc, hfont_orig);
981 DeleteObject(hfont);
984 test_valid = find_font_for_range(hdc, "Microsoft Himalaya", 70, test_tibetan[0], &hfont, &hfont_orig);
985 if (hfont != NULL)
987 test_shape_ok_valid(test_valid, hdc, test_tibetan, 17, &Control, &State, 0, 17, tibetan_c, tibetan_g);
988 SelectObject(hdc, hfont_orig);
989 DeleteObject(hfont);
992 test_valid = find_font_for_range(hdc, "Mangal", 15, test_devanagari[0], &hfont, &hfont_orig);
993 if (hfont != NULL)
995 test_shape_ok_valid(test_valid, hdc, test_devanagari, 8, &Control, &State, 0, 8, devanagari_c, devanagari_g);
996 SelectObject(hdc, hfont_orig);
997 DeleteObject(hfont);
1000 test_valid = find_font_for_range(hdc, "Vrinda", 16, test_bengali[0], &hfont, &hfont_orig);
1001 if (hfont != NULL)
1003 test_shape_ok_valid(test_valid, hdc, test_bengali, 5, &Control, &State, 0, 5, bengali_c, bengali_g);
1004 SelectObject(hdc, hfont_orig);
1005 DeleteObject(hfont);
1008 test_valid = find_font_for_range(hdc, "Raavi", 17, test_gurmukhi[0], &hfont, &hfont_orig);
1009 if (hfont != NULL)
1011 test_shape_ok_valid(test_valid, hdc, test_gurmukhi, 7, &Control, &State, 0, 7, gurmukhi_c, gurmukhi_g);
1012 SelectObject(hdc, hfont_orig);
1013 DeleteObject(hfont);
1016 test_valid = find_font_for_range(hdc, "Shruti", 18, test_gujarati[0], &hfont, &hfont_orig);
1017 if (hfont != NULL)
1019 test_shape_ok_valid(test_valid, hdc, test_gujarati, 7, &Control, &State, 0, 7, gujarati_c, gujarati_g);
1020 SelectObject(hdc, hfont_orig);
1021 DeleteObject(hfont);
1024 test_valid = find_font_for_range(hdc, "Kalinga", 19, test_oriya[0], &hfont, &hfont_orig);
1025 if (hfont != NULL)
1027 test_shape_ok_valid(test_valid, hdc, test_oriya, 5, &Control, &State, 0, 4, oriya_c, oriya_g);
1028 SelectObject(hdc, hfont_orig);
1029 DeleteObject(hfont);
1032 test_valid = find_font_for_range(hdc, "Latha", 20, test_tamil[0], &hfont, &hfont_orig);
1033 if (hfont != NULL)
1035 test_shape_ok_valid(test_valid, hdc, test_tamil, 5, &Control, &State, 0, 4, tamil_c, tamil_g);
1036 SelectObject(hdc, hfont_orig);
1037 DeleteObject(hfont);
1040 test_valid = find_font_for_range(hdc, "Gautami", 21, test_telugu[0], &hfont, &hfont_orig);
1041 if (hfont != NULL)
1043 test_shape_ok_valid(test_valid, hdc, test_telugu, 6, &Control, &State, 0, 6, telugu_c, telugu_g);
1044 SelectObject(hdc, hfont_orig);
1045 DeleteObject(hfont);
1048 test_valid = find_font_for_range(hdc, "Kartika", 23, test_malayalam[0], &hfont, &hfont_orig);
1049 if (hfont != NULL)
1051 test_shape_ok_valid(test_valid, hdc, test_malayalam, 6, &Control, &State, 0, 6, malayalam_c, malayalam_g);
1052 SelectObject(hdc, hfont_orig);
1053 DeleteObject(hfont);
1056 test_valid = find_font_for_range(hdc, "Tunga", 22, test_kannada[0], &hfont, &hfont_orig);
1057 if (hfont != NULL)
1059 test_shape_ok_valid(test_valid, hdc, test_kannada, 5, &Control, &State, 0, 4, kannada_c, kannada_g);
1060 SelectObject(hdc, hfont_orig);
1061 DeleteObject(hfont);
1065 static void test_ScriptShape(HDC hdc)
1067 static const WCHAR test1[] = {'w', 'i', 'n', 'e',0};
1068 static const WCHAR test2[] = {0x202B, 'i', 'n', 0x202C,0};
1069 HRESULT hr;
1070 SCRIPT_CACHE sc = NULL;
1071 WORD glyphs[4], glyphs2[4], logclust[4];
1072 SCRIPT_VISATTR attrs[4];
1073 SCRIPT_ITEM items[2];
1074 int nb;
1076 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1077 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1078 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1080 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, NULL, &nb);
1081 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1083 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, NULL);
1084 ok(hr == E_INVALIDARG, "ScriptShape should return E_INVALIDARG not %08x\n", hr);
1086 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1087 ok(hr == E_PENDING, "ScriptShape should return E_PENDING not %08x\n", hr);
1089 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, NULL, attrs, &nb);
1090 ok(broken(hr == S_OK) ||
1091 hr == E_INVALIDARG || /* Vista, W2K8 */
1092 hr == E_FAIL, /* WIN7 */
1093 "ScriptShape should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1094 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1096 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1097 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1098 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1101 memset(glyphs,-1,sizeof(glyphs));
1102 memset(logclust,-1,sizeof(logclust));
1103 memset(attrs,-1,sizeof(attrs));
1104 hr = ScriptShape(NULL, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1105 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1106 ok(nb == 4, "Wrong number of items\n");
1107 ok(logclust[0] == 0, "clusters out of order\n");
1108 ok(logclust[1] == 1, "clusters out of order\n");
1109 ok(logclust[2] == 2, "clusters out of order\n");
1110 ok(logclust[3] == 3, "clusters out of order\n");
1111 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1112 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1113 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1114 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1115 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1116 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1117 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1118 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1119 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1120 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1121 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1122 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1123 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1124 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1125 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1126 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1128 ScriptFreeCache(&sc);
1129 sc = NULL;
1131 memset(glyphs2,-1,sizeof(glyphs2));
1132 memset(logclust,-1,sizeof(logclust));
1133 memset(attrs,-1,sizeof(attrs));
1134 hr = ScriptShape(hdc, &sc, test2, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1135 ok(hr == S_OK, "ScriptShape should return S_OK not %08x\n", hr);
1136 ok(nb == 4, "Wrong number of items\n");
1137 ok(glyphs2[0] == 0 || broken(glyphs2[0] == 0x80), "Incorrect glyph for 0x202B\n");
1138 ok(glyphs2[3] == 0 || broken(glyphs2[3] == 0x80), "Incorrect glyph for 0x202C\n");
1139 ok(logclust[0] == 0, "clusters out of order\n");
1140 ok(logclust[1] == 1, "clusters out of order\n");
1141 ok(logclust[2] == 2, "clusters out of order\n");
1142 ok(logclust[3] == 3, "clusters out of order\n");
1143 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1144 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1145 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1146 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1147 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1148 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1149 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1150 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1151 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1152 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1153 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1154 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1155 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1156 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1157 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1158 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1160 /* modify LTR to RTL */
1161 items[0].a.fRTL = 1;
1162 memset(glyphs2,-1,sizeof(glyphs2));
1163 memset(logclust,-1,sizeof(logclust));
1164 memset(attrs,-1,sizeof(attrs));
1165 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs2, logclust, attrs, &nb);
1166 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1167 ok(nb == 4, "Wrong number of items\n");
1168 ok(glyphs2[0] == glyphs[3], "Glyphs not reordered properly\n");
1169 ok(glyphs2[1] == glyphs[2], "Glyphs not reordered properly\n");
1170 ok(glyphs2[2] == glyphs[1], "Glyphs not reordered properly\n");
1171 ok(glyphs2[3] == glyphs[0], "Glyphs not reordered properly\n");
1172 ok(logclust[0] == 3, "clusters out of order\n");
1173 ok(logclust[1] == 2, "clusters out of order\n");
1174 ok(logclust[2] == 1, "clusters out of order\n");
1175 ok(logclust[3] == 0, "clusters out of order\n");
1176 ok(attrs[0].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1177 ok(attrs[1].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1178 ok(attrs[2].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1179 ok(attrs[3].uJustification == SCRIPT_JUSTIFY_CHARACTER, "uJustification incorrect\n");
1180 ok(attrs[0].fClusterStart == 1, "fClusterStart incorrect\n");
1181 ok(attrs[1].fClusterStart == 1, "fClusterStart incorrect\n");
1182 ok(attrs[2].fClusterStart == 1, "fClusterStart incorrect\n");
1183 ok(attrs[3].fClusterStart == 1, "fClusterStart incorrect\n");
1184 ok(attrs[0].fDiacritic == 0, "fDiacritic incorrect\n");
1185 ok(attrs[1].fDiacritic == 0, "fDiacritic incorrect\n");
1186 ok(attrs[2].fDiacritic == 0, "fDiacritic incorrect\n");
1187 ok(attrs[3].fDiacritic == 0, "fDiacritic incorrect\n");
1188 ok(attrs[0].fZeroWidth == 0, "fZeroWidth incorrect\n");
1189 ok(attrs[1].fZeroWidth == 0, "fZeroWidth incorrect\n");
1190 ok(attrs[2].fZeroWidth == 0, "fZeroWidth incorrect\n");
1191 ok(attrs[3].fZeroWidth == 0, "fZeroWidth incorrect\n");
1193 ScriptFreeCache(&sc);
1196 static void test_ScriptPlace(HDC hdc)
1198 static const WCHAR test1[] = {'t', 'e', 's', 't',0};
1199 BOOL ret;
1200 HRESULT hr;
1201 SCRIPT_CACHE sc = NULL;
1202 WORD glyphs[4], logclust[4];
1203 SCRIPT_VISATTR attrs[4];
1204 SCRIPT_ITEM items[2];
1205 int nb, widths[4];
1206 GOFFSET offset[4];
1207 ABC abc[4];
1209 hr = ScriptItemize(test1, 4, 2, NULL, NULL, items, NULL);
1210 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
1211 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1213 hr = ScriptShape(hdc, &sc, test1, 4, 4, &items[0].a, glyphs, logclust, attrs, &nb);
1214 ok(!hr, "ScriptShape should return S_OK not %08x\n", hr);
1215 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1217 hr = ScriptPlace(hdc, &sc, glyphs, 4, NULL, &items[0].a, widths, NULL, NULL);
1218 ok(hr == E_INVALIDARG, "ScriptPlace should return E_INVALIDARG not %08x\n", hr);
1220 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, NULL);
1221 ok(broken(hr == E_PENDING) ||
1222 hr == E_INVALIDARG || /* Vista, W2K8 */
1223 hr == E_FAIL, /* WIN7 */
1224 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1226 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1227 ok(hr == E_PENDING, "ScriptPlace should return E_PENDING not %08x\n", hr);
1229 hr = ScriptPlace(NULL, &sc, glyphs, 4, attrs, &items[0].a, widths, NULL, abc);
1230 ok(broken(hr == E_PENDING) ||
1231 hr == E_INVALIDARG || /* Vista, W2K8 */
1232 hr == E_FAIL, /* WIN7 */
1233 "ScriptPlace should return E_FAIL or E_INVALIDARG, not %08x\n", hr);
1235 hr = ScriptPlace(hdc, &sc, glyphs, 4, attrs, &items[0].a, widths, offset, NULL);
1236 ok(!hr, "ScriptPlace should return S_OK not %08x\n", hr);
1237 ok(items[0].a.fNoGlyphIndex == FALSE, "fNoGlyphIndex TRUE\n");
1239 ret = ExtTextOutW(hdc, 1, 1, 0, NULL, glyphs, 4, widths);
1240 ok(ret, "ExtTextOutW should return TRUE\n");
1242 ScriptFreeCache(&sc);
1245 static void test_ScriptItemIzeShapePlace(HDC hdc, unsigned short pwOutGlyphs[256])
1247 HRESULT hr;
1248 int iMaxProps;
1249 const SCRIPT_PROPERTIES **ppSp;
1251 int cInChars;
1252 int cMaxItems;
1253 SCRIPT_ITEM pItem[255];
1254 int pcItems;
1255 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1256 WCHAR TestItem2[] = {'T', 'e', 's', 't', 'b', 0};
1257 WCHAR TestItem3[] = {'T', 'e', 's', 't', 'c',' ','1','2','3',' ',' ','e','n','d',0};
1258 WCHAR TestItem4[] = {'T', 'e', 's', 't', 'd',' ',0x0684,0x0694,0x06a4,' ',' ','\r','\n','e','n','d',0};
1259 WCHAR TestItem5[] = {0x0684,'T','e','s','t','e',' ',0x0684,0x0694,0x06a4,' ',' ','e','n','d',0};
1260 WCHAR TestItem6[] = {'T', 'e', 's', 't', 'f',' ',' ',' ','\r','\n','e','n','d',0};
1262 SCRIPT_CACHE psc;
1263 int cChars;
1264 int cMaxGlyphs;
1265 unsigned short pwOutGlyphs1[256];
1266 unsigned short pwOutGlyphs2[256];
1267 unsigned short pwLogClust[256];
1268 SCRIPT_VISATTR psva[256];
1269 int pcGlyphs;
1270 int piAdvance[256];
1271 GOFFSET pGoffset[256];
1272 ABC pABC[256];
1273 int cnt;
1275 /* Start testing usp10 functions */
1276 /* This test determines that the pointer returned by ScriptGetProperties is valid
1277 * by checking a known value in the table */
1278 hr = ScriptGetProperties(&ppSp, &iMaxProps);
1279 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
1280 trace("number of script properties %d\n", iMaxProps);
1281 ok (iMaxProps > 0, "Number of scripts returned should not be 0\n");
1282 if (iMaxProps > 0)
1283 ok( ppSp[0]->langid == 0, "Langid[0] not = to 0\n"); /* Check a known value to ensure */
1284 /* ptrs work */
1286 /* This is a valid test that will cause parsing to take place */
1287 cInChars = 5;
1288 cMaxItems = 255;
1289 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1290 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1291 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1292 * returned. */
1293 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1294 if (pcItems > 0)
1295 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1296 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1297 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1299 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1300 * ie. ScriptItemize has succeeded and that pItem has been set */
1301 cInChars = 5;
1302 if (hr == 0) {
1303 psc = NULL; /* must be null on first call */
1304 cChars = cInChars;
1305 cMaxGlyphs = cInChars;
1306 hr = ScriptShape(NULL, &psc, TestItem1, cChars,
1307 cMaxGlyphs, &pItem[0].a,
1308 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1309 ok (hr == E_PENDING, "If psc is NULL (%08x) the E_PENDING should be returned\n", hr);
1310 cMaxGlyphs = 4;
1311 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1312 cMaxGlyphs, &pItem[0].a,
1313 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1314 ok (hr == E_OUTOFMEMORY, "If not enough output area cChars (%d) is > than CMaxGlyphs "
1315 "(%d) but not E_OUTOFMEMORY\n",
1316 cChars, cMaxGlyphs);
1317 cMaxGlyphs = 256;
1318 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1319 cMaxGlyphs, &pItem[0].a,
1320 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1321 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1322 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1323 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1324 if (hr ==0) {
1325 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1326 pGoffset, pABC);
1327 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1328 hr = ScriptPlace(NULL, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1329 pGoffset, pABC);
1330 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1331 for (cnt=0; cnt < pcGlyphs; cnt++)
1332 pwOutGlyphs[cnt] = pwOutGlyphs1[cnt]; /* Send to next function */
1335 /* This test will check to make sure that SCRIPT_CACHE is reused and that not translation *
1336 * takes place if fNoGlyphIndex is set. */
1338 cInChars = 5;
1339 cMaxItems = 255;
1340 hr = ScriptItemize(TestItem2, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1341 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1342 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1343 * returned. */
1344 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1345 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1346 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1347 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue */
1348 if (hr == 0) {
1349 cChars = cInChars;
1350 cMaxGlyphs = 256;
1351 pItem[0].a.fNoGlyphIndex = 1; /* say no translate */
1352 hr = ScriptShape(NULL, &psc, TestItem2, cChars,
1353 cMaxGlyphs, &pItem[0].a,
1354 pwOutGlyphs2, pwLogClust, psva, &pcGlyphs);
1355 ok (hr != E_PENDING, "If psc should not be NULL (%08x) and the E_PENDING should be returned\n", hr);
1356 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1357 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1358 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1359 for (cnt=0; cnt < cChars && TestItem2[cnt] == pwOutGlyphs2[cnt]; cnt++) {}
1360 ok (cnt == cChars, "Translation to place when told not to. WCHAR %d - %04x != %04x\n",
1361 cnt, TestItem2[cnt], pwOutGlyphs2[cnt]);
1362 if (hr ==0) {
1363 hr = ScriptPlace(hdc, &psc, pwOutGlyphs2, pcGlyphs, psva, &pItem[0].a, piAdvance,
1364 pGoffset, pABC);
1365 ok (hr == 0, "ScriptPlace should return 0 not (%08x)\n", hr);
1368 ScriptFreeCache( &psc);
1369 ok (!psc, "psc is not null after ScriptFreeCache\n");
1373 /* This is a valid test that will cause parsing to take place and create 3 script_items */
1374 cInChars = (sizeof(TestItem3)/2)-1;
1375 cMaxItems = 255;
1376 hr = ScriptItemize(TestItem3, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1377 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1378 if (hr == 0)
1380 ok (pcItems == 3, "The number of SCRIPT_ITEMS should be 3 not %d\n", pcItems);
1381 if (pcItems > 2)
1383 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1384 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1385 pItem[0].iCharPos, pItem[1].iCharPos);
1386 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1387 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1388 pItem[1].iCharPos, pItem[2].iCharPos);
1389 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == cInChars,
1390 "Start pos [2] not = 11 (%d) or end [3] pos not = 14 (%d), cInChars = %d\n",
1391 pItem[2].iCharPos, pItem[3].iCharPos, cInChars);
1395 /* This is a valid test that will cause parsing to take place and create 5 script_items */
1396 cInChars = (sizeof(TestItem4)/2)-1;
1397 cMaxItems = 255;
1398 hr = ScriptItemize(TestItem4, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1399 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1400 if (hr == 0)
1402 ok (pcItems == 5, "The number of SCRIPT_ITEMS should be 5 not %d\n", pcItems);
1403 if (pcItems > 4)
1405 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == 6,
1406 "Start pos [0] not = 0 (%d) or end pos [1] not = %d\n",
1407 pItem[0].iCharPos, pItem[1].iCharPos);
1408 ok (pItem[0].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1409 pItem[0].a.s.uBidiLevel);
1410 ok (pItem[1].iCharPos == 6 && pItem[2].iCharPos == 11,
1411 "Start pos [1] not = 6 (%d) or end pos [2] not = 11 (%d)\n",
1412 pItem[1].iCharPos, pItem[2].iCharPos);
1413 ok (pItem[1].a.s.uBidiLevel == 1, "Should have been bidi=1 not %d\n",
1414 pItem[1].a.s.uBidiLevel);
1415 ok (pItem[2].iCharPos == 11 && pItem[3].iCharPos == 12,
1416 "Start pos [2] not = 11 (%d) or end [3] pos not = 12 (%d)\n",
1417 pItem[2].iCharPos, pItem[3].iCharPos);
1418 ok (pItem[2].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1419 pItem[2].a.s.uBidiLevel);
1420 ok (pItem[3].iCharPos == 12 && pItem[4].iCharPos == 13,
1421 "Start pos [3] not = 12 (%d) or end [4] pos not = 13 (%d)\n",
1422 pItem[3].iCharPos, pItem[4].iCharPos);
1423 ok (pItem[3].a.s.uBidiLevel == 0, "Should have been bidi=0 not %d\n",
1424 pItem[3].a.s.uBidiLevel);
1425 ok (pItem[4].iCharPos == 13 && pItem[5].iCharPos == cInChars,
1426 "Start pos [4] not = 13 (%d) or end [5] pos not = 16 (%d), cInChars = %d\n",
1427 pItem[4].iCharPos, pItem[5].iCharPos, cInChars);
1432 * This test is for when the first unicode character requires bidi support
1434 cInChars = (sizeof(TestItem5)-1)/sizeof(WCHAR);
1435 hr = ScriptItemize(TestItem5, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1436 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1437 ok (pcItems == 4, "There should have been 4 items, found %d\n", pcItems);
1438 ok (pItem[0].a.s.uBidiLevel == 1, "The first character should have been bidi=1 not %d\n",
1439 pItem[0].a.s.uBidiLevel);
1441 /* This test checks to make sure that the test to see if there are sufficient buffers to store *
1442 * the pointer to the last char works. Note that windows often needs a greater number of *
1443 * SCRIPT_ITEMS to process a string than is returned in pcItems. */
1444 cInChars = (sizeof(TestItem6)/2)-1;
1445 cMaxItems = 4;
1446 hr = ScriptItemize(TestItem6, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1447 ok (hr == E_OUTOFMEMORY, "ScriptItemize should return E_OUTOFMEMORY, returned %08x\n", hr);
1451 static void test_ScriptGetCMap(HDC hdc, unsigned short pwOutGlyphs[256])
1453 HRESULT hr;
1454 SCRIPT_CACHE psc = NULL;
1455 int cInChars;
1456 int cChars;
1457 unsigned short pwOutGlyphs2[256];
1458 unsigned short pwOutGlyphs3[256];
1459 DWORD dwFlags;
1460 int cnt;
1462 static const WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1463 static const WCHAR TestItem2[] = {0x202B, 'i', 'n', 0x202C,0};
1464 static const WCHAR TestItem3[] = {'a','b','c','d','(','<','{','[',0x2039,0};
1465 static const WCHAR TestItem3b[] = {'a','b','c','d',')','>','}',']',0x203A,0};
1467 /* Check to make sure that SCRIPT_CACHE gets allocated ok */
1468 dwFlags = 0;
1469 cInChars = cChars = 5;
1470 /* Some sanity checks for ScriptGetCMap */
1472 hr = ScriptGetCMap(NULL, NULL, NULL, 0, 0, NULL);
1473 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL,0,0,NULL), "
1474 "expected E_INVALIDARG, got %08x\n", hr);
1476 hr = ScriptGetCMap(NULL, NULL, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1477 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1478 "expected E_INVALIDARG, got %08x\n", hr);
1480 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1481 psc = NULL;
1482 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1483 ok( hr == E_PENDING, "(NULL,&psc,NULL,0,0,NULL), expected E_PENDING, "
1484 "got %08x\n", hr);
1485 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1487 /* Set psc to NULL but add hdc, to be able to check if a pointer is returned in psc */
1488 psc = NULL;
1489 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, 0, pwOutGlyphs3);
1490 ok( hr == S_OK, "ScriptGetCMap(NULL,&psc,NULL,0,0,NULL), expected S_OK, "
1491 "got %08x\n", hr);
1492 ok( psc != NULL, "ScritpGetCMap expected psc to be not NULL\n");
1493 ScriptFreeCache( &psc);
1495 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1496 psc = NULL;
1497 hr = ScriptGetCMap(NULL, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1498 ok( hr == E_PENDING, "(NULL,&psc,), expected E_PENDING, got %08x\n", hr);
1499 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1500 /* Check to see if the results are the same as those returned by ScriptShape */
1501 hr = ScriptGetCMap(hdc, &psc, TestItem1, cInChars, dwFlags, pwOutGlyphs3);
1502 ok (hr == 0, "ScriptGetCMap should return 0 not (%08x)\n", hr);
1503 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1504 for (cnt=0; cnt < cChars && pwOutGlyphs[cnt] == pwOutGlyphs3[cnt]; cnt++) {}
1505 ok (cnt == cInChars, "Translation not correct. WCHAR %d - %04x != %04x\n",
1506 cnt, pwOutGlyphs[cnt], pwOutGlyphs3[cnt]);
1508 ScriptFreeCache( &psc);
1509 ok (!psc, "psc is not null after ScriptFreeCache\n");
1511 cInChars = cChars = 4;
1512 hr = ScriptGetCMap(hdc, &psc, TestItem2, cInChars, dwFlags, pwOutGlyphs3);
1513 ok (hr == S_FALSE, "ScriptGetCMap should return S_FALSE not (%08x)\n", hr);
1514 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1515 ok(pwOutGlyphs3[0] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1516 ok(pwOutGlyphs3[3] == 0 || broken(pwOutGlyphs3[0] == 0x80), "Glyph 0 should be default glyph\n");
1519 cInChars = cChars = 9;
1520 hr = ScriptGetCMap(hdc, &psc, TestItem3b, cInChars, dwFlags, pwOutGlyphs2);
1521 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1522 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1524 cInChars = cChars = 9;
1525 dwFlags = SGCM_RTL;
1526 hr = ScriptGetCMap(hdc, &psc, TestItem3, cInChars, dwFlags, pwOutGlyphs3);
1527 ok (hr == S_OK, "ScriptGetCMap should return S_OK not (%08x)\n", hr);
1528 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1529 ok(pwOutGlyphs3[0] == pwOutGlyphs2[0], "glyph incorrectly altered\n");
1530 ok(pwOutGlyphs3[1] == pwOutGlyphs2[1], "glyph incorreclty altered\n");
1531 ok(pwOutGlyphs3[2] == pwOutGlyphs2[2], "glyph incorreclty altered\n");
1532 ok(pwOutGlyphs3[3] == pwOutGlyphs2[3], "glyph incorreclty altered\n");
1533 ok(pwOutGlyphs3[4] == pwOutGlyphs2[4], "glyph not mirrored correctly\n");
1534 ok(pwOutGlyphs3[5] == pwOutGlyphs2[5], "glyph not mirrored correctly\n");
1535 ok(pwOutGlyphs3[6] == pwOutGlyphs2[6], "glyph not mirrored correctly\n");
1536 ok(pwOutGlyphs3[7] == pwOutGlyphs2[7], "glyph not mirrored correctly\n");
1537 ok(pwOutGlyphs3[8] == pwOutGlyphs2[8], "glyph not mirrored correctly\n");
1539 ScriptFreeCache( &psc);
1540 ok (!psc, "psc is not null after ScriptFreeCache\n");
1543 static void test_ScriptGetFontProperties(HDC hdc)
1545 HRESULT hr;
1546 SCRIPT_CACHE psc,old_psc;
1547 SCRIPT_FONTPROPERTIES sfp;
1549 /* Some sanity checks for ScriptGetFontProperties */
1551 hr = ScriptGetFontProperties(NULL,NULL,NULL);
1552 ok( hr == E_INVALIDARG, "(NULL,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1554 hr = ScriptGetFontProperties(NULL,NULL,&sfp);
1555 ok( hr == E_INVALIDARG, "(NULL,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1557 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1558 psc = NULL;
1559 hr = ScriptGetFontProperties(NULL,&psc,NULL);
1560 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1561 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1563 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1564 psc = NULL;
1565 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1566 ok( hr == E_PENDING, "(NULL,&psc,&sfp), expected E_PENDING, got %08x\n", hr);
1567 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1569 hr = ScriptGetFontProperties(hdc,NULL,NULL);
1570 ok( hr == E_INVALIDARG, "(hdc,NULL,NULL), expected E_INVALIDARG, got %08x\n", hr);
1572 hr = ScriptGetFontProperties(hdc,NULL,&sfp);
1573 ok( hr == E_INVALIDARG, "(hdc,NULL,&sfp), expected E_INVALIDARG, got %08x\n", hr);
1575 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1576 psc = NULL;
1577 hr = ScriptGetFontProperties(hdc,&psc,NULL);
1578 ok( hr == E_INVALIDARG, "(hdc,&psc,NULL), expected E_INVALIDARG, got %08x\n", hr);
1579 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1581 /* Pass an invalid sfp */
1582 psc = NULL;
1583 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES) - 1;
1584 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1585 ok( hr == E_INVALIDARG, "(hdc,&psc,&sfp) invalid, expected E_INVALIDARG, got %08x\n", hr);
1586 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1587 ScriptFreeCache(&psc);
1588 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1590 /* Give it the correct cBytes, we don't care about what's coming back */
1591 sfp.cBytes = sizeof(SCRIPT_FONTPROPERTIES);
1592 psc = NULL;
1593 hr = ScriptGetFontProperties(hdc,&psc,&sfp);
1594 ok( hr == S_OK, "(hdc,&psc,&sfp) partly initialized, expected S_OK, got %08x\n", hr);
1595 ok( psc != NULL, "Expected a pointer in psc, got NULL\n");
1597 /* Save the psc pointer */
1598 old_psc = psc;
1599 /* Now a NULL hdc again */
1600 hr = ScriptGetFontProperties(NULL,&psc,&sfp);
1601 ok( hr == S_OK, "(NULL,&psc,&sfp), expected S_OK, got %08x\n", hr);
1602 ok( psc == old_psc, "Expected psc not to be changed, was %p is now %p\n", old_psc, psc);
1603 ScriptFreeCache(&psc);
1604 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1607 static void test_ScriptTextOut(HDC hdc)
1609 HRESULT hr;
1611 int cInChars;
1612 int cMaxItems;
1613 SCRIPT_ITEM pItem[255];
1614 int pcItems;
1615 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1617 SCRIPT_CACHE psc;
1618 int cChars;
1619 int cMaxGlyphs;
1620 unsigned short pwOutGlyphs1[256];
1621 WORD pwLogClust[256];
1622 SCRIPT_VISATTR psva[256];
1623 int pcGlyphs;
1624 int piAdvance[256];
1625 GOFFSET pGoffset[256];
1626 ABC pABC[256];
1627 RECT rect;
1628 int piX;
1629 int iCP = 1;
1630 BOOL fTrailing = FALSE;
1631 SCRIPT_LOGATTR *psla;
1632 SCRIPT_LOGATTR sla[256];
1634 /* This is a valid test that will cause parsing to take place */
1635 cInChars = 5;
1636 cMaxItems = 255;
1637 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1638 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1639 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1640 * returned. */
1641 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1642 if (pcItems > 0)
1643 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1644 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1645 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1647 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1648 * ie. ScriptItemize has succeeded and that pItem has been set */
1649 cInChars = 5;
1650 if (hr == 0) {
1651 psc = NULL; /* must be null on first call */
1652 cChars = cInChars;
1653 cMaxGlyphs = 256;
1654 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1655 cMaxGlyphs, &pItem[0].a,
1656 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1657 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1658 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1659 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1660 if (hr ==0) {
1661 /* Note hdc is needed as glyph info is not yet in psc */
1662 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1663 pGoffset, pABC);
1664 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1665 ScriptFreeCache(&psc); /* Get rid of psc for next test set */
1666 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1668 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
1669 ok (hr == E_INVALIDARG, "Should return 0 not (%08x)\n", hr);
1671 hr = ScriptTextOut(NULL, NULL, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1672 piAdvance, NULL, pGoffset);
1673 ok( hr == E_INVALIDARG, "(NULL,NULL,TestItem1, cInChars, dwFlags, pwOutGlyphs3), "
1674 "expected E_INVALIDARG, got %08x\n", hr);
1676 /* Set psc to NULL, to be able to check if a pointer is returned in psc */
1677 psc = NULL;
1678 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, NULL, NULL, 0, NULL, 0,
1679 NULL, NULL, NULL);
1680 ok( hr == E_INVALIDARG, "(NULL,&psc,NULL,0,0,0,NULL,), expected E_INVALIDARG, "
1681 "got %08x\n", hr);
1682 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1684 /* hdc is required for this one rather than the usual optional */
1685 psc = NULL;
1686 hr = ScriptTextOut(NULL, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1687 piAdvance, NULL, pGoffset);
1688 ok( hr == E_INVALIDARG, "(NULL,&psc,), expected E_INVALIDARG, got %08x\n", hr);
1689 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1691 /* Set that it returns 0 status */
1692 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1693 piAdvance, NULL, pGoffset);
1694 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1696 /* Test Rect Rgn is acceptable */
1697 rect.top = 10;
1698 rect.bottom = 20;
1699 rect.left = 10;
1700 rect.right = 40;
1701 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1702 piAdvance, NULL, pGoffset);
1703 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1705 iCP = 1;
1706 hr = ScriptCPtoX(iCP, fTrailing, cChars, pcGlyphs, (const WORD *) &pwLogClust,
1707 (const SCRIPT_VISATTR *) &psva, (const int *)&piAdvance, &pItem[0].a, &piX);
1708 ok(hr == S_OK, "ScriptCPtoX Stub should return S_OK not %08x\n", hr);
1710 psla = (SCRIPT_LOGATTR *)&sla;
1711 hr = ScriptBreak(TestItem1, cChars, &pItem[0].a, psla);
1712 ok(hr == S_OK, "ScriptBreak Stub should return S_OK not %08x\n", hr);
1714 /* Clean up and go */
1715 ScriptFreeCache(&psc);
1716 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1721 static void test_ScriptTextOut2(HDC hdc)
1723 /* Intent is to validate that the HDC passed into ScriptTextOut is
1724 * used instead of the (possibly) invalid cached one
1726 HRESULT hr;
1728 HDC hdc1, hdc2;
1729 int cInChars;
1730 int cMaxItems;
1731 SCRIPT_ITEM pItem[255];
1732 int pcItems;
1733 WCHAR TestItem1[] = {'T', 'e', 's', 't', 'a', 0};
1735 SCRIPT_CACHE psc;
1736 int cChars;
1737 int cMaxGlyphs;
1738 unsigned short pwOutGlyphs1[256];
1739 WORD pwLogClust[256];
1740 SCRIPT_VISATTR psva[256];
1741 int pcGlyphs;
1742 int piAdvance[256];
1743 GOFFSET pGoffset[256];
1744 ABC pABC[256];
1746 /* Create an extra DC that will be used until the ScriptTextOut */
1747 hdc1 = CreateCompatibleDC(hdc);
1748 ok (hdc1 != 0, "CreateCompatibleDC failed to create a DC\n");
1749 hdc2 = CreateCompatibleDC(hdc);
1750 ok (hdc2 != 0, "CreateCompatibleDC failed to create a DC\n");
1752 /* This is a valid test that will cause parsing to take place */
1753 cInChars = 5;
1754 cMaxItems = 255;
1755 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1756 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1757 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1758 * returned. */
1759 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1760 if (pcItems > 0)
1761 ok (pItem[0].iCharPos == 0 && pItem[1].iCharPos == cInChars,
1762 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1763 pItem[0].iCharPos, cInChars, pItem[1].iCharPos);
1765 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1766 * ie. ScriptItemize has succeeded and that pItem has been set */
1767 cInChars = 5;
1768 if (hr == 0) {
1769 psc = NULL; /* must be null on first call */
1770 cChars = cInChars;
1771 cMaxGlyphs = 256;
1772 hr = ScriptShape(hdc2, &psc, TestItem1, cChars,
1773 cMaxGlyphs, &pItem[0].a,
1774 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1775 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1776 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1777 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1778 if (hr ==0) {
1779 /* Note hdc is needed as glyph info is not yet in psc */
1780 hr = ScriptPlace(hdc2, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1781 pGoffset, pABC);
1782 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1784 /* key part!!! cached dc is being deleted */
1785 hr = DeleteDC(hdc2);
1786 ok(hr == 1, "DeleteDC should return 1 not %08x\n", hr);
1788 /* At this point the cached hdc (hdc2) has been destroyed,
1789 * however, we are passing in a *real* hdc (the original hdc).
1790 * The text should be written to that DC
1792 hr = ScriptTextOut(hdc1, &psc, 0, 0, 0, NULL, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1793 piAdvance, NULL, pGoffset);
1794 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1795 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1797 DeleteDC(hdc1);
1799 /* Clean up and go */
1800 ScriptFreeCache(&psc);
1801 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1806 static void test_ScriptTextOut3(HDC hdc)
1808 HRESULT hr;
1810 int cInChars;
1811 int cMaxItems;
1812 SCRIPT_ITEM pItem[255];
1813 int pcItems;
1814 WCHAR TestItem1[] = {' ','\r', 0};
1816 SCRIPT_CACHE psc;
1817 int cChars;
1818 int cMaxGlyphs;
1819 unsigned short pwOutGlyphs1[256];
1820 WORD pwLogClust[256];
1821 SCRIPT_VISATTR psva[256];
1822 int pcGlyphs;
1823 int piAdvance[256];
1824 GOFFSET pGoffset[256];
1825 ABC pABC[256];
1826 RECT rect;
1828 /* This is to ensure that nonexistent glyphs are translated into a valid glyph number */
1829 cInChars = 2;
1830 cMaxItems = 255;
1831 hr = ScriptItemize(TestItem1, cInChars, cMaxItems, NULL, NULL, pItem, &pcItems);
1832 ok (hr == 0, "ScriptItemize should return 0, returned %08x\n", hr);
1833 /* This test is for the interim operation of ScriptItemize where only one SCRIPT_ITEM is *
1834 * returned. */
1835 ok (pcItems > 0, "The number of SCRIPT_ITEMS should be greater than 0\n");
1836 if (pcItems > 0)
1837 ok (pItem[0].iCharPos == 0 && pItem[2].iCharPos == cInChars,
1838 "Start pos not = 0 (%d) or end pos not = %d (%d)\n",
1839 pItem[0].iCharPos, cInChars, pItem[2].iCharPos);
1841 /* It would appear that we have a valid SCRIPT_ANALYSIS and can continue
1842 * ie. ScriptItemize has succeeded and that pItem has been set */
1843 cInChars = 2;
1844 if (hr == 0) {
1845 psc = NULL; /* must be null on first call */
1846 cChars = cInChars;
1847 cMaxGlyphs = 256;
1848 hr = ScriptShape(hdc, &psc, TestItem1, cChars,
1849 cMaxGlyphs, &pItem[0].a,
1850 pwOutGlyphs1, pwLogClust, psva, &pcGlyphs);
1851 ok (hr == 0, "ScriptShape should return 0 not (%08x)\n", hr);
1852 ok (psc != NULL, "psc should not be null and have SCRIPT_CACHE buffer address\n");
1853 ok (pcGlyphs == cChars, "Chars in (%d) should equal Glyphs out (%d)\n", cChars, pcGlyphs);
1854 if (hr ==0) {
1855 /* Note hdc is needed as glyph info is not yet in psc */
1856 hr = ScriptPlace(hdc, &psc, pwOutGlyphs1, pcGlyphs, psva, &pItem[0].a, piAdvance,
1857 pGoffset, pABC);
1858 ok (hr == 0, "Should return 0 not (%08x)\n", hr);
1860 /* Test Rect Rgn is acceptable */
1861 rect.top = 10;
1862 rect.bottom = 20;
1863 rect.left = 10;
1864 rect.right = 40;
1865 hr = ScriptTextOut(hdc, &psc, 0, 0, 0, &rect, &pItem[0].a, NULL, 0, pwOutGlyphs1, pcGlyphs,
1866 piAdvance, NULL, pGoffset);
1867 ok (hr == 0, "ScriptTextOut should return 0 not (%08x)\n", hr);
1870 /* Clean up and go */
1871 ScriptFreeCache(&psc);
1872 ok( psc == NULL, "Expected psc to be NULL, got %p\n", psc);
1876 #define test_item_ScriptXtoX(a,b,c,d,e,f) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _test_item_ScriptXtoX(a,b,c,d,e,f)
1878 static void _test_item_ScriptXtoX(SCRIPT_ANALYSIS *psa, int cChars, int cGlyphs, const int* offsets, const WORD *pwLogClust, const int* piAdvance )
1880 int iX, iCP;
1881 int icChars, icGlyphs;
1882 int piCP, piX;
1883 HRESULT hr;
1884 SCRIPT_VISATTR psva[10];
1885 int piTrailing;
1886 BOOL fTrailing;
1887 int direction;
1889 memset(psva,0,sizeof(psva));
1890 direction = (psa->fRTL)?-1:+1;
1892 for(iCP = 0; iCP < cChars; iCP++)
1894 iX = offsets[iCP];
1895 icChars = cChars;
1896 icGlyphs = cGlyphs;
1897 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1898 winetest_ok(hr == S_OK, "ScriptXtoCP: should return S_OK not %08x\n", hr);
1899 winetest_ok(piCP == iCP, "ScriptXtoCP: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1900 winetest_ok(piTrailing == 0, "ScriptXtoCP: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1903 for(iCP = 0; iCP < cChars; iCP++)
1905 iX = offsets[iCP]+direction;
1906 icChars = cChars;
1907 icGlyphs = cGlyphs;
1908 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1909 winetest_ok(hr == S_OK, "ScriptXtoCP leading: should return S_OK not %08x\n", hr);
1910 winetest_ok(piCP == iCP, "ScriptXtoCP leading: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1911 winetest_ok(piTrailing == 0, "ScriptXtoCP leading: iX=%d should return piTrailing=0 not %d\n", iX, piTrailing);
1914 for(iCP = 0; iCP < cChars; iCP++)
1916 iX = offsets[iCP+1]-direction;
1917 icChars = cChars;
1918 icGlyphs = cGlyphs;
1919 hr = ScriptXtoCP(iX, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piCP, &piTrailing);
1920 winetest_ok(hr == S_OK, "ScriptXtoCP trailing: should return S_OK not %08x\n", hr);
1921 winetest_ok(piCP == iCP, "ScriptXtoCP trailing: iX=%d should return piCP=%d not %d\n", iX, iCP, piCP);
1922 winetest_ok(piTrailing == 1, "ScriptXtoCP trailing: iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
1925 for(iCP = 0; iCP <= cChars+1; iCP++)
1927 fTrailing = FALSE;
1928 icChars = cChars;
1929 icGlyphs = cGlyphs;
1930 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
1931 winetest_ok(hr == S_OK, "ScriptCPtoX: should return S_OK not %08x\n", hr);
1932 winetest_ok(piX == offsets[iCP],
1933 "ScriptCPtoX: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP], piX);
1936 for(iCP = 0; iCP <= cChars+1; iCP++)
1938 fTrailing = TRUE;
1939 icChars = cChars;
1940 icGlyphs = cGlyphs;
1941 hr = ScriptCPtoX(iCP, fTrailing, icChars, icGlyphs, pwLogClust, psva, piAdvance, psa, &piX);
1942 winetest_ok(hr == S_OK, "ScriptCPtoX trailing: should return S_OK not %08x\n", hr);
1943 winetest_ok(piX == offsets[iCP+1],
1944 "ScriptCPtoX trailing: iCP=%d should return piX=%d not %d\n", iCP, offsets[iCP+1], piX);
1948 static void test_ScriptXtoX(void)
1949 /****************************************************************************************
1950 * This routine tests the ScriptXtoCP and ScriptCPtoX functions using static variables *
1951 ****************************************************************************************/
1953 WORD pwLogClust[10] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
1954 WORD pwLogClust_RTL[10] = {3, 3, 3, 2, 2, 1, 1, 0, 0, 0};
1955 WORD pwLogClust_2[7] = {4, 3, 3, 2, 1, 0 ,0};
1956 int piAdvance[10] = {201, 190, 210, 180, 170, 204, 189, 195, 212, 203};
1957 int piAdvance_2[5] = {39, 26, 19, 17, 11};
1958 static const int offsets[13] = {0, 67, 134, 201, 296, 391, 496, 601, 1052, 1503, 1954, 1954, 1954};
1959 static const int offsets_RTL[13] = {781, 721, 661, 601, 496, 391, 296, 201, 134, 67, 0, 0, 0};
1960 static const int offsets_2[10] = {112, 101, 92, 84, 65, 39, 19, 0, 0, 0};
1961 SCRIPT_VISATTR psva[10];
1962 SCRIPT_ANALYSIS sa;
1963 int iX;
1964 int piCP;
1965 int piTrailing;
1966 HRESULT hr;
1968 memset(&sa, 0 , sizeof(SCRIPT_ANALYSIS));
1969 memset(psva, 0, sizeof(psva));
1971 sa.fRTL = FALSE;
1972 hr = ScriptXtoCP(-1, 10, 10, pwLogClust, psva, piAdvance, &sa, &piCP, &piTrailing);
1973 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1974 if (piTrailing)
1975 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1976 else /* win2k3 */
1977 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
1979 for (iX = 0; iX <= 7; iX++)
1981 WORD clust = 0;
1982 INT advance = 16;
1983 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
1984 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX, piCP,piTrailing);
1986 for (iX = 8; iX < 16; iX++)
1988 WORD clust = 0;
1989 INT advance = 16;
1990 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
1991 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX, piCP,piTrailing);
1994 sa.fRTL = TRUE;
1995 hr = ScriptXtoCP(-1, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
1996 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
1997 if (piTrailing)
1998 ok(piCP == -1, "Negative iX should return piCP=-1 not %d\n", piCP);
1999 else /* win2k3 */
2000 ok(piCP == 10, "Negative iX should return piCP=10 not %d\n", piCP);
2002 iX = 1954;
2003 hr = ScriptXtoCP(1954, 10, 10, pwLogClust_RTL, psva, piAdvance, &sa, &piCP, &piTrailing);
2004 ok(hr == S_OK, "ScriptXtoCP should return S_OK not %08x\n", hr);
2005 ok(piCP == -1, "iX=%d should return piCP=-1 not %d\n", iX, piCP);
2006 ok(piTrailing == 1, "iX=%d should return piTrailing=1 not %d\n", iX, piTrailing);
2008 for (iX = 1; iX <= 8; iX++)
2010 WORD clust = 0;
2011 INT advance = 16;
2012 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2013 ok(piCP==0 && piTrailing==1,"%i should return 0(%i) and 1(%i)\n",iX,piCP,piTrailing);
2015 for (iX = 9; iX < 16; iX++)
2017 WORD clust = 0;
2018 INT advance = 16;
2019 hr = ScriptXtoCP(iX, 1, 1, &clust, psva, &advance, &sa, &piCP, &piTrailing);
2020 ok(piCP==0 && piTrailing==0,"%i should return 0(%i) and 0(%i)\n",iX,piCP,piTrailing);
2023 sa.fRTL = FALSE;
2024 test_item_ScriptXtoX(&sa, 10, 10, offsets, pwLogClust, piAdvance);
2025 sa.fRTL = TRUE;
2026 test_item_ScriptXtoX(&sa, 10, 10, offsets_RTL, pwLogClust_RTL, piAdvance);
2027 test_item_ScriptXtoX(&sa, 7, 5, offsets_2, pwLogClust_2, piAdvance_2);
2030 static void test_ScriptString(HDC hdc)
2032 /*******************************************************************************************
2034 * This set of tests are for the string functions of uniscribe. The ScriptStringAnalyse
2035 * function allocates memory pointed to by the SCRIPT_STRING_ANALYSIS ssa pointer. This
2036 * memory is freed by ScriptStringFree. There needs to be a valid hdc for this as
2037 * ScriptStringAnalyse calls ScriptSItemize, ScriptShape and ScriptPlace which require it.
2041 HRESULT hr;
2042 WCHAR teststr[] = {'T','e','s','t','1',' ','a','2','b','3', '\0'};
2043 int len = (sizeof(teststr) / sizeof(WCHAR)) - 1;
2044 int Glyphs = len * 2 + 16;
2045 int Charset;
2046 DWORD Flags = SSA_GLYPHS;
2047 int ReqWidth = 100;
2048 const int Dx[5] = {10, 10, 10, 10, 10};
2049 const BYTE InClass = 0;
2050 SCRIPT_STRING_ANALYSIS ssa = NULL;
2052 int X = 10;
2053 int Y = 100;
2054 UINT Options = 0;
2055 const RECT rc = {0, 50, 100, 100};
2056 int MinSel = 0;
2057 int MaxSel = 0;
2058 BOOL Disabled = FALSE;
2059 const int *clip_len;
2060 int i;
2061 UINT *order;
2064 Charset = -1; /* this flag indicates unicode input */
2065 /* Test without hdc to get E_PENDING */
2066 hr = ScriptStringAnalyse( NULL, teststr, len, Glyphs, Charset, Flags,
2067 ReqWidth, NULL, NULL, Dx, NULL,
2068 &InClass, &ssa);
2069 ok(hr == E_PENDING, "ScriptStringAnalyse Stub should return E_PENDING not %08x\n", hr);
2071 /* test with hdc, this should be a valid test */
2072 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2073 ReqWidth, NULL, NULL, Dx, NULL,
2074 &InClass, &ssa);
2075 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2076 ScriptStringFree(&ssa);
2078 /* test makes sure that a call with a valid pssa still works */
2079 hr = ScriptStringAnalyse( hdc, teststr, len, Glyphs, Charset, Flags,
2080 ReqWidth, NULL, NULL, Dx, NULL,
2081 &InClass, &ssa);
2082 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2083 ok(ssa != NULL, "ScriptStringAnalyse pssa should not be NULL\n");
2085 if (hr == S_OK)
2087 hr = ScriptStringOut(ssa, X, Y, Options, &rc, MinSel, MaxSel, Disabled);
2088 ok(hr == S_OK, "ScriptStringOut should return S_OK not %08x\n", hr);
2091 clip_len = ScriptString_pcOutChars(ssa);
2092 ok(*clip_len == len, "ScriptString_pcOutChars failed, got %d, expected %d\n", *clip_len, len);
2094 order = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *clip_len * sizeof(UINT));
2095 hr = ScriptStringGetOrder(ssa, order);
2096 ok(hr == S_OK, "ScriptStringGetOrder failed, got %08x, expected S_OK\n", hr);
2098 for (i = 0; i < *clip_len; i++) ok(order[i] == i, "%d: got %d expected %d\n", i, order[i], i);
2099 HeapFree(GetProcessHeap(), 0, order);
2101 hr = ScriptStringFree(&ssa);
2102 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2105 static void test_ScriptStringXtoCP_CPtoX(HDC hdc)
2107 /*****************************************************************************************
2109 * This test is for the ScriptStringXtoCP and ScriptStringXtoCP functions. Due to the
2110 * nature of the fonts between Windows and Wine, the test is implemented by generating
2111 * values using one one function then checking the output of the second. In this way
2112 * the validity of the functions is established using Windows as a base and confirming
2113 * similar behaviour in wine.
2116 HRESULT hr;
2117 static const WCHAR teststr1[] = {0x05e9, 'i', 0x05dc, 'n', 0x05d5, 'e', 0x05dd, '.',0};
2118 static const BOOL rtl[] = {1, 0, 1, 0, 1, 0, 1, 0};
2119 void *String = (WCHAR *) &teststr1; /* ScriptStringAnalysis needs void */
2120 int String_len = (sizeof(teststr1)/sizeof(WCHAR))-1;
2121 int Glyphs = String_len * 2 + 16; /* size of buffer as recommended */
2122 int Charset = -1; /* unicode */
2123 DWORD Flags = SSA_GLYPHS;
2124 int ReqWidth = 100;
2125 const BYTE InClass = 0;
2126 SCRIPT_STRING_ANALYSIS ssa = NULL;
2128 int Ch; /* Character position in string */
2129 int iTrailing;
2130 int Cp; /* Character position in string */
2131 int X;
2132 int trail,lead;
2133 BOOL fTrailing;
2135 /* Test with hdc, this should be a valid test
2136 * Here we generate an SCRIPT_STRING_ANALYSIS that will be used as input to the
2137 * following character positions to X and X to character position functions.
2140 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2141 ReqWidth, NULL, NULL, NULL, NULL,
2142 &InClass, &ssa);
2143 ok(hr == S_OK ||
2144 hr == E_INVALIDARG, /* NT */
2145 "ScriptStringAnalyse should return S_OK or E_INVALIDARG not %08x\n", hr);
2147 if (hr == S_OK)
2149 ok(ssa != NULL, "ScriptStringAnalyse ssa should not be NULL\n");
2152 * Loop to generate character positions to provide starting positions for the
2153 * ScriptStringCPtoX and ScriptStringXtoCP functions
2155 for (Cp = 0; Cp < String_len; Cp++)
2157 /* The fTrailing flag is used to indicate whether the X being returned is at
2158 * the beginning or the end of the character. What happens here is that if
2159 * fTrailing indicates the end of the character, ie. FALSE, then ScriptStringXtoCP
2160 * returns the beginning of the next character and iTrailing is FALSE. So for this
2161 * loop iTrailing will be FALSE in both cases.
2163 hr = ScriptStringCPtoX(ssa, Cp, TRUE, &trail);
2164 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2165 hr = ScriptStringCPtoX(ssa, Cp, FALSE, &lead);
2166 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2167 if (rtl[Cp])
2168 ok(lead > trail, "Leading values should be after trailing for rtl characters(%i)\n",Cp);
2169 else
2170 ok(lead < trail, "Trailing values should be after leading for ltr characters(%i)\n",Cp);
2172 /* move by 1 pixel so that we are not inbetween 2 characters. That could result in being the lead of a rtl and
2173 at the same time the trail of an ltr */
2175 /* inside the leading edge */
2176 X = lead;
2177 if (rtl[Cp]) X--; else X++;
2178 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2179 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2180 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2181 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2182 iTrailing, X);
2184 /* inside the trailing edge */
2185 X = trail;
2186 if (rtl[Cp]) X++; else X--;
2187 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2188 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2189 ok(Cp == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp, Ch, trail);
2190 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2191 iTrailing, X);
2193 /* outside the "trailing" edge */
2194 if (Cp < String_len-1)
2196 if (rtl[Cp]) X = lead; else X = trail;
2197 X++;
2198 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2199 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2200 ok(Cp + 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp + 1, Ch, trail);
2201 if (rtl[Cp+1])
2202 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2203 iTrailing, X);
2204 else
2205 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2206 iTrailing, X);
2209 /* outside the "leading" edge */
2210 if (Cp != 0)
2212 if (rtl[Cp]) X = trail; else X = lead;
2213 X--;
2214 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2215 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2216 ok(Cp - 1 == Ch, "ScriptStringXtoCP should return Ch = %d not %d for X = %d\n", Cp - 1, Ch, trail);
2217 if (Cp != 0 && rtl[Cp-1])
2218 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = %d\n",
2219 iTrailing, X);
2220 else
2221 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = %d\n",
2222 iTrailing, X);
2226 /* Check beyond the leading boundary of the whole string */
2227 if (rtl[0])
2229 /* having a leading rtl character seems to confuse usp */
2230 /* this looks to be a windows bug we should emulate */
2231 hr = ScriptStringCPtoX(ssa, 0, TRUE, &X);
2232 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2233 X--;
2234 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2235 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2236 ok(Ch == 1, "ScriptStringXtoCP should return Ch = 1 not %d for X outside leading edge when rtl\n", Ch);
2237 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside leading edge when rtl\n",
2238 iTrailing);
2240 else
2242 hr = ScriptStringCPtoX(ssa, 0, FALSE, &X);
2243 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2244 X--;
2245 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2246 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2247 ok(Ch == -1, "ScriptStringXtoCP should return Ch = -1 not %d for X outside leading edge\n", Ch);
2248 ok(iTrailing == TRUE, "ScriptStringXtoCP should return iTrailing = 1 not %d for X = outside leading edge\n",
2249 iTrailing);
2252 /* Check beyond the end boundary of the whole string */
2253 if (rtl[String_len-1])
2255 hr = ScriptStringCPtoX(ssa, String_len-1, FALSE, &X);
2256 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2258 else
2260 hr = ScriptStringCPtoX(ssa, String_len-1, TRUE, &X);
2261 ok(hr == S_OK, "ScriptStringCPtoX should return S_OK not %08x\n", hr);
2263 X++;
2264 hr = ScriptStringXtoCP(ssa, X, &Ch, &iTrailing);
2265 ok(hr == S_OK, "ScriptStringXtoCP should return S_OK not %08x\n", hr);
2266 ok(Ch == String_len, "ScriptStringXtoCP should return Ch = %i not %d for X outside trailing edge\n", String_len, Ch);
2267 ok(iTrailing == FALSE, "ScriptStringXtoCP should return iTrailing = 0 not %d for X = outside trailing edge\n",
2268 iTrailing);
2271 * Cleanup the SSA for the next round of tests
2273 hr = ScriptStringFree(&ssa);
2274 ok(hr == S_OK, "ScriptStringFree should return S_OK not %08x\n", hr);
2277 * Test to see that exceeding the number of chars returns E_INVALIDARG. First
2278 * generate an SSA for the subsequent tests.
2280 hr = ScriptStringAnalyse( hdc, String, String_len, Glyphs, Charset, Flags,
2281 ReqWidth, NULL, NULL, NULL, NULL,
2282 &InClass, &ssa);
2283 ok(hr == S_OK, "ScriptStringAnalyse should return S_OK not %08x\n", hr);
2286 * When ScriptStringCPtoX is called with a character position Cp that exceeds the
2287 * string length, return E_INVALIDARG. This also invalidates the ssa so a
2288 * ScriptStringFree should also fail.
2290 fTrailing = FALSE;
2291 Cp = String_len + 1;
2292 hr = ScriptStringCPtoX(ssa, Cp, fTrailing, &X);
2293 ok(hr == E_INVALIDARG, "ScriptStringCPtoX should return E_INVALIDARG not %08x\n", hr);
2295 ScriptStringFree(&ssa);
2299 static void test_ScriptCacheGetHeight(HDC hdc)
2301 HRESULT hr;
2302 SCRIPT_CACHE sc = NULL;
2303 LONG height;
2305 hr = ScriptCacheGetHeight(NULL, NULL, NULL);
2306 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2308 hr = ScriptCacheGetHeight(NULL, &sc, NULL);
2309 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2311 hr = ScriptCacheGetHeight(NULL, &sc, &height);
2312 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2314 height = 0;
2316 hr = ScriptCacheGetHeight(hdc, &sc, &height);
2317 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2318 ok(height > 0, "expected height > 0\n");
2320 ScriptFreeCache(&sc);
2323 static void test_ScriptGetGlyphABCWidth(HDC hdc)
2325 HRESULT hr;
2326 SCRIPT_CACHE sc = NULL;
2327 ABC abc;
2329 hr = ScriptGetGlyphABCWidth(NULL, NULL, 'a', NULL);
2330 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2332 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', NULL);
2333 ok(broken(hr == E_PENDING) ||
2334 hr == E_INVALIDARG, /* WIN7 */
2335 "expected E_INVALIDARG, got 0x%08x\n", hr);
2337 hr = ScriptGetGlyphABCWidth(NULL, &sc, 'a', &abc);
2338 ok(hr == E_PENDING, "expected E_PENDING, got 0x%08x\n", hr);
2340 if (0) { /* crashes on WinXP */
2341 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', NULL);
2342 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2345 hr = ScriptGetGlyphABCWidth(hdc, &sc, 'a', &abc);
2346 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2348 ScriptFreeCache(&sc);
2351 static void test_ScriptLayout(void)
2353 HRESULT hr;
2354 static const BYTE levels[][10] =
2356 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
2357 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
2358 { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2359 { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
2361 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
2362 { 1, 1, 1, 2, 2, 2, 1, 1, 1, 1 },
2363 { 2, 2, 2, 1, 1, 1, 2, 2, 2, 2 },
2364 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 },
2365 { 1, 1, 2, 2, 3, 3, 2, 2, 1, 1 },
2367 { 0, 0, 1, 1, 2, 2, 1, 1, 0, 1 },
2368 { 1, 0, 1, 2, 2, 1, 2, 1, 0, 1 },
2370 static const int expect_l2v[][10] =
2372 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2373 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2374 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2375 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2377 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2378 /**/ { 9, 8, 7, 4, 5, 6, 3 ,2 ,1, 0},
2379 /**/ { 7, 8, 9, 6, 5, 4, 0 ,1 ,2, 3},
2380 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2381 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2383 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2384 /**/ { 0, 1, 7, 5, 6, 4, 3 ,2 ,8, 9},
2386 static const int expect_v2l[][10] =
2388 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2389 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2390 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
2391 { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 },
2393 { 0, 1, 2, 3, 4, 9, 8 ,7 ,6, 5},
2394 { 9, 8, 7, 6, 3, 4, 5 ,2 ,1, 0},
2395 { 6, 7, 8, 9, 5, 4, 3 ,0 ,1, 2},
2396 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2397 { 9, 8, 2, 3, 5, 4, 6 ,7 ,1, 0},
2399 { 0, 1, 7, 6, 4, 5, 3 ,2 ,8, 9},
2400 { 0, 1, 7, 6, 5, 3, 4 ,2 ,8, 9},
2403 int i, j, vistolog[sizeof(levels[0])], logtovis[sizeof(levels[0])];
2405 hr = ScriptLayout(sizeof(levels[0]), NULL, vistolog, logtovis);
2406 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2408 hr = ScriptLayout(sizeof(levels[0]), levels[0], NULL, NULL);
2409 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
2411 for (i = 0; i < sizeof(levels)/sizeof(levels[0]); i++)
2413 hr = ScriptLayout(sizeof(levels[0]), levels[i], vistolog, logtovis);
2414 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
2416 for (j = 0; j < sizeof(levels[i]); j++)
2418 ok(expect_v2l[i][j] == vistolog[j],
2419 "failure: levels[%d][%d] = %d, vistolog[%d] = %d\n",
2420 i, j, levels[i][j], j, vistolog[j] );
2423 for (j = 0; j < sizeof(levels[i]); j++)
2425 ok(expect_l2v[i][j] == logtovis[j],
2426 "failure: levels[%d][%d] = %d, logtovis[%d] = %d\n",
2427 i, j, levels[i][j], j, logtovis[j] );
2432 static BOOL CALLBACK enum_proc(LGRPID group, LCID lcid, LPSTR locale, LONG_PTR lparam)
2434 HRESULT hr;
2435 SCRIPT_DIGITSUBSTITUTE sds;
2436 SCRIPT_CONTROL sc;
2437 SCRIPT_STATE ss;
2438 LCID lcid_old;
2440 if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE;
2442 memset(&sds, 0, sizeof(sds));
2443 memset(&sc, 0, sizeof(sc));
2444 memset(&ss, 0, sizeof(ss));
2446 lcid_old = GetThreadLocale();
2447 if (!SetThreadLocale(lcid)) return TRUE;
2449 hr = ScriptRecordDigitSubstitution(lcid, &sds);
2450 ok(hr == S_OK, "ScriptRecordDigitSubstitution failed: 0x%08x\n", hr);
2452 hr = ScriptApplyDigitSubstitution(&sds, &sc, &ss);
2453 ok(hr == S_OK, "ScriptApplyDigitSubstitution failed: 0x%08x\n", hr);
2455 SetThreadLocale(lcid_old);
2456 return TRUE;
2459 static void test_digit_substitution(void)
2461 BOOL ret;
2462 unsigned int i;
2463 static const LGRPID groups[] =
2465 LGRPID_WESTERN_EUROPE,
2466 LGRPID_CENTRAL_EUROPE,
2467 LGRPID_BALTIC,
2468 LGRPID_GREEK,
2469 LGRPID_CYRILLIC,
2470 LGRPID_TURKISH,
2471 LGRPID_JAPANESE,
2472 LGRPID_KOREAN,
2473 LGRPID_TRADITIONAL_CHINESE,
2474 LGRPID_SIMPLIFIED_CHINESE,
2475 LGRPID_THAI,
2476 LGRPID_HEBREW,
2477 LGRPID_ARABIC,
2478 LGRPID_VIETNAMESE,
2479 LGRPID_INDIC,
2480 LGRPID_GEORGIAN,
2481 LGRPID_ARMENIAN
2483 HMODULE hKernel32;
2484 static BOOL (WINAPI * pEnumLanguageGroupLocalesA)(LANGGROUPLOCALE_ENUMPROCA,LGRPID,DWORD,LONG_PTR);
2486 hKernel32 = GetModuleHandleA("kernel32.dll");
2487 pEnumLanguageGroupLocalesA = (void*)GetProcAddress(hKernel32, "EnumLanguageGroupLocalesA");
2489 if (!pEnumLanguageGroupLocalesA)
2491 win_skip("EnumLanguageGroupLocalesA not available on this platform\n");
2492 return;
2495 for (i = 0; i < sizeof(groups)/sizeof(groups[0]); i++)
2497 ret = pEnumLanguageGroupLocalesA(enum_proc, groups[i], 0, 0);
2498 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2500 win_skip("EnumLanguageGroupLocalesA not implemented on this platform\n");
2501 break;
2504 ok(ret, "EnumLanguageGroupLocalesA failed unexpectedly: %u\n", GetLastError());
2508 static void test_ScriptGetProperties(void)
2510 const SCRIPT_PROPERTIES **props;
2511 HRESULT hr;
2512 int num;
2514 hr = ScriptGetProperties(NULL, NULL);
2515 ok(hr == E_INVALIDARG, "ScriptGetProperties succeeded\n");
2517 hr = ScriptGetProperties(NULL, &num);
2518 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2520 hr = ScriptGetProperties(&props, NULL);
2521 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2523 hr = ScriptGetProperties(&props, &num);
2524 ok(hr == S_OK, "ScriptGetProperties failed: 0x%08x\n", hr);
2527 static void test_ScriptBreak(void)
2529 static const WCHAR test[] = {' ','\r','\n',0};
2530 SCRIPT_ITEM items[4];
2531 SCRIPT_LOGATTR la;
2532 HRESULT hr;
2534 hr = ScriptItemize(test, 3, 4, NULL, NULL, items, NULL);
2535 ok(!hr, "ScriptItemize should return S_OK not %08x\n", hr);
2537 memset(&la, 0, sizeof(la));
2538 hr = ScriptBreak(test, 1, &items[0].a, &la);
2539 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2541 ok(!la.fSoftBreak, "fSoftBreak set\n");
2542 ok(la.fWhiteSpace, "fWhiteSpace not set\n");
2543 ok(la.fCharStop, "fCharStop not set\n");
2544 ok(!la.fWordStop, "fWordStop set\n");
2545 ok(!la.fInvalid, "fInvalid set\n");
2546 ok(!la.fReserved, "fReserved set\n");
2548 memset(&la, 0, sizeof(la));
2549 hr = ScriptBreak(test + 1, 1, &items[1].a, &la);
2550 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2552 ok(!la.fSoftBreak, "fSoftBreak set\n");
2553 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2554 ok(la.fCharStop, "fCharStop not set\n");
2555 ok(!la.fWordStop, "fWordStop set\n");
2556 ok(!la.fInvalid, "fInvalid set\n");
2557 ok(!la.fReserved, "fReserved set\n");
2559 memset(&la, 0, sizeof(la));
2560 hr = ScriptBreak(test + 2, 1, &items[2].a, &la);
2561 ok(!hr, "ScriptBreak should return S_OK not %08x\n", hr);
2563 ok(!la.fSoftBreak, "fSoftBreak set\n");
2564 ok(!la.fWhiteSpace, "fWhiteSpace set\n");
2565 ok(la.fCharStop, "fCharStop not set\n");
2566 ok(!la.fWordStop, "fWordStop set\n");
2567 ok(!la.fInvalid, "fInvalid set\n");
2568 ok(!la.fReserved, "fReserved set\n");
2571 static void test_newlines(void)
2573 static const WCHAR test1[] = {'t','e','x','t','\r','t','e','x','t',0};
2574 static const WCHAR test2[] = {'t','e','x','t','\n','t','e','x','t',0};
2575 static const WCHAR test3[] = {'t','e','x','t','\r','\n','t','e','x','t',0};
2576 static const WCHAR test4[] = {'t','e','x','t','\n','\r','t','e','x','t',0};
2577 static const WCHAR test5[] = {'1','2','3','4','\n','\r','1','2','3','4',0};
2578 SCRIPT_ITEM items[5];
2579 HRESULT hr;
2580 int count;
2582 count = 0;
2583 hr = ScriptItemize(test1, lstrlenW(test1), 5, NULL, NULL, items, &count);
2584 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2585 ok(count == 3, "got %d expected 3\n", count);
2587 count = 0;
2588 hr = ScriptItemize(test2, lstrlenW(test2), 5, NULL, NULL, items, &count);
2589 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2590 ok(count == 3, "got %d expected 3\n", count);
2592 count = 0;
2593 hr = ScriptItemize(test3, lstrlenW(test3), 5, NULL, NULL, items, &count);
2594 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2595 ok(count == 4, "got %d expected 4\n", count);
2597 count = 0;
2598 hr = ScriptItemize(test4, lstrlenW(test4), 5, NULL, NULL, items, &count);
2599 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2600 ok(count == 4, "got %d expected 4\n", count);
2602 count = 0;
2603 hr = ScriptItemize(test5, lstrlenW(test5), 5, NULL, NULL, items, &count);
2604 ok(hr == S_OK, "ScriptItemize failed: 0x%08x\n", hr);
2605 ok(count == 4, "got %d expected 4\n", count);
2608 START_TEST(usp10)
2610 HWND hwnd;
2611 HDC hdc;
2612 LOGFONTA lf;
2613 HFONT hfont;
2615 unsigned short pwOutGlyphs[256];
2617 /* We need a valid HDC to drive a lot of Script functions which requires the following *
2618 * to set up for the tests. */
2619 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
2620 0, 0, 0, NULL);
2621 assert(hwnd != 0);
2622 ShowWindow(hwnd, SW_SHOW);
2623 UpdateWindow(hwnd);
2625 hdc = GetDC(hwnd); /* We now have a hdc */
2626 ok( hdc != NULL, "HDC failed to be created %p\n", hdc);
2628 memset(&lf, 0, sizeof(LOGFONTA));
2629 lstrcpyA(lf.lfFaceName, "Tahoma");
2630 lf.lfHeight = 10;
2631 lf.lfWeight = 3;
2632 lf.lfWidth = 10;
2634 hfont = SelectObject(hdc, CreateFontIndirectA(&lf));
2635 ok(hfont != NULL, "SelectObject failed: %p\n", hfont);
2637 test_ScriptItemize();
2638 test_ScriptItemIzeShapePlace(hdc,pwOutGlyphs);
2639 test_ScriptGetCMap(hdc, pwOutGlyphs);
2640 test_ScriptCacheGetHeight(hdc);
2641 test_ScriptGetGlyphABCWidth(hdc);
2642 test_ScriptShape(hdc);
2643 test_ScriptShapeOpenType(hdc);
2644 test_ScriptPlace(hdc);
2646 test_ScriptGetFontProperties(hdc);
2647 test_ScriptTextOut(hdc);
2648 test_ScriptTextOut2(hdc);
2649 test_ScriptTextOut3(hdc);
2650 test_ScriptXtoX();
2651 test_ScriptString(hdc);
2652 test_ScriptStringXtoCP_CPtoX(hdc);
2654 test_ScriptLayout();
2655 test_digit_substitution();
2656 test_ScriptGetProperties();
2657 test_ScriptBreak();
2658 test_newlines();
2660 ReleaseDC(hwnd, hdc);
2661 DestroyWindow(hwnd);