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 separated 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
)))
1443 heap_free(BidiLevel
);
1447 for (i
= 0; i
< analysis
->numItems
; i
++)
1449 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1450 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1451 int numGlyphs
= 1.5 * cChar
+ 16;
1452 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1453 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1454 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1455 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1456 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1457 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1458 int numGlyphsReturned
;
1459 HFONT originalFont
= 0x0;
1461 /* FIXME: non unicode strings */
1462 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1463 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1465 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1467 heap_free (BidiLevel
);
1469 heap_free (pwLogClust
);
1470 heap_free (piAdvance
);
1472 heap_free (pGoffset
);
1478 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1481 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1482 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1483 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1484 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1485 if (analysis
->glyphs
[i
].fallbackFont
)
1487 ScriptFreeCache(sc
);
1488 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1492 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1493 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1494 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1495 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1496 piAdvance
, pGoffset
, abc
);
1498 SelectObject(hdc
,originalFont
);
1500 if (dwFlags
& SSA_TAB
)
1503 for (tabi
= 0; tabi
< cChar
; tabi
++)
1505 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1506 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1507 tab_x
+=piAdvance
[tabi
];
1511 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1512 analysis
->glyphs
[i
].glyphs
= glyphs
;
1513 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1514 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1515 analysis
->glyphs
[i
].psva
= psva
;
1516 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1517 analysis
->glyphs
[i
].abc
= abc
;
1518 analysis
->glyphs
[i
].iMaxPosX
= -1;
1520 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1525 for (i
= 0; i
< analysis
->numItems
; i
++)
1526 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1529 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1530 heap_free(BidiLevel
);
1538 heap_free(analysis
->glyphs
);
1539 heap_free(analysis
->logattrs
);
1540 heap_free(analysis
->pItem
);
1541 heap_free(analysis
->logical2visual
);
1542 heap_free(analysis
);
1546 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1550 if (pva
[glyph
].fClusterStart
)
1552 for (i
= 0; i
< cChars
; i
++)
1553 if (pwLogClust
[i
] == glyph
) break;
1561 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1572 StringAnalysis
*analysis
;
1575 COLORREF BkColor
= 0x0;
1576 COLORREF TextColor
= 0x0;
1578 INT runStart
, runEnd
;
1579 INT iGlyph
, cGlyphs
;
1580 HFONT oldFont
= 0x0;
1582 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1583 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1585 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1587 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1588 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1593 BkMode
= GetBkMode(analysis
->hdc
);
1594 SetBkMode( analysis
->hdc
, OPAQUE
);
1595 BkColor
= GetBkColor(analysis
->hdc
);
1596 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1599 TextColor
= GetTextColor(analysis
->hdc
);
1600 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1603 if (analysis
->glyphs
[iItem
].fallbackFont
)
1604 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1606 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1607 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1610 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1611 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1613 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1615 if (analysis
->pItem
[iItem
].a
.fRTL
)
1617 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1618 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1620 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1624 if (cStart
>=0 && runStart
)
1625 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1627 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1630 if (analysis
->pItem
[iItem
].a
.fRTL
)
1631 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1633 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1635 if (analysis
->pItem
[iItem
].a
.fRTL
)
1636 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1638 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1642 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1647 clust_glyph
= iGlyph
+ cGlyphs
;
1648 if (analysis
->pItem
[iItem
].a
.fRTL
)
1653 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1654 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1661 hr
= ScriptTextOut(analysis
->hdc
,
1662 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1663 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1664 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1665 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1666 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1668 TRACE("ScriptTextOut hr=%08x\n", hr
);
1672 SetBkColor(analysis
->hdc
, BkColor
);
1673 SetBkMode( analysis
->hdc
, BkMode
);
1675 SetTextColor(analysis
->hdc
, TextColor
);
1677 if (analysis
->glyphs
[iItem
].fallbackFont
)
1678 SelectObject(analysis
->hdc
, oldFont
);
1683 /***********************************************************************
1684 * ScriptStringOut (USP10.@)
1686 * This function takes the output of ScriptStringAnalyse and joins the segments
1687 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1688 * only processes glyphs.
1691 * ssa [I] buffer to hold the analysed string components
1692 * iX [I] X axis displacement for output
1693 * iY [I] Y axis displacement for output
1694 * uOptions [I] flags controling output processing
1695 * prc [I] rectangle coordinates
1696 * iMinSel [I] starting pos for substringing output string
1697 * iMaxSel [I] ending pos for substringing output string
1698 * fDisabled [I] controls text highlighting
1702 * Failure: is the value returned by ScriptTextOut
1704 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1713 StringAnalysis
*analysis
;
1717 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1718 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1720 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1721 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1723 for (item
= 0; item
< analysis
->numItems
; item
++)
1725 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1730 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1732 if (iMaxSel
> 0 && iMinSel
< 0)
1734 for (item
= 0; item
< analysis
->numItems
; item
++)
1736 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1745 /***********************************************************************
1746 * ScriptStringCPtoX (USP10.@)
1749 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1753 StringAnalysis
* analysis
= ssa
;
1755 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1757 if (!ssa
|| !pX
) return S_FALSE
;
1758 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1760 /* icp out of range */
1763 analysis
->invalid
= TRUE
;
1764 return E_INVALIDARG
;
1767 for(item
=0; item
<analysis
->numItems
; item
++)
1772 i
= analysis
->logical2visual
[item
];
1773 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1774 /* initialize max extents for uninitialized runs */
1775 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1777 if (analysis
->pItem
[i
].a
.fRTL
)
1778 ScriptCPtoX(0, FALSE
, 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
);
1782 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1783 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1784 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1787 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1789 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1793 icp
-= analysis
->pItem
[i
].iCharPos
;
1794 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1795 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1796 &analysis
->pItem
[i
].a
, &offset
);
1803 /* icp out of range */
1804 analysis
->invalid
= TRUE
;
1805 return E_INVALIDARG
;
1808 /***********************************************************************
1809 * ScriptStringXtoCP (USP10.@)
1812 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1814 StringAnalysis
* analysis
= ssa
;
1817 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1819 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1820 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1825 if (analysis
->pItem
[0].a
.fRTL
)
1828 *piTrailing
= FALSE
;
1838 for(item
=0; item
<analysis
->numItems
; item
++)
1843 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
1846 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1847 /* initialize max extents for uninitialized runs */
1848 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1850 if (analysis
->pItem
[i
].a
.fRTL
)
1851 ScriptCPtoX(0, FALSE
, 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
);
1855 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1856 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1857 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1860 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
1862 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
1866 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1867 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1868 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
1869 *piCh
+= analysis
->pItem
[i
].iCharPos
;
1875 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
1876 *piTrailing
= FALSE
;
1882 /***********************************************************************
1883 * ScriptStringFree (USP10.@)
1885 * Free a string analysis.
1888 * pssa [I] string analysis.
1892 * Failure: Non-zero HRESULT value.
1894 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
1896 StringAnalysis
* analysis
;
1900 TRACE("(%p)\n", pssa
);
1902 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
1904 invalid
= analysis
->invalid
;
1906 if (analysis
->glyphs
)
1908 for (i
= 0; i
< analysis
->numItems
; i
++)
1910 heap_free(analysis
->glyphs
[i
].glyphs
);
1911 heap_free(analysis
->glyphs
[i
].pwLogClust
);
1912 heap_free(analysis
->glyphs
[i
].piAdvance
);
1913 heap_free(analysis
->glyphs
[i
].psva
);
1914 heap_free(analysis
->glyphs
[i
].pGoffset
);
1915 heap_free(analysis
->glyphs
[i
].abc
);
1916 if (analysis
->glyphs
[i
].fallbackFont
)
1917 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
1918 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
1919 heap_free(analysis
->glyphs
[i
].sc
);
1921 heap_free(analysis
->glyphs
);
1924 heap_free(analysis
->pItem
);
1925 heap_free(analysis
->logattrs
);
1926 heap_free(analysis
->sz
);
1927 heap_free(analysis
->logical2visual
);
1928 heap_free(analysis
);
1930 if (invalid
) return E_INVALIDARG
;
1934 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
1935 int direction
, int* iCluster
, int *check_out
)
1939 WORD clust
= pwLogClust
[item
];
1941 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
1943 if (pwLogClust
[check
] == clust
)
1946 if (iCluster
&& *iCluster
== -1)
1958 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
)
1961 int log_clust_max
= 0;
1964 advance
= piAdvance
[glyph
];
1966 for (i
= 0; i
< cChars
; i
++)
1968 if (pwLogClust
[i
] > log_clust_max
)
1969 log_clust_max
= pwLogClust
[i
];
1972 if (glyph
> log_clust_max
)
1975 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
1978 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
1980 if (glyph
> log_clust_max
)
1982 advance
+= piAdvance
[glyph
];
1988 /***********************************************************************
1989 * ScriptCPtoX (USP10.@)
1992 HRESULT WINAPI
ScriptCPtoX(int iCP
,
1996 const WORD
*pwLogClust
,
1997 const SCRIPT_VISATTR
*psva
,
1998 const int *piAdvance
,
1999 const SCRIPT_ANALYSIS
*psa
,
2007 float special_size
= 0.0;
2012 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2013 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2016 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2024 int max_clust
= pwLogClust
[0];
2026 for (item
=0; item
< cGlyphs
; item
++)
2027 if (pwLogClust
[item
] > max_clust
)
2029 ERR("We do not handle non reversed clusters properly\n");
2034 for (item
= max_clust
; item
>=0; item
--)
2035 iMaxPos
+= piAdvance
[item
];
2039 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2041 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2044 int clust
= pwLogClust
[item
];
2047 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2050 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2052 if (check
>= cChars
&& !iMaxPos
)
2054 for (check
= clust
; check
< cChars
; check
++)
2055 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2057 special_size
/= (cChars
- item
);
2058 iPosX
+= special_size
;
2062 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2065 if (clust_size
== 0)
2069 iPosX
+= advance
/ (float)clust_size
;
2072 else if (iSpecial
!= -1)
2073 iPosX
+= special_size
;
2074 else /* (iCluster != -1) */
2076 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2077 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2080 if (clust_size
== 0)
2084 iPosX
+= adv
/ (float)clust_size
;
2090 iPosX
= iMaxPos
- iPosX
;
2096 TRACE("*piX=%d\n", *piX
);
2100 /***********************************************************************
2101 * ScriptXtoCP (USP10.@)
2104 HRESULT WINAPI
ScriptXtoCP(int iX
,
2107 const WORD
*pwLogClust
,
2108 const SCRIPT_VISATTR
*psva
,
2109 const int *piAdvance
,
2110 const SCRIPT_ANALYSIS
*psa
,
2122 float special_size
= 0.0;
2125 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2126 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2127 psa
, piCP
, piTrailing
);
2129 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2134 int max_clust
= pwLogClust
[0];
2143 for (item
=0; item
< cChars
; item
++)
2144 if (pwLogClust
[item
] > max_clust
)
2146 ERR("We do not handle non reversed clusters properly\n");
2158 iPosX
= iLastPosX
= 0;
2163 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2166 if (iSpecial
== -1 &&
2169 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2170 (direction
< 0 && iCluster
-clust_size
>= item
))
2176 int clust
= pwLogClust
[item
];
2180 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2182 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2184 if (check
>= cChars
&& direction
> 0)
2186 for (check
= clust
; check
< cChars
; check
++)
2187 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2189 special_size
/= (cChars
- item
);
2190 iPosX
+= special_size
;
2194 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2201 iPosX
+= advance
/ (float)clust_size
;
2204 else if (iSpecial
!= -1)
2205 iPosX
+= special_size
;
2206 else /* (iCluster != -1) */
2208 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2209 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2216 iPosX
+= adv
/ (float)clust_size
;
2224 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2226 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2227 item
+=(clust_size
-1);
2235 if (iX
== iLastPosX
)
2237 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2240 if (iLastPosX
== iX
)
2242 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2244 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2245 item
-=(clust_size
-1);
2254 TRACE("*piCP=%d\n", *piCP
);
2255 TRACE("*piTrailing=%d\n", *piTrailing
);
2259 /***********************************************************************
2260 * ScriptBreak (USP10.@)
2262 * Retrieve line break information.
2265 * chars [I] Array of characters.
2266 * sa [I] String analysis.
2267 * la [I] Array of logical attribute structures.
2273 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2275 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2277 if (!la
) return S_FALSE
;
2279 BREAK_line(chars
, count
, sa
, la
);
2284 /***********************************************************************
2285 * ScriptIsComplex (USP10.@)
2287 * Determine if a string is complex.
2290 * chars [I] Array of characters to test.
2291 * len [I] Length in characters.
2299 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2303 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2305 for (i
= 0; i
< len
; i
++)
2309 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2312 script
= get_char_script(chars
[i
]);
2313 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2314 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2320 /***********************************************************************
2321 * ScriptShapeOpenType (USP10.@)
2323 * Produce glyphs and visual attributes for a run.
2326 * hdc [I] Device context.
2327 * psc [I/O] Opaque pointer to a script cache.
2328 * psa [I/O] Script analysis.
2329 * tagScript [I] The OpenType tag for the Script
2330 * tagLangSys [I] The OpenType tag for the Language
2331 * rcRangeChars[I] Array of Character counts in each range
2332 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2333 * cRanges [I] Count of ranges
2334 * pwcChars [I] Array of characters specifying the run.
2335 * cChars [I] Number of characters in pwcChars.
2336 * cMaxGlyphs [I] Length of pwOutGlyphs.
2337 * pwLogClust [O] Array of logical cluster info.
2338 * pCharProps [O] Array of character property values
2339 * pwOutGlyphs [O] Array of glyphs.
2340 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2341 * pcGlyphs [O] Number of glyphs returned.
2345 * Failure: Non-zero HRESULT value.
2347 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2348 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2349 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2350 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2351 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2352 int cMaxGlyphs
, WORD
*pwLogClust
,
2353 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2354 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2360 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2362 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2363 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2364 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2366 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2367 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2369 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2370 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2373 FIXME("Ranges not supported yet\n");
2375 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2378 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2379 if (!pwLogClust
) return E_FAIL
;
2381 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2382 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2384 /* set fNoGlyphIndex non truetype/opentype fonts */
2385 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2386 psa
->fNoGlyphIndex
= TRUE
;
2388 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2389 for (i
= 0; i
< cChars
; i
++)
2392 if (rtl
) idx
= cChars
- 1 - i
;
2393 /* FIXME: set to better values */
2394 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2395 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2396 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2397 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2398 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2399 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2401 /* FIXME: have the shaping engine set this */
2402 pCharProps
[i
].fCanGlyphAlone
= 0;
2404 pwLogClust
[i
] = idx
;
2407 if (psa
&& !psa
->fNoGlyphIndex
)
2410 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2412 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2413 if (!rChars
) return E_OUTOFMEMORY
;
2414 for (i
= 0; i
< cChars
; i
++)
2418 if (rtl
) idx
= cChars
- 1 - i
;
2420 chInput
= mirror_char(pwcChars
[idx
]);
2422 chInput
= pwcChars
[idx
];
2423 /* special case for tabs */
2424 if (chInput
== 0x0009)
2426 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2434 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
)
2439 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2441 rChars
[i
] = chInput
;
2444 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2445 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2446 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2451 TRACE("no glyph translation\n");
2452 for (i
= 0; i
< cChars
; i
++)
2455 /* No mirroring done here */
2456 if (rtl
) idx
= cChars
- 1 - i
;
2457 pwOutGlyphs
[i
] = pwcChars
[idx
];
2465 /***********************************************************************
2466 * ScriptShape (USP10.@)
2468 * Produce glyphs and visual attributes for a run.
2471 * hdc [I] Device context.
2472 * psc [I/O] Opaque pointer to a script cache.
2473 * pwcChars [I] Array of characters specifying the run.
2474 * cChars [I] Number of characters in pwcChars.
2475 * cMaxGlyphs [I] Length of pwOutGlyphs.
2476 * psa [I/O] Script analysis.
2477 * pwOutGlyphs [O] Array of glyphs.
2478 * pwLogClust [O] Array of logical cluster info.
2479 * psva [O] Array of visual attributes.
2480 * pcGlyphs [O] Number of glyphs returned.
2484 * Failure: Non-zero HRESULT value.
2486 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2487 int cChars
, int cMaxGlyphs
,
2488 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2489 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2493 SCRIPT_CHARPROP
*charProps
;
2494 SCRIPT_GLYPHPROP
*glyphProps
;
2496 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2497 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2499 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2500 if (!charProps
) return E_OUTOFMEMORY
;
2501 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2504 heap_free(charProps
);
2505 return E_OUTOFMEMORY
;
2508 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2512 for (i
= 0; i
< *pcGlyphs
; i
++)
2513 psva
[i
] = glyphProps
[i
].sva
;
2516 heap_free(charProps
);
2517 heap_free(glyphProps
);
2522 /***********************************************************************
2523 * ScriptPlaceOpenType (USP10.@)
2525 * Produce advance widths for a run.
2528 * hdc [I] Device context.
2529 * psc [I/O] Opaque pointer to a script cache.
2530 * psa [I/O] String analysis.
2531 * tagScript [I] The OpenType tag for the Script
2532 * tagLangSys [I] The OpenType tag for the Language
2533 * rcRangeChars[I] Array of Character counts in each range
2534 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2535 * cRanges [I] Count of ranges
2536 * pwcChars [I] Array of characters specifying the run.
2537 * pwLogClust [I] Array of logical cluster info
2538 * pCharProps [I] Array of character property values
2539 * cChars [I] Number of characters in pwcChars.
2540 * pwGlyphs [I] Array of glyphs.
2541 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2542 * cGlyphs [I] Count of Glyphs
2543 * piAdvance [O] Array of advance widths.
2544 * pGoffset [O] Glyph offsets.
2545 * pABC [O] Combined ABC width.
2549 * Failure: Non-zero HRESULT value.
2552 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2553 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2554 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2555 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2556 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2557 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2558 int cGlyphs
, int *piAdvance
,
2559 GOFFSET
*pGoffset
, ABC
*pABC
2565 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2567 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2568 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2569 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2572 if (!pGlyphProps
) return E_INVALIDARG
;
2573 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2574 if (!pGoffset
) return E_FAIL
;
2577 FIXME("Ranges not supported yet\n");
2579 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2580 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2582 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2583 for (i
= 0; i
< cGlyphs
; i
++)
2586 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2588 if (!hdc
) return E_PENDING
;
2589 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2591 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2596 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2598 abc
.abcA
= abc
.abcC
= 0;
2600 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2604 pABC
->abcA
+= abc
.abcA
;
2605 pABC
->abcB
+= abc
.abcB
;
2606 pABC
->abcC
+= abc
.abcC
;
2608 /* FIXME: set to more reasonable values */
2609 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2610 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2613 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2617 /***********************************************************************
2618 * ScriptPlace (USP10.@)
2620 * Produce advance widths for a run.
2623 * hdc [I] Device context.
2624 * psc [I/O] Opaque pointer to a script cache.
2625 * pwGlyphs [I] Array of glyphs.
2626 * cGlyphs [I] Number of glyphs in pwGlyphs.
2627 * psva [I] Array of visual attributes.
2628 * psa [I/O] String analysis.
2629 * piAdvance [O] Array of advance widths.
2630 * pGoffset [O] Glyph offsets.
2631 * pABC [O] Combined ABC width.
2635 * Failure: Non-zero HRESULT value.
2637 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2638 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2639 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2642 SCRIPT_GLYPHPROP
*glyphProps
;
2645 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2646 piAdvance
, pGoffset
, pABC
);
2648 if (!psva
) return E_INVALIDARG
;
2649 if (!pGoffset
) return E_FAIL
;
2651 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2652 if (!glyphProps
) return E_OUTOFMEMORY
;
2654 for (i
= 0; i
< cGlyphs
; i
++)
2655 glyphProps
[i
].sva
= psva
[i
];
2657 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2659 heap_free(glyphProps
);
2664 /***********************************************************************
2665 * ScriptGetCMap (USP10.@)
2667 * Retrieve glyph indices.
2670 * hdc [I] Device context.
2671 * psc [I/O] Opaque pointer to a script cache.
2672 * pwcInChars [I] Array of Unicode characters.
2673 * cChars [I] Number of characters in pwcInChars.
2674 * dwFlags [I] Flags.
2675 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2679 * Failure: Non-zero HRESULT value.
2681 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2682 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2687 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2688 cChars
, dwFlags
, pwOutGlyphs
);
2690 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2694 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2696 for (i
= 0; i
< cChars
; i
++)
2699 if (dwFlags
== SGCM_RTL
)
2700 inChar
= mirror_char(pwcInChars
[i
]);
2702 inChar
= pwcInChars
[i
];
2703 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2706 if (!hdc
) return E_PENDING
;
2707 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2708 if (glyph
== 0xffff)
2713 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2719 TRACE("no glyph translation\n");
2720 for (i
= 0; i
< cChars
; i
++)
2723 if (dwFlags
== SGCM_RTL
)
2724 inChar
= mirror_char(pwcInChars
[i
]);
2726 inChar
= pwcInChars
[i
];
2727 pwOutGlyphs
[i
] = inChar
;
2733 /***********************************************************************
2734 * ScriptTextOut (USP10.@)
2737 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2738 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2739 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2740 const int *piJustify
, const GOFFSET
*pGoffset
)
2744 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2745 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2746 piAdvance
, piJustify
, pGoffset
);
2748 if (!hdc
|| !psc
) return E_INVALIDARG
;
2749 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2751 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2752 fuOptions
|= ETO_IGNORELANGUAGE
;
2753 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2754 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2756 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2761 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2763 return E_OUTOFMEMORY
;
2765 for (i
= 0; i
< cGlyphs
; i
++)
2766 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2768 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2770 heap_free(rtlGlyphs
);
2773 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2779 /***********************************************************************
2780 * ScriptCacheGetHeight (USP10.@)
2782 * Retrieve the height of the font in the cache.
2785 * hdc [I] Device context.
2786 * psc [I/O] Opaque pointer to a script cache.
2787 * height [O] Receives font height.
2791 * Failure: Non-zero HRESULT value.
2793 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2797 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2799 if (!height
) return E_INVALIDARG
;
2800 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2802 *height
= get_cache_height(psc
);
2806 /***********************************************************************
2807 * ScriptGetGlyphABCWidth (USP10.@)
2809 * Retrieve the width of a glyph.
2812 * hdc [I] Device context.
2813 * psc [I/O] Opaque pointer to a script cache.
2814 * glyph [I] Glyph to retrieve the width for.
2815 * abc [O] ABC widths of the glyph.
2819 * Failure: Non-zero HRESULT value.
2821 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2825 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2827 if (!abc
) return E_INVALIDARG
;
2828 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2830 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
2832 if (!hdc
) return E_PENDING
;
2833 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2835 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
2840 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
2842 abc
->abcA
= abc
->abcC
= 0;
2844 set_cache_glyph_widths(psc
, glyph
, abc
);
2849 /***********************************************************************
2850 * ScriptLayout (USP10.@)
2852 * Map embedding levels to visual and/or logical order.
2855 * runs [I] Size of level array.
2856 * level [I] Array of embedding levels.
2857 * vistolog [O] Map of embedding levels from visual to logical order.
2858 * logtovis [O] Map of embedding levels from logical to visual order.
2862 * Failure: Non-zero HRESULT value.
2865 * This stub works correctly for any sequence of a single
2866 * embedding level but not for sequences of different
2867 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2869 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
2874 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
2876 if (!level
|| (!vistolog
&& !logtovis
))
2877 return E_INVALIDARG
;
2879 indexs
= heap_alloc(sizeof(int) * runs
);
2881 return E_OUTOFMEMORY
;
2886 for( ich
= 0; ich
< runs
; ich
++)
2891 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2892 for (ich
= 0; ich
< runs
; ich
++)
2893 vistolog
[ich
] = indexs
[ich
];
2899 for( ich
= 0; ich
< runs
; ich
++)
2904 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2905 for (ich
= 0; ich
< runs
; ich
++)
2906 logtovis
[ich
] = indexs
[ich
];
2913 /***********************************************************************
2914 * ScriptStringGetLogicalWidths (USP10.@)
2916 * Returns logical widths from a string analysis.
2919 * ssa [I] string analysis.
2920 * piDx [O] logical widths returned.
2924 * Failure: a non-zero HRESULT.
2926 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
2929 StringAnalysis
*analysis
= ssa
;
2931 TRACE("%p, %p\n", ssa
, piDx
);
2933 if (!analysis
) return S_FALSE
;
2934 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2936 for (i
= 0; i
< analysis
->numItems
; i
++)
2938 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2941 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
2944 for (j
= 0; j
< cChar
; j
++)
2947 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
2948 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
2949 cChar
, j
, direction
, NULL
, NULL
);
2950 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
);
2952 for (k
= 0; k
< clust_size
; k
++)
2954 piDx
[next
] = advance
/ clust_size
;
2963 /***********************************************************************
2964 * ScriptStringValidate (USP10.@)
2966 * Validate a string analysis.
2969 * ssa [I] string analysis.
2973 * Failure: S_FALSE if invalid sequences are found
2974 * or a non-zero HRESULT if it fails.
2976 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
2978 StringAnalysis
*analysis
= ssa
;
2980 TRACE("(%p)\n", ssa
);
2982 if (!analysis
) return E_INVALIDARG
;
2983 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
2986 /***********************************************************************
2987 * ScriptString_pSize (USP10.@)
2989 * Retrieve width and height of an analysed string.
2992 * ssa [I] string analysis.
2995 * Success: Pointer to a SIZE structure.
2998 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
3001 StringAnalysis
*analysis
= ssa
;
3003 TRACE("(%p)\n", ssa
);
3005 if (!analysis
) return NULL
;
3006 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
3010 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
3011 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
3013 analysis
->sz
->cx
= 0;
3014 for (i
= 0; i
< analysis
->numItems
; i
++)
3016 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3017 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3018 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3019 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3022 return analysis
->sz
;
3025 /***********************************************************************
3026 * ScriptString_pLogAttr (USP10.@)
3028 * Retrieve logical attributes of an analysed string.
3031 * ssa [I] string analysis.
3034 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3037 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3039 StringAnalysis
*analysis
= ssa
;
3041 TRACE("(%p)\n", ssa
);
3043 if (!analysis
) return NULL
;
3044 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3045 return analysis
->logattrs
;
3048 /***********************************************************************
3049 * ScriptString_pcOutChars (USP10.@)
3051 * Retrieve the length of a string after clipping.
3054 * ssa [I] String analysis.
3057 * Success: Pointer to the length.
3060 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3062 StringAnalysis
*analysis
= ssa
;
3064 TRACE("(%p)\n", ssa
);
3066 if (!analysis
) return NULL
;
3067 return &analysis
->clip_len
;
3070 /***********************************************************************
3071 * ScriptStringGetOrder (USP10.@)
3073 * Retrieve a glyph order map.
3076 * ssa [I] String analysis.
3077 * order [I/O] Array of glyph positions.
3081 * Failure: a non-zero HRESULT.
3083 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3087 StringAnalysis
*analysis
= ssa
;
3089 TRACE("(%p)\n", ssa
);
3091 if (!analysis
) return S_FALSE
;
3092 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3094 /* FIXME: handle RTL scripts */
3095 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3096 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3102 /***********************************************************************
3103 * ScriptGetLogicalWidths (USP10.@)
3105 * Convert advance widths to logical widths.
3108 * sa [I] Script analysis.
3109 * nbchars [I] Number of characters.
3110 * nbglyphs [I] Number of glyphs.
3111 * glyph_width [I] Array of glyph widths.
3112 * log_clust [I] Array of logical clusters.
3113 * sva [I] Visual attributes.
3114 * widths [O] Array of logical widths.
3118 * Failure: a non-zero HRESULT.
3120 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3121 const int *glyph_width
, const WORD
*log_clust
,
3122 const SCRIPT_VISATTR
*sva
, int *widths
)
3126 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3127 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3130 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3134 /***********************************************************************
3135 * ScriptApplyLogicalWidth (USP10.@)
3137 * Generate glyph advance widths.
3140 * dx [I] Array of logical advance widths.
3141 * num_chars [I] Number of characters.
3142 * num_glyphs [I] Number of glyphs.
3143 * log_clust [I] Array of logical clusters.
3144 * sva [I] Visual attributes.
3145 * advance [I] Array of glyph advance widths.
3146 * sa [I] Script analysis.
3147 * abc [I/O] Summed ABC widths.
3148 * justify [O] Array of glyph advance widths.
3152 * Failure: a non-zero HRESULT.
3154 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3155 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3156 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3157 ABC
*abc
, int *justify
)
3161 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3162 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3164 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3168 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3169 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3173 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3175 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];