2 * Implementation of Shaping for the Uniscribe Script Processor (usp10.dll)
4 * Copyright 2010 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "usp10_internal.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
26 #define FIRST_ARABIC_CHAR 0x0600
27 #define LAST_ARABIC_CHAR 0x06ff
29 typedef VOID (*ContextualShapingProc
)(HDC
, ScriptCache
*, SCRIPT_ANALYSIS
*,
30 WCHAR
*, INT
, WORD
*, INT
*, INT
, WORD
*);
32 static void ContextualShape_Control(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
33 static void ContextualShape_Arabic(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
34 static void ContextualShape_Hebrew(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
35 static void ContextualShape_Syriac(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
36 static void ContextualShape_Thaana(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
37 static void ContextualShape_Phags_pa(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
38 static void ContextualShape_Thai(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
39 static void ContextualShape_Lao(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
40 static void ContextualShape_Sinhala(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
41 static void ContextualShape_Devanagari(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
42 static void ContextualShape_Bengali(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
43 static void ContextualShape_Gurmukhi(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
44 static void ContextualShape_Gujarati(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
45 static void ContextualShape_Oriya(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
46 static void ContextualShape_Tamil(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
47 static void ContextualShape_Telugu(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
48 static void ContextualShape_Kannada(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
49 static void ContextualShape_Malayalam(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
50 static void ContextualShape_Khmer(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
51 static void ContextualShape_Mongolian(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
53 typedef VOID (*ShapeCharGlyphPropProc
)( HDC
, ScriptCache
*, SCRIPT_ANALYSIS
*, const WCHAR
*, const INT
, const WORD
*, const INT
, WORD
*, SCRIPT_CHARPROP
*, SCRIPT_GLYPHPROP
*);
55 static void ShapeCharGlyphProp_Default( ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
);
56 static void ShapeCharGlyphProp_Control( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
57 static void ShapeCharGlyphProp_Latin( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
58 static void ShapeCharGlyphProp_Arabic( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
59 static void ShapeCharGlyphProp_Hebrew( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
60 static void ShapeCharGlyphProp_Thai( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
61 static void ShapeCharGlyphProp_None( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
62 static void ShapeCharGlyphProp_Tibet( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
63 static void ShapeCharGlyphProp_Sinhala( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
64 static void ShapeCharGlyphProp_Devanagari( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
65 static void ShapeCharGlyphProp_Bengali( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
66 static void ShapeCharGlyphProp_Gurmukhi( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
67 static void ShapeCharGlyphProp_Gujarati( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
68 static void ShapeCharGlyphProp_Oriya( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
69 static void ShapeCharGlyphProp_Tamil( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
70 static void ShapeCharGlyphProp_Telugu( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
71 static void ShapeCharGlyphProp_Kannada( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
72 static void ShapeCharGlyphProp_Malayalam( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
73 static void ShapeCharGlyphProp_Khmer( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
75 extern const unsigned short indic_syllabic_table
[];
76 extern const unsigned short wine_shaping_table
[];
77 extern const unsigned short wine_shaping_forms
[LAST_ARABIC_CHAR
- FIRST_ARABIC_CHAR
+ 1][4];
99 typedef struct tagVowelComponents
105 typedef struct tagConsonantComponents
109 } ConsonantComponents
;
111 typedef void (*second_reorder_function
)(LPWSTR pwChar
, IndicSyllable
*syllable
,WORD
* pwGlyphs
, IndicSyllable
* glyph_index
, lexical_function lex
);
113 typedef int (*combining_lexical_function
)(WCHAR c
);
115 /* the orders of joined_forms and contextual_features need to line up */
116 static const char* contextual_features
[] =
128 static OPENTYPE_FEATURE_RECORD standard_features
[] =
130 { MS_MAKE_TAG('c','c','m','p'), 1},
131 { MS_MAKE_TAG('l','o','c','l'), 1},
134 static OPENTYPE_FEATURE_RECORD latin_features
[] =
136 { MS_MAKE_TAG('l','o','c','l'), 1},
137 { MS_MAKE_TAG('c','c','m','p'), 1},
138 { MS_MAKE_TAG('l','i','g','a'), 1},
139 { MS_MAKE_TAG('c','l','i','g'), 1},
142 static OPENTYPE_FEATURE_RECORD latin_gpos_features
[] =
144 { MS_MAKE_TAG('k','e','r','n'), 1},
145 { MS_MAKE_TAG('m','a','r','k'), 1},
146 { MS_MAKE_TAG('m','k','m','k'), 1},
149 static OPENTYPE_FEATURE_RECORD arabic_features
[] =
151 { MS_MAKE_TAG('r','l','i','g'), 1},
152 { MS_MAKE_TAG('c','a','l','t'), 1},
153 { MS_MAKE_TAG('l','i','g','a'), 1},
154 { MS_MAKE_TAG('d','l','i','g'), 1},
155 { MS_MAKE_TAG('c','s','w','h'), 1},
156 { MS_MAKE_TAG('m','s','e','t'), 1},
159 static const char* required_arabic_features
[] =
168 static OPENTYPE_FEATURE_RECORD arabic_gpos_features
[] =
170 { MS_MAKE_TAG('c','u','r','s'), 1},
171 { MS_MAKE_TAG('k','e','r','n'), 1},
172 { MS_MAKE_TAG('m','a','r','k'), 1},
173 { MS_MAKE_TAG('m','k','m','k'), 1},
176 static OPENTYPE_FEATURE_RECORD hebrew_features
[] =
178 { MS_MAKE_TAG('c','c','m','p'), 1},
179 { MS_MAKE_TAG('d','l','i','g'), 0},
182 static OPENTYPE_FEATURE_RECORD hebrew_gpos_features
[] =
184 { MS_MAKE_TAG('k','e','r','n'), 1},
185 { MS_MAKE_TAG('m','a','r','k'), 1},
188 static OPENTYPE_FEATURE_RECORD syriac_features
[] =
190 { MS_MAKE_TAG('r','l','i','g'), 1},
191 { MS_MAKE_TAG('c','a','l','t'), 1},
192 { MS_MAKE_TAG('l','i','g','a'), 1},
193 { MS_MAKE_TAG('d','l','i','g'), 1},
196 static const char* required_syriac_features
[] =
208 static OPENTYPE_FEATURE_RECORD syriac_gpos_features
[] =
210 { MS_MAKE_TAG('k','e','r','n'), 1},
211 { MS_MAKE_TAG('m','a','r','k'), 1},
212 { MS_MAKE_TAG('m','k','m','k'), 1},
215 static OPENTYPE_FEATURE_RECORD sinhala_features
[] =
217 /* Presentation forms */
218 { MS_MAKE_TAG('b','l','w','s'), 1},
219 { MS_MAKE_TAG('a','b','v','s'), 1},
220 { MS_MAKE_TAG('p','s','t','s'), 1},
223 static OPENTYPE_FEATURE_RECORD tibetan_features
[] =
225 { MS_MAKE_TAG('a','b','v','s'), 1},
226 { MS_MAKE_TAG('b','l','w','s'), 1},
229 static OPENTYPE_FEATURE_RECORD tibetan_gpos_features
[] =
231 { MS_MAKE_TAG('a','b','v','m'), 1},
232 { MS_MAKE_TAG('b','l','w','m'), 1},
235 static OPENTYPE_FEATURE_RECORD phags_features
[] =
237 { MS_MAKE_TAG('a','b','v','s'), 1},
238 { MS_MAKE_TAG('b','l','w','s'), 1},
239 { MS_MAKE_TAG('c','a','l','t'), 1},
242 static OPENTYPE_FEATURE_RECORD thai_features
[] =
244 { MS_MAKE_TAG('c','c','m','p'), 1},
247 static OPENTYPE_FEATURE_RECORD thai_gpos_features
[] =
249 { MS_MAKE_TAG('k','e','r','n'), 1},
250 { MS_MAKE_TAG('m','a','r','k'), 1},
251 { MS_MAKE_TAG('m','k','m','k'), 1},
254 static const char* required_lao_features
[] =
260 static const char* required_devanagari_features
[] =
276 static OPENTYPE_FEATURE_RECORD devanagari_features
[] =
278 { MS_MAKE_TAG('p','r','e','s'), 1},
279 { MS_MAKE_TAG('a','b','v','s'), 1},
280 { MS_MAKE_TAG('b','l','w','s'), 1},
281 { MS_MAKE_TAG('p','s','t','s'), 1},
282 { MS_MAKE_TAG('h','a','l','n'), 1},
283 { MS_MAKE_TAG('c','a','l','t'), 1},
286 static OPENTYPE_FEATURE_RECORD devanagari_gpos_features
[] =
288 { MS_MAKE_TAG('k','e','r','n'), 1},
289 { MS_MAKE_TAG('d','i','s','t'), 1},
290 { MS_MAKE_TAG('a','b','v','m'), 1},
291 { MS_MAKE_TAG('b','l','w','m'), 1},
294 static OPENTYPE_FEATURE_RECORD myanmar_features
[] =
296 { MS_MAKE_TAG('l','i','g','a'), 1},
297 { MS_MAKE_TAG('c','l','i','g'), 1},
300 static const char* required_bengali_features
[] =
317 static const char* required_gurmukhi_features
[] =
336 static const char* required_oriya_features
[] =
353 static const char* required_tamil_features
[] =
369 static const char* required_telugu_features
[] =
387 static OPENTYPE_FEATURE_RECORD khmer_features
[] =
389 { MS_MAKE_TAG('p','r','e','s'), 1},
390 { MS_MAKE_TAG('b','l','w','s'), 1},
391 { MS_MAKE_TAG('a','b','v','s'), 1},
392 { MS_MAKE_TAG('p','s','t','s'), 1},
393 { MS_MAKE_TAG('c','l','i','g'), 1},
396 static const char* required_khmer_features
[] =
410 static OPENTYPE_FEATURE_RECORD khmer_gpos_features
[] =
412 { MS_MAKE_TAG('d','i','s','t'), 1},
413 { MS_MAKE_TAG('b','l','w','m'), 1},
414 { MS_MAKE_TAG('a','b','v','m'), 1},
415 { MS_MAKE_TAG('m','k','m','k'), 1},
418 static OPENTYPE_FEATURE_RECORD ethiopic_features
[] =
420 { MS_MAKE_TAG('c','c','m','p'), 1},
421 { MS_MAKE_TAG('l','o','c','l'), 1},
422 { MS_MAKE_TAG('c','a','l','t'), 1},
423 { MS_MAKE_TAG('l','i','g','a'), 1},
426 static OPENTYPE_FEATURE_RECORD mongolian_features
[] =
428 { MS_MAKE_TAG('c','c','m','p'), 1},
429 { MS_MAKE_TAG('l','o','c','l'), 1},
430 { MS_MAKE_TAG('c','a','l','t'), 1},
431 { MS_MAKE_TAG('r','l','i','g'), 1},
434 typedef struct ScriptShapeDataTag
{
435 TEXTRANGE_PROPERTIES defaultTextRange
;
436 TEXTRANGE_PROPERTIES defaultGPOSTextRange
;
437 const char** requiredFeatures
;
438 OPENTYPE_TAG newOtTag
;
439 ContextualShapingProc contextProc
;
440 ShapeCharGlyphPropProc charGlyphPropProc
;
443 /* in order of scripts */
444 static const ScriptShapeData ShapingData
[] =
446 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
447 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
448 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
449 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
450 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, ContextualShape_Control
, ShapeCharGlyphProp_Control
},
451 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
452 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
453 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
454 {{ hebrew_features
, 2}, {hebrew_gpos_features
, 2}, NULL
, 0, ContextualShape_Hebrew
, ShapeCharGlyphProp_Hebrew
},
455 {{ syriac_features
, 4}, {syriac_gpos_features
, 3}, required_syriac_features
, 0, ContextualShape_Syriac
, ShapeCharGlyphProp_None
},
456 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
457 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, ContextualShape_Thaana
, ShapeCharGlyphProp_None
},
458 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
459 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
460 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
461 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
462 {{ sinhala_features
, 3}, {NULL
, 0}, NULL
, 0, ContextualShape_Sinhala
, ShapeCharGlyphProp_Sinhala
},
463 {{ tibetan_features
, 2}, {tibetan_gpos_features
, 2}, NULL
, 0, NULL
, ShapeCharGlyphProp_Tibet
},
464 {{ tibetan_features
, 2}, {tibetan_gpos_features
, 2}, NULL
, 0, NULL
, ShapeCharGlyphProp_Tibet
},
465 {{ phags_features
, 3}, {NULL
, 0}, NULL
, 0, ContextualShape_Phags_pa
, ShapeCharGlyphProp_Thai
},
466 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, ShapeCharGlyphProp_Thai
},
467 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, NULL
},
468 {{ thai_features
, 1}, {thai_gpos_features
, 3}, required_lao_features
, 0, ContextualShape_Lao
, ShapeCharGlyphProp_Thai
},
469 {{ thai_features
, 1}, {thai_gpos_features
, 3}, required_lao_features
, 0, ContextualShape_Lao
, ShapeCharGlyphProp_Thai
},
470 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari
, ShapeCharGlyphProp_Devanagari
},
471 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari
, NULL
},
472 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, ShapeCharGlyphProp_Bengali
},
473 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, NULL
},
474 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, ShapeCharGlyphProp_Bengali
},
475 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_gurmukhi_features
, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi
, ShapeCharGlyphProp_Gurmukhi
},
476 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_gurmukhi_features
, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi
, NULL
},
477 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, ShapeCharGlyphProp_Gujarati
},
478 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, NULL
},
479 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, ShapeCharGlyphProp_Gujarati
},
480 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_oriya_features
, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya
, ShapeCharGlyphProp_Oriya
},
481 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_oriya_features
, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya
, NULL
},
482 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_tamil_features
, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil
, ShapeCharGlyphProp_Tamil
},
483 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_tamil_features
, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil
, NULL
},
484 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu
, ShapeCharGlyphProp_Telugu
},
485 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu
, NULL
},
486 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada
, ShapeCharGlyphProp_Kannada
},
487 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada
, NULL
},
488 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam
, ShapeCharGlyphProp_Malayalam
},
489 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam
, NULL
},
490 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
491 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
492 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
493 {{ myanmar_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
494 {{ myanmar_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
495 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
496 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
497 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
498 {{ khmer_features
, 5}, {khmer_gpos_features
, 4}, required_khmer_features
, 0, ContextualShape_Khmer
, ShapeCharGlyphProp_Khmer
},
499 {{ khmer_features
, 5}, {khmer_gpos_features
, 4}, required_khmer_features
, 0, ContextualShape_Khmer
, ShapeCharGlyphProp_Khmer
},
500 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
501 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
502 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
503 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
504 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
505 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
506 {{ ethiopic_features
, 4}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
507 {{ ethiopic_features
, 4}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
508 {{ mongolian_features
, 4}, {NULL
, 0}, NULL
, 0, ContextualShape_Mongolian
, NULL
},
509 {{ mongolian_features
, 4}, {NULL
, 0}, NULL
, 0, ContextualShape_Mongolian
, NULL
},
510 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
511 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
512 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
513 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
514 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
515 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
516 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
517 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
518 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
519 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
520 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
521 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
522 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
523 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
524 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
525 {{ hebrew_features
, 2}, {hebrew_gpos_features
, 2}, NULL
, 0, ContextualShape_Hebrew
, NULL
},
526 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
527 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, ShapeCharGlyphProp_Thai
},
530 extern scriptData scriptInformation
[];
532 static INT
GSUB_apply_feature_all_lookups(LPCVOID header
, LoadedFeature
*feature
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
535 int out_index
= GSUB_E_NOGLYPH
;
537 TRACE("%i lookups\n", feature
->lookup_count
);
538 for (i
= 0; i
< feature
->lookup_count
; i
++)
540 out_index
= OpenType_apply_GSUB_lookup(header
, feature
->lookups
[i
], glyphs
, glyph_index
, write_dir
, glyph_count
);
541 if (out_index
!= GSUB_E_NOGLYPH
)
544 if (out_index
== GSUB_E_NOGLYPH
)
545 TRACE("lookups found no glyphs\n");
549 out2
= GSUB_apply_feature_all_lookups(header
, feature
, glyphs
, glyph_index
, write_dir
, glyph_count
);
550 if (out2
!=GSUB_E_NOGLYPH
)
556 static OPENTYPE_TAG
get_opentype_script(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
, BOOL tryNew
)
560 if (psc
->userScript
!= 0)
562 if (tryNew
&& ShapingData
[psa
->eScript
].newOtTag
!= 0 && psc
->userScript
== scriptInformation
[psa
->eScript
].scriptTag
)
563 return ShapingData
[psa
->eScript
].newOtTag
;
565 return psc
->userScript
;
568 if (tryNew
&& ShapingData
[psa
->eScript
].newOtTag
!= 0)
569 return ShapingData
[psa
->eScript
].newOtTag
;
571 if (scriptInformation
[psa
->eScript
].scriptTag
)
572 return scriptInformation
[psa
->eScript
].scriptTag
;
575 * fall back to the font charset
577 charset
= GetTextCharsetInfo(hdc
, NULL
, 0x0);
581 case BALTIC_CHARSET
: return MS_MAKE_TAG('l','a','t','n');
582 case CHINESEBIG5_CHARSET
: return MS_MAKE_TAG('h','a','n','i');
583 case EASTEUROPE_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
584 case GB2312_CHARSET
: return MS_MAKE_TAG('h','a','n','i');
585 case GREEK_CHARSET
: return MS_MAKE_TAG('g','r','e','k');
586 case HANGUL_CHARSET
: return MS_MAKE_TAG('h','a','n','g');
587 case RUSSIAN_CHARSET
: return MS_MAKE_TAG('c','y','r','l');
588 case SHIFTJIS_CHARSET
: return MS_MAKE_TAG('k','a','n','a');
589 case TURKISH_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
590 case VIETNAMESE_CHARSET
: return MS_MAKE_TAG('l','a','t','n');
591 case JOHAB_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
592 case ARABIC_CHARSET
: return MS_MAKE_TAG('a','r','a','b');
593 case HEBREW_CHARSET
: return MS_MAKE_TAG('h','e','b','r');
594 case THAI_CHARSET
: return MS_MAKE_TAG('t','h','a','i');
595 default: return MS_MAKE_TAG('l','a','t','n');
599 static LoadedFeature
* load_OT_feature(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
, char tableType
, const char* feat
)
601 LoadedFeature
*feature
= NULL
;
603 if (psc
->GSUB_Table
|| psc
->GPOS_Table
)
607 OPENTYPE_TAG language
;
608 OPENTYPE_TAG script
= 0x00000000;
613 script
= get_opentype_script(hdc
,psa
,psc
,(attempt
==2));
614 if (psc
->userLang
!= 0)
615 language
= psc
->userLang
;
617 language
= MS_MAKE_TAG('d','f','l','t');
620 OpenType_GetFontFeatureTags(psc
, script
, language
, FALSE
, MS_MAKE_TAG(feat
[0],feat
[1],feat
[2],feat
[3]), tableType
, 1, &tags
, &cTags
, &feature
);
622 } while(attempt
&& !feature
);
624 /* try in the default (latin) table */
625 if (!feature
&& !script
)
626 OpenType_GetFontFeatureTags(psc
, MS_MAKE_TAG('l','a','t','n'), MS_MAKE_TAG('d','f','l','t'), FALSE
, MS_MAKE_TAG(feat
[0],feat
[1],feat
[2],feat
[3]), tableType
, 1, &tags
, &cTags
, &feature
);
629 TRACE("Feature %s located at %p\n",debugstr_an(feat
,4),feature
);
633 static INT
apply_GSUB_feature_to_glyph(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, WORD
*glyphs
, INT index
, INT write_dir
, INT
* glyph_count
, const char* feat
)
635 LoadedFeature
*feature
;
637 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, feat
);
639 return GSUB_E_NOFEATURE
;
641 TRACE("applying feature %s\n",feat
);
642 return GSUB_apply_feature_all_lookups(psc
->GSUB_Table
, feature
, glyphs
, index
, write_dir
, glyph_count
);
645 static VOID
*load_gsub_table(HDC hdc
)
647 VOID
* GSUB_Table
= NULL
;
648 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL
, 0);
649 if (length
!= GDI_ERROR
)
651 GSUB_Table
= HeapAlloc(GetProcessHeap(),0,length
);
652 GetFontData(hdc
, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, GSUB_Table
, length
);
653 TRACE("Loaded GSUB table of %i bytes\n",length
);
658 static VOID
*load_gpos_table(HDC hdc
)
660 VOID
* GPOS_Table
= NULL
;
661 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, NULL
, 0);
662 if (length
!= GDI_ERROR
)
664 GPOS_Table
= HeapAlloc(GetProcessHeap(),0,length
);
665 GetFontData(hdc
, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, GPOS_Table
, length
);
666 TRACE("Loaded GPOS table of %i bytes\n",length
);
671 static VOID
*load_gdef_table(HDC hdc
)
673 VOID
* GDEF_Table
= NULL
;
674 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'D', 'E', 'F'), 0, NULL
, 0);
675 if (length
!= GDI_ERROR
)
677 GDEF_Table
= HeapAlloc(GetProcessHeap(),0,length
);
678 GetFontData(hdc
, MS_MAKE_TAG('G', 'D', 'E', 'F'), 0, GDEF_Table
, length
);
679 TRACE("Loaded GDEF table of %i bytes\n",length
);
684 static VOID
load_ot_tables(HDC hdc
, ScriptCache
*psc
)
686 if (!psc
->GSUB_Table
)
687 psc
->GSUB_Table
= load_gsub_table(hdc
);
688 if (!psc
->GPOS_Table
)
689 psc
->GPOS_Table
= load_gpos_table(hdc
);
690 if (!psc
->GDEF_Table
)
691 psc
->GDEF_Table
= load_gdef_table(hdc
);
694 INT
SHAPE_does_GSUB_feature_apply_to_chars(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, const WCHAR
*chars
, INT write_dir
, INT count
, const char* feature
)
697 INT glyph_count
= count
;
700 glyphs
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
)*(count
*2));
701 GetGlyphIndicesW(hdc
, chars
, count
, glyphs
, 0);
702 rc
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, glyphs
, 0, write_dir
, &glyph_count
, feature
);
703 if (rc
> GSUB_E_NOGLYPH
)
704 rc
= count
- glyph_count
;
708 HeapFree(GetProcessHeap(),0,glyphs
);
712 static void UpdateClustersFromGlyphProp(const int cGlyphs
, const int cChars
, WORD
* pwLogClust
, SCRIPT_GLYPHPROP
*pGlyphProp
)
716 for (i
= 0; i
< cGlyphs
; i
++)
718 if (!pGlyphProp
[i
].sva
.fClusterStart
)
721 for (j
= 0; j
< cChars
; j
++)
723 if (pwLogClust
[j
] == i
)
726 while (k
>= 0 && k
<cChars
&& !pGlyphProp
[pwLogClust
[k
]].sva
.fClusterStart
)
728 if (k
>= 0 && k
<cChars
&& pGlyphProp
[pwLogClust
[k
]].sva
.fClusterStart
)
729 pwLogClust
[j
] = pwLogClust
[k
];
736 static void UpdateClusters(int nextIndex
, int changeCount
, int write_dir
, int chars
, WORD
* pwLogClust
)
738 if (changeCount
== 0)
743 int target_glyph
= nextIndex
- write_dir
;
745 int target_index
= -1;
746 int replacing_glyph
= -1;
748 int top_logclust
= 0;
753 target_glyph
= nextIndex
- changeCount
;
755 target_glyph
= nextIndex
+ (changeCount
+ 1);
758 seeking_glyph
= target_glyph
;
759 for (i
= 0; i
< chars
; i
++)
760 if (pwLogClust
[i
] > top_logclust
)
761 top_logclust
= pwLogClust
[i
];
765 for (i
= 0; i
< chars
; i
++)
767 if (pwLogClust
[i
] == seeking_glyph
)
774 for (i
= chars
- 1; i
>= 0; i
--)
776 if (pwLogClust
[i
] == seeking_glyph
)
782 if (target_index
== -1)
785 while (target_index
== -1 && seeking_glyph
<= top_logclust
);
787 if (target_index
== -1)
789 ERR("Unable to find target glyph\n");
796 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
798 if (pwLogClust
[i
] == target_glyph
)
800 if(pwLogClust
[i
] == replacing_glyph
)
801 pwLogClust
[i
] = target_glyph
;
805 if (changed
>= changeCount
)
807 replacing_glyph
= pwLogClust
[i
];
808 pwLogClust
[i
] = target_glyph
;
815 /* renumber trailing indexes*/
816 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
818 if (pwLogClust
[i
] != target_glyph
)
819 pwLogClust
[i
] += changeCount
;
824 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
825 pwLogClust
[i
] += changeCount
;
830 static int apply_GSUB_feature(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, WORD
*pwOutGlyphs
, int write_dir
, INT
* pcGlyphs
, INT cChars
, const char* feat
, WORD
*pwLogClust
)
834 LoadedFeature
*feature
;
837 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, feat
);
839 return GSUB_E_NOFEATURE
;
841 TRACE("applying feature %s: %i lookups\n",debugstr_an(feat
,4),feature
->lookup_count
);
842 for (lookup_index
= 0; lookup_index
< feature
->lookup_count
; lookup_index
++)
850 TRACE("applying lookup (%i/%i)\n",lookup_index
,feature
->lookup_count
);
851 while(i
< *pcGlyphs
&& i
>= 0)
854 INT prevCount
= *pcGlyphs
;
856 nextIndex
= OpenType_apply_GSUB_lookup(psc
->GSUB_Table
, feature
->lookups
[lookup_index
], pwOutGlyphs
, i
, write_dir
, pcGlyphs
);
857 if (*pcGlyphs
!= prevCount
)
859 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, write_dir
, cChars
, pwLogClust
);
868 return GSUB_E_NOFEATURE
;
871 static VOID
GPOS_apply_feature(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
, LoadedFeature
*feature
, const WORD
*glyphs
, INT glyph_count
, GOFFSET
*pGoffset
)
875 TRACE("%i lookups\n", feature
->lookup_count
);
876 for (i
= 0; i
< feature
->lookup_count
; i
++)
879 for (j
= 0; j
< glyph_count
; )
880 j
= OpenType_apply_GPOS_lookup(psc
, lpotm
, lplogfont
, analysis
, piAdvance
, feature
->lookups
[i
], glyphs
, j
, glyph_count
, pGoffset
);
884 static inline BOOL
get_GSUB_Indic2(SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
)
890 hr
= OpenType_GetFontScriptTags(psc
, ShapingData
[psa
->eScript
].newOtTag
, 1, &tag
, &count
);
892 return(SUCCEEDED(hr
));
895 static void insert_glyph(WORD
*pwGlyphs
, INT
*pcGlyphs
, INT cChars
, INT write_dir
, WORD glyph
, INT index
, WORD
*pwLogClust
)
898 for (i
= *pcGlyphs
; i
>=index
; i
--)
899 pwGlyphs
[i
+1] = pwGlyphs
[i
];
900 pwGlyphs
[index
] = glyph
;
901 *pcGlyphs
= *pcGlyphs
+1;
903 UpdateClusters(index
-3, 1, write_dir
, cChars
, pwLogClust
);
905 UpdateClusters(index
, 1, write_dir
, cChars
, pwLogClust
);
908 static void mark_invalid_combinations(HDC hdc
, const WCHAR
* pwcChars
, INT cChars
, WORD
*pwGlyphs
, INT
*pcGlyphs
, INT write_dir
, WORD
*pwLogClust
, combining_lexical_function lex
)
912 WCHAR invalid
= 0x25cc;
915 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
917 /* Mark invalid combinations */
918 for (i
= 0; i
< cChars
; i
++)
919 context_type
[i
] = lex(pwcChars
[i
]);
921 GetGlyphIndicesW(hdc
, &invalid
, 1, &invalid_glyph
, 0);
922 for (i
= 1, g
=1; i
< cChars
- 1; i
++, g
++)
924 if (context_type
[i
] != 0 && context_type
[i
+write_dir
]==context_type
[i
])
926 insert_glyph(pwGlyphs
, pcGlyphs
, cChars
, write_dir
, invalid_glyph
, g
, pwLogClust
);
931 HeapFree(GetProcessHeap(),0,context_type
);
934 static void ContextualShape_Control(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
937 for (i
=0; i
< cChars
; i
++)
943 pwOutGlyphs
[i
] = psc
->sfp
.wgBlank
;
946 if (pwcChars
[i
] < 0x1C)
947 pwOutGlyphs
[i
] = psc
->sfp
.wgDefault
;
949 pwOutGlyphs
[i
] = psc
->sfp
.wgBlank
;
954 static WCHAR
neighbour_char(int i
, int delta
, const WCHAR
* chars
, INT cchLen
)
958 if ( i
+ delta
>= cchLen
)
966 static CHAR
neighbour_joining_type(int i
, int delta
, const CHAR
* context_type
, INT cchLen
, SCRIPT_ANALYSIS
*psa
)
970 if (psa
->fLinkBefore
)
975 if ( i
+ delta
>= cchLen
)
985 if (context_type
[i
] == jtT
)
986 return neighbour_joining_type(i
,delta
,context_type
,cchLen
,psa
);
988 return context_type
[i
];
991 static inline BOOL
right_join_causing(CHAR joining_type
)
993 return (joining_type
== jtL
|| joining_type
== jtD
|| joining_type
== jtC
);
996 static inline BOOL
left_join_causing(CHAR joining_type
)
998 return (joining_type
== jtR
|| joining_type
== jtD
|| joining_type
== jtC
);
1001 static inline BOOL
word_break_causing(WCHAR chr
)
1003 /* we are working within a string of characters already guareented to
1004 be within one script, Syriac, so we do not worry about any character
1005 other than the space character outside of that range */
1006 return (chr
== 0 || chr
== 0x20 );
1009 static int combining_lexical_Arabic(WCHAR c
)
1011 enum {Arab_Norm
= 0, Arab_DIAC1
, Arab_DIAC2
, Arab_DIAC3
, Arab_DIAC4
, Arab_DIAC5
, Arab_DIAC6
, Arab_DIAC7
, Arab_DIAC8
};
1022 case 0x06E1: return Arab_DIAC1
;
1025 case 0x0656: return Arab_DIAC2
;
1026 case 0x0651: return Arab_DIAC3
;
1042 case 0x06EC: return Arab_DIAC4
;
1045 case 0x06ED: return Arab_DIAC5
;
1046 case 0x0670: return Arab_DIAC6
;
1047 case 0x0653: return Arab_DIAC7
;
1049 case 0x0654: return Arab_DIAC8
;
1050 default: return Arab_Norm
;
1055 * ContextualShape_Arabic
1057 static void ContextualShape_Arabic(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1064 if (*pcGlyphs
!= cChars
)
1066 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1070 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1081 load_ot_tables(hdc
, psc
);
1083 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
1084 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1086 for (i
= 0; i
< cChars
; i
++)
1087 context_type
[i
] = get_table_entry( wine_shaping_table
, pwcChars
[i
] );
1089 for (i
= 0; i
< cChars
; i
++)
1091 if (context_type
[i
] == jtR
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1092 context_shape
[i
] = Xr
;
1093 else if (context_type
[i
] == jtL
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1094 context_shape
[i
] = Xl
;
1095 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)) && right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1096 context_shape
[i
] = Xm
;
1097 else if (context_type
[i
] == jtD
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1098 context_shape
[i
] = Xr
;
1099 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1100 context_shape
[i
] = Xl
;
1102 context_shape
[i
] = Xn
;
1105 /* Contextual Shaping */
1107 while(i
< *pcGlyphs
)
1109 BOOL shaped
= FALSE
;
1111 if (psc
->GSUB_Table
)
1114 INT prevCount
= *pcGlyphs
;
1115 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1116 if (nextIndex
> GSUB_E_NOGLYPH
)
1119 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1121 shaped
= (nextIndex
> GSUB_E_NOGLYPH
);
1126 if (context_shape
[i
] == Xn
)
1128 WORD newGlyph
= pwOutGlyphs
[i
];
1129 if (pwcChars
[i
] >= FIRST_ARABIC_CHAR
&& pwcChars
[i
] <= LAST_ARABIC_CHAR
)
1131 /* fall back to presentation form B */
1132 WCHAR context_char
= wine_shaping_forms
[pwcChars
[i
] - FIRST_ARABIC_CHAR
][context_shape
[i
]];
1133 if (context_char
!= pwcChars
[i
] && GetGlyphIndicesW(hdc
, &context_char
, 1, &newGlyph
, 0) != GDI_ERROR
&& newGlyph
!= 0x0000)
1134 pwOutGlyphs
[i
] = newGlyph
;
1141 HeapFree(GetProcessHeap(),0,context_shape
);
1142 HeapFree(GetProcessHeap(),0,context_type
);
1144 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Arabic
);
1147 static int combining_lexical_Hebrew(WCHAR c
)
1149 enum {Hebr_Norm
=0, Hebr_DIAC
, Hebr_CANT1
, Hebr_CANT2
, Hebr_CANT3
, Hebr_CANT4
, Hebr_CANT5
, Hebr_CANT6
, Hebr_CANT7
, Hebr_CANT8
, Hebr_CANT9
, Hebr_CANT10
, Hebr_DAGESH
, Hebr_DOTABV
, Hebr_HOLAM
, Hebr_METEG
, Hebr_PATAH
, Hebr_QAMATS
, Hebr_RAFE
, Hebr_SHINSIN
};
1160 case 0x05BB: return Hebr_DIAC
;
1164 case 0x05AE: return Hebr_CANT1
;
1167 case 0x05AC: return Hebr_CANT2
;
1173 case 0x05AB: return Hebr_CANT3
;
1177 case 0x059F: return Hebr_CANT4
;
1179 case 0x05A0: return Hebr_CANT5
;
1181 case 0x05A5: return Hebr_CANT6
;
1184 case 0x05A6: return Hebr_CANT7
;
1187 case 0x05AA: return Hebr_CANT8
;
1189 case 0x05AD: return Hebr_CANT9
;
1190 case 0x05AF: return Hebr_CANT10
;
1191 case 0x05BC: return Hebr_DAGESH
;
1192 case 0x05C4: return Hebr_DOTABV
;
1193 case 0x05B9: return Hebr_HOLAM
;
1194 case 0x05BD: return Hebr_METEG
;
1195 case 0x05B7: return Hebr_PATAH
;
1196 case 0x05B8: return Hebr_QAMATS
;
1197 case 0x05BF: return Hebr_RAFE
;
1199 case 0x05C2: return Hebr_SHINSIN
;
1200 default: return Hebr_Norm
;
1204 static void ContextualShape_Hebrew(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1208 if (*pcGlyphs
!= cChars
)
1210 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1214 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1219 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Hebrew
);
1223 * ContextualShape_Syriac
1226 static int combining_lexical_Syriac(WCHAR c
)
1228 enum {Syriac_Norm
=0, Syriac_DIAC1
, Syriac_DIAC2
, Syriac_DIAC3
, Syriac_DIAC4
, Syriac_DIAC5
, Syriac_DIAC6
, Syriac_DIAC7
, Syriac_DIAC8
, Syriac_DIAC9
, Syriac_DIAC10
, Syriac_DIAC11
, Syriac_DIAC12
, Syriac_DIAC13
, Syriac_DIAC14
, Syriac_DIAC15
, Syriac_DIAC16
, Syriac_DIAC17
};
1236 case 0x73D: return Syriac_DIAC1
;
1241 case 0x73E: return Syriac_DIAC2
;
1244 case 0x74A: return Syriac_DIAC3
;
1247 case 0x73F: return Syriac_DIAC4
;
1250 case 0x73C: return Syriac_DIAC5
;
1252 case 0x30A: return Syriac_DIAC6
;
1254 case 0x325: return Syriac_DIAC7
;
1256 case 0x303: return Syriac_DIAC8
;
1261 case 0x331: return Syriac_DIAC9
;
1262 case 0x308: return Syriac_DIAC10
;
1263 case 0x304: return Syriac_DIAC11
;
1264 case 0x307: return Syriac_DIAC12
;
1265 case 0x323: return Syriac_DIAC13
;
1266 case 0x743: return Syriac_DIAC14
;
1267 case 0x744: return Syriac_DIAC15
;
1268 case 0x745: return Syriac_DIAC16
;
1269 case 0x746: return Syriac_DIAC17
;
1270 default: return Syriac_Norm
;
1275 #define DALATH 0x715
1278 static void ContextualShape_Syriac(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1285 if (*pcGlyphs
!= cChars
)
1287 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1291 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1302 load_ot_tables(hdc
, psc
);
1304 if (!psc
->GSUB_Table
)
1307 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
1308 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1310 for (i
= 0; i
< cChars
; i
++)
1311 context_type
[i
] = get_table_entry( wine_shaping_table
, pwcChars
[i
] );
1313 for (i
= 0; i
< cChars
; i
++)
1315 if (pwcChars
[i
] == ALAPH
)
1317 WCHAR rchar
= neighbour_char(i
,dirR
,pwcChars
,cChars
);
1319 if (left_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)) && word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1320 context_shape
[i
] = Afj
;
1321 else if ( rchar
!= DALATH
&& rchar
!= RISH
&&
1322 !left_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)) &&
1323 word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1324 context_shape
[i
] = Afn
;
1325 else if ( (rchar
== DALATH
|| rchar
== RISH
) && word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1326 context_shape
[i
] = Afx
;
1328 context_shape
[i
] = Xn
;
1330 else if (context_type
[i
] == jtR
&&
1331 right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1332 context_shape
[i
] = Xr
;
1333 else if (context_type
[i
] == jtL
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1334 context_shape
[i
] = Xl
;
1335 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)) && right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1336 context_shape
[i
] = Xm
;
1337 else if (context_type
[i
] == jtD
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1338 context_shape
[i
] = Xr
;
1339 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1340 context_shape
[i
] = Xl
;
1342 context_shape
[i
] = Xn
;
1345 /* Contextual Shaping */
1347 while(i
< *pcGlyphs
)
1350 INT prevCount
= *pcGlyphs
;
1351 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1352 if (nextIndex
> GSUB_E_NOGLYPH
)
1354 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1361 HeapFree(GetProcessHeap(),0,context_shape
);
1362 HeapFree(GetProcessHeap(),0,context_type
);
1364 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Syriac
);
1367 static int combining_lexical_Thaana(WCHAR c
)
1369 enum {Thaana_Norm
=0, Thaana_FILI
};
1382 case 0x7AF: return Thaana_FILI
;
1383 default: return Thaana_Norm
;
1387 static void ContextualShape_Thaana(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1391 if (*pcGlyphs
!= cChars
)
1393 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1397 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1402 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Thaana
);
1406 * ContextualShape_Phags_pa
1409 #define phags_pa_CANDRABINDU 0xA873
1410 #define phags_pa_START 0xA840
1411 #define phags_pa_END 0xA87F
1413 static void ContextualShape_Phags_pa(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1419 if (*pcGlyphs
!= cChars
)
1421 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1425 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1436 load_ot_tables(hdc
, psc
);
1438 if (!psc
->GSUB_Table
)
1441 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1443 for (i
= 0; i
< cChars
; i
++)
1445 if (pwcChars
[i
] >= phags_pa_START
&& pwcChars
[i
] <= phags_pa_END
)
1447 WCHAR rchar
= neighbour_char(i
,dirR
,pwcChars
,cChars
);
1448 WCHAR lchar
= neighbour_char(i
,dirL
,pwcChars
,cChars
);
1449 BOOL jrchar
= (rchar
!= phags_pa_CANDRABINDU
&& rchar
>= phags_pa_START
&& rchar
<= phags_pa_END
);
1450 BOOL jlchar
= (lchar
!= phags_pa_CANDRABINDU
&& lchar
>= phags_pa_START
&& lchar
<= phags_pa_END
);
1452 if (jrchar
&& jlchar
)
1453 context_shape
[i
] = Xm
;
1455 context_shape
[i
] = Xr
;
1457 context_shape
[i
] = Xl
;
1459 context_shape
[i
] = Xn
;
1462 context_shape
[i
] = -1;
1465 /* Contextual Shaping */
1467 while(i
< *pcGlyphs
)
1469 if (context_shape
[i
] >= 0)
1472 INT prevCount
= *pcGlyphs
;
1473 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1474 if (nextIndex
> GSUB_E_NOGLYPH
)
1476 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1486 HeapFree(GetProcessHeap(),0,context_shape
);
1489 static int combining_lexical_Thai(WCHAR c
)
1491 enum {Thai_Norm
=0, Thai_ABOVE1
, Thai_ABOVE2
, Thai_ABOVE3
, Thai_ABOVE4
, Thai_BELOW1
, Thai_BELOW2
, Thai_AM
};
1499 case 0xE37: return Thai_ABOVE1
;
1501 case 0xE4D: return Thai_ABOVE2
;
1505 case 0xE4B: return Thai_ABOVE3
;
1507 case 0xE4E: return Thai_ABOVE4
;
1509 case 0xE39: return Thai_BELOW1
;
1510 case 0xE3A: return Thai_BELOW2
;
1511 case 0xE33: return Thai_AM
;
1512 default: return Thai_Norm
;
1516 static void ContextualShape_Thai(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1520 if (*pcGlyphs
!= cChars
)
1522 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1526 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1531 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Thai
);
1534 static int combining_lexical_Lao(WCHAR c
)
1536 enum {Lao_Norm
=0, Lao_ABOVE1
, Lao_ABOVE2
, Lao_BELOW1
, Lao_BELOW2
, Lao_AM
};
1546 case 0xECD: return Lao_ABOVE1
;
1551 case 0xECC: return Lao_ABOVE2
;
1552 case 0xEBC: return Lao_BELOW1
;
1554 case 0xEB9: return Lao_BELOW2
;
1555 case 0xEB3: return Lao_AM
;
1556 default: return Lao_Norm
;
1560 static void ContextualShape_Lao(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1564 if (*pcGlyphs
!= cChars
)
1566 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1570 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1575 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Lao
);
1578 static void ReplaceInsertChars(HDC hdc
, INT cWalk
, INT
* pcChars
, WCHAR
*pwOutChars
, const WCHAR
*replacements
)
1583 pwOutChars
[cWalk
] = replacements
[0];
1587 for (i
= 1; replacements
[i
] != 0x0000 && i
< 3; i
++)
1590 for (j
= *pcChars
; j
> cWalk
; j
--)
1591 pwOutChars
[j
] = pwOutChars
[j
-1];
1592 *pcChars
= *pcChars
+1;
1593 pwOutChars
[cWalk
] = replacements
[i
];
1598 static void DecomposeVowels(HDC hdc
, WCHAR
*pwOutChars
, INT
*pcChars
, const VowelComponents vowels
[], WORD
* pwLogClust
, INT cChars
)
1603 for (cWalk
= 0; cWalk
< *pcChars
; cWalk
++)
1605 for (i
= 0; vowels
[i
].base
!= 0x0; i
++)
1607 if (pwOutChars
[cWalk
] == vowels
[i
].base
)
1610 ReplaceInsertChars(hdc
, cWalk
, pcChars
, pwOutChars
, vowels
[i
].parts
);
1611 if (vowels
[i
].parts
[1]) { cWalk
++; o
++; }
1612 if (vowels
[i
].parts
[2]) { cWalk
++; o
++; }
1613 UpdateClusters(cWalk
, o
, 1, cChars
, pwLogClust
);
1620 static void ComposeConsonants(HDC hdc
, WCHAR
*pwOutChars
, INT
*pcChars
, const ConsonantComponents consonants
[], WORD
* pwLogClust
)
1626 for (cWalk
= 0; cWalk
< *pcChars
; cWalk
++)
1628 for (i
= 0; consonants
[i
].output
!= 0x0; i
++)
1631 for (j
= 0; j
+ cWalk
< *pcChars
&& consonants
[i
].parts
[j
]!=0x0; j
++)
1632 if (pwOutChars
[cWalk
+j
] != consonants
[i
].parts
[j
])
1635 if (consonants
[i
].parts
[j
]==0x0) /* matched all */
1639 pwOutChars
[cWalk
] = consonants
[i
].output
;
1640 for(k
= cWalk
+1; k
< *pcChars
- j
; k
++)
1641 pwOutChars
[k
] = pwOutChars
[k
+j
];
1642 *pcChars
= *pcChars
- j
;
1643 for (k
= j
; k
> 0; k
--)
1644 pwLogClust
[cWalk
+ k
+ offset
] = pwLogClust
[cWalk
+ offset
];
1646 for (k
= cWalk
+ j
+ offset
; k
< *pcChars
+ offset
; k
++)
1655 static void Reorder_Ra_follows_base(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1660 WORD Ra
= pwChar
[s
->start
];
1661 WORD H
= pwChar
[s
->start
+1];
1663 TRACE("Doing reorder of Ra to %i\n",s
->base
);
1664 for (j
= s
->start
; j
< s
->base
-1; j
++)
1665 pwChar
[j
] = pwChar
[j
+2];
1666 pwChar
[s
->base
-1] = Ra
;
1667 pwChar
[s
->base
] = H
;
1669 s
->ralf
= s
->base
-1;
1674 static void Reorder_Ra_follows_matra(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1679 int stop
= (s
->blwf
>=0)? s
->blwf
+1 : s
->base
;
1680 WORD Ra
= pwChar
[s
->start
];
1681 WORD H
= pwChar
[s
->start
+1];
1682 for (loc
= s
->end
; loc
> stop
; loc
--)
1683 if (lexical(pwChar
[loc
]) == lex_Matra_post
|| lexical(pwChar
[loc
]) == lex_Matra_below
)
1686 TRACE("Doing reorder of Ra to %i\n",loc
);
1687 for (j
= s
->start
; j
< loc
-1; j
++)
1688 pwChar
[j
] = pwChar
[j
+2];
1694 if (s
->blwf
>= 0) s
->blwf
-= 2;
1695 if (s
->pref
>= 0) s
->pref
-= 2;
1699 static void Reorder_Ra_follows_syllable(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1704 WORD Ra
= pwChar
[s
->start
];
1705 WORD H
= pwChar
[s
->start
+1];
1707 TRACE("Doing reorder of Ra to %i\n",s
->end
-1);
1708 for (j
= s
->start
; j
< s
->end
-1; j
++)
1709 pwChar
[j
] = pwChar
[j
+2];
1710 pwChar
[s
->end
-1] = Ra
;
1715 if (s
->blwf
>= 0) s
->blwf
-= 2;
1716 if (s
->pref
>= 0) s
->pref
-= 2;
1720 static void Reorder_Matra_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1724 /* reorder Matras */
1725 if (s
->end
> s
->base
)
1727 for (i
= 1; i
<= s
->end
-s
->base
; i
++)
1729 if (lexical(pwChar
[s
->base
+i
]) == lex_Matra_pre
)
1732 WCHAR c
= pwChar
[s
->base
+i
];
1733 TRACE("Doing reorder of %x %x\n",c
,pwChar
[s
->base
]);
1734 for (j
= s
->base
+i
; j
> s
->base
; j
--)
1735 pwChar
[j
] = pwChar
[j
-1];
1736 pwChar
[s
->base
] = c
;
1738 if (s
->ralf
>= s
->base
) s
->ralf
++;
1739 if (s
->blwf
>= s
->base
) s
->blwf
++;
1740 if (s
->pref
>= s
->base
) s
->pref
++;
1747 static void Reorder_Matra_precede_syllable(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1751 /* reorder Matras */
1752 if (s
->end
> s
->base
)
1754 for (i
= 1; i
<= s
->end
-s
->base
; i
++)
1756 if (lexical(pwChar
[s
->base
+i
]) == lex_Matra_pre
)
1759 WCHAR c
= pwChar
[s
->base
+i
];
1760 TRACE("Doing reorder of %x to %i\n",c
,s
->start
);
1761 for (j
= s
->base
+i
; j
> s
->start
; j
--)
1762 pwChar
[j
] = pwChar
[j
-1];
1763 pwChar
[s
->start
] = c
;
1765 if (s
->ralf
>= 0) s
->ralf
++;
1766 if (s
->blwf
>= 0) s
->blwf
++;
1767 if (s
->pref
>= 0) s
->pref
++;
1774 static void SecondReorder_Blwf_follows_matra(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1776 if (s
->blwf
>= 0 && g
->blwf
> g
->base
)
1780 for (loc
= s
->end
; loc
> s
->blwf
; loc
--)
1781 if (lexical(pwChar
[loc
]) == lex_Matra_below
|| lexical(pwChar
[loc
]) == lex_Matra_above
|| lexical(pwChar
[loc
]) == lex_Matra_post
)
1784 g_offset
= (loc
- s
->blwf
) - 1;
1788 WORD blwf
= glyphs
[g
->blwf
];
1789 TRACE("Doing reorder of Below-base to %i (glyph offset %i)\n",loc
,g_offset
);
1790 /* do not care about the pwChar array anymore, just the glyphs */
1791 for (j
= 0; j
< g_offset
; j
++)
1792 glyphs
[g
->blwf
+ j
] = glyphs
[g
->blwf
+ j
+ 1];
1793 glyphs
[g
->blwf
+ g_offset
] = blwf
;
1798 static void SecondReorder_Matra_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1802 /* reorder previously moved Matras to correct position*/
1803 for (i
= s
->start
; i
< s
->base
; i
++)
1805 if (lexical(pwChar
[i
]) == lex_Matra_pre
)
1808 int g_start
= g
->start
+ i
- s
->start
;
1809 if (g_start
< g
->base
-1 )
1811 WCHAR og
= glyphs
[g_start
];
1812 TRACE("Doing reorder of matra from %i to %i\n",g_start
,g
->base
);
1813 for (j
= g_start
; j
< g
->base
-1; j
++)
1814 glyphs
[j
] = glyphs
[j
+1];
1815 glyphs
[g
->base
-1] = og
;
1821 static void SecondReorder_Pref_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1823 if (s
->pref
>= 0 && g
->pref
> g
->base
)
1826 WCHAR og
= glyphs
[g
->pref
];
1827 TRACE("Doing reorder of pref from %i to %i\n",g
->pref
,g
->base
);
1828 for (j
= g
->pref
; j
> g
->base
; j
--)
1829 glyphs
[j
] = glyphs
[j
-1];
1830 glyphs
[g
->base
] = og
;
1834 static void Reorder_Like_Sinhala(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1836 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1837 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1838 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1840 Reorder_Ra_follows_base(pwChar
, s
, lexical
);
1841 Reorder_Matra_precede_base(pwChar
, s
, lexical
);
1844 static void Reorder_Like_Devanagari(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1846 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1847 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1848 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1850 Reorder_Ra_follows_matra(pwChar
, s
, lexical
);
1851 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1854 static void Reorder_Like_Bengali(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1856 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1857 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1858 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1860 Reorder_Ra_follows_base(pwChar
, s
, lexical
);
1861 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1864 static void Reorder_Like_Kannada(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1866 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1867 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1868 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1870 Reorder_Ra_follows_syllable(pwChar
, s
, lexical
);
1871 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1874 static void SecondReorder_Like_Telugu(LPWSTR pwChar
, IndicSyllable
*s
, WORD
* pwGlyphs
, IndicSyllable
*g
, lexical_function lexical
)
1876 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1877 TRACE("Glyphs (%i..%i..%i)\n",g
->start
,g
->base
,g
->end
);
1878 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1879 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1881 SecondReorder_Blwf_follows_matra(pwChar
, s
, pwGlyphs
, g
, lexical
);
1884 static void SecondReorder_Like_Tamil(LPWSTR pwChar
, IndicSyllable
*s
, WORD
* pwGlyphs
, IndicSyllable
*g
, lexical_function lexical
)
1886 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1887 TRACE("Glyphs (%i..%i..%i)\n",g
->start
,g
->base
,g
->end
);
1888 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1889 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1891 SecondReorder_Matra_precede_base(pwChar
, s
, pwGlyphs
, g
, lexical
);
1892 SecondReorder_Pref_precede_base(pwChar
, s
, pwGlyphs
, g
, lexical
);
1896 static inline void shift_syllable_glyph_indexs(IndicSyllable
*glyph_index
, INT index
, INT shift
)
1901 if (glyph_index
->start
> index
)
1902 glyph_index
->start
+= shift
;
1903 if (glyph_index
->base
> index
)
1904 glyph_index
->base
+= shift
;
1905 if (glyph_index
->end
> index
)
1906 glyph_index
->end
+= shift
;
1907 if (glyph_index
->ralf
> index
)
1908 glyph_index
->ralf
+= shift
;
1909 if (glyph_index
->blwf
> index
)
1910 glyph_index
->blwf
+= shift
;
1911 if (glyph_index
->pref
> index
)
1912 glyph_index
->pref
+= shift
;
1915 static void Apply_Indic_BasicForm(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwChars
, INT cChars
, IndicSyllable
*syllable
, WORD
*pwOutGlyphs
, INT
* pcGlyphs
, WORD
*pwLogClust
, lexical_function lexical
, IndicSyllable
*glyph_index
, LoadedFeature
*feature
)
1917 int index
= glyph_index
->start
;
1922 while(index
<= glyph_index
->end
)
1925 INT prevCount
= *pcGlyphs
;
1926 nextIndex
= GSUB_apply_feature_all_lookups(psc
->GSUB_Table
, feature
, pwOutGlyphs
, index
, 1, pcGlyphs
);
1927 if (nextIndex
> GSUB_E_NOGLYPH
)
1929 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1930 shift_syllable_glyph_indexs(glyph_index
,index
,*pcGlyphs
- prevCount
);
1938 static inline INT
find_consonant_halant(WCHAR
* pwChars
, INT index
, INT end
, lexical_function lexical
)
1941 while (i
+ index
< end
- 1 && !(is_consonant(lexical(pwChars
[index
+i
])) && (lexical(pwChars
[index
+i
+1]) == lex_Halant
|| (index
+ i
< end
- 2 && lexical(pwChars
[index
+i
+1]) == lex_Nukta
&& lexical(pwChars
[index
+i
+2] == lex_Halant
)))))
1943 if (index
+ i
<= end
-1)
1949 static void Apply_Indic_PreBase(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwChars
, INT cChars
, IndicSyllable
*syllable
, WORD
*pwOutGlyphs
, INT
* pcGlyphs
, WORD
*pwLogClust
, lexical_function lexical
, IndicSyllable
*glyph_index
, const char* feature
)
1951 INT index
, nextIndex
;
1954 count
= syllable
->base
- syllable
->start
;
1957 index
= find_consonant_halant(&pwChars
[syllable
->start
], 0, count
, lexical
);
1958 while (index
>= 0 && index
+ g_offset
< (glyph_index
->base
- glyph_index
->start
))
1960 INT prevCount
= *pcGlyphs
;
1961 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, index
+glyph_index
->start
+g_offset
, 1, pcGlyphs
, feature
);
1962 if (nextIndex
> GSUB_E_NOGLYPH
)
1964 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1965 shift_syllable_glyph_indexs(glyph_index
, index
+ glyph_index
->start
+ g_offset
, (*pcGlyphs
- prevCount
));
1966 g_offset
+= (*pcGlyphs
- prevCount
);
1970 index
= find_consonant_halant(&pwChars
[syllable
->start
], index
, count
, lexical
);
1974 static void Apply_Indic_Rphf(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwChars
, INT cChars
, IndicSyllable
*syllable
, WORD
*pwOutGlyphs
, INT
* pcGlyphs
, WORD
*pwLogClust
, lexical_function lexical
, IndicSyllable
*glyph_index
)
1977 INT prevCount
= *pcGlyphs
;
1979 if (syllable
->ralf
>= 0)
1981 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, glyph_index
->ralf
, 1, pcGlyphs
, "rphf");
1982 if (nextIndex
> GSUB_E_NOGLYPH
)
1984 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1985 shift_syllable_glyph_indexs(glyph_index
,glyph_index
->ralf
,*pcGlyphs
- prevCount
);
1990 static inline INT
find_halant_consonant(WCHAR
* pwChars
, INT index
, INT end
, lexical_function lexical
)
1993 while (index
+ i
< end
-1 && !(lexical(pwChars
[index
+i
]) == lex_Halant
&&
1994 ((index
+ i
< end
-2 && lexical(pwChars
[index
+i
]) == lex_Nukta
&& is_consonant(lexical(pwChars
[index
+i
+1]))) ||
1995 is_consonant(lexical(pwChars
[index
+i
+1])))))
1997 if (index
+ i
<= end
-1)
2003 static void Apply_Indic_PostBase(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwChars
, INT cChars
, IndicSyllable
*syllable
, WORD
*pwOutGlyphs
, INT
* pcGlyphs
, WORD
*pwLogClust
, lexical_function lexical
, IndicSyllable
*glyph_index
, BOOL modern
, const char* feat
)
2005 INT index
, nextIndex
;
2006 INT count
, g_offset
=0;
2007 INT ralf
= syllable
->ralf
;
2009 count
= syllable
->end
- syllable
->base
;
2011 index
= find_halant_consonant(&pwChars
[syllable
->base
], 0, count
, lexical
);
2015 INT prevCount
= *pcGlyphs
;
2016 if (ralf
>=0 && ralf
< index
)
2024 WORD g
= pwOutGlyphs
[index
+glyph_index
->base
+g_offset
];
2025 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
] = pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1];
2026 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1] = g
;
2029 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, index
+glyph_index
->base
+g_offset
, 1, pcGlyphs
, feat
);
2030 if (nextIndex
> GSUB_E_NOGLYPH
)
2032 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
2033 shift_syllable_glyph_indexs(glyph_index
,index
+glyph_index
->start
+g_offset
, (*pcGlyphs
- prevCount
));
2034 g_offset
+= (*pcGlyphs
- prevCount
);
2038 WORD g
= pwOutGlyphs
[index
+glyph_index
->base
+g_offset
];
2039 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
] = pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1];
2040 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1] = g
;
2044 index
= find_halant_consonant(&pwChars
[syllable
->base
], index
, count
, lexical
);
2048 static void ShapeIndicSyllables(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwChars
, INT cChars
, IndicSyllable
*syllables
, INT syllable_count
, WORD
*pwOutGlyphs
, INT
* pcGlyphs
, WORD
*pwLogClust
, lexical_function lexical
, second_reorder_function second_reorder
, BOOL modern
)
2051 int overall_shift
= 0;
2052 LoadedFeature
*locl
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "locl"):NULL
;
2053 LoadedFeature
*nukt
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "nukt");
2054 LoadedFeature
*akhn
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "akhn");
2055 LoadedFeature
*rkrf
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "rkrf"):NULL
;
2056 LoadedFeature
*pstf
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "pstf");
2057 LoadedFeature
*vatu
= (!rkrf
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "vatu"):NULL
;
2058 LoadedFeature
*cjct
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "cjct"):NULL
;
2059 BOOL rphf
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "rphf") != NULL
);
2060 BOOL pref
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "pref") != NULL
);
2061 BOOL blwf
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "blwf") != NULL
);
2062 BOOL half
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "half") != NULL
);
2063 IndicSyllable glyph_indexs
;
2065 for (c
= 0; c
< syllable_count
; c
++)
2068 memcpy(&glyph_indexs
, &syllables
[c
], sizeof(IndicSyllable
));
2069 shift_syllable_glyph_indexs(&glyph_indexs
, -1, overall_shift
);
2070 old_end
= glyph_indexs
.end
;
2074 TRACE("applying feature locl\n");
2075 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, locl
);
2079 TRACE("applying feature nukt\n");
2080 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, nukt
);
2084 TRACE("applying feature akhn\n");
2085 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, akhn
);
2089 Apply_Indic_Rphf(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
);
2092 TRACE("applying feature rkrf\n");
2093 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, rkrf
);
2096 Apply_Indic_PostBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, modern
, "pref");
2100 Apply_Indic_PreBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, "blwf");
2102 Apply_Indic_PostBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, modern
, "blwf");
2106 Apply_Indic_PreBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, "half");
2109 TRACE("applying feature pstf\n");
2110 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, pstf
);
2114 TRACE("applying feature vatu\n");
2115 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, vatu
);
2119 TRACE("applying feature cjct\n");
2120 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, cjct
);
2124 second_reorder(pwChars
, &syllables
[c
], pwOutGlyphs
, &glyph_indexs
, lexical
);
2126 overall_shift
+= glyph_indexs
.end
- old_end
;
2130 static inline int unicode_lex(WCHAR c
)
2134 if (!c
) return lex_Generic
;
2135 if (c
== 0x200D) return lex_ZWJ
;
2136 if (c
== 0x200C) return lex_ZWNJ
;
2137 if (c
== 0x00A0) return lex_NBSP
;
2139 type
= get_table_entry( indic_syllabic_table
, c
);
2141 if ((type
& 0x00ff) != 0x0007) type
= type
& 0x00ff;
2145 case 0x0d07: /* Unknown */
2146 case 0x0e07: /* Unknwon */
2147 default: return lex_Generic
;
2153 case 0x0014: return lex_Modifier
;
2161 case 0x0010: return lex_Consonant
;
2162 case 0x0004: return lex_Nukta
;
2163 case 0x0005: return lex_Halant
;
2165 case 0x0008: return lex_Vowel
;
2167 case 0x0107: return lex_Matra_post
;
2169 case 0x0307: return lex_Matra_pre
;
2175 case 0x0407: return lex_Composed_Vowel
;
2176 case 0x0507: return lex_Matra_above
;
2177 case 0x0607: return lex_Matra_below
;
2179 case 0x0015: return lex_Ra
;
2183 static int sinhala_lex(WCHAR c
)
2190 case 0x0DDE: return lex_Matra_post
;
2192 return unicode_lex(c
);
2196 static const VowelComponents Sinhala_vowels
[] = {
2197 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2198 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2199 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2200 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2201 {0x0000, {0x0000,0x0000,0x0}}};
2203 static void ContextualShape_Sinhala(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2205 int cCount
= cChars
;
2208 IndicSyllable
*syllables
= NULL
;
2209 int syllable_count
= 0;
2211 if (*pcGlyphs
!= cChars
)
2213 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2217 input
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
) * (cChars
* 3));
2219 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2221 /* Step 1: Decompose multi part vowels */
2222 DecomposeVowels(hdc
, input
, &cCount
, Sinhala_vowels
, pwLogClust
, cChars
);
2224 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2226 /* Step 2: Reorder within Syllables */
2227 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, sinhala_lex
, Reorder_Like_Sinhala
, TRUE
);
2228 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2230 /* Step 3: Strip dangling joiners */
2231 for (i
= 0; i
< cCount
; i
++)
2233 if ((input
[i
] == 0x200D || input
[i
] == 0x200C) &&
2234 (i
== 0 || input
[i
-1] == 0x0020 || i
== cCount
-1 || input
[i
+1] == 0x0020))
2238 /* Step 4: Base Form application to syllables */
2239 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2241 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, sinhala_lex
, NULL
, TRUE
);
2243 HeapFree(GetProcessHeap(),0,input
);
2244 HeapFree(GetProcessHeap(),0,syllables
);
2247 static int devanagari_lex(WCHAR c
)
2251 case 0x0930: return lex_Ra
;
2253 return unicode_lex(c
);
2257 static const ConsonantComponents Devanagari_consonants
[] ={
2258 {{0x0928, 0x093C, 0x00000}, 0x0929},
2259 {{0x0930, 0x093C, 0x00000}, 0x0931},
2260 {{0x0933, 0x093C, 0x00000}, 0x0934},
2261 {{0x0915, 0x093C, 0x00000}, 0x0958},
2262 {{0x0916, 0x093C, 0x00000}, 0x0959},
2263 {{0x0917, 0x093C, 0x00000}, 0x095A},
2264 {{0x091C, 0x093C, 0x00000}, 0x095B},
2265 {{0x0921, 0x093C, 0x00000}, 0x095C},
2266 {{0x0922, 0x093C, 0x00000}, 0x095D},
2267 {{0x092B, 0x093C, 0x00000}, 0x095E},
2268 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2270 static void ContextualShape_Devanagari(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2272 int cCount
= cChars
;
2274 IndicSyllable
*syllables
= NULL
;
2275 int syllable_count
= 0;
2276 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2278 if (*pcGlyphs
!= cChars
)
2280 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2284 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2285 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2287 /* Step 1: Compose Consonant and Nukta */
2288 ComposeConsonants(hdc
, input
, &cCount
, Devanagari_consonants
, pwLogClust
);
2289 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2291 /* Step 2: Reorder within Syllables */
2292 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, devanagari_lex
, Reorder_Like_Devanagari
, modern
);
2293 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2294 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2297 /* Step 3: Base Form application to syllables */
2298 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, devanagari_lex
, NULL
, modern
);
2300 HeapFree(GetProcessHeap(),0,input
);
2301 HeapFree(GetProcessHeap(),0,syllables
);
2304 static int bengali_lex(WCHAR c
)
2308 case 0x09B0: return lex_Ra
;
2310 return unicode_lex(c
);
2314 static const VowelComponents Bengali_vowels
[] = {
2315 {0x09CB, {0x09C7,0x09BE,0x0000}},
2316 {0x09CC, {0x09C7,0x09D7,0x0000}},
2317 {0x0000, {0x0000,0x0000,0x0000}}};
2319 static const ConsonantComponents Bengali_consonants
[] = {
2320 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2321 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2322 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2323 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2324 {{0x0000,0x0000,0x0000}, 0x0000}};
2326 static void ContextualShape_Bengali(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2328 int cCount
= cChars
;
2330 IndicSyllable
*syllables
= NULL
;
2331 int syllable_count
= 0;
2332 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2334 if (*pcGlyphs
!= cChars
)
2336 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2340 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
* 2) * sizeof(WCHAR
));
2341 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2343 /* Step 1: Decompose Vowels and Compose Consonants */
2344 DecomposeVowels(hdc
, input
, &cCount
, Bengali_vowels
, pwLogClust
, cChars
);
2345 ComposeConsonants(hdc
, input
, &cCount
, Bengali_consonants
, pwLogClust
);
2346 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2348 /* Step 2: Reorder within Syllables */
2349 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, bengali_lex
, Reorder_Like_Bengali
, modern
);
2350 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2351 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2354 /* Step 3: Initial form is only applied to the beginning of words */
2355 for (cCount
= cCount
- 1 ; cCount
>= 0; cCount
--)
2357 if (cCount
== 0 || input
[cCount
] == 0x0020) /* space */
2361 if (index
> 0) index
++;
2363 apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, &pwOutGlyphs
[index
], 0, 1, &gCount
, "init");
2367 /* Step 4: Base Form application to syllables */
2368 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, bengali_lex
, NULL
, modern
);
2370 HeapFree(GetProcessHeap(),0,input
);
2371 HeapFree(GetProcessHeap(),0,syllables
);
2374 static int gurmukhi_lex(WCHAR c
)
2377 return lex_Modifier
;
2379 return unicode_lex(c
);
2382 static const ConsonantComponents Gurmukhi_consonants
[] = {
2383 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2384 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2385 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2386 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2387 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2388 {{0x0000,0x0000,0x0000}, 0x0000}};
2390 static void ContextualShape_Gurmukhi(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2392 int cCount
= cChars
;
2394 IndicSyllable
*syllables
= NULL
;
2395 int syllable_count
= 0;
2396 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2398 if (*pcGlyphs
!= cChars
)
2400 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2404 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2405 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2407 /* Step 1: Compose Consonants */
2408 ComposeConsonants(hdc
, input
, &cCount
, Gurmukhi_consonants
, pwLogClust
);
2409 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2411 /* Step 2: Reorder within Syllables */
2412 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, gurmukhi_lex
, Reorder_Like_Bengali
, modern
);
2413 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2414 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2417 /* Step 3: Base Form application to syllables */
2418 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, gurmukhi_lex
, NULL
, modern
);
2420 HeapFree(GetProcessHeap(),0,input
);
2421 HeapFree(GetProcessHeap(),0,syllables
);
2424 static int gujarati_lex(WCHAR c
)
2428 case 0x0AB0: return lex_Ra
;
2430 return unicode_lex(c
);
2434 static void ContextualShape_Gujarati(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2436 int cCount
= cChars
;
2438 IndicSyllable
*syllables
= NULL
;
2439 int syllable_count
= 0;
2440 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2442 if (*pcGlyphs
!= cChars
)
2444 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2448 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2449 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2451 /* Step 1: Reorder within Syllables */
2452 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, gujarati_lex
, Reorder_Like_Devanagari
, modern
);
2453 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2454 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2457 /* Step 2: Base Form application to syllables */
2458 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, gujarati_lex
, NULL
, modern
);
2460 HeapFree(GetProcessHeap(),0,input
);
2461 HeapFree(GetProcessHeap(),0,syllables
);
2464 static int oriya_lex(WCHAR c
)
2468 case 0x0B30: return lex_Ra
;
2470 return unicode_lex(c
);
2474 static const VowelComponents Oriya_vowels
[] = {
2475 {0x0B48, {0x0B47,0x0B56,0x0000}},
2476 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2477 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2478 {0x0000, {0x0000,0x0000,0x0000}}};
2480 static const ConsonantComponents Oriya_consonants
[] = {
2481 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2482 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2483 {{0x0000,0x0000,0x0000}, 0x0000}};
2485 static void ContextualShape_Oriya(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2487 int cCount
= cChars
;
2489 IndicSyllable
*syllables
= NULL
;
2490 int syllable_count
= 0;
2491 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2493 if (*pcGlyphs
!= cChars
)
2495 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2499 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2500 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2502 /* Step 1: Decompose Vowels and Compose Consonants */
2503 DecomposeVowels(hdc
, input
, &cCount
, Oriya_vowels
, pwLogClust
, cChars
);
2504 ComposeConsonants(hdc
, input
, &cCount
, Oriya_consonants
, pwLogClust
);
2505 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2507 /* Step 2: Reorder within Syllables */
2508 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, oriya_lex
, Reorder_Like_Bengali
, modern
);
2509 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2510 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2513 /* Step 3: Base Form application to syllables */
2514 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, oriya_lex
, NULL
, modern
);
2516 HeapFree(GetProcessHeap(),0,input
);
2517 HeapFree(GetProcessHeap(),0,syllables
);
2520 static int tamil_lex(WCHAR c
)
2522 return unicode_lex(c
);
2525 static const VowelComponents Tamil_vowels
[] = {
2526 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2527 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2528 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2529 {0x0000, {0x0000,0x0000,0x0000}}};
2531 static const ConsonantComponents Tamil_consonants
[] = {
2532 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2533 {{0x0000,0x0000,0x0000}, 0x0000}};
2535 static void ContextualShape_Tamil(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2537 int cCount
= cChars
;
2539 IndicSyllable
*syllables
= NULL
;
2540 int syllable_count
= 0;
2541 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2543 if (*pcGlyphs
!= cChars
)
2545 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2549 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2550 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2552 /* Step 1: Decompose Vowels and Compose Consonants */
2553 DecomposeVowels(hdc
, input
, &cCount
, Tamil_vowels
, pwLogClust
, cChars
);
2554 ComposeConsonants(hdc
, input
, &cCount
, Tamil_consonants
, pwLogClust
);
2555 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2557 /* Step 2: Reorder within Syllables */
2558 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, tamil_lex
, Reorder_Like_Bengali
, modern
);
2559 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2560 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2563 /* Step 3: Base Form application to syllables */
2564 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, tamil_lex
, SecondReorder_Like_Tamil
, modern
);
2566 HeapFree(GetProcessHeap(),0,input
);
2567 HeapFree(GetProcessHeap(),0,syllables
);
2570 static int telugu_lex(WCHAR c
)
2575 case 0x0C44: return lex_Modifier
;
2577 return unicode_lex(c
);
2581 static const VowelComponents Telugu_vowels
[] = {
2582 {0x0C48, {0x0C46,0x0C56,0x0000}},
2583 {0x0000, {0x0000,0x0000,0x0000}}};
2585 static void ContextualShape_Telugu(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2587 int cCount
= cChars
;
2589 IndicSyllable
*syllables
= NULL
;
2590 int syllable_count
= 0;
2591 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2593 if (*pcGlyphs
!= cChars
)
2595 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2599 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2600 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2602 /* Step 1: Decompose Vowels */
2603 DecomposeVowels(hdc
, input
, &cCount
, Telugu_vowels
, pwLogClust
, cChars
);
2604 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2606 /* Step 2: Reorder within Syllables */
2607 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, telugu_lex
, Reorder_Like_Bengali
, modern
);
2608 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2609 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2612 /* Step 3: Base Form application to syllables */
2613 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, telugu_lex
, SecondReorder_Like_Telugu
, modern
);
2615 HeapFree(GetProcessHeap(),0,input
);
2616 HeapFree(GetProcessHeap(),0,syllables
);
2619 static int kannada_lex(WCHAR c
)
2623 case 0x0CB0: return lex_Ra
;
2625 return unicode_lex(c
);
2629 static const VowelComponents Kannada_vowels
[] = {
2630 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2631 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2632 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2633 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2634 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2635 {0x0000, {0x0000,0x0000,0x0000}}};
2637 static void ContextualShape_Kannada(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2639 int cCount
= cChars
;
2641 IndicSyllable
*syllables
= NULL
;
2642 int syllable_count
= 0;
2643 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2645 if (*pcGlyphs
!= cChars
)
2647 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2651 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*3) * sizeof(WCHAR
));
2652 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2654 /* Step 1: Decompose Vowels */
2655 DecomposeVowels(hdc
, input
, &cCount
, Kannada_vowels
, pwLogClust
, cChars
);
2656 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2658 /* Step 2: Reorder within Syllables */
2659 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, kannada_lex
, Reorder_Like_Kannada
, modern
);
2660 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2661 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2664 /* Step 3: Base Form application to syllables */
2665 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, kannada_lex
, SecondReorder_Like_Telugu
, modern
);
2667 HeapFree(GetProcessHeap(),0,input
);
2668 HeapFree(GetProcessHeap(),0,syllables
);
2671 static int malayalam_lex(WCHAR c
)
2673 return unicode_lex(c
);
2676 static const VowelComponents Malayalam_vowels
[] = {
2677 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2678 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2679 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2680 {0x0000, {0x0000,0x0000,0x0000}}};
2682 static void ContextualShape_Malayalam(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2684 int cCount
= cChars
;
2686 IndicSyllable
*syllables
= NULL
;
2687 int syllable_count
= 0;
2688 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2690 if (*pcGlyphs
!= cChars
)
2692 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2696 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2697 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2699 /* Step 1: Decompose Vowels */
2700 DecomposeVowels(hdc
, input
, &cCount
, Malayalam_vowels
, pwLogClust
, cChars
);
2701 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2703 /* Step 2: Reorder within Syllables */
2704 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, malayalam_lex
, Reorder_Like_Devanagari
, modern
);
2705 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2706 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2709 /* Step 3: Base Form application to syllables */
2710 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, malayalam_lex
, SecondReorder_Like_Tamil
, modern
);
2712 HeapFree(GetProcessHeap(),0,input
);
2713 HeapFree(GetProcessHeap(),0,syllables
);
2716 static int khmer_lex(WCHAR c
)
2718 return unicode_lex(c
);
2721 static void ContextualShape_Khmer(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2723 int cCount
= cChars
;
2725 IndicSyllable
*syllables
= NULL
;
2726 int syllable_count
= 0;
2728 if (*pcGlyphs
!= cChars
)
2730 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2734 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2735 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2737 /* Step 1: Reorder within Syllables */
2738 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, khmer_lex
, Reorder_Like_Devanagari
, FALSE
);
2739 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2740 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2743 /* Step 2: Base Form application to syllables */
2744 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, khmer_lex
, NULL
, FALSE
);
2746 HeapFree(GetProcessHeap(),0,input
);
2747 HeapFree(GetProcessHeap(),0,syllables
);
2750 static inline BOOL
mongolian_wordbreak(WCHAR chr
)
2752 return ((chr
== 0x0020) || (chr
== 0x200C) || (chr
== 0x202F) || (chr
== 0x180E) || (chr
== 0x1800) || (chr
== 0x1802) || (chr
== 0x1803) || (chr
== 0x1805) || (chr
== 0x1808) || (chr
== 0x1809) || (chr
== 0x1807));
2755 static void ContextualShape_Mongolian(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2761 if (*pcGlyphs
!= cChars
)
2763 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2767 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
2772 if (!psc
->GSUB_Table
)
2775 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
2777 for (i
= 0; i
< cChars
; i
++)
2779 if (i
== 0 || mongolian_wordbreak(pwcChars
[i
-1]))
2781 if ((i
== cChars
-1) || mongolian_wordbreak(pwcChars
[i
+1]))
2782 context_shape
[i
] = Xn
;
2784 context_shape
[i
] = Xl
;
2788 if ((i
== cChars
-1) || mongolian_wordbreak(pwcChars
[i
+1]))
2789 context_shape
[i
] = Xr
;
2791 context_shape
[i
] = Xm
;
2795 /* Contextual Shaping */
2797 while(i
< *pcGlyphs
)
2800 INT prevCount
= *pcGlyphs
;
2801 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
2802 if (nextIndex
> GSUB_E_NOGLYPH
)
2804 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
2811 HeapFree(GetProcessHeap(),0,context_shape
);
2814 static void ShapeCharGlyphProp_Default( ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
)
2818 for (i
= 0; i
< cGlyphs
; i
++)
2823 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2826 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2827 char_index
[char_count
++] = k
;
2830 if (char_count
== 0)
2833 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
2835 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
2836 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
2839 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
2842 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
2843 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
2846 static void ShapeCharGlyphProp_Latin( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2850 ShapeCharGlyphProp_Default( psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
2852 for (i
= 0; i
< cGlyphs
; i
++)
2853 if (pGlyphProp
[i
].sva
.fZeroWidth
)
2854 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2857 static void ShapeCharGlyphProp_Control( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2860 for (i
= 0; i
< cGlyphs
; i
++)
2862 pGlyphProp
[i
].sva
.fClusterStart
= 1;
2863 pGlyphProp
[i
].sva
.fDiacritic
= 0;
2864 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
2866 if (pwGlyphs
[i
] == psc
->sfp
.wgDefault
)
2867 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
2869 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
2873 static void ShapeCharGlyphProp_Arabic( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2876 int initGlyph
, finaGlyph
;
2880 spaces
= HeapAlloc(GetProcessHeap(),0,cGlyphs
);
2881 memset(spaces
,0,cGlyphs
);
2883 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
2885 initGlyph
= cGlyphs
-1;
2893 finaGlyph
= cGlyphs
-1;
2898 for (i
= 0; i
< cGlyphs
; i
++)
2900 for (k
= 0; k
< cChars
; k
++)
2901 if (pwLogClust
[k
] == i
)
2903 if (pwcChars
[k
] == 0x0020)
2908 for (i
= 0; i
< cGlyphs
; i
++)
2912 BOOL isInit
, isFinal
;
2914 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2917 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2918 char_index
[char_count
++] = k
;
2921 isInit
= (i
== initGlyph
|| (i
+dirR
> 0 && i
+dirR
< cGlyphs
&& spaces
[i
+dirR
]));
2922 isFinal
= (i
== finaGlyph
|| (i
+dirL
> 0 && i
+dirL
< cGlyphs
&& spaces
[i
+dirL
]));
2924 if (char_count
== 0)
2927 if (char_count
== 1)
2929 if (pwcChars
[char_index
[0]] == 0x0020) /* space */
2931 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BLANK
;
2932 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
2934 else if (pwcChars
[char_index
[0]] == 0x0640) /* kashida */
2935 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_KASHIDA
;
2936 else if (pwcChars
[char_index
[0]] == 0x0633) /* SEEN */
2938 if (!isInit
&& !isFinal
)
2939 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_SEEN_M
;
2941 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_SEEN
;
2943 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2947 if (pwcChars
[char_index
[0]] == 0x0628 ) /* BA */
2948 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BA
;
2949 else if (pwcChars
[char_index
[0]] == 0x0631 ) /* RA */
2950 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_RA
;
2951 else if (pwcChars
[char_index
[0]] == 0x0647 ) /* HA */
2952 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_HA
;
2953 else if ((pwcChars
[char_index
[0]] == 0x0627 || pwcChars
[char_index
[0]] == 0x0625 || pwcChars
[char_index
[0]] == 0x0623 || pwcChars
[char_index
[0]] == 0x0622) ) /* alef-like */
2954 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_ALEF
;
2956 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2958 else if (!isInit
&& !isFinal
)
2959 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2961 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2963 else if (char_count
== 2)
2965 if ((pwcChars
[char_index
[0]] == 0x0628 && pwcChars
[char_index
[1]]== 0x0631) || (pwcChars
[char_index
[0]] == 0x0631 && pwcChars
[char_index
[1]]== 0x0628)) /* BA+RA */
2966 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BARA
;
2968 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2970 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2972 else if (!isInit
&& !isFinal
)
2973 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2975 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2978 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
2979 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
2980 HeapFree(GetProcessHeap(),0,spaces
);
2983 static void ShapeCharGlyphProp_Hebrew( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2987 for (i
= 0; i
< cGlyphs
; i
++)
2992 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2995 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2996 char_index
[char_count
++] = k
;
2999 if (char_count
== 0)
3000 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3003 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3004 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3005 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3009 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3010 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3013 static void ShapeCharGlyphProp_Thai( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3019 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
3026 finaGlyph
= cGlyphs
-1;
3030 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3032 for (i
= 0; i
< cGlyphs
; i
++)
3038 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3041 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3042 char_index
[char_count
++] = k
;
3046 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3048 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3050 if (char_count
== 0)
3053 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3054 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3056 /* handle Thai SARA AM (U+0E33) differently than GDEF */
3057 if (char_count
== 1 && pwcChars
[char_index
[0]] == 0x0e33)
3058 pGlyphProp
[i
].sva
.fClusterStart
= 0;
3061 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3063 /* Do not allow justification between marks and their base */
3064 for (i
= 0; i
< cGlyphs
; i
++)
3066 if (!pGlyphProp
[i
].sva
.fClusterStart
)
3067 pGlyphProp
[i
-dirL
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3071 static void ShapeCharGlyphProp_None( HDC hdc
, ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
)
3075 for (i
= 0; i
< cGlyphs
; i
++)
3080 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3083 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3084 char_index
[char_count
++] = k
;
3087 if (char_count
== 0)
3090 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3092 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3093 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3096 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3098 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3099 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3102 static void ShapeCharGlyphProp_Tibet( HDC hdc
, ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
)
3106 for (i
= 0; i
< cGlyphs
; i
++)
3111 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3114 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3115 char_index
[char_count
++] = k
;
3118 if (char_count
== 0)
3121 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3123 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
3124 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3127 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3129 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3130 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3132 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3133 for (i
= 0; i
< cGlyphs
; i
++)
3135 if (!pGlyphProp
[i
].sva
.fClusterStart
)
3137 pGlyphProp
[i
].sva
.fDiacritic
= 0;
3138 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
3143 static void ShapeCharGlyphProp_BaseIndic( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
, lexical_function lexical
, BOOL use_syllables
, BOOL override_gsub
)
3147 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3148 for (i
= 0; i
< cGlyphs
; i
++)
3153 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3156 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3157 char_index
[char_count
++] = k
;
3162 /* Most indic scripts do not set fDiacritic or fZeroWidth */
3163 pGlyphProp
[i
].sva
.fDiacritic
= FALSE
;
3164 pGlyphProp
[i
].sva
.fZeroWidth
= FALSE
;
3167 if (char_count
== 0)
3169 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3173 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3175 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
3176 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3179 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3181 pGlyphProp
[i
].sva
.fClusterStart
= 0;
3182 for (k
= 0; k
< char_count
&& !pGlyphProp
[i
].sva
.fClusterStart
; k
++)
3183 switch (lexical(pwcChars
[char_index
[k
]]))
3186 case lex_Matra_post
:
3187 case lex_Matra_above
:
3188 case lex_Matra_below
:
3194 /* check for dangling joiners */
3195 if (pwcChars
[char_index
[k
]-1] == 0x0020 || pwcChars
[char_index
[k
]+1] == 0x0020)
3196 pGlyphProp
[i
].sva
.fClusterStart
= 1;
3201 pGlyphProp
[i
].sva
.fClusterStart
= 1;
3208 IndicSyllable
*syllables
= NULL
;
3209 int syllable_count
= 0;
3210 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
3212 Indic_ParseSyllables( hdc
, psa
, psc
, pwcChars
, cChars
, &syllables
, &syllable_count
, lexical
, modern
);
3214 for (i
= 0; i
< syllable_count
; i
++)
3217 WORD g
= pwLogClust
[syllables
[i
].start
];
3218 for (j
= syllables
[i
].start
+1; j
<= syllables
[i
].end
; j
++)
3220 if (pwLogClust
[j
] != g
)
3222 pGlyphProp
[pwLogClust
[j
]].sva
.fClusterStart
= 0;
3228 HeapFree(GetProcessHeap(), 0, syllables
);
3231 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3234 static void ShapeCharGlyphProp_Sinhala( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3236 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, sinhala_lex
, FALSE
, FALSE
);
3239 static void ShapeCharGlyphProp_Devanagari( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3241 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, devanagari_lex
, TRUE
, TRUE
);
3244 static void ShapeCharGlyphProp_Bengali( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3246 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, bengali_lex
, TRUE
, TRUE
);
3249 static void ShapeCharGlyphProp_Gurmukhi( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3251 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, gurmukhi_lex
, TRUE
, TRUE
);
3254 static void ShapeCharGlyphProp_Gujarati( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3256 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, gujarati_lex
, TRUE
, TRUE
);
3259 static void ShapeCharGlyphProp_Oriya( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3261 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, oriya_lex
, TRUE
, TRUE
);
3264 static void ShapeCharGlyphProp_Tamil( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3266 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, tamil_lex
, TRUE
, TRUE
);
3269 static void ShapeCharGlyphProp_Telugu( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3271 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, telugu_lex
, TRUE
, TRUE
);
3274 static void ShapeCharGlyphProp_Kannada( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3276 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, kannada_lex
, TRUE
, TRUE
);
3279 static void ShapeCharGlyphProp_Malayalam( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3281 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, malayalam_lex
, TRUE
, TRUE
);
3284 static void ShapeCharGlyphProp_Khmer( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3286 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, khmer_lex
, TRUE
, TRUE
);
3289 void SHAPE_CharGlyphProp(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
3291 load_ot_tables(hdc
, psc
);
3293 if (ShapingData
[psa
->eScript
].charGlyphPropProc
)
3294 ShapingData
[psa
->eScript
].charGlyphPropProc(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
3296 ShapeCharGlyphProp_Default(psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
3299 void SHAPE_ContextualShaping(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
3301 load_ot_tables(hdc
, psc
);
3303 if (ShapingData
[psa
->eScript
].contextProc
)
3304 ShapingData
[psa
->eScript
].contextProc(hdc
, psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
3307 static void SHAPE_ApplyOpenTypeFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, INT cChars
, const TEXTRANGE_PROPERTIES
*rpRangeProperties
, WORD
*pwLogClust
)
3312 if (!rpRangeProperties
)
3315 load_ot_tables(hdc
, psc
);
3317 if (!psc
->GSUB_Table
)
3320 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
3325 for (i
= 0; i
< rpRangeProperties
->cotfRecords
; i
++)
3327 if (rpRangeProperties
->potfRecords
[i
].lParameter
> 0)
3328 apply_GSUB_feature(hdc
, psa
, psc
, pwOutGlyphs
, dirL
, pcGlyphs
, cChars
, (const char*)&rpRangeProperties
->potfRecords
[i
].tagFeature
, pwLogClust
);
3332 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, INT cChars
, WORD
*pwLogClust
)
3334 const TEXTRANGE_PROPERTIES
*rpRangeProperties
;
3335 rpRangeProperties
= &ShapingData
[psa
->eScript
].defaultTextRange
;
3337 SHAPE_ApplyOpenTypeFeatures(hdc
, psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, rpRangeProperties
, pwLogClust
);
3340 void SHAPE_ApplyOpenTypePositions(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WORD
* pwGlyphs
, INT cGlyphs
, int *piAdvance
, GOFFSET
*pGoffset
)
3342 const TEXTRANGE_PROPERTIES
*rpRangeProperties
= &ShapingData
[psa
->eScript
].defaultGPOSTextRange
;
3345 load_ot_tables(hdc
, psc
);
3347 if (!psc
->GPOS_Table
|| !psc
->otm
)
3350 for (i
= 0; i
< rpRangeProperties
->cotfRecords
; i
++)
3352 if (rpRangeProperties
->potfRecords
[i
].lParameter
> 0)
3354 LoadedFeature
*feature
;
3356 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GPOS_TABLE
, (const char*)&rpRangeProperties
->potfRecords
[i
].tagFeature
);
3360 GPOS_apply_feature(psc
, psc
->otm
, &psc
->lf
, psa
, piAdvance
, feature
, pwGlyphs
, cGlyphs
, pGoffset
);
3365 HRESULT
SHAPE_CheckFontForRequiredFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
)
3367 LoadedFeature
*feature
;
3370 if (!ShapingData
[psa
->eScript
].requiredFeatures
)
3373 load_ot_tables(hdc
, psc
);
3375 /* we need to have at least one of the required features */
3377 while (ShapingData
[psa
->eScript
].requiredFeatures
[i
])
3379 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_ALL_TABLES
, ShapingData
[psa
->eScript
].requiredFeatures
[i
]);
3385 return USP_E_SCRIPT_NOT_IN_FONT
;
3388 HRESULT
SHAPE_GetFontScriptTags( HDC hdc
, ScriptCache
*psc
,
3389 SCRIPT_ANALYSIS
*psa
, int cMaxTags
,
3390 OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
3393 OPENTYPE_TAG searching
= 0x00000000;
3395 load_ot_tables(hdc
, psc
);
3397 if (psa
&& scriptInformation
[psa
->eScript
].scriptTag
)
3398 searching
= scriptInformation
[psa
->eScript
].scriptTag
;
3400 hr
= OpenType_GetFontScriptTags(psc
, searching
, cMaxTags
, pScriptTags
, pcTags
);
3406 HRESULT
SHAPE_GetFontLanguageTags( HDC hdc
, ScriptCache
*psc
,
3407 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
3408 int cMaxTags
, OPENTYPE_TAG
*pLangSysTags
,
3412 OPENTYPE_TAG searching
= 0x00000000;
3413 BOOL fellback
= FALSE
;
3415 load_ot_tables(hdc
, psc
);
3417 if (psa
&& psc
->userLang
!= 0)
3418 searching
= psc
->userLang
;
3420 hr
= OpenType_GetFontLanguageTags(psc
, tagScript
, searching
, cMaxTags
, pLangSysTags
, pcTags
);
3424 hr
= OpenType_GetFontLanguageTags(psc
, MS_MAKE_TAG('l','a','t','n'), searching
, cMaxTags
, pLangSysTags
, pcTags
);
3427 if (FAILED(hr
) || fellback
)
3429 if (SUCCEEDED(hr
) && fellback
&& psa
)
3434 HRESULT
SHAPE_GetFontFeatureTags( HDC hdc
, ScriptCache
*psc
,
3435 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
3436 OPENTYPE_TAG tagLangSys
, int cMaxTags
,
3437 OPENTYPE_TAG
*pFeatureTags
, int *pcTags
)
3440 BOOL filter
= FALSE
;
3442 load_ot_tables(hdc
, psc
);
3444 if (psa
&& scriptInformation
[psa
->eScript
].scriptTag
)
3446 FIXME("Filtering not implemented\n");
3450 hr
= OpenType_GetFontFeatureTags(psc
, tagScript
, tagLangSys
, filter
, 0x00000000, FEATURE_ALL_TABLES
, cMaxTags
, pFeatureTags
, pcTags
, NULL
);