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 /* Myanmar: U+1000–U+109F */
111 { Script_Myanmar
, 0x1000, 0x109f, Script_Myanmar_Numeric
, 0},
112 /* Georgian: U+10A0–U+10FF */
113 { Script_Georgian
, 0x10a0, 0x10ff, 0, 0},
114 /* Vedic Extensions: U+1CD0-U+1CFF */
115 { Script_Devanagari
, 0x1cd0, 0x1cff, Script_Devanagari_Numeric
, 0},
116 /* Phonetic Extensions: U+1D00–U+1DBF */
117 { Script_Latin
, 0x1d00, 0x1dbf, 0, 0},
118 /* Combining Diacritical Marks Supplement: U+1DC0–U+1DFF */
119 { Script_Diacritical
,0x1dc0, 0x1dff, 0, 0},
120 /* Latin Extended Additional: U+1E00–U+1EFF */
121 { Script_Latin
, 0x1e00, 0x1eff, 0, 0},
122 /* Greek Extended: U+1F00–U+1FFF */
123 { Script_Greek
, 0x1f00, 0x1fff, 0, 0},
124 /* General Punctuation: U+2000 –U+206f */
125 { Script_Latin
, 0x2000, 0x206f, 0, 0},
126 /* Superscripts and Subscripts : U+2070 –U+209f */
127 /* Currency Symbols : U+20a0 –U+20cf */
128 { Script_Numeric2
, 0x2070, 0x2070, 0, 0},
129 { Script_Latin
, 0x2071, 0x2073, 0, 0},
130 { Script_Numeric2
, 0x2074, 0x2079, 0, 0},
131 { Script_Latin
, 0x207a, 0x207f, 0, 0},
132 { Script_Numeric2
, 0x2080, 0x2089, 0, 0},
133 { Script_Latin
, 0x208a, 0x20cf, 0, 0},
134 /* Letterlike Symbols : U+2100 –U+214f */
135 /* Number Forms : U+2150 –U+218f */
136 /* Arrows : U+2190 –U+21ff */
137 /* Mathematical Operators : U+2200 –U+22ff */
138 /* Miscellaneous Technical : U+2300 –U+23ff */
139 /* Control Pictures : U+2400 –U+243f */
140 /* Optical Character Recognition : U+2440 –U+245f */
141 /* Enclosed Alphanumerics : U+2460 –U+24ff */
142 /* Box Drawing : U+2500 –U+25ff */
143 /* Block Elements : U+2580 –U+259f */
144 /* Geometric Shapes : U+25a0 –U+25ff */
145 /* Miscellaneous Symbols : U+2600 –U+26ff */
146 /* Dingbats : U+2700 –U+27bf */
147 /* Miscellaneous Mathematical Symbols-A : U+27c0 –U+27ef */
148 /* Supplemental Arrows-A : U+27f0 –U+27ff */
149 { Script_Latin
, 0x2100, 0x27ff, 0, 0},
150 /* Supplemental Arrows-B : U+2900 –U+297f */
151 /* Miscellaneous Mathematical Symbols-B : U+2980 –U+29ff */
152 /* Supplemental Mathematical Operators : U+2a00 –U+2aff */
153 /* Miscellaneous Symbols and Arrows : U+2b00 –U+2bff */
154 { Script_Latin
, 0x2900, 0x2bff, 0, 0},
155 /* Latin Extended-C: U+2C60–U+2C7F */
156 { Script_Latin
, 0x2c60, 0x2c7f, 0, 0},
157 /* Georgian: U+2D00–U+2D2F */
158 { Script_Georgian
, 0x2d00, 0x2d2f, 0, 0},
159 /* Cyrillic Extended-A: U+2DE0–U+2DFF */
160 { Script_Cyrillic
, 0x2de0, 0x2dff, 0, 0},
161 /* Cyrillic Extended-B: U+A640–U+A69F */
162 { Script_Cyrillic
, 0xa640, 0xa69f, 0, 0},
163 /* Modifier Tone Letters: U+A700–U+A71F */
164 /* Latin Extended-D: U+A720–U+A7FF */
165 { Script_Latin
, 0xa700, 0xa7ff, 0, 0},
166 /* Phags-pa: U+A840–U+A87F */
167 { Script_Phags_pa
, 0xa840, 0xa87f, 0, 0},
168 /* Devanagari Extended: U+A8E0-U+A8FF */
169 { Script_Devanagari
, 0xa8e0, 0xa8ff, Script_Devanagari_Numeric
, 0},
170 /* Myanmar Extended-A: U+AA60–U+AA7F */
171 { Script_Myanmar
, 0xaa60, 0xaa7f, Script_Myanmar_Numeric
, 0},
172 /* Latin Ligatures: U+FB00–U+FB06 */
173 { Script_Latin
, 0xfb00, 0xfb06, 0, 0},
174 /* Armenian ligatures U+FB13..U+FB17 */
175 { Script_Armenian
, 0xfb13, 0xfb17, 0, 0},
176 /* Alphabetic Presentation Forms: U+FB1D–U+FB4F */
177 { Script_Hebrew
, 0xfb1d, 0xfb4f, 0, 0},
178 /* Arabic Presentation Forms-A: U+FB50–U+FDFF*/
179 { Script_Arabic
, 0xfb50, 0xfdff, 0, 0},
180 /* Arabic Presentation Forms-B: U+FE70–U+FEFF*/
181 { Script_Arabic
, 0xfe70, 0xfeff, 0, 0},
183 { SCRIPT_UNDEFINED
, 0, 0, 0}
186 typedef struct _scriptData
189 SCRIPT_PROPERTIES props
;
190 OPENTYPE_TAG scriptTag
;
191 WCHAR fallbackFont
[LF_FACESIZE
];
194 /* the must be in order so that the index matches the Script value */
195 static const scriptData scriptInformation
[] = {
196 {{SCRIPT_UNDEFINED
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
197 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
200 {{Script_Latin
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
201 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
202 MS_MAKE_TAG('l','a','t','n'),
204 {{Script_CR
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
205 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
208 {{Script_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
209 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
212 {{Script_Control
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
213 {LANG_ENGLISH
, 0, 1, 0, 0, ANSI_CHARSET
, 1, 0, 0, 0, 0, 0, 1, 0, 0},
216 {{Script_Punctuation
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
217 {LANG_NEUTRAL
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
220 {{Script_Arabic
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
221 {LANG_ARABIC
, 0, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 1, 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_Arabic_Numeric
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
225 {LANG_ARABIC
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
226 MS_MAKE_TAG('a','r','a','b'),
227 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
228 {{Script_Hebrew
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
229 {LANG_HEBREW
, 0, 1, 0, 1, HEBREW_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
230 MS_MAKE_TAG('h','e','b','r'),
231 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
232 {{Script_Syriac
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
233 {LANG_SYRIAC
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 1, 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_Persian
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
237 {LANG_PERSIAN
, 1, 1, 0, 0, ARABIC_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
238 MS_MAKE_TAG('s','y','r','c'),
239 {'E','s','t','r','a','n','g','e','l','o',' ','E','d','e','s','s','a',0}},
240 {{Script_Thaana
, 1, 1, 0, 0, 0, 0, { 1,0,0,0,0,0,0,0,0,0,0}},
241 {LANG_DIVEHI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
242 MS_MAKE_TAG('t','h','a','a'),
243 {'M','V',' ','B','o','l','i',0}},
244 {{Script_Greek
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
245 {LANG_GREEK
, 0, 0, 0, 0, GREEK_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
246 MS_MAKE_TAG('g','r','e','k'),
248 {{Script_Cyrillic
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
249 {LANG_RUSSIAN
, 0, 0, 0, 0, RUSSIAN_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
250 MS_MAKE_TAG('c','y','r','l'),
252 {{Script_Armenian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
253 {LANG_ARMENIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
254 MS_MAKE_TAG('a','r','m','n'),
255 {'S','y','l','f','a','e','n',0}},
256 {{Script_Georgian
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
257 {LANG_GEORGIAN
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
258 MS_MAKE_TAG('g','e','o','r'),
259 {'S','y','l','f','a','e','n',0}},
260 {{Script_Sinhala
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
261 {LANG_SINHALESE
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
262 MS_MAKE_TAG('s','i','n','h'),
263 {'I','s','k','o','o','l','a',' ','P','o','t','a',0}},
264 {{Script_Tibetan
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
265 {LANG_TIBETAN
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 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_Tibetan_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
269 {LANG_TIBETAN
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
270 MS_MAKE_TAG('t','i','b','t'),
271 {'M','i','c','r','o','s','o','f','t',' ','H','i','m','a','l','a','y','a',0}},
272 {{Script_Phags_pa
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
273 {LANG_MONGOLIAN
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
274 MS_MAKE_TAG('p','h','a','g'),
275 {'M','i','c','r','o','s','o','f','t',' ','P','h','a','g','s','P','a',0}},
276 {{Script_Thai
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
277 {LANG_THAI
, 0, 1, 1, 1, THAI_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 1},
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_Thai_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
281 {LANG_THAI
, 1, 1, 0, 0, THAI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
282 MS_MAKE_TAG('t','h','a','i'),
283 {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}},
284 {{Script_Lao
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
285 {LANG_LAO
, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 1, 0, 1, 0, 0, 0, 0},
286 MS_MAKE_TAG('l','a','o',' '),
287 {'D','o','k','C','h','a','m','p','a',0}},
288 {{Script_Lao_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
289 {LANG_LAO
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
290 MS_MAKE_TAG('l','a','o',' '),
291 {'D','o','k','C','h','a','m','p','a',0}},
292 {{Script_Devanagari
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
293 {LANG_HINDI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
294 MS_MAKE_TAG('d','e','v','a'),
295 {'M','a','n','g','a','l',0}},
296 {{Script_Devanagari_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
297 {LANG_HINDI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
298 MS_MAKE_TAG('d','e','v','a'),
299 {'M','a','n','g','a','l',0}},
300 {{Script_Bengali
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
301 {LANG_BENGALI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
302 MS_MAKE_TAG('b','e','n','g'),
303 {'V','r','i','n','d','a',0}},
304 {{Script_Bengali_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
305 {LANG_BENGALI
, 1, 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_Bengali_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
309 {LANG_BENGALI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
310 MS_MAKE_TAG('b','e','n','g'),
311 {'V','r','i','n','d','a',0}},
312 {{Script_Gurmukhi
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
313 {LANG_PUNJABI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
314 MS_MAKE_TAG('g','u','r','u'),
315 {'R','a','a','v','i',0}},
316 {{Script_Gurmukhi_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
317 {LANG_PUNJABI
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
318 MS_MAKE_TAG('g','u','r','u'),
319 {'R','a','a','v','i',0}},
320 {{Script_Gujarati
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
321 {LANG_GUJARATI
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
322 MS_MAKE_TAG('g','u','j','r'),
323 {'S','h','r','u','t','i',0}},
324 {{Script_Gujarati_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
325 {LANG_GUJARATI
, 1, 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_Gujarati_Currency
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
329 {LANG_GUJARATI
, 0, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
330 MS_MAKE_TAG('g','u','j','r'),
331 {'S','h','r','u','t','i',0}},
332 {{Script_Oriya
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
333 {LANG_ORIYA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
334 MS_MAKE_TAG('o','r','y','a'),
335 {'K','a','l','i','n','g','a',0}},
336 {{Script_Oriya_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
337 {LANG_ORIYA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
338 MS_MAKE_TAG('o','r','y','a'),
339 {'K','a','l','i','n','g','a',0}},
340 {{Script_Tamil
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
341 {LANG_TAMIL
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
342 MS_MAKE_TAG('t','a','m','l'),
343 {'L','a','t','h','a',0}},
344 {{Script_Tamil_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
345 {LANG_TAMIL
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
346 MS_MAKE_TAG('t','a','m','l'),
347 {'L','a','t','h','a',0}},
348 {{Script_Telugu
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
349 {LANG_TELUGU
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
350 MS_MAKE_TAG('t','e','l','u'),
351 {'G','a','u','t','a','m','i',0}},
352 {{Script_Telugu_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
353 {LANG_TELUGU
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
354 MS_MAKE_TAG('t','e','l','u'),
355 {'G','a','u','t','a','m','i',0}},
356 {{Script_Kannada
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
357 {LANG_KANNADA
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
358 MS_MAKE_TAG('k','n','d','a'),
359 {'T','u','n','g','a',0}},
360 {{Script_Kannada_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
361 {LANG_KANNADA
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
362 MS_MAKE_TAG('k','n','d','a'),
363 {'T','u','n','g','a',0}},
364 {{Script_Malayalam
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
365 {LANG_MALAYALAM
, 0, 1, 0, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
366 MS_MAKE_TAG('m','l','y','m'),
367 {'K','a','r','t','i','k','a',0}},
368 {{Script_Malayalam_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
369 {LANG_MALAYALAM
, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
370 MS_MAKE_TAG('m','l','y','m'),
371 {'K','a','r','t','i','k','a',0}},
372 {{Script_Diacritical
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
373 {LANG_ENGLISH
, 0, 1, 0, 1, ANSI_CHARSET
, 0, 0, 0, 0, 0, 1, 1, 0, 0},
376 {{Script_Punctuation2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
377 {LANG_ENGLISH
, 0, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
378 MS_MAKE_TAG('l','a','t','n'),
380 {{Script_Numeric2
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
381 {LANG_ENGLISH
, 1, 0, 0, 0, ANSI_CHARSET
, 0, 0, 0, 0, 0, 0, 1, 0, 0},
384 {{Script_Myanmar
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
385 {0x55, 0, 1, 1, 1, DEFAULT_CHARSET
, 0, 0, 0, 0, 1, 0, 0, 0, 0},
386 MS_MAKE_TAG('m','y','m','r'),
388 {{Script_Myanmar_Numeric
, 0, 0, 0, 0, 0, 0, { 0,0,0,0,0,0,0,0,0,0,0}},
389 {0x55, 1, 1, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 0, 0, 0, 0, 0, 0},
390 MS_MAKE_TAG('m','y','m','r'),
394 static const SCRIPT_PROPERTIES
*script_props
[] =
396 &scriptInformation
[0].props
, &scriptInformation
[1].props
,
397 &scriptInformation
[2].props
, &scriptInformation
[3].props
,
398 &scriptInformation
[4].props
, &scriptInformation
[5].props
,
399 &scriptInformation
[6].props
, &scriptInformation
[7].props
,
400 &scriptInformation
[8].props
, &scriptInformation
[9].props
,
401 &scriptInformation
[10].props
, &scriptInformation
[11].props
,
402 &scriptInformation
[12].props
, &scriptInformation
[13].props
,
403 &scriptInformation
[14].props
, &scriptInformation
[15].props
,
404 &scriptInformation
[16].props
, &scriptInformation
[17].props
,
405 &scriptInformation
[18].props
, &scriptInformation
[19].props
,
406 &scriptInformation
[20].props
, &scriptInformation
[21].props
,
407 &scriptInformation
[22].props
, &scriptInformation
[23].props
,
408 &scriptInformation
[24].props
, &scriptInformation
[25].props
,
409 &scriptInformation
[26].props
, &scriptInformation
[27].props
,
410 &scriptInformation
[28].props
, &scriptInformation
[29].props
,
411 &scriptInformation
[30].props
, &scriptInformation
[31].props
,
412 &scriptInformation
[32].props
, &scriptInformation
[33].props
,
413 &scriptInformation
[34].props
, &scriptInformation
[35].props
,
414 &scriptInformation
[36].props
, &scriptInformation
[37].props
,
415 &scriptInformation
[38].props
, &scriptInformation
[39].props
,
416 &scriptInformation
[40].props
, &scriptInformation
[41].props
,
417 &scriptInformation
[42].props
, &scriptInformation
[43].props
,
418 &scriptInformation
[44].props
, &scriptInformation
[45].props
,
419 &scriptInformation
[46].props
, &scriptInformation
[47].props
428 SCRIPT_VISATTR
* psva
;
444 StringGlyphs
* glyphs
;
445 SCRIPT_LOGATTR
* logattrs
;
450 static inline void *heap_alloc(SIZE_T size
)
452 return HeapAlloc(GetProcessHeap(), 0, size
);
455 static inline void *heap_alloc_zero(SIZE_T size
)
457 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
460 static inline void *heap_realloc_zero(LPVOID mem
, SIZE_T size
)
462 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, mem
, size
);
465 static inline BOOL
heap_free(LPVOID mem
)
467 return HeapFree(GetProcessHeap(), 0, mem
);
470 static inline WCHAR
get_cache_default_char(SCRIPT_CACHE
*psc
)
472 return ((ScriptCache
*)*psc
)->tm
.tmDefaultChar
;
475 static inline LONG
get_cache_height(SCRIPT_CACHE
*psc
)
477 return ((ScriptCache
*)*psc
)->tm
.tmHeight
;
480 static inline BYTE
get_cache_pitch_family(SCRIPT_CACHE
*psc
)
482 return ((ScriptCache
*)*psc
)->tm
.tmPitchAndFamily
;
485 static inline WORD
get_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
)
487 WORD
*block
= ((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
489 if (!block
) return 0;
490 return block
[c
& GLYPH_BLOCK_MASK
];
493 static inline WORD
set_cache_glyph(SCRIPT_CACHE
*psc
, WCHAR c
, WORD glyph
)
495 WORD
**block
= &((ScriptCache
*)*psc
)->glyphs
[c
>> GLYPH_BLOCK_SHIFT
];
497 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(WORD
) * GLYPH_BLOCK_SIZE
))) return 0;
498 return ((*block
)[c
& GLYPH_BLOCK_MASK
] = glyph
);
501 static inline BOOL
get_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
503 static const ABC nil
;
504 ABC
*block
= ((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
506 if (!block
|| !memcmp(&block
[glyph
& GLYPH_BLOCK_MASK
], &nil
, sizeof(ABC
))) return FALSE
;
507 memcpy(abc
, &block
[glyph
& GLYPH_BLOCK_MASK
], sizeof(ABC
));
511 static inline BOOL
set_cache_glyph_widths(SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
513 ABC
**block
= &((ScriptCache
*)*psc
)->widths
[glyph
>> GLYPH_BLOCK_SHIFT
];
515 if (!*block
&& !(*block
= heap_alloc_zero(sizeof(ABC
) * GLYPH_BLOCK_SIZE
))) return FALSE
;
516 memcpy(&(*block
)[glyph
& GLYPH_BLOCK_MASK
], abc
, sizeof(ABC
));
520 static HRESULT
init_script_cache(const HDC hdc
, SCRIPT_CACHE
*psc
)
524 if (!psc
) return E_INVALIDARG
;
525 if (*psc
) return S_OK
;
526 if (!hdc
) return E_PENDING
;
528 if (!(sc
= heap_alloc_zero(sizeof(ScriptCache
)))) return E_OUTOFMEMORY
;
529 if (!GetTextMetricsW(hdc
, &sc
->tm
))
534 if (!GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(LOGFONTW
), &sc
->lf
))
539 sc
->sfnt
= (GetFontData(hdc
, MS_MAKE_TAG('h','e','a','d'), 0, NULL
, 0)!=GDI_ERROR
);
541 TRACE("<- %p\n", sc
);
545 static WCHAR
mirror_char( WCHAR ch
)
547 extern const WCHAR wine_mirror_map
[];
548 return ch
+ wine_mirror_map
[wine_mirror_map
[ch
>> 8] + (ch
& 0xff)];
551 static WORD
get_char_script( WCHAR ch
)
553 static const WCHAR latin_punc
[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
557 if (ch
== 0xc || ch
== 0x20 || ch
== 0x202f)
560 /* These punctuation are separated out as Latin punctuation */
561 if (strchrW(latin_punc
,ch
))
562 return Script_Punctuation2
;
564 /* These chars are itemized as Punctuation by Windows */
565 if (ch
== 0x2212 || ch
== 0x2044)
566 return Script_Punctuation
;
568 GetStringTypeW(CT_CTYPE1
, &ch
, 1, &type
);
571 return SCRIPT_UNDEFINED
;
574 return Script_Control
;
579 if (ch
< scriptRanges
[i
].rangeFirst
|| scriptRanges
[i
].script
== SCRIPT_UNDEFINED
)
582 if (ch
>= scriptRanges
[i
].rangeFirst
&& ch
<= scriptRanges
[i
].rangeLast
)
584 if (scriptRanges
[i
].numericScript
&& type
& C1_DIGIT
)
585 return scriptRanges
[i
].numericScript
;
586 if (scriptRanges
[i
].punctScript
&& type
& C1_PUNCT
)
587 return scriptRanges
[i
].punctScript
;
588 return scriptRanges
[i
].script
;
593 return SCRIPT_UNDEFINED
;
596 /***********************************************************************
600 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
604 case DLL_PROCESS_ATTACH
:
605 DisableThreadLibraryCalls(hInstDLL
);
607 case DLL_PROCESS_DETACH
:
613 /***********************************************************************
614 * ScriptFreeCache (USP10.@)
616 * Free a script cache.
619 * psc [I/O] Script cache.
623 * Failure: Non-zero HRESULT value.
625 HRESULT WINAPI
ScriptFreeCache(SCRIPT_CACHE
*psc
)
632 for (i
= 0; i
< GLYPH_MAX
/ GLYPH_BLOCK_SIZE
; i
++)
634 heap_free(((ScriptCache
*)*psc
)->glyphs
[i
]);
635 heap_free(((ScriptCache
*)*psc
)->widths
[i
]);
637 heap_free(((ScriptCache
*)*psc
)->GSUB_Table
);
638 heap_free(((ScriptCache
*)*psc
)->GDEF_Table
);
639 heap_free(((ScriptCache
*)*psc
)->features
);
646 /***********************************************************************
647 * ScriptGetProperties (USP10.@)
649 * Retrieve a list of script properties.
652 * props [I] Pointer to an array of SCRIPT_PROPERTIES pointers.
653 * num [I] Pointer to the number of scripts.
657 * Failure: Non-zero HRESULT value.
660 * Behaviour matches WinXP.
662 HRESULT WINAPI
ScriptGetProperties(const SCRIPT_PROPERTIES
***props
, int *num
)
664 TRACE("(%p,%p)\n", props
, num
);
666 if (!props
&& !num
) return E_INVALIDARG
;
668 if (num
) *num
= sizeof(script_props
)/sizeof(script_props
[0]);
669 if (props
) *props
= script_props
;
674 /***********************************************************************
675 * ScriptGetFontProperties (USP10.@)
677 * Get information on special glyphs.
680 * hdc [I] Device context.
681 * psc [I/O] Opaque pointer to a script cache.
682 * sfp [O] Font properties structure.
684 HRESULT WINAPI
ScriptGetFontProperties(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_FONTPROPERTIES
*sfp
)
688 TRACE("%p,%p,%p\n", hdc
, psc
, sfp
);
690 if (!sfp
) return E_INVALIDARG
;
691 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
693 if (sfp
->cBytes
!= sizeof(SCRIPT_FONTPROPERTIES
))
696 /* return something sensible? */
698 sfp
->wgDefault
= get_cache_default_char(psc
);
700 sfp
->wgKashida
= 0xffff;
701 sfp
->iKashidaWidth
= 0;
706 /***********************************************************************
707 * ScriptRecordDigitSubstitution (USP10.@)
709 * Record digit substitution settings for a given locale.
712 * locale [I] Locale identifier.
713 * sds [I] Structure to record substitution settings.
717 * Failure: E_POINTER if sds is NULL, E_INVALIDARG otherwise.
720 * http://blogs.msdn.com/michkap/archive/2006/02/22/536877.aspx
722 HRESULT WINAPI
ScriptRecordDigitSubstitution(LCID locale
, SCRIPT_DIGITSUBSTITUTE
*sds
)
726 TRACE("0x%x, %p\n", locale
, sds
);
728 /* This implementation appears to be correct for all languages, but it's
729 * not clear if sds->DigitSubstitute is ever set to anything except
730 * CONTEXT or NONE in reality */
732 if (!sds
) return E_POINTER
;
734 locale
= ConvertDefaultLocale(locale
);
736 if (!IsValidLocale(locale
, LCID_INSTALLED
))
739 plgid
= PRIMARYLANGID(LANGIDFROMLCID(locale
));
740 sds
->TraditionalDigitLanguage
= plgid
;
742 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
743 sds
->NationalDigitLanguage
= plgid
;
745 sds
->NationalDigitLanguage
= LANG_ENGLISH
;
747 if (!GetLocaleInfoW(locale
, LOCALE_IDIGITSUBSTITUTION
| LOCALE_RETURN_NUMBER
,
748 (LPWSTR
)&sub
, sizeof(sub
)/sizeof(WCHAR
))) return E_INVALIDARG
;
753 if (plgid
== LANG_ARABIC
|| plgid
== LANG_FARSI
)
754 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_CONTEXT
;
756 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
759 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NONE
;
762 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_NATIONAL
;
765 sds
->DigitSubstitute
= SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
;
773 /***********************************************************************
774 * ScriptApplyDigitSubstitution (USP10.@)
776 * Apply digit substitution settings.
779 * sds [I] Structure with recorded substitution settings.
780 * sc [I] Script control structure.
781 * ss [I] Script state structure.
785 * Failure: E_INVALIDARG if sds is invalid. Otherwise an HRESULT.
787 HRESULT WINAPI
ScriptApplyDigitSubstitution(const SCRIPT_DIGITSUBSTITUTE
*sds
,
788 SCRIPT_CONTROL
*sc
, SCRIPT_STATE
*ss
)
790 SCRIPT_DIGITSUBSTITUTE psds
;
792 TRACE("%p, %p, %p\n", sds
, sc
, ss
);
794 if (!sc
|| !ss
) return E_POINTER
;
798 if (ScriptRecordDigitSubstitution(LOCALE_USER_DEFAULT
, &psds
) != S_OK
)
802 sc
->uDefaultLanguage
= LANG_ENGLISH
;
803 sc
->fContextDigits
= 0;
804 ss
->fDigitSubstitute
= 0;
806 switch (sds
->DigitSubstitute
) {
807 case SCRIPT_DIGITSUBSTITUTE_CONTEXT
:
808 case SCRIPT_DIGITSUBSTITUTE_NATIONAL
:
809 case SCRIPT_DIGITSUBSTITUTE_NONE
:
810 case SCRIPT_DIGITSUBSTITUTE_TRADITIONAL
:
817 static inline BOOL
is_indic(WORD script
)
819 return (script
>= Script_Devanagari
&& script
<= Script_Malayalam_Numeric
);
822 static inline WORD
base_indic(WORD script
)
826 case Script_Devanagari
:
827 case Script_Devanagari_Numeric
: return Script_Devanagari
;
829 case Script_Bengali_Numeric
:
830 case Script_Bengali_Currency
: return Script_Bengali
;
831 case Script_Gurmukhi
:
832 case Script_Gurmukhi_Numeric
: return Script_Gurmukhi
;
833 case Script_Gujarati
:
834 case Script_Gujarati_Numeric
:
835 case Script_Gujarati_Currency
: return Script_Gujarati
;
837 case Script_Oriya_Numeric
: return Script_Oriya
;
839 case Script_Tamil_Numeric
: return Script_Tamil
;
841 case Script_Telugu_Numeric
: return Script_Telugu
;
843 case Script_Kannada_Numeric
: return Script_Kannada
;
844 case Script_Malayalam
:
845 case Script_Malayalam_Numeric
: return Script_Malayalam
;
851 /***********************************************************************
852 * ScriptItemizeOpenType (USP10.@)
854 * Split a Unicode string into shapeable parts.
857 * pwcInChars [I] String to split.
858 * cInChars [I] Number of characters in pwcInChars.
859 * cMaxItems [I] Maximum number of items to return.
860 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
861 * psState [I] Pointer to a SCRIPT_STATE structure.
862 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
863 * pScriptTags [O] Buffer to receive OPENTYPE_TAGs.
864 * pcItems [O] Number of script items returned.
868 * Failure: Non-zero HRESULT value.
870 HRESULT WINAPI
ScriptItemizeOpenType(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
871 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
872 SCRIPT_ITEM
*pItems
, OPENTYPE_TAG
*pScriptTags
, int *pcItems
)
875 #define Numeric_space 0x0020
879 int cnt
= 0, index
= 0, str
= 0;
883 WORD
*strength
= NULL
;
884 WORD
*scripts
= NULL
;
887 WORD last_indic
= -1;
889 BOOL forceLevels
= FALSE
;
891 TRACE("%s,%d,%d,%p,%p,%p,%p\n", debugstr_wn(pwcInChars
, cInChars
), cInChars
, cMaxItems
,
892 psControl
, psState
, pItems
, pcItems
);
894 if (!pwcInChars
|| !cInChars
|| !pItems
|| cMaxItems
< 2)
897 scripts
= heap_alloc(cInChars
* sizeof(WORD
));
899 return E_OUTOFMEMORY
;
901 for (i
= 0; i
< cInChars
; i
++)
903 scripts
[i
] = get_char_script(pwcInChars
[i
]);
904 /* Devanagari danda (U+0964) and double danda (U+0965) are used for
906 if ((pwcInChars
[i
] == 0x964 || pwcInChars
[i
] ==0x965) && last_indic
> 0)
907 scripts
[i
] = last_indic
;
908 else if (is_indic(scripts
[i
]))
909 last_indic
= base_indic(scripts
[i
]);
911 /* Some unicode points (Zero Width Space U+200B -
912 Right-to-Left Mark U+200F) will force us into bidi mode */
913 if (!forceLevels
&& pwcInChars
[i
] >= 0x200B && pwcInChars
[i
] <= 0x200F)
916 /* Diacritical marks merge with other scripts */
917 if (scripts
[i
] == Script_Diacritical
&& i
> 0)
918 scripts
[i
] = scripts
[i
-1];
921 for (i
= 0; i
< cInChars
; i
++)
923 /* Joiners get merged preferencially right */
924 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
928 scripts
[i
] = scripts
[i
-1];
931 for (j
= i
+1; j
< cInChars
; j
++)
933 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
935 scripts
[i
] = scripts
[j
];
943 if (psState
&& psControl
)
945 levels
= heap_alloc_zero(cInChars
* sizeof(WORD
));
949 return E_OUTOFMEMORY
;
952 BIDI_DetermineLevels(pwcInChars
, cInChars
, psState
, psControl
, levels
);
953 baselevel
= levels
[0];
954 for (i
= 0; i
< cInChars
; i
++)
955 if (levels
[i
]!=levels
[0])
957 if (i
>= cInChars
&& !odd(baselevel
) && !odd(psState
->uBidiLevel
) && !forceLevels
)
964 BOOL inNumber
= FALSE
;
965 static WCHAR math_punc
[] = {'#','$','%','+',',','-','.','/',':',0x2212, 0x2044, 0x00a0,0};
967 strength
= heap_alloc_zero(cInChars
* sizeof(WORD
));
972 return E_OUTOFMEMORY
;
974 BIDI_GetStrengths(pwcInChars
, cInChars
, psControl
, strength
);
976 /* We currently mis-level leading Diacriticals */
977 if (scripts
[0] == Script_Diacritical
)
978 for (i
= 0; i
< cInChars
&& scripts
[0] == Script_Diacritical
; i
++)
980 levels
[i
] = odd(levels
[i
])?levels
[i
]+1:levels
[i
];
981 strength
[i
] = BIDI_STRONG
;
984 for (i
= 0; i
< cInChars
; i
++)
986 /* Script_Numeric and select puncuation at level 0 get bumped to level 2 */
987 if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && inNumber
&& strchrW(math_punc
,pwcInChars
[i
]))
989 scripts
[i
] = Script_Numeric
;
992 else if ((levels
[i
] == 0 || (odd(psState
->uBidiLevel
) && levels
[i
] == psState
->uBidiLevel
+1)) && scripts
[i
] == Script_Numeric
)
1000 /* Joiners get merged preferencially right */
1001 if (i
> 0 && (pwcInChars
[i
] == ZWJ
|| pwcInChars
[i
] == ZWNJ
))
1004 if (i
+1 == cInChars
&& levels
[i
-1] == levels
[i
])
1005 strength
[i
] = strength
[i
-1];
1007 for (j
= i
+1; j
< cInChars
&& levels
[i
] == levels
[j
]; j
++)
1008 if (pwcInChars
[j
] != ZWJ
&& pwcInChars
[j
] != ZWNJ
&& pwcInChars
[j
] != Numeric_space
)
1010 strength
[i
] = strength
[j
];
1015 if (psControl
->fMergeNeutralItems
)
1017 /* Merge the neutrals */
1018 for (i
= 0; i
< cInChars
; i
++)
1020 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1023 for (j
= i
; j
> 0; j
--)
1025 if (levels
[i
] != levels
[j
])
1027 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1029 scripts
[i
] = scripts
[j
];
1030 strength
[i
] = strength
[j
];
1035 /* Try going the other way */
1036 if (strength
[i
] == BIDI_NEUTRAL
|| strength
[i
] == BIDI_WEAK
)
1039 for (j
= i
; j
< cInChars
; j
++)
1041 if (levels
[i
] != levels
[j
])
1043 if ((strength
[j
] == BIDI_STRONG
) || (strength
[i
] == BIDI_NEUTRAL
&& strength
[j
] == BIDI_WEAK
))
1045 scripts
[i
] = scripts
[j
];
1046 strength
[i
] = strength
[j
];
1056 while ((!levels
|| (levels
&& levels
[cnt
+1] == levels
[0])) && (pwcInChars
[cnt
] == Numeric_space
) && cnt
< cInChars
)
1059 if (cnt
== cInChars
) /* All Spaces */
1062 New_Script
= scripts
[cnt
];
1065 pItems
[index
].iCharPos
= 0;
1066 pItems
[index
].a
= scriptInformation
[scripts
[cnt
]].a
;
1067 pScriptTags
[index
] = scriptInformation
[scripts
[cnt
]].scriptTag
;
1069 if (strength
&& strength
[cnt
] == BIDI_STRONG
)
1070 str
= strength
[cnt
];
1078 if (strength
[cnt
] == BIDI_STRONG
)
1079 layoutRTL
= (odd(levels
[cnt
]))?1:0;
1081 layoutRTL
= (psState
->uBidiLevel
|| odd(levels
[cnt
]))?1:0;
1082 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1083 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1084 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1086 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1088 layoutRTL
= (odd(baselevel
))?1:0;
1089 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1090 pItems
[index
].a
.fLayoutRTL
= odd(baselevel
);
1091 pItems
[index
].a
.fRTL
= odd(baselevel
);
1094 TRACE("New_Level=%i New_Strength=%i New_Script=%d, eScript=%d index=%d cnt=%d iCharPos=%d\n",
1095 levels
?levels
[cnt
]:-1, str
, New_Script
, pItems
[index
].a
.eScript
, index
, cnt
,
1096 pItems
[index
].iCharPos
);
1098 for (cnt
=1; cnt
< cInChars
; cnt
++)
1100 if(pwcInChars
[cnt
] != Numeric_space
)
1101 New_Script
= scripts
[cnt
];
1105 while (cnt
+ j
< cInChars
- 1 && pwcInChars
[cnt
+j
] == Numeric_space
&& levels
[cnt
] == levels
[cnt
+j
])
1107 if (cnt
+ j
< cInChars
&& levels
[cnt
] == levels
[cnt
+j
])
1108 New_Script
= scripts
[cnt
+j
];
1110 New_Script
= scripts
[cnt
];
1114 /* merge space strengths*/
1115 if (strength
&& strength
[cnt
] == BIDI_STRONG
&& str
!= BIDI_STRONG
&& New_Script
== pItems
[index
].a
.eScript
)
1118 if (strength
&& strength
[cnt
] == BIDI_NEUTRAL
&& str
== BIDI_STRONG
&& pwcInChars
[cnt
] != Numeric_space
&& New_Script
== pItems
[index
].a
.eScript
)
1121 /* changes in level */
1122 if (levels
&& (levels
[cnt
] != pItems
[index
].a
.s
.uBidiLevel
))
1124 TRACE("Level break(%i/%i)\n",pItems
[index
].a
.s
.uBidiLevel
,levels
[cnt
]);
1127 /* changes in strength */
1128 else if (strength
&& pwcInChars
[cnt
] != Numeric_space
&& str
!= strength
[cnt
])
1130 TRACE("Strength break (%i/%i)\n",str
,strength
[cnt
]);
1133 /* changes in script */
1134 else if (((pwcInChars
[cnt
] != Numeric_space
) && (New_Script
!= -1) && (New_Script
!= pItems
[index
].a
.eScript
)) || (New_Script
== Script_Control
))
1136 TRACE("Script break(%i/%i)\n",pItems
[index
].a
.eScript
,New_Script
);
1140 if (!new_run
&& strength
&& str
== BIDI_STRONG
)
1142 layoutRTL
= odd(levels
[cnt
])?1:0;
1143 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1148 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
);
1151 if (index
+1 > cMaxItems
)
1152 return E_OUTOFMEMORY
;
1155 str
= strength
[cnt
];
1157 pItems
[index
].iCharPos
= cnt
;
1158 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1160 pItems
[index
].a
= scriptInformation
[New_Script
].a
;
1161 pScriptTags
[index
] = scriptInformation
[New_Script
].scriptTag
;
1164 if (levels
[cnt
] == 0)
1167 layoutRTL
= (layoutRTL
|| odd(levels
[cnt
]))?1:0;
1168 pItems
[index
].a
.fRTL
= odd(levels
[cnt
]);
1169 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1170 pItems
[index
].a
.s
.uBidiLevel
= levels
[cnt
];
1172 else if (!pItems
[index
].a
.s
.uBidiLevel
)
1174 pItems
[index
].a
.s
.uBidiLevel
= baselevel
;
1175 pItems
[index
].a
.fLayoutRTL
= layoutRTL
;
1176 pItems
[index
].a
.fRTL
= odd(baselevel
);
1179 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1183 /* While not strictly necessary according to the spec, make sure the n+1
1184 * item is set up to prevent random behaviour if the caller erroneously
1185 * checks the n+1 structure */
1187 memset(&pItems
[index
].a
, 0, sizeof(SCRIPT_ANALYSIS
));
1189 TRACE("index=%d cnt=%d iCharPos=%d\n", index
, cnt
, pItems
[index
].iCharPos
);
1191 /* Set one SCRIPT_STATE item being returned */
1192 if (index
+ 1 > cMaxItems
) return E_OUTOFMEMORY
;
1193 if (pcItems
) *pcItems
= index
;
1195 /* Set SCRIPT_ITEM */
1196 pItems
[index
].iCharPos
= cnt
; /* the last item contains the ptr to the lastchar */
1198 heap_free(strength
);
1203 /***********************************************************************
1204 * ScriptItemize (USP10.@)
1206 * Split a Unicode string into shapeable parts.
1209 * pwcInChars [I] String to split.
1210 * cInChars [I] Number of characters in pwcInChars.
1211 * cMaxItems [I] Maximum number of items to return.
1212 * psControl [I] Pointer to a SCRIPT_CONTROL structure.
1213 * psState [I] Pointer to a SCRIPT_STATE structure.
1214 * pItems [O] Buffer to receive SCRIPT_ITEM structures.
1215 * pcItems [O] Number of script items returned.
1219 * Failure: Non-zero HRESULT value.
1221 HRESULT WINAPI
ScriptItemize(const WCHAR
*pwcInChars
, int cInChars
, int cMaxItems
,
1222 const SCRIPT_CONTROL
*psControl
, const SCRIPT_STATE
*psState
,
1223 SCRIPT_ITEM
*pItems
, int *pcItems
)
1225 OPENTYPE_TAG
*discarded_tags
;
1228 discarded_tags
= heap_alloc(cMaxItems
* sizeof(OPENTYPE_TAG
));
1229 if (!discarded_tags
)
1230 return E_OUTOFMEMORY
;
1231 res
= ScriptItemizeOpenType(pwcInChars
, cInChars
, cMaxItems
, psControl
, psState
, pItems
, discarded_tags
, pcItems
);
1232 heap_free(discarded_tags
);
1236 static inline int getGivenTabWidth(ScriptCache
*psc
, SCRIPT_TABDEF
*pTabdef
, int charPos
, int current_x
)
1240 INT
*lpTabPos
= NULL
;
1245 lpTabPos
= pTabdef
->pTabStops
;
1247 if (pTabdef
&& pTabdef
->iTabOrigin
)
1249 if (pTabdef
->iScale
)
1250 nTabOrg
= (pTabdef
->iTabOrigin
* pTabdef
->iScale
)/4;
1252 nTabOrg
= pTabdef
->iTabOrigin
* psc
->tm
.tmAveCharWidth
;
1256 cTabStops
= pTabdef
->cTabStops
;
1260 if (pTabdef
->iScale
)
1261 defWidth
= ((pTabdef
->pTabStops
[0])*pTabdef
->iScale
) / 4;
1263 defWidth
= (pTabdef
->pTabStops
[0])*psc
->tm
.tmAveCharWidth
;
1267 defWidth
= 8 * psc
->tm
.tmAveCharWidth
;
1269 for (; cTabStops
>0 ; lpTabPos
++, cTabStops
--)
1271 int position
= *lpTabPos
;
1273 position
= -1 * position
;
1274 if (pTabdef
->iScale
)
1275 position
= (position
* pTabdef
->iScale
) / 4;
1277 position
= position
* psc
->tm
.tmAveCharWidth
;
1279 if( nTabOrg
+ position
> current_x
)
1283 /* a left aligned tab */
1284 x
= (nTabOrg
+ *lpTabPos
) - current_x
;
1289 FIXME("Negative tabstop\n");
1294 if ((!cTabStops
) && (defWidth
> 0))
1295 x
=((((current_x
- nTabOrg
) / defWidth
)+1) * defWidth
) - current_x
;
1296 else if ((!cTabStops
) && (defWidth
< 0))
1297 FIXME("TODO: Negative defWidth\n");
1302 /***********************************************************************
1303 * Helper function for ScriptStringAnalyse
1305 static BOOL
requires_fallback(HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
1306 const WCHAR
*pwcInChars
, int cChars
)
1308 /* FIXME: When to properly fallback is still a bit of a mystery */
1311 if (psa
->fNoGlyphIndex
)
1314 if (init_script_cache(hdc
, psc
) != S_OK
)
1317 if (SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
) != S_OK
)
1320 glyphs
= heap_alloc(sizeof(WORD
) * cChars
);
1323 if (ScriptGetCMap(hdc
, psc
, pwcInChars
, cChars
, 0, glyphs
) != S_OK
)
1333 static void find_fallback_font(DWORD scriptid
, LPWSTR FaceName
)
1337 if (!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Uniscribe\\Fallback", &hkey
))
1339 static const WCHAR szFmt
[] = {'%','x',0};
1341 DWORD count
= LF_FACESIZE
* sizeof(WCHAR
);
1344 sprintfW(value
, szFmt
, scriptInformation
[scriptid
].scriptTag
);
1345 if (RegQueryValueExW(hkey
, value
, 0, &type
, (LPBYTE
)FaceName
, &count
))
1346 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1350 lstrcpyW(FaceName
,scriptInformation
[scriptid
].fallbackFont
);
1353 /***********************************************************************
1354 * ScriptStringAnalyse (USP10.@)
1357 HRESULT WINAPI
ScriptStringAnalyse(HDC hdc
, const void *pString
, int cString
,
1358 int cGlyphs
, int iCharset
, DWORD dwFlags
,
1359 int iReqWidth
, SCRIPT_CONTROL
*psControl
,
1360 SCRIPT_STATE
*psState
, const int *piDx
,
1361 SCRIPT_TABDEF
*pTabdef
, const BYTE
*pbInClass
,
1362 SCRIPT_STRING_ANALYSIS
*pssa
)
1364 HRESULT hr
= E_OUTOFMEMORY
;
1365 StringAnalysis
*analysis
= NULL
;
1366 SCRIPT_CONTROL sControl
;
1367 SCRIPT_STATE sState
;
1368 int i
, num_items
= 255;
1370 WCHAR
*iString
= NULL
;
1372 TRACE("(%p,%p,%d,%d,%d,0x%x,%d,%p,%p,%p,%p,%p,%p)\n",
1373 hdc
, pString
, cString
, cGlyphs
, iCharset
, dwFlags
, iReqWidth
,
1374 psControl
, psState
, piDx
, pTabdef
, pbInClass
, pssa
);
1378 FIXME("Only Unicode strings are supported\n");
1379 return E_INVALIDARG
;
1381 if (cString
< 1 || !pString
) return E_INVALIDARG
;
1382 if ((dwFlags
& SSA_GLYPHS
) && !hdc
) return E_PENDING
;
1384 if (!(analysis
= heap_alloc_zero(sizeof(StringAnalysis
)))) return E_OUTOFMEMORY
;
1385 if (!(analysis
->pItem
= heap_alloc_zero(num_items
* sizeof(SCRIPT_ITEM
) + 1))) goto error
;
1387 /* FIXME: handle clipping */
1388 analysis
->clip_len
= cString
;
1389 analysis
->hdc
= hdc
;
1390 analysis
->dwFlags
= dwFlags
;
1395 memset(&sState
, 0, sizeof(SCRIPT_STATE
));
1398 sControl
= *psControl
;
1400 memset(&sControl
, 0, sizeof(SCRIPT_CONTROL
));
1402 if (dwFlags
& SSA_PASSWORD
)
1404 iString
= heap_alloc(sizeof(WCHAR
)*cString
);
1410 for (i
= 0; i
< cString
; i
++)
1411 iString
[i
] = *((const WCHAR
*)pString
);
1415 hr
= ScriptItemize(pString
, cString
, num_items
, &sControl
, &sState
, analysis
->pItem
,
1416 &analysis
->numItems
);
1418 while (hr
== E_OUTOFMEMORY
)
1423 if (!(tmp
= heap_realloc_zero(analysis
->pItem
, num_items
* sizeof(SCRIPT_ITEM
) + 1)))
1426 analysis
->pItem
= tmp
;
1427 hr
= ScriptItemize(pString
, cString
, num_items
, psControl
, psState
, analysis
->pItem
,
1428 &analysis
->numItems
);
1430 if (hr
!= S_OK
) goto error
;
1432 /* set back to out of memory for default goto error behaviour */
1435 if (dwFlags
& SSA_BREAK
)
1437 if ((analysis
->logattrs
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * cString
)))
1439 for (i
= 0; i
< analysis
->numItems
; i
++)
1440 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
]);
1446 if (!(analysis
->logical2visual
= heap_alloc_zero(sizeof(int) * analysis
->numItems
)))
1448 if (!(BidiLevel
= heap_alloc_zero(analysis
->numItems
)))
1451 if (dwFlags
& SSA_GLYPHS
)
1454 if (!(analysis
->glyphs
= heap_alloc_zero(sizeof(StringGlyphs
) * analysis
->numItems
)))
1456 heap_free(BidiLevel
);
1460 for (i
= 0; i
< analysis
->numItems
; i
++)
1462 SCRIPT_CACHE
*sc
= (SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
;
1463 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1464 int numGlyphs
= 1.5 * cChar
+ 16;
1465 WORD
*glyphs
= heap_alloc_zero(sizeof(WORD
) * numGlyphs
);
1466 WORD
*pwLogClust
= heap_alloc_zero(sizeof(WORD
) * cChar
);
1467 int *piAdvance
= heap_alloc_zero(sizeof(int) * numGlyphs
);
1468 SCRIPT_VISATTR
*psva
= heap_alloc_zero(sizeof(SCRIPT_VISATTR
) * numGlyphs
);
1469 GOFFSET
*pGoffset
= heap_alloc_zero(sizeof(GOFFSET
) * numGlyphs
);
1470 ABC
*abc
= heap_alloc_zero(sizeof(ABC
));
1471 int numGlyphsReturned
;
1472 HFONT originalFont
= 0x0;
1474 /* FIXME: non unicode strings */
1475 const WCHAR
* pStr
= (const WCHAR
*)pString
;
1476 analysis
->glyphs
[i
].fallbackFont
= NULL
;
1478 if (!glyphs
|| !pwLogClust
|| !piAdvance
|| !psva
|| !pGoffset
|| !abc
)
1480 heap_free (BidiLevel
);
1482 heap_free (pwLogClust
);
1483 heap_free (piAdvance
);
1485 heap_free (pGoffset
);
1491 if ((dwFlags
& SSA_FALLBACK
) && requires_fallback(hdc
, sc
, &analysis
->pItem
[i
].a
, &pStr
[analysis
->pItem
[i
].iCharPos
], cChar
))
1494 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), & lf
);
1495 lf
.lfCharSet
= scriptInformation
[analysis
->pItem
[i
].a
.eScript
].props
.bCharSet
;
1496 find_fallback_font(analysis
->pItem
[i
].a
.eScript
, lf
.lfFaceName
);
1497 analysis
->glyphs
[i
].fallbackFont
= CreateFontIndirectW(&lf
);
1498 if (analysis
->glyphs
[i
].fallbackFont
)
1500 ScriptFreeCache(sc
);
1501 originalFont
= SelectObject(hdc
, analysis
->glyphs
[i
].fallbackFont
);
1505 hr
= ScriptShape(hdc
, sc
, &pStr
[analysis
->pItem
[i
].iCharPos
],
1506 cChar
, numGlyphs
, &analysis
->pItem
[i
].a
,
1507 glyphs
, pwLogClust
, psva
, &numGlyphsReturned
);
1508 hr
= ScriptPlace(hdc
, sc
, glyphs
, numGlyphsReturned
, psva
, &analysis
->pItem
[i
].a
,
1509 piAdvance
, pGoffset
, abc
);
1511 SelectObject(hdc
,originalFont
);
1513 if (dwFlags
& SSA_TAB
)
1516 for (tabi
= 0; tabi
< cChar
; tabi
++)
1518 if (pStr
[analysis
->pItem
[i
].iCharPos
+tabi
] == 0x0009)
1519 piAdvance
[tabi
] = getGivenTabWidth(analysis
->glyphs
[i
].sc
, pTabdef
, analysis
->pItem
[i
].iCharPos
+tabi
, tab_x
);
1520 tab_x
+=piAdvance
[tabi
];
1524 analysis
->glyphs
[i
].numGlyphs
= numGlyphsReturned
;
1525 analysis
->glyphs
[i
].glyphs
= glyphs
;
1526 analysis
->glyphs
[i
].pwLogClust
= pwLogClust
;
1527 analysis
->glyphs
[i
].piAdvance
= piAdvance
;
1528 analysis
->glyphs
[i
].psva
= psva
;
1529 analysis
->glyphs
[i
].pGoffset
= pGoffset
;
1530 analysis
->glyphs
[i
].abc
= abc
;
1531 analysis
->glyphs
[i
].iMaxPosX
= -1;
1533 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1538 for (i
= 0; i
< analysis
->numItems
; i
++)
1539 BidiLevel
[i
] = analysis
->pItem
[i
].a
.s
.uBidiLevel
;
1542 ScriptLayout(analysis
->numItems
, BidiLevel
, NULL
, analysis
->logical2visual
);
1543 heap_free(BidiLevel
);
1551 heap_free(analysis
->glyphs
);
1552 heap_free(analysis
->logattrs
);
1553 heap_free(analysis
->pItem
);
1554 heap_free(analysis
->logical2visual
);
1555 heap_free(analysis
);
1559 static inline BOOL
does_glyph_start_cluster(const SCRIPT_VISATTR
*pva
, const WORD
*pwLogClust
, int cChars
, int glyph
, int direction
)
1563 if (pva
[glyph
].fClusterStart
)
1565 for (i
= 0; i
< cChars
; i
++)
1566 if (pwLogClust
[i
] == glyph
) break;
1574 static HRESULT
SS_ItemOut( SCRIPT_STRING_ANALYSIS ssa
,
1585 StringAnalysis
*analysis
;
1588 COLORREF BkColor
= 0x0;
1589 COLORREF TextColor
= 0x0;
1591 INT runStart
, runEnd
;
1592 INT iGlyph
, cGlyphs
;
1593 HFONT oldFont
= 0x0;
1595 TRACE("(%p,%d,%d,%d,%d,%d, 0x%1x, %d, %d)\n",
1596 ssa
, iX
, iY
, iItem
, cStart
, cEnd
, uOptions
, fSelected
, fDisabled
);
1598 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1600 if ((cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
<= cStart
) ||
1601 (cEnd
>= 0 && analysis
->pItem
[iItem
].iCharPos
>= cEnd
))
1606 BkMode
= GetBkMode(analysis
->hdc
);
1607 SetBkMode( analysis
->hdc
, OPAQUE
);
1608 BkColor
= GetBkColor(analysis
->hdc
);
1609 SetBkColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1612 TextColor
= GetTextColor(analysis
->hdc
);
1613 SetTextColor(analysis
->hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1616 if (analysis
->glyphs
[iItem
].fallbackFont
)
1617 oldFont
= SelectObject(analysis
->hdc
, analysis
->glyphs
[iItem
].fallbackFont
);
1619 if (cStart
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cStart
&& analysis
->pItem
[iItem
].iCharPos
<= cStart
)
1620 runStart
= cStart
- analysis
->pItem
[iItem
].iCharPos
;
1623 if (cEnd
>= 0 && analysis
->pItem
[iItem
+1].iCharPos
> cEnd
&& analysis
->pItem
[iItem
].iCharPos
<= cEnd
)
1624 runEnd
= (cEnd
-1) - analysis
->pItem
[iItem
].iCharPos
;
1626 runEnd
= (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
) - 1;
1628 if (analysis
->pItem
[iItem
].a
.fRTL
)
1630 if (cEnd
>= 0 && cEnd
< analysis
->pItem
[iItem
+1].iCharPos
)
1631 ScriptStringCPtoX(ssa
, cEnd
, FALSE
, &off_x
);
1633 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
+1].iCharPos
-1, TRUE
, &off_x
);
1637 if (cStart
>=0 && runStart
)
1638 ScriptStringCPtoX(ssa
, cStart
, FALSE
, &off_x
);
1640 ScriptStringCPtoX(ssa
, analysis
->pItem
[iItem
].iCharPos
, FALSE
, &off_x
);
1643 if (analysis
->pItem
[iItem
].a
.fRTL
)
1644 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
];
1646 iGlyph
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
];
1648 if (analysis
->pItem
[iItem
].a
.fRTL
)
1649 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runStart
] - iGlyph
;
1651 cGlyphs
= analysis
->glyphs
[iItem
].pwLogClust
[runEnd
] - iGlyph
;
1655 if (cEnd
< 0 || scriptInformation
[analysis
->pItem
[iItem
].a
.eScript
].props
.fNeedsCaretInfo
)
1660 clust_glyph
= iGlyph
+ cGlyphs
;
1661 if (analysis
->pItem
[iItem
].a
.fRTL
)
1666 while(clust_glyph
< analysis
->glyphs
[iItem
].numGlyphs
&&
1667 !does_glyph_start_cluster(analysis
->glyphs
[iItem
].psva
, analysis
->glyphs
[iItem
].pwLogClust
, (analysis
->pItem
[iItem
+1].iCharPos
- analysis
->pItem
[iItem
].iCharPos
), clust_glyph
, direction
))
1674 hr
= ScriptTextOut(analysis
->hdc
,
1675 (SCRIPT_CACHE
*)&analysis
->glyphs
[iItem
].sc
, iX
+ off_x
,
1676 iY
, uOptions
, prc
, &analysis
->pItem
[iItem
].a
, NULL
, 0,
1677 &analysis
->glyphs
[iItem
].glyphs
[iGlyph
], cGlyphs
,
1678 &analysis
->glyphs
[iItem
].piAdvance
[iGlyph
], NULL
,
1679 &analysis
->glyphs
[iItem
].pGoffset
[iGlyph
]);
1681 TRACE("ScriptTextOut hr=%08x\n", hr
);
1685 SetBkColor(analysis
->hdc
, BkColor
);
1686 SetBkMode( analysis
->hdc
, BkMode
);
1688 SetTextColor(analysis
->hdc
, TextColor
);
1690 if (analysis
->glyphs
[iItem
].fallbackFont
)
1691 SelectObject(analysis
->hdc
, oldFont
);
1696 /***********************************************************************
1697 * ScriptStringOut (USP10.@)
1699 * This function takes the output of ScriptStringAnalyse and joins the segments
1700 * of glyphs and passes the resulting string to ScriptTextOut. ScriptStringOut
1701 * only processes glyphs.
1704 * ssa [I] buffer to hold the analysed string components
1705 * iX [I] X axis displacement for output
1706 * iY [I] Y axis displacement for output
1707 * uOptions [I] flags controling output processing
1708 * prc [I] rectangle coordinates
1709 * iMinSel [I] starting pos for substringing output string
1710 * iMaxSel [I] ending pos for substringing output string
1711 * fDisabled [I] controls text highlighting
1715 * Failure: is the value returned by ScriptTextOut
1717 HRESULT WINAPI
ScriptStringOut(SCRIPT_STRING_ANALYSIS ssa
,
1726 StringAnalysis
*analysis
;
1730 TRACE("(%p,%d,%d,0x%1x,%p,%d,%d,%d)\n",
1731 ssa
, iX
, iY
, uOptions
, prc
, iMinSel
, iMaxSel
, fDisabled
);
1733 if (!(analysis
= ssa
)) return E_INVALIDARG
;
1734 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return E_INVALIDARG
;
1736 for (item
= 0; item
< analysis
->numItems
; item
++)
1738 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], -1, -1, uOptions
, prc
, FALSE
, fDisabled
);
1743 if (iMinSel
< iMaxSel
&& (iMinSel
> 0 || iMaxSel
> 0))
1745 if (iMaxSel
> 0 && iMinSel
< 0)
1747 for (item
= 0; item
< analysis
->numItems
; item
++)
1749 hr
= SS_ItemOut( ssa
, iX
, iY
, analysis
->logical2visual
[item
], iMinSel
, iMaxSel
, uOptions
, prc
, TRUE
, fDisabled
);
1758 /***********************************************************************
1759 * ScriptStringCPtoX (USP10.@)
1762 HRESULT WINAPI
ScriptStringCPtoX(SCRIPT_STRING_ANALYSIS ssa
, int icp
, BOOL fTrailing
, int* pX
)
1766 StringAnalysis
* analysis
= ssa
;
1768 TRACE("(%p), %d, %d, (%p)\n", ssa
, icp
, fTrailing
, pX
);
1770 if (!ssa
|| !pX
) return S_FALSE
;
1771 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1773 /* icp out of range */
1776 analysis
->invalid
= TRUE
;
1777 return E_INVALIDARG
;
1780 for(item
=0; item
<analysis
->numItems
; item
++)
1785 i
= analysis
->logical2visual
[item
];
1786 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1787 /* initialize max extents for uninitialized runs */
1788 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1790 if (analysis
->pItem
[i
].a
.fRTL
)
1791 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1792 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1793 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1795 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1796 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1797 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1800 if (icp
>= analysis
->pItem
[i
+1].iCharPos
|| icp
< analysis
->pItem
[i
].iCharPos
)
1802 runningX
+= analysis
->glyphs
[i
].iMaxPosX
;
1806 icp
-= analysis
->pItem
[i
].iCharPos
;
1807 ScriptCPtoX(icp
, fTrailing
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1808 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1809 &analysis
->pItem
[i
].a
, &offset
);
1816 /* icp out of range */
1817 analysis
->invalid
= TRUE
;
1818 return E_INVALIDARG
;
1821 /***********************************************************************
1822 * ScriptStringXtoCP (USP10.@)
1825 HRESULT WINAPI
ScriptStringXtoCP(SCRIPT_STRING_ANALYSIS ssa
, int iX
, int* piCh
, int* piTrailing
)
1827 StringAnalysis
* analysis
= ssa
;
1830 TRACE("(%p), %d, (%p), (%p)\n", ssa
, iX
, piCh
, piTrailing
);
1832 if (!ssa
|| !piCh
|| !piTrailing
) return S_FALSE
;
1833 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
1838 if (analysis
->pItem
[0].a
.fRTL
)
1841 *piTrailing
= FALSE
;
1851 for(item
=0; item
<analysis
->numItems
; item
++)
1856 for (i
= 0; i
< analysis
->numItems
&& analysis
->logical2visual
[i
] != item
; i
++)
1859 CP
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
1860 /* initialize max extents for uninitialized runs */
1861 if (analysis
->glyphs
[i
].iMaxPosX
== -1)
1863 if (analysis
->pItem
[i
].a
.fRTL
)
1864 ScriptCPtoX(0, FALSE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1865 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1866 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1868 ScriptCPtoX(CP
, TRUE
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1869 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1870 &analysis
->pItem
[i
].a
, &analysis
->glyphs
[i
].iMaxPosX
);
1873 if (iX
> analysis
->glyphs
[i
].iMaxPosX
)
1875 iX
-= analysis
->glyphs
[i
].iMaxPosX
;
1879 ScriptXtoCP(iX
, CP
, analysis
->glyphs
[i
].numGlyphs
, analysis
->glyphs
[i
].pwLogClust
,
1880 analysis
->glyphs
[i
].psva
, analysis
->glyphs
[i
].piAdvance
,
1881 &analysis
->pItem
[i
].a
, piCh
, piTrailing
);
1882 *piCh
+= analysis
->pItem
[i
].iCharPos
;
1888 *piCh
= analysis
->pItem
[analysis
->numItems
].iCharPos
;
1889 *piTrailing
= FALSE
;
1895 /***********************************************************************
1896 * ScriptStringFree (USP10.@)
1898 * Free a string analysis.
1901 * pssa [I] string analysis.
1905 * Failure: Non-zero HRESULT value.
1907 HRESULT WINAPI
ScriptStringFree(SCRIPT_STRING_ANALYSIS
*pssa
)
1909 StringAnalysis
* analysis
;
1913 TRACE("(%p)\n", pssa
);
1915 if (!pssa
|| !(analysis
= *pssa
)) return E_INVALIDARG
;
1917 invalid
= analysis
->invalid
;
1919 if (analysis
->glyphs
)
1921 for (i
= 0; i
< analysis
->numItems
; i
++)
1923 heap_free(analysis
->glyphs
[i
].glyphs
);
1924 heap_free(analysis
->glyphs
[i
].pwLogClust
);
1925 heap_free(analysis
->glyphs
[i
].piAdvance
);
1926 heap_free(analysis
->glyphs
[i
].psva
);
1927 heap_free(analysis
->glyphs
[i
].pGoffset
);
1928 heap_free(analysis
->glyphs
[i
].abc
);
1929 if (analysis
->glyphs
[i
].fallbackFont
)
1930 DeleteObject(analysis
->glyphs
[i
].fallbackFont
);
1931 ScriptFreeCache((SCRIPT_CACHE
*)&analysis
->glyphs
[i
].sc
);
1932 heap_free(analysis
->glyphs
[i
].sc
);
1934 heap_free(analysis
->glyphs
);
1937 heap_free(analysis
->pItem
);
1938 heap_free(analysis
->logattrs
);
1939 heap_free(analysis
->sz
);
1940 heap_free(analysis
->logical2visual
);
1941 heap_free(analysis
);
1943 if (invalid
) return E_INVALIDARG
;
1947 static inline int get_cluster_size(const WORD
*pwLogClust
, int cChars
, int item
,
1948 int direction
, int* iCluster
, int *check_out
)
1952 WORD clust
= pwLogClust
[item
];
1954 for (check
= item
+direction
; check
< cChars
&& check
>= 0; check
+=direction
)
1956 if (pwLogClust
[check
] == clust
)
1959 if (iCluster
&& *iCluster
== -1)
1971 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
)
1974 int log_clust_max
= 0;
1977 advance
= piAdvance
[glyph
];
1979 for (i
= 0; i
< cChars
; i
++)
1981 if (pwLogClust
[i
] > log_clust_max
)
1982 log_clust_max
= pwLogClust
[i
];
1985 if (glyph
> log_clust_max
)
1988 for (glyph
+=direction
; glyph
< cGlyphs
&& glyph
>= 0; glyph
+=direction
)
1991 if (does_glyph_start_cluster(pva
, pwLogClust
, cChars
, glyph
, direction
))
1993 if (glyph
> log_clust_max
)
1995 advance
+= piAdvance
[glyph
];
2001 /***********************************************************************
2002 * ScriptCPtoX (USP10.@)
2005 HRESULT WINAPI
ScriptCPtoX(int iCP
,
2009 const WORD
*pwLogClust
,
2010 const SCRIPT_VISATTR
*psva
,
2011 const int *piAdvance
,
2012 const SCRIPT_ANALYSIS
*psa
,
2020 float special_size
= 0.0;
2025 TRACE("(%d,%d,%d,%d,%p,%p,%p,%p,%p)\n",
2026 iCP
, fTrailing
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2029 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2037 int max_clust
= pwLogClust
[0];
2039 for (item
=0; item
< cGlyphs
; item
++)
2040 if (pwLogClust
[item
] > max_clust
)
2042 ERR("We do not handle non reversed clusters properly\n");
2047 for (item
= max_clust
; item
>=0; item
--)
2048 iMaxPos
+= piAdvance
[item
];
2052 for (item
=0; item
< iCP
&& item
< cChars
; item
++)
2054 if (iSpecial
== -1 && (iCluster
== -1 || (iCluster
!= -1 && iCluster
+clust_size
<= item
)))
2057 int clust
= pwLogClust
[item
];
2060 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, 1, &iCluster
,
2063 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, 1);
2065 if (check
>= cChars
&& !iMaxPos
)
2067 for (check
= clust
; check
< cChars
; check
++)
2068 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, 1);
2070 special_size
/= (cChars
- item
);
2071 iPosX
+= special_size
;
2075 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2078 if (clust_size
== 0)
2082 iPosX
+= advance
/ (float)clust_size
;
2085 else if (iSpecial
!= -1)
2086 iPosX
+= special_size
;
2087 else /* (iCluster != -1) */
2089 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], 1);
2090 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2093 if (clust_size
== 0)
2097 iPosX
+= adv
/ (float)clust_size
;
2103 iPosX
= iMaxPos
- iPosX
;
2109 TRACE("*piX=%d\n", *piX
);
2113 /***********************************************************************
2114 * ScriptXtoCP (USP10.@)
2117 HRESULT WINAPI
ScriptXtoCP(int iX
,
2120 const WORD
*pwLogClust
,
2121 const SCRIPT_VISATTR
*psva
,
2122 const int *piAdvance
,
2123 const SCRIPT_ANALYSIS
*psa
,
2135 float special_size
= 0.0;
2138 TRACE("(%d,%d,%d,%p,%p,%p,%p,%p,%p)\n",
2139 iX
, cChars
, cGlyphs
, pwLogClust
, psva
, piAdvance
,
2140 psa
, piCP
, piTrailing
);
2142 if (psa
->fRTL
&& ! psa
->fLogicalOrder
)
2147 int max_clust
= pwLogClust
[0];
2156 for (item
=0; item
< cChars
; item
++)
2157 if (pwLogClust
[item
] > max_clust
)
2159 ERR("We do not handle non reversed clusters properly\n");
2171 iPosX
= iLastPosX
= 0;
2176 for (; iPosX
<= iX
&& item
< cChars
&& item
>= 0; item
+=direction
)
2179 if (iSpecial
== -1 &&
2182 ((direction
> 0 && iCluster
+clust_size
<= item
) ||
2183 (direction
< 0 && iCluster
-clust_size
>= item
))
2189 int clust
= pwLogClust
[item
];
2193 clust_size
= get_cluster_size(pwLogClust
, cChars
, item
, direction
,
2195 advance
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, clust
, direction
);
2197 if (check
>= cChars
&& direction
> 0)
2199 for (check
= clust
; check
< cChars
; check
++)
2200 special_size
+= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, check
, direction
);
2202 special_size
/= (cChars
- item
);
2203 iPosX
+= special_size
;
2207 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2214 iPosX
+= advance
/ (float)clust_size
;
2217 else if (iSpecial
!= -1)
2218 iPosX
+= special_size
;
2219 else /* (iCluster != -1) */
2221 int adv
= get_glyph_cluster_advance(piAdvance
, psva
, pwLogClust
, cGlyphs
, cChars
, pwLogClust
[iCluster
], direction
);
2222 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
)
2229 iPosX
+= adv
/ (float)clust_size
;
2237 if (item
< cChars
&& ((iPosX
- iLastPosX
) / 2.0) + iX
>= iPosX
)
2239 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2240 item
+=(clust_size
-1);
2248 if (iX
== iLastPosX
)
2250 if (iX
>= iLastPosX
&& iX
<= iPosX
)
2253 if (iLastPosX
== iX
)
2255 else if (item
< 0 || ((iLastPosX
- iPosX
) / 2.0) + iX
<= iLastPosX
)
2257 if (scriptInformation
[psa
->eScript
].props
.fNeedsCaretInfo
&& clust_size
> 1)
2258 item
-=(clust_size
-1);
2267 TRACE("*piCP=%d\n", *piCP
);
2268 TRACE("*piTrailing=%d\n", *piTrailing
);
2272 /***********************************************************************
2273 * ScriptBreak (USP10.@)
2275 * Retrieve line break information.
2278 * chars [I] Array of characters.
2279 * sa [I] String analysis.
2280 * la [I] Array of logical attribute structures.
2286 HRESULT WINAPI
ScriptBreak(const WCHAR
*chars
, int count
, const SCRIPT_ANALYSIS
*sa
, SCRIPT_LOGATTR
*la
)
2288 TRACE("(%s, %d, %p, %p)\n", debugstr_wn(chars
, count
), count
, sa
, la
);
2290 if (!la
) return S_FALSE
;
2292 BREAK_line(chars
, count
, sa
, la
);
2297 /***********************************************************************
2298 * ScriptIsComplex (USP10.@)
2300 * Determine if a string is complex.
2303 * chars [I] Array of characters to test.
2304 * len [I] Length in characters.
2312 HRESULT WINAPI
ScriptIsComplex(const WCHAR
*chars
, int len
, DWORD flag
)
2316 TRACE("(%s,%d,0x%x)\n", debugstr_wn(chars
, len
), len
, flag
);
2318 for (i
= 0; i
< len
; i
++)
2322 if ((flag
& SIC_ASCIIDIGIT
) && chars
[i
] >= 0x30 && chars
[i
] <= 0x39)
2325 script
= get_char_script(chars
[i
]);
2326 if ((scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_COMPLEX
))||
2327 (!scriptInformation
[script
].props
.fComplex
&& (flag
& SIC_NEUTRAL
)))
2333 /***********************************************************************
2334 * ScriptShapeOpenType (USP10.@)
2336 * Produce glyphs and visual attributes for a run.
2339 * hdc [I] Device context.
2340 * psc [I/O] Opaque pointer to a script cache.
2341 * psa [I/O] Script analysis.
2342 * tagScript [I] The OpenType tag for the Script
2343 * tagLangSys [I] The OpenType tag for the Language
2344 * rcRangeChars[I] Array of Character counts in each range
2345 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2346 * cRanges [I] Count of ranges
2347 * pwcChars [I] Array of characters specifying the run.
2348 * cChars [I] Number of characters in pwcChars.
2349 * cMaxGlyphs [I] Length of pwOutGlyphs.
2350 * pwLogClust [O] Array of logical cluster info.
2351 * pCharProps [O] Array of character property values
2352 * pwOutGlyphs [O] Array of glyphs.
2353 * pOutGlyphProps [O] Array of attributes for the retrieved glyphs
2354 * pcGlyphs [O] Number of glyphs returned.
2358 * Failure: Non-zero HRESULT value.
2360 HRESULT WINAPI
ScriptShapeOpenType( HDC hdc
, SCRIPT_CACHE
*psc
,
2361 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
2362 OPENTYPE_TAG tagLangSys
, int *rcRangeChars
,
2363 TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2364 int cRanges
, const WCHAR
*pwcChars
, int cChars
,
2365 int cMaxGlyphs
, WORD
*pwLogClust
,
2366 SCRIPT_CHARPROP
*pCharProps
, WORD
*pwOutGlyphs
,
2367 SCRIPT_GLYPHPROP
*pOutGlyphProps
, int *pcGlyphs
)
2373 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %d, %d, %p, %p, %p, %p, %p )\n",
2375 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2376 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2377 cChars
, cMaxGlyphs
, pwLogClust
, pCharProps
, pwOutGlyphs
, pOutGlyphProps
, pcGlyphs
);
2379 if (psa
) TRACE("psa values: %d, %d, %d, %d, %d, %d, %d\n", psa
->eScript
, psa
->fRTL
, psa
->fLayoutRTL
,
2380 psa
->fLinkBefore
, psa
->fLinkAfter
, psa
->fLogicalOrder
, psa
->fNoGlyphIndex
);
2382 if (!pOutGlyphProps
|| !pcGlyphs
|| !pCharProps
) return E_INVALIDARG
;
2383 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2386 FIXME("Ranges not supported yet\n");
2388 rtl
= (psa
&& !psa
->fLogicalOrder
&& psa
->fRTL
);
2391 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2392 if (!pwLogClust
) return E_FAIL
;
2394 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2395 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2397 /* set fNoGlyphIndex non truetype/opentype fonts */
2398 if (!psa
->fNoGlyphIndex
&& !((ScriptCache
*)*psc
)->sfnt
)
2399 psa
->fNoGlyphIndex
= TRUE
;
2401 /* Initialize a SCRIPT_VISATTR and LogClust for each char in this run */
2402 for (i
= 0; i
< cChars
; i
++)
2405 if (rtl
) idx
= cChars
- 1 - i
;
2406 /* FIXME: set to better values */
2407 pOutGlyphProps
[i
].sva
.uJustification
= (pwcChars
[idx
] == ' ') ? SCRIPT_JUSTIFY_BLANK
: SCRIPT_JUSTIFY_CHARACTER
;
2408 pOutGlyphProps
[i
].sva
.fClusterStart
= 1;
2409 pOutGlyphProps
[i
].sva
.fDiacritic
= 0;
2410 pOutGlyphProps
[i
].sva
.fZeroWidth
= 0;
2411 pOutGlyphProps
[i
].sva
.fReserved
= 0;
2412 pOutGlyphProps
[i
].sva
.fShapeReserved
= 0;
2414 /* FIXME: have the shaping engine set this */
2415 pCharProps
[i
].fCanGlyphAlone
= 0;
2417 pwLogClust
[i
] = idx
;
2420 if (psa
&& !psa
->fNoGlyphIndex
)
2423 if ((hr
= SHAPE_CheckFontForRequiredFeatures(hdc
, (ScriptCache
*)*psc
, psa
)) != S_OK
) return hr
;
2425 rChars
= heap_alloc(sizeof(WCHAR
) * cChars
);
2426 if (!rChars
) return E_OUTOFMEMORY
;
2427 for (i
= 0; i
< cChars
; i
++)
2431 if (rtl
) idx
= cChars
- 1 - i
;
2433 chInput
= mirror_char(pwcChars
[idx
]);
2435 chInput
= pwcChars
[idx
];
2436 /* special case for tabs */
2437 if (chInput
== 0x0009)
2439 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, chInput
)))
2447 if (GetGlyphIndicesW(hdc
, &chInput
, 1, &glyph
, 0) == GDI_ERROR
)
2452 pwOutGlyphs
[i
] = set_cache_glyph(psc
, chInput
, glyph
);
2454 rChars
[i
] = chInput
;
2457 SHAPE_ContextualShaping(hdc
, (ScriptCache
*)*psc
, psa
, rChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
2458 SHAPE_ApplyDefaultOpentypeFeatures(hdc
, (ScriptCache
*)*psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, pwLogClust
);
2459 SHAPE_CharGlyphProp(hdc
, (ScriptCache
*)*psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, *pcGlyphs
, pwLogClust
, pCharProps
, pOutGlyphProps
);
2464 TRACE("no glyph translation\n");
2465 for (i
= 0; i
< cChars
; i
++)
2468 /* No mirroring done here */
2469 if (rtl
) idx
= cChars
- 1 - i
;
2470 pwOutGlyphs
[i
] = pwcChars
[idx
];
2478 /***********************************************************************
2479 * ScriptShape (USP10.@)
2481 * Produce glyphs and visual attributes for a run.
2484 * hdc [I] Device context.
2485 * psc [I/O] Opaque pointer to a script cache.
2486 * pwcChars [I] Array of characters specifying the run.
2487 * cChars [I] Number of characters in pwcChars.
2488 * cMaxGlyphs [I] Length of pwOutGlyphs.
2489 * psa [I/O] Script analysis.
2490 * pwOutGlyphs [O] Array of glyphs.
2491 * pwLogClust [O] Array of logical cluster info.
2492 * psva [O] Array of visual attributes.
2493 * pcGlyphs [O] Number of glyphs returned.
2497 * Failure: Non-zero HRESULT value.
2499 HRESULT WINAPI
ScriptShape(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcChars
,
2500 int cChars
, int cMaxGlyphs
,
2501 SCRIPT_ANALYSIS
*psa
, WORD
*pwOutGlyphs
, WORD
*pwLogClust
,
2502 SCRIPT_VISATTR
*psva
, int *pcGlyphs
)
2506 SCRIPT_CHARPROP
*charProps
;
2507 SCRIPT_GLYPHPROP
*glyphProps
;
2509 if (!psva
|| !pcGlyphs
) return E_INVALIDARG
;
2510 if (cChars
> cMaxGlyphs
) return E_OUTOFMEMORY
;
2512 charProps
= heap_alloc_zero(sizeof(SCRIPT_CHARPROP
)*cChars
);
2513 if (!charProps
) return E_OUTOFMEMORY
;
2514 glyphProps
= heap_alloc_zero(sizeof(SCRIPT_GLYPHPROP
)*cMaxGlyphs
);
2517 heap_free(charProps
);
2518 return E_OUTOFMEMORY
;
2521 hr
= ScriptShapeOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, pwcChars
, cChars
, cMaxGlyphs
, pwLogClust
, charProps
, pwOutGlyphs
, glyphProps
, pcGlyphs
);
2525 for (i
= 0; i
< *pcGlyphs
; i
++)
2526 psva
[i
] = glyphProps
[i
].sva
;
2529 heap_free(charProps
);
2530 heap_free(glyphProps
);
2535 /***********************************************************************
2536 * ScriptPlaceOpenType (USP10.@)
2538 * Produce advance widths for a run.
2541 * hdc [I] Device context.
2542 * psc [I/O] Opaque pointer to a script cache.
2543 * psa [I/O] String analysis.
2544 * tagScript [I] The OpenType tag for the Script
2545 * tagLangSys [I] The OpenType tag for the Language
2546 * rcRangeChars[I] Array of Character counts in each range
2547 * rpRangeProperties [I] Array of TEXTRANGE_PROPERTIES structures
2548 * cRanges [I] Count of ranges
2549 * pwcChars [I] Array of characters specifying the run.
2550 * pwLogClust [I] Array of logical cluster info
2551 * pCharProps [I] Array of character property values
2552 * cChars [I] Number of characters in pwcChars.
2553 * pwGlyphs [I] Array of glyphs.
2554 * pGlyphProps [I] Array of attributes for the retrieved glyphs
2555 * cGlyphs [I] Count of Glyphs
2556 * piAdvance [O] Array of advance widths.
2557 * pGoffset [O] Glyph offsets.
2558 * pABC [O] Combined ABC width.
2562 * Failure: Non-zero HRESULT value.
2565 HRESULT WINAPI
ScriptPlaceOpenType( HDC hdc
, SCRIPT_CACHE
*psc
, SCRIPT_ANALYSIS
*psa
,
2566 OPENTYPE_TAG tagScript
, OPENTYPE_TAG tagLangSys
,
2567 int *rcRangeChars
, TEXTRANGE_PROPERTIES
**rpRangeProperties
,
2568 int cRanges
, const WCHAR
*pwcChars
, WORD
*pwLogClust
,
2569 SCRIPT_CHARPROP
*pCharProps
, int cChars
,
2570 const WORD
*pwGlyphs
, const SCRIPT_GLYPHPROP
*pGlyphProps
,
2571 int cGlyphs
, int *piAdvance
,
2572 GOFFSET
*pGoffset
, ABC
*pABC
2578 TRACE("(%p, %p, %p, %s, %s, %p, %p, %d, %s, %p, %p, %d, %p, %p, %d, %p %p %p)\n",
2580 debugstr_an((char*)&tagScript
,4), debugstr_an((char*)&tagLangSys
,4),
2581 rcRangeChars
, rpRangeProperties
, cRanges
, debugstr_wn(pwcChars
, cChars
),
2582 pwLogClust
, pCharProps
, cChars
, pwGlyphs
, pGlyphProps
, cGlyphs
, piAdvance
,
2585 if (!pGlyphProps
) return E_INVALIDARG
;
2586 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2587 if (!pGoffset
) return E_FAIL
;
2590 FIXME("Ranges not supported yet\n");
2592 ((ScriptCache
*)*psc
)->userScript
= tagScript
;
2593 ((ScriptCache
*)*psc
)->userLang
= tagLangSys
;
2595 if (pABC
) memset(pABC
, 0, sizeof(ABC
));
2596 for (i
= 0; i
< cGlyphs
; i
++)
2599 if (!get_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
))
2601 if (!hdc
) return E_PENDING
;
2602 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
) && !psa
->fNoGlyphIndex
)
2604 if (!GetCharABCWidthsI(hdc
, 0, 1, (WORD
*)&pwGlyphs
[i
], &abc
)) return S_FALSE
;
2609 if (!GetCharWidth32W(hdc
, pwGlyphs
[i
], pwGlyphs
[i
], &width
)) return S_FALSE
;
2611 abc
.abcA
= abc
.abcC
= 0;
2613 set_cache_glyph_widths(psc
, pwGlyphs
[i
], &abc
);
2617 pABC
->abcA
+= abc
.abcA
;
2618 pABC
->abcB
+= abc
.abcB
;
2619 pABC
->abcC
+= abc
.abcC
;
2621 /* FIXME: set to more reasonable values */
2622 pGoffset
[i
].du
= pGoffset
[i
].dv
= 0;
2623 if (piAdvance
) piAdvance
[i
] = abc
.abcA
+ abc
.abcB
+ abc
.abcC
;
2626 if (pABC
) TRACE("Total for run: abcA=%d, abcB=%d, abcC=%d\n", pABC
->abcA
, pABC
->abcB
, pABC
->abcC
);
2630 /***********************************************************************
2631 * ScriptPlace (USP10.@)
2633 * Produce advance widths for a run.
2636 * hdc [I] Device context.
2637 * psc [I/O] Opaque pointer to a script cache.
2638 * pwGlyphs [I] Array of glyphs.
2639 * cGlyphs [I] Number of glyphs in pwGlyphs.
2640 * psva [I] Array of visual attributes.
2641 * psa [I/O] String analysis.
2642 * piAdvance [O] Array of advance widths.
2643 * pGoffset [O] Glyph offsets.
2644 * pABC [O] Combined ABC width.
2648 * Failure: Non-zero HRESULT value.
2650 HRESULT WINAPI
ScriptPlace(HDC hdc
, SCRIPT_CACHE
*psc
, const WORD
*pwGlyphs
,
2651 int cGlyphs
, const SCRIPT_VISATTR
*psva
,
2652 SCRIPT_ANALYSIS
*psa
, int *piAdvance
, GOFFSET
*pGoffset
, ABC
*pABC
)
2655 SCRIPT_GLYPHPROP
*glyphProps
;
2658 TRACE("(%p, %p, %p, %d, %p, %p, %p, %p, %p)\n", hdc
, psc
, pwGlyphs
, cGlyphs
, psva
, psa
,
2659 piAdvance
, pGoffset
, pABC
);
2661 if (!psva
) return E_INVALIDARG
;
2662 if (!pGoffset
) return E_FAIL
;
2664 glyphProps
= heap_alloc(sizeof(SCRIPT_GLYPHPROP
)*cGlyphs
);
2665 if (!glyphProps
) return E_OUTOFMEMORY
;
2667 for (i
= 0; i
< cGlyphs
; i
++)
2668 glyphProps
[i
].sva
= psva
[i
];
2670 hr
= ScriptPlaceOpenType(hdc
, psc
, psa
, scriptInformation
[psa
->eScript
].scriptTag
, 0, NULL
, NULL
, 0, NULL
, NULL
, NULL
, 0, pwGlyphs
, glyphProps
, cGlyphs
, piAdvance
, pGoffset
, pABC
);
2672 heap_free(glyphProps
);
2677 /***********************************************************************
2678 * ScriptGetCMap (USP10.@)
2680 * Retrieve glyph indices.
2683 * hdc [I] Device context.
2684 * psc [I/O] Opaque pointer to a script cache.
2685 * pwcInChars [I] Array of Unicode characters.
2686 * cChars [I] Number of characters in pwcInChars.
2687 * dwFlags [I] Flags.
2688 * pwOutGlyphs [O] Buffer to receive the array of glyph indices.
2692 * Failure: Non-zero HRESULT value.
2694 HRESULT WINAPI
ScriptGetCMap(HDC hdc
, SCRIPT_CACHE
*psc
, const WCHAR
*pwcInChars
,
2695 int cChars
, DWORD dwFlags
, WORD
*pwOutGlyphs
)
2700 TRACE("(%p,%p,%s,%d,0x%x,%p)\n", hdc
, psc
, debugstr_wn(pwcInChars
, cChars
),
2701 cChars
, dwFlags
, pwOutGlyphs
);
2703 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2707 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2709 for (i
= 0; i
< cChars
; i
++)
2712 if (dwFlags
== SGCM_RTL
)
2713 inChar
= mirror_char(pwcInChars
[i
]);
2715 inChar
= pwcInChars
[i
];
2716 if (!(pwOutGlyphs
[i
] = get_cache_glyph(psc
, inChar
)))
2719 if (!hdc
) return E_PENDING
;
2720 if (GetGlyphIndicesW(hdc
, &inChar
, 1, &glyph
, GGI_MARK_NONEXISTING_GLYPHS
) == GDI_ERROR
) return S_FALSE
;
2721 if (glyph
== 0xffff)
2726 pwOutGlyphs
[i
] = set_cache_glyph(psc
, inChar
, glyph
);
2732 TRACE("no glyph translation\n");
2733 for (i
= 0; i
< cChars
; i
++)
2736 if (dwFlags
== SGCM_RTL
)
2737 inChar
= mirror_char(pwcInChars
[i
]);
2739 inChar
= pwcInChars
[i
];
2740 pwOutGlyphs
[i
] = inChar
;
2746 /***********************************************************************
2747 * ScriptTextOut (USP10.@)
2750 HRESULT WINAPI
ScriptTextOut(const HDC hdc
, SCRIPT_CACHE
*psc
, int x
, int y
, UINT fuOptions
,
2751 const RECT
*lprc
, const SCRIPT_ANALYSIS
*psa
, const WCHAR
*pwcReserved
,
2752 int iReserved
, const WORD
*pwGlyphs
, int cGlyphs
, const int *piAdvance
,
2753 const int *piJustify
, const GOFFSET
*pGoffset
)
2757 TRACE("(%p, %p, %d, %d, %04x, %p, %p, %p, %d, %p, %d, %p, %p, %p)\n",
2758 hdc
, psc
, x
, y
, fuOptions
, lprc
, psa
, pwcReserved
, iReserved
, pwGlyphs
, cGlyphs
,
2759 piAdvance
, piJustify
, pGoffset
);
2761 if (!hdc
|| !psc
) return E_INVALIDARG
;
2762 if (!piAdvance
|| !psa
|| !pwGlyphs
) return E_INVALIDARG
;
2764 fuOptions
&= ETO_CLIPPED
+ ETO_OPAQUE
;
2765 fuOptions
|= ETO_IGNORELANGUAGE
;
2766 if (!psa
->fNoGlyphIndex
) /* Have Glyphs? */
2767 fuOptions
|= ETO_GLYPH_INDEX
; /* Say don't do translation to glyph */
2769 if (psa
->fRTL
&& psa
->fLogicalOrder
)
2774 rtlGlyphs
= heap_alloc(cGlyphs
* sizeof(WORD
));
2776 return E_OUTOFMEMORY
;
2778 for (i
= 0; i
< cGlyphs
; i
++)
2779 rtlGlyphs
[i
] = pwGlyphs
[cGlyphs
-1-i
];
2781 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, rtlGlyphs
, cGlyphs
, NULL
))
2783 heap_free(rtlGlyphs
);
2786 if (!ExtTextOutW(hdc
, x
, y
, fuOptions
, lprc
, pwGlyphs
, cGlyphs
, NULL
))
2792 /***********************************************************************
2793 * ScriptCacheGetHeight (USP10.@)
2795 * Retrieve the height of the font in the cache.
2798 * hdc [I] Device context.
2799 * psc [I/O] Opaque pointer to a script cache.
2800 * height [O] Receives font height.
2804 * Failure: Non-zero HRESULT value.
2806 HRESULT WINAPI
ScriptCacheGetHeight(HDC hdc
, SCRIPT_CACHE
*psc
, LONG
*height
)
2810 TRACE("(%p, %p, %p)\n", hdc
, psc
, height
);
2812 if (!height
) return E_INVALIDARG
;
2813 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2815 *height
= get_cache_height(psc
);
2819 /***********************************************************************
2820 * ScriptGetGlyphABCWidth (USP10.@)
2822 * Retrieve the width of a glyph.
2825 * hdc [I] Device context.
2826 * psc [I/O] Opaque pointer to a script cache.
2827 * glyph [I] Glyph to retrieve the width for.
2828 * abc [O] ABC widths of the glyph.
2832 * Failure: Non-zero HRESULT value.
2834 HRESULT WINAPI
ScriptGetGlyphABCWidth(HDC hdc
, SCRIPT_CACHE
*psc
, WORD glyph
, ABC
*abc
)
2838 TRACE("(%p, %p, 0x%04x, %p)\n", hdc
, psc
, glyph
, abc
);
2840 if (!abc
) return E_INVALIDARG
;
2841 if ((hr
= init_script_cache(hdc
, psc
)) != S_OK
) return hr
;
2843 if (!get_cache_glyph_widths(psc
, glyph
, abc
))
2845 if (!hdc
) return E_PENDING
;
2846 if ((get_cache_pitch_family(psc
) & TMPF_TRUETYPE
))
2848 if (!GetCharABCWidthsI(hdc
, 0, 1, &glyph
, abc
)) return S_FALSE
;
2853 if (!GetCharWidth32W(hdc
, glyph
, glyph
, &width
)) return S_FALSE
;
2855 abc
->abcA
= abc
->abcC
= 0;
2857 set_cache_glyph_widths(psc
, glyph
, abc
);
2862 /***********************************************************************
2863 * ScriptLayout (USP10.@)
2865 * Map embedding levels to visual and/or logical order.
2868 * runs [I] Size of level array.
2869 * level [I] Array of embedding levels.
2870 * vistolog [O] Map of embedding levels from visual to logical order.
2871 * logtovis [O] Map of embedding levels from logical to visual order.
2875 * Failure: Non-zero HRESULT value.
2878 * This stub works correctly for any sequence of a single
2879 * embedding level but not for sequences of different
2880 * embedding levels, i.e. mixtures of RTL and LTR scripts.
2882 HRESULT WINAPI
ScriptLayout(int runs
, const BYTE
*level
, int *vistolog
, int *logtovis
)
2887 TRACE("(%d, %p, %p, %p)\n", runs
, level
, vistolog
, logtovis
);
2889 if (!level
|| (!vistolog
&& !logtovis
))
2890 return E_INVALIDARG
;
2892 indexs
= heap_alloc(sizeof(int) * runs
);
2894 return E_OUTOFMEMORY
;
2899 for( ich
= 0; ich
< runs
; ich
++)
2904 ich
+= BIDI_ReorderV2lLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2905 for (ich
= 0; ich
< runs
; ich
++)
2906 vistolog
[ich
] = indexs
[ich
];
2912 for( ich
= 0; ich
< runs
; ich
++)
2917 ich
+= BIDI_ReorderL2vLevel(0, indexs
+ich
, level
+ich
, runs
- ich
, FALSE
);
2918 for (ich
= 0; ich
< runs
; ich
++)
2919 logtovis
[ich
] = indexs
[ich
];
2926 /***********************************************************************
2927 * ScriptStringGetLogicalWidths (USP10.@)
2929 * Returns logical widths from a string analysis.
2932 * ssa [I] string analysis.
2933 * piDx [O] logical widths returned.
2937 * Failure: a non-zero HRESULT.
2939 HRESULT WINAPI
ScriptStringGetLogicalWidths(SCRIPT_STRING_ANALYSIS ssa
, int *piDx
)
2942 StringAnalysis
*analysis
= ssa
;
2944 TRACE("%p, %p\n", ssa
, piDx
);
2946 if (!analysis
) return S_FALSE
;
2947 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
2949 for (i
= 0; i
< analysis
->numItems
; i
++)
2951 int cChar
= analysis
->pItem
[i
+1].iCharPos
- analysis
->pItem
[i
].iCharPos
;
2954 if (analysis
->pItem
[i
].a
.fRTL
&& ! analysis
->pItem
[i
].a
.fLogicalOrder
)
2957 for (j
= 0; j
< cChar
; j
++)
2960 int glyph
= analysis
->glyphs
[i
].pwLogClust
[j
];
2961 int clust_size
= get_cluster_size(analysis
->glyphs
[i
].pwLogClust
,
2962 cChar
, j
, direction
, NULL
, NULL
);
2963 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
);
2965 for (k
= 0; k
< clust_size
; k
++)
2967 piDx
[next
] = advance
/ clust_size
;
2976 /***********************************************************************
2977 * ScriptStringValidate (USP10.@)
2979 * Validate a string analysis.
2982 * ssa [I] string analysis.
2986 * Failure: S_FALSE if invalid sequences are found
2987 * or a non-zero HRESULT if it fails.
2989 HRESULT WINAPI
ScriptStringValidate(SCRIPT_STRING_ANALYSIS ssa
)
2991 StringAnalysis
*analysis
= ssa
;
2993 TRACE("(%p)\n", ssa
);
2995 if (!analysis
) return E_INVALIDARG
;
2996 return (analysis
->invalid
) ? S_FALSE
: S_OK
;
2999 /***********************************************************************
3000 * ScriptString_pSize (USP10.@)
3002 * Retrieve width and height of an analysed string.
3005 * ssa [I] string analysis.
3008 * Success: Pointer to a SIZE structure.
3011 const SIZE
* WINAPI
ScriptString_pSize(SCRIPT_STRING_ANALYSIS ssa
)
3014 StringAnalysis
*analysis
= ssa
;
3016 TRACE("(%p)\n", ssa
);
3018 if (!analysis
) return NULL
;
3019 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return NULL
;
3023 if (!(analysis
->sz
= heap_alloc(sizeof(SIZE
)))) return NULL
;
3024 analysis
->sz
->cy
= analysis
->glyphs
[0].sc
->tm
.tmHeight
;
3026 analysis
->sz
->cx
= 0;
3027 for (i
= 0; i
< analysis
->numItems
; i
++)
3029 if (analysis
->glyphs
[i
].sc
->tm
.tmHeight
> analysis
->sz
->cy
)
3030 analysis
->sz
->cy
= analysis
->glyphs
[i
].sc
->tm
.tmHeight
;
3031 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++)
3032 analysis
->sz
->cx
+= analysis
->glyphs
[i
].piAdvance
[j
];
3035 return analysis
->sz
;
3038 /***********************************************************************
3039 * ScriptString_pLogAttr (USP10.@)
3041 * Retrieve logical attributes of an analysed string.
3044 * ssa [I] string analysis.
3047 * Success: Pointer to an array of SCRIPT_LOGATTR structures.
3050 const SCRIPT_LOGATTR
* WINAPI
ScriptString_pLogAttr(SCRIPT_STRING_ANALYSIS ssa
)
3052 StringAnalysis
*analysis
= ssa
;
3054 TRACE("(%p)\n", ssa
);
3056 if (!analysis
) return NULL
;
3057 if (!(analysis
->dwFlags
& SSA_BREAK
)) return NULL
;
3058 return analysis
->logattrs
;
3061 /***********************************************************************
3062 * ScriptString_pcOutChars (USP10.@)
3064 * Retrieve the length of a string after clipping.
3067 * ssa [I] String analysis.
3070 * Success: Pointer to the length.
3073 const int * WINAPI
ScriptString_pcOutChars(SCRIPT_STRING_ANALYSIS ssa
)
3075 StringAnalysis
*analysis
= ssa
;
3077 TRACE("(%p)\n", ssa
);
3079 if (!analysis
) return NULL
;
3080 return &analysis
->clip_len
;
3083 /***********************************************************************
3084 * ScriptStringGetOrder (USP10.@)
3086 * Retrieve a glyph order map.
3089 * ssa [I] String analysis.
3090 * order [I/O] Array of glyph positions.
3094 * Failure: a non-zero HRESULT.
3096 HRESULT WINAPI
ScriptStringGetOrder(SCRIPT_STRING_ANALYSIS ssa
, UINT
*order
)
3100 StringAnalysis
*analysis
= ssa
;
3102 TRACE("(%p)\n", ssa
);
3104 if (!analysis
) return S_FALSE
;
3105 if (!(analysis
->dwFlags
& SSA_GLYPHS
)) return S_FALSE
;
3107 /* FIXME: handle RTL scripts */
3108 for (i
= 0, k
= 0; i
< analysis
->numItems
; i
++)
3109 for (j
= 0; j
< analysis
->glyphs
[i
].numGlyphs
; j
++, k
++)
3115 /***********************************************************************
3116 * ScriptGetLogicalWidths (USP10.@)
3118 * Convert advance widths to logical widths.
3121 * sa [I] Script analysis.
3122 * nbchars [I] Number of characters.
3123 * nbglyphs [I] Number of glyphs.
3124 * glyph_width [I] Array of glyph widths.
3125 * log_clust [I] Array of logical clusters.
3126 * sva [I] Visual attributes.
3127 * widths [O] Array of logical widths.
3131 * Failure: a non-zero HRESULT.
3133 HRESULT WINAPI
ScriptGetLogicalWidths(const SCRIPT_ANALYSIS
*sa
, int nbchars
, int nbglyphs
,
3134 const int *glyph_width
, const WORD
*log_clust
,
3135 const SCRIPT_VISATTR
*sva
, int *widths
)
3139 TRACE("(%p, %d, %d, %p, %p, %p, %p)\n",
3140 sa
, nbchars
, nbglyphs
, glyph_width
, log_clust
, sva
, widths
);
3143 for (i
= 0; i
< nbchars
; i
++) widths
[i
] = glyph_width
[i
];
3147 /***********************************************************************
3148 * ScriptApplyLogicalWidth (USP10.@)
3150 * Generate glyph advance widths.
3153 * dx [I] Array of logical advance widths.
3154 * num_chars [I] Number of characters.
3155 * num_glyphs [I] Number of glyphs.
3156 * log_clust [I] Array of logical clusters.
3157 * sva [I] Visual attributes.
3158 * advance [I] Array of glyph advance widths.
3159 * sa [I] Script analysis.
3160 * abc [I/O] Summed ABC widths.
3161 * justify [O] Array of glyph advance widths.
3165 * Failure: a non-zero HRESULT.
3167 HRESULT WINAPI
ScriptApplyLogicalWidth(const int *dx
, int num_chars
, int num_glyphs
,
3168 const WORD
*log_clust
, const SCRIPT_VISATTR
*sva
,
3169 const int *advance
, const SCRIPT_ANALYSIS
*sa
,
3170 ABC
*abc
, int *justify
)
3174 FIXME("(%p, %d, %d, %p, %p, %p, %p, %p, %p)\n",
3175 dx
, num_chars
, num_glyphs
, log_clust
, sva
, advance
, sa
, abc
, justify
);
3177 for (i
= 0; i
< num_chars
; i
++) justify
[i
] = advance
[i
];
3181 HRESULT WINAPI
ScriptJustify(const SCRIPT_VISATTR
*sva
, const int *advance
,
3182 int num_glyphs
, int dx
, int min_kashida
, int *justify
)
3186 FIXME("(%p, %p, %d, %d, %d, %p)\n", sva
, advance
, num_glyphs
, dx
, min_kashida
, justify
);
3188 for (i
= 0; i
< num_glyphs
; i
++) justify
[i
] = advance
[i
];