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
32 #include "usp10_internal.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
38 #define FIRST_ARABIC_CHAR 0x0600
39 #define LAST_ARABIC_CHAR 0x06ff
41 typedef VOID (*ContextualShapingProc)(HDC, ScriptCache*, SCRIPT_ANALYSIS*,
42 WCHAR*, INT, WORD*, INT*, INT, WORD*);
44 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
45 static void ContextualShape_Hebrew(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
46 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
47 static void ContextualShape_Thaana(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
48 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
49 static void ContextualShape_Thai(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
50 static void ContextualShape_Lao(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
51 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
52 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
53 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
54 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
55 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
56 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
57 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
58 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
59 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
60 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
61 static void ContextualShape_Khmer(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
62 static void ContextualShape_Mongolian(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
64 typedef VOID (*ShapeCharGlyphPropProc)( HDC , ScriptCache*, SCRIPT_ANALYSIS*, const WCHAR*, const INT, const WORD*, const INT, WORD*, SCRIPT_CHARPROP*, SCRIPT_GLYPHPROP*);
66 static void ShapeCharGlyphProp_Default( 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_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 );
68 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 );
69 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 );
70 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 );
71 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 );
72 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 );
73 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 );
74 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 );
75 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 );
76 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 );
77 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 );
78 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 );
79 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 );
80 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 );
81 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 );
82 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 );
84 extern const unsigned short indic_syllabic_table[];
85 extern const unsigned short wine_shaping_table[];
86 extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
108 typedef struct tagVowelComponents
114 typedef struct tagConsonantComponents
118 } ConsonantComponents;
120 typedef void (*second_reorder_function)(LPWSTR pwChar, IndicSyllable *syllable,WORD* pwGlyphs, IndicSyllable* glyph_index, lexical_function lex);
122 typedef int (*combining_lexical_function)(WCHAR c);
124 /* the orders of joined_forms and contextual_features need to line up */
125 static const char* contextual_features[] =
137 static OPENTYPE_FEATURE_RECORD standard_features[] =
139 { MS_MAKE_TAG('c','c','m','p'), 1},
140 { MS_MAKE_TAG('l','o','c','l'), 1},
143 static OPENTYPE_FEATURE_RECORD latin_features[] =
145 { MS_MAKE_TAG('l','i','g','a'), 1},
146 { MS_MAKE_TAG('c','l','i','g'), 1},
149 static OPENTYPE_FEATURE_RECORD latin_gpos_features[] =
151 { MS_MAKE_TAG('k','e','r','n'), 1},
152 { MS_MAKE_TAG('m','a','r','k'), 1},
153 { MS_MAKE_TAG('m','k','m','k'), 1},
156 static OPENTYPE_FEATURE_RECORD arabic_features[] =
158 { MS_MAKE_TAG('r','l','i','g'), 1},
159 { MS_MAKE_TAG('c','a','l','t'), 1},
160 { MS_MAKE_TAG('l','i','g','a'), 1},
161 { MS_MAKE_TAG('d','l','i','g'), 1},
162 { MS_MAKE_TAG('c','s','w','h'), 1},
163 { MS_MAKE_TAG('m','s','e','t'), 1},
166 static const char* required_arabic_features[] =
175 static OPENTYPE_FEATURE_RECORD arabic_gpos_features[] =
177 { MS_MAKE_TAG('c','u','r','s'), 1},
178 { MS_MAKE_TAG('k','e','r','n'), 1},
179 { MS_MAKE_TAG('m','a','r','k'), 1},
180 { MS_MAKE_TAG('m','k','m','k'), 1},
183 static OPENTYPE_FEATURE_RECORD hebrew_features[] =
185 { MS_MAKE_TAG('c','c','m','p'), 1},
186 { MS_MAKE_TAG('d','l','i','g'), 0},
189 static OPENTYPE_FEATURE_RECORD hebrew_gpos_features[] =
191 { MS_MAKE_TAG('k','e','r','n'), 1},
192 { MS_MAKE_TAG('m','a','r','k'), 1},
195 static OPENTYPE_FEATURE_RECORD syriac_features[] =
197 { MS_MAKE_TAG('r','l','i','g'), 1},
198 { MS_MAKE_TAG('c','a','l','t'), 1},
199 { MS_MAKE_TAG('l','i','g','a'), 1},
200 { MS_MAKE_TAG('d','l','i','g'), 1},
203 static const char* required_syriac_features[] =
215 static OPENTYPE_FEATURE_RECORD syriac_gpos_features[] =
217 { MS_MAKE_TAG('k','e','r','n'), 1},
218 { MS_MAKE_TAG('m','a','r','k'), 1},
219 { MS_MAKE_TAG('m','k','m','k'), 1},
222 static OPENTYPE_FEATURE_RECORD sinhala_features[] =
224 /* Presentation forms */
225 { MS_MAKE_TAG('b','l','w','s'), 1},
226 { MS_MAKE_TAG('a','b','v','s'), 1},
227 { MS_MAKE_TAG('p','s','t','s'), 1},
230 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
232 { MS_MAKE_TAG('a','b','v','s'), 1},
233 { MS_MAKE_TAG('b','l','w','s'), 1},
236 static OPENTYPE_FEATURE_RECORD tibetan_gpos_features[] =
238 { MS_MAKE_TAG('a','b','v','m'), 1},
239 { MS_MAKE_TAG('b','l','w','m'), 1},
242 static OPENTYPE_FEATURE_RECORD phags_features[] =
244 { MS_MAKE_TAG('a','b','v','s'), 1},
245 { MS_MAKE_TAG('b','l','w','s'), 1},
246 { MS_MAKE_TAG('c','a','l','t'), 1},
249 static OPENTYPE_FEATURE_RECORD thai_features[] =
251 { MS_MAKE_TAG('c','c','m','p'), 1},
254 static OPENTYPE_FEATURE_RECORD thai_gpos_features[] =
256 { MS_MAKE_TAG('k','e','r','n'), 1},
257 { MS_MAKE_TAG('m','a','r','k'), 1},
258 { MS_MAKE_TAG('m','k','m','k'), 1},
261 static const char* required_lao_features[] =
267 static const char* required_devanagari_features[] =
283 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
285 { MS_MAKE_TAG('p','r','e','s'), 1},
286 { MS_MAKE_TAG('a','b','v','s'), 1},
287 { MS_MAKE_TAG('b','l','w','s'), 1},
288 { MS_MAKE_TAG('p','s','t','s'), 1},
289 { MS_MAKE_TAG('h','a','l','n'), 1},
290 { MS_MAKE_TAG('c','a','l','t'), 1},
293 static OPENTYPE_FEATURE_RECORD devanagari_gpos_features[] =
295 { MS_MAKE_TAG('k','e','r','n'), 1},
296 { MS_MAKE_TAG('d','i','s','t'), 1},
297 { MS_MAKE_TAG('a','b','v','m'), 1},
298 { MS_MAKE_TAG('b','l','w','m'), 1},
301 static OPENTYPE_FEATURE_RECORD myanmar_features[] =
303 { MS_MAKE_TAG('l','i','g','a'), 1},
304 { MS_MAKE_TAG('c','l','i','g'), 1},
307 static const char* required_bengali_features[] =
324 static const char* required_gurmukhi_features[] =
343 static const char* required_oriya_features[] =
360 static const char* required_tamil_features[] =
376 static const char* required_telugu_features[] =
394 static OPENTYPE_FEATURE_RECORD khmer_features[] =
396 { MS_MAKE_TAG('p','r','e','s'), 1},
397 { MS_MAKE_TAG('b','l','w','s'), 1},
398 { MS_MAKE_TAG('a','b','v','s'), 1},
399 { MS_MAKE_TAG('p','s','t','s'), 1},
400 { MS_MAKE_TAG('c','l','i','g'), 1},
403 static const char* required_khmer_features[] =
417 static OPENTYPE_FEATURE_RECORD khmer_gpos_features[] =
419 { MS_MAKE_TAG('d','i','s','t'), 1},
420 { MS_MAKE_TAG('b','l','w','m'), 1},
421 { MS_MAKE_TAG('a','b','v','m'), 1},
422 { MS_MAKE_TAG('m','k','m','k'), 1},
425 static OPENTYPE_FEATURE_RECORD ethiopic_features[] =
427 { MS_MAKE_TAG('c','c','m','p'), 1},
428 { MS_MAKE_TAG('l','o','c','l'), 1},
429 { MS_MAKE_TAG('c','a','l','t'), 1},
430 { MS_MAKE_TAG('l','i','g','a'), 1},
433 static OPENTYPE_FEATURE_RECORD mongolian_features[] =
435 { MS_MAKE_TAG('c','c','m','p'), 1},
436 { MS_MAKE_TAG('l','o','c','l'), 1},
437 { MS_MAKE_TAG('c','a','l','t'), 1},
438 { MS_MAKE_TAG('r','l','i','g'), 1},
441 typedef struct ScriptShapeDataTag {
442 TEXTRANGE_PROPERTIES defaultTextRange;
443 TEXTRANGE_PROPERTIES defaultGPOSTextRange;
444 const char** requiredFeatures;
445 OPENTYPE_TAG newOtTag;
446 ContextualShapingProc contextProc;
447 ShapeCharGlyphPropProc charGlyphPropProc;
450 /* in order of scripts */
451 static const ScriptShapeData ShapingData[] =
453 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
454 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
455 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
456 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
457 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
458 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
459 {{ arabic_features, 6}, {arabic_gpos_features, 4}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
460 {{ arabic_features, 6}, {arabic_gpos_features, 4}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
461 {{ hebrew_features, 2}, {hebrew_gpos_features, 2}, NULL, 0, ContextualShape_Hebrew, ShapeCharGlyphProp_Hebrew},
462 {{ syriac_features, 4}, {syriac_gpos_features, 3}, required_syriac_features, 0, ContextualShape_Syriac, ShapeCharGlyphProp_None},
463 {{ arabic_features, 6}, {arabic_gpos_features, 4}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
464 {{ NULL, 0}, {NULL, 0}, NULL, 0, ContextualShape_Thaana, ShapeCharGlyphProp_None},
465 {{ standard_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
466 {{ standard_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
467 {{ standard_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
468 {{ standard_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
469 {{ sinhala_features, 3}, {NULL, 0}, NULL, 0, ContextualShape_Sinhala, ShapeCharGlyphProp_Sinhala},
470 {{ tibetan_features, 2}, {tibetan_gpos_features, 2}, NULL, 0, NULL, ShapeCharGlyphProp_Tibet},
471 {{ tibetan_features, 2}, {tibetan_gpos_features, 2}, NULL, 0, NULL, ShapeCharGlyphProp_Tibet},
472 {{ phags_features, 3}, {NULL, 0}, NULL, 0, ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
473 {{ thai_features, 1}, {thai_gpos_features, 3}, NULL, 0, ContextualShape_Thai, ShapeCharGlyphProp_Thai},
474 {{ thai_features, 1}, {thai_gpos_features, 3}, NULL, 0, ContextualShape_Thai, NULL},
475 {{ thai_features, 1}, {thai_gpos_features, 3}, required_lao_features, 0, ContextualShape_Lao, ShapeCharGlyphProp_Thai},
476 {{ thai_features, 1}, {thai_gpos_features, 3}, required_lao_features, 0, ContextualShape_Lao, ShapeCharGlyphProp_Thai},
477 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_devanagari_features, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
478 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_devanagari_features, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari, NULL},
479 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
480 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, NULL},
481 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
482 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_gurmukhi_features, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
483 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_gurmukhi_features, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi, NULL},
484 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
485 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, NULL},
486 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
487 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_oriya_features, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
488 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_oriya_features, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya, NULL},
489 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_tamil_features, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
490 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_tamil_features, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil, NULL},
491 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
492 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu, NULL},
493 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
494 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada, NULL},
495 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
496 {{ devanagari_features, 6}, {devanagari_gpos_features, 4}, required_telugu_features, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam, NULL},
497 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
498 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
499 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
500 {{ myanmar_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
501 {{ myanmar_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
502 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
503 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
504 {{ standard_features, 2}, {NULL, 0}, NULL, 0, NULL, NULL},
505 {{ khmer_features, 5}, {khmer_gpos_features, 4}, required_khmer_features, 0, ContextualShape_Khmer, ShapeCharGlyphProp_Khmer},
506 {{ khmer_features, 5}, {khmer_gpos_features, 4}, required_khmer_features, 0, ContextualShape_Khmer, ShapeCharGlyphProp_Khmer},
507 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
508 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
509 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, 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 {{ ethiopic_features, 4}, {NULL, 0}, NULL, 0, NULL, NULL},
514 {{ ethiopic_features, 4}, {NULL, 0}, NULL, 0, NULL, NULL},
515 {{ mongolian_features, 4}, {NULL, 0}, NULL, 0, ContextualShape_Mongolian, NULL},
516 {{ mongolian_features, 4}, {NULL, 0}, NULL, 0, ContextualShape_Mongolian, 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 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
526 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
527 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
528 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
529 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
530 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
531 {{ NULL, 0}, {NULL, 0}, NULL, 0, NULL, NULL},
532 {{ hebrew_features, 2}, {hebrew_gpos_features, 2}, NULL, 0, ContextualShape_Hebrew, NULL},
533 {{ latin_features, 2}, {latin_gpos_features, 3}, NULL, 0, NULL, NULL},
534 {{ thai_features, 1}, {thai_gpos_features, 3}, NULL, 0, ContextualShape_Thai, ShapeCharGlyphProp_Thai},
537 extern scriptData scriptInformation[];
539 static INT GSUB_apply_feature_all_lookups(LPCVOID header, LoadedFeature *feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
542 int out_index = GSUB_E_NOGLYPH;
544 TRACE("%i lookups\n", feature->lookup_count);
545 for (i = 0; i < feature->lookup_count; i++)
547 out_index = OpenType_apply_GSUB_lookup(header, feature->lookups[i], glyphs, glyph_index, write_dir, glyph_count);
548 if (out_index != GSUB_E_NOGLYPH)
551 if (out_index == GSUB_E_NOGLYPH)
552 TRACE("lookups found no glyphs\n");
556 out2 = GSUB_apply_feature_all_lookups(header, feature, glyphs, glyph_index, write_dir, glyph_count);
557 if (out2!=GSUB_E_NOGLYPH)
563 static OPENTYPE_TAG get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
567 if (psc->userScript != 0)
569 if (tryNew && ShapingData[psa->eScript].newOtTag != 0 && psc->userScript == scriptInformation[psa->eScript].scriptTag)
570 return ShapingData[psa->eScript].newOtTag;
572 return psc->userScript;
575 if (tryNew && ShapingData[psa->eScript].newOtTag != 0)
576 return ShapingData[psa->eScript].newOtTag;
578 if (scriptInformation[psa->eScript].scriptTag)
579 return scriptInformation[psa->eScript].scriptTag;
582 * fall back to the font charset
584 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
588 case BALTIC_CHARSET: return MS_MAKE_TAG('l','a','t','n');
589 case CHINESEBIG5_CHARSET: return MS_MAKE_TAG('h','a','n','i');
590 case EASTEUROPE_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
591 case GB2312_CHARSET: return MS_MAKE_TAG('h','a','n','i');
592 case GREEK_CHARSET: return MS_MAKE_TAG('g','r','e','k');
593 case HANGUL_CHARSET: return MS_MAKE_TAG('h','a','n','g');
594 case RUSSIAN_CHARSET: return MS_MAKE_TAG('c','y','r','l');
595 case SHIFTJIS_CHARSET: return MS_MAKE_TAG('k','a','n','a');
596 case TURKISH_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
597 case VIETNAMESE_CHARSET: return MS_MAKE_TAG('l','a','t','n');
598 case JOHAB_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
599 case ARABIC_CHARSET: return MS_MAKE_TAG('a','r','a','b');
600 case HEBREW_CHARSET: return MS_MAKE_TAG('h','e','b','r');
601 case THAI_CHARSET: return MS_MAKE_TAG('t','h','a','i');
602 default: return MS_MAKE_TAG('l','a','t','n');
606 static LoadedFeature* load_OT_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, char tableType, const char* feat)
608 LoadedFeature *feature = NULL;
610 if (psc->GSUB_Table || psc->GPOS_Table)
614 OPENTYPE_TAG language;
620 script = get_opentype_script(hdc,psa,psc,(attempt==2));
621 if (psc->userLang != 0)
622 language = psc->userLang;
624 language = MS_MAKE_TAG('d','f','l','t');
627 OpenType_GetFontFeatureTags(psc, script, language, FALSE, MS_MAKE_TAG(feat[0],feat[1],feat[2],feat[3]), tableType, 1, &tags, &cTags, &feature);
629 } while(attempt && !feature);
631 /* try in the default (latin) table */
633 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);
636 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
640 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)
642 LoadedFeature *feature;
644 feature = load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, feat);
646 return GSUB_E_NOFEATURE;
648 TRACE("applying feature %s\n",feat);
649 return GSUB_apply_feature_all_lookups(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
652 static VOID *load_gsub_table(HDC hdc)
654 VOID* GSUB_Table = NULL;
655 int length = GetFontData(hdc, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, 0);
656 if (length != GDI_ERROR)
658 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
659 GetFontData(hdc, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, GSUB_Table, length);
660 TRACE("Loaded GSUB table of %i bytes\n",length);
665 static VOID *load_gpos_table(HDC hdc)
667 VOID* GPOS_Table = NULL;
668 int length = GetFontData(hdc, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, NULL, 0);
669 if (length != GDI_ERROR)
671 GPOS_Table = HeapAlloc(GetProcessHeap(),0,length);
672 GetFontData(hdc, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, GPOS_Table, length);
673 TRACE("Loaded GPOS table of %i bytes\n",length);
678 static VOID load_ot_tables(HDC hdc, ScriptCache *psc)
680 if (!psc->GSUB_Table)
681 psc->GSUB_Table = load_gsub_table(hdc);
682 if (!psc->GPOS_Table)
683 psc->GPOS_Table = load_gpos_table(hdc);
686 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)
689 INT glyph_count = count;
692 glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*(count*2));
693 GetGlyphIndicesW(hdc, chars, count, glyphs, 0);
694 rc = apply_GSUB_feature_to_glyph(hdc, psa, psc, glyphs, 0, write_dir, &glyph_count, feature);
695 if (rc > GSUB_E_NOGLYPH)
696 rc = count - glyph_count;
700 HeapFree(GetProcessHeap(),0,glyphs);
704 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
708 for (i = 0; i < cGlyphs; i++)
710 if (!pGlyphProp[i].sva.fClusterStart)
713 for (j = 0; j < cChars; j++)
715 if (pwLogClust[j] == i)
718 while (k >= 0 && k <cChars && !pGlyphProp[pwLogClust[k]].sva.fClusterStart)
720 if (k >= 0 && k <cChars && pGlyphProp[pwLogClust[k]].sva.fClusterStart)
721 pwLogClust[j] = pwLogClust[k];
728 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
730 if (changeCount == 0)
735 int target_glyph = nextIndex - write_dir;
737 int target_index = -1;
738 int replacing_glyph = -1;
740 int top_logclust = 0;
745 target_glyph = nextIndex - changeCount;
747 target_glyph = nextIndex + (changeCount + 1);
750 seeking_glyph = target_glyph;
751 for (i = 0; i < chars; i++)
752 if (pwLogClust[i] > top_logclust)
753 top_logclust = pwLogClust[i];
757 for (i = 0; i < chars; i++)
759 if (pwLogClust[i] == seeking_glyph)
766 for (i = chars - 1; i >= 0; i--)
768 if (pwLogClust[i] == seeking_glyph)
774 if (target_index == -1)
777 while (target_index == -1 && seeking_glyph <= top_logclust);
779 if (target_index == -1)
781 ERR("Unable to find target glyph\n");
788 for(i = target_index; i < chars && i >= 0; i+=write_dir)
790 if (pwLogClust[i] == target_glyph)
792 if(pwLogClust[i] == replacing_glyph)
793 pwLogClust[i] = target_glyph;
797 if (changed >= changeCount)
799 replacing_glyph = pwLogClust[i];
800 pwLogClust[i] = target_glyph;
807 /* renumber trailing indexes*/
808 for(i = target_index; i < chars && i >= 0; i+=write_dir)
810 if (pwLogClust[i] != target_glyph)
811 pwLogClust[i] += changeCount;
816 for(i = target_index; i < chars && i >= 0; i+=write_dir)
817 pwLogClust[i] += changeCount;
822 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 )
826 LoadedFeature *feature;
829 feature = load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, feat);
831 return GSUB_E_NOFEATURE;
833 TRACE("applying feature %s: %i lookups\n",debugstr_an(feat,4),feature->lookup_count);
834 for (lookup_index = 0; lookup_index < feature->lookup_count; lookup_index++)
842 TRACE("applying lookup (%i/%i)\n",lookup_index,feature->lookup_count);
843 while(i < *pcGlyphs && i >= 0)
846 INT prevCount = *pcGlyphs;
848 nextIndex = OpenType_apply_GSUB_lookup(psc->GSUB_Table, feature->lookups[lookup_index], pwOutGlyphs, i, write_dir, pcGlyphs);
849 if (*pcGlyphs != prevCount)
851 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
860 return GSUB_E_NOFEATURE;
863 static VOID GPOS_apply_feature(LPOUTLINETEXTMETRICW lpotm, LPLOGFONTW lplogfont, const SCRIPT_ANALYSIS *analysis, INT* piAdvance,
864 LPCVOID header, LoadedFeature *feature, const WORD *glyphs, INT glyph_count, GOFFSET *pGoffset)
868 TRACE("%i lookups\n", feature->lookup_count);
869 for (i = 0; i < feature->lookup_count; i++)
872 for (j = 0; j < glyph_count; )
873 j = OpenType_apply_GPOS_lookup(lpotm, lplogfont, analysis, piAdvance, header, feature->lookups[i], glyphs, j, glyph_count, pGoffset);
877 static inline BOOL get_GSUB_Indic2(SCRIPT_ANALYSIS *psa, ScriptCache *psc)
883 hr = OpenType_GetFontScriptTags(psc, ShapingData[psa->eScript].newOtTag, 1, &tag, &count);
885 return(SUCCEEDED(hr));
888 static void insert_glyph(WORD *pwGlyphs, INT *pcGlyphs, INT cChars, INT write_dir, WORD glyph, INT index, WORD *pwLogClust)
891 for (i = *pcGlyphs; i>=index; i--)
892 pwGlyphs[i+1] = pwGlyphs[i];
893 pwGlyphs[index] = glyph;
894 *pcGlyphs = *pcGlyphs+1;
896 UpdateClusters(index-3, 1, write_dir, cChars, pwLogClust);
898 UpdateClusters(index, 1, write_dir, cChars, pwLogClust);
901 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)
905 WCHAR invalid = 0x25cc;
908 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
910 /* Mark invalid combinations */
911 for (i = 0; i < cChars; i++)
912 context_type[i] = lex(pwcChars[i]);
914 GetGlyphIndicesW(hdc, &invalid, 1, &invalid_glyph, 0);
915 for (i = 1, g=1; i < cChars; i++, g++)
917 if (context_type[i] != 0 && context_type[i+write_dir]==context_type[i])
919 insert_glyph(pwGlyphs, pcGlyphs, cChars, write_dir, invalid_glyph, g, pwLogClust);
924 HeapFree(GetProcessHeap(),0,context_type);
927 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
931 if ( i+ delta >= cchLen)
939 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
943 if (psa->fLinkBefore)
948 if ( i+ delta >= cchLen)
958 if (context_type[i] == jtT)
959 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
961 return context_type[i];
964 static inline BOOL right_join_causing(CHAR joining_type)
966 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
969 static inline BOOL left_join_causing(CHAR joining_type)
971 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
974 static inline BOOL word_break_causing(WCHAR chr)
976 /* we are working within a string of characters already guareented to
977 be within one script, Syriac, so we do not worry about any character
978 other than the space character outside of that range */
979 return (chr == 0 || chr == 0x20 );
982 static int combining_lexical_Arabic(WCHAR c)
984 enum {Arab_Norm = 0, Arab_DIAC1, Arab_DIAC2, Arab_DIAC3, Arab_DIAC4, Arab_DIAC5, Arab_DIAC6, Arab_DIAC7, Arab_DIAC8};
995 case 0x06E1: return Arab_DIAC1;
998 case 0x0656: return Arab_DIAC2;
999 case 0x0651: return Arab_DIAC3;
1015 case 0x06EC: return Arab_DIAC4;
1018 case 0x06ED: return Arab_DIAC5;
1019 case 0x0670: return Arab_DIAC6;
1020 case 0x0653: return Arab_DIAC7;
1022 case 0x0654: return Arab_DIAC8;
1023 default: return Arab_Norm;
1028 * ContextualShape_Arabic
1030 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1037 if (*pcGlyphs != cChars)
1039 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1043 if (!psa->fLogicalOrder && psa->fRTL)
1054 load_ot_tables(hdc, psc);
1056 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1057 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1059 for (i = 0; i < cChars; i++)
1060 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1062 for (i = 0; i < cChars; i++)
1064 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1065 context_shape[i] = Xr;
1066 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1067 context_shape[i] = Xl;
1068 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)))
1069 context_shape[i] = Xm;
1070 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1071 context_shape[i] = Xr;
1072 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1073 context_shape[i] = Xl;
1075 context_shape[i] = Xn;
1078 /* Contextual Shaping */
1080 while(i < *pcGlyphs)
1082 BOOL shaped = FALSE;
1084 if (psc->GSUB_Table)
1087 INT prevCount = *pcGlyphs;
1088 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1089 if (nextIndex > GSUB_E_NOGLYPH)
1092 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1094 shaped = (nextIndex > GSUB_E_NOGLYPH);
1099 if (context_shape[i] == Xn)
1101 WORD newGlyph = pwOutGlyphs[i];
1102 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1104 /* fall back to presentation form B */
1105 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1106 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1107 pwOutGlyphs[i] = newGlyph;
1114 HeapFree(GetProcessHeap(),0,context_shape);
1115 HeapFree(GetProcessHeap(),0,context_type);
1117 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Arabic);
1120 static int combining_lexical_Hebrew(WCHAR c)
1122 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};
1133 case 0x05BB: return Hebr_DIAC;
1137 case 0x05AE: return Hebr_CANT1;
1140 case 0x05AC: return Hebr_CANT2;
1146 case 0x05AB: return Hebr_CANT3;
1150 case 0x059F: return Hebr_CANT4;
1152 case 0x05A0: return Hebr_CANT5;
1154 case 0x05A5: return Hebr_CANT6;
1157 case 0x05A6: return Hebr_CANT7;
1160 case 0x05AA: return Hebr_CANT8;
1162 case 0x05AD: return Hebr_CANT9;
1163 case 0x05AF: return Hebr_CANT10;
1164 case 0x05BC: return Hebr_DAGESH;
1165 case 0x05C4: return Hebr_DOTABV;
1166 case 0x05B9: return Hebr_HOLAM;
1167 case 0x05BD: return Hebr_METEG;
1168 case 0x05B7: return Hebr_PATAH;
1169 case 0x05B8: return Hebr_QAMATS;
1170 case 0x05BF: return Hebr_RAFE;
1172 case 0x05C2: return Hebr_SHINSIN;
1173 default: return Hebr_Norm;
1177 static void ContextualShape_Hebrew(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1181 if (*pcGlyphs != cChars)
1183 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1187 if (!psa->fLogicalOrder && psa->fRTL)
1192 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Hebrew);
1196 * ContextualShape_Syriac
1199 static int combining_lexical_Syriac(WCHAR c)
1201 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};
1209 case 0x73D: return Syriac_DIAC1;
1214 case 0x73E: return Syriac_DIAC2;
1217 case 0x74A: return Syriac_DIAC3;
1220 case 0x73F: return Syriac_DIAC4;
1223 case 0x73C: return Syriac_DIAC5;
1225 case 0x30A: return Syriac_DIAC6;
1227 case 0x325: return Syriac_DIAC7;
1229 case 0x303: return Syriac_DIAC8;
1234 case 0x331: return Syriac_DIAC9;
1235 case 0x308: return Syriac_DIAC10;
1236 case 0x304: return Syriac_DIAC11;
1237 case 0x307: return Syriac_DIAC12;
1238 case 0x323: return Syriac_DIAC13;
1239 case 0x743: return Syriac_DIAC14;
1240 case 0x744: return Syriac_DIAC15;
1241 case 0x745: return Syriac_DIAC16;
1242 case 0x746: return Syriac_DIAC17;
1243 default: return Syriac_Norm;
1248 #define DALATH 0x715
1251 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1258 if (*pcGlyphs != cChars)
1260 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1264 if (!psa->fLogicalOrder && psa->fRTL)
1275 load_ot_tables(hdc, psc);
1277 if (!psc->GSUB_Table)
1280 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1281 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1283 for (i = 0; i < cChars; i++)
1284 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1286 for (i = 0; i < cChars; i++)
1288 if (pwcChars[i] == ALAPH)
1290 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1292 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1293 context_shape[i] = Afj;
1294 else if ( rchar != DALATH && rchar != RISH &&
1295 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1296 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1297 context_shape[i] = Afn;
1298 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1299 context_shape[i] = Afx;
1301 context_shape[i] = Xn;
1303 else if (context_type[i] == jtR &&
1304 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1305 context_shape[i] = Xr;
1306 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1307 context_shape[i] = Xl;
1308 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)))
1309 context_shape[i] = Xm;
1310 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1311 context_shape[i] = Xr;
1312 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1313 context_shape[i] = Xl;
1315 context_shape[i] = Xn;
1318 /* Contextual Shaping */
1320 while(i < *pcGlyphs)
1323 INT prevCount = *pcGlyphs;
1324 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1325 if (nextIndex > GSUB_E_NOGLYPH)
1327 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1334 HeapFree(GetProcessHeap(),0,context_shape);
1335 HeapFree(GetProcessHeap(),0,context_type);
1337 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Syriac);
1340 static int combining_lexical_Thaana(WCHAR c)
1342 enum {Thaana_Norm=0, Thaana_FILI};
1355 case 0x7AF: return Thaana_FILI;
1356 default: return Thaana_Norm;
1360 static void ContextualShape_Thaana(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1364 if (*pcGlyphs != cChars)
1366 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1370 if (!psa->fLogicalOrder && psa->fRTL)
1375 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Thaana);
1379 * ContextualShape_Phags_pa
1382 #define phags_pa_CANDRABINDU 0xA873
1383 #define phags_pa_START 0xA840
1384 #define phags_pa_END 0xA87F
1386 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1392 if (*pcGlyphs != cChars)
1394 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1398 if (!psa->fLogicalOrder && psa->fRTL)
1409 load_ot_tables(hdc, psc);
1411 if (!psc->GSUB_Table)
1414 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1416 for (i = 0; i < cChars; i++)
1418 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1420 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1421 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1422 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1423 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1425 if (jrchar && jlchar)
1426 context_shape[i] = Xm;
1428 context_shape[i] = Xr;
1430 context_shape[i] = Xl;
1432 context_shape[i] = Xn;
1435 context_shape[i] = -1;
1438 /* Contextual Shaping */
1440 while(i < *pcGlyphs)
1442 if (context_shape[i] >= 0)
1445 INT prevCount = *pcGlyphs;
1446 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1447 if (nextIndex > GSUB_E_NOGLYPH)
1449 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1459 HeapFree(GetProcessHeap(),0,context_shape);
1462 static int combining_lexical_Thai(WCHAR c)
1464 enum {Thai_Norm=0, Thai_ABOVE1, Thai_ABOVE2, Thai_ABOVE3, Thai_ABOVE4, Thai_BELOW1, Thai_BELOW2, Thai_AM};
1472 case 0xE37: return Thai_ABOVE1;
1474 case 0xE4D: return Thai_ABOVE2;
1478 case 0xE4B: return Thai_ABOVE3;
1480 case 0xE4E: return Thai_ABOVE4;
1482 case 0xE39: return Thai_BELOW1;
1483 case 0xE3A: return Thai_BELOW2;
1484 case 0xE33: return Thai_AM;
1485 default: return Thai_Norm;
1489 static void ContextualShape_Thai(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1493 if (*pcGlyphs != cChars)
1495 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1499 if (!psa->fLogicalOrder && psa->fRTL)
1504 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Thai);
1507 static int combining_lexical_Lao(WCHAR c)
1509 enum {Lao_Norm=0, Lao_ABOVE1, Lao_ABOVE2, Lao_BELOW1, Lao_BELOW2, Lao_AM};
1519 case 0xECD: return Lao_ABOVE1;
1524 case 0xECC: return Lao_ABOVE2;
1525 case 0xEBC: return Lao_BELOW1;
1527 case 0xEB9: return Lao_BELOW2;
1528 case 0xEB3: return Lao_AM;
1529 default: return Lao_Norm;
1533 static void ContextualShape_Lao(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1537 if (*pcGlyphs != cChars)
1539 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1543 if (!psa->fLogicalOrder && psa->fRTL)
1548 mark_invalid_combinations(hdc, pwcChars, cChars, pwOutGlyphs, pcGlyphs, dirL, pwLogClust, combining_lexical_Lao);
1551 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1556 pwOutChars[cWalk] = replacements[0];
1560 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1563 for (j = *pcChars; j > cWalk; j--)
1564 pwOutChars[j] = pwOutChars[j-1];
1565 *pcChars= *pcChars+1;
1566 pwOutChars[cWalk] = replacements[i];
1571 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[], WORD* pwLogClust, INT cChars)
1576 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1578 for (i = 0; vowels[i].base != 0x0; i++)
1580 if (pwOutChars[cWalk] == vowels[i].base)
1583 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1584 if (vowels[i].parts[1]) { cWalk++; o++; }
1585 if (vowels[i].parts[2]) { cWalk++; o++; }
1586 UpdateClusters(cWalk, o, 1, cChars, pwLogClust);
1593 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[], WORD* pwLogClust)
1599 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1601 for (i = 0; consonants[i].output!= 0x0; i++)
1604 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1605 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1608 if (consonants[i].parts[j]==0x0) /* matched all */
1612 pwOutChars[cWalk] = consonants[i].output;
1613 for(k = cWalk+1; k < *pcChars - j; k++)
1614 pwOutChars[k] = pwOutChars[k+j];
1615 *pcChars = *pcChars - j;
1616 for (k = j ; k > 0; k--)
1617 pwLogClust[cWalk + k + offset] = pwLogClust[cWalk + offset];
1619 for (k = cWalk + j + offset; k < *pcChars + offset; k++)
1628 static void Reorder_Ra_follows_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1633 WORD Ra = pwChar[s->start];
1634 WORD H = pwChar[s->start+1];
1636 TRACE("Doing reorder of Ra to %i\n",s->base);
1637 for (j = s->start; j < s->base-1; j++)
1638 pwChar[j] = pwChar[j+2];
1639 pwChar[s->base-1] = Ra;
1640 pwChar[s->base] = H;
1642 s->ralf = s->base-1;
1647 static void Reorder_Ra_follows_matra(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1652 int stop = (s->blwf >=0)? s->blwf+1 : s->base;
1653 WORD Ra = pwChar[s->start];
1654 WORD H = pwChar[s->start+1];
1655 for (loc = s->end; loc > stop; loc--)
1656 if (lexical(pwChar[loc]) == lex_Matra_post || lexical(pwChar[loc]) == lex_Matra_below)
1659 TRACE("Doing reorder of Ra to %i\n",loc);
1660 for (j = s->start; j < loc-1; j++)
1661 pwChar[j] = pwChar[j+2];
1667 if (s->blwf >= 0) s->blwf -= 2;
1668 if (s->pref >= 0) s->pref -= 2;
1672 static void Reorder_Ra_follows_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1677 WORD Ra = pwChar[s->start];
1678 WORD H = pwChar[s->start+1];
1680 TRACE("Doing reorder of Ra to %i\n",s->end-1);
1681 for (j = s->start; j < s->end-1; j++)
1682 pwChar[j] = pwChar[j+2];
1683 pwChar[s->end-1] = Ra;
1688 if (s->blwf >= 0) s->blwf -= 2;
1689 if (s->pref >= 0) s->pref -= 2;
1693 static void Reorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1697 /* reorder Matras */
1698 if (s->end > s->base)
1700 for (i = 1; i <= s->end-s->base; i++)
1702 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1705 WCHAR c = pwChar[s->base+i];
1706 TRACE("Doing reorder of %x %x\n",c,pwChar[s->base]);
1707 for (j = s->base+i; j > s->base; j--)
1708 pwChar[j] = pwChar[j-1];
1709 pwChar[s->base] = c;
1711 if (s->ralf >= s->base) s->ralf++;
1712 if (s->blwf >= s->base) s->blwf++;
1713 if (s->pref >= s->base) s->pref++;
1720 static void Reorder_Matra_precede_syllable(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 to %i\n",c,s->start);
1734 for (j = s->base+i; j > s->start; j--)
1735 pwChar[j] = pwChar[j-1];
1736 pwChar[s->start] = c;
1738 if (s->ralf >= 0) s->ralf++;
1739 if (s->blwf >= 0) s->blwf++;
1740 if (s->pref >= 0) s->pref++;
1747 static void SecondReorder_Blwf_follows_matra(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1749 if (s->blwf >= 0 && g->blwf > g->base)
1753 for (loc = s->end; loc > s->blwf; loc--)
1754 if (lexical(pwChar[loc]) == lex_Matra_below || lexical(pwChar[loc]) == lex_Matra_above || lexical(pwChar[loc]) == lex_Matra_post)
1757 g_offset = (loc - s->blwf) - 1;
1761 WORD blwf = glyphs[g->blwf];
1762 TRACE("Doing reorder of Below-base to %i (glyph offset %i)\n",loc,g_offset);
1763 /* do not care about the pwChar array anymore, just the glyphs */
1764 for (j = 0; j < g_offset; j++)
1765 glyphs[g->blwf + j] = glyphs[g->blwf + j + 1];
1766 glyphs[g->blwf + g_offset] = blwf;
1771 static void SecondReorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1775 /* reorder previously moved Matras to correct position*/
1776 for (i = s->start; i < s->base; i++)
1778 if (lexical(pwChar[i]) == lex_Matra_pre)
1781 int g_start = g->start + i - s->start;
1782 if (g_start < g->base -1 )
1784 WCHAR og = glyphs[g_start];
1785 TRACE("Doing reorder of matra from %i to %i\n",g_start,g->base);
1786 for (j = g_start; j < g->base-1; j++)
1787 glyphs[j] = glyphs[j+1];
1788 glyphs[g->base-1] = og;
1794 static void SecondReorder_Pref_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1796 if (s->pref >= 0 && g->pref > g->base)
1799 WCHAR og = glyphs[g->pref];
1800 TRACE("Doing reorder of pref from %i to %i\n",g->pref,g->base);
1801 for (j = g->pref; j > g->base; j--)
1802 glyphs[j] = glyphs[j-1];
1803 glyphs[g->base] = og;
1807 static void Reorder_Like_Sinhala(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1809 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1810 if (s->start == s->base && s->base == s->end) return;
1811 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1813 Reorder_Ra_follows_base(pwChar, s, lexical);
1814 Reorder_Matra_precede_base(pwChar, s, lexical);
1817 static void Reorder_Like_Devanagari(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1819 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1820 if (s->start == s->base && s->base == s->end) return;
1821 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1823 Reorder_Ra_follows_matra(pwChar, s, lexical);
1824 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1827 static void Reorder_Like_Bengali(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1829 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1830 if (s->start == s->base && s->base == s->end) return;
1831 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1833 Reorder_Ra_follows_base(pwChar, s, lexical);
1834 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1837 static void Reorder_Like_Kannada(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1839 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1840 if (s->start == s->base && s->base == s->end) return;
1841 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1843 Reorder_Ra_follows_syllable(pwChar, s, lexical);
1844 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1847 static void SecondReorder_Like_Telugu(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
1849 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1850 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
1851 if (s->start == s->base && s->base == s->end) return;
1852 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1854 SecondReorder_Blwf_follows_matra(pwChar, s, pwGlyphs, g, lexical);
1857 static void SecondReorder_Like_Tamil(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
1859 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1860 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
1861 if (s->start == s->base && s->base == s->end) return;
1862 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1864 SecondReorder_Matra_precede_base(pwChar, s, pwGlyphs, g, lexical);
1865 SecondReorder_Pref_precede_base(pwChar, s, pwGlyphs, g, lexical);
1869 static inline void shift_syllable_glyph_indexs(IndicSyllable *glyph_index, INT index, INT shift)
1874 if (glyph_index->start > index)
1875 glyph_index->start += shift;
1876 if (glyph_index->base > index)
1877 glyph_index->base+= shift;
1878 if (glyph_index->end > index)
1879 glyph_index->end+= shift;
1880 if (glyph_index->ralf > index)
1881 glyph_index->ralf+= shift;
1882 if (glyph_index->blwf > index)
1883 glyph_index->blwf+= shift;
1884 if (glyph_index->pref > index)
1885 glyph_index->pref+= shift;
1888 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 )
1890 int index = glyph_index->start;
1895 while(index <= glyph_index->end)
1898 INT prevCount = *pcGlyphs;
1899 nextIndex = GSUB_apply_feature_all_lookups(psc->GSUB_Table, feature, pwOutGlyphs, index, 1, pcGlyphs);
1900 if (nextIndex > GSUB_E_NOGLYPH)
1902 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
1903 shift_syllable_glyph_indexs(glyph_index,index,*pcGlyphs - prevCount);
1911 static inline INT find_consonant_halant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
1914 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)))))
1916 if (index + i <= end-1)
1922 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)
1924 INT index, nextIndex;
1927 count = syllable->base - syllable->start;
1930 index = find_consonant_halant(&pwChars[syllable->start], 0, count, lexical);
1931 while (index >= 0 && index + g_offset < (glyph_index->base - glyph_index->start))
1933 INT prevCount = *pcGlyphs;
1934 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->start+g_offset, 1, pcGlyphs, feature);
1935 if (nextIndex > GSUB_E_NOGLYPH)
1937 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
1938 shift_syllable_glyph_indexs(glyph_index, index + glyph_index->start + g_offset, (*pcGlyphs - prevCount));
1939 g_offset += (*pcGlyphs - prevCount);
1943 index = find_consonant_halant(&pwChars[syllable->start], index, count, lexical);
1947 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)
1950 INT prevCount = *pcGlyphs;
1952 if (syllable->ralf >= 0)
1954 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, glyph_index->ralf, 1, pcGlyphs, "rphf");
1955 if (nextIndex > GSUB_E_NOGLYPH)
1957 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
1958 shift_syllable_glyph_indexs(glyph_index,glyph_index->ralf,*pcGlyphs - prevCount);
1963 static inline INT find_halant_consonant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
1966 while (index + i < end-1 && !(lexical(pwChars[index+i]) == lex_Halant &&
1967 ((index + i < end-2 && lexical(pwChars[index+i]) == lex_Nukta && is_consonant(lexical(pwChars[index+i+1]))) ||
1968 is_consonant(lexical(pwChars[index+i+1])))))
1970 if (index + i <= end-1)
1976 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)
1978 INT index, nextIndex;
1979 INT count, g_offset=0;
1980 INT ralf = syllable->ralf;
1982 count = syllable->end - syllable->base;
1984 index = find_halant_consonant(&pwChars[syllable->base], 0, count, lexical);
1988 INT prevCount = *pcGlyphs;
1989 if (ralf >=0 && ralf < index)
1997 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
1998 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
1999 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2002 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->base+g_offset, 1, pcGlyphs, feat);
2003 if (nextIndex > GSUB_E_NOGLYPH)
2005 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2006 shift_syllable_glyph_indexs(glyph_index,index+glyph_index->start+g_offset, (*pcGlyphs - prevCount));
2007 g_offset += (*pcGlyphs - prevCount);
2011 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
2012 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
2013 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2017 index = find_halant_consonant(&pwChars[syllable->base], index, count, lexical);
2021 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)
2024 int overall_shift = 0;
2025 LoadedFeature *locl = (modern)?load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "locl"):NULL;
2026 LoadedFeature *nukt = load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "nukt");
2027 LoadedFeature *akhn = load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "akhn");
2028 LoadedFeature *rkrf = (modern)?load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "rkrf"):NULL;
2029 LoadedFeature *pstf = load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "pstf");
2030 LoadedFeature *vatu = (!rkrf)?load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "vatu"):NULL;
2031 LoadedFeature *cjct = (modern)?load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "cjct"):NULL;
2032 BOOL rphf = (load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "rphf") != NULL);
2033 BOOL pref = (load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "pref") != NULL);
2034 BOOL blwf = (load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "blwf") != NULL);
2035 BOOL half = (load_OT_feature(hdc, psa, psc, FEATURE_GSUB_TABLE, "half") != NULL);
2036 IndicSyllable glyph_indexs;
2038 for (c = 0; c < syllable_count; c++)
2041 memcpy(&glyph_indexs, &syllables[c], sizeof(IndicSyllable));
2042 shift_syllable_glyph_indexs(&glyph_indexs, -1, overall_shift);
2043 old_end = glyph_indexs.end;
2047 TRACE("applying feature locl\n");
2048 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, locl);
2052 TRACE("applying feature nukt\n");
2053 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, nukt);
2057 TRACE("applying feature akhn\n");
2058 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, akhn);
2062 Apply_Indic_Rphf(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs);
2065 TRACE("applying feature rkrf\n");
2066 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, rkrf);
2069 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "pref");
2073 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "blwf");
2075 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "blwf");
2079 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "half");
2082 TRACE("applying feature pstf\n");
2083 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, pstf);
2087 TRACE("applying feature vatu\n");
2088 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, vatu);
2092 TRACE("applying feature cjct\n");
2093 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, cjct);
2097 second_reorder(pwChars, &syllables[c], pwOutGlyphs, &glyph_indexs, lexical);
2099 overall_shift += glyph_indexs.end - old_end;
2103 static inline int unicode_lex(WCHAR c)
2107 if (!c) return lex_Generic;
2108 if (c == 0x200D) return lex_ZWJ;
2109 if (c == 0x200C) return lex_ZWNJ;
2110 if (c == 0x00A0) return lex_NBSP;
2112 type = get_table_entry( indic_syllabic_table, c );
2114 if ((type & 0x00ff) != 0x0007) type = type & 0x00ff;
2118 case 0x0d07: /* Unknown */
2119 case 0x0e07: /* Unknwon */
2120 default: return lex_Generic;
2126 case 0x0014: return lex_Modifier;
2134 case 0x0010: return lex_Consonant;
2135 case 0x0004: return lex_Nukta;
2136 case 0x0005: return lex_Halant;
2138 case 0x0008: return lex_Vowel;
2140 case 0x0107: return lex_Matra_post;
2142 case 0x0307: return lex_Matra_pre;
2148 case 0x0407: return lex_Composed_Vowel;
2149 case 0x0507: return lex_Matra_above;
2150 case 0x0607: return lex_Matra_below;
2151 case 0x000c: return lex_Ra;
2155 static int sinhala_lex(WCHAR c)
2162 case 0x0DDE: return lex_Matra_post;
2164 return unicode_lex(c);
2168 static const VowelComponents Sinhala_vowels[] = {
2169 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2170 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2171 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2172 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2173 {0x0000, {0x0000,0x0000,0x0}}};
2175 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2177 int cCount = cChars;
2180 IndicSyllable *syllables = NULL;
2181 int syllable_count = 0;
2183 if (*pcGlyphs != cChars)
2185 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2189 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
2191 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2193 /* Step 1: Decompose multi part vowels */
2194 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels, pwLogClust, cChars);
2196 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2198 /* Step 2: Reorder within Syllables */
2199 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, sinhala_lex, Reorder_Like_Sinhala, TRUE);
2200 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2202 /* Step 3: Strip dangling joiners */
2203 for (i = 0; i < cCount; i++)
2205 if ((input[i] == 0x200D || input[i] == 0x200C) &&
2206 (i == 0 || input[i-1] == 0x0020 || i == cCount-1 || input[i+1] == 0x0020))
2210 /* Step 4: Base Form application to syllables */
2211 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2213 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, sinhala_lex, NULL, TRUE);
2215 HeapFree(GetProcessHeap(),0,input);
2216 HeapFree(GetProcessHeap(),0,syllables);
2219 static int devanagari_lex(WCHAR c)
2223 case 0x0930: return lex_Ra;
2225 return unicode_lex(c);
2229 static const ConsonantComponents Devanagari_consonants[] ={
2230 {{0x0928, 0x093C, 0x00000}, 0x0929},
2231 {{0x0930, 0x093C, 0x00000}, 0x0931},
2232 {{0x0933, 0x093C, 0x00000}, 0x0934},
2233 {{0x0915, 0x093C, 0x00000}, 0x0958},
2234 {{0x0916, 0x093C, 0x00000}, 0x0959},
2235 {{0x0917, 0x093C, 0x00000}, 0x095A},
2236 {{0x091C, 0x093C, 0x00000}, 0x095B},
2237 {{0x0921, 0x093C, 0x00000}, 0x095C},
2238 {{0x0922, 0x093C, 0x00000}, 0x095D},
2239 {{0x092B, 0x093C, 0x00000}, 0x095E},
2240 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2242 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2244 int cCount = cChars;
2246 IndicSyllable *syllables = NULL;
2247 int syllable_count = 0;
2248 BOOL modern = get_GSUB_Indic2(psa, psc);
2250 if (*pcGlyphs != cChars)
2252 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2256 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2257 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2259 /* Step 1: Compose Consonant and Nukta */
2260 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants, pwLogClust);
2261 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2263 /* Step 2: Reorder within Syllables */
2264 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, devanagari_lex, Reorder_Like_Devanagari, modern);
2265 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2266 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2269 /* Step 3: Base Form application to syllables */
2270 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, devanagari_lex, NULL, modern);
2272 HeapFree(GetProcessHeap(),0,input);
2273 HeapFree(GetProcessHeap(),0,syllables);
2276 static int bengali_lex(WCHAR c)
2280 case 0x09B0: return lex_Ra;
2282 return unicode_lex(c);
2286 static const VowelComponents Bengali_vowels[] = {
2287 {0x09CB, {0x09C7,0x09BE,0x0000}},
2288 {0x09CC, {0x09C7,0x09D7,0x0000}},
2289 {0x0000, {0x0000,0x0000,0x0000}}};
2291 static const ConsonantComponents Bengali_consonants[] = {
2292 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2293 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2294 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2295 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2296 {{0x0000,0x0000,0x0000}, 0x0000}};
2298 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2300 int cCount = cChars;
2302 IndicSyllable *syllables = NULL;
2303 int syllable_count = 0;
2304 BOOL modern = get_GSUB_Indic2(psa, psc);
2306 if (*pcGlyphs != cChars)
2308 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2312 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2313 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2315 /* Step 1: Decompose Vowels and Compose Consonants */
2316 DecomposeVowels(hdc, input, &cCount, Bengali_vowels, pwLogClust, cChars);
2317 ComposeConsonants(hdc, input, &cCount, Bengali_consonants, pwLogClust);
2318 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2320 /* Step 2: Reorder within Syllables */
2321 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, bengali_lex, Reorder_Like_Bengali, modern);
2322 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2323 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2326 /* Step 3: Initial form is only applied to the beginning of words */
2327 for (cCount = cCount - 1 ; cCount >= 0; cCount --)
2329 if (cCount == 0 || input[cCount] == 0x0020) /* space */
2333 if (index > 0) index++;
2335 apply_GSUB_feature_to_glyph(hdc, psa, psc, &pwOutGlyphs[index], 0, 1, &gCount, "init");
2339 /* Step 4: Base Form application to syllables */
2340 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, bengali_lex, NULL, modern);
2342 HeapFree(GetProcessHeap(),0,input);
2343 HeapFree(GetProcessHeap(),0,syllables);
2346 static int gurmukhi_lex(WCHAR c)
2349 return lex_Modifier;
2351 return unicode_lex(c);
2354 static const ConsonantComponents Gurmukhi_consonants[] = {
2355 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2356 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2357 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2358 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2359 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2360 {{0x0000,0x0000,0x0000}, 0x0000}};
2362 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2364 int cCount = cChars;
2366 IndicSyllable *syllables = NULL;
2367 int syllable_count = 0;
2368 BOOL modern = get_GSUB_Indic2(psa, psc);
2370 if (*pcGlyphs != cChars)
2372 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2376 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2377 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2379 /* Step 1: Compose Consonants */
2380 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants, pwLogClust);
2381 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2383 /* Step 2: Reorder within Syllables */
2384 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gurmukhi_lex, Reorder_Like_Bengali, modern);
2385 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2386 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2389 /* Step 3: Base Form application to syllables */
2390 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gurmukhi_lex, NULL, modern);
2392 HeapFree(GetProcessHeap(),0,input);
2393 HeapFree(GetProcessHeap(),0,syllables);
2396 static int gujarati_lex(WCHAR c)
2400 case 0x0AB0: return lex_Ra;
2402 return unicode_lex(c);
2406 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2408 int cCount = cChars;
2410 IndicSyllable *syllables = NULL;
2411 int syllable_count = 0;
2412 BOOL modern = get_GSUB_Indic2(psa, psc);
2414 if (*pcGlyphs != cChars)
2416 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2420 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2421 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2423 /* Step 1: Reorder within Syllables */
2424 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gujarati_lex, Reorder_Like_Devanagari, modern);
2425 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2426 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2429 /* Step 2: Base Form application to syllables */
2430 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gujarati_lex, NULL, modern);
2432 HeapFree(GetProcessHeap(),0,input);
2433 HeapFree(GetProcessHeap(),0,syllables);
2436 static int oriya_lex(WCHAR c)
2440 case 0x0B30: return lex_Ra;
2442 return unicode_lex(c);
2446 static const VowelComponents Oriya_vowels[] = {
2447 {0x0B48, {0x0B47,0x0B56,0x0000}},
2448 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2449 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2450 {0x0000, {0x0000,0x0000,0x0000}}};
2452 static const ConsonantComponents Oriya_consonants[] = {
2453 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2454 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2455 {{0x0000,0x0000,0x0000}, 0x0000}};
2457 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2459 int cCount = cChars;
2461 IndicSyllable *syllables = NULL;
2462 int syllable_count = 0;
2463 BOOL modern = get_GSUB_Indic2(psa, psc);
2465 if (*pcGlyphs != cChars)
2467 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2471 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2472 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2474 /* Step 1: Decompose Vowels and Compose Consonants */
2475 DecomposeVowels(hdc, input, &cCount, Oriya_vowels, pwLogClust, cChars);
2476 ComposeConsonants(hdc, input, &cCount, Oriya_consonants, pwLogClust);
2477 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2479 /* Step 2: Reorder within Syllables */
2480 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, oriya_lex, Reorder_Like_Bengali, modern);
2481 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2482 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2485 /* Step 3: Base Form application to syllables */
2486 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, oriya_lex, NULL, modern);
2488 HeapFree(GetProcessHeap(),0,input);
2489 HeapFree(GetProcessHeap(),0,syllables);
2492 static int tamil_lex(WCHAR c)
2494 return unicode_lex(c);
2497 static const VowelComponents Tamil_vowels[] = {
2498 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2499 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2500 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2501 {0x0000, {0x0000,0x0000,0x0000}}};
2503 static const ConsonantComponents Tamil_consonants[] = {
2504 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2505 {{0x0000,0x0000,0x0000}, 0x0000}};
2507 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2509 int cCount = cChars;
2511 IndicSyllable *syllables = NULL;
2512 int syllable_count = 0;
2513 BOOL modern = get_GSUB_Indic2(psa, psc);
2515 if (*pcGlyphs != cChars)
2517 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2521 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2522 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2524 /* Step 1: Decompose Vowels and Compose Consonants */
2525 DecomposeVowels(hdc, input, &cCount, Tamil_vowels, pwLogClust, cChars);
2526 ComposeConsonants(hdc, input, &cCount, Tamil_consonants, pwLogClust);
2527 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2529 /* Step 2: Reorder within Syllables */
2530 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, tamil_lex, Reorder_Like_Bengali, modern);
2531 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2532 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2535 /* Step 3: Base Form application to syllables */
2536 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, tamil_lex, SecondReorder_Like_Tamil, modern);
2538 HeapFree(GetProcessHeap(),0,input);
2539 HeapFree(GetProcessHeap(),0,syllables);
2542 static int telugu_lex(WCHAR c)
2547 case 0x0C44: return lex_Modifier;
2549 return unicode_lex(c);
2553 static const VowelComponents Telugu_vowels[] = {
2554 {0x0C48, {0x0C46,0x0C56,0x0000}},
2555 {0x0000, {0x0000,0x0000,0x0000}}};
2557 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2559 int cCount = cChars;
2561 IndicSyllable *syllables = NULL;
2562 int syllable_count = 0;
2563 BOOL modern = get_GSUB_Indic2(psa, psc);
2565 if (*pcGlyphs != cChars)
2567 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2571 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2572 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2574 /* Step 1: Decompose Vowels */
2575 DecomposeVowels(hdc, input, &cCount, Telugu_vowels, pwLogClust, cChars);
2576 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2578 /* Step 2: Reorder within Syllables */
2579 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, telugu_lex, Reorder_Like_Bengali, modern);
2580 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2581 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2584 /* Step 3: Base Form application to syllables */
2585 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, telugu_lex, SecondReorder_Like_Telugu, modern);
2587 HeapFree(GetProcessHeap(),0,input);
2588 HeapFree(GetProcessHeap(),0,syllables);
2591 static int kannada_lex(WCHAR c)
2595 case 0x0CB0: return lex_Ra;
2597 return unicode_lex(c);
2601 static const VowelComponents Kannada_vowels[] = {
2602 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2603 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2604 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2605 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2606 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2607 {0x0000, {0x0000,0x0000,0x0000}}};
2609 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2611 int cCount = cChars;
2613 IndicSyllable *syllables = NULL;
2614 int syllable_count = 0;
2615 BOOL modern = get_GSUB_Indic2(psa, psc);
2617 if (*pcGlyphs != cChars)
2619 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2623 input = HeapAlloc(GetProcessHeap(), 0, (cChars*3) * sizeof(WCHAR));
2624 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2626 /* Step 1: Decompose Vowels */
2627 DecomposeVowels(hdc, input, &cCount, Kannada_vowels, pwLogClust, cChars);
2628 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2630 /* Step 2: Reorder within Syllables */
2631 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, kannada_lex, Reorder_Like_Kannada, modern);
2632 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2633 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2636 /* Step 3: Base Form application to syllables */
2637 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, kannada_lex, SecondReorder_Like_Telugu, modern);
2639 HeapFree(GetProcessHeap(),0,input);
2640 HeapFree(GetProcessHeap(),0,syllables);
2643 static int malayalam_lex(WCHAR c)
2645 return unicode_lex(c);
2648 static const VowelComponents Malayalam_vowels[] = {
2649 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2650 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2651 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2652 {0x0000, {0x0000,0x0000,0x0000}}};
2654 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2656 int cCount = cChars;
2658 IndicSyllable *syllables = NULL;
2659 int syllable_count = 0;
2660 BOOL modern = get_GSUB_Indic2(psa, psc);
2662 if (*pcGlyphs != cChars)
2664 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2668 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2669 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2671 /* Step 1: Decompose Vowels */
2672 DecomposeVowels(hdc, input, &cCount, Malayalam_vowels, pwLogClust, cChars);
2673 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2675 /* Step 2: Reorder within Syllables */
2676 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, malayalam_lex, Reorder_Like_Devanagari, modern);
2677 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2678 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2681 /* Step 3: Base Form application to syllables */
2682 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, malayalam_lex, SecondReorder_Like_Tamil, modern);
2684 HeapFree(GetProcessHeap(),0,input);
2685 HeapFree(GetProcessHeap(),0,syllables);
2688 static int khmer_lex(WCHAR c)
2690 return unicode_lex(c);
2693 static void ContextualShape_Khmer(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2695 int cCount = cChars;
2697 IndicSyllable *syllables = NULL;
2698 int syllable_count = 0;
2700 if (*pcGlyphs != cChars)
2702 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2706 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2707 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2709 /* Step 1: Reorder within Syllables */
2710 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, khmer_lex, Reorder_Like_Devanagari, FALSE);
2711 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2712 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2715 /* Step 2: Base Form application to syllables */
2716 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, khmer_lex, NULL, FALSE);
2718 HeapFree(GetProcessHeap(),0,input);
2719 HeapFree(GetProcessHeap(),0,syllables);
2722 static inline BOOL mongolian_wordbreak(WCHAR chr)
2724 return ((chr == 0x0020) || (chr == 0x200C) || (chr == 0x202F) || (chr == 0x180E) || (chr == 0x1800) || (chr == 0x1802) || (chr == 0x1803) || (chr == 0x1805) || (chr == 0x1808) || (chr == 0x1809) || (chr == 0x1807));
2727 static void ContextualShape_Mongolian(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2733 if (*pcGlyphs != cChars)
2735 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2739 if (!psa->fLogicalOrder && psa->fRTL)
2744 load_ot_tables(hdc, psc);
2746 if (!psc->GSUB_Table)
2749 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
2751 for (i = 0; i < cChars; i++)
2753 if (i == 0 || mongolian_wordbreak(pwcChars[i-1]))
2755 if ((i == cChars-1) || mongolian_wordbreak(pwcChars[i+1]))
2756 context_shape[i] = Xn;
2758 context_shape[i] = Xl;
2762 if ((i == cChars-1) || mongolian_wordbreak(pwcChars[i+1]))
2763 context_shape[i] = Xr;
2765 context_shape[i] = Xm;
2769 /* Contextual Shaping */
2771 while(i < *pcGlyphs)
2774 INT prevCount = *pcGlyphs;
2775 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
2776 if (nextIndex > GSUB_E_NOGLYPH)
2778 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
2785 HeapFree(GetProcessHeap(),0,context_shape);
2788 static void ShapeCharGlyphProp_Default( 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)
2792 for (i = 0; i < cGlyphs; i++)
2797 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
2800 for (; k < cChars && pwLogClust[k] == i; k++)
2801 char_index[char_count++] = k;
2804 if (char_count == 0)
2807 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2809 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2810 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2813 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2816 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
2817 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2820 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 )
2823 int initGlyph, finaGlyph;
2827 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2828 memset(spaces,0,cGlyphs);
2830 if (!psa->fLogicalOrder && psa->fRTL)
2832 initGlyph = cGlyphs-1;
2840 finaGlyph = cGlyphs-1;
2845 for (i = 0; i < cGlyphs; i++)
2847 for (k = 0; k < cChars; k++)
2848 if (pwLogClust[k] == i)
2850 if (pwcChars[k] == 0x0020)
2855 for (i = 0; i < cGlyphs; i++)
2859 BOOL isInit, isFinal;
2861 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
2864 for (; k < cChars && pwLogClust[k] == i; k++)
2865 char_index[char_count++] = k;
2868 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
2869 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
2871 if (char_count == 0)
2874 if (char_count == 1)
2876 if (pwcChars[char_index[0]] == 0x0020) /* space */
2878 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
2879 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2881 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
2882 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
2883 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
2885 if (!isInit && !isFinal)
2886 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
2888 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
2890 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2894 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
2895 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
2896 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
2897 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
2898 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
2899 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
2900 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
2901 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
2903 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2905 else if (!isInit && !isFinal)
2906 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2908 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2910 else if (char_count == 2)
2912 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
2913 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
2915 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2917 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2919 else if (!isInit && !isFinal)
2920 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2922 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2925 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
2926 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2927 HeapFree(GetProcessHeap(),0,spaces);
2930 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 )
2934 for (i = 0; i < cGlyphs; i++)
2939 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
2942 for (; k < cChars && pwLogClust[k] == i; k++)
2943 char_index[char_count++] = k;
2946 if (char_count == 0)
2947 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2950 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2951 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2952 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2956 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
2957 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2960 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 )
2966 if (!psa->fLogicalOrder && psa->fRTL)
2973 finaGlyph = cGlyphs-1;
2977 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
2979 for (i = 0; i < cGlyphs; i++)
2985 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
2988 for (; k < cChars && pwLogClust[k] == i; k++)
2989 char_index[char_count++] = k;
2993 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2995 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2997 if (char_count == 0)
3000 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3001 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3003 /* handle Thai SARA AM (U+0E33) differently than GDEF */
3004 if (char_count == 1 && pwcChars[char_index[0]] == 0x0e33)
3005 pGlyphProp[i].sva.fClusterStart = 0;
3008 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3010 /* Do not allow justification between marks and their base */
3011 for (i = 0; i < cGlyphs; i++)
3013 if (!pGlyphProp[i].sva.fClusterStart)
3014 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3018 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)
3022 for (i = 0; i < cGlyphs; i++)
3027 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
3030 for (; k < cChars && pwLogClust[k] == i; k++)
3031 char_index[char_count++] = k;
3034 if (char_count == 0)
3037 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3039 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3040 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3043 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3045 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3046 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3049 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)
3053 for (i = 0; i < cGlyphs; i++)
3058 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
3061 for (; k < cChars && pwLogClust[k] == i; k++)
3062 char_index[char_count++] = k;
3065 if (char_count == 0)
3068 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3070 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3071 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3074 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3076 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3077 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3079 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3080 for (i = 0; i < cGlyphs; i++)
3082 if (!pGlyphProp[i].sva.fClusterStart)
3084 pGlyphProp[i].sva.fDiacritic = 0;
3085 pGlyphProp[i].sva.fZeroWidth = 0;
3090 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)
3094 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3095 for (i = 0; i < cGlyphs; i++)
3100 k = USP10_FindGlyphInLogClust(pwLogClust, cChars, i);
3103 for (; k < cChars && pwLogClust[k] == i; k++)
3104 char_index[char_count++] = k;
3109 /* Most indic scripts do not set fDiacritic or fZeroWidth */
3110 pGlyphProp[i].sva.fDiacritic = FALSE;
3111 pGlyphProp[i].sva.fZeroWidth = FALSE;
3114 if (char_count == 0)
3116 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3120 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3122 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3123 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3126 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3128 pGlyphProp[i].sva.fClusterStart = 0;
3129 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
3130 switch (lexical(pwcChars[char_index[k]]))
3133 case lex_Matra_post:
3134 case lex_Matra_above:
3135 case lex_Matra_below:
3141 /* check for dangling joiners */
3142 if (pwcChars[char_index[k]-1] == 0x0020 || pwcChars[char_index[k]+1] == 0x0020)
3143 pGlyphProp[i].sva.fClusterStart = 1;
3148 pGlyphProp[i].sva.fClusterStart = 1;
3155 IndicSyllable *syllables = NULL;
3156 int syllable_count = 0;
3157 BOOL modern = get_GSUB_Indic2(psa, psc);
3159 Indic_ParseSyllables( hdc, psa, psc, pwcChars, cChars, &syllables, &syllable_count, lexical, modern);
3161 for (i = 0; i < syllable_count; i++)
3164 WORD g = pwLogClust[syllables[i].start];
3165 for (j = syllables[i].start+1; j <= syllables[i].end; j++)
3167 if (pwLogClust[j] != g)
3169 pGlyphProp[pwLogClust[j]].sva.fClusterStart = 0;
3175 HeapFree(GetProcessHeap(), 0, syllables);
3178 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3181 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 )
3183 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, sinhala_lex, FALSE, FALSE);
3186 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 )
3188 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex, TRUE, TRUE);
3191 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 )
3193 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex, TRUE, TRUE);
3196 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 )
3198 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex, TRUE, TRUE);
3201 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 )
3203 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex, TRUE, TRUE);
3206 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 )
3208 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex, TRUE, TRUE);
3211 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 )
3213 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, tamil_lex, TRUE, TRUE);
3216 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 )
3218 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, telugu_lex, TRUE, TRUE);
3221 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 )
3223 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, kannada_lex, TRUE, TRUE);
3226 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 )
3228 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, malayalam_lex, TRUE, TRUE);
3231 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 )
3233 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, khmer_lex, TRUE, TRUE);
3236 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)
3238 if (ShapingData[psa->eScript].charGlyphPropProc)
3239 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3241 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3244 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
3246 load_ot_tables(hdc, psc);
3248 if (ShapingData[psa->eScript].contextProc)
3249 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
3252 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)
3257 if (!rpRangeProperties)
3260 load_ot_tables(hdc, psc);
3262 if (!psc->GSUB_Table)
3265 if (!psa->fLogicalOrder && psa->fRTL)
3270 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3272 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3273 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
3277 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
3279 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3280 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
3282 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
3285 void SHAPE_ApplyOpenTypePositions(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WORD* pwGlyphs, INT cGlyphs, int *piAdvance, GOFFSET *pGoffset )
3287 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3290 rpRangeProperties = &ShapingData[psa->eScript].defaultGPOSTextRange;
3292 if (!rpRangeProperties)
3295 load_ot_tables(hdc, psc);
3297 if (!psc->GPOS_Table || !psc->otm)
3300 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3302 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3304 LoadedFeature *feature;
3306 feature = load_OT_feature(hdc, psa, psc, FEATURE_GPOS_TABLE, (const char*)&rpRangeProperties->potfRecords[i].tagFeature);
3310 GPOS_apply_feature(psc->otm, &psc->lf, psa, piAdvance, psc->GPOS_Table, feature, pwGlyphs, cGlyphs, pGoffset);
3315 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
3317 LoadedFeature *feature;
3320 if (!ShapingData[psa->eScript].requiredFeatures)
3323 load_ot_tables(hdc, psc);
3325 /* we need to have at least one of the required features */
3327 while (ShapingData[psa->eScript].requiredFeatures[i])
3329 feature = load_OT_feature(hdc, psa, psc, FEATURE_ALL_TABLES, ShapingData[psa->eScript].requiredFeatures[i]);
3335 return USP_E_SCRIPT_NOT_IN_FONT;
3338 HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc,
3339 SCRIPT_ANALYSIS *psa, int cMaxTags,
3340 OPENTYPE_TAG *pScriptTags, int *pcTags)
3343 OPENTYPE_TAG searching = 0x00000000;
3345 load_ot_tables(hdc, psc);
3347 if (psa && scriptInformation[psa->eScript].scriptTag)
3348 searching = scriptInformation[psa->eScript].scriptTag;
3350 hr = OpenType_GetFontScriptTags(psc, searching, cMaxTags, pScriptTags, pcTags);
3356 HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc,
3357 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
3358 int cMaxTags, OPENTYPE_TAG *pLangSysTags,
3362 OPENTYPE_TAG searching = 0x00000000;
3363 BOOL fellback = FALSE;
3365 load_ot_tables(hdc, psc);
3367 if (psa && psc->userLang != 0)
3368 searching = psc->userLang;
3370 hr = OpenType_GetFontLanguageTags(psc, tagScript, searching, cMaxTags, pLangSysTags, pcTags);
3374 hr = OpenType_GetFontLanguageTags(psc, MS_MAKE_TAG('l','a','t','n'), searching, cMaxTags, pLangSysTags, pcTags);
3377 if (FAILED(hr) || fellback)
3379 if (SUCCEEDED(hr) && fellback && psa)
3384 HRESULT SHAPE_GetFontFeatureTags( HDC hdc, ScriptCache *psc,
3385 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
3386 OPENTYPE_TAG tagLangSys, int cMaxTags,
3387 OPENTYPE_TAG *pFeatureTags, int *pcTags)
3390 BOOL filter = FALSE;
3392 load_ot_tables(hdc, psc);
3394 if (psa && scriptInformation[psa->eScript].scriptTag)
3396 FIXME("Filtering not implemented\n");
3400 hr = OpenType_GetFontFeatureTags(psc, tagScript, tagLangSys, filter, 0x00000000, FEATURE_ALL_TABLES, cMaxTags, pFeatureTags, pcTags, NULL);