2 * Implementation of Uniscribe Script Processor (usp10.dll)
4 * Copyright 2005 Steven Edwards for CodeWeavers
5 * Copyright 2006 Hans Leidekker
6 * Copyright 2010 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Uniscribe allows for processing of complex scripts such as joining
24 * and filtering characters and bi-directional text with custom line breaks.
37 #include "usp10_internal.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
44 typedef struct _scriptRange
53 static const scriptRange scriptRanges
[] = {
54 /* Basic Latin: U+0000–U+007A */
55 /* Latin-1 Supplement: U+0080–U+00FF */
56 /* Latin Extended-A: U+0100–U+017F */
57 /* Latin Extended-B: U+0180–U+024F */
58 /* IPA Extensions: U+0250–U+02AF */
59 { Script_Latin
, 0x00, 0x2af , Script_Numeric
, Script_Punctuation
},
60 /* Greek: U+0370–U+03FF */
61 { Script_Greek
, 0x370, 0x3ff, 0, 0},
62 /* Cyrillic: U+0400–U+04FF */
63 /* Cyrillic Supplement: U+0500–U+052F */
64 { Script_Cyrillic
, 0x400, 0x52f, 0, 0},
65 /* Armenian: U+0530–U+058F */
66 { Script_Armenian
, 0x530, 0x58f, 0, 0},
67 /* Hebrew: U+0590–U+05FF */
68 { Script_Hebrew
, 0x590, 0x5ff, 0, 0},
69 /* Arabic: U+0600–U+06FF */
70 { Script_Arabic
, 0x600, 0x6ef, Script_Arabic_Numeric
, 0},
71 /* Defined by Windows */
72 { Script_Persian
, 0x6f0, 0x6f9, 0, 0},
73 /* Continue Arabic: U+0600–U+06FF */
74 { Script_Arabic
, 0x6fa, 0x6ff, 0, 0},
75 /* Syriac: U+0700–U+074F*/
76 { Script_Syriac
, 0x700, 0x74f, 0, 0},
77 /* Arabic Supplement: U+0750–U+077F */
78 { Script_Arabic
, 0x750, 0x77f, 0, 0},
79 /* Thaana: U+0780–U+07BF */
80 { Script_Thaana
, 0x780, 0x7bf, 0, 0},
81 /* Devanagari: U+0900–U+097F */
82 { Script_Devanagari
, 0x900, 0x97f, Script_Devanagari_Numeric
, 0},
83 /* Bengali: U+0980–U+09FF */
84 { Script_Bengali
, 0x980, 0x9ff, Script_Bengali_Numeric
, 0},
85 /* Gurmukhi: U+0A00–U+0A7F*/
86 { Script_Gurmukhi
, 0xa00, 0xa7f, Script_Gurmukhi_Numeric
, 0},
87 /* Gujarati: U+0A80–U+0AFF*/
88 { Script_Gujarati
, 0xa80, 0xaff, Script_Gujarati_Numeric
, 0},
89 /* Oriya: U+0B00–U+0B7F */
90 { Script_Oriya
, 0xb00, 0xb7f, Script_Oriya_Numeric
, 0},
91 /* Tamil: U+0B80–U+0BFF */
92 { Script_Tamil
, 0xb80, 0xbff, Script_Tamil_Numeric
, 0},
93 /* Telugu: U+0C00–U+0C7F */
94 { Script_Telugu
, 0xc00, 0xc7f, Script_Telugu_Numeric
, 0},
95 /* Kannada: U+0C80–U+0CFF */
96 { Script_Kannada
, 0xc80, 0xcff, Script_Kannada_Numeric
, 0},
97 /* Malayalam: U+0D00–U+0D7F */
98 { Script_Malayalam
, 0xd00, 0xd7f, Script_Malayalam_Numeric
, 0},
99 /* Sinhala: U+0D80–U+0DFF */
100 { Script_Sinhala
, 0xd80, 0xdff, 0, 0},
101 /* Thai: U+0E00–U+0E7F */
102 { Script_Thai
, 0xe00, 0xe7f, Script_Thai_Numeric
, 0},
103 /* Lao: U+0E80–U+0EFF */
104 { Script_Lao
, 0xe80, 0xeff, Script_Lao_Numeric
, 0},
105 /* Tibetan: U+0F00–U+0FFF */
106 { Script_Tibetan
, 0xf00, 0xfff, Script_Tibetan_Numeric
, 0},
107 /* Georgian: U+10A0–U+10FF */
108 { Script_Georgian
, 0x10a0, 0x10ff, 0, 0},
109 /* Vedic Extensions: U+1CD0-U+1CFF */
110 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
111 /* Phonetic Extensions: U+1D00–U+1DBF */
112 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
113 /* Latin Extended Additional: U+1E00–U+1EFF */
114 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
115 /* Greek Extended: U+1F00–U+1FFF */
116 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
117 /* General Punctuation: U+2000 –U+206f */
118 /* Superscripts and Subscripts : U+2070 –U+209f */
119 /* Currency Symbols : U+20a0 –U+20cf */
120 { Script_Latin
, 0x2000, 0x20cf, 0, 0},
121 /* Letterlike Symbols : U+2100 –U+214f */
122 /* Number Forms : U+2150 –U+218f */
123 /* Arrows : U+2190 –U+21ff */
124 /* Mathematical Operators : U+2200 –U+22ff */
125 /* Miscellaneous Technical : U+2300 –U+23ff */
126 /* Control Pictures : U+2400 –U+243f */
127 /* Optical Character Recognition : U+2440 –U+245f */
128 /* Enclosed Alphanumerics : U+2460 –U+24ff */
129 /* Box Drawing : U+2500 –U+25ff */
130 /* Block Elements : U+2580 –U+259f */
131 /* Geometric Shapes : U+25a0 –U+25ff */
132 /* Miscellaneous Symbols : U+2600 –U+26ff */
133 /* Dingbats : U+2700 –U+27bf */
134 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
135 /* Supplemental Arrows-A : U+27f0 –U+27ff */
136 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
137 /* Supplemental Arrows-B : U+2900 –U+297f */
138 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
139 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
140 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
141 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
142 /* Latin Extended-C: U+2C60–U+2C7F */
143 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
144 /* Georgian: U+2D00–U+2D2F */
145 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
146 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
147 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
148 /* Cyrillic Extended-B: U+A640–U+A69F */
149 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
150 /* Modifier Tone Letters: U+A700–U+A71F */
151 /* Latin Extended-D: U+A720–U+A7FF */
152 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
153 /* Phags-pa: U+A840–U+A87F */
154 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
155 /* Devanagari Extended: U+A8E0-U+A8FF */
156 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
157 /* Latin Ligatures: U+FB00–U+FB06 */
158 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
159 /* Armenian ligatures U+FB13..U+FB17 */
160 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
161 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
162 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
163 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
164 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
165 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
166 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
168 { SCRIPT_UNDEFINED
, 0, 0, 0}
171 typedef struct _scriptData
174 SCRIPT_PROPERTIES props
;
175 OPENTYPE_TAG scriptTag
;
176 WCHAR fallbackFont
[LF_FACESIZE
];
179 /* the must be in order so that the index matches the Script value */
180 static const scriptData scriptInformation
[] = {
181 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
182 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
185 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
186 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
187 MS_MAKE_TAG('l','a','t','n'),
189 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
190 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
193 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
194 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
197 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
198 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
201 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
202 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
205 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
206 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
207 MS_MAKE_TAG('a','r','a','b'),
208 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
209 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
210 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
211 MS_MAKE_TAG('a','r','a','b'),
212 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
213 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
214 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
215 MS_MAKE_TAG('h','e','b','r'),
216 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
217 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
218 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
219 MS_MAKE_TAG('s','y','r','c'),
220 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
221 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
222 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
223 MS_MAKE_TAG('s','y','r','c'),
224 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
225 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
226 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
227 MS_MAKE_TAG('t','h','a','a'),
228 {'M','V',' ','B','o','l','i',0}},
229 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
230 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
231 MS_MAKE_TAG('g','r','e','k'),
233 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
234 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
235 MS_MAKE_TAG('c','y','r','l'),
237 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
238 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
239 MS_MAKE_TAG('a','r','m','n'),
240 {'S','y','l','f','a','e','n',0}},
241 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
242 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
243 MS_MAKE_TAG('g','e','o','r'),
244 {'S','y','l','f','a','e','n',0}},
245 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
246 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
247 MS_MAKE_TAG('s','i','n','h'),
248 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
249 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
250 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
251 MS_MAKE_TAG('t','i','b','t'),
252 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
253 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
254 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
255 MS_MAKE_TAG('t','i','b','t'),
256 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
257 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
258 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
259 MS_MAKE_TAG('p','h','a','g'),
260 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
261 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
262 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
263 MS_MAKE_TAG('t','h','a','i'),
264 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
265 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
266 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
267 MS_MAKE_TAG('t','h','a','i'),
268 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
269 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
270 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
271 MS_MAKE_TAG('l','a','o',' '),
272 {'D','o','k','C','h','a','m','p','a',0}},
273 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
274 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
275 MS_MAKE_TAG('l','a','o',' '),
276 {'D','o','k','C','h','a','m','p','a',0}},
277 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
278 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
279 MS_MAKE_TAG('d','e','v','a'),
280 {'M','a','n','g','a','l',0}},
281 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
282 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
283 MS_MAKE_TAG('d','e','v','a'),
284 {'M','a','n','g','a','l',0}},
285 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
286 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
287 MS_MAKE_TAG('b','e','n','g'),
288 {'V','r','i','n','d','a',0}},
289 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
290 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
291 MS_MAKE_TAG('b','e','n','g'),
292 {'V','r','i','n','d','a',0}},
293 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
294 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
295 MS_MAKE_TAG('b','e','n','g'),
296 {'V','r','i','n','d','a',0}},
297 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
298 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
299 MS_MAKE_TAG('g','u','r','u'),
300 {'R','a','a','v','i',0}},
301 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
302 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
303 MS_MAKE_TAG('g','u','r','u'),
304 {'R','a','a','v','i',0}},
305 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
306 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
307 MS_MAKE_TAG('g','u','j','r'),
308 {'S','h','r','u','t','i',0}},
309 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
310 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
311 MS_MAKE_TAG('g','u','j','r'),
312 {'S','h','r','u','t','i',0}},
313 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
314 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
315 MS_MAKE_TAG('g','u','j','r'),
316 {'S','h','r','u','t','i',0}},
317 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
318 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
319 MS_MAKE_TAG('o','r','y','a'),
320 {'K','a','l','i','n','g','a',0}},
321 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
322 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
323 MS_MAKE_TAG('o','r','y','a'),
324 {'K','a','l','i','n','g','a',0}},
325 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
326 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
327 MS_MAKE_TAG('t','a','m','l'),
328 {'L','a','t','h','a',0}},
329 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
330 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
331 MS_MAKE_TAG('t','a','m','l'),
332 {'L','a','t','h','a',0}},
333 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
334 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
335 MS_MAKE_TAG('t','e','l','u'),
336 {'G','a','u','t','a','m','i',0}},
337 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
338 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
339 MS_MAKE_TAG('t','e','l','u'),
340 {'G','a','u','t','a','m','i',0}},
341 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
342 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
343 MS_MAKE_TAG('k','n','d','a'),
344 {'T','u','n','g','a',0}},
345 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
346 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
347 MS_MAKE_TAG('k','n','d','a'),
348 {'T','u','n','g','a',0}},
349 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
350 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
351 MS_MAKE_TAG('m','l','y','m'),
352 {'K','a','r','t','i','k','a',0}},
353 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
354 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
355 MS_MAKE_TAG('m','l','y','m'),
356 {'K','a','r','t','i','k','a',0}},
359 static const SCRIPT_PROPERTIES
*script_props
[] =
361 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
362 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
363 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
364 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
365 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
366 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
367 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
368 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
369 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
370 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
371 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
372 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
373 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
374 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
375 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
376 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
377 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
378 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
379 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
380 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
381 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
382 &scriptInformation
[42].props
, &scriptInformation
[43].props
391 SCRIPT_VISATTR
* psva
;
407 StringGlyphs
* glyphs
;
408 SCRIPT_LOGATTR
* logattrs
;
413 static inline void *heap_alloc(SIZE_T size
)
415 return HeapAlloc(GetProcessHeap(), 0, size
);
418 static inline void *heap_alloc_zero(SIZE_T size
)
420 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
423 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
425 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
428 static inline BOOL
heap_free(LPVOID mem
)
430 return HeapFree(GetProcessHeap(), 0, mem
);
433 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
435 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
438 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
440 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
443 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
445 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
448 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
450 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
452 if (!block
) return 0;
453 return block
[c
& GLYPH_BLOCK_MASK
];
456 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
458 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
460 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
461 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
464 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
466 static const ABC nil
;
467 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
469 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
470 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
474 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
476 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
478 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
479 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
483 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
487 if (!psc
) return E_INVALIDARG
;
488 if (*psc
) return S_OK
;
489 if (!hdc
) return E_PENDING
;
491 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
492 if (!GetTextMetricsW(hdc
, &sc
->tm
))
497 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
502 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
504 TRACE("<- %p\n", sc
);
508 static WCHAR
mirror_char( WCHAR ch
)
510 extern const WCHAR wine_mirror_map
[];
511 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
514 static WORD
get_char_script( WCHAR ch
)
519 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
522 /* These chars are itemized as Punctuation by Windows */
523 if (ch
== 0x2212 || ch
== 0x2044 || ch
== 0x00a0)
524 return Script_Punctuation
;
526 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
529 return SCRIPT_UNDEFINED
;
532 return Script_Control
;
537 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
540 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
542 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
543 return scriptRanges
[i
].numericScript
;
544 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
545 return scriptRanges
[i
].punctScript
;
546 return scriptRanges
[i
].script
;
551 return SCRIPT_UNDEFINED
;
554 /***********************************************************************
558 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
562 case DLL_PROCESS_ATTACH
:
563 DisableThreadLibraryCalls(hInstDLL
);
565 case DLL_PROCESS_DETACH
:
571 /***********************************************************************
572 * ScriptFreeCache (USP10.@)
574 * Free a script cache.
577 * psc [I/O] Script cache.
581 * Failure: Non-zero HRESULT value.
583 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
590 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
592 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
593 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
595 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
596 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
597 heap_free(((ScriptCache
*)*psc
)->features
);
604 /***********************************************************************
605 * ScriptGetProperties (USP10.@)
607 * Retrieve a list of script properties.
610 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
611 * num [I] Pointer to the number of scripts.
615 * Failure: Non-zero HRESULT value.
618 * Behaviour matches WinXP.
620 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
622 TRACE("(%p,%p)\n", props
, num
);
624 if (!props
&& !num
) return E_INVALIDARG
;
626 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
627 if (props
) *props
= script_props
;
632 /***********************************************************************
633 * ScriptGetFontProperties (USP10.@)
635 * Get information on special glyphs.
638 * hdc [I] Device context.
639 * psc [I/O] Opaque pointer to a script cache.
640 * sfp [O] Font properties structure.
642 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
646 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
648 if (!sfp
) return E_INVALIDARG
;
649 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
651 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
654 /* return something sensible? */
656 sfp
->wgDefault
= get_cache_default_char(psc
);
658 sfp
->wgKashida
= 0xffff;
659 sfp
->iKashidaWidth
= 0;
664 /***********************************************************************
665 * ScriptRecordDigitSubstitution (USP10.@)
667 * Record digit substitution settings for a given locale.
670 * locale [I] Locale identifier.
671 * sds [I] Structure to record substitution settings.
675 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
678 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
680 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
684 TRACE("0x%x, %p\n", locale
, sds
);
686 /* This implementation appears to be correct for all languages, but it's
687 * not clear if sds->DigitSubstitute is ever set to anything except
688 * CONTEXT or NONE in reality */
690 if (!sds
) return E_POINTER
;
692 locale
= ConvertDefaultLocale(locale
);
694 if (!IsValidLocale(locale
, LCID_INSTALLED
))
697 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
698 sds
->TraditionalDigitLanguage
= plgid
;
700 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
701 sds
->NationalDigitLanguage
= plgid
;
703 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
705 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
706 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
711 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
712 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
714 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
717 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
720 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
723 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
731 /***********************************************************************
732 * ScriptApplyDigitSubstitution (USP10.@)
734 * Apply digit substitution settings.
737 * sds [I] Structure with recorded substitution settings.
738 * sc [I] Script control structure.
739 * ss [I] Script state structure.
743 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
745 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
746 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
748 SCRIPT_DIGITSUBSTITUTE psds
;
750 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
752 if (!sc
|| !ss
) return E_POINTER
;
756 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
760 sc
->uDefaultLanguage
= LANG_ENGLISH
;
761 sc
->fContextDigits
= 0;
762 ss
->fDigitSubstitute
= 0;
764 switch (sds
->DigitSubstitute
) {
765 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
766 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
767 case SCRIPT_DIGITSUBSTITUTE_NONE
:
768 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
775 /***********************************************************************
776 * ScriptItemizeOpenType (USP10.@)
778 * Split a Unicode string into shapeable parts.
781 * pwcInChars [I] String to split.
782 * cInChars [I] Number of characters in pwcInChars.
783 * cMaxItems [I] Maximum number of items to return.
784 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
785 * psState [I] Pointer to a SCRIPT_STATE structure.
786 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
787 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
788 * pcItems [O] Number of script items returned.
792 * Failure: Non-zero HRESULT value.
794 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
795 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
796 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
799 #define Numeric_space 0x0020
803 int cnt
= 0, index
= 0, str
= 0;
806 WORD
*strength
= NULL
;
810 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
811 psControl
, psState
, pItems
, pcItems
);
813 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
816 if (psState
&& psControl
)
819 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
821 return E_OUTOFMEMORY
;
823 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
824 baselevel
= levels
[0];
825 for (i
= 0; i
< cInChars
; i
++)
826 if (levels
[i
]!=levels
[0])
828 if (i
>= cInChars
&& !odd(baselevel
))
835 BOOL inNumber
= FALSE
;
836 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
838 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
842 return E_OUTOFMEMORY
;
844 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
846 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
847 for (i
= 0; i
< cInChars
; i
++)
849 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
851 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && get_char_script(pwcInChars
[i
]) == Script_Numeric
)
859 if (psControl
->fMergeNeutralItems
)
861 HeapFree(GetProcessHeap(),0,strength
);
867 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
|| pwcInChars
[cnt
] == ZWJ
|| pwcInChars
[cnt
] == ZWNJ
) && cnt
< cInChars
)
870 if (cnt
== cInChars
) /* All Spaces */
873 New_Script
= get_char_script(pwcInChars
[cnt
]);
876 pItems
[index
].iCharPos
= 0;
877 pItems
[index
].a
= scriptInformation
[get_char_script(pwcInChars
[cnt
])].a
;
878 pScriptTags
[index
] = scriptInformation
[get_char_script(pwcInChars
[cnt
])].scriptTag
;
880 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
889 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
890 pItems
[index
].a
.fLayoutRTL
= odd(levels
[cnt
]);
891 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
893 else if (!pItems
[index
].a
.s
.uBidiLevel
)
895 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
896 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
897 pItems
[index
].a
.fRTL
= odd(baselevel
);
900 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
901 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
902 pItems
[index
].iCharPos
);
904 for (cnt
=1; cnt
< cInChars
; cnt
++)
906 if(pwcInChars
[cnt
] != Numeric_space
&& pwcInChars
[cnt
] != ZWJ
&& pwcInChars
[cnt
] != ZWNJ
)
907 New_Script
= get_char_script(pwcInChars
[cnt
]);
911 while (cnt
+ j
< cInChars
- 1 && (pwcInChars
[cnt
+j
] == Numeric_space
|| pwcInChars
[cnt
+j
] == ZWJ
|| pwcInChars
[cnt
+j
] == ZWNJ
) && levels
[cnt
] == levels
[cnt
+j
])
913 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
914 New_Script
= get_char_script(pwcInChars
[cnt
+j
]);
916 New_Script
= get_char_script(pwcInChars
[cnt
]);
920 /* merge space strengths*/
921 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
924 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
927 /* changes in level */
928 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
930 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
933 /* changes in strength */
934 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
936 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
939 /* changes in script */
940 else if ((!levels
) && (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
)))
942 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
948 TRACE("New_Level = %i, New_Strength = %i, New_Script=%d, eScript=%d\n", levels
?levels
[cnt
]:-1, strength
?strength
[cnt
]:str
, New_Script
, pItems
[index
].a
.eScript
);
951 if (index
+1 > cMaxItems
)
952 return E_OUTOFMEMORY
;
957 pItems
[index
].iCharPos
= cnt
;
958 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
960 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
961 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
964 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
965 pItems
[index
].a
.fLayoutRTL
= odd(levels
[cnt
]);
966 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
968 else if (!pItems
[index
].a
.s
.uBidiLevel
)
970 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
971 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
972 pItems
[index
].a
.fRTL
= odd(baselevel
);
975 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
979 /* While not strictly necessary according to the spec, make sure the n+1
980 * item is set up to prevent random behaviour if the caller erroneously
981 * checks the n+1 structure */
983 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
985 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
987 /* Set one SCRIPT_STATE item being returned */
988 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
989 if (pcItems
) *pcItems
= index
;
991 /* Set SCRIPT_ITEM */
992 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
998 /***********************************************************************
999 * ScriptItemize (USP10.@)
1001 * Split a Unicode string into shapeable parts.
1004 * pwcInChars [I] String to split.
1005 * cInChars [I] Number of characters in pwcInChars.
1006 * cMaxItems [I] Maximum number of items to return.
1007 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1008 * psState [I] Pointer to a SCRIPT_STATE structure.
1009 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1010 * pcItems [O] Number of script items returned.
1014 * Failure: Non-zero HRESULT value.
1016 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1017 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1018 SCRIPT_ITEM
*pItems
, int *pcItems
)
1020 OPENTYPE_TAG
*discarded_tags
;
1023 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1024 if (!discarded_tags
)
1025 return E_OUTOFMEMORY
;
1026 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1027 heap_free(discarded_tags
);
1031 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1035 INT
*lpTabPos
= NULL
;
1040 lpTabPos
= pTabdef
->pTabStops
;
1042 if (pTabdef
&& pTabdef
->iTabOrigin
)
1044 if (pTabdef
->iScale
)
1045 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1047 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1051 cTabStops
= pTabdef
->cTabStops
;
1055 if (pTabdef
->iScale
)
1056 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1058 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1062 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1064 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1066 int position
= *lpTabPos
;
1068 position
= -1 * position
;
1069 if (pTabdef
->iScale
)
1070 position
= (position
* pTabdef
->iScale
) / 4;
1072 position
= position
* psc
->tm
.tmAveCharWidth
;
1074 if( nTabOrg
+ position
> current_x
)
1078 /* a left aligned tab */
1079 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1084 FIXME("Negative tabstop\n");
1089 if ((!cTabStops
) && (defWidth
> 0))
1090 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1091 else if ((!cTabStops
) && (defWidth
< 0))
1092 FIXME("TODO: Negative defWidth\n");
1097 /***********************************************************************
1098 * Helper function for ScriptStringAnalyse
1100 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1101 const WCHAR
*pwcInChars
, int cChars
)
1103 /* FIXME: When to properly fallback is still a bit of a mystery */
1106 if (psa
->fNoGlyphIndex
)
1109 if (init_script_cache(hdc
, psc
) != S_OK
)
1112 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1115 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1118 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1128 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1132 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1134 static const WCHAR szFmt
[] = {'%','x',0};
1136 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1139 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1140 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1141 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1145 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1148 /***********************************************************************
1149 * ScriptStringAnalyse (USP10.@)
1152 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1153 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1154 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1155 SCRIPT_STATE
*psState
, const int *piDx
,
1156 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1157 SCRIPT_STRING_ANALYSIS
*pssa
)
1159 HRESULT hr
= E_OUTOFMEMORY
;
1160 StringAnalysis
*analysis
= NULL
;
1161 SCRIPT_CONTROL sControl
;
1162 SCRIPT_STATE sState
;
1163 int i
, num_items
= 255;
1165 WCHAR
*iString
= NULL
;
1167 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1168 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1169 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1173 FIXME("Only Unicode strings are supported\n");
1174 return E_INVALIDARG
;
1176 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1177 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1179 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1180 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1182 /* FIXME: handle clipping */
1183 analysis
->clip_len
= cString
;
1184 analysis
->hdc
= hdc
;
1185 analysis
->dwFlags
= dwFlags
;
1190 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1193 sControl
= *psControl
;
1195 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1197 if (dwFlags
& SSA_PASSWORD
)
1199 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1205 for (i
= 0; i
< cString
; i
++)
1206 iString
[i
] = *((const WCHAR
*)pString
);
1210 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1211 &analysis
->numItems
);
1213 while (hr
== E_OUTOFMEMORY
)
1218 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1221 analysis
->pItem
= tmp
;
1222 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1223 &analysis
->numItems
);
1225 if (hr
!= S_OK
) goto error
;
1227 /* set back to out of memory for default goto error behaviour */
1230 if (dwFlags
& SSA_BREAK
)
1232 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1234 for (i
= 0; i
< analysis
->numItems
; i
++)
1235 ScriptBreak(&((LPWSTR
)pString
)[analysis
->pItem
[i
].iCharPos
], analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
, &analysis
->pItem
[i
].a
, &analysis
->logattrs
[analysis
->pItem
[i
].iCharPos
]);
1241 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1243 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1246 if (dwFlags
& SSA_GLYPHS
)
1249 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1252 for (i
= 0; i
< analysis
->numItems
; i
++)
1254 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1255 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1256 int numGlyphs
= 1.5 * cChar
+ 16;
1257 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1258 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1259 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1260 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1261 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1262 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1263 int numGlyphsReturned
;
1264 HFONT originalFont
= 0x0;
1266 /* FIXME: non unicode strings */
1267 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1268 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1270 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1273 heap_free (pwLogClust
);
1274 heap_free (piAdvance
);
1276 heap_free (pGoffset
);
1282 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1285 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1286 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1287 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1288 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1289 if (analysis
->glyphs
[i
].fallbackFont
)
1291 ScriptFreeCache(sc
);
1292 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1296 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1297 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1298 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1299 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1300 piAdvance
, pGoffset
, abc
);
1302 SelectObject(hdc
,originalFont
);
1304 if (dwFlags
& SSA_TAB
)
1307 for (tabi
= 0; tabi
< cChar
; tabi
++)
1309 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1310 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1311 tab_x
+=piAdvance
[tabi
];
1315 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1316 analysis
->glyphs
[i
].glyphs
= glyphs
;
1317 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1318 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1319 analysis
->glyphs
[i
].psva
= psva
;
1320 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1321 analysis
->glyphs
[i
].abc
= abc
;
1322 analysis
->glyphs
[i
].iMaxPosX
= -1;
1324 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1329 for (i
= 0; i
< analysis
->numItems
; i
++)
1330 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1333 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1334 heap_free(BidiLevel
);
1342 heap_free(analysis
->glyphs
);
1343 heap_free(analysis
->logattrs
);
1344 heap_free(analysis
->pItem
);
1345 heap_free(analysis
->logical2visual
);
1346 heap_free(analysis
);
1350 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1354 if (pva
[glyph
].fClusterStart
)
1356 for (i
= 0; i
< cChars
; i
++)
1357 if (pwLogClust
[i
] == glyph
) break;
1365 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1376 StringAnalysis
*analysis
;
1379 COLORREF BkColor
= 0x0;
1380 COLORREF TextColor
= 0x0;
1382 INT runStart
, runEnd
;
1383 INT iGlyph
, cGlyphs
;
1384 HFONT oldFont
= 0x0;
1386 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1387 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1389 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1391 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1392 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1397 BkMode
= GetBkMode(analysis
->hdc
);
1398 SetBkMode( analysis
->hdc
, OPAQUE
);
1399 BkColor
= GetBkColor(analysis
->hdc
);
1400 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1403 TextColor
= GetTextColor(analysis
->hdc
);
1404 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1407 if (analysis
->glyphs
[iItem
].fallbackFont
)
1408 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1410 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1411 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1414 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1415 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1417 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1419 if (analysis
->pItem
[iItem
].a
.fRTL
)
1421 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1422 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1424 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1428 if (cStart
>=0 && runStart
)
1429 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1431 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1434 if (analysis
->pItem
[iItem
].a
.fRTL
)
1435 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1437 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1439 if (analysis
->pItem
[iItem
].a
.fRTL
)
1440 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1442 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1446 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1451 clust_glyph
= iGlyph
+ cGlyphs
;
1452 if (analysis
->pItem
[iItem
].a
.fRTL
)
1457 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1458 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1465 hr
= ScriptTextOut(analysis
->hdc
,
1466 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1467 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1468 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1469 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1470 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1472 TRACE("ScriptTextOut hr=%08x\n", hr
);
1476 SetBkColor(analysis
->hdc
, BkColor
);
1477 SetBkMode( analysis
->hdc
, BkMode
);
1479 SetTextColor(analysis
->hdc
, TextColor
);
1481 if (analysis
->glyphs
[iItem
].fallbackFont
)
1482 SelectObject(analysis
->hdc
, oldFont
);
1487 /***********************************************************************
1488 * ScriptStringOut (USP10.@)
1490 * This function takes the output of ScriptStringAnalyse and joins the segments
1491 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1492 * only processes glyphs.
1495 * ssa [I] buffer to hold the analysed string components
1496 * iX [I] X axis displacement for output
1497 * iY [I] Y axis displacement for output
1498 * uOptions [I] flags controling output processing
1499 * prc [I] rectangle coordinates
1500 * iMinSel [I] starting pos for substringing output string
1501 * iMaxSel [I] ending pos for substringing output string
1502 * fDisabled [I] controls text highlighting
1506 * Failure: is the value returned by ScriptTextOut
1508 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1517 StringAnalysis
*analysis
;
1521 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1522 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1524 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1525 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1527 for (item
= 0; item
< analysis
->numItems
; item
++)
1529 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1534 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1536 if (iMaxSel
> 0 && iMinSel
< 0)
1538 for (item
= 0; item
< analysis
->numItems
; item
++)
1540 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1549 /***********************************************************************
1550 * ScriptStringCPtoX (USP10.@)
1553 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1557 StringAnalysis
* analysis
= ssa
;
1559 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1561 if (!ssa
|| !pX
) return S_FALSE
;
1562 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1564 /* icp out of range */
1567 analysis
->invalid
= TRUE
;
1568 return E_INVALIDARG
;
1571 for(item
=0; item
<analysis
->numItems
; item
++)
1576 i
= analysis
->logical2visual
[item
];
1577 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1578 /* initialize max extents for uninitialized runs */
1579 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1581 if (analysis
->pItem
[i
].a
.fRTL
)
1582 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1583 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1584 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1586 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1587 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1588 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1591 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1593 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1597 icp
-= analysis
->pItem
[i
].iCharPos
;
1598 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1599 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1600 &analysis
->pItem
[i
].a
, &offset
);
1607 /* icp out of range */
1608 analysis
->invalid
= TRUE
;
1609 return E_INVALIDARG
;
1612 /***********************************************************************
1613 * ScriptStringXtoCP (USP10.@)
1616 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1618 StringAnalysis
* analysis
= ssa
;
1621 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1623 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1624 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1629 if (analysis
->pItem
[0].a
.fRTL
)
1632 *piTrailing
= FALSE
;
1642 for(item
=0; item
<analysis
->numItems
; item
++)
1647 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
1650 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1651 /* initialize max extents for uninitialized runs */
1652 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1654 if (analysis
->pItem
[i
].a
.fRTL
)
1655 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1656 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1657 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1659 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1660 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1661 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1664 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
1666 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
1670 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1671 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1672 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
1673 *piCh
+= analysis
->pItem
[i
].iCharPos
;
1679 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
1680 *piTrailing
= FALSE
;
1686 /***********************************************************************
1687 * ScriptStringFree (USP10.@)
1689 * Free a string analysis.
1692 * pssa [I] string analysis.
1696 * Failure: Non-zero HRESULT value.
1698 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
1700 StringAnalysis
* analysis
;
1704 TRACE("(%p)\n", pssa
);
1706 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
1708 invalid
= analysis
->invalid
;
1710 if (analysis
->glyphs
)
1712 for (i
= 0; i
< analysis
->numItems
; i
++)
1714 heap_free(analysis
->glyphs
[i
].glyphs
);
1715 heap_free(analysis
->glyphs
[i
].pwLogClust
);
1716 heap_free(analysis
->glyphs
[i
].piAdvance
);
1717 heap_free(analysis
->glyphs
[i
].psva
);
1718 heap_free(analysis
->glyphs
[i
].pGoffset
);
1719 heap_free(analysis
->glyphs
[i
].abc
);
1720 if (analysis
->glyphs
[i
].fallbackFont
)
1721 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
1722 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
1723 heap_free(analysis
->glyphs
[i
].sc
);
1725 heap_free(analysis
->glyphs
);
1728 heap_free(analysis
->pItem
);
1729 heap_free(analysis
->logattrs
);
1730 heap_free(analysis
->sz
);
1731 heap_free(analysis
->logical2visual
);
1732 heap_free(analysis
);
1734 if (invalid
) return E_INVALIDARG
;
1738 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
1739 int direction
, int* iCluster
, int *check_out
)
1743 WORD clust
= pwLogClust
[item
];
1745 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
1747 if (pwLogClust
[check
] == clust
)
1750 if (iCluster
&& *iCluster
== -1)
1762 static inline int get_glyph_cluster_advance(const int* piAdvance
, const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cGlyphs
, int cChars
, int glyph
, int direction
)
1765 int log_clust_max
= 0;
1768 advance
= piAdvance
[glyph
];
1770 for (i
= 0; i
< cChars
; i
++)
1772 if (pwLogClust
[i
] > log_clust_max
)
1773 log_clust_max
= pwLogClust
[i
];
1776 if (glyph
> log_clust_max
)
1779 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
1782 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
1784 if (glyph
> log_clust_max
)
1786 advance
+= piAdvance
[glyph
];
1792 /***********************************************************************
1793 * ScriptCPtoX (USP10.@)
1796 HRESULT WINAPI
ScriptCPtoX(int iCP
,
1800 const WORD
*pwLogClust
,
1801 const SCRIPT_VISATTR
*psva
,
1802 const int *piAdvance
,
1803 const SCRIPT_ANALYSIS
*psa
,
1811 float special_size
= 0.0;
1816 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
1817 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
1820 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
1828 int max_clust
= pwLogClust
[0];
1830 for (item
=0; item
< cGlyphs
; item
++)
1831 if (pwLogClust
[item
] > max_clust
)
1833 ERR("We do not handle non reversed clusters properly\n");
1838 for (item
= max_clust
; item
>=0; item
--)
1839 iMaxPos
+= piAdvance
[item
];
1843 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
1845 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
1848 int clust
= pwLogClust
[item
];
1851 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
1854 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
1856 if (check
>= cChars
&& !iMaxPos
)
1858 for (check
= clust
; check
< cChars
; check
++)
1859 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
1861 special_size
/= (cChars
- item
);
1862 iPosX
+= special_size
;
1866 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
1869 if (clust_size
== 0)
1873 iPosX
+= advance
/ (float)clust_size
;
1876 else if (iSpecial
!= -1)
1877 iPosX
+= special_size
;
1878 else /* (iCluster != -1) */
1880 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
1881 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
1884 if (clust_size
== 0)
1888 iPosX
+= adv
/ (float)clust_size
;
1894 iPosX
= iMaxPos
- iPosX
;
1900 TRACE("*piX=%d\n", *piX
);
1904 /***********************************************************************
1905 * ScriptXtoCP (USP10.@)
1908 HRESULT WINAPI
ScriptXtoCP(int iX
,
1911 const WORD
*pwLogClust
,
1912 const SCRIPT_VISATTR
*psva
,
1913 const int *piAdvance
,
1914 const SCRIPT_ANALYSIS
*psa
,
1926 float special_size
= 0.0;
1929 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
1930 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
1931 psa
, piCP
, piTrailing
);
1933 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
1938 int max_clust
= pwLogClust
[0];
1947 for (item
=0; item
< cChars
; item
++)
1948 if (pwLogClust
[item
] > max_clust
)
1950 ERR("We do not handle non reversed clusters properly\n");
1962 iPosX
= iLastPosX
= 0;
1967 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
1970 if (iSpecial
== -1 &&
1973 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
1974 (direction
< 0 && iCluster
-clust_size
>= item
))
1980 int clust
= pwLogClust
[item
];
1984 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
1986 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
1988 if (check
>= cChars
&& direction
> 0)
1990 for (check
= clust
; check
< cChars
; check
++)
1991 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
1993 special_size
/= (cChars
- item
);
1994 iPosX
+= special_size
;
1998 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2005 iPosX
+= advance
/ (float)clust_size
;
2008 else if (iSpecial
!= -1)
2009 iPosX
+= special_size
;
2010 else /* (iCluster != -1) */
2012 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2013 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2020 iPosX
+= adv
/ (float)clust_size
;
2028 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2030 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2031 item
+=(clust_size
-1);
2039 if (iX
== iLastPosX
)
2041 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2044 if (iLastPosX
== iX
)
2046 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2048 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2049 item
-=(clust_size
-1);
2058 TRACE("*piCP=%d\n", *piCP
);
2059 TRACE("*piTrailing=%d\n", *piTrailing
);
2063 /***********************************************************************
2064 * ScriptBreak (USP10.@)
2066 * Retrieve line break information.
2069 * chars [I] Array of characters.
2070 * sa [I] String analysis.
2071 * la [I] Array of logical attribute structures.
2077 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2079 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2081 if (!la
) return S_FALSE
;
2083 BREAK_line(chars
, count
, sa
, la
);
2088 /***********************************************************************
2089 * ScriptIsComplex (USP10.@)
2091 * Determine if a string is complex.
2094 * chars [I] Array of characters to test.
2095 * len [I] Length in characters.
2103 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2107 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2109 for (i
= 0; i
< len
; i
++)
2113 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2116 script
= get_char_script(chars
[i
]);
2117 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2118 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2124 /***********************************************************************
2125 * ScriptShapeOpenType (USP10.@)
2127 * Produce glyphs and visual attributes for a run.
2130 * hdc [I] Device context.
2131 * psc [I/O] Opaque pointer to a script cache.
2132 * psa [I/O] Script analysis.
2133 * tagScript [I] The OpenType tag for the Script
2134 * tagLangSys [I] The OpenType tag for the Language
2135 * rcRangeChars[I] Array of Character counts in each range
2136 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2137 * cRanges [I] Count of ranges
2138 * pwcChars [I] Array of characters specifying the run.
2139 * cChars [I] Number of characters in pwcChars.
2140 * cMaxGlyphs [I] Length of pwOutGlyphs.
2141 * pwLogClust [O] Array of logical cluster info.
2142 * pCharProps [O] Array of character property values
2143 * pwOutGlyphs [O] Array of glyphs.
2144 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2145 * pcGlyphs [O] Number of glyphs returned.
2149 * Failure: Non-zero HRESULT value.
2151 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2152 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2153 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2154 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2155 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2156 int cMaxGlyphs
, WORD
*pwLogClust
,
2157 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2158 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2164 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2166 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2167 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2168 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2170 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2171 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2173 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2174 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2177 FIXME("Ranges not supported yet\n");
2179 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2182 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2183 if (!pwLogClust
) return E_FAIL
;
2185 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2186 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2188 /* set fNoGlyphIndex non truetype/opentype fonts */
2189 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2190 psa
->fNoGlyphIndex
= TRUE
;
2192 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2193 for (i
= 0; i
< cChars
; i
++)
2196 if (rtl
) idx
= cChars
- 1 - i
;
2197 /* FIXME: set to better values */
2198 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2199 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2200 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2201 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2202 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2203 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2205 /* FIXME: have the shaping engine set this */
2206 pCharProps
[i
].fCanGlyphAlone
= 0;
2208 pwLogClust
[i
] = idx
;
2211 if (psa
&& !psa
->fNoGlyphIndex
)
2214 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2216 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2217 if (!rChars
) return E_OUTOFMEMORY
;
2218 for (i
= 0; i
< cChars
; i
++)
2222 if (rtl
) idx
= cChars
- 1 - i
;
2224 chInput
= mirror_char(pwcChars
[idx
]);
2226 chInput
= pwcChars
[idx
];
2227 /* special case for tabs */
2228 if (chInput
== 0x0009)
2230 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2233 if (!hdc
) return E_PENDING
;
2234 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
) return S_FALSE
;
2235 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2237 rChars
[i
] = chInput
;
2240 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2241 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2242 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2247 TRACE("no glyph translation\n");
2248 for (i
= 0; i
< cChars
; i
++)
2251 /* No mirroring done here */
2252 if (rtl
) idx
= cChars
- 1 - i
;
2253 pwOutGlyphs
[i
] = pwcChars
[idx
];
2261 /***********************************************************************
2262 * ScriptShape (USP10.@)
2264 * Produce glyphs and visual attributes for a run.
2267 * hdc [I] Device context.
2268 * psc [I/O] Opaque pointer to a script cache.
2269 * pwcChars [I] Array of characters specifying the run.
2270 * cChars [I] Number of characters in pwcChars.
2271 * cMaxGlyphs [I] Length of pwOutGlyphs.
2272 * psa [I/O] Script analysis.
2273 * pwOutGlyphs [O] Array of glyphs.
2274 * pwLogClust [O] Array of logical cluster info.
2275 * psva [O] Array of visual attributes.
2276 * pcGlyphs [O] Number of glyphs returned.
2280 * Failure: Non-zero HRESULT value.
2282 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2283 int cChars
, int cMaxGlyphs
,
2284 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2285 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2289 SCRIPT_CHARPROP
*charProps
;
2290 SCRIPT_GLYPHPROP
*glyphProps
;
2292 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2293 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2295 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2296 if (!charProps
) return E_OUTOFMEMORY
;
2297 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2298 if (!glyphProps
) return E_OUTOFMEMORY
;
2300 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2304 for (i
= 0; i
< *pcGlyphs
; i
++)
2305 psva
[i
] = glyphProps
[i
].sva
;
2308 heap_free(charProps
);
2309 heap_free(glyphProps
);
2314 /***********************************************************************
2315 * ScriptPlaceOpenType (USP10.@)
2317 * Produce advance widths for a run.
2320 * hdc [I] Device context.
2321 * psc [I/O] Opaque pointer to a script cache.
2322 * psa [I/O] String analysis.
2323 * tagScript [I] The OpenType tag for the Script
2324 * tagLangSys [I] The OpenType tag for the Language
2325 * rcRangeChars[I] Array of Character counts in each range
2326 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2327 * cRanges [I] Count of ranges
2328 * pwcChars [I] Array of characters specifying the run.
2329 * pwLogClust [I] Array of logical cluster info
2330 * pCharProps [I] Array of character property values
2331 * cChars [I] Number of characters in pwcChars.
2332 * pwGlyphs [I] Array of glyphs.
2333 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2334 * cGlyphs [I] Count of Glyphs
2335 * piAdvance [O] Array of advance widths.
2336 * pGoffset [O] Glyph offsets.
2337 * pABC [O] Combined ABC width.
2341 * Failure: Non-zero HRESULT value.
2344 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2345 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2346 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2347 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2348 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2349 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2350 int cGlyphs
, int *piAdvance
,
2351 GOFFSET
*pGoffset
, ABC
*pABC
2357 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2359 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2360 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2361 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2364 if (!pGlyphProps
) return E_INVALIDARG
;
2365 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2366 if (!pGoffset
) return E_FAIL
;
2369 FIXME("Ranges not supported yet\n");
2371 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2372 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2374 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2375 for (i
= 0; i
< cGlyphs
; i
++)
2378 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2380 if (!hdc
) return E_PENDING
;
2381 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2383 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2388 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2390 abc
.abcA
= abc
.abcC
= 0;
2392 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2396 pABC
->abcA
+= abc
.abcA
;
2397 pABC
->abcB
+= abc
.abcB
;
2398 pABC
->abcC
+= abc
.abcC
;
2400 /* FIXME: set to more reasonable values */
2401 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2402 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2405 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2409 /***********************************************************************
2410 * ScriptPlace (USP10.@)
2412 * Produce advance widths for a run.
2415 * hdc [I] Device context.
2416 * psc [I/O] Opaque pointer to a script cache.
2417 * pwGlyphs [I] Array of glyphs.
2418 * cGlyphs [I] Number of glyphs in pwGlyphs.
2419 * psva [I] Array of visual attributes.
2420 * psa [I/O] String analysis.
2421 * piAdvance [O] Array of advance widths.
2422 * pGoffset [O] Glyph offsets.
2423 * pABC [O] Combined ABC width.
2427 * Failure: Non-zero HRESULT value.
2429 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2430 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2431 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2434 SCRIPT_GLYPHPROP
*glyphProps
;
2437 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2438 piAdvance
, pGoffset
, pABC
);
2440 if (!psva
) return E_INVALIDARG
;
2441 if (!pGoffset
) return E_FAIL
;
2443 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2444 if (!glyphProps
) return E_OUTOFMEMORY
;
2446 for (i
= 0; i
< cGlyphs
; i
++)
2447 glyphProps
[i
].sva
= psva
[i
];
2449 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2451 heap_free(glyphProps
);
2456 /***********************************************************************
2457 * ScriptGetCMap (USP10.@)
2459 * Retrieve glyph indices.
2462 * hdc [I] Device context.
2463 * psc [I/O] Opaque pointer to a script cache.
2464 * pwcInChars [I] Array of Unicode characters.
2465 * cChars [I] Number of characters in pwcInChars.
2466 * dwFlags [I] Flags.
2467 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2471 * Failure: Non-zero HRESULT value.
2473 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2474 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2479 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2480 cChars
, dwFlags
, pwOutGlyphs
);
2482 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2486 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2488 for (i
= 0; i
< cChars
; i
++)
2491 if (dwFlags
== SGCM_RTL
)
2492 inChar
= mirror_char(pwcInChars
[i
]);
2494 inChar
= pwcInChars
[i
];
2495 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2498 if (!hdc
) return E_PENDING
;
2499 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2500 if (glyph
== 0xffff)
2505 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2511 TRACE("no glyph translation\n");
2512 for (i
= 0; i
< cChars
; i
++)
2515 if (dwFlags
== SGCM_RTL
)
2516 inChar
= mirror_char(pwcInChars
[i
]);
2518 inChar
= pwcInChars
[i
];
2519 pwOutGlyphs
[i
] = inChar
;
2525 /***********************************************************************
2526 * ScriptTextOut (USP10.@)
2529 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2530 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2531 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2532 const int *piJustify
, const GOFFSET
*pGoffset
)
2536 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2537 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2538 piAdvance
, piJustify
, pGoffset
);
2540 if (!hdc
|| !psc
) return E_INVALIDARG
;
2541 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2543 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2544 fuOptions
|= ETO_IGNORELANGUAGE
;
2545 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2546 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2548 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2553 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2555 return E_OUTOFMEMORY
;
2557 for (i
= 0; i
< cGlyphs
; i
++)
2558 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2560 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2562 heap_free(rtlGlyphs
);
2565 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2571 /***********************************************************************
2572 * ScriptCacheGetHeight (USP10.@)
2574 * Retrieve the height of the font in the cache.
2577 * hdc [I] Device context.
2578 * psc [I/O] Opaque pointer to a script cache.
2579 * height [O] Receives font height.
2583 * Failure: Non-zero HRESULT value.
2585 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2589 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2591 if (!height
) return E_INVALIDARG
;
2592 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2594 *height
= get_cache_height(psc
);
2598 /***********************************************************************
2599 * ScriptGetGlyphABCWidth (USP10.@)
2601 * Retrieve the width of a glyph.
2604 * hdc [I] Device context.
2605 * psc [I/O] Opaque pointer to a script cache.
2606 * glyph [I] Glyph to retrieve the width for.
2607 * abc [O] ABC widths of the glyph.
2611 * Failure: Non-zero HRESULT value.
2613 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2617 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2619 if (!abc
) return E_INVALIDARG
;
2620 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2622 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
2624 if (!hdc
) return E_PENDING
;
2625 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2627 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
2632 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
2634 abc
->abcA
= abc
->abcC
= 0;
2636 set_cache_glyph_widths(psc
, glyph
, abc
);
2641 /***********************************************************************
2642 * ScriptLayout (USP10.@)
2644 * Map embedding levels to visual and/or logical order.
2647 * runs [I] Size of level array.
2648 * level [I] Array of embedding levels.
2649 * vistolog [O] Map of embedding levels from visual to logical order.
2650 * logtovis [O] Map of embedding levels from logical to visual order.
2654 * Failure: Non-zero HRESULT value.
2657 * This stub works correctly for any sequence of a single
2658 * embedding level but not for sequences of different
2659 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2661 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
2666 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
2668 if (!level
|| (!vistolog
&& !logtovis
))
2669 return E_INVALIDARG
;
2671 indexs
= heap_alloc(sizeof(int) * runs
);
2673 return E_OUTOFMEMORY
;
2678 for( ich
= 0; ich
< runs
; ich
++)
2683 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2684 for (ich
= 0; ich
< runs
; ich
++)
2685 vistolog
[ich
] = indexs
[ich
];
2691 for( ich
= 0; ich
< runs
; ich
++)
2696 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2697 for (ich
= 0; ich
< runs
; ich
++)
2698 logtovis
[ich
] = indexs
[ich
];
2705 /***********************************************************************
2706 * ScriptStringGetLogicalWidths (USP10.@)
2708 * Returns logical widths from a string analysis.
2711 * ssa [I] string analysis.
2712 * piDx [O] logical widths returned.
2716 * Failure: a non-zero HRESULT.
2718 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
2721 StringAnalysis
*analysis
= ssa
;
2723 TRACE("%p, %p\n", ssa
, piDx
);
2725 if (!analysis
) return S_FALSE
;
2726 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2728 for (i
= 0; i
< analysis
->numItems
; i
++)
2730 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2733 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
2736 for (j
= 0; j
< cChar
; j
++)
2739 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
2740 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
2741 cChar
, j
, direction
, NULL
, NULL
);
2742 int advance
= get_glyph_cluster_advance(analysis
->glyphs
[i
].piAdvance
, analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].pwLogClust
, analysis
->glyphs
[i
].numGlyphs
, cChar
, glyph
, direction
);
2744 for (k
= 0; k
< clust_size
; k
++)
2746 piDx
[next
] = advance
/ clust_size
;
2755 /***********************************************************************
2756 * ScriptStringValidate (USP10.@)
2758 * Validate a string analysis.
2761 * ssa [I] string analysis.
2765 * Failure: S_FALSE if invalid sequences are found
2766 * or a non-zero HRESULT if it fails.
2768 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
2770 StringAnalysis
*analysis
= ssa
;
2772 TRACE("(%p)\n", ssa
);
2774 if (!analysis
) return E_INVALIDARG
;
2775 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
2778 /***********************************************************************
2779 * ScriptString_pSize (USP10.@)
2781 * Retrieve width and height of an analysed string.
2784 * ssa [I] string analysis.
2787 * Success: Pointer to a SIZE structure.
2790 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
2793 StringAnalysis
*analysis
= ssa
;
2795 TRACE("(%p)\n", ssa
);
2797 if (!analysis
) return NULL
;
2798 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
2802 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
2803 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
2805 analysis
->sz
->cx
= 0;
2806 for (i
= 0; i
< analysis
->numItems
; i
++)
2808 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
2809 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
2810 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
2811 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
2814 return analysis
->sz
;
2817 /***********************************************************************
2818 * ScriptString_pLogAttr (USP10.@)
2820 * Retrieve logical attributes of an analysed string.
2823 * ssa [I] string analysis.
2826 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
2829 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
2831 StringAnalysis
*analysis
= ssa
;
2833 TRACE("(%p)\n", ssa
);
2835 if (!analysis
) return NULL
;
2836 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
2837 return analysis
->logattrs
;
2840 /***********************************************************************
2841 * ScriptString_pcOutChars (USP10.@)
2843 * Retrieve the length of a string after clipping.
2846 * ssa [I] String analysis.
2849 * Success: Pointer to the length.
2852 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
2854 StringAnalysis
*analysis
= ssa
;
2856 TRACE("(%p)\n", ssa
);
2858 if (!analysis
) return NULL
;
2859 return &analysis
->clip_len
;
2862 /***********************************************************************
2863 * ScriptStringGetOrder (USP10.@)
2865 * Retrieve a glyph order map.
2868 * ssa [I] String analysis.
2869 * order [I/O] Array of glyph positions.
2873 * Failure: a non-zero HRESULT.
2875 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
2879 StringAnalysis
*analysis
= ssa
;
2881 TRACE("(%p)\n", ssa
);
2883 if (!analysis
) return S_FALSE
;
2884 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2886 /* FIXME: handle RTL scripts */
2887 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
2888 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
2894 /***********************************************************************
2895 * ScriptGetLogicalWidths (USP10.@)
2897 * Convert advance widths to logical widths.
2900 * sa [I] Script analysis.
2901 * nbchars [I] Number of characters.
2902 * nbglyphs [I] Number of glyphs.
2903 * glyph_width [I] Array of glyph widths.
2904 * log_clust [I] Array of logical clusters.
2905 * sva [I] Visual attributes.
2906 * widths [O] Array of logical widths.
2910 * Failure: a non-zero HRESULT.
2912 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
2913 const int *glyph_width
, const WORD
*log_clust
,
2914 const SCRIPT_VISATTR
*sva
, int *widths
)
2918 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
2919 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
2922 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
2926 /***********************************************************************
2927 * ScriptApplyLogicalWidth (USP10.@)
2929 * Generate glyph advance widths.
2932 * dx [I] Array of logical advance widths.
2933 * num_chars [I] Number of characters.
2934 * num_glyphs [I] Number of glyphs.
2935 * log_clust [I] Array of logical clusters.
2936 * sva [I] Visual attributes.
2937 * advance [I] Array of glyph advance widths.
2938 * sa [I] Script analysis.
2939 * abc [I/O] Summed ABC widths.
2940 * justify [O] Array of glyph advance widths.
2944 * Failure: a non-zero HRESULT.
2946 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
2947 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
2948 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
2949 ABC
*abc
, int *justify
)
2953 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
2954 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
2956 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
2960 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
2961 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
2965 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
2967 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];