2 * Implementation of Shaping for the Uniscribe Script Processor (usp10.dll)
4 * Copyright 2010 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "usp10_internal.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe
);
26 #define FIRST_ARABIC_CHAR 0x0600
27 #define LAST_ARABIC_CHAR 0x06ff
29 typedef VOID (*ContextualShapingProc
)(HDC
, ScriptCache
*, SCRIPT_ANALYSIS
*,
30 WCHAR
*, INT
, WORD
*, INT
*, INT
, WORD
*);
32 static void ContextualShape_Control(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
33 static void ContextualShape_Arabic(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
34 static void ContextualShape_Hebrew(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
35 static void ContextualShape_Syriac(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
36 static void ContextualShape_Thaana(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
37 static void ContextualShape_Phags_pa(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
38 static void ContextualShape_Thai(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
39 static void ContextualShape_Lao(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
40 static void ContextualShape_Sinhala(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
41 static void ContextualShape_Devanagari(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
42 static void ContextualShape_Bengali(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
43 static void ContextualShape_Gurmukhi(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
44 static void ContextualShape_Gujarati(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
45 static void ContextualShape_Oriya(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
46 static void ContextualShape_Tamil(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
47 static void ContextualShape_Telugu(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
48 static void ContextualShape_Kannada(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
49 static void ContextualShape_Malayalam(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
50 static void ContextualShape_Khmer(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
51 static void ContextualShape_Mongolian(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
);
53 typedef VOID (*ShapeCharGlyphPropProc
)( HDC
, ScriptCache
*, SCRIPT_ANALYSIS
*, const WCHAR
*, const INT
, const WORD
*, const INT
, WORD
*, SCRIPT_CHARPROP
*, SCRIPT_GLYPHPROP
*);
55 static void ShapeCharGlyphProp_Default( ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
);
56 static void ShapeCharGlyphProp_Control( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
57 static void ShapeCharGlyphProp_Latin( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
58 static void ShapeCharGlyphProp_Arabic( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
59 static void ShapeCharGlyphProp_Hebrew( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
60 static void ShapeCharGlyphProp_Thai( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
61 static void ShapeCharGlyphProp_None( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
62 static void ShapeCharGlyphProp_Tibet( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
63 static void ShapeCharGlyphProp_Sinhala( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
64 static void ShapeCharGlyphProp_Devanagari( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
65 static void ShapeCharGlyphProp_Bengali( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
66 static void ShapeCharGlyphProp_Gurmukhi( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
67 static void ShapeCharGlyphProp_Gujarati( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
68 static void ShapeCharGlyphProp_Oriya( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
69 static void ShapeCharGlyphProp_Tamil( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
70 static void ShapeCharGlyphProp_Telugu( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
71 static void ShapeCharGlyphProp_Kannada( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
72 static void ShapeCharGlyphProp_Malayalam( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
73 static void ShapeCharGlyphProp_Khmer( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
);
75 extern const unsigned short indic_syllabic_table
[];
76 extern const unsigned short wine_shaping_table
[];
77 extern const unsigned short wine_shaping_forms
[LAST_ARABIC_CHAR
- FIRST_ARABIC_CHAR
+ 1][4];
99 typedef struct tagVowelComponents
105 typedef struct tagConsonantComponents
109 } ConsonantComponents
;
111 typedef void (*second_reorder_function
)(LPWSTR pwChar
, IndicSyllable
*syllable
,WORD
* pwGlyphs
, IndicSyllable
* glyph_index
, lexical_function lex
);
113 typedef int (*combining_lexical_function
)(WCHAR c
);
115 /* the orders of joined_forms and contextual_features need to line up */
116 static const char* contextual_features
[] =
128 static OPENTYPE_FEATURE_RECORD standard_features
[] =
130 { MS_MAKE_TAG('c','c','m','p'), 1},
131 { MS_MAKE_TAG('l','o','c','l'), 1},
134 static OPENTYPE_FEATURE_RECORD latin_features
[] =
136 { MS_MAKE_TAG('l','o','c','l'), 1},
137 { MS_MAKE_TAG('c','c','m','p'), 1},
138 { MS_MAKE_TAG('l','i','g','a'), 1},
139 { MS_MAKE_TAG('c','l','i','g'), 1},
142 static OPENTYPE_FEATURE_RECORD latin_gpos_features
[] =
144 { MS_MAKE_TAG('k','e','r','n'), 1},
145 { MS_MAKE_TAG('m','a','r','k'), 1},
146 { MS_MAKE_TAG('m','k','m','k'), 1},
149 static OPENTYPE_FEATURE_RECORD arabic_features
[] =
151 { MS_MAKE_TAG('r','l','i','g'), 1},
152 { MS_MAKE_TAG('c','a','l','t'), 1},
153 { MS_MAKE_TAG('l','i','g','a'), 1},
154 { MS_MAKE_TAG('d','l','i','g'), 1},
155 { MS_MAKE_TAG('c','s','w','h'), 1},
156 { MS_MAKE_TAG('m','s','e','t'), 1},
159 static const char* required_arabic_features
[] =
168 static OPENTYPE_FEATURE_RECORD arabic_gpos_features
[] =
170 { MS_MAKE_TAG('c','u','r','s'), 1},
171 { MS_MAKE_TAG('k','e','r','n'), 1},
172 { MS_MAKE_TAG('m','a','r','k'), 1},
173 { MS_MAKE_TAG('m','k','m','k'), 1},
176 static OPENTYPE_FEATURE_RECORD hebrew_features
[] =
178 { MS_MAKE_TAG('c','c','m','p'), 1},
179 { MS_MAKE_TAG('d','l','i','g'), 0},
182 static OPENTYPE_FEATURE_RECORD hebrew_gpos_features
[] =
184 { MS_MAKE_TAG('k','e','r','n'), 1},
185 { MS_MAKE_TAG('m','a','r','k'), 1},
188 static OPENTYPE_FEATURE_RECORD syriac_features
[] =
190 { MS_MAKE_TAG('r','l','i','g'), 1},
191 { MS_MAKE_TAG('c','a','l','t'), 1},
192 { MS_MAKE_TAG('l','i','g','a'), 1},
193 { MS_MAKE_TAG('d','l','i','g'), 1},
196 static const char* required_syriac_features
[] =
208 static OPENTYPE_FEATURE_RECORD syriac_gpos_features
[] =
210 { MS_MAKE_TAG('k','e','r','n'), 1},
211 { MS_MAKE_TAG('m','a','r','k'), 1},
212 { MS_MAKE_TAG('m','k','m','k'), 1},
215 static OPENTYPE_FEATURE_RECORD sinhala_features
[] =
217 /* Presentation forms */
218 { MS_MAKE_TAG('b','l','w','s'), 1},
219 { MS_MAKE_TAG('a','b','v','s'), 1},
220 { MS_MAKE_TAG('p','s','t','s'), 1},
223 static OPENTYPE_FEATURE_RECORD tibetan_features
[] =
225 { MS_MAKE_TAG('a','b','v','s'), 1},
226 { MS_MAKE_TAG('b','l','w','s'), 1},
229 static OPENTYPE_FEATURE_RECORD tibetan_gpos_features
[] =
231 { MS_MAKE_TAG('a','b','v','m'), 1},
232 { MS_MAKE_TAG('b','l','w','m'), 1},
235 static OPENTYPE_FEATURE_RECORD phags_features
[] =
237 { MS_MAKE_TAG('a','b','v','s'), 1},
238 { MS_MAKE_TAG('b','l','w','s'), 1},
239 { MS_MAKE_TAG('c','a','l','t'), 1},
242 static OPENTYPE_FEATURE_RECORD thai_features
[] =
244 { MS_MAKE_TAG('c','c','m','p'), 1},
247 static OPENTYPE_FEATURE_RECORD thai_gpos_features
[] =
249 { MS_MAKE_TAG('k','e','r','n'), 1},
250 { MS_MAKE_TAG('m','a','r','k'), 1},
251 { MS_MAKE_TAG('m','k','m','k'), 1},
254 static const char* required_lao_features
[] =
260 static const char* required_devanagari_features
[] =
276 static OPENTYPE_FEATURE_RECORD devanagari_features
[] =
278 { MS_MAKE_TAG('p','r','e','s'), 1},
279 { MS_MAKE_TAG('a','b','v','s'), 1},
280 { MS_MAKE_TAG('b','l','w','s'), 1},
281 { MS_MAKE_TAG('p','s','t','s'), 1},
282 { MS_MAKE_TAG('h','a','l','n'), 1},
283 { MS_MAKE_TAG('c','a','l','t'), 1},
286 static OPENTYPE_FEATURE_RECORD devanagari_gpos_features
[] =
288 { MS_MAKE_TAG('k','e','r','n'), 1},
289 { MS_MAKE_TAG('d','i','s','t'), 1},
290 { MS_MAKE_TAG('a','b','v','m'), 1},
291 { MS_MAKE_TAG('b','l','w','m'), 1},
294 static OPENTYPE_FEATURE_RECORD myanmar_features
[] =
296 { MS_MAKE_TAG('l','i','g','a'), 1},
297 { MS_MAKE_TAG('c','l','i','g'), 1},
300 static const char* required_bengali_features
[] =
317 static const char* required_gurmukhi_features
[] =
336 static const char* required_oriya_features
[] =
353 static const char* required_tamil_features
[] =
369 static const char* required_telugu_features
[] =
387 static OPENTYPE_FEATURE_RECORD khmer_features
[] =
389 { MS_MAKE_TAG('p','r','e','s'), 1},
390 { MS_MAKE_TAG('b','l','w','s'), 1},
391 { MS_MAKE_TAG('a','b','v','s'), 1},
392 { MS_MAKE_TAG('p','s','t','s'), 1},
393 { MS_MAKE_TAG('c','l','i','g'), 1},
396 static const char* required_khmer_features
[] =
410 static OPENTYPE_FEATURE_RECORD khmer_gpos_features
[] =
412 { MS_MAKE_TAG('d','i','s','t'), 1},
413 { MS_MAKE_TAG('b','l','w','m'), 1},
414 { MS_MAKE_TAG('a','b','v','m'), 1},
415 { MS_MAKE_TAG('m','k','m','k'), 1},
418 static OPENTYPE_FEATURE_RECORD ethiopic_features
[] =
420 { MS_MAKE_TAG('c','c','m','p'), 1},
421 { MS_MAKE_TAG('l','o','c','l'), 1},
422 { MS_MAKE_TAG('c','a','l','t'), 1},
423 { MS_MAKE_TAG('l','i','g','a'), 1},
426 static OPENTYPE_FEATURE_RECORD mongolian_features
[] =
428 { MS_MAKE_TAG('c','c','m','p'), 1},
429 { MS_MAKE_TAG('l','o','c','l'), 1},
430 { MS_MAKE_TAG('c','a','l','t'), 1},
431 { MS_MAKE_TAG('r','l','i','g'), 1},
434 typedef struct ScriptShapeDataTag
{
435 TEXTRANGE_PROPERTIES defaultTextRange
;
436 TEXTRANGE_PROPERTIES defaultGPOSTextRange
;
437 const char** requiredFeatures
;
438 OPENTYPE_TAG newOtTag
;
439 ContextualShapingProc contextProc
;
440 ShapeCharGlyphPropProc charGlyphPropProc
;
443 /* in order of scripts */
444 static const ScriptShapeData ShapingData
[] =
446 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
447 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
448 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
449 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
450 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, ContextualShape_Control
, ShapeCharGlyphProp_Control
},
451 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
452 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
453 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
454 {{ hebrew_features
, 2}, {hebrew_gpos_features
, 2}, NULL
, 0, ContextualShape_Hebrew
, ShapeCharGlyphProp_Hebrew
},
455 {{ syriac_features
, 4}, {syriac_gpos_features
, 3}, required_syriac_features
, 0, ContextualShape_Syriac
, ShapeCharGlyphProp_None
},
456 {{ arabic_features
, 6}, {arabic_gpos_features
, 4}, required_arabic_features
, 0, ContextualShape_Arabic
, ShapeCharGlyphProp_Arabic
},
457 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, ContextualShape_Thaana
, ShapeCharGlyphProp_None
},
458 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
459 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
460 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
461 {{ standard_features
, 2}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, NULL
},
462 {{ sinhala_features
, 3}, {NULL
, 0}, NULL
, 0, ContextualShape_Sinhala
, ShapeCharGlyphProp_Sinhala
},
463 {{ tibetan_features
, 2}, {tibetan_gpos_features
, 2}, NULL
, 0, NULL
, ShapeCharGlyphProp_Tibet
},
464 {{ tibetan_features
, 2}, {tibetan_gpos_features
, 2}, NULL
, 0, NULL
, ShapeCharGlyphProp_Tibet
},
465 {{ phags_features
, 3}, {NULL
, 0}, NULL
, 0, ContextualShape_Phags_pa
, ShapeCharGlyphProp_Thai
},
466 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, ShapeCharGlyphProp_Thai
},
467 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, NULL
},
468 {{ thai_features
, 1}, {thai_gpos_features
, 3}, required_lao_features
, 0, ContextualShape_Lao
, ShapeCharGlyphProp_Thai
},
469 {{ thai_features
, 1}, {thai_gpos_features
, 3}, required_lao_features
, 0, ContextualShape_Lao
, ShapeCharGlyphProp_Thai
},
470 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari
, ShapeCharGlyphProp_Devanagari
},
471 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari
, NULL
},
472 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, ShapeCharGlyphProp_Bengali
},
473 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, NULL
},
474 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_bengali_features
, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali
, ShapeCharGlyphProp_Bengali
},
475 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_gurmukhi_features
, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi
, ShapeCharGlyphProp_Gurmukhi
},
476 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_gurmukhi_features
, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi
, NULL
},
477 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, ShapeCharGlyphProp_Gujarati
},
478 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, NULL
},
479 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_devanagari_features
, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati
, ShapeCharGlyphProp_Gujarati
},
480 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_oriya_features
, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya
, ShapeCharGlyphProp_Oriya
},
481 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_oriya_features
, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya
, NULL
},
482 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_tamil_features
, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil
, ShapeCharGlyphProp_Tamil
},
483 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_tamil_features
, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil
, NULL
},
484 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu
, ShapeCharGlyphProp_Telugu
},
485 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu
, NULL
},
486 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada
, ShapeCharGlyphProp_Kannada
},
487 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada
, NULL
},
488 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam
, ShapeCharGlyphProp_Malayalam
},
489 {{ devanagari_features
, 6}, {devanagari_gpos_features
, 4}, required_telugu_features
, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam
, NULL
},
490 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
491 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
492 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
493 {{ myanmar_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
494 {{ myanmar_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
495 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
496 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
497 {{ standard_features
, 2}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
498 {{ khmer_features
, 5}, {khmer_gpos_features
, 4}, required_khmer_features
, 0, ContextualShape_Khmer
, ShapeCharGlyphProp_Khmer
},
499 {{ khmer_features
, 5}, {khmer_gpos_features
, 4}, required_khmer_features
, 0, ContextualShape_Khmer
, ShapeCharGlyphProp_Khmer
},
500 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
501 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
502 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
503 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
504 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
505 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
506 {{ ethiopic_features
, 4}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
507 {{ ethiopic_features
, 4}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
508 {{ mongolian_features
, 4}, {NULL
, 0}, NULL
, 0, ContextualShape_Mongolian
, NULL
},
509 {{ mongolian_features
, 4}, {NULL
, 0}, NULL
, 0, ContextualShape_Mongolian
, NULL
},
510 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
511 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
512 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
513 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
514 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
515 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
516 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
517 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
518 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
519 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
520 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
521 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
522 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
523 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
524 {{ NULL
, 0}, {NULL
, 0}, NULL
, 0, NULL
, NULL
},
525 {{ hebrew_features
, 2}, {hebrew_gpos_features
, 2}, NULL
, 0, ContextualShape_Hebrew
, NULL
},
526 {{ latin_features
, 4}, {latin_gpos_features
, 3}, NULL
, 0, NULL
, ShapeCharGlyphProp_Latin
},
527 {{ thai_features
, 1}, {thai_gpos_features
, 3}, NULL
, 0, ContextualShape_Thai
, ShapeCharGlyphProp_Thai
},
530 extern scriptData scriptInformation
[];
532 static INT
GSUB_apply_feature_all_lookups(LPCVOID header
, LoadedFeature
*feature
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
535 int out_index
= GSUB_E_NOGLYPH
;
537 TRACE("%i lookups\n", feature
->lookup_count
);
538 for (i
= 0; i
< feature
->lookup_count
; i
++)
540 out_index
= OpenType_apply_GSUB_lookup(header
, feature
->lookups
[i
], glyphs
, glyph_index
, write_dir
, glyph_count
);
541 if (out_index
!= GSUB_E_NOGLYPH
)
544 if (out_index
== GSUB_E_NOGLYPH
)
545 TRACE("lookups found no glyphs\n");
549 out2
= GSUB_apply_feature_all_lookups(header
, feature
, glyphs
, glyph_index
, write_dir
, glyph_count
);
550 if (out2
!=GSUB_E_NOGLYPH
)
556 static OPENTYPE_TAG
get_opentype_script(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
, BOOL tryNew
)
560 if (psc
->userScript
!= 0)
562 if (tryNew
&& ShapingData
[psa
->eScript
].newOtTag
!= 0 && psc
->userScript
== scriptInformation
[psa
->eScript
].scriptTag
)
563 return ShapingData
[psa
->eScript
].newOtTag
;
565 return psc
->userScript
;
568 if (tryNew
&& ShapingData
[psa
->eScript
].newOtTag
!= 0)
569 return ShapingData
[psa
->eScript
].newOtTag
;
571 if (scriptInformation
[psa
->eScript
].scriptTag
)
572 return scriptInformation
[psa
->eScript
].scriptTag
;
575 * fall back to the font charset
577 charset
= GetTextCharsetInfo(hdc
, NULL
, 0x0);
581 case BALTIC_CHARSET
: return MS_MAKE_TAG('l','a','t','n');
582 case CHINESEBIG5_CHARSET
: return MS_MAKE_TAG('h','a','n','i');
583 case EASTEUROPE_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
584 case GB2312_CHARSET
: return MS_MAKE_TAG('h','a','n','i');
585 case GREEK_CHARSET
: return MS_MAKE_TAG('g','r','e','k');
586 case HANGUL_CHARSET
: return MS_MAKE_TAG('h','a','n','g');
587 case RUSSIAN_CHARSET
: return MS_MAKE_TAG('c','y','r','l');
588 case SHIFTJIS_CHARSET
: return MS_MAKE_TAG('k','a','n','a');
589 case TURKISH_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
590 case VIETNAMESE_CHARSET
: return MS_MAKE_TAG('l','a','t','n');
591 case JOHAB_CHARSET
: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
592 case ARABIC_CHARSET
: return MS_MAKE_TAG('a','r','a','b');
593 case HEBREW_CHARSET
: return MS_MAKE_TAG('h','e','b','r');
594 case THAI_CHARSET
: return MS_MAKE_TAG('t','h','a','i');
595 default: return MS_MAKE_TAG('l','a','t','n');
599 static LoadedFeature
* load_OT_feature(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
, char tableType
, const char* feat
)
601 LoadedFeature
*feature
= NULL
;
603 if (psc
->GSUB_Table
|| psc
->GPOS_Table
)
607 OPENTYPE_TAG language
;
608 OPENTYPE_TAG script
= 0x00000000;
613 script
= get_opentype_script(hdc
,psa
,psc
,(attempt
==2));
614 if (psc
->userLang
!= 0)
615 language
= psc
->userLang
;
617 language
= MS_MAKE_TAG('d','f','l','t');
620 OpenType_GetFontFeatureTags(psc
, script
, language
, FALSE
, MS_MAKE_TAG(feat
[0],feat
[1],feat
[2],feat
[3]), tableType
, 1, &tags
, &cTags
, &feature
);
622 } while(attempt
&& !feature
);
624 /* try in the default (latin) table */
625 if (!feature
&& !script
)
626 OpenType_GetFontFeatureTags(psc
, MS_MAKE_TAG('l','a','t','n'), MS_MAKE_TAG('d','f','l','t'), FALSE
, MS_MAKE_TAG(feat
[0],feat
[1],feat
[2],feat
[3]), tableType
, 1, &tags
, &cTags
, &feature
);
629 TRACE("Feature %s located at %p\n",debugstr_an(feat
,4),feature
);
633 static INT
apply_GSUB_feature_to_glyph(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, WORD
*glyphs
, INT index
, INT write_dir
, INT
* glyph_count
, const char* feat
)
635 LoadedFeature
*feature
;
637 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, feat
);
639 return GSUB_E_NOFEATURE
;
641 TRACE("applying feature %s\n",feat
);
642 return GSUB_apply_feature_all_lookups(psc
->GSUB_Table
, feature
, glyphs
, index
, write_dir
, glyph_count
);
645 static VOID
*load_gsub_table(HDC hdc
)
647 VOID
* GSUB_Table
= NULL
;
648 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL
, 0);
649 if (length
!= GDI_ERROR
)
651 GSUB_Table
= HeapAlloc(GetProcessHeap(),0,length
);
652 GetFontData(hdc
, MS_MAKE_TAG('G', 'S', 'U', 'B'), 0, GSUB_Table
, length
);
653 TRACE("Loaded GSUB table of %i bytes\n",length
);
658 static VOID
*load_gpos_table(HDC hdc
)
660 VOID
* GPOS_Table
= NULL
;
661 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, NULL
, 0);
662 if (length
!= GDI_ERROR
)
664 GPOS_Table
= HeapAlloc(GetProcessHeap(),0,length
);
665 GetFontData(hdc
, MS_MAKE_TAG('G', 'P', 'O', 'S'), 0, GPOS_Table
, length
);
666 TRACE("Loaded GPOS table of %i bytes\n",length
);
671 static VOID
*load_gdef_table(HDC hdc
)
673 VOID
* GDEF_Table
= NULL
;
674 int length
= GetFontData(hdc
, MS_MAKE_TAG('G', 'D', 'E', 'F'), 0, NULL
, 0);
675 if (length
!= GDI_ERROR
)
677 GDEF_Table
= HeapAlloc(GetProcessHeap(),0,length
);
678 GetFontData(hdc
, MS_MAKE_TAG('G', 'D', 'E', 'F'), 0, GDEF_Table
, length
);
679 TRACE("Loaded GDEF table of %i bytes\n",length
);
684 static VOID
load_ot_tables(HDC hdc
, ScriptCache
*psc
)
686 if (!psc
->GSUB_Table
)
687 psc
->GSUB_Table
= load_gsub_table(hdc
);
688 if (!psc
->GPOS_Table
)
689 psc
->GPOS_Table
= load_gpos_table(hdc
);
690 if (!psc
->GDEF_Table
)
691 psc
->GDEF_Table
= load_gdef_table(hdc
);
694 INT
SHAPE_does_GSUB_feature_apply_to_chars(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, const WCHAR
*chars
, INT write_dir
, INT count
, const char* feature
)
697 INT glyph_count
= count
;
700 glyphs
= HeapAlloc(GetProcessHeap(),0,sizeof(WORD
)*(count
*2));
701 GetGlyphIndicesW(hdc
, chars
, count
, glyphs
, 0);
702 rc
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, glyphs
, 0, write_dir
, &glyph_count
, feature
);
703 if (rc
> GSUB_E_NOGLYPH
)
704 rc
= count
- glyph_count
;
708 HeapFree(GetProcessHeap(),0,glyphs
);
712 static void UpdateClustersFromGlyphProp(const int cGlyphs
, const int cChars
, WORD
* pwLogClust
, SCRIPT_GLYPHPROP
*pGlyphProp
)
716 for (i
= 0; i
< cGlyphs
; i
++)
718 if (!pGlyphProp
[i
].sva
.fClusterStart
)
721 for (j
= 0; j
< cChars
; j
++)
723 if (pwLogClust
[j
] == i
)
726 while (k
>= 0 && k
<cChars
&& !pGlyphProp
[pwLogClust
[k
]].sva
.fClusterStart
)
728 if (k
>= 0 && k
<cChars
&& pGlyphProp
[pwLogClust
[k
]].sva
.fClusterStart
)
729 pwLogClust
[j
] = pwLogClust
[k
];
736 static void UpdateClusters(int nextIndex
, int changeCount
, int write_dir
, int chars
, WORD
* pwLogClust
)
738 if (changeCount
== 0)
743 int target_glyph
= nextIndex
- write_dir
;
745 int target_index
= -1;
746 int replacing_glyph
= -1;
748 int top_logclust
= 0;
753 target_glyph
= nextIndex
- changeCount
;
755 target_glyph
= nextIndex
+ (changeCount
+ 1);
758 seeking_glyph
= target_glyph
;
759 for (i
= 0; i
< chars
; i
++)
760 if (pwLogClust
[i
] > top_logclust
)
761 top_logclust
= pwLogClust
[i
];
765 for (i
= 0; i
< chars
; i
++)
767 if (pwLogClust
[i
] == seeking_glyph
)
774 for (i
= chars
- 1; i
>= 0; i
--)
776 if (pwLogClust
[i
] == seeking_glyph
)
782 if (target_index
== -1)
785 while (target_index
== -1 && seeking_glyph
<= top_logclust
);
787 if (target_index
== -1)
789 ERR("Unable to find target glyph\n");
796 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
798 if (pwLogClust
[i
] == target_glyph
)
800 if(pwLogClust
[i
] == replacing_glyph
)
801 pwLogClust
[i
] = target_glyph
;
805 if (changed
>= changeCount
)
807 replacing_glyph
= pwLogClust
[i
];
808 pwLogClust
[i
] = target_glyph
;
815 /* renumber trailing indexes*/
816 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
818 if (pwLogClust
[i
] != target_glyph
)
819 pwLogClust
[i
] += changeCount
;
824 for(i
= target_index
; i
< chars
&& i
>= 0; i
+=write_dir
)
825 pwLogClust
[i
] += changeCount
;
830 static int apply_GSUB_feature(HDC hdc
, SCRIPT_ANALYSIS
*psa
, ScriptCache
* psc
, WORD
*pwOutGlyphs
, int write_dir
, INT
* pcGlyphs
, INT cChars
, const char* feat
, WORD
*pwLogClust
)
834 LoadedFeature
*feature
;
837 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, feat
);
839 return GSUB_E_NOFEATURE
;
841 TRACE("applying feature %s: %i lookups\n",debugstr_an(feat
,4),feature
->lookup_count
);
842 for (lookup_index
= 0; lookup_index
< feature
->lookup_count
; lookup_index
++)
850 TRACE("applying lookup (%i/%i)\n",lookup_index
,feature
->lookup_count
);
851 while(i
< *pcGlyphs
&& i
>= 0)
854 INT prevCount
= *pcGlyphs
;
856 nextIndex
= OpenType_apply_GSUB_lookup(psc
->GSUB_Table
, feature
->lookups
[lookup_index
], pwOutGlyphs
, i
, write_dir
, pcGlyphs
);
857 if (*pcGlyphs
!= prevCount
)
859 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, write_dir
, cChars
, pwLogClust
);
868 return GSUB_E_NOFEATURE
;
871 static VOID
GPOS_apply_feature(ScriptCache
*psc
, LPOUTLINETEXTMETRICW lpotm
, LPLOGFONTW lplogfont
, const SCRIPT_ANALYSIS
*analysis
, INT
* piAdvance
, LoadedFeature
*feature
, const WORD
*glyphs
, INT glyph_count
, GOFFSET
*pGoffset
)
875 TRACE("%i lookups\n", feature
->lookup_count
);
876 for (i
= 0; i
< feature
->lookup_count
; i
++)
879 for (j
= 0; j
< glyph_count
; )
880 j
= OpenType_apply_GPOS_lookup(psc
, lpotm
, lplogfont
, analysis
, piAdvance
, feature
->lookups
[i
], glyphs
, j
, glyph_count
, pGoffset
);
884 static inline BOOL
get_GSUB_Indic2(SCRIPT_ANALYSIS
*psa
, ScriptCache
*psc
)
890 hr
= OpenType_GetFontScriptTags(psc
, ShapingData
[psa
->eScript
].newOtTag
, 1, &tag
, &count
);
892 return(SUCCEEDED(hr
));
895 static void insert_glyph(WORD
*pwGlyphs
, INT
*pcGlyphs
, INT cChars
, INT write_dir
, WORD glyph
, INT index
, WORD
*pwLogClust
)
898 for (i
= *pcGlyphs
; i
>=index
; i
--)
899 pwGlyphs
[i
+1] = pwGlyphs
[i
];
900 pwGlyphs
[index
] = glyph
;
901 *pcGlyphs
= *pcGlyphs
+1;
903 UpdateClusters(index
-3, 1, write_dir
, cChars
, pwLogClust
);
905 UpdateClusters(index
, 1, write_dir
, cChars
, pwLogClust
);
908 static void mark_invalid_combinations(HDC hdc
, const WCHAR
* pwcChars
, INT cChars
, WORD
*pwGlyphs
, INT
*pcGlyphs
, INT write_dir
, WORD
*pwLogClust
, combining_lexical_function lex
)
912 WCHAR invalid
= 0x25cc;
915 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
917 /* Mark invalid combinations */
918 for (i
= 0; i
< cChars
; i
++)
919 context_type
[i
] = lex(pwcChars
[i
]);
921 GetGlyphIndicesW(hdc
, &invalid
, 1, &invalid_glyph
, 0);
922 for (i
= 1, g
=1; i
< cChars
- 1; i
++, g
++)
924 if (context_type
[i
] != 0 && context_type
[i
+write_dir
]==context_type
[i
])
926 insert_glyph(pwGlyphs
, pcGlyphs
, cChars
, write_dir
, invalid_glyph
, g
, pwLogClust
);
931 HeapFree(GetProcessHeap(),0,context_type
);
934 static void ContextualShape_Control(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
937 for (i
=0; i
< cChars
; i
++)
941 case 0x000D: pwOutGlyphs
[i
] = psc
->sfp
.wgBlank
; break;
943 if (pwcChars
[i
] < 0x1C)
944 pwOutGlyphs
[i
] = psc
->sfp
.wgDefault
;
946 pwOutGlyphs
[i
] = psc
->sfp
.wgBlank
;
951 static WCHAR
neighbour_char(int i
, int delta
, const WCHAR
* chars
, INT cchLen
)
955 if ( i
+ delta
>= cchLen
)
963 static CHAR
neighbour_joining_type(int i
, int delta
, const CHAR
* context_type
, INT cchLen
, SCRIPT_ANALYSIS
*psa
)
967 if (psa
->fLinkBefore
)
972 if ( i
+ delta
>= cchLen
)
982 if (context_type
[i
] == jtT
)
983 return neighbour_joining_type(i
,delta
,context_type
,cchLen
,psa
);
985 return context_type
[i
];
988 static inline BOOL
right_join_causing(CHAR joining_type
)
990 return (joining_type
== jtL
|| joining_type
== jtD
|| joining_type
== jtC
);
993 static inline BOOL
left_join_causing(CHAR joining_type
)
995 return (joining_type
== jtR
|| joining_type
== jtD
|| joining_type
== jtC
);
998 static inline BOOL
word_break_causing(WCHAR chr
)
1000 /* we are working within a string of characters already guareented to
1001 be within one script, Syriac, so we do not worry about any character
1002 other than the space character outside of that range */
1003 return (chr
== 0 || chr
== 0x20 );
1006 static int combining_lexical_Arabic(WCHAR c
)
1008 enum {Arab_Norm
= 0, Arab_DIAC1
, Arab_DIAC2
, Arab_DIAC3
, Arab_DIAC4
, Arab_DIAC5
, Arab_DIAC6
, Arab_DIAC7
, Arab_DIAC8
};
1019 case 0x06E1: return Arab_DIAC1
;
1022 case 0x0656: return Arab_DIAC2
;
1023 case 0x0651: return Arab_DIAC3
;
1039 case 0x06EC: return Arab_DIAC4
;
1042 case 0x06ED: return Arab_DIAC5
;
1043 case 0x0670: return Arab_DIAC6
;
1044 case 0x0653: return Arab_DIAC7
;
1046 case 0x0654: return Arab_DIAC8
;
1047 default: return Arab_Norm
;
1052 * ContextualShape_Arabic
1054 static void ContextualShape_Arabic(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1061 if (*pcGlyphs
!= cChars
)
1063 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1067 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1078 load_ot_tables(hdc
, psc
);
1080 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
1081 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1083 for (i
= 0; i
< cChars
; i
++)
1084 context_type
[i
] = get_table_entry( wine_shaping_table
, pwcChars
[i
] );
1086 for (i
= 0; i
< cChars
; i
++)
1088 if (context_type
[i
] == jtR
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1089 context_shape
[i
] = Xr
;
1090 else if (context_type
[i
] == jtL
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1091 context_shape
[i
] = Xl
;
1092 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
)))
1093 context_shape
[i
] = Xm
;
1094 else if (context_type
[i
] == jtD
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1095 context_shape
[i
] = Xr
;
1096 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1097 context_shape
[i
] = Xl
;
1099 context_shape
[i
] = Xn
;
1102 /* Contextual Shaping */
1104 while(i
< *pcGlyphs
)
1106 BOOL shaped
= FALSE
;
1108 if (psc
->GSUB_Table
)
1111 INT prevCount
= *pcGlyphs
;
1112 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1113 if (nextIndex
> GSUB_E_NOGLYPH
)
1116 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1118 shaped
= (nextIndex
> GSUB_E_NOGLYPH
);
1123 if (context_shape
[i
] == Xn
)
1125 WORD newGlyph
= pwOutGlyphs
[i
];
1126 if (pwcChars
[i
] >= FIRST_ARABIC_CHAR
&& pwcChars
[i
] <= LAST_ARABIC_CHAR
)
1128 /* fall back to presentation form B */
1129 WCHAR context_char
= wine_shaping_forms
[pwcChars
[i
] - FIRST_ARABIC_CHAR
][context_shape
[i
]];
1130 if (context_char
!= pwcChars
[i
] && GetGlyphIndicesW(hdc
, &context_char
, 1, &newGlyph
, 0) != GDI_ERROR
&& newGlyph
!= 0x0000)
1131 pwOutGlyphs
[i
] = newGlyph
;
1138 HeapFree(GetProcessHeap(),0,context_shape
);
1139 HeapFree(GetProcessHeap(),0,context_type
);
1141 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Arabic
);
1144 static int combining_lexical_Hebrew(WCHAR c
)
1146 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
};
1157 case 0x05BB: return Hebr_DIAC
;
1161 case 0x05AE: return Hebr_CANT1
;
1164 case 0x05AC: return Hebr_CANT2
;
1170 case 0x05AB: return Hebr_CANT3
;
1174 case 0x059F: return Hebr_CANT4
;
1176 case 0x05A0: return Hebr_CANT5
;
1178 case 0x05A5: return Hebr_CANT6
;
1181 case 0x05A6: return Hebr_CANT7
;
1184 case 0x05AA: return Hebr_CANT8
;
1186 case 0x05AD: return Hebr_CANT9
;
1187 case 0x05AF: return Hebr_CANT10
;
1188 case 0x05BC: return Hebr_DAGESH
;
1189 case 0x05C4: return Hebr_DOTABV
;
1190 case 0x05B9: return Hebr_HOLAM
;
1191 case 0x05BD: return Hebr_METEG
;
1192 case 0x05B7: return Hebr_PATAH
;
1193 case 0x05B8: return Hebr_QAMATS
;
1194 case 0x05BF: return Hebr_RAFE
;
1196 case 0x05C2: return Hebr_SHINSIN
;
1197 default: return Hebr_Norm
;
1201 static void ContextualShape_Hebrew(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1205 if (*pcGlyphs
!= cChars
)
1207 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1211 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1216 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Hebrew
);
1220 * ContextualShape_Syriac
1223 static int combining_lexical_Syriac(WCHAR c
)
1225 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
};
1233 case 0x73D: return Syriac_DIAC1
;
1238 case 0x73E: return Syriac_DIAC2
;
1241 case 0x74A: return Syriac_DIAC3
;
1244 case 0x73F: return Syriac_DIAC4
;
1247 case 0x73C: return Syriac_DIAC5
;
1249 case 0x30A: return Syriac_DIAC6
;
1251 case 0x325: return Syriac_DIAC7
;
1253 case 0x303: return Syriac_DIAC8
;
1258 case 0x331: return Syriac_DIAC9
;
1259 case 0x308: return Syriac_DIAC10
;
1260 case 0x304: return Syriac_DIAC11
;
1261 case 0x307: return Syriac_DIAC12
;
1262 case 0x323: return Syriac_DIAC13
;
1263 case 0x743: return Syriac_DIAC14
;
1264 case 0x744: return Syriac_DIAC15
;
1265 case 0x745: return Syriac_DIAC16
;
1266 case 0x746: return Syriac_DIAC17
;
1267 default: return Syriac_Norm
;
1272 #define DALATH 0x715
1275 static void ContextualShape_Syriac(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1282 if (*pcGlyphs
!= cChars
)
1284 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1288 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1299 load_ot_tables(hdc
, psc
);
1301 if (!psc
->GSUB_Table
)
1304 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
1305 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1307 for (i
= 0; i
< cChars
; i
++)
1308 context_type
[i
] = get_table_entry( wine_shaping_table
, pwcChars
[i
] );
1310 for (i
= 0; i
< cChars
; i
++)
1312 if (pwcChars
[i
] == ALAPH
)
1314 WCHAR rchar
= neighbour_char(i
,dirR
,pwcChars
,cChars
);
1316 if (left_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)) && word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1317 context_shape
[i
] = Afj
;
1318 else if ( rchar
!= DALATH
&& rchar
!= RISH
&&
1319 !left_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)) &&
1320 word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1321 context_shape
[i
] = Afn
;
1322 else if ( (rchar
== DALATH
|| rchar
== RISH
) && word_break_causing(neighbour_char(i
,dirL
,pwcChars
,cChars
)))
1323 context_shape
[i
] = Afx
;
1325 context_shape
[i
] = Xn
;
1327 else if (context_type
[i
] == jtR
&&
1328 right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1329 context_shape
[i
] = Xr
;
1330 else if (context_type
[i
] == jtL
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1331 context_shape
[i
] = Xl
;
1332 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
)))
1333 context_shape
[i
] = Xm
;
1334 else if (context_type
[i
] == jtD
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
1335 context_shape
[i
] = Xr
;
1336 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
1337 context_shape
[i
] = Xl
;
1339 context_shape
[i
] = Xn
;
1342 /* Contextual Shaping */
1344 while(i
< *pcGlyphs
)
1347 INT prevCount
= *pcGlyphs
;
1348 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1349 if (nextIndex
> GSUB_E_NOGLYPH
)
1351 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1358 HeapFree(GetProcessHeap(),0,context_shape
);
1359 HeapFree(GetProcessHeap(),0,context_type
);
1361 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Syriac
);
1364 static int combining_lexical_Thaana(WCHAR c
)
1366 enum {Thaana_Norm
=0, Thaana_FILI
};
1379 case 0x7AF: return Thaana_FILI
;
1380 default: return Thaana_Norm
;
1384 static void ContextualShape_Thaana(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1388 if (*pcGlyphs
!= cChars
)
1390 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1394 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1399 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Thaana
);
1403 * ContextualShape_Phags_pa
1406 #define phags_pa_CANDRABINDU 0xA873
1407 #define phags_pa_START 0xA840
1408 #define phags_pa_END 0xA87F
1410 static void ContextualShape_Phags_pa(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1416 if (*pcGlyphs
!= cChars
)
1418 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1422 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1433 load_ot_tables(hdc
, psc
);
1435 if (!psc
->GSUB_Table
)
1438 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
1440 for (i
= 0; i
< cChars
; i
++)
1442 if (pwcChars
[i
] >= phags_pa_START
&& pwcChars
[i
] <= phags_pa_END
)
1444 WCHAR rchar
= neighbour_char(i
,dirR
,pwcChars
,cChars
);
1445 WCHAR lchar
= neighbour_char(i
,dirL
,pwcChars
,cChars
);
1446 BOOL jrchar
= (rchar
!= phags_pa_CANDRABINDU
&& rchar
>= phags_pa_START
&& rchar
<= phags_pa_END
);
1447 BOOL jlchar
= (lchar
!= phags_pa_CANDRABINDU
&& lchar
>= phags_pa_START
&& lchar
<= phags_pa_END
);
1449 if (jrchar
&& jlchar
)
1450 context_shape
[i
] = Xm
;
1452 context_shape
[i
] = Xr
;
1454 context_shape
[i
] = Xl
;
1456 context_shape
[i
] = Xn
;
1459 context_shape
[i
] = -1;
1462 /* Contextual Shaping */
1464 while(i
< *pcGlyphs
)
1466 if (context_shape
[i
] >= 0)
1469 INT prevCount
= *pcGlyphs
;
1470 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
1471 if (nextIndex
> GSUB_E_NOGLYPH
)
1473 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
1483 HeapFree(GetProcessHeap(),0,context_shape
);
1486 static int combining_lexical_Thai(WCHAR c
)
1488 enum {Thai_Norm
=0, Thai_ABOVE1
, Thai_ABOVE2
, Thai_ABOVE3
, Thai_ABOVE4
, Thai_BELOW1
, Thai_BELOW2
, Thai_AM
};
1496 case 0xE37: return Thai_ABOVE1
;
1498 case 0xE4D: return Thai_ABOVE2
;
1502 case 0xE4B: return Thai_ABOVE3
;
1504 case 0xE4E: return Thai_ABOVE4
;
1506 case 0xE39: return Thai_BELOW1
;
1507 case 0xE3A: return Thai_BELOW2
;
1508 case 0xE33: return Thai_AM
;
1509 default: return Thai_Norm
;
1513 static void ContextualShape_Thai(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1517 if (*pcGlyphs
!= cChars
)
1519 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1523 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1528 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Thai
);
1531 static int combining_lexical_Lao(WCHAR c
)
1533 enum {Lao_Norm
=0, Lao_ABOVE1
, Lao_ABOVE2
, Lao_BELOW1
, Lao_BELOW2
, Lao_AM
};
1543 case 0xECD: return Lao_ABOVE1
;
1548 case 0xECC: return Lao_ABOVE2
;
1549 case 0xEBC: return Lao_BELOW1
;
1551 case 0xEB9: return Lao_BELOW2
;
1552 case 0xEB3: return Lao_AM
;
1553 default: return Lao_Norm
;
1557 static void ContextualShape_Lao(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
1561 if (*pcGlyphs
!= cChars
)
1563 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1567 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
1572 mark_invalid_combinations(hdc
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, dirL
, pwLogClust
, combining_lexical_Lao
);
1575 static void ReplaceInsertChars(HDC hdc
, INT cWalk
, INT
* pcChars
, WCHAR
*pwOutChars
, const WCHAR
*replacements
)
1580 pwOutChars
[cWalk
] = replacements
[0];
1584 for (i
= 1; replacements
[i
] != 0x0000 && i
< 3; i
++)
1587 for (j
= *pcChars
; j
> cWalk
; j
--)
1588 pwOutChars
[j
] = pwOutChars
[j
-1];
1589 *pcChars
= *pcChars
+1;
1590 pwOutChars
[cWalk
] = replacements
[i
];
1595 static void DecomposeVowels(HDC hdc
, WCHAR
*pwOutChars
, INT
*pcChars
, const VowelComponents vowels
[], WORD
* pwLogClust
, INT cChars
)
1600 for (cWalk
= 0; cWalk
< *pcChars
; cWalk
++)
1602 for (i
= 0; vowels
[i
].base
!= 0x0; i
++)
1604 if (pwOutChars
[cWalk
] == vowels
[i
].base
)
1607 ReplaceInsertChars(hdc
, cWalk
, pcChars
, pwOutChars
, vowels
[i
].parts
);
1608 if (vowels
[i
].parts
[1]) { cWalk
++; o
++; }
1609 if (vowels
[i
].parts
[2]) { cWalk
++; o
++; }
1610 UpdateClusters(cWalk
, o
, 1, cChars
, pwLogClust
);
1617 static void ComposeConsonants(HDC hdc
, WCHAR
*pwOutChars
, INT
*pcChars
, const ConsonantComponents consonants
[], WORD
* pwLogClust
)
1623 for (cWalk
= 0; cWalk
< *pcChars
; cWalk
++)
1625 for (i
= 0; consonants
[i
].output
!= 0x0; i
++)
1628 for (j
= 0; j
+ cWalk
< *pcChars
&& consonants
[i
].parts
[j
]!=0x0; j
++)
1629 if (pwOutChars
[cWalk
+j
] != consonants
[i
].parts
[j
])
1632 if (consonants
[i
].parts
[j
]==0x0) /* matched all */
1636 pwOutChars
[cWalk
] = consonants
[i
].output
;
1637 for(k
= cWalk
+1; k
< *pcChars
- j
; k
++)
1638 pwOutChars
[k
] = pwOutChars
[k
+j
];
1639 *pcChars
= *pcChars
- j
;
1640 for (k
= j
; k
> 0; k
--)
1641 pwLogClust
[cWalk
+ k
+ offset
] = pwLogClust
[cWalk
+ offset
];
1643 for (k
= cWalk
+ j
+ offset
; k
< *pcChars
+ offset
; k
++)
1652 static void Reorder_Ra_follows_base(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1657 WORD Ra
= pwChar
[s
->start
];
1658 WORD H
= pwChar
[s
->start
+1];
1660 TRACE("Doing reorder of Ra to %i\n",s
->base
);
1661 for (j
= s
->start
; j
< s
->base
-1; j
++)
1662 pwChar
[j
] = pwChar
[j
+2];
1663 pwChar
[s
->base
-1] = Ra
;
1664 pwChar
[s
->base
] = H
;
1666 s
->ralf
= s
->base
-1;
1671 static void Reorder_Ra_follows_matra(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1676 int stop
= (s
->blwf
>=0)? s
->blwf
+1 : s
->base
;
1677 WORD Ra
= pwChar
[s
->start
];
1678 WORD H
= pwChar
[s
->start
+1];
1679 for (loc
= s
->end
; loc
> stop
; loc
--)
1680 if (lexical(pwChar
[loc
]) == lex_Matra_post
|| lexical(pwChar
[loc
]) == lex_Matra_below
)
1683 TRACE("Doing reorder of Ra to %i\n",loc
);
1684 for (j
= s
->start
; j
< loc
-1; j
++)
1685 pwChar
[j
] = pwChar
[j
+2];
1691 if (s
->blwf
>= 0) s
->blwf
-= 2;
1692 if (s
->pref
>= 0) s
->pref
-= 2;
1696 static void Reorder_Ra_follows_syllable(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1701 WORD Ra
= pwChar
[s
->start
];
1702 WORD H
= pwChar
[s
->start
+1];
1704 TRACE("Doing reorder of Ra to %i\n",s
->end
-1);
1705 for (j
= s
->start
; j
< s
->end
-1; j
++)
1706 pwChar
[j
] = pwChar
[j
+2];
1707 pwChar
[s
->end
-1] = Ra
;
1712 if (s
->blwf
>= 0) s
->blwf
-= 2;
1713 if (s
->pref
>= 0) s
->pref
-= 2;
1717 static void Reorder_Matra_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1721 /* reorder Matras */
1722 if (s
->end
> s
->base
)
1724 for (i
= 1; i
<= s
->end
-s
->base
; i
++)
1726 if (lexical(pwChar
[s
->base
+i
]) == lex_Matra_pre
)
1729 WCHAR c
= pwChar
[s
->base
+i
];
1730 TRACE("Doing reorder of %x %x\n",c
,pwChar
[s
->base
]);
1731 for (j
= s
->base
+i
; j
> s
->base
; j
--)
1732 pwChar
[j
] = pwChar
[j
-1];
1733 pwChar
[s
->base
] = c
;
1735 if (s
->ralf
>= s
->base
) s
->ralf
++;
1736 if (s
->blwf
>= s
->base
) s
->blwf
++;
1737 if (s
->pref
>= s
->base
) s
->pref
++;
1744 static void Reorder_Matra_precede_syllable(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1748 /* reorder Matras */
1749 if (s
->end
> s
->base
)
1751 for (i
= 1; i
<= s
->end
-s
->base
; i
++)
1753 if (lexical(pwChar
[s
->base
+i
]) == lex_Matra_pre
)
1756 WCHAR c
= pwChar
[s
->base
+i
];
1757 TRACE("Doing reorder of %x to %i\n",c
,s
->start
);
1758 for (j
= s
->base
+i
; j
> s
->start
; j
--)
1759 pwChar
[j
] = pwChar
[j
-1];
1760 pwChar
[s
->start
] = c
;
1762 if (s
->ralf
>= 0) s
->ralf
++;
1763 if (s
->blwf
>= 0) s
->blwf
++;
1764 if (s
->pref
>= 0) s
->pref
++;
1771 static void SecondReorder_Blwf_follows_matra(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1773 if (s
->blwf
>= 0 && g
->blwf
> g
->base
)
1777 for (loc
= s
->end
; loc
> s
->blwf
; loc
--)
1778 if (lexical(pwChar
[loc
]) == lex_Matra_below
|| lexical(pwChar
[loc
]) == lex_Matra_above
|| lexical(pwChar
[loc
]) == lex_Matra_post
)
1781 g_offset
= (loc
- s
->blwf
) - 1;
1785 WORD blwf
= glyphs
[g
->blwf
];
1786 TRACE("Doing reorder of Below-base to %i (glyph offset %i)\n",loc
,g_offset
);
1787 /* do not care about the pwChar array anymore, just the glyphs */
1788 for (j
= 0; j
< g_offset
; j
++)
1789 glyphs
[g
->blwf
+ j
] = glyphs
[g
->blwf
+ j
+ 1];
1790 glyphs
[g
->blwf
+ g_offset
] = blwf
;
1795 static void SecondReorder_Matra_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1799 /* reorder previously moved Matras to correct position*/
1800 for (i
= s
->start
; i
< s
->base
; i
++)
1802 if (lexical(pwChar
[i
]) == lex_Matra_pre
)
1805 int g_start
= g
->start
+ i
- s
->start
;
1806 if (g_start
< g
->base
-1 )
1808 WCHAR og
= glyphs
[g_start
];
1809 TRACE("Doing reorder of matra from %i to %i\n",g_start
,g
->base
);
1810 for (j
= g_start
; j
< g
->base
-1; j
++)
1811 glyphs
[j
] = glyphs
[j
+1];
1812 glyphs
[g
->base
-1] = og
;
1818 static void SecondReorder_Pref_precede_base(LPWSTR pwChar
, IndicSyllable
*s
, WORD
*glyphs
, IndicSyllable
*g
, lexical_function lexical
)
1820 if (s
->pref
>= 0 && g
->pref
> g
->base
)
1823 WCHAR og
= glyphs
[g
->pref
];
1824 TRACE("Doing reorder of pref from %i to %i\n",g
->pref
,g
->base
);
1825 for (j
= g
->pref
; j
> g
->base
; j
--)
1826 glyphs
[j
] = glyphs
[j
-1];
1827 glyphs
[g
->base
] = og
;
1831 static void Reorder_Like_Sinhala(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1833 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1834 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1835 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1837 Reorder_Ra_follows_base(pwChar
, s
, lexical
);
1838 Reorder_Matra_precede_base(pwChar
, s
, lexical
);
1841 static void Reorder_Like_Devanagari(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1843 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1844 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1845 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1847 Reorder_Ra_follows_matra(pwChar
, s
, lexical
);
1848 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1851 static void Reorder_Like_Bengali(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1853 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1854 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1855 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1857 Reorder_Ra_follows_base(pwChar
, s
, lexical
);
1858 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1861 static void Reorder_Like_Kannada(LPWSTR pwChar
, IndicSyllable
*s
, lexical_function lexical
)
1863 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1864 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1865 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1867 Reorder_Ra_follows_syllable(pwChar
, s
, lexical
);
1868 Reorder_Matra_precede_syllable(pwChar
, s
, lexical
);
1871 static void SecondReorder_Like_Telugu(LPWSTR pwChar
, IndicSyllable
*s
, WORD
* pwGlyphs
, IndicSyllable
*g
, lexical_function lexical
)
1873 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1874 TRACE("Glyphs (%i..%i..%i)\n",g
->start
,g
->base
,g
->end
);
1875 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1876 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1878 SecondReorder_Blwf_follows_matra(pwChar
, s
, pwGlyphs
, g
, lexical
);
1881 static void SecondReorder_Like_Tamil(LPWSTR pwChar
, IndicSyllable
*s
, WORD
* pwGlyphs
, IndicSyllable
*g
, lexical_function lexical
)
1883 TRACE("Syllable (%i..%i..%i)\n",s
->start
,s
->base
,s
->end
);
1884 TRACE("Glyphs (%i..%i..%i)\n",g
->start
,g
->base
,g
->end
);
1885 if (s
->start
== s
->base
&& s
->base
== s
->end
) return;
1886 if (lexical(pwChar
[s
->base
]) == lex_Vowel
) return;
1888 SecondReorder_Matra_precede_base(pwChar
, s
, pwGlyphs
, g
, lexical
);
1889 SecondReorder_Pref_precede_base(pwChar
, s
, pwGlyphs
, g
, lexical
);
1893 static inline void shift_syllable_glyph_indexs(IndicSyllable
*glyph_index
, INT index
, INT shift
)
1898 if (glyph_index
->start
> index
)
1899 glyph_index
->start
+= shift
;
1900 if (glyph_index
->base
> index
)
1901 glyph_index
->base
+= shift
;
1902 if (glyph_index
->end
> index
)
1903 glyph_index
->end
+= shift
;
1904 if (glyph_index
->ralf
> index
)
1905 glyph_index
->ralf
+= shift
;
1906 if (glyph_index
->blwf
> index
)
1907 glyph_index
->blwf
+= shift
;
1908 if (glyph_index
->pref
> index
)
1909 glyph_index
->pref
+= shift
;
1912 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
)
1914 int index
= glyph_index
->start
;
1919 while(index
<= glyph_index
->end
)
1922 INT prevCount
= *pcGlyphs
;
1923 nextIndex
= GSUB_apply_feature_all_lookups(psc
->GSUB_Table
, feature
, pwOutGlyphs
, index
, 1, pcGlyphs
);
1924 if (nextIndex
> GSUB_E_NOGLYPH
)
1926 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1927 shift_syllable_glyph_indexs(glyph_index
,index
,*pcGlyphs
- prevCount
);
1935 static inline INT
find_consonant_halant(WCHAR
* pwChars
, INT index
, INT end
, lexical_function lexical
)
1938 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
)))))
1940 if (index
+ i
<= end
-1)
1946 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
)
1948 INT index
, nextIndex
;
1951 count
= syllable
->base
- syllable
->start
;
1954 index
= find_consonant_halant(&pwChars
[syllable
->start
], 0, count
, lexical
);
1955 while (index
>= 0 && index
+ g_offset
< (glyph_index
->base
- glyph_index
->start
))
1957 INT prevCount
= *pcGlyphs
;
1958 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, index
+glyph_index
->start
+g_offset
, 1, pcGlyphs
, feature
);
1959 if (nextIndex
> GSUB_E_NOGLYPH
)
1961 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1962 shift_syllable_glyph_indexs(glyph_index
, index
+ glyph_index
->start
+ g_offset
, (*pcGlyphs
- prevCount
));
1963 g_offset
+= (*pcGlyphs
- prevCount
);
1967 index
= find_consonant_halant(&pwChars
[syllable
->start
], index
, count
, lexical
);
1971 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
)
1974 INT prevCount
= *pcGlyphs
;
1976 if (syllable
->ralf
>= 0)
1978 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, glyph_index
->ralf
, 1, pcGlyphs
, "rphf");
1979 if (nextIndex
> GSUB_E_NOGLYPH
)
1981 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
1982 shift_syllable_glyph_indexs(glyph_index
,glyph_index
->ralf
,*pcGlyphs
- prevCount
);
1987 static inline INT
find_halant_consonant(WCHAR
* pwChars
, INT index
, INT end
, lexical_function lexical
)
1990 while (index
+ i
< end
-1 && !(lexical(pwChars
[index
+i
]) == lex_Halant
&&
1991 ((index
+ i
< end
-2 && lexical(pwChars
[index
+i
]) == lex_Nukta
&& is_consonant(lexical(pwChars
[index
+i
+1]))) ||
1992 is_consonant(lexical(pwChars
[index
+i
+1])))))
1994 if (index
+ i
<= end
-1)
2000 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
)
2002 INT index
, nextIndex
;
2003 INT count
, g_offset
=0;
2004 INT ralf
= syllable
->ralf
;
2006 count
= syllable
->end
- syllable
->base
;
2008 index
= find_halant_consonant(&pwChars
[syllable
->base
], 0, count
, lexical
);
2012 INT prevCount
= *pcGlyphs
;
2013 if (ralf
>=0 && ralf
< index
)
2021 WORD g
= pwOutGlyphs
[index
+glyph_index
->base
+g_offset
];
2022 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
] = pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1];
2023 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1] = g
;
2026 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, index
+glyph_index
->base
+g_offset
, 1, pcGlyphs
, feat
);
2027 if (nextIndex
> GSUB_E_NOGLYPH
)
2029 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, 1, cChars
, pwLogClust
);
2030 shift_syllable_glyph_indexs(glyph_index
,index
+glyph_index
->start
+g_offset
, (*pcGlyphs
- prevCount
));
2031 g_offset
+= (*pcGlyphs
- prevCount
);
2035 WORD g
= pwOutGlyphs
[index
+glyph_index
->base
+g_offset
];
2036 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
] = pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1];
2037 pwOutGlyphs
[index
+glyph_index
->base
+g_offset
+1] = g
;
2041 index
= find_halant_consonant(&pwChars
[syllable
->base
], index
, count
, lexical
);
2045 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
)
2048 int overall_shift
= 0;
2049 LoadedFeature
*locl
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "locl"):NULL
;
2050 LoadedFeature
*nukt
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "nukt");
2051 LoadedFeature
*akhn
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "akhn");
2052 LoadedFeature
*rkrf
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "rkrf"):NULL
;
2053 LoadedFeature
*pstf
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "pstf");
2054 LoadedFeature
*vatu
= (!rkrf
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "vatu"):NULL
;
2055 LoadedFeature
*cjct
= (modern
)?load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "cjct"):NULL
;
2056 BOOL rphf
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "rphf") != NULL
);
2057 BOOL pref
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "pref") != NULL
);
2058 BOOL blwf
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "blwf") != NULL
);
2059 BOOL half
= (load_OT_feature(hdc
, psa
, psc
, FEATURE_GSUB_TABLE
, "half") != NULL
);
2060 IndicSyllable glyph_indexs
;
2062 for (c
= 0; c
< syllable_count
; c
++)
2065 memcpy(&glyph_indexs
, &syllables
[c
], sizeof(IndicSyllable
));
2066 shift_syllable_glyph_indexs(&glyph_indexs
, -1, overall_shift
);
2067 old_end
= glyph_indexs
.end
;
2071 TRACE("applying feature locl\n");
2072 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, locl
);
2076 TRACE("applying feature nukt\n");
2077 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, nukt
);
2081 TRACE("applying feature akhn\n");
2082 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, akhn
);
2086 Apply_Indic_Rphf(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
);
2089 TRACE("applying feature rkrf\n");
2090 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, rkrf
);
2093 Apply_Indic_PostBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, modern
, "pref");
2097 Apply_Indic_PreBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, "blwf");
2099 Apply_Indic_PostBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, modern
, "blwf");
2103 Apply_Indic_PreBase(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, "half");
2106 TRACE("applying feature pstf\n");
2107 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, pstf
);
2111 TRACE("applying feature vatu\n");
2112 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, vatu
);
2116 TRACE("applying feature cjct\n");
2117 Apply_Indic_BasicForm(hdc
, psc
, psa
, pwChars
, cChars
, &syllables
[c
], pwOutGlyphs
, pcGlyphs
, pwLogClust
, lexical
, &glyph_indexs
, cjct
);
2121 second_reorder(pwChars
, &syllables
[c
], pwOutGlyphs
, &glyph_indexs
, lexical
);
2123 overall_shift
+= glyph_indexs
.end
- old_end
;
2127 static inline int unicode_lex(WCHAR c
)
2131 if (!c
) return lex_Generic
;
2132 if (c
== 0x200D) return lex_ZWJ
;
2133 if (c
== 0x200C) return lex_ZWNJ
;
2134 if (c
== 0x00A0) return lex_NBSP
;
2136 type
= get_table_entry( indic_syllabic_table
, c
);
2138 if ((type
& 0x00ff) != 0x0007) type
= type
& 0x00ff;
2142 case 0x0d07: /* Unknown */
2143 case 0x0e07: /* Unknwon */
2144 default: return lex_Generic
;
2150 case 0x0014: return lex_Modifier
;
2158 case 0x0010: return lex_Consonant
;
2159 case 0x0004: return lex_Nukta
;
2160 case 0x0005: return lex_Halant
;
2162 case 0x0008: return lex_Vowel
;
2164 case 0x0107: return lex_Matra_post
;
2166 case 0x0307: return lex_Matra_pre
;
2172 case 0x0407: return lex_Composed_Vowel
;
2173 case 0x0507: return lex_Matra_above
;
2174 case 0x0607: return lex_Matra_below
;
2176 case 0x0015: return lex_Ra
;
2180 static int sinhala_lex(WCHAR c
)
2187 case 0x0DDE: return lex_Matra_post
;
2189 return unicode_lex(c
);
2193 static const VowelComponents Sinhala_vowels
[] = {
2194 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2195 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2196 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2197 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2198 {0x0000, {0x0000,0x0000,0x0}}};
2200 static void ContextualShape_Sinhala(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2202 int cCount
= cChars
;
2205 IndicSyllable
*syllables
= NULL
;
2206 int syllable_count
= 0;
2208 if (*pcGlyphs
!= cChars
)
2210 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2214 input
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
) * (cChars
* 3));
2216 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2218 /* Step 1: Decompose multi part vowels */
2219 DecomposeVowels(hdc
, input
, &cCount
, Sinhala_vowels
, pwLogClust
, cChars
);
2221 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2223 /* Step 2: Reorder within Syllables */
2224 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, sinhala_lex
, Reorder_Like_Sinhala
, TRUE
);
2225 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2227 /* Step 3: Strip dangling joiners */
2228 for (i
= 0; i
< cCount
; i
++)
2230 if ((input
[i
] == 0x200D || input
[i
] == 0x200C) &&
2231 (i
== 0 || input
[i
-1] == 0x0020 || i
== cCount
-1 || input
[i
+1] == 0x0020))
2235 /* Step 4: Base Form application to syllables */
2236 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2238 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, sinhala_lex
, NULL
, TRUE
);
2240 HeapFree(GetProcessHeap(),0,input
);
2241 HeapFree(GetProcessHeap(),0,syllables
);
2244 static int devanagari_lex(WCHAR c
)
2248 case 0x0930: return lex_Ra
;
2250 return unicode_lex(c
);
2254 static const ConsonantComponents Devanagari_consonants
[] ={
2255 {{0x0928, 0x093C, 0x00000}, 0x0929},
2256 {{0x0930, 0x093C, 0x00000}, 0x0931},
2257 {{0x0933, 0x093C, 0x00000}, 0x0934},
2258 {{0x0915, 0x093C, 0x00000}, 0x0958},
2259 {{0x0916, 0x093C, 0x00000}, 0x0959},
2260 {{0x0917, 0x093C, 0x00000}, 0x095A},
2261 {{0x091C, 0x093C, 0x00000}, 0x095B},
2262 {{0x0921, 0x093C, 0x00000}, 0x095C},
2263 {{0x0922, 0x093C, 0x00000}, 0x095D},
2264 {{0x092B, 0x093C, 0x00000}, 0x095E},
2265 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2267 static void ContextualShape_Devanagari(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2269 int cCount
= cChars
;
2271 IndicSyllable
*syllables
= NULL
;
2272 int syllable_count
= 0;
2273 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2275 if (*pcGlyphs
!= cChars
)
2277 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2281 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2282 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2284 /* Step 1: Compose Consonant and Nukta */
2285 ComposeConsonants(hdc
, input
, &cCount
, Devanagari_consonants
, pwLogClust
);
2286 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2288 /* Step 2: Reorder within Syllables */
2289 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, devanagari_lex
, Reorder_Like_Devanagari
, modern
);
2290 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2291 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2294 /* Step 3: Base Form application to syllables */
2295 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, devanagari_lex
, NULL
, modern
);
2297 HeapFree(GetProcessHeap(),0,input
);
2298 HeapFree(GetProcessHeap(),0,syllables
);
2301 static int bengali_lex(WCHAR c
)
2305 case 0x09B0: return lex_Ra
;
2307 return unicode_lex(c
);
2311 static const VowelComponents Bengali_vowels
[] = {
2312 {0x09CB, {0x09C7,0x09BE,0x0000}},
2313 {0x09CC, {0x09C7,0x09D7,0x0000}},
2314 {0x0000, {0x0000,0x0000,0x0000}}};
2316 static const ConsonantComponents Bengali_consonants
[] = {
2317 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2318 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2319 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2320 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2321 {{0x0000,0x0000,0x0000}, 0x0000}};
2323 static void ContextualShape_Bengali(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2325 int cCount
= cChars
;
2327 IndicSyllable
*syllables
= NULL
;
2328 int syllable_count
= 0;
2329 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2331 if (*pcGlyphs
!= cChars
)
2333 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2337 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
* 2) * sizeof(WCHAR
));
2338 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2340 /* Step 1: Decompose Vowels and Compose Consonants */
2341 DecomposeVowels(hdc
, input
, &cCount
, Bengali_vowels
, pwLogClust
, cChars
);
2342 ComposeConsonants(hdc
, input
, &cCount
, Bengali_consonants
, pwLogClust
);
2343 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2345 /* Step 2: Reorder within Syllables */
2346 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, bengali_lex
, Reorder_Like_Bengali
, modern
);
2347 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2348 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2351 /* Step 3: Initial form is only applied to the beginning of words */
2352 for (cCount
= cCount
- 1 ; cCount
>= 0; cCount
--)
2354 if (cCount
== 0 || input
[cCount
] == 0x0020) /* space */
2358 if (index
> 0) index
++;
2360 apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, &pwOutGlyphs
[index
], 0, 1, &gCount
, "init");
2364 /* Step 4: Base Form application to syllables */
2365 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, bengali_lex
, NULL
, modern
);
2367 HeapFree(GetProcessHeap(),0,input
);
2368 HeapFree(GetProcessHeap(),0,syllables
);
2371 static int gurmukhi_lex(WCHAR c
)
2374 return lex_Modifier
;
2376 return unicode_lex(c
);
2379 static const ConsonantComponents Gurmukhi_consonants
[] = {
2380 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2381 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2382 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2383 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2384 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2385 {{0x0000,0x0000,0x0000}, 0x0000}};
2387 static void ContextualShape_Gurmukhi(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2389 int cCount
= cChars
;
2391 IndicSyllable
*syllables
= NULL
;
2392 int syllable_count
= 0;
2393 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2395 if (*pcGlyphs
!= cChars
)
2397 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2401 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2402 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2404 /* Step 1: Compose Consonants */
2405 ComposeConsonants(hdc
, input
, &cCount
, Gurmukhi_consonants
, pwLogClust
);
2406 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2408 /* Step 2: Reorder within Syllables */
2409 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, gurmukhi_lex
, Reorder_Like_Bengali
, modern
);
2410 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2411 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2414 /* Step 3: Base Form application to syllables */
2415 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, gurmukhi_lex
, NULL
, modern
);
2417 HeapFree(GetProcessHeap(),0,input
);
2418 HeapFree(GetProcessHeap(),0,syllables
);
2421 static int gujarati_lex(WCHAR c
)
2425 case 0x0AB0: return lex_Ra
;
2427 return unicode_lex(c
);
2431 static void ContextualShape_Gujarati(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2433 int cCount
= cChars
;
2435 IndicSyllable
*syllables
= NULL
;
2436 int syllable_count
= 0;
2437 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2439 if (*pcGlyphs
!= cChars
)
2441 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2445 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2446 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2448 /* Step 1: Reorder within Syllables */
2449 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, gujarati_lex
, Reorder_Like_Devanagari
, modern
);
2450 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2451 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2454 /* Step 2: Base Form application to syllables */
2455 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, gujarati_lex
, NULL
, modern
);
2457 HeapFree(GetProcessHeap(),0,input
);
2458 HeapFree(GetProcessHeap(),0,syllables
);
2461 static int oriya_lex(WCHAR c
)
2465 case 0x0B30: return lex_Ra
;
2467 return unicode_lex(c
);
2471 static const VowelComponents Oriya_vowels
[] = {
2472 {0x0B48, {0x0B47,0x0B56,0x0000}},
2473 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2474 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2475 {0x0000, {0x0000,0x0000,0x0000}}};
2477 static const ConsonantComponents Oriya_consonants
[] = {
2478 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2479 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2480 {{0x0000,0x0000,0x0000}, 0x0000}};
2482 static void ContextualShape_Oriya(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2484 int cCount
= cChars
;
2486 IndicSyllable
*syllables
= NULL
;
2487 int syllable_count
= 0;
2488 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2490 if (*pcGlyphs
!= cChars
)
2492 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2496 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2497 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2499 /* Step 1: Decompose Vowels and Compose Consonants */
2500 DecomposeVowels(hdc
, input
, &cCount
, Oriya_vowels
, pwLogClust
, cChars
);
2501 ComposeConsonants(hdc
, input
, &cCount
, Oriya_consonants
, pwLogClust
);
2502 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2504 /* Step 2: Reorder within Syllables */
2505 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, oriya_lex
, Reorder_Like_Bengali
, modern
);
2506 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2507 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2510 /* Step 3: Base Form application to syllables */
2511 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, oriya_lex
, NULL
, modern
);
2513 HeapFree(GetProcessHeap(),0,input
);
2514 HeapFree(GetProcessHeap(),0,syllables
);
2517 static int tamil_lex(WCHAR c
)
2519 return unicode_lex(c
);
2522 static const VowelComponents Tamil_vowels
[] = {
2523 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2524 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2525 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2526 {0x0000, {0x0000,0x0000,0x0000}}};
2528 static const ConsonantComponents Tamil_consonants
[] = {
2529 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2530 {{0x0000,0x0000,0x0000}, 0x0000}};
2532 static void ContextualShape_Tamil(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2534 int cCount
= cChars
;
2536 IndicSyllable
*syllables
= NULL
;
2537 int syllable_count
= 0;
2538 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2540 if (*pcGlyphs
!= cChars
)
2542 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2546 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2547 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2549 /* Step 1: Decompose Vowels and Compose Consonants */
2550 DecomposeVowels(hdc
, input
, &cCount
, Tamil_vowels
, pwLogClust
, cChars
);
2551 ComposeConsonants(hdc
, input
, &cCount
, Tamil_consonants
, pwLogClust
);
2552 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2554 /* Step 2: Reorder within Syllables */
2555 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, tamil_lex
, Reorder_Like_Bengali
, modern
);
2556 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2557 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2560 /* Step 3: Base Form application to syllables */
2561 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, tamil_lex
, SecondReorder_Like_Tamil
, modern
);
2563 HeapFree(GetProcessHeap(),0,input
);
2564 HeapFree(GetProcessHeap(),0,syllables
);
2567 static int telugu_lex(WCHAR c
)
2572 case 0x0C44: return lex_Modifier
;
2574 return unicode_lex(c
);
2578 static const VowelComponents Telugu_vowels
[] = {
2579 {0x0C48, {0x0C46,0x0C56,0x0000}},
2580 {0x0000, {0x0000,0x0000,0x0000}}};
2582 static void ContextualShape_Telugu(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2584 int cCount
= cChars
;
2586 IndicSyllable
*syllables
= NULL
;
2587 int syllable_count
= 0;
2588 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2590 if (*pcGlyphs
!= cChars
)
2592 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2596 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2597 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2599 /* Step 1: Decompose Vowels */
2600 DecomposeVowels(hdc
, input
, &cCount
, Telugu_vowels
, pwLogClust
, cChars
);
2601 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2603 /* Step 2: Reorder within Syllables */
2604 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, telugu_lex
, Reorder_Like_Bengali
, modern
);
2605 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2606 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2609 /* Step 3: Base Form application to syllables */
2610 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, telugu_lex
, SecondReorder_Like_Telugu
, modern
);
2612 HeapFree(GetProcessHeap(),0,input
);
2613 HeapFree(GetProcessHeap(),0,syllables
);
2616 static int kannada_lex(WCHAR c
)
2620 case 0x0CB0: return lex_Ra
;
2622 return unicode_lex(c
);
2626 static const VowelComponents Kannada_vowels
[] = {
2627 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2628 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2629 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2630 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2631 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2632 {0x0000, {0x0000,0x0000,0x0000}}};
2634 static void ContextualShape_Kannada(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2636 int cCount
= cChars
;
2638 IndicSyllable
*syllables
= NULL
;
2639 int syllable_count
= 0;
2640 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2642 if (*pcGlyphs
!= cChars
)
2644 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2648 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*3) * sizeof(WCHAR
));
2649 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2651 /* Step 1: Decompose Vowels */
2652 DecomposeVowels(hdc
, input
, &cCount
, Kannada_vowels
, pwLogClust
, cChars
);
2653 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2655 /* Step 2: Reorder within Syllables */
2656 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, kannada_lex
, Reorder_Like_Kannada
, modern
);
2657 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2658 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2661 /* Step 3: Base Form application to syllables */
2662 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, kannada_lex
, SecondReorder_Like_Telugu
, modern
);
2664 HeapFree(GetProcessHeap(),0,input
);
2665 HeapFree(GetProcessHeap(),0,syllables
);
2668 static int malayalam_lex(WCHAR c
)
2670 return unicode_lex(c
);
2673 static const VowelComponents Malayalam_vowels
[] = {
2674 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2675 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2676 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2677 {0x0000, {0x0000,0x0000,0x0000}}};
2679 static void ContextualShape_Malayalam(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2681 int cCount
= cChars
;
2683 IndicSyllable
*syllables
= NULL
;
2684 int syllable_count
= 0;
2685 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
2687 if (*pcGlyphs
!= cChars
)
2689 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2693 input
= HeapAlloc(GetProcessHeap(), 0, (cChars
*2) * sizeof(WCHAR
));
2694 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2696 /* Step 1: Decompose Vowels */
2697 DecomposeVowels(hdc
, input
, &cCount
, Malayalam_vowels
, pwLogClust
, cChars
);
2698 TRACE("New composed string %s (%i)\n",debugstr_wn(input
,cCount
),cCount
);
2700 /* Step 2: Reorder within Syllables */
2701 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, malayalam_lex
, Reorder_Like_Devanagari
, modern
);
2702 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2703 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2706 /* Step 3: Base Form application to syllables */
2707 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, malayalam_lex
, SecondReorder_Like_Tamil
, modern
);
2709 HeapFree(GetProcessHeap(),0,input
);
2710 HeapFree(GetProcessHeap(),0,syllables
);
2713 static int khmer_lex(WCHAR c
)
2715 return unicode_lex(c
);
2718 static void ContextualShape_Khmer(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2720 int cCount
= cChars
;
2722 IndicSyllable
*syllables
= NULL
;
2723 int syllable_count
= 0;
2725 if (*pcGlyphs
!= cChars
)
2727 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2731 input
= HeapAlloc(GetProcessHeap(), 0, cChars
* sizeof(WCHAR
));
2732 memcpy(input
, pwcChars
, cChars
* sizeof(WCHAR
));
2734 /* Step 1: Reorder within Syllables */
2735 Indic_ReorderCharacters( hdc
, psa
, psc
, input
, cCount
, &syllables
, &syllable_count
, khmer_lex
, Reorder_Like_Devanagari
, FALSE
);
2736 TRACE("reordered string %s\n",debugstr_wn(input
,cCount
));
2737 GetGlyphIndicesW(hdc
, input
, cCount
, pwOutGlyphs
, 0);
2740 /* Step 2: Base Form application to syllables */
2741 ShapeIndicSyllables(hdc
, psc
, psa
, input
, cChars
, syllables
, syllable_count
, pwOutGlyphs
, pcGlyphs
, pwLogClust
, khmer_lex
, NULL
, FALSE
);
2743 HeapFree(GetProcessHeap(),0,input
);
2744 HeapFree(GetProcessHeap(),0,syllables
);
2747 static inline BOOL
mongolian_wordbreak(WCHAR chr
)
2749 return ((chr
== 0x0020) || (chr
== 0x200C) || (chr
== 0x202F) || (chr
== 0x180E) || (chr
== 0x1800) || (chr
== 0x1802) || (chr
== 0x1803) || (chr
== 0x1805) || (chr
== 0x1808) || (chr
== 0x1809) || (chr
== 0x1807));
2752 static void ContextualShape_Mongolian(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
2758 if (*pcGlyphs
!= cChars
)
2760 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2764 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
2769 if (!psc
->GSUB_Table
)
2772 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
2774 for (i
= 0; i
< cChars
; i
++)
2776 if (i
== 0 || mongolian_wordbreak(pwcChars
[i
-1]))
2778 if ((i
== cChars
-1) || mongolian_wordbreak(pwcChars
[i
+1]))
2779 context_shape
[i
] = Xn
;
2781 context_shape
[i
] = Xl
;
2785 if ((i
== cChars
-1) || mongolian_wordbreak(pwcChars
[i
+1]))
2786 context_shape
[i
] = Xr
;
2788 context_shape
[i
] = Xm
;
2792 /* Contextual Shaping */
2794 while(i
< *pcGlyphs
)
2797 INT prevCount
= *pcGlyphs
;
2798 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
2799 if (nextIndex
> GSUB_E_NOGLYPH
)
2801 UpdateClusters(nextIndex
, *pcGlyphs
- prevCount
, dirL
, cChars
, pwLogClust
);
2808 HeapFree(GetProcessHeap(),0,context_shape
);
2811 static void ShapeCharGlyphProp_Default( ScriptCache
* psc
, SCRIPT_ANALYSIS
* psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
* pwLogClust
, SCRIPT_CHARPROP
* pCharProp
, SCRIPT_GLYPHPROP
* pGlyphProp
)
2815 for (i
= 0; i
< cGlyphs
; i
++)
2820 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2823 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2824 char_index
[char_count
++] = k
;
2827 if (char_count
== 0)
2830 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
2832 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
2833 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
2836 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
2839 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
2840 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
2843 static void ShapeCharGlyphProp_Latin( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2847 ShapeCharGlyphProp_Default( psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
2849 for (i
= 0; i
< cGlyphs
; i
++)
2850 if (pGlyphProp
[i
].sva
.fZeroWidth
)
2851 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2854 static void ShapeCharGlyphProp_Control( HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WCHAR
* pwcChars
, const INT cChars
, const WORD
* pwGlyphs
, const INT cGlyphs
, WORD
*pwLogClust
, SCRIPT_CHARPROP
*pCharProp
, SCRIPT_GLYPHPROP
*pGlyphProp
)
2857 for (i
= 0; i
< cGlyphs
; i
++)
2859 pGlyphProp
[i
].sva
.fClusterStart
= 1;
2860 pGlyphProp
[i
].sva
.fDiacritic
= 0;
2861 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
2863 if (pwGlyphs
[i
] == psc
->sfp
.wgDefault
)
2864 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
2866 pGlyphProp
[i
].sva
.fZeroWidth
= 1;
2870 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
)
2873 int initGlyph
, finaGlyph
;
2877 spaces
= HeapAlloc(GetProcessHeap(),0,cGlyphs
);
2878 memset(spaces
,0,cGlyphs
);
2880 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
2882 initGlyph
= cGlyphs
-1;
2890 finaGlyph
= cGlyphs
-1;
2895 for (i
= 0; i
< cGlyphs
; i
++)
2897 for (k
= 0; k
< cChars
; k
++)
2898 if (pwLogClust
[k
] == i
)
2900 if (pwcChars
[k
] == 0x0020)
2905 for (i
= 0; i
< cGlyphs
; i
++)
2909 BOOL isInit
, isFinal
;
2911 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2914 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2915 char_index
[char_count
++] = k
;
2918 isInit
= (i
== initGlyph
|| (i
+dirR
> 0 && i
+dirR
< cGlyphs
&& spaces
[i
+dirR
]));
2919 isFinal
= (i
== finaGlyph
|| (i
+dirL
> 0 && i
+dirL
< cGlyphs
&& spaces
[i
+dirL
]));
2921 if (char_count
== 0)
2924 if (char_count
== 1)
2926 if (pwcChars
[char_index
[0]] == 0x0020) /* space */
2928 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BLANK
;
2929 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
2931 else if (pwcChars
[char_index
[0]] == 0x0640) /* kashida */
2932 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_KASHIDA
;
2933 else if (pwcChars
[char_index
[0]] == 0x0633) /* SEEN */
2935 if (!isInit
&& !isFinal
)
2936 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_SEEN_M
;
2938 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_SEEN
;
2940 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2944 if (pwcChars
[char_index
[0]] == 0x0628 ) /* BA */
2945 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BA
;
2946 else if (pwcChars
[char_index
[0]] == 0x0631 ) /* RA */
2947 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_RA
;
2948 else if (pwcChars
[char_index
[0]] == 0x0647 ) /* HA */
2949 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_HA
;
2950 else if ((pwcChars
[char_index
[0]] == 0x0627 || pwcChars
[char_index
[0]] == 0x0625 || pwcChars
[char_index
[0]] == 0x0623 || pwcChars
[char_index
[0]] == 0x0622) ) /* alef-like */
2951 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_ALEF
;
2953 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2955 else if (!isInit
&& !isFinal
)
2956 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2958 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2960 else if (char_count
== 2)
2962 if ((pwcChars
[char_index
[0]] == 0x0628 && pwcChars
[char_index
[1]]== 0x0631) || (pwcChars
[char_index
[0]] == 0x0631 && pwcChars
[char_index
[1]]== 0x0628)) /* BA+RA */
2963 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_BARA
;
2965 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2967 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2969 else if (!isInit
&& !isFinal
)
2970 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_ARABIC_NORMAL
;
2972 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
2975 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
2976 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
2977 HeapFree(GetProcessHeap(),0,spaces
);
2980 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
)
2984 for (i
= 0; i
< cGlyphs
; i
++)
2989 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
2992 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
2993 char_index
[char_count
++] = k
;
2996 if (char_count
== 0)
2997 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3000 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3001 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3002 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3006 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3007 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3010 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
)
3016 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
3023 finaGlyph
= cGlyphs
-1;
3027 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3029 for (i
= 0; i
< cGlyphs
; i
++)
3035 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3038 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3039 char_index
[char_count
++] = k
;
3043 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3045 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3047 if (char_count
== 0)
3050 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3051 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3053 /* handle Thai SARA AM (U+0E33) differently than GDEF */
3054 if (char_count
== 1 && pwcChars
[char_index
[0]] == 0x0e33)
3055 pGlyphProp
[i
].sva
.fClusterStart
= 0;
3058 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3060 /* Do not allow justification between marks and their base */
3061 for (i
= 0; i
< cGlyphs
; i
++)
3063 if (!pGlyphProp
[i
].sva
.fClusterStart
)
3064 pGlyphProp
[i
-dirL
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3068 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
)
3072 for (i
= 0; i
< cGlyphs
; i
++)
3077 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3080 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3081 char_index
[char_count
++] = k
;
3084 if (char_count
== 0)
3087 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3089 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_CHARACTER
;
3090 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3093 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3095 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3096 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3099 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
)
3103 for (i
= 0; i
< cGlyphs
; i
++)
3108 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3111 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3112 char_index
[char_count
++] = k
;
3115 if (char_count
== 0)
3118 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3120 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
3121 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3124 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3126 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3127 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3129 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3130 for (i
= 0; i
< cGlyphs
; i
++)
3132 if (!pGlyphProp
[i
].sva
.fClusterStart
)
3134 pGlyphProp
[i
].sva
.fDiacritic
= 0;
3135 pGlyphProp
[i
].sva
.fZeroWidth
= 0;
3140 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
)
3144 OpenType_GDEF_UpdateGlyphProps(psc
, pwGlyphs
, cGlyphs
, pwLogClust
, cChars
, pGlyphProp
);
3145 for (i
= 0; i
< cGlyphs
; i
++)
3150 k
= USP10_FindGlyphInLogClust(pwLogClust
, cChars
, i
);
3153 for (; k
< cChars
&& pwLogClust
[k
] == i
; k
++)
3154 char_index
[char_count
++] = k
;
3159 /* Most indic scripts do not set fDiacritic or fZeroWidth */
3160 pGlyphProp
[i
].sva
.fDiacritic
= FALSE
;
3161 pGlyphProp
[i
].sva
.fZeroWidth
= FALSE
;
3164 if (char_count
== 0)
3166 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3170 if (char_count
==1 && pwcChars
[char_index
[0]] == 0x0020) /* space */
3172 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_BLANK
;
3173 pCharProp
[char_index
[0]].fCanGlyphAlone
= 1;
3176 pGlyphProp
[i
].sva
.uJustification
= SCRIPT_JUSTIFY_NONE
;
3178 pGlyphProp
[i
].sva
.fClusterStart
= 0;
3179 for (k
= 0; k
< char_count
&& !pGlyphProp
[i
].sva
.fClusterStart
; k
++)
3180 switch (lexical(pwcChars
[char_index
[k
]]))
3183 case lex_Matra_post
:
3184 case lex_Matra_above
:
3185 case lex_Matra_below
:
3191 /* check for dangling joiners */
3192 if (pwcChars
[char_index
[k
]-1] == 0x0020 || pwcChars
[char_index
[k
]+1] == 0x0020)
3193 pGlyphProp
[i
].sva
.fClusterStart
= 1;
3198 pGlyphProp
[i
].sva
.fClusterStart
= 1;
3205 IndicSyllable
*syllables
= NULL
;
3206 int syllable_count
= 0;
3207 BOOL modern
= get_GSUB_Indic2(psa
, psc
);
3209 Indic_ParseSyllables( hdc
, psa
, psc
, pwcChars
, cChars
, &syllables
, &syllable_count
, lexical
, modern
);
3211 for (i
= 0; i
< syllable_count
; i
++)
3214 WORD g
= pwLogClust
[syllables
[i
].start
];
3215 for (j
= syllables
[i
].start
+1; j
<= syllables
[i
].end
; j
++)
3217 if (pwLogClust
[j
] != g
)
3219 pGlyphProp
[pwLogClust
[j
]].sva
.fClusterStart
= 0;
3225 HeapFree(GetProcessHeap(), 0, syllables
);
3228 UpdateClustersFromGlyphProp(cGlyphs
, cChars
, pwLogClust
, pGlyphProp
);
3231 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
)
3233 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, sinhala_lex
, FALSE
, FALSE
);
3236 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
)
3238 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, devanagari_lex
, TRUE
, TRUE
);
3241 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
)
3243 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, bengali_lex
, TRUE
, TRUE
);
3246 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
)
3248 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, gurmukhi_lex
, TRUE
, TRUE
);
3251 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
)
3253 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, gujarati_lex
, TRUE
, TRUE
);
3256 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
)
3258 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, oriya_lex
, TRUE
, TRUE
);
3261 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
)
3263 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, tamil_lex
, TRUE
, TRUE
);
3266 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
)
3268 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, telugu_lex
, TRUE
, TRUE
);
3271 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
)
3273 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, kannada_lex
, TRUE
, TRUE
);
3276 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
)
3278 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, malayalam_lex
, TRUE
, TRUE
);
3281 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
)
3283 ShapeCharGlyphProp_BaseIndic(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
, khmer_lex
, TRUE
, TRUE
);
3286 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
)
3288 load_ot_tables(hdc
, psc
);
3290 if (ShapingData
[psa
->eScript
].charGlyphPropProc
)
3291 ShapingData
[psa
->eScript
].charGlyphPropProc(hdc
, psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
3293 ShapeCharGlyphProp_Default(psc
, psa
, pwcChars
, cChars
, pwGlyphs
, cGlyphs
, pwLogClust
, pCharProp
, pGlyphProp
);
3296 void SHAPE_ContextualShaping(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, WORD
*pwLogClust
)
3298 load_ot_tables(hdc
, psc
);
3300 if (ShapingData
[psa
->eScript
].contextProc
)
3301 ShapingData
[psa
->eScript
].contextProc(hdc
, psc
, psa
, pwcChars
, cChars
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, pwLogClust
);
3304 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
)
3309 if (!rpRangeProperties
)
3312 load_ot_tables(hdc
, psc
);
3314 if (!psc
->GSUB_Table
)
3317 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
3322 for (i
= 0; i
< rpRangeProperties
->cotfRecords
; i
++)
3324 if (rpRangeProperties
->potfRecords
[i
].lParameter
> 0)
3325 apply_GSUB_feature(hdc
, psa
, psc
, pwOutGlyphs
, dirL
, pcGlyphs
, cChars
, (const char*)&rpRangeProperties
->potfRecords
[i
].tagFeature
, pwLogClust
);
3329 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
, INT cChars
, WORD
*pwLogClust
)
3331 const TEXTRANGE_PROPERTIES
*rpRangeProperties
;
3332 rpRangeProperties
= &ShapingData
[psa
->eScript
].defaultTextRange
;
3334 SHAPE_ApplyOpenTypeFeatures(hdc
, psc
, psa
, pwOutGlyphs
, pcGlyphs
, cMaxGlyphs
, cChars
, rpRangeProperties
, pwLogClust
);
3337 void SHAPE_ApplyOpenTypePositions(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, const WORD
* pwGlyphs
, INT cGlyphs
, int *piAdvance
, GOFFSET
*pGoffset
)
3339 const TEXTRANGE_PROPERTIES
*rpRangeProperties
;
3342 rpRangeProperties
= &ShapingData
[psa
->eScript
].defaultGPOSTextRange
;
3344 if (!rpRangeProperties
)
3347 load_ot_tables(hdc
, psc
);
3349 if (!psc
->GPOS_Table
|| !psc
->otm
)
3352 for (i
= 0; i
< rpRangeProperties
->cotfRecords
; i
++)
3354 if (rpRangeProperties
->potfRecords
[i
].lParameter
> 0)
3356 LoadedFeature
*feature
;
3358 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_GPOS_TABLE
, (const char*)&rpRangeProperties
->potfRecords
[i
].tagFeature
);
3362 GPOS_apply_feature(psc
, psc
->otm
, &psc
->lf
, psa
, piAdvance
, feature
, pwGlyphs
, cGlyphs
, pGoffset
);
3367 HRESULT
SHAPE_CheckFontForRequiredFeatures(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
)
3369 LoadedFeature
*feature
;
3372 if (!ShapingData
[psa
->eScript
].requiredFeatures
)
3375 load_ot_tables(hdc
, psc
);
3377 /* we need to have at least one of the required features */
3379 while (ShapingData
[psa
->eScript
].requiredFeatures
[i
])
3381 feature
= load_OT_feature(hdc
, psa
, psc
, FEATURE_ALL_TABLES
, ShapingData
[psa
->eScript
].requiredFeatures
[i
]);
3387 return USP_E_SCRIPT_NOT_IN_FONT
;
3390 HRESULT
SHAPE_GetFontScriptTags( HDC hdc
, ScriptCache
*psc
,
3391 SCRIPT_ANALYSIS
*psa
, int cMaxTags
,
3392 OPENTYPE_TAG
*pScriptTags
, int *pcTags
)
3395 OPENTYPE_TAG searching
= 0x00000000;
3397 load_ot_tables(hdc
, psc
);
3399 if (psa
&& scriptInformation
[psa
->eScript
].scriptTag
)
3400 searching
= scriptInformation
[psa
->eScript
].scriptTag
;
3402 hr
= OpenType_GetFontScriptTags(psc
, searching
, cMaxTags
, pScriptTags
, pcTags
);
3408 HRESULT
SHAPE_GetFontLanguageTags( HDC hdc
, ScriptCache
*psc
,
3409 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
3410 int cMaxTags
, OPENTYPE_TAG
*pLangSysTags
,
3414 OPENTYPE_TAG searching
= 0x00000000;
3415 BOOL fellback
= FALSE
;
3417 load_ot_tables(hdc
, psc
);
3419 if (psa
&& psc
->userLang
!= 0)
3420 searching
= psc
->userLang
;
3422 hr
= OpenType_GetFontLanguageTags(psc
, tagScript
, searching
, cMaxTags
, pLangSysTags
, pcTags
);
3426 hr
= OpenType_GetFontLanguageTags(psc
, MS_MAKE_TAG('l','a','t','n'), searching
, cMaxTags
, pLangSysTags
, pcTags
);
3429 if (FAILED(hr
) || fellback
)
3431 if (SUCCEEDED(hr
) && fellback
&& psa
)
3436 HRESULT
SHAPE_GetFontFeatureTags( HDC hdc
, ScriptCache
*psc
,
3437 SCRIPT_ANALYSIS
*psa
, OPENTYPE_TAG tagScript
,
3438 OPENTYPE_TAG tagLangSys
, int cMaxTags
,
3439 OPENTYPE_TAG
*pFeatureTags
, int *pcTags
)
3442 BOOL filter
= FALSE
;
3444 load_ot_tables(hdc
, psc
);
3446 if (psa
&& scriptInformation
[psa
->eScript
].scriptTag
)
3448 FIXME("Filtering not implemented\n");
3452 hr
= OpenType_GetFontFeatureTags(psc
, tagScript
, tagLangSys
, filter
, 0x00000000, FEATURE_ALL_TABLES
, cMaxTags
, pFeatureTags
, pcTags
, NULL
);