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 { Script_Latin
, 0x00, 0x07a , Script_Numeric
, Script_Punctuation
},
56 /* Latin-1 Supplement: U+0080–U+00FF */
57 /* Latin Extended-A: U+0100–U+017F */
58 /* Latin Extended-B: U+0180–U+024F */
59 /* IPA Extensions: U+0250–U+02AF */
60 { Script_Latin
, 0x80, 0x2af , Script_Numeric2
, Script_Punctuation
},
61 /* Combining Diacritical Marks : U+0300–U+036F */
62 { Script_Diacritical
,0x300, 0x36f, 0, 0},
63 /* Greek: U+0370–U+03FF */
64 { Script_Greek
, 0x370, 0x3ff, 0, 0},
65 /* Cyrillic: U+0400–U+04FF */
66 /* Cyrillic Supplement: U+0500–U+052F */
67 { Script_Cyrillic
, 0x400, 0x52f, 0, 0},
68 /* Armenian: U+0530–U+058F */
69 { Script_Armenian
, 0x530, 0x58f, 0, 0},
70 /* Hebrew: U+0590–U+05FF */
71 { Script_Hebrew
, 0x590, 0x5ff, 0, 0},
72 /* Arabic: U+0600–U+06FF */
73 { Script_Arabic
, 0x600, 0x6ef, Script_Arabic_Numeric
, 0},
74 /* Defined by Windows */
75 { Script_Persian
, 0x6f0, 0x6f9, 0, 0},
76 /* Continue Arabic: U+0600–U+06FF */
77 { Script_Arabic
, 0x6fa, 0x6ff, 0, 0},
78 /* Syriac: U+0700–U+074F*/
79 { Script_Syriac
, 0x700, 0x74f, 0, 0},
80 /* Arabic Supplement: U+0750–U+077F */
81 { Script_Arabic
, 0x750, 0x77f, 0, 0},
82 /* Thaana: U+0780–U+07BF */
83 { Script_Thaana
, 0x780, 0x7bf, 0, 0},
84 /* Devanagari: U+0900–U+097F */
85 { Script_Devanagari
, 0x900, 0x97f, Script_Devanagari_Numeric
, 0},
86 /* Bengali: U+0980–U+09FF */
87 { Script_Bengali
, 0x980, 0x9ff, Script_Bengali_Numeric
, 0},
88 /* Gurmukhi: U+0A00–U+0A7F*/
89 { Script_Gurmukhi
, 0xa00, 0xa7f, Script_Gurmukhi_Numeric
, 0},
90 /* Gujarati: U+0A80–U+0AFF*/
91 { Script_Gujarati
, 0xa80, 0xaff, Script_Gujarati_Numeric
, 0},
92 /* Oriya: U+0B00–U+0B7F */
93 { Script_Oriya
, 0xb00, 0xb7f, Script_Oriya_Numeric
, 0},
94 /* Tamil: U+0B80–U+0BFF */
95 { Script_Tamil
, 0xb80, 0xbff, Script_Tamil_Numeric
, 0},
96 /* Telugu: U+0C00–U+0C7F */
97 { Script_Telugu
, 0xc00, 0xc7f, Script_Telugu_Numeric
, 0},
98 /* Kannada: U+0C80–U+0CFF */
99 { Script_Kannada
, 0xc80, 0xcff, Script_Kannada_Numeric
, 0},
100 /* Malayalam: U+0D00–U+0D7F */
101 { Script_Malayalam
, 0xd00, 0xd7f, Script_Malayalam_Numeric
, 0},
102 /* Sinhala: U+0D80–U+0DFF */
103 { Script_Sinhala
, 0xd80, 0xdff, 0, 0},
104 /* Thai: U+0E00–U+0E7F */
105 { Script_Thai
, 0xe00, 0xe7f, Script_Thai_Numeric
, 0},
106 /* Lao: U+0E80–U+0EFF */
107 { Script_Lao
, 0xe80, 0xeff, Script_Lao_Numeric
, 0},
108 /* Tibetan: U+0F00–U+0FFF */
109 { Script_Tibetan
, 0xf00, 0xfff, 0, 0},
110 /* Georgian: U+10A0–U+10FF */
111 { Script_Georgian
, 0x10a0, 0x10ff, 0, 0},
112 /* Vedic Extensions: U+1CD0-U+1CFF */
113 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
114 /* Phonetic Extensions: U+1D00–U+1DBF */
115 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
116 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
117 { Script_Diacritical
,0x1dc0, 0x1dff, 0, 0},
118 /* Latin Extended Additional: U+1E00–U+1EFF */
119 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
120 /* Greek Extended: U+1F00–U+1FFF */
121 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
122 /* General Punctuation: U+2000 –U+206f */
123 { Script_Latin
, 0x2000, 0x206f, 0, 0},
124 /* Superscripts and Subscripts : U+2070 –U+209f */
125 /* Currency Symbols : U+20a0 –U+20cf */
126 { Script_Numeric2
, 0x2070, 0x2070, 0, 0},
127 { Script_Latin
, 0x2071, 0x2073, 0, 0},
128 { Script_Numeric2
, 0x2074, 0x2079, 0, 0},
129 { Script_Latin
, 0x207a, 0x207f, 0, 0},
130 { Script_Numeric2
, 0x2080, 0x2089, 0, 0},
131 { Script_Latin
, 0x208a, 0x20cf, 0, 0},
132 /* Letterlike Symbols : U+2100 –U+214f */
133 /* Number Forms : U+2150 –U+218f */
134 /* Arrows : U+2190 –U+21ff */
135 /* Mathematical Operators : U+2200 –U+22ff */
136 /* Miscellaneous Technical : U+2300 –U+23ff */
137 /* Control Pictures : U+2400 –U+243f */
138 /* Optical Character Recognition : U+2440 –U+245f */
139 /* Enclosed Alphanumerics : U+2460 –U+24ff */
140 /* Box Drawing : U+2500 –U+25ff */
141 /* Block Elements : U+2580 –U+259f */
142 /* Geometric Shapes : U+25a0 –U+25ff */
143 /* Miscellaneous Symbols : U+2600 –U+26ff */
144 /* Dingbats : U+2700 –U+27bf */
145 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
146 /* Supplemental Arrows-A : U+27f0 –U+27ff */
147 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
148 /* Supplemental Arrows-B : U+2900 –U+297f */
149 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
150 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
151 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
152 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
153 /* Latin Extended-C: U+2C60–U+2C7F */
154 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
155 /* Georgian: U+2D00–U+2D2F */
156 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
157 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
158 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
159 /* Cyrillic Extended-B: U+A640–U+A69F */
160 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
161 /* Modifier Tone Letters: U+A700–U+A71F */
162 /* Latin Extended-D: U+A720–U+A7FF */
163 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
164 /* Phags-pa: U+A840–U+A87F */
165 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
166 /* Devanagari Extended: U+A8E0-U+A8FF */
167 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
168 /* Latin Ligatures: U+FB00–U+FB06 */
169 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
170 /* Armenian ligatures U+FB13..U+FB17 */
171 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
172 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
173 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
174 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
175 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
176 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
177 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
179 { SCRIPT_UNDEFINED
, 0, 0, 0}
182 typedef struct _scriptData
185 SCRIPT_PROPERTIES props
;
186 OPENTYPE_TAG scriptTag
;
187 WCHAR fallbackFont
[LF_FACESIZE
];
190 /* the must be in order so that the index matches the Script value */
191 static const scriptData scriptInformation
[] = {
192 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
193 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
196 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
197 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
198 MS_MAKE_TAG('l','a','t','n'),
200 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
201 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
204 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
205 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
208 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
209 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
212 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
213 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
216 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
217 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 0},
218 MS_MAKE_TAG('a','r','a','b'),
219 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
220 {{Script_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
221 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
222 MS_MAKE_TAG('a','r','a','b'),
223 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
224 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
225 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
226 MS_MAKE_TAG('h','e','b','r'),
227 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
228 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
229 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 0},
230 MS_MAKE_TAG('s','y','r','c'),
231 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
232 {{Script_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
233 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
234 MS_MAKE_TAG('s','y','r','c'),
235 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
236 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
237 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
238 MS_MAKE_TAG('t','h','a','a'),
239 {'M','V',' ','B','o','l','i',0}},
240 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
241 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
242 MS_MAKE_TAG('g','r','e','k'),
244 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
245 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
246 MS_MAKE_TAG('c','y','r','l'),
248 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
249 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
250 MS_MAKE_TAG('a','r','m','n'),
251 {'S','y','l','f','a','e','n',0}},
252 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
253 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
254 MS_MAKE_TAG('g','e','o','r'),
255 {'S','y','l','f','a','e','n',0}},
256 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
257 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
258 MS_MAKE_TAG('s','i','n','h'),
259 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
260 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
261 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
262 MS_MAKE_TAG('t','i','b','t'),
263 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
264 {{Script_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
265 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
266 MS_MAKE_TAG('t','i','b','t'),
267 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
268 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
269 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
270 MS_MAKE_TAG('p','h','a','g'),
271 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
272 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
273 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
274 MS_MAKE_TAG('t','h','a','i'),
275 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
276 {{Script_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
277 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
278 MS_MAKE_TAG('t','h','a','i'),
279 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
280 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
281 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
282 MS_MAKE_TAG('l','a','o',' '),
283 {'D','o','k','C','h','a','m','p','a',0}},
284 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
285 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
286 MS_MAKE_TAG('l','a','o',' '),
287 {'D','o','k','C','h','a','m','p','a',0}},
288 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
289 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
290 MS_MAKE_TAG('d','e','v','a'),
291 {'M','a','n','g','a','l',0}},
292 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
293 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
294 MS_MAKE_TAG('d','e','v','a'),
295 {'M','a','n','g','a','l',0}},
296 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
297 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
298 MS_MAKE_TAG('b','e','n','g'),
299 {'V','r','i','n','d','a',0}},
300 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
301 {LANG_BENGALI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
302 MS_MAKE_TAG('b','e','n','g'),
303 {'V','r','i','n','d','a',0}},
304 {{Script_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
305 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
306 MS_MAKE_TAG('b','e','n','g'),
307 {'V','r','i','n','d','a',0}},
308 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
309 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
310 MS_MAKE_TAG('g','u','r','u'),
311 {'R','a','a','v','i',0}},
312 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
313 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
314 MS_MAKE_TAG('g','u','r','u'),
315 {'R','a','a','v','i',0}},
316 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
317 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
318 MS_MAKE_TAG('g','u','j','r'),
319 {'S','h','r','u','t','i',0}},
320 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
321 {LANG_GUJARATI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
322 MS_MAKE_TAG('g','u','j','r'),
323 {'S','h','r','u','t','i',0}},
324 {{Script_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
325 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
326 MS_MAKE_TAG('g','u','j','r'),
327 {'S','h','r','u','t','i',0}},
328 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
329 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
330 MS_MAKE_TAG('o','r','y','a'),
331 {'K','a','l','i','n','g','a',0}},
332 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
333 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
334 MS_MAKE_TAG('o','r','y','a'),
335 {'K','a','l','i','n','g','a',0}},
336 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
337 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
338 MS_MAKE_TAG('t','a','m','l'),
339 {'L','a','t','h','a',0}},
340 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
341 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
342 MS_MAKE_TAG('t','a','m','l'),
343 {'L','a','t','h','a',0}},
344 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
345 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
346 MS_MAKE_TAG('t','e','l','u'),
347 {'G','a','u','t','a','m','i',0}},
348 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
349 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
350 MS_MAKE_TAG('t','e','l','u'),
351 {'G','a','u','t','a','m','i',0}},
352 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
353 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
354 MS_MAKE_TAG('k','n','d','a'),
355 {'T','u','n','g','a',0}},
356 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
357 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
358 MS_MAKE_TAG('k','n','d','a'),
359 {'T','u','n','g','a',0}},
360 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
361 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
362 MS_MAKE_TAG('m','l','y','m'),
363 {'K','a','r','t','i','k','a',0}},
364 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
365 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
366 MS_MAKE_TAG('m','l','y','m'),
367 {'K','a','r','t','i','k','a',0}},
368 {{Script_Diacritical
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
369 {LANG_ENGLISH
, 0, 1, 0, 1, ANSI_CHARSET
, 0, 0, 0, 0, 0, 1, 1, 0, 0},
372 {{Script_Punctuation2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
373 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
374 MS_MAKE_TAG('l','a','t','n'),
376 {{Script_Numeric2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
377 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
382 static const SCRIPT_PROPERTIES
*script_props
[] =
384 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
385 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
386 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
387 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
388 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
389 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
390 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
391 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
392 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
393 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
394 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
395 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
396 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
397 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
398 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
399 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
400 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
401 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
402 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
403 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
404 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
405 &scriptInformation
[42].props
, &scriptInformation
[43].props
,
406 &scriptInformation
[44].props
, &scriptInformation
[45].props
415 SCRIPT_VISATTR
* psva
;
431 StringGlyphs
* glyphs
;
432 SCRIPT_LOGATTR
* logattrs
;
437 static inline void *heap_alloc(SIZE_T size
)
439 return HeapAlloc(GetProcessHeap(), 0, size
);
442 static inline void *heap_alloc_zero(SIZE_T size
)
444 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
447 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
449 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
452 static inline BOOL
heap_free(LPVOID mem
)
454 return HeapFree(GetProcessHeap(), 0, mem
);
457 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
459 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
462 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
464 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
467 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
469 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
472 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
474 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
476 if (!block
) return 0;
477 return block
[c
& GLYPH_BLOCK_MASK
];
480 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
482 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
484 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
485 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
488 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
490 static const ABC nil
;
491 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
493 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
494 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
498 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
500 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
502 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
503 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
507 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
511 if (!psc
) return E_INVALIDARG
;
512 if (*psc
) return S_OK
;
513 if (!hdc
) return E_PENDING
;
515 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
516 if (!GetTextMetricsW(hdc
, &sc
->tm
))
521 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
526 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
528 TRACE("<- %p\n", sc
);
532 static WCHAR
mirror_char( WCHAR ch
)
534 extern const WCHAR wine_mirror_map
[];
535 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
538 static WORD
get_char_script( WCHAR ch
)
540 static const WCHAR latin_punc
[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
544 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
547 /* These punctuation are seperated out as Latin punctuation */
548 if (strchrW(latin_punc
,ch
))
549 return Script_Punctuation2
;
551 /* These chars are itemized as Punctuation by Windows */
552 if (ch
== 0x2212 || ch
== 0x2044)
553 return Script_Punctuation
;
555 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
558 return SCRIPT_UNDEFINED
;
561 return Script_Control
;
566 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
569 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
571 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
572 return scriptRanges
[i
].numericScript
;
573 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
574 return scriptRanges
[i
].punctScript
;
575 return scriptRanges
[i
].script
;
580 return SCRIPT_UNDEFINED
;
583 /***********************************************************************
587 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
591 case DLL_PROCESS_ATTACH
:
592 DisableThreadLibraryCalls(hInstDLL
);
594 case DLL_PROCESS_DETACH
:
600 /***********************************************************************
601 * ScriptFreeCache (USP10.@)
603 * Free a script cache.
606 * psc [I/O] Script cache.
610 * Failure: Non-zero HRESULT value.
612 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
619 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
621 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
622 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
624 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
625 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
626 heap_free(((ScriptCache
*)*psc
)->features
);
633 /***********************************************************************
634 * ScriptGetProperties (USP10.@)
636 * Retrieve a list of script properties.
639 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
640 * num [I] Pointer to the number of scripts.
644 * Failure: Non-zero HRESULT value.
647 * Behaviour matches WinXP.
649 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
651 TRACE("(%p,%p)\n", props
, num
);
653 if (!props
&& !num
) return E_INVALIDARG
;
655 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
656 if (props
) *props
= script_props
;
661 /***********************************************************************
662 * ScriptGetFontProperties (USP10.@)
664 * Get information on special glyphs.
667 * hdc [I] Device context.
668 * psc [I/O] Opaque pointer to a script cache.
669 * sfp [O] Font properties structure.
671 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
675 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
677 if (!sfp
) return E_INVALIDARG
;
678 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
680 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
683 /* return something sensible? */
685 sfp
->wgDefault
= get_cache_default_char(psc
);
687 sfp
->wgKashida
= 0xffff;
688 sfp
->iKashidaWidth
= 0;
693 /***********************************************************************
694 * ScriptRecordDigitSubstitution (USP10.@)
696 * Record digit substitution settings for a given locale.
699 * locale [I] Locale identifier.
700 * sds [I] Structure to record substitution settings.
704 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
707 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
709 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
713 TRACE("0x%x, %p\n", locale
, sds
);
715 /* This implementation appears to be correct for all languages, but it's
716 * not clear if sds->DigitSubstitute is ever set to anything except
717 * CONTEXT or NONE in reality */
719 if (!sds
) return E_POINTER
;
721 locale
= ConvertDefaultLocale(locale
);
723 if (!IsValidLocale(locale
, LCID_INSTALLED
))
726 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
727 sds
->TraditionalDigitLanguage
= plgid
;
729 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
730 sds
->NationalDigitLanguage
= plgid
;
732 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
734 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
735 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
740 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
741 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
743 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
746 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
749 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
752 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
760 /***********************************************************************
761 * ScriptApplyDigitSubstitution (USP10.@)
763 * Apply digit substitution settings.
766 * sds [I] Structure with recorded substitution settings.
767 * sc [I] Script control structure.
768 * ss [I] Script state structure.
772 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
774 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
775 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
777 SCRIPT_DIGITSUBSTITUTE psds
;
779 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
781 if (!sc
|| !ss
) return E_POINTER
;
785 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
789 sc
->uDefaultLanguage
= LANG_ENGLISH
;
790 sc
->fContextDigits
= 0;
791 ss
->fDigitSubstitute
= 0;
793 switch (sds
->DigitSubstitute
) {
794 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
795 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
796 case SCRIPT_DIGITSUBSTITUTE_NONE
:
797 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
804 static inline BOOL
is_indic(WORD script
)
806 return (script
>= Script_Devanagari
&& script
<= Script_Malayalam_Numeric
);
809 static inline WORD
base_indic(WORD script
)
813 case Script_Devanagari
:
814 case Script_Devanagari_Numeric
: return Script_Devanagari
;
816 case Script_Bengali_Numeric
:
817 case Script_Bengali_Currency
: return Script_Bengali
;
818 case Script_Gurmukhi
:
819 case Script_Gurmukhi_Numeric
: return Script_Gurmukhi
;
820 case Script_Gujarati
:
821 case Script_Gujarati_Numeric
:
822 case Script_Gujarati_Currency
: return Script_Gujarati
;
824 case Script_Oriya_Numeric
: return Script_Oriya
;
826 case Script_Tamil_Numeric
: return Script_Tamil
;
828 case Script_Telugu_Numeric
: return Script_Telugu
;
830 case Script_Kannada_Numeric
: return Script_Kannada
;
831 case Script_Malayalam
:
832 case Script_Malayalam_Numeric
: return Script_Malayalam
;
838 /***********************************************************************
839 * ScriptItemizeOpenType (USP10.@)
841 * Split a Unicode string into shapeable parts.
844 * pwcInChars [I] String to split.
845 * cInChars [I] Number of characters in pwcInChars.
846 * cMaxItems [I] Maximum number of items to return.
847 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
848 * psState [I] Pointer to a SCRIPT_STATE structure.
849 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
850 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
851 * pcItems [O] Number of script items returned.
855 * Failure: Non-zero HRESULT value.
857 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
858 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
859 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
862 #define Numeric_space 0x0020
866 int cnt
= 0, index
= 0, str
= 0;
870 WORD
*strength
= NULL
;
871 WORD
*scripts
= NULL
;
874 WORD last_indic
= -1;
876 BOOL forceLevels
= FALSE
;
878 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
879 psControl
, psState
, pItems
, pcItems
);
881 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
884 scripts
= heap_alloc(cInChars
* sizeof(WORD
));
886 return E_OUTOFMEMORY
;
888 for (i
= 0; i
< cInChars
; i
++)
890 scripts
[i
] = get_char_script(pwcInChars
[i
]);
891 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
893 if ((pwcInChars
[i
] == 0x964 || pwcInChars
[i
] ==0x965) && last_indic
> 0)
894 scripts
[i
] = last_indic
;
895 else if (is_indic(scripts
[i
]))
896 last_indic
= base_indic(scripts
[i
]);
898 /* Some unicode points (Zero Width Space U+200B -
899 Right-to-Left Mark U+200F) will force us into bidi mode */
900 if (!forceLevels
&& pwcInChars
[i
] >= 0x200B && pwcInChars
[i
] <= 0x200F)
903 /* Diacritical marks merge with other scripts */
904 if (scripts
[i
] == Script_Diacritical
&& i
> 0)
905 scripts
[i
] = scripts
[i
-1];
908 for (i
= 0; i
< cInChars
; i
++)
910 /* Joiners get merged preferencially right */
911 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
915 scripts
[i
] = scripts
[i
-1];
918 for (j
= i
+1; j
< cInChars
; j
++)
920 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
922 scripts
[i
] = scripts
[j
];
930 if (psState
&& psControl
)
932 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
936 return E_OUTOFMEMORY
;
939 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
940 baselevel
= levels
[0];
941 for (i
= 0; i
< cInChars
; i
++)
942 if (levels
[i
]!=levels
[0])
944 if (i
>= cInChars
&& !odd(baselevel
) && !odd(psState
->uBidiLevel
) && !forceLevels
)
951 BOOL inNumber
= FALSE
;
952 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
954 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
959 return E_OUTOFMEMORY
;
961 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
963 /* We currently mis-level leading Diacriticals */
964 if (scripts
[0] == Script_Diacritical
)
965 for (i
= 0; i
< cInChars
&& scripts
[0] == Script_Diacritical
; i
++)
967 levels
[i
] = odd(levels
[i
])?levels
[i
]+1:levels
[i
];
968 strength
[i
] = BIDI_STRONG
;
971 for (i
= 0; i
< cInChars
; i
++)
973 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
974 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
976 scripts
[i
] = Script_Numeric
;
979 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && scripts
[i
] == Script_Numeric
)
987 /* Joiners get merged preferencially right */
988 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
991 if (i
+1 == cInChars
&& levels
[i
-1] == levels
[i
])
992 strength
[i
] = strength
[i
-1];
994 for (j
= i
+1; j
< cInChars
&& levels
[i
] == levels
[j
]; j
++)
995 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
997 strength
[i
] = strength
[j
];
1002 if (psControl
->fMergeNeutralItems
)
1004 /* Merge the neutrals */
1005 for (i
= 0; i
< cInChars
; i
++)
1007 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1010 for (j
= i
; j
> 0; j
--)
1012 if (levels
[i
] != levels
[j
])
1014 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1016 scripts
[i
] = scripts
[j
];
1017 strength
[i
] = strength
[j
];
1022 /* Try going the other way */
1023 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1026 for (j
= i
; j
< cInChars
; j
++)
1028 if (levels
[i
] != levels
[j
])
1030 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1032 scripts
[i
] = scripts
[j
];
1033 strength
[i
] = strength
[j
];
1043 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
) && cnt
< cInChars
)
1046 if (cnt
== cInChars
) /* All Spaces */
1049 New_Script
= scripts
[cnt
];
1052 pItems
[index
].iCharPos
= 0;
1053 pItems
[index
].a
= scriptInformation
[scripts
[cnt
]].a
;
1054 pScriptTags
[index
] = scriptInformation
[scripts
[cnt
]].scriptTag
;
1056 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
1057 str
= strength
[cnt
];
1065 if (strength
[cnt
] == BIDI_STRONG
)
1066 layoutRTL
= (odd(levels
[cnt
]))?1:0;
1068 layoutRTL
= (psState
->uBidiLevel
|| odd(levels
[cnt
]))?1:0;
1069 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1070 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1071 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1073 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1075 layoutRTL
= (odd(baselevel
))?1:0;
1076 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1077 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
1078 pItems
[index
].a
.fRTL
= odd(baselevel
);
1081 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1082 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
1083 pItems
[index
].iCharPos
);
1085 for (cnt
=1; cnt
< cInChars
; cnt
++)
1087 if(pwcInChars
[cnt
] != Numeric_space
)
1088 New_Script
= scripts
[cnt
];
1092 while (cnt
+ j
< cInChars
- 1 && pwcInChars
[cnt
+j
] == Numeric_space
&& levels
[cnt
] == levels
[cnt
+j
])
1094 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
1095 New_Script
= scripts
[cnt
+j
];
1097 New_Script
= scripts
[cnt
];
1101 /* merge space strengths*/
1102 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
1105 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
1108 /* changes in level */
1109 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
1111 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
1114 /* changes in strength */
1115 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
1117 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
1120 /* changes in script */
1121 else if (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
))
1123 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
1127 if (!new_run
&& strength
&& str
== BIDI_STRONG
)
1129 layoutRTL
= odd(levels
[cnt
])?1:0;
1130 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1135 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
);
1138 if (index
+1 > cMaxItems
)
1139 return E_OUTOFMEMORY
;
1142 str
= strength
[cnt
];
1144 pItems
[index
].iCharPos
= cnt
;
1145 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1147 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
1148 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
1151 if (levels
[cnt
] == 0)
1154 layoutRTL
= (layoutRTL
|| odd(levels
[cnt
]))?1:0;
1155 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1156 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1157 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1159 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1161 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1162 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1163 pItems
[index
].a
.fRTL
= odd(baselevel
);
1166 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1170 /* While not strictly necessary according to the spec, make sure the n+1
1171 * item is set up to prevent random behaviour if the caller erroneously
1172 * checks the n+1 structure */
1174 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1176 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1178 /* Set one SCRIPT_STATE item being returned */
1179 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
1180 if (pcItems
) *pcItems
= index
;
1182 /* Set SCRIPT_ITEM */
1183 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
1185 heap_free(strength
);
1190 /***********************************************************************
1191 * ScriptItemize (USP10.@)
1193 * Split a Unicode string into shapeable parts.
1196 * pwcInChars [I] String to split.
1197 * cInChars [I] Number of characters in pwcInChars.
1198 * cMaxItems [I] Maximum number of items to return.
1199 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1200 * psState [I] Pointer to a SCRIPT_STATE structure.
1201 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1202 * pcItems [O] Number of script items returned.
1206 * Failure: Non-zero HRESULT value.
1208 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1209 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1210 SCRIPT_ITEM
*pItems
, int *pcItems
)
1212 OPENTYPE_TAG
*discarded_tags
;
1215 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1216 if (!discarded_tags
)
1217 return E_OUTOFMEMORY
;
1218 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1219 heap_free(discarded_tags
);
1223 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1227 INT
*lpTabPos
= NULL
;
1232 lpTabPos
= pTabdef
->pTabStops
;
1234 if (pTabdef
&& pTabdef
->iTabOrigin
)
1236 if (pTabdef
->iScale
)
1237 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1239 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1243 cTabStops
= pTabdef
->cTabStops
;
1247 if (pTabdef
->iScale
)
1248 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1250 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1254 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1256 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1258 int position
= *lpTabPos
;
1260 position
= -1 * position
;
1261 if (pTabdef
->iScale
)
1262 position
= (position
* pTabdef
->iScale
) / 4;
1264 position
= position
* psc
->tm
.tmAveCharWidth
;
1266 if( nTabOrg
+ position
> current_x
)
1270 /* a left aligned tab */
1271 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1276 FIXME("Negative tabstop\n");
1281 if ((!cTabStops
) && (defWidth
> 0))
1282 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1283 else if ((!cTabStops
) && (defWidth
< 0))
1284 FIXME("TODO: Negative defWidth\n");
1289 /***********************************************************************
1290 * Helper function for ScriptStringAnalyse
1292 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1293 const WCHAR
*pwcInChars
, int cChars
)
1295 /* FIXME: When to properly fallback is still a bit of a mystery */
1298 if (psa
->fNoGlyphIndex
)
1301 if (init_script_cache(hdc
, psc
) != S_OK
)
1304 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1307 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1310 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1320 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1324 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1326 static const WCHAR szFmt
[] = {'%','x',0};
1328 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1331 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1332 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1333 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1337 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1340 /***********************************************************************
1341 * ScriptStringAnalyse (USP10.@)
1344 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1345 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1346 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1347 SCRIPT_STATE
*psState
, const int *piDx
,
1348 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1349 SCRIPT_STRING_ANALYSIS
*pssa
)
1351 HRESULT hr
= E_OUTOFMEMORY
;
1352 StringAnalysis
*analysis
= NULL
;
1353 SCRIPT_CONTROL sControl
;
1354 SCRIPT_STATE sState
;
1355 int i
, num_items
= 255;
1357 WCHAR
*iString
= NULL
;
1359 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1360 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1361 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1365 FIXME("Only Unicode strings are supported\n");
1366 return E_INVALIDARG
;
1368 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1369 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1371 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1372 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1374 /* FIXME: handle clipping */
1375 analysis
->clip_len
= cString
;
1376 analysis
->hdc
= hdc
;
1377 analysis
->dwFlags
= dwFlags
;
1382 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1385 sControl
= *psControl
;
1387 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1389 if (dwFlags
& SSA_PASSWORD
)
1391 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1397 for (i
= 0; i
< cString
; i
++)
1398 iString
[i
] = *((const WCHAR
*)pString
);
1402 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1403 &analysis
->numItems
);
1405 while (hr
== E_OUTOFMEMORY
)
1410 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1413 analysis
->pItem
= tmp
;
1414 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1415 &analysis
->numItems
);
1417 if (hr
!= S_OK
) goto error
;
1419 /* set back to out of memory for default goto error behaviour */
1422 if (dwFlags
& SSA_BREAK
)
1424 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1426 for (i
= 0; i
< analysis
->numItems
; i
++)
1427 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
]);
1433 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1435 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1438 if (dwFlags
& SSA_GLYPHS
)
1441 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1444 for (i
= 0; i
< analysis
->numItems
; i
++)
1446 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1447 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1448 int numGlyphs
= 1.5 * cChar
+ 16;
1449 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1450 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1451 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1452 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1453 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1454 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1455 int numGlyphsReturned
;
1456 HFONT originalFont
= 0x0;
1458 /* FIXME: non unicode strings */
1459 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1460 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1462 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1465 heap_free (pwLogClust
);
1466 heap_free (piAdvance
);
1468 heap_free (pGoffset
);
1474 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1477 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1478 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1479 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1480 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1481 if (analysis
->glyphs
[i
].fallbackFont
)
1483 ScriptFreeCache(sc
);
1484 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1488 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1489 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1490 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1491 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1492 piAdvance
, pGoffset
, abc
);
1494 SelectObject(hdc
,originalFont
);
1496 if (dwFlags
& SSA_TAB
)
1499 for (tabi
= 0; tabi
< cChar
; tabi
++)
1501 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1502 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1503 tab_x
+=piAdvance
[tabi
];
1507 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1508 analysis
->glyphs
[i
].glyphs
= glyphs
;
1509 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1510 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1511 analysis
->glyphs
[i
].psva
= psva
;
1512 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1513 analysis
->glyphs
[i
].abc
= abc
;
1514 analysis
->glyphs
[i
].iMaxPosX
= -1;
1516 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1521 for (i
= 0; i
< analysis
->numItems
; i
++)
1522 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1525 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1526 heap_free(BidiLevel
);
1534 heap_free(analysis
->glyphs
);
1535 heap_free(analysis
->logattrs
);
1536 heap_free(analysis
->pItem
);
1537 heap_free(analysis
->logical2visual
);
1538 heap_free(analysis
);
1542 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1546 if (pva
[glyph
].fClusterStart
)
1548 for (i
= 0; i
< cChars
; i
++)
1549 if (pwLogClust
[i
] == glyph
) break;
1557 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1568 StringAnalysis
*analysis
;
1571 COLORREF BkColor
= 0x0;
1572 COLORREF TextColor
= 0x0;
1574 INT runStart
, runEnd
;
1575 INT iGlyph
, cGlyphs
;
1576 HFONT oldFont
= 0x0;
1578 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1579 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1581 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1583 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1584 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1589 BkMode
= GetBkMode(analysis
->hdc
);
1590 SetBkMode( analysis
->hdc
, OPAQUE
);
1591 BkColor
= GetBkColor(analysis
->hdc
);
1592 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1595 TextColor
= GetTextColor(analysis
->hdc
);
1596 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1599 if (analysis
->glyphs
[iItem
].fallbackFont
)
1600 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1602 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1603 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1606 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1607 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1609 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1611 if (analysis
->pItem
[iItem
].a
.fRTL
)
1613 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1614 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1616 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1620 if (cStart
>=0 && runStart
)
1621 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1623 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1626 if (analysis
->pItem
[iItem
].a
.fRTL
)
1627 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1629 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1631 if (analysis
->pItem
[iItem
].a
.fRTL
)
1632 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1634 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1638 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1643 clust_glyph
= iGlyph
+ cGlyphs
;
1644 if (analysis
->pItem
[iItem
].a
.fRTL
)
1649 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1650 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1657 hr
= ScriptTextOut(analysis
->hdc
,
1658 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1659 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1660 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1661 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1662 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1664 TRACE("ScriptTextOut hr=%08x\n", hr
);
1668 SetBkColor(analysis
->hdc
, BkColor
);
1669 SetBkMode( analysis
->hdc
, BkMode
);
1671 SetTextColor(analysis
->hdc
, TextColor
);
1673 if (analysis
->glyphs
[iItem
].fallbackFont
)
1674 SelectObject(analysis
->hdc
, oldFont
);
1679 /***********************************************************************
1680 * ScriptStringOut (USP10.@)
1682 * This function takes the output of ScriptStringAnalyse and joins the segments
1683 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1684 * only processes glyphs.
1687 * ssa [I] buffer to hold the analysed string components
1688 * iX [I] X axis displacement for output
1689 * iY [I] Y axis displacement for output
1690 * uOptions [I] flags controling output processing
1691 * prc [I] rectangle coordinates
1692 * iMinSel [I] starting pos for substringing output string
1693 * iMaxSel [I] ending pos for substringing output string
1694 * fDisabled [I] controls text highlighting
1698 * Failure: is the value returned by ScriptTextOut
1700 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1709 StringAnalysis
*analysis
;
1713 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1714 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1716 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1717 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1719 for (item
= 0; item
< analysis
->numItems
; item
++)
1721 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1726 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1728 if (iMaxSel
> 0 && iMinSel
< 0)
1730 for (item
= 0; item
< analysis
->numItems
; item
++)
1732 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1741 /***********************************************************************
1742 * ScriptStringCPtoX (USP10.@)
1745 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1749 StringAnalysis
* analysis
= ssa
;
1751 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1753 if (!ssa
|| !pX
) return S_FALSE
;
1754 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1756 /* icp out of range */
1759 analysis
->invalid
= TRUE
;
1760 return E_INVALIDARG
;
1763 for(item
=0; item
<analysis
->numItems
; item
++)
1768 i
= analysis
->logical2visual
[item
];
1769 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1770 /* initialize max extents for uninitialized runs */
1771 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1773 if (analysis
->pItem
[i
].a
.fRTL
)
1774 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1775 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1776 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1778 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1779 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1780 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1783 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1785 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1789 icp
-= analysis
->pItem
[i
].iCharPos
;
1790 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1791 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1792 &analysis
->pItem
[i
].a
, &offset
);
1799 /* icp out of range */
1800 analysis
->invalid
= TRUE
;
1801 return E_INVALIDARG
;
1804 /***********************************************************************
1805 * ScriptStringXtoCP (USP10.@)
1808 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1810 StringAnalysis
* analysis
= ssa
;
1813 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1815 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1816 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1821 if (analysis
->pItem
[0].a
.fRTL
)
1824 *piTrailing
= FALSE
;
1834 for(item
=0; item
<analysis
->numItems
; item
++)
1839 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
1842 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1843 /* initialize max extents for uninitialized runs */
1844 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1846 if (analysis
->pItem
[i
].a
.fRTL
)
1847 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1848 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1849 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1851 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1852 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1853 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1856 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
1858 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
1862 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1863 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1864 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
1865 *piCh
+= analysis
->pItem
[i
].iCharPos
;
1871 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
1872 *piTrailing
= FALSE
;
1878 /***********************************************************************
1879 * ScriptStringFree (USP10.@)
1881 * Free a string analysis.
1884 * pssa [I] string analysis.
1888 * Failure: Non-zero HRESULT value.
1890 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
1892 StringAnalysis
* analysis
;
1896 TRACE("(%p)\n", pssa
);
1898 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
1900 invalid
= analysis
->invalid
;
1902 if (analysis
->glyphs
)
1904 for (i
= 0; i
< analysis
->numItems
; i
++)
1906 heap_free(analysis
->glyphs
[i
].glyphs
);
1907 heap_free(analysis
->glyphs
[i
].pwLogClust
);
1908 heap_free(analysis
->glyphs
[i
].piAdvance
);
1909 heap_free(analysis
->glyphs
[i
].psva
);
1910 heap_free(analysis
->glyphs
[i
].pGoffset
);
1911 heap_free(analysis
->glyphs
[i
].abc
);
1912 if (analysis
->glyphs
[i
].fallbackFont
)
1913 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
1914 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
1915 heap_free(analysis
->glyphs
[i
].sc
);
1917 heap_free(analysis
->glyphs
);
1920 heap_free(analysis
->pItem
);
1921 heap_free(analysis
->logattrs
);
1922 heap_free(analysis
->sz
);
1923 heap_free(analysis
->logical2visual
);
1924 heap_free(analysis
);
1926 if (invalid
) return E_INVALIDARG
;
1930 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
1931 int direction
, int* iCluster
, int *check_out
)
1935 WORD clust
= pwLogClust
[item
];
1937 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
1939 if (pwLogClust
[check
] == clust
)
1942 if (iCluster
&& *iCluster
== -1)
1954 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
)
1957 int log_clust_max
= 0;
1960 advance
= piAdvance
[glyph
];
1962 for (i
= 0; i
< cChars
; i
++)
1964 if (pwLogClust
[i
] > log_clust_max
)
1965 log_clust_max
= pwLogClust
[i
];
1968 if (glyph
> log_clust_max
)
1971 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
1974 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
1976 if (glyph
> log_clust_max
)
1978 advance
+= piAdvance
[glyph
];
1984 /***********************************************************************
1985 * ScriptCPtoX (USP10.@)
1988 HRESULT WINAPI
ScriptCPtoX(int iCP
,
1992 const WORD
*pwLogClust
,
1993 const SCRIPT_VISATTR
*psva
,
1994 const int *piAdvance
,
1995 const SCRIPT_ANALYSIS
*psa
,
2003 float special_size
= 0.0;
2008 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2009 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2012 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2020 int max_clust
= pwLogClust
[0];
2022 for (item
=0; item
< cGlyphs
; item
++)
2023 if (pwLogClust
[item
] > max_clust
)
2025 ERR("We do not handle non reversed clusters properly\n");
2030 for (item
= max_clust
; item
>=0; item
--)
2031 iMaxPos
+= piAdvance
[item
];
2035 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2037 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2040 int clust
= pwLogClust
[item
];
2043 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2046 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2048 if (check
>= cChars
&& !iMaxPos
)
2050 for (check
= clust
; check
< cChars
; check
++)
2051 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2053 special_size
/= (cChars
- item
);
2054 iPosX
+= special_size
;
2058 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2061 if (clust_size
== 0)
2065 iPosX
+= advance
/ (float)clust_size
;
2068 else if (iSpecial
!= -1)
2069 iPosX
+= special_size
;
2070 else /* (iCluster != -1) */
2072 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2073 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2076 if (clust_size
== 0)
2080 iPosX
+= adv
/ (float)clust_size
;
2086 iPosX
= iMaxPos
- iPosX
;
2092 TRACE("*piX=%d\n", *piX
);
2096 /***********************************************************************
2097 * ScriptXtoCP (USP10.@)
2100 HRESULT WINAPI
ScriptXtoCP(int iX
,
2103 const WORD
*pwLogClust
,
2104 const SCRIPT_VISATTR
*psva
,
2105 const int *piAdvance
,
2106 const SCRIPT_ANALYSIS
*psa
,
2118 float special_size
= 0.0;
2121 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2122 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2123 psa
, piCP
, piTrailing
);
2125 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2130 int max_clust
= pwLogClust
[0];
2139 for (item
=0; item
< cChars
; item
++)
2140 if (pwLogClust
[item
] > max_clust
)
2142 ERR("We do not handle non reversed clusters properly\n");
2154 iPosX
= iLastPosX
= 0;
2159 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2162 if (iSpecial
== -1 &&
2165 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2166 (direction
< 0 && iCluster
-clust_size
>= item
))
2172 int clust
= pwLogClust
[item
];
2176 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2178 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2180 if (check
>= cChars
&& direction
> 0)
2182 for (check
= clust
; check
< cChars
; check
++)
2183 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2185 special_size
/= (cChars
- item
);
2186 iPosX
+= special_size
;
2190 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2197 iPosX
+= advance
/ (float)clust_size
;
2200 else if (iSpecial
!= -1)
2201 iPosX
+= special_size
;
2202 else /* (iCluster != -1) */
2204 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2205 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2212 iPosX
+= adv
/ (float)clust_size
;
2220 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2222 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2223 item
+=(clust_size
-1);
2231 if (iX
== iLastPosX
)
2233 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2236 if (iLastPosX
== iX
)
2238 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2240 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2241 item
-=(clust_size
-1);
2250 TRACE("*piCP=%d\n", *piCP
);
2251 TRACE("*piTrailing=%d\n", *piTrailing
);
2255 /***********************************************************************
2256 * ScriptBreak (USP10.@)
2258 * Retrieve line break information.
2261 * chars [I] Array of characters.
2262 * sa [I] String analysis.
2263 * la [I] Array of logical attribute structures.
2269 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2271 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2273 if (!la
) return S_FALSE
;
2275 BREAK_line(chars
, count
, sa
, la
);
2280 /***********************************************************************
2281 * ScriptIsComplex (USP10.@)
2283 * Determine if a string is complex.
2286 * chars [I] Array of characters to test.
2287 * len [I] Length in characters.
2295 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2299 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2301 for (i
= 0; i
< len
; i
++)
2305 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2308 script
= get_char_script(chars
[i
]);
2309 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2310 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2316 /***********************************************************************
2317 * ScriptShapeOpenType (USP10.@)
2319 * Produce glyphs and visual attributes for a run.
2322 * hdc [I] Device context.
2323 * psc [I/O] Opaque pointer to a script cache.
2324 * psa [I/O] Script analysis.
2325 * tagScript [I] The OpenType tag for the Script
2326 * tagLangSys [I] The OpenType tag for the Language
2327 * rcRangeChars[I] Array of Character counts in each range
2328 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2329 * cRanges [I] Count of ranges
2330 * pwcChars [I] Array of characters specifying the run.
2331 * cChars [I] Number of characters in pwcChars.
2332 * cMaxGlyphs [I] Length of pwOutGlyphs.
2333 * pwLogClust [O] Array of logical cluster info.
2334 * pCharProps [O] Array of character property values
2335 * pwOutGlyphs [O] Array of glyphs.
2336 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2337 * pcGlyphs [O] Number of glyphs returned.
2341 * Failure: Non-zero HRESULT value.
2343 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2344 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2345 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2346 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2347 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2348 int cMaxGlyphs
, WORD
*pwLogClust
,
2349 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2350 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2356 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2358 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2359 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2360 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2362 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2363 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2365 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2366 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2369 FIXME("Ranges not supported yet\n");
2371 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2374 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2375 if (!pwLogClust
) return E_FAIL
;
2377 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2378 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2380 /* set fNoGlyphIndex non truetype/opentype fonts */
2381 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2382 psa
->fNoGlyphIndex
= TRUE
;
2384 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2385 for (i
= 0; i
< cChars
; i
++)
2388 if (rtl
) idx
= cChars
- 1 - i
;
2389 /* FIXME: set to better values */
2390 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2391 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2392 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2393 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2394 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2395 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2397 /* FIXME: have the shaping engine set this */
2398 pCharProps
[i
].fCanGlyphAlone
= 0;
2400 pwLogClust
[i
] = idx
;
2403 if (psa
&& !psa
->fNoGlyphIndex
)
2406 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2408 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2409 if (!rChars
) return E_OUTOFMEMORY
;
2410 for (i
= 0; i
< cChars
; i
++)
2414 if (rtl
) idx
= cChars
- 1 - i
;
2416 chInput
= mirror_char(pwcChars
[idx
]);
2418 chInput
= pwcChars
[idx
];
2419 /* special case for tabs */
2420 if (chInput
== 0x0009)
2422 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2425 if (!hdc
) return E_PENDING
;
2426 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
) return S_FALSE
;
2427 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2429 rChars
[i
] = chInput
;
2432 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2433 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2434 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2439 TRACE("no glyph translation\n");
2440 for (i
= 0; i
< cChars
; i
++)
2443 /* No mirroring done here */
2444 if (rtl
) idx
= cChars
- 1 - i
;
2445 pwOutGlyphs
[i
] = pwcChars
[idx
];
2453 /***********************************************************************
2454 * ScriptShape (USP10.@)
2456 * Produce glyphs and visual attributes for a run.
2459 * hdc [I] Device context.
2460 * psc [I/O] Opaque pointer to a script cache.
2461 * pwcChars [I] Array of characters specifying the run.
2462 * cChars [I] Number of characters in pwcChars.
2463 * cMaxGlyphs [I] Length of pwOutGlyphs.
2464 * psa [I/O] Script analysis.
2465 * pwOutGlyphs [O] Array of glyphs.
2466 * pwLogClust [O] Array of logical cluster info.
2467 * psva [O] Array of visual attributes.
2468 * pcGlyphs [O] Number of glyphs returned.
2472 * Failure: Non-zero HRESULT value.
2474 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2475 int cChars
, int cMaxGlyphs
,
2476 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2477 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2481 SCRIPT_CHARPROP
*charProps
;
2482 SCRIPT_GLYPHPROP
*glyphProps
;
2484 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2485 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2487 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2488 if (!charProps
) return E_OUTOFMEMORY
;
2489 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2490 if (!glyphProps
) return E_OUTOFMEMORY
;
2492 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2496 for (i
= 0; i
< *pcGlyphs
; i
++)
2497 psva
[i
] = glyphProps
[i
].sva
;
2500 heap_free(charProps
);
2501 heap_free(glyphProps
);
2506 /***********************************************************************
2507 * ScriptPlaceOpenType (USP10.@)
2509 * Produce advance widths for a run.
2512 * hdc [I] Device context.
2513 * psc [I/O] Opaque pointer to a script cache.
2514 * psa [I/O] String analysis.
2515 * tagScript [I] The OpenType tag for the Script
2516 * tagLangSys [I] The OpenType tag for the Language
2517 * rcRangeChars[I] Array of Character counts in each range
2518 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2519 * cRanges [I] Count of ranges
2520 * pwcChars [I] Array of characters specifying the run.
2521 * pwLogClust [I] Array of logical cluster info
2522 * pCharProps [I] Array of character property values
2523 * cChars [I] Number of characters in pwcChars.
2524 * pwGlyphs [I] Array of glyphs.
2525 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2526 * cGlyphs [I] Count of Glyphs
2527 * piAdvance [O] Array of advance widths.
2528 * pGoffset [O] Glyph offsets.
2529 * pABC [O] Combined ABC width.
2533 * Failure: Non-zero HRESULT value.
2536 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2537 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2538 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2539 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2540 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2541 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2542 int cGlyphs
, int *piAdvance
,
2543 GOFFSET
*pGoffset
, ABC
*pABC
2549 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2551 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2552 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2553 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2556 if (!pGlyphProps
) return E_INVALIDARG
;
2557 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2558 if (!pGoffset
) return E_FAIL
;
2561 FIXME("Ranges not supported yet\n");
2563 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2564 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2566 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2567 for (i
= 0; i
< cGlyphs
; i
++)
2570 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2572 if (!hdc
) return E_PENDING
;
2573 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2575 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2580 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2582 abc
.abcA
= abc
.abcC
= 0;
2584 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2588 pABC
->abcA
+= abc
.abcA
;
2589 pABC
->abcB
+= abc
.abcB
;
2590 pABC
->abcC
+= abc
.abcC
;
2592 /* FIXME: set to more reasonable values */
2593 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2594 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2597 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2601 /***********************************************************************
2602 * ScriptPlace (USP10.@)
2604 * Produce advance widths for a run.
2607 * hdc [I] Device context.
2608 * psc [I/O] Opaque pointer to a script cache.
2609 * pwGlyphs [I] Array of glyphs.
2610 * cGlyphs [I] Number of glyphs in pwGlyphs.
2611 * psva [I] Array of visual attributes.
2612 * psa [I/O] String analysis.
2613 * piAdvance [O] Array of advance widths.
2614 * pGoffset [O] Glyph offsets.
2615 * pABC [O] Combined ABC width.
2619 * Failure: Non-zero HRESULT value.
2621 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2622 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2623 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2626 SCRIPT_GLYPHPROP
*glyphProps
;
2629 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2630 piAdvance
, pGoffset
, pABC
);
2632 if (!psva
) return E_INVALIDARG
;
2633 if (!pGoffset
) return E_FAIL
;
2635 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2636 if (!glyphProps
) return E_OUTOFMEMORY
;
2638 for (i
= 0; i
< cGlyphs
; i
++)
2639 glyphProps
[i
].sva
= psva
[i
];
2641 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2643 heap_free(glyphProps
);
2648 /***********************************************************************
2649 * ScriptGetCMap (USP10.@)
2651 * Retrieve glyph indices.
2654 * hdc [I] Device context.
2655 * psc [I/O] Opaque pointer to a script cache.
2656 * pwcInChars [I] Array of Unicode characters.
2657 * cChars [I] Number of characters in pwcInChars.
2658 * dwFlags [I] Flags.
2659 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2663 * Failure: Non-zero HRESULT value.
2665 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2666 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2671 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2672 cChars
, dwFlags
, pwOutGlyphs
);
2674 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2678 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2680 for (i
= 0; i
< cChars
; i
++)
2683 if (dwFlags
== SGCM_RTL
)
2684 inChar
= mirror_char(pwcInChars
[i
]);
2686 inChar
= pwcInChars
[i
];
2687 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2690 if (!hdc
) return E_PENDING
;
2691 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2692 if (glyph
== 0xffff)
2697 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2703 TRACE("no glyph translation\n");
2704 for (i
= 0; i
< cChars
; i
++)
2707 if (dwFlags
== SGCM_RTL
)
2708 inChar
= mirror_char(pwcInChars
[i
]);
2710 inChar
= pwcInChars
[i
];
2711 pwOutGlyphs
[i
] = inChar
;
2717 /***********************************************************************
2718 * ScriptTextOut (USP10.@)
2721 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2722 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2723 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2724 const int *piJustify
, const GOFFSET
*pGoffset
)
2728 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2729 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2730 piAdvance
, piJustify
, pGoffset
);
2732 if (!hdc
|| !psc
) return E_INVALIDARG
;
2733 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2735 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2736 fuOptions
|= ETO_IGNORELANGUAGE
;
2737 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2738 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2740 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2745 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2747 return E_OUTOFMEMORY
;
2749 for (i
= 0; i
< cGlyphs
; i
++)
2750 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2752 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2754 heap_free(rtlGlyphs
);
2757 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2763 /***********************************************************************
2764 * ScriptCacheGetHeight (USP10.@)
2766 * Retrieve the height of the font in the cache.
2769 * hdc [I] Device context.
2770 * psc [I/O] Opaque pointer to a script cache.
2771 * height [O] Receives font height.
2775 * Failure: Non-zero HRESULT value.
2777 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2781 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2783 if (!height
) return E_INVALIDARG
;
2784 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2786 *height
= get_cache_height(psc
);
2790 /***********************************************************************
2791 * ScriptGetGlyphABCWidth (USP10.@)
2793 * Retrieve the width of a glyph.
2796 * hdc [I] Device context.
2797 * psc [I/O] Opaque pointer to a script cache.
2798 * glyph [I] Glyph to retrieve the width for.
2799 * abc [O] ABC widths of the glyph.
2803 * Failure: Non-zero HRESULT value.
2805 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2809 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2811 if (!abc
) return E_INVALIDARG
;
2812 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2814 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
2816 if (!hdc
) return E_PENDING
;
2817 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2819 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
2824 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
2826 abc
->abcA
= abc
->abcC
= 0;
2828 set_cache_glyph_widths(psc
, glyph
, abc
);
2833 /***********************************************************************
2834 * ScriptLayout (USP10.@)
2836 * Map embedding levels to visual and/or logical order.
2839 * runs [I] Size of level array.
2840 * level [I] Array of embedding levels.
2841 * vistolog [O] Map of embedding levels from visual to logical order.
2842 * logtovis [O] Map of embedding levels from logical to visual order.
2846 * Failure: Non-zero HRESULT value.
2849 * This stub works correctly for any sequence of a single
2850 * embedding level but not for sequences of different
2851 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2853 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
2858 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
2860 if (!level
|| (!vistolog
&& !logtovis
))
2861 return E_INVALIDARG
;
2863 indexs
= heap_alloc(sizeof(int) * runs
);
2865 return E_OUTOFMEMORY
;
2870 for( ich
= 0; ich
< runs
; ich
++)
2875 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2876 for (ich
= 0; ich
< runs
; ich
++)
2877 vistolog
[ich
] = indexs
[ich
];
2883 for( ich
= 0; ich
< runs
; ich
++)
2888 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2889 for (ich
= 0; ich
< runs
; ich
++)
2890 logtovis
[ich
] = indexs
[ich
];
2897 /***********************************************************************
2898 * ScriptStringGetLogicalWidths (USP10.@)
2900 * Returns logical widths from a string analysis.
2903 * ssa [I] string analysis.
2904 * piDx [O] logical widths returned.
2908 * Failure: a non-zero HRESULT.
2910 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
2913 StringAnalysis
*analysis
= ssa
;
2915 TRACE("%p, %p\n", ssa
, piDx
);
2917 if (!analysis
) return S_FALSE
;
2918 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2920 for (i
= 0; i
< analysis
->numItems
; i
++)
2922 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2925 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
2928 for (j
= 0; j
< cChar
; j
++)
2931 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
2932 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
2933 cChar
, j
, direction
, NULL
, NULL
);
2934 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
);
2936 for (k
= 0; k
< clust_size
; k
++)
2938 piDx
[next
] = advance
/ clust_size
;
2947 /***********************************************************************
2948 * ScriptStringValidate (USP10.@)
2950 * Validate a string analysis.
2953 * ssa [I] string analysis.
2957 * Failure: S_FALSE if invalid sequences are found
2958 * or a non-zero HRESULT if it fails.
2960 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
2962 StringAnalysis
*analysis
= ssa
;
2964 TRACE("(%p)\n", ssa
);
2966 if (!analysis
) return E_INVALIDARG
;
2967 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
2970 /***********************************************************************
2971 * ScriptString_pSize (USP10.@)
2973 * Retrieve width and height of an analysed string.
2976 * ssa [I] string analysis.
2979 * Success: Pointer to a SIZE structure.
2982 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
2985 StringAnalysis
*analysis
= ssa
;
2987 TRACE("(%p)\n", ssa
);
2989 if (!analysis
) return NULL
;
2990 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
2994 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
2995 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
2997 analysis
->sz
->cx
= 0;
2998 for (i
= 0; i
< analysis
->numItems
; i
++)
3000 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3001 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3002 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3003 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3006 return analysis
->sz
;
3009 /***********************************************************************
3010 * ScriptString_pLogAttr (USP10.@)
3012 * Retrieve logical attributes of an analysed string.
3015 * ssa [I] string analysis.
3018 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3021 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3023 StringAnalysis
*analysis
= ssa
;
3025 TRACE("(%p)\n", ssa
);
3027 if (!analysis
) return NULL
;
3028 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3029 return analysis
->logattrs
;
3032 /***********************************************************************
3033 * ScriptString_pcOutChars (USP10.@)
3035 * Retrieve the length of a string after clipping.
3038 * ssa [I] String analysis.
3041 * Success: Pointer to the length.
3044 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3046 StringAnalysis
*analysis
= ssa
;
3048 TRACE("(%p)\n", ssa
);
3050 if (!analysis
) return NULL
;
3051 return &analysis
->clip_len
;
3054 /***********************************************************************
3055 * ScriptStringGetOrder (USP10.@)
3057 * Retrieve a glyph order map.
3060 * ssa [I] String analysis.
3061 * order [I/O] Array of glyph positions.
3065 * Failure: a non-zero HRESULT.
3067 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3071 StringAnalysis
*analysis
= ssa
;
3073 TRACE("(%p)\n", ssa
);
3075 if (!analysis
) return S_FALSE
;
3076 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3078 /* FIXME: handle RTL scripts */
3079 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3080 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3086 /***********************************************************************
3087 * ScriptGetLogicalWidths (USP10.@)
3089 * Convert advance widths to logical widths.
3092 * sa [I] Script analysis.
3093 * nbchars [I] Number of characters.
3094 * nbglyphs [I] Number of glyphs.
3095 * glyph_width [I] Array of glyph widths.
3096 * log_clust [I] Array of logical clusters.
3097 * sva [I] Visual attributes.
3098 * widths [O] Array of logical widths.
3102 * Failure: a non-zero HRESULT.
3104 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3105 const int *glyph_width
, const WORD
*log_clust
,
3106 const SCRIPT_VISATTR
*sva
, int *widths
)
3110 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3111 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3114 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3118 /***********************************************************************
3119 * ScriptApplyLogicalWidth (USP10.@)
3121 * Generate glyph advance widths.
3124 * dx [I] Array of logical advance widths.
3125 * num_chars [I] Number of characters.
3126 * num_glyphs [I] Number of glyphs.
3127 * log_clust [I] Array of logical clusters.
3128 * sva [I] Visual attributes.
3129 * advance [I] Array of glyph advance widths.
3130 * sa [I] Script analysis.
3131 * abc [I/O] Summed ABC widths.
3132 * justify [O] Array of glyph advance widths.
3136 * Failure: a non-zero HRESULT.
3138 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3139 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3140 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3141 ABC
*abc
, int *justify
)
3145 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3146 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3148 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3152 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3153 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3157 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3159 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];