2 * Implementation of Shaping for the Uniscribe Script Processor (usp10.dll)
4 * Copyright 2010 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "usp10_internal.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
38 #define FIRST_ARABIC_CHAR 0x0600
39 #define LAST_ARABIC_CHAR 0x06ff
41 typedef VOID (*ContextualShapingProc)(HDC, ScriptCache*, SCRIPT_ANALYSIS*,
42 WCHAR*, INT, WORD*, INT*, INT, WORD*);
44 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
45 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
46 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
47 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
48 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
49 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
50 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
51 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
52 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
53 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
54 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
55 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
56 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
57 static void ContextualShape_Khmer(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
58 static void ContextualShape_Mongolian(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
60 typedef VOID (*ShapeCharGlyphPropProc)( HDC , ScriptCache*, SCRIPT_ANALYSIS*, const WCHAR*, const INT, const WORD*, const INT, WORD*, SCRIPT_CHARPROP*, SCRIPT_GLYPHPROP*);
62 static void ShapeCharGlyphProp_Default( HDC hdc, ScriptCache* psc, SCRIPT_ANALYSIS* psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD* pwLogClust, SCRIPT_CHARPROP* pCharProp, SCRIPT_GLYPHPROP* pGlyphProp);
63 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 );
64 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 );
65 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 );
66 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 );
67 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 );
68 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 );
69 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 );
70 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 );
71 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 );
72 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 );
73 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 );
74 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 );
75 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 );
76 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 );
77 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 );
79 extern const unsigned short indic_syllabic_table[];
80 extern const unsigned short wine_shaping_table[];
81 extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
103 #ifdef WORDS_BIGENDIAN
104 #define GET_BE_WORD(x) (x)
105 #define GET_BE_DWORD(x) (x)
107 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
108 #define GET_BE_DWORD(x) RtlUlongByteSwap(x)
111 /* These are all structures needed for the GSUB table */
112 #define GSUB_TAG MS_MAKE_TAG('G', 'S', 'U', 'B')
113 #define GSUB_E_NOFEATURE -2
114 #define GSUB_E_NOGLYPH -1
130 GSUB_ScriptRecord ScriptRecord[1];
136 } GSUB_LangSysRecord;
141 GSUB_LangSysRecord LangSysRecord[1];
145 WORD LookupOrder; /* Reserved */
146 WORD ReqFeatureIndex;
148 WORD FeatureIndex[1];
154 } GSUB_FeatureRecord;
158 GSUB_FeatureRecord FeatureRecord[1];
162 WORD FeatureParams; /* Reserved */
164 WORD LookupListIndex[1];
183 } GSUB_CoverageFormat1;
188 WORD StartCoverageIndex;
194 GSUB_RangeRecord RangeRecord[1];
195 } GSUB_CoverageFormat2;
198 WORD SubstFormat; /* = 1 */
201 } GSUB_SingleSubstFormat1;
204 WORD SubstFormat; /* = 2 */
208 }GSUB_SingleSubstFormat2;
211 WORD SubstFormat; /* = 1 */
215 }GSUB_MultipleSubstFormat1;
223 WORD SubstFormat; /* = 1 */
227 }GSUB_LigatureSubstFormat1;
242 WORD LookupListIndex;
244 }GSUB_SubstLookupRecord;
247 WORD SubstFormat; /* = 1 */
249 WORD ChainSubRuleSetCount;
250 WORD ChainSubRuleSet[1];
251 }GSUB_ChainContextSubstFormat1;
254 WORD SubstFormat; /* = 3 */
255 WORD BacktrackGlyphCount;
257 }GSUB_ChainContextSubstFormat3_1;
260 WORD InputGlyphCount;
262 }GSUB_ChainContextSubstFormat3_2;
265 WORD LookaheadGlyphCount;
267 }GSUB_ChainContextSubstFormat3_3;
271 GSUB_SubstLookupRecord SubstLookupRecord[1];
272 }GSUB_ChainContextSubstFormat3_4;
275 WORD SubstFormat; /* = 1 */
277 WORD AlternateSetCount;
278 WORD AlternateSet[1];
279 } GSUB_AlternateSubstFormat1;
286 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count);
287 static HRESULT GSUB_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags, LPCVOID* script_table);
288 static HRESULT GSUB_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags, LPCVOID* language_table);
289 static HRESULT GSUB_GetFontFeatureTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG language_tag, BOOL filtered, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags, LoadedFeature** feature);
291 typedef struct tagVowelComponents
297 typedef struct tagConsonantComponents
301 } ConsonantComponents;
303 typedef void (*second_reorder_function)(LPWSTR pwChar, IndicSyllable *syllable,WORD* pwGlyphs, IndicSyllable* glyph_index, lexical_function lex);
305 /* the orders of joined_forms and contextual_features need to line up */
306 static const char* contextual_features[] =
318 static OPENTYPE_FEATURE_RECORD standard_features[] =
320 { MS_MAKE_TAG('c','c','m','p'), 1},
321 { MS_MAKE_TAG('l','o','c','l'), 1},
324 static OPENTYPE_FEATURE_RECORD latin_features[] =
326 { MS_MAKE_TAG('l','i','g','a'), 1},
327 { MS_MAKE_TAG('c','l','i','g'), 1},
330 static OPENTYPE_FEATURE_RECORD arabic_features[] =
332 { MS_MAKE_TAG('r','l','i','g'), 1},
333 { MS_MAKE_TAG('c','a','l','t'), 1},
334 { MS_MAKE_TAG('l','i','g','a'), 1},
335 { MS_MAKE_TAG('d','l','i','g'), 1},
336 { MS_MAKE_TAG('c','s','w','h'), 1},
337 { MS_MAKE_TAG('m','s','e','t'), 1},
340 static const char* required_arabic_features[] =
349 static OPENTYPE_FEATURE_RECORD hebrew_features[] =
351 { MS_MAKE_TAG('d','l','i','g'), 0},
354 static OPENTYPE_FEATURE_RECORD syriac_features[] =
356 { MS_MAKE_TAG('r','l','i','g'), 1},
357 { MS_MAKE_TAG('c','a','l','t'), 1},
358 { MS_MAKE_TAG('l','i','g','a'), 1},
359 { MS_MAKE_TAG('d','l','i','g'), 1},
362 static const char* required_syriac_features[] =
374 static OPENTYPE_FEATURE_RECORD sinhala_features[] =
376 /* Presentation forms */
377 { MS_MAKE_TAG('b','l','w','s'), 1},
378 { MS_MAKE_TAG('a','b','v','s'), 1},
379 { MS_MAKE_TAG('p','s','t','s'), 1},
382 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
384 { MS_MAKE_TAG('a','b','v','s'), 1},
385 { MS_MAKE_TAG('b','l','w','s'), 1},
388 static OPENTYPE_FEATURE_RECORD phags_features[] =
390 { MS_MAKE_TAG('a','b','v','s'), 1},
391 { MS_MAKE_TAG('b','l','w','s'), 1},
392 { MS_MAKE_TAG('c','a','l','t'), 1},
395 static OPENTYPE_FEATURE_RECORD thai_features[] =
397 { MS_MAKE_TAG('c','c','m','p'), 1},
400 static const char* required_lao_features[] =
406 static const char* required_devanagari_features[] =
422 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
424 { MS_MAKE_TAG('p','r','e','s'), 1},
425 { MS_MAKE_TAG('a','b','v','s'), 1},
426 { MS_MAKE_TAG('b','l','w','s'), 1},
427 { MS_MAKE_TAG('p','s','t','s'), 1},
428 { MS_MAKE_TAG('h','a','l','n'), 1},
429 { MS_MAKE_TAG('c','a','l','t'), 1},
432 static OPENTYPE_FEATURE_RECORD myanmar_features[] =
434 { MS_MAKE_TAG('l','i','g','a'), 1},
435 { MS_MAKE_TAG('c','l','i','g'), 1},
438 static const char* required_bengali_features[] =
455 static const char* required_gurmukhi_features[] =
474 static const char* required_oriya_features[] =
491 static const char* required_tamil_features[] =
507 static const char* required_telugu_features[] =
525 static OPENTYPE_FEATURE_RECORD khmer_features[] =
527 { MS_MAKE_TAG('p','r','e','s'), 1},
528 { MS_MAKE_TAG('b','l','w','s'), 1},
529 { MS_MAKE_TAG('a','b','v','s'), 1},
530 { MS_MAKE_TAG('p','s','t','s'), 1},
531 { MS_MAKE_TAG('c','l','i','g'), 1},
534 static const char* required_khmer_features[] =
548 static OPENTYPE_FEATURE_RECORD no_features[] =
551 static OPENTYPE_FEATURE_RECORD ethiopic_features[] =
553 { MS_MAKE_TAG('c','c','m','p'), 1},
554 { MS_MAKE_TAG('l','o','c','l'), 1},
555 { MS_MAKE_TAG('c','a','l','t'), 1},
556 { MS_MAKE_TAG('l','i','g','a'), 1},
559 static OPENTYPE_FEATURE_RECORD mongolian_features[] =
561 { MS_MAKE_TAG('c','c','m','p'), 1},
562 { MS_MAKE_TAG('l','o','c','l'), 1},
563 { MS_MAKE_TAG('c','a','l','t'), 1},
564 { MS_MAKE_TAG('r','l','i','g'), 1},
567 typedef struct ScriptShapeDataTag {
568 TEXTRANGE_PROPERTIES defaultTextRange;
569 const char** requiredFeatures;
570 OPENTYPE_TAG newOtTag;
571 ContextualShapingProc contextProc;
572 ShapeCharGlyphPropProc charGlyphPropProc;
575 /* in order of scripts */
576 static const ScriptShapeData ShapingData[] =
578 {{ standard_features, 2}, NULL, 0, NULL, NULL},
579 {{ latin_features, 2}, NULL, 0, NULL, NULL},
580 {{ latin_features, 2}, NULL, 0, NULL, NULL},
581 {{ latin_features, 2}, NULL, 0, NULL, NULL},
582 {{ standard_features, 2}, NULL, 0, NULL, NULL},
583 {{ latin_features, 2}, NULL, 0, NULL, NULL},
584 {{ arabic_features, 6}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
585 {{ arabic_features, 6}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
586 {{ hebrew_features, 1}, NULL, 0, NULL, NULL},
587 {{ syriac_features, 4}, required_syriac_features, 0, ContextualShape_Syriac, ShapeCharGlyphProp_None},
588 {{ arabic_features, 6}, required_arabic_features, 0, ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
589 {{ NULL, 0}, NULL, 0, NULL, ShapeCharGlyphProp_None},
590 {{ standard_features, 2}, NULL, 0, NULL, NULL},
591 {{ standard_features, 2}, NULL, 0, NULL, NULL},
592 {{ standard_features, 2}, NULL, 0, NULL, NULL},
593 {{ standard_features, 2}, NULL, 0, NULL, NULL},
594 {{ sinhala_features, 3}, NULL, 0, ContextualShape_Sinhala, ShapeCharGlyphProp_Sinhala},
595 {{ tibetan_features, 2}, NULL, 0, NULL, ShapeCharGlyphProp_Tibet},
596 {{ tibetan_features, 2}, NULL, 0, NULL, ShapeCharGlyphProp_Tibet},
597 {{ phags_features, 3}, NULL, 0, ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
598 {{ thai_features, 1}, NULL, 0, NULL, ShapeCharGlyphProp_Thai},
599 {{ thai_features, 1}, NULL, 0, NULL, ShapeCharGlyphProp_Thai},
600 {{ thai_features, 1}, required_lao_features, 0, NULL, ShapeCharGlyphProp_Thai},
601 {{ thai_features, 1}, required_lao_features, 0, NULL, ShapeCharGlyphProp_Thai},
602 {{ devanagari_features, 6}, required_devanagari_features, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
603 {{ devanagari_features, 6}, required_devanagari_features, MS_MAKE_TAG('d','e','v','2'), ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
604 {{ devanagari_features, 6}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
605 {{ devanagari_features, 6}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
606 {{ devanagari_features, 6}, required_bengali_features, MS_MAKE_TAG('b','n','g','2'), ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
607 {{ devanagari_features, 6}, required_gurmukhi_features, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
608 {{ devanagari_features, 6}, required_gurmukhi_features, MS_MAKE_TAG('g','u','r','2'), ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
609 {{ devanagari_features, 6}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
610 {{ devanagari_features, 6}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
611 {{ devanagari_features, 6}, required_devanagari_features, MS_MAKE_TAG('g','j','r','2'), ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
612 {{ devanagari_features, 6}, required_oriya_features, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
613 {{ devanagari_features, 6}, required_oriya_features, MS_MAKE_TAG('o','r','y','2'), ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
614 {{ devanagari_features, 6}, required_tamil_features, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
615 {{ devanagari_features, 6}, required_tamil_features, MS_MAKE_TAG('t','a','m','2'), ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
616 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
617 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('t','e','l','2'), ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
618 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
619 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('k','n','d','2'), ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
620 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
621 {{ devanagari_features, 6}, required_telugu_features, MS_MAKE_TAG('m','l','m','2'), ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
622 {{ standard_features, 2}, NULL, 0, NULL, NULL},
623 {{ latin_features, 2}, NULL, 0, NULL, NULL},
624 {{ standard_features, 2}, NULL, 0, NULL, NULL},
625 {{ myanmar_features, 2}, NULL, 0, NULL, NULL},
626 {{ myanmar_features, 2}, NULL, 0, NULL, NULL},
627 {{ standard_features, 2}, NULL, 0, NULL, NULL},
628 {{ standard_features, 2}, NULL, 0, NULL, NULL},
629 {{ standard_features, 2}, NULL, 0, NULL, NULL},
630 {{ khmer_features, 5}, required_khmer_features, 0, ContextualShape_Khmer, ShapeCharGlyphProp_Khmer},
631 {{ khmer_features, 5}, required_khmer_features, 0, ContextualShape_Khmer, ShapeCharGlyphProp_Khmer},
632 {{ no_features, 0}, NULL, 0, NULL, NULL},
633 {{ no_features, 0}, NULL, 0, NULL, NULL},
634 {{ no_features, 0}, NULL, 0, NULL, NULL},
635 {{ no_features, 0}, NULL, 0, NULL, NULL},
636 {{ no_features, 0}, NULL, 0, NULL, NULL},
637 {{ no_features, 0}, NULL, 0, NULL, NULL},
638 {{ ethiopic_features, 4}, NULL, 0, NULL, NULL},
639 {{ ethiopic_features, 4}, NULL, 0, NULL, NULL},
640 {{ mongolian_features, 4}, NULL, 0, ContextualShape_Mongolian, NULL},
641 {{ mongolian_features, 4}, NULL, 0, ContextualShape_Mongolian, NULL},
642 {{ no_features, 0}, NULL, 0, NULL, NULL},
643 {{ no_features, 0}, NULL, 0, NULL, NULL},
644 {{ no_features, 0}, NULL, 0, NULL, NULL},
645 {{ no_features, 0}, NULL, 0, NULL, NULL},
646 {{ no_features, 0}, NULL, 0, NULL, NULL},
647 {{ no_features, 0}, NULL, 0, NULL, NULL},
648 {{ no_features, 0}, NULL, 0, NULL, NULL},
649 {{ no_features, 0}, NULL, 0, NULL, NULL},
650 {{ no_features, 0}, NULL, 0, NULL, NULL},
651 {{ no_features, 0}, NULL, 0, NULL, NULL},
652 {{ no_features, 0}, NULL, 0, NULL, NULL},
653 {{ no_features, 0}, NULL, 0, NULL, NULL},
654 {{ no_features, 0}, NULL, 0, NULL, NULL},
655 {{ no_features, 0}, NULL, 0, NULL, NULL},
656 {{ no_features, 0}, NULL, 0, NULL, NULL},
657 {{ hebrew_features, 1}, NULL, 0, NULL, NULL},
658 {{ latin_features, 2}, NULL, 0, NULL, NULL},
659 {{ thai_features, 1}, NULL, 0, NULL, ShapeCharGlyphProp_Thai},
662 extern scriptData scriptInformation[];
664 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
666 const GSUB_CoverageFormat1* cf1;
670 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
672 int count = GET_BE_WORD(cf1->GlyphCount);
674 TRACE("Coverage Format 1, %i glyphs\n",count);
675 for (i = 0; i < count; i++)
676 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
680 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
682 const GSUB_CoverageFormat2* cf2;
685 cf2 = (const GSUB_CoverageFormat2*)cf1;
687 count = GET_BE_WORD(cf2->RangeCount);
688 TRACE("Coverage Format 2, %i ranges\n",count);
689 for (i = 0; i < count; i++)
691 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
693 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
694 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
696 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
697 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
703 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
708 static INT GSUB_apply_SingleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
711 TRACE("Single Substitution Subtable\n");
713 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
716 const GSUB_SingleSubstFormat1 *ssf1;
717 offset = GET_BE_WORD(look->SubTable[j]);
718 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
719 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
721 int offset = GET_BE_WORD(ssf1->Coverage);
722 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
723 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
725 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
726 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
727 TRACE(" 0x%x\n",glyphs[glyph_index]);
728 return glyph_index + write_dir;
733 const GSUB_SingleSubstFormat2 *ssf2;
737 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
738 offset = GET_BE_WORD(ssf1->Coverage);
739 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
740 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
741 TRACE(" Coverage index %i\n",index);
744 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
745 return GSUB_E_NOGLYPH;
747 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
748 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
749 TRACE("0x%x\n",glyphs[glyph_index]);
750 return glyph_index + write_dir;
754 return GSUB_E_NOGLYPH;
757 static INT GSUB_apply_MultipleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
760 TRACE("Multiple Substitution Subtable\n");
762 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
765 const GSUB_MultipleSubstFormat1 *msf1;
766 offset = GET_BE_WORD(look->SubTable[j]);
767 msf1 = (const GSUB_MultipleSubstFormat1*)((const BYTE*)look+offset);
769 offset = GET_BE_WORD(msf1->Coverage);
770 index = GSUB_is_glyph_covered((const BYTE*)msf1+offset, glyphs[glyph_index]);
773 const GSUB_Sequence *seq;
776 offset = GET_BE_WORD(msf1->Sequence[index]);
777 seq = (const GSUB_Sequence*)((const BYTE*)msf1+offset);
778 sub_count = GET_BE_WORD(seq->GlyphCount);
779 TRACE(" Glyph 0x%x (+%i)->",glyphs[glyph_index],(sub_count-1));
781 for (j = (*glyph_count)+(sub_count-1); j > glyph_index; j--)
782 glyphs[j] =glyphs[j-(sub_count-1)];
784 for (j = 0; j < sub_count; j++)
786 glyphs[glyph_index + (sub_count-1) - j] = GET_BE_WORD(seq->Substitute[j]);
788 glyphs[glyph_index + j] = GET_BE_WORD(seq->Substitute[j]);
790 *glyph_count = *glyph_count + (sub_count - 1);
792 if (TRACE_ON(uniscribe))
794 for (j = 0; j < sub_count; j++)
795 TRACE(" 0x%x",glyphs[glyph_index+j]);
799 return glyph_index + (sub_count * write_dir);
802 return GSUB_E_NOGLYPH;
805 static INT GSUB_apply_AlternateSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
808 TRACE("Alternate Substitution Subtable\n");
810 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
813 const GSUB_AlternateSubstFormat1 *asf1;
816 offset = GET_BE_WORD(look->SubTable[j]);
817 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
818 offset = GET_BE_WORD(asf1->Coverage);
820 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
823 const GSUB_AlternateSet *as;
824 offset = GET_BE_WORD(asf1->AlternateSet[index]);
825 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
826 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
827 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
828 return GSUB_E_NOGLYPH;
830 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
831 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
832 TRACE(" 0x%x\n",glyphs[glyph_index]);
833 return glyph_index + write_dir;
836 return GSUB_E_NOGLYPH;
839 static INT GSUB_apply_LigatureSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
843 TRACE("Ligature Substitution Subtable\n");
844 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
846 const GSUB_LigatureSubstFormat1 *lsf1;
849 offset = GET_BE_WORD(look->SubTable[j]);
850 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
851 offset = GET_BE_WORD(lsf1->Coverage);
852 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
853 TRACE(" Coverage index %i\n",index);
856 const GSUB_LigatureSet *ls;
859 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
860 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
861 count = GET_BE_WORD(ls->LigatureCount);
862 TRACE(" LigatureSet has %i members\n",count);
863 for (k = 0; k < count; k++)
865 const GSUB_Ligature *lig;
866 int CompCount,l,CompIndex;
868 offset = GET_BE_WORD(ls->Ligature[k]);
869 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
870 CompCount = GET_BE_WORD(lig->CompCount) - 1;
871 CompIndex = glyph_index+write_dir;
872 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
875 CompGlyph = GET_BE_WORD(lig->Component[l]);
876 if (CompGlyph != glyphs[CompIndex])
878 CompIndex += write_dir;
882 int replaceIdx = glyph_index;
884 replaceIdx = glyph_index - CompCount;
886 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
887 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
888 TRACE("0x%x\n",glyphs[replaceIdx]);
892 for (j = replaceIdx + 1; j < *glyph_count; j++)
893 glyphs[j] =glyphs[j+CompCount];
894 *glyph_count = *glyph_count - CompCount;
896 return replaceIdx + write_dir;
901 return GSUB_E_NOGLYPH;
904 static INT GSUB_apply_ChainContextSubst(const GSUB_LookupList* lookup, const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
909 TRACE("Chaining Contextual Substitution Subtable\n");
910 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
912 const GSUB_ChainContextSubstFormat1 *ccsf1;
914 int dirLookahead = write_dir;
915 int dirBacktrack = -1 * write_dir;
917 offset = GET_BE_WORD(look->SubTable[j]);
918 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
919 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
921 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
924 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
926 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
929 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
933 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
934 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
935 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
936 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
937 int newIndex = glyph_index;
939 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
941 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
943 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
945 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
946 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
949 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
951 TRACE("Matched Backtrack\n");
953 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)(((LPBYTE)ccsf1)+sizeof(GSUB_ChainContextSubstFormat3_1) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)-1)));
955 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
956 for (k = 0; k < indexGlyphs; k++)
958 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
959 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
962 if (k != indexGlyphs)
964 TRACE("Matched IndexGlyphs\n");
966 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)(((LPBYTE)ccsf3_2)+sizeof(GSUB_ChainContextSubstFormat3_2) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_2->InputGlyphCount)-1)));
968 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
970 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
971 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
974 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
976 TRACE("Matched LookAhead\n");
978 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)(((LPBYTE)ccsf3_3)+sizeof(GSUB_ChainContextSubstFormat3_3) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)-1)));
980 if (GET_BE_WORD(ccsf3_4->SubstCount))
982 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
984 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
985 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
987 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
988 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
991 ERR("Chain failed to generate a glyph\n");
997 else return GSUB_E_NOGLYPH;
1003 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1006 const GSUB_LookupTable *look;
1008 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1009 look = (const GSUB_LookupTable*)((const BYTE*)lookup + offset);
1010 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1011 switch(GET_BE_WORD(look->LookupType))
1014 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1016 return GSUB_apply_MultipleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1018 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1020 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1022 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
1024 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1026 return GSUB_E_NOGLYPH;
1029 static INT apply_GSUB_lookup(LPCVOID table, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1031 const GSUB_Header *header = (const GSUB_Header *)table;
1032 const GSUB_LookupList *lookup = (const GSUB_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1034 return GSUB_apply_lookup(lookup, lookup_index, glyphs, glyph_index, write_dir, glyph_count);
1037 static INT GSUB_apply_feature_all_lookups(LPCVOID header, LoadedFeature *feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1040 int out_index = GSUB_E_NOGLYPH;
1042 TRACE("%i lookups\n", feature->lookup_count);
1043 for (i = 0; i < feature->lookup_count; i++)
1045 out_index = apply_GSUB_lookup(header, feature->lookups[i], glyphs, glyph_index, write_dir, glyph_count);
1046 if (out_index != GSUB_E_NOGLYPH)
1049 if (out_index == GSUB_E_NOGLYPH)
1050 TRACE("lookups found no glyphs\n");
1054 out2 = GSUB_apply_feature_all_lookups(header, feature, glyphs, glyph_index, write_dir, glyph_count);
1055 if (out2!=GSUB_E_NOGLYPH)
1061 static OPENTYPE_TAG get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
1065 if (psc->userScript != 0)
1067 if (tryNew && ShapingData[psa->eScript].newOtTag != 0 && psc->userScript == scriptInformation[psa->eScript].scriptTag)
1068 return ShapingData[psa->eScript].newOtTag;
1070 return psc->userScript;
1073 if (tryNew && ShapingData[psa->eScript].newOtTag != 0)
1074 return ShapingData[psa->eScript].newOtTag;
1076 if (scriptInformation[psa->eScript].scriptTag)
1077 return scriptInformation[psa->eScript].scriptTag;
1080 * fall back to the font charset
1082 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
1086 case BALTIC_CHARSET: return MS_MAKE_TAG('l','a','t','n');
1087 case CHINESEBIG5_CHARSET: return MS_MAKE_TAG('h','a','n','i');
1088 case EASTEUROPE_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
1089 case GB2312_CHARSET: return MS_MAKE_TAG('h','a','n','i');
1090 case GREEK_CHARSET: return MS_MAKE_TAG('g','r','e','k');
1091 case HANGUL_CHARSET: return MS_MAKE_TAG('h','a','n','g');
1092 case RUSSIAN_CHARSET: return MS_MAKE_TAG('c','y','r','l');
1093 case SHIFTJIS_CHARSET: return MS_MAKE_TAG('k','a','n','a');
1094 case TURKISH_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
1095 case VIETNAMESE_CHARSET: return MS_MAKE_TAG('l','a','t','n');
1096 case JOHAB_CHARSET: return MS_MAKE_TAG('l','a','t','n'); /* ?? */
1097 case ARABIC_CHARSET: return MS_MAKE_TAG('a','r','a','b');
1098 case HEBREW_CHARSET: return MS_MAKE_TAG('h','e','b','r');
1099 case THAI_CHARSET: return MS_MAKE_TAG('t','h','a','i');
1100 default: return MS_MAKE_TAG('l','a','t','n');
1104 static LoadedFeature* load_GSUB_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, const char* feat)
1106 LoadedFeature *feature = NULL;
1108 if (psc->GSUB_Table)
1112 OPENTYPE_TAG language;
1113 OPENTYPE_TAG script;
1118 script = get_opentype_script(hdc,psa,psc,(attempt==2));
1119 if (psc->userLang != 0)
1120 language = psc->userLang;
1122 language = MS_MAKE_TAG('d','f','l','t');
1125 GSUB_GetFontFeatureTags(psc, script, language, FALSE, MS_MAKE_TAG(feat[0],feat[1],feat[2],feat[3]), 1, &tags, &cTags, &feature);
1127 } while(attempt && !feature);
1129 /* try in the default (latin) table */
1131 GSUB_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]), 1, &tags, &cTags, &feature);
1134 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
1138 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)
1140 LoadedFeature *feature;
1142 feature = load_GSUB_feature(hdc, psa, psc, feat);
1144 return GSUB_E_NOFEATURE;
1146 TRACE("applying feature %s\n",feat);
1147 return GSUB_apply_feature_all_lookups(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
1150 static VOID *load_gsub_table(HDC hdc)
1152 VOID* GSUB_Table = NULL;
1153 int length = GetFontData(hdc, GSUB_TAG , 0, NULL, 0);
1154 if (length != GDI_ERROR)
1156 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
1157 GetFontData(hdc, GSUB_TAG , 0, GSUB_Table, length);
1158 TRACE("Loaded GSUB table of %i bytes\n",length);
1163 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)
1166 INT glyph_count = count;
1169 glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*(count*2));
1170 GetGlyphIndicesW(hdc, chars, count, glyphs, 0);
1171 rc = apply_GSUB_feature_to_glyph(hdc, psa, psc, glyphs, 0, write_dir, &glyph_count, feature);
1172 if (rc > GSUB_E_NOGLYPH)
1173 rc = count - glyph_count;
1177 HeapFree(GetProcessHeap(),0,glyphs);
1181 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1185 for (i = 0; i < cGlyphs; i++)
1187 if (!pGlyphProp[i].sva.fClusterStart)
1190 for (j = 0; j < cChars; j++)
1192 if (pwLogClust[j] == i)
1195 while (!pGlyphProp[pwLogClust[k]].sva.fClusterStart && k >= 0 && k <cChars)
1197 if (pGlyphProp[pwLogClust[k]].sva.fClusterStart)
1198 pwLogClust[j] = pwLogClust[k];
1205 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
1207 if (changeCount == 0)
1212 int target_glyph = nextIndex - write_dir;
1214 int target_index = -1;
1215 int replacing_glyph = -1;
1217 int top_logclust = 0;
1219 if (changeCount > 0)
1222 target_glyph = nextIndex - changeCount;
1224 target_glyph = nextIndex + (changeCount + 1);
1227 seeking_glyph = target_glyph;
1228 for (i = 0; i < chars; i++)
1229 if (pwLogClust[i] > top_logclust)
1230 top_logclust = pwLogClust[i];
1234 for (i = 0; i < chars; i++)
1236 if (pwLogClust[i] == seeking_glyph)
1243 for (i = chars - 1; i >= 0; i--)
1245 if (pwLogClust[i] == seeking_glyph)
1251 if (target_index == -1)
1254 while (target_index == -1 && seeking_glyph <= top_logclust);
1256 if (target_index == -1)
1258 ERR("Unable to find target glyph\n");
1262 if (changeCount < 0)
1265 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1267 if (pwLogClust[i] == target_glyph)
1269 if(pwLogClust[i] == replacing_glyph)
1270 pwLogClust[i] = target_glyph;
1274 if (changed >= changeCount)
1276 replacing_glyph = pwLogClust[i];
1277 pwLogClust[i] = target_glyph;
1284 /* renumber trailing indexes*/
1285 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1287 if (pwLogClust[i] != target_glyph)
1288 pwLogClust[i] += changeCount;
1293 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1294 pwLogClust[i] += changeCount;
1299 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 )
1301 if (psc->GSUB_Table)
1303 LoadedFeature *feature;
1306 feature = load_GSUB_feature(hdc, psa, psc, feat);
1308 return GSUB_E_NOFEATURE;
1310 TRACE("applying feature %s: %i lookups\n",debugstr_an(feat,4),feature->lookup_count);
1311 for (lookup_index = 0; lookup_index < feature->lookup_count; lookup_index++)
1319 TRACE("applying lookup (%i/%i)\n",lookup_index,feature->lookup_count);
1320 while(i < *pcGlyphs && i >= 0)
1323 INT prevCount = *pcGlyphs;
1325 nextIndex = apply_GSUB_lookup(psc->GSUB_Table, feature->lookups[lookup_index], pwOutGlyphs, i, write_dir, pcGlyphs);
1326 if (*pcGlyphs != prevCount)
1328 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
1337 return GSUB_E_NOFEATURE;
1340 static inline BOOL get_GSUB_Indic2(SCRIPT_ANALYSIS *psa, ScriptCache *psc)
1346 hr = GSUB_GetFontScriptTags(psc, ShapingData[psa->eScript].newOtTag, 1, &tag, &count, NULL);
1348 return(SUCCEEDED(hr));
1351 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
1355 if ( i+ delta >= cchLen)
1363 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
1367 if (psa->fLinkBefore)
1372 if ( i+ delta >= cchLen)
1374 if (psa->fLinkAfter)
1382 if (context_type[i] == jtT)
1383 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
1385 return context_type[i];
1388 static inline BOOL right_join_causing(CHAR joining_type)
1390 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
1393 static inline BOOL left_join_causing(CHAR joining_type)
1395 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
1398 static inline BOOL word_break_causing(WCHAR chr)
1400 /* we are working within a string of characters already guareented to
1401 be within one script, Syriac, so we do not worry about any character
1402 other than the space character outside of that range */
1403 return (chr == 0 || chr == 0x20 );
1407 * ContextualShape_Arabic
1409 static void ContextualShape_Arabic(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 if (!psc->GSUB_Table)
1434 psc->GSUB_Table = load_gsub_table(hdc);
1436 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1437 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1439 for (i = 0; i < cChars; i++)
1440 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1442 for (i = 0; i < cChars; i++)
1444 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1445 context_shape[i] = Xr;
1446 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1447 context_shape[i] = Xl;
1448 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)))
1449 context_shape[i] = Xm;
1450 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1451 context_shape[i] = Xr;
1452 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1453 context_shape[i] = Xl;
1455 context_shape[i] = Xn;
1458 /* Contextual Shaping */
1460 while(i < *pcGlyphs)
1462 BOOL shaped = FALSE;
1464 if (psc->GSUB_Table)
1467 INT prevCount = *pcGlyphs;
1468 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1469 if (nextIndex > GSUB_E_NOGLYPH)
1472 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1474 shaped = (nextIndex > GSUB_E_NOGLYPH);
1479 if (context_shape[i] == Xn)
1481 WORD newGlyph = pwOutGlyphs[i];
1482 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1484 /* fall back to presentation form B */
1485 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1486 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1487 pwOutGlyphs[i] = newGlyph;
1494 HeapFree(GetProcessHeap(),0,context_shape);
1495 HeapFree(GetProcessHeap(),0,context_type);
1499 * ContextualShape_Syriac
1503 #define DALATH 0x715
1506 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1513 if (*pcGlyphs != cChars)
1515 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1519 if (!psa->fLogicalOrder && psa->fRTL)
1530 if (!psc->GSUB_Table)
1531 psc->GSUB_Table = load_gsub_table(hdc);
1533 if (!psc->GSUB_Table)
1536 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1537 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1539 for (i = 0; i < cChars; i++)
1540 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1542 for (i = 0; i < cChars; i++)
1544 if (pwcChars[i] == ALAPH)
1546 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1548 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1549 context_shape[i] = Afj;
1550 else if ( rchar != DALATH && rchar != RISH &&
1551 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1552 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1553 context_shape[i] = Afn;
1554 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1555 context_shape[i] = Afx;
1557 context_shape[i] = Xn;
1559 else if (context_type[i] == jtR &&
1560 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1561 context_shape[i] = Xr;
1562 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1563 context_shape[i] = Xl;
1564 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)))
1565 context_shape[i] = Xm;
1566 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1567 context_shape[i] = Xr;
1568 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1569 context_shape[i] = Xl;
1571 context_shape[i] = Xn;
1574 /* Contextual Shaping */
1576 while(i < *pcGlyphs)
1579 INT prevCount = *pcGlyphs;
1580 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1581 if (nextIndex > GSUB_E_NOGLYPH)
1583 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1590 HeapFree(GetProcessHeap(),0,context_shape);
1591 HeapFree(GetProcessHeap(),0,context_type);
1595 * ContextualShape_Phags_pa
1598 #define phags_pa_CANDRABINDU 0xA873
1599 #define phags_pa_START 0xA840
1600 #define phags_pa_END 0xA87F
1602 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1608 if (*pcGlyphs != cChars)
1610 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1614 if (!psa->fLogicalOrder && psa->fRTL)
1625 if (!psc->GSUB_Table)
1626 psc->GSUB_Table = load_gsub_table(hdc);
1628 if (!psc->GSUB_Table)
1631 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1633 for (i = 0; i < cChars; i++)
1635 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1637 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1638 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1639 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1640 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1642 if (jrchar && jlchar)
1643 context_shape[i] = Xm;
1645 context_shape[i] = Xr;
1647 context_shape[i] = Xl;
1649 context_shape[i] = Xn;
1652 context_shape[i] = -1;
1655 /* Contextual Shaping */
1657 while(i < *pcGlyphs)
1659 if (context_shape[i] >= 0)
1662 INT prevCount = *pcGlyphs;
1663 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1664 if (nextIndex > GSUB_E_NOGLYPH)
1666 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1676 HeapFree(GetProcessHeap(),0,context_shape);
1679 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1684 pwOutChars[cWalk] = replacements[0];
1688 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1691 for (j = *pcChars; j > cWalk; j--)
1692 pwOutChars[j] = pwOutChars[j-1];
1693 *pcChars= *pcChars+1;
1694 pwOutChars[cWalk] = replacements[i];
1699 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[], WORD* pwLogClust, INT cChars)
1704 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1706 for (i = 0; vowels[i].base != 0x0; i++)
1708 if (pwOutChars[cWalk] == vowels[i].base)
1711 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1712 if (vowels[i].parts[1]) { cWalk++; o++; }
1713 if (vowels[i].parts[2]) { cWalk++; o++; }
1714 UpdateClusters(cWalk, o, 1, cChars, pwLogClust);
1721 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[], WORD* pwLogClust)
1727 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1729 for (i = 0; consonants[i].output!= 0x0; i++)
1732 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1733 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1736 if (consonants[i].parts[j]==0x0) /* matched all */
1740 pwOutChars[cWalk] = consonants[i].output;
1741 for(k = cWalk+1; k < *pcChars - j; k++)
1742 pwOutChars[k] = pwOutChars[k+j];
1743 *pcChars = *pcChars - j;
1744 for (k = j ; k > 0; k--)
1745 pwLogClust[cWalk + k + offset] = pwLogClust[cWalk + offset];
1747 for (k = cWalk + j + offset; k < *pcChars + offset; k++)
1756 static void Reorder_Ra_follows_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1761 WORD Ra = pwChar[s->start];
1762 WORD H = pwChar[s->start+1];
1764 TRACE("Doing reorder of Ra to %i\n",s->base);
1765 for (j = s->start; j < s->base-1; j++)
1766 pwChar[j] = pwChar[j+2];
1767 pwChar[s->base-1] = Ra;
1768 pwChar[s->base] = H;
1770 s->ralf = s->base-1;
1775 static void Reorder_Ra_follows_matra(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1780 int stop = (s->blwf >=0)? s->blwf+1 : s->base;
1781 WORD Ra = pwChar[s->start];
1782 WORD H = pwChar[s->start+1];
1783 for (loc = s->end; loc > stop; loc--)
1784 if (lexical(pwChar[loc]) == lex_Matra_post || lexical(pwChar[loc]) == lex_Matra_below)
1787 TRACE("Doing reorder of Ra to %i\n",loc);
1788 for (j = s->start; j < loc-1; j++)
1789 pwChar[j] = pwChar[j+2];
1795 if (s->blwf >= 0) s->blwf -= 2;
1796 if (s->pref >= 0) s->pref -= 2;
1800 static void Reorder_Ra_follows_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1805 WORD Ra = pwChar[s->start];
1806 WORD H = pwChar[s->start+1];
1808 TRACE("Doing reorder of Ra to %i\n",s->end-1);
1809 for (j = s->start; j < s->end-1; j++)
1810 pwChar[j] = pwChar[j+2];
1811 pwChar[s->end-1] = Ra;
1816 if (s->blwf >= 0) s->blwf -= 2;
1817 if (s->pref >= 0) s->pref -= 2;
1821 static void Reorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1825 /* reorder Matras */
1826 if (s->end > s->base)
1828 for (i = 1; i <= s->end-s->base; i++)
1830 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1833 WCHAR c = pwChar[s->base+i];
1834 TRACE("Doing reorder of %x %x\n",c,pwChar[s->base]);
1835 for (j = s->base+i; j > s->base; j--)
1836 pwChar[j] = pwChar[j-1];
1837 pwChar[s->base] = c;
1839 if (s->ralf >= s->base) s->ralf++;
1840 if (s->blwf >= s->base) s->blwf++;
1841 if (s->pref >= s->base) s->pref++;
1848 static void Reorder_Matra_precede_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1852 /* reorder Matras */
1853 if (s->end > s->base)
1855 for (i = 1; i <= s->end-s->base; i++)
1857 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1860 WCHAR c = pwChar[s->base+i];
1861 TRACE("Doing reorder of %x to %i\n",c,s->start);
1862 for (j = s->base+i; j > s->start; j--)
1863 pwChar[j] = pwChar[j-1];
1864 pwChar[s->start] = c;
1866 if (s->ralf >= 0) s->ralf++;
1867 if (s->blwf >= 0) s->blwf++;
1868 if (s->pref >= 0) s->pref++;
1875 static void SecondReorder_Blwf_follows_matra(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1877 if (s->blwf >= 0 && g->blwf > g->base)
1881 for (loc = s->end; loc > s->blwf; loc--)
1882 if (lexical(pwChar[loc]) == lex_Matra_below || lexical(pwChar[loc]) == lex_Matra_above || lexical(pwChar[loc]) == lex_Matra_post)
1885 g_offset = (loc - s->blwf) - 1;
1889 WORD blwf = glyphs[g->blwf];
1890 TRACE("Doing reorder of Below-base to %i (glyph offset %i)\n",loc,g_offset);
1891 /* do not care about the pwChar array anymore, just the glyphs */
1892 for (j = 0; j < g_offset; j++)
1893 glyphs[g->blwf + j] = glyphs[g->blwf + j + 1];
1894 glyphs[g->blwf + g_offset] = blwf;
1899 static void SecondReorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1903 /* reorder previously moved Matras to correct position*/
1904 for (i = s->start; i < s->base; i++)
1906 if (lexical(pwChar[i]) == lex_Matra_pre)
1909 int g_start = g->start + i - s->start;
1910 if (g_start < g->base -1 )
1912 WCHAR og = glyphs[g_start];
1913 TRACE("Doing reorder of matra from %i to %i\n",g_start,g->base);
1914 for (j = g_start; j < g->base-1; j++)
1915 glyphs[j] = glyphs[j+1];
1916 glyphs[g->base-1] = og;
1922 static void SecondReorder_Pref_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1924 if (s->pref >= 0 && g->pref > g->base)
1927 WCHAR og = glyphs[g->pref];
1928 TRACE("Doing reorder of pref from %i to %i\n",g->pref,g->base);
1929 for (j = g->pref; j > g->base; j--)
1930 glyphs[j] = glyphs[j-1];
1931 glyphs[g->base] = og;
1935 static void Reorder_Like_Sinhala(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1937 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1938 if (s->start == s->base && s->base == s->end) return;
1939 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1941 Reorder_Ra_follows_base(pwChar, s, lexical);
1942 Reorder_Matra_precede_base(pwChar, s, lexical);
1945 static void Reorder_Like_Devanagari(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1947 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1948 if (s->start == s->base && s->base == s->end) return;
1949 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1951 Reorder_Ra_follows_matra(pwChar, s, lexical);
1952 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1955 static void Reorder_Like_Bengali(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1957 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1958 if (s->start == s->base && s->base == s->end) return;
1959 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1961 Reorder_Ra_follows_base(pwChar, s, lexical);
1962 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1965 static void Reorder_Like_Kannada(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1967 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1968 if (s->start == s->base && s->base == s->end) return;
1969 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1971 Reorder_Ra_follows_syllable(pwChar, s, lexical);
1972 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1975 static void SecondReorder_Like_Telugu(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
1977 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1978 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
1979 if (s->start == s->base && s->base == s->end) return;
1980 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1982 SecondReorder_Blwf_follows_matra(pwChar, s, pwGlyphs, g, lexical);
1985 static void SecondReorder_Like_Tamil(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
1987 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1988 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
1989 if (s->start == s->base && s->base == s->end) return;
1990 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1992 SecondReorder_Matra_precede_base(pwChar, s, pwGlyphs, g, lexical);
1993 SecondReorder_Pref_precede_base(pwChar, s, pwGlyphs, g, lexical);
1997 static inline void shift_syllable_glyph_indexs(IndicSyllable *glyph_index, INT index, INT shift)
2002 if (glyph_index->start > index)
2003 glyph_index->start += shift;
2004 if (glyph_index->base > index)
2005 glyph_index->base+= shift;
2006 if (glyph_index->end > index)
2007 glyph_index->end+= shift;
2008 if (glyph_index->ralf > index)
2009 glyph_index->ralf+= shift;
2010 if (glyph_index->blwf > index)
2011 glyph_index->blwf+= shift;
2012 if (glyph_index->pref > index)
2013 glyph_index->pref+= shift;
2016 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 )
2018 int index = glyph_index->start;
2023 while(index <= glyph_index->end)
2026 INT prevCount = *pcGlyphs;
2027 nextIndex = GSUB_apply_feature_all_lookups(psc->GSUB_Table, feature, pwOutGlyphs, index, 1, pcGlyphs);
2028 if (nextIndex > GSUB_E_NOGLYPH)
2030 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2031 shift_syllable_glyph_indexs(glyph_index,index,*pcGlyphs - prevCount);
2039 static inline INT find_consonant_halant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2042 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)))))
2044 if (index + i <= end-1)
2050 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)
2052 INT index, nextIndex;
2055 count = syllable->base - syllable->start;
2058 index = find_consonant_halant(&pwChars[syllable->start], 0, count, lexical);
2059 while (index >= 0 && index + g_offset < (glyph_index->base - glyph_index->start))
2061 INT prevCount = *pcGlyphs;
2062 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->start+g_offset, 1, pcGlyphs, feature);
2063 if (nextIndex > GSUB_E_NOGLYPH)
2065 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2066 shift_syllable_glyph_indexs(glyph_index, index + glyph_index->start + g_offset, (*pcGlyphs - prevCount));
2067 g_offset += (*pcGlyphs - prevCount);
2071 index = find_consonant_halant(&pwChars[syllable->start], index, count, lexical);
2075 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)
2078 INT prevCount = *pcGlyphs;
2080 if (syllable->ralf >= 0)
2082 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, glyph_index->ralf, 1, pcGlyphs, "rphf");
2083 if (nextIndex > GSUB_E_NOGLYPH)
2085 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2086 shift_syllable_glyph_indexs(glyph_index,glyph_index->ralf,*pcGlyphs - prevCount);
2091 static inline INT find_halant_consonant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2094 while (index + i < end-1 && !(lexical(pwChars[index+i]) == lex_Halant &&
2095 ((index + i < end-2 && lexical(pwChars[index+i]) == lex_Nukta && is_consonant(lexical(pwChars[index+i+1]))) ||
2096 is_consonant(lexical(pwChars[index+i+1])))))
2098 if (index + i <= end-1)
2104 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)
2106 INT index, nextIndex;
2107 INT count, g_offset=0;
2108 INT ralf = syllable->ralf;
2110 count = syllable->end - syllable->base;
2112 index = find_halant_consonant(&pwChars[syllable->base], 0, count, lexical);
2116 INT prevCount = *pcGlyphs;
2117 if (ralf >=0 && ralf < index)
2125 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
2126 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
2127 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2130 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->base+g_offset, 1, pcGlyphs, feat);
2131 if (nextIndex > GSUB_E_NOGLYPH)
2133 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2134 shift_syllable_glyph_indexs(glyph_index,index+glyph_index->start+g_offset, (*pcGlyphs - prevCount));
2135 g_offset += (*pcGlyphs - prevCount);
2139 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
2140 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
2141 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2145 index = find_halant_consonant(&pwChars[syllable->base], index, count, lexical);
2149 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)
2152 int overall_shift = 0;
2153 LoadedFeature *locl = (modern)?load_GSUB_feature(hdc, psa, psc, "locl"):NULL;
2154 LoadedFeature *nukt = load_GSUB_feature(hdc, psa, psc, "nukt");
2155 LoadedFeature *akhn = load_GSUB_feature(hdc, psa, psc, "akhn");
2156 LoadedFeature *rkrf = (modern)?load_GSUB_feature(hdc, psa, psc, "rkrf"):NULL;
2157 LoadedFeature *pstf = load_GSUB_feature(hdc, psa, psc, "pstf");
2158 LoadedFeature *vatu = (!rkrf)?load_GSUB_feature(hdc, psa, psc, "vatu"):NULL;
2159 LoadedFeature *cjct = (modern)?load_GSUB_feature(hdc, psa, psc, "cjct"):NULL;
2160 BOOL rphf = (load_GSUB_feature(hdc, psa, psc, "rphf") != NULL);
2161 BOOL pref = (load_GSUB_feature(hdc, psa, psc, "pref") != NULL);
2162 BOOL blwf = (load_GSUB_feature(hdc, psa, psc, "blwf") != NULL);
2163 BOOL half = (load_GSUB_feature(hdc, psa, psc, "half") != NULL);
2164 IndicSyllable glyph_indexs;
2166 for (c = 0; c < syllable_count; c++)
2169 memcpy(&glyph_indexs, &syllables[c], sizeof(IndicSyllable));
2170 shift_syllable_glyph_indexs(&glyph_indexs, -1, overall_shift);
2171 old_end = glyph_indexs.end;
2175 TRACE("applying feature locl\n");
2176 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, locl);
2180 TRACE("applying feature nukt\n");
2181 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, nukt);
2185 TRACE("applying feature akhn\n");
2186 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, akhn);
2190 Apply_Indic_Rphf(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs);
2193 TRACE("applying feature rkrf\n");
2194 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, rkrf);
2197 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "pref");
2201 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "blwf");
2203 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "blwf");
2207 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "half");
2210 TRACE("applying feature pstf\n");
2211 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, pstf);
2215 TRACE("applying feature vatu\n");
2216 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, vatu);
2220 TRACE("applying feature cjct\n");
2221 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, cjct);
2225 second_reorder(pwChars, &syllables[c], pwOutGlyphs, &glyph_indexs, lexical);
2227 overall_shift += glyph_indexs.end - old_end;
2231 static inline int unicode_lex(WCHAR c)
2235 if (!c) return lex_Generic;
2236 if (c == 0x200D) return lex_ZWJ;
2237 if (c == 0x200C) return lex_ZWNJ;
2238 if (c == 0x00A0) return lex_NBSP;
2240 type = get_table_entry( indic_syllabic_table, c );
2242 if ((type & 0x00ff) != 0x0007) type = type & 0x00ff;
2246 case 0x0d07: /* Unknown */
2247 case 0x0e07: /* Unknwon */
2248 default: return lex_Generic;
2254 case 0x0014: return lex_Modifier;
2262 case 0x0010: return lex_Consonant;
2263 case 0x0004: return lex_Nukta;
2264 case 0x0005: return lex_Halant;
2266 case 0x0008: return lex_Vowel;
2268 case 0x0107: return lex_Matra_post;
2270 case 0x0307: return lex_Matra_pre;
2276 case 0x0407: return lex_Composed_Vowel;
2277 case 0x0507: return lex_Matra_above;
2278 case 0x0607: return lex_Matra_below;
2279 case 0x000c: return lex_Ra;
2283 static int sinhala_lex(WCHAR c)
2290 case 0x0DDE: return lex_Matra_post;
2292 return unicode_lex(c);
2296 static const VowelComponents Sinhala_vowels[] = {
2297 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2298 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2299 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2300 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2301 {0x0000, {0x0000,0x0000,0x0}}};
2303 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2305 int cCount = cChars;
2308 IndicSyllable *syllables = NULL;
2309 int syllable_count = 0;
2311 if (*pcGlyphs != cChars)
2313 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2317 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
2319 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2321 /* Step 1: Decompose multi part vowels */
2322 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels, pwLogClust, cChars);
2324 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2326 /* Step 2: Reorder within Syllables */
2327 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, sinhala_lex, Reorder_Like_Sinhala, TRUE);
2328 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2330 /* Step 3: Strip dangling joiners */
2331 for (i = 0; i < cCount; i++)
2333 if ((input[i] == 0x200D || input[i] == 0x200C) &&
2334 (i == 0 || input[i-1] == 0x0020 || i == cCount-1 || input[i+1] == 0x0020))
2338 /* Step 4: Base Form application to syllables */
2339 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2341 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, sinhala_lex, NULL, TRUE);
2343 HeapFree(GetProcessHeap(),0,input);
2344 HeapFree(GetProcessHeap(),0,syllables);
2347 static int devanagari_lex(WCHAR c)
2351 case 0x0930: return lex_Ra;
2353 return unicode_lex(c);
2357 static const ConsonantComponents Devanagari_consonants[] ={
2358 {{0x0928, 0x093C, 0x00000}, 0x0929},
2359 {{0x0930, 0x093C, 0x00000}, 0x0931},
2360 {{0x0933, 0x093C, 0x00000}, 0x0934},
2361 {{0x0915, 0x093C, 0x00000}, 0x0958},
2362 {{0x0916, 0x093C, 0x00000}, 0x0959},
2363 {{0x0917, 0x093C, 0x00000}, 0x095A},
2364 {{0x091C, 0x093C, 0x00000}, 0x095B},
2365 {{0x0921, 0x093C, 0x00000}, 0x095C},
2366 {{0x0922, 0x093C, 0x00000}, 0x095D},
2367 {{0x092B, 0x093C, 0x00000}, 0x095E},
2368 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2370 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2372 int cCount = cChars;
2374 IndicSyllable *syllables = NULL;
2375 int syllable_count = 0;
2376 BOOL modern = get_GSUB_Indic2(psa, psc);
2378 if (*pcGlyphs != cChars)
2380 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2384 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2385 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2387 /* Step 1: Compose Consonant and Nukta */
2388 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants, pwLogClust);
2389 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2391 /* Step 2: Reorder within Syllables */
2392 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, devanagari_lex, Reorder_Like_Devanagari, modern);
2393 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2394 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2397 /* Step 3: Base Form application to syllables */
2398 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, devanagari_lex, NULL, modern);
2400 HeapFree(GetProcessHeap(),0,input);
2401 HeapFree(GetProcessHeap(),0,syllables);
2404 static int bengali_lex(WCHAR c)
2408 case 0x09B0: return lex_Ra;
2410 return unicode_lex(c);
2414 static const VowelComponents Bengali_vowels[] = {
2415 {0x09CB, {0x09C7,0x09BE,0x0000}},
2416 {0x09CC, {0x09C7,0x09D7,0x0000}},
2417 {0x0000, {0x0000,0x0000,0x0000}}};
2419 static const ConsonantComponents Bengali_consonants[] = {
2420 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2421 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2422 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2423 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2424 {{0x0000,0x0000,0x0000}, 0x0000}};
2426 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2428 int cCount = cChars;
2430 IndicSyllable *syllables = NULL;
2431 int syllable_count = 0;
2432 BOOL modern = get_GSUB_Indic2(psa, psc);
2434 if (*pcGlyphs != cChars)
2436 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2440 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2441 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2443 /* Step 1: Decompose Vowels and Compose Consonents */
2444 DecomposeVowels(hdc, input, &cCount, Bengali_vowels, pwLogClust, cChars);
2445 ComposeConsonants(hdc, input, &cCount, Bengali_consonants, pwLogClust);
2446 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2448 /* Step 2: Reorder within Syllables */
2449 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, bengali_lex, Reorder_Like_Bengali, modern);
2450 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2451 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2454 /* Step 3: Initial form is only applied to the beginning of words */
2455 for (cCount = cCount - 1 ; cCount >= 0; cCount --)
2457 if (cCount == 0 || input[cCount] == 0x0020) /* space */
2461 if (index > 0) index++;
2463 apply_GSUB_feature_to_glyph(hdc, psa, psc, &pwOutGlyphs[index], 0, 1, &gCount, "init");
2467 /* Step 4: Base Form application to syllables */
2468 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, bengali_lex, NULL, modern);
2470 HeapFree(GetProcessHeap(),0,input);
2471 HeapFree(GetProcessHeap(),0,syllables);
2474 static int gurmukhi_lex(WCHAR c)
2477 return lex_Modifier;
2479 return unicode_lex(c);
2482 static const ConsonantComponents Gurmukhi_consonants[] = {
2483 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2484 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2485 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2486 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2487 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2488 {{0x0000,0x0000,0x0000}, 0x0000}};
2490 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2492 int cCount = cChars;
2494 IndicSyllable *syllables = NULL;
2495 int syllable_count = 0;
2496 BOOL modern = get_GSUB_Indic2(psa, psc);
2498 if (*pcGlyphs != cChars)
2500 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2504 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2505 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2507 /* Step 1: Compose Consonents */
2508 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants, pwLogClust);
2509 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2511 /* Step 2: Reorder within Syllables */
2512 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gurmukhi_lex, Reorder_Like_Bengali, modern);
2513 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2514 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2517 /* Step 3: Base Form application to syllables */
2518 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gurmukhi_lex, NULL, modern);
2520 HeapFree(GetProcessHeap(),0,input);
2521 HeapFree(GetProcessHeap(),0,syllables);
2524 static int gujarati_lex(WCHAR c)
2528 case 0x0AB0: return lex_Ra;
2530 return unicode_lex(c);
2534 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2536 int cCount = cChars;
2538 IndicSyllable *syllables = NULL;
2539 int syllable_count = 0;
2540 BOOL modern = get_GSUB_Indic2(psa, psc);
2542 if (*pcGlyphs != cChars)
2544 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2548 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2549 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2551 /* Step 1: Reorder within Syllables */
2552 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gujarati_lex, Reorder_Like_Devanagari, modern);
2553 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2554 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2557 /* Step 2: Base Form application to syllables */
2558 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gujarati_lex, NULL, modern);
2560 HeapFree(GetProcessHeap(),0,input);
2561 HeapFree(GetProcessHeap(),0,syllables);
2564 static int oriya_lex(WCHAR c)
2568 case 0x0B30: return lex_Ra;
2570 return unicode_lex(c);
2574 static const VowelComponents Oriya_vowels[] = {
2575 {0x0B48, {0x0B47,0x0B56,0x0000}},
2576 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2577 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2578 {0x0000, {0x0000,0x0000,0x0000}}};
2580 static const ConsonantComponents Oriya_consonants[] = {
2581 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2582 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2583 {{0x0000,0x0000,0x0000}, 0x0000}};
2585 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2587 int cCount = cChars;
2589 IndicSyllable *syllables = NULL;
2590 int syllable_count = 0;
2591 BOOL modern = get_GSUB_Indic2(psa, psc);
2593 if (*pcGlyphs != cChars)
2595 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2599 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2600 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2602 /* Step 1: Decompose Vowels and Compose Consonents */
2603 DecomposeVowels(hdc, input, &cCount, Oriya_vowels, pwLogClust, cChars);
2604 ComposeConsonants(hdc, input, &cCount, Oriya_consonants, pwLogClust);
2605 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2607 /* Step 2: Reorder within Syllables */
2608 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, oriya_lex, Reorder_Like_Bengali, modern);
2609 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2610 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2613 /* Step 3: Base Form application to syllables */
2614 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, oriya_lex, NULL, modern);
2616 HeapFree(GetProcessHeap(),0,input);
2617 HeapFree(GetProcessHeap(),0,syllables);
2620 static int tamil_lex(WCHAR c)
2622 return unicode_lex(c);
2625 static const VowelComponents Tamil_vowels[] = {
2626 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2627 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2628 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2629 {0x0000, {0x0000,0x0000,0x0000}}};
2631 static const ConsonantComponents Tamil_consonants[] = {
2632 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2633 {{0x0000,0x0000,0x0000}, 0x0000}};
2635 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2637 int cCount = cChars;
2639 IndicSyllable *syllables = NULL;
2640 int syllable_count = 0;
2641 BOOL modern = get_GSUB_Indic2(psa, psc);
2643 if (*pcGlyphs != cChars)
2645 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2649 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2650 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2652 /* Step 1: Decompose Vowels and Compose Consonents */
2653 DecomposeVowels(hdc, input, &cCount, Tamil_vowels, pwLogClust, cChars);
2654 ComposeConsonants(hdc, input, &cCount, Tamil_consonants, pwLogClust);
2655 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2657 /* Step 2: Reorder within Syllables */
2658 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, tamil_lex, Reorder_Like_Bengali, modern);
2659 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2660 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2663 /* Step 3: Base Form application to syllables */
2664 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, tamil_lex, SecondReorder_Like_Tamil, modern);
2666 HeapFree(GetProcessHeap(),0,input);
2667 HeapFree(GetProcessHeap(),0,syllables);
2670 static int telugu_lex(WCHAR c)
2675 case 0x0C44: return lex_Modifier;
2677 return unicode_lex(c);
2681 static const VowelComponents Telugu_vowels[] = {
2682 {0x0C48, {0x0C46,0x0C56,0x0000}},
2683 {0x0000, {0x0000,0x0000,0x0000}}};
2685 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2687 int cCount = cChars;
2689 IndicSyllable *syllables = NULL;
2690 int syllable_count = 0;
2691 BOOL modern = get_GSUB_Indic2(psa, psc);
2693 if (*pcGlyphs != cChars)
2695 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2699 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2700 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2702 /* Step 1: Decompose Vowels */
2703 DecomposeVowels(hdc, input, &cCount, Telugu_vowels, pwLogClust, cChars);
2704 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2706 /* Step 2: Reorder within Syllables */
2707 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, telugu_lex, Reorder_Like_Bengali, modern);
2708 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2709 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2712 /* Step 3: Base Form application to syllables */
2713 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, telugu_lex, SecondReorder_Like_Telugu, modern);
2715 HeapFree(GetProcessHeap(),0,input);
2716 HeapFree(GetProcessHeap(),0,syllables);
2719 static int kannada_lex(WCHAR c)
2723 case 0x0CB0: return lex_Ra;
2725 return unicode_lex(c);
2729 static const VowelComponents Kannada_vowels[] = {
2730 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2731 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2732 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2733 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2734 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2735 {0x0000, {0x0000,0x0000,0x0000}}};
2737 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2739 int cCount = cChars;
2741 IndicSyllable *syllables = NULL;
2742 int syllable_count = 0;
2743 BOOL modern = get_GSUB_Indic2(psa, psc);
2745 if (*pcGlyphs != cChars)
2747 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2751 input = HeapAlloc(GetProcessHeap(), 0, (cChars*3) * sizeof(WCHAR));
2752 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2754 /* Step 1: Decompose Vowels */
2755 DecomposeVowels(hdc, input, &cCount, Kannada_vowels, pwLogClust, cChars);
2756 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2758 /* Step 2: Reorder within Syllables */
2759 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, kannada_lex, Reorder_Like_Kannada, modern);
2760 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2761 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2764 /* Step 3: Base Form application to syllables */
2765 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, kannada_lex, SecondReorder_Like_Telugu, modern);
2767 HeapFree(GetProcessHeap(),0,input);
2768 HeapFree(GetProcessHeap(),0,syllables);
2771 static int malayalam_lex(WCHAR c)
2773 return unicode_lex(c);
2776 static const VowelComponents Malayalam_vowels[] = {
2777 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2778 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2779 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2780 {0x0000, {0x0000,0x0000,0x0000}}};
2782 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2784 int cCount = cChars;
2786 IndicSyllable *syllables = NULL;
2787 int syllable_count = 0;
2788 BOOL modern = get_GSUB_Indic2(psa, psc);
2790 if (*pcGlyphs != cChars)
2792 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2796 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2797 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2799 /* Step 1: Decompose Vowels */
2800 DecomposeVowels(hdc, input, &cCount, Malayalam_vowels, pwLogClust, cChars);
2801 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2803 /* Step 2: Reorder within Syllables */
2804 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, malayalam_lex, Reorder_Like_Devanagari, modern);
2805 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2806 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2809 /* Step 3: Base Form application to syllables */
2810 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, malayalam_lex, SecondReorder_Like_Tamil, modern);
2812 HeapFree(GetProcessHeap(),0,input);
2813 HeapFree(GetProcessHeap(),0,syllables);
2816 static int khmer_lex(WCHAR c)
2818 return unicode_lex(c);
2821 static void ContextualShape_Khmer(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2823 int cCount = cChars;
2825 IndicSyllable *syllables = NULL;
2826 int syllable_count = 0;
2828 if (*pcGlyphs != cChars)
2830 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2834 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2835 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2837 /* Step 1: Reorder within Syllables */
2838 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, khmer_lex, Reorder_Like_Devanagari, FALSE);
2839 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2840 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2843 /* Step 2: Base Form application to syllables */
2844 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, khmer_lex, NULL, FALSE);
2846 HeapFree(GetProcessHeap(),0,input);
2847 HeapFree(GetProcessHeap(),0,syllables);
2850 static inline BOOL mongolian_wordbreak(WCHAR chr)
2852 return ((chr == 0x0020) || (chr == 0x200C) || (chr == 0x202F) || (chr == 0x180E) || (chr == 0x1800) || (chr == 0x1802) || (chr == 0x1803) || (chr == 0x1805) || (chr == 0x1808) || (chr == 0x1809) || (chr == 0x1807));
2855 static void ContextualShape_Mongolian(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2861 if (*pcGlyphs != cChars)
2863 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2867 if (!psa->fLogicalOrder && psa->fRTL)
2872 if (!psc->GSUB_Table)
2873 psc->GSUB_Table = load_gsub_table(hdc);
2875 if (!psc->GSUB_Table)
2878 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
2880 for (i = 0; i < cChars; i++)
2882 if (i == 0 || mongolian_wordbreak(pwcChars[i-1]))
2884 if ((i == cChars-1) || mongolian_wordbreak(pwcChars[i+1]))
2885 context_shape[i] = Xn;
2887 context_shape[i] = Xl;
2891 if ((i == cChars-1) || mongolian_wordbreak(pwcChars[i+1]))
2892 context_shape[i] = Xr;
2894 context_shape[i] = Xm;
2898 /* Contextual Shaping */
2900 while(i < *pcGlyphs)
2903 INT prevCount = *pcGlyphs;
2904 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
2905 if (nextIndex > GSUB_E_NOGLYPH)
2907 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
2914 HeapFree(GetProcessHeap(),0,context_shape);
2917 static void ShapeCharGlyphProp_Default( HDC hdc, ScriptCache* psc, SCRIPT_ANALYSIS* psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD* pwLogClust, SCRIPT_CHARPROP* pCharProp, SCRIPT_GLYPHPROP* pGlyphProp)
2921 for (i = 0; i < cGlyphs; i++)
2926 for (k = 0; k < cChars; k++)
2928 if (pwLogClust[k] == i)
2930 char_index[char_count] = k;
2935 if (char_count == 0)
2938 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2940 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2941 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2944 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2947 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
2948 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2951 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 )
2954 int initGlyph, finaGlyph;
2958 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2959 memset(spaces,0,cGlyphs);
2961 if (!psa->fLogicalOrder && psa->fRTL)
2963 initGlyph = cGlyphs-1;
2971 finaGlyph = cGlyphs-1;
2976 for (i = 0; i < cGlyphs; i++)
2978 for (k = 0; k < cChars; k++)
2979 if (pwLogClust[k] == i)
2981 if (pwcChars[k] == 0x0020)
2986 for (i = 0; i < cGlyphs; i++)
2990 BOOL isInit, isFinal;
2992 for (k = 0; k < cChars; k++)
2994 if (pwLogClust[k] == i)
2996 char_index[char_count] = k;
3001 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
3002 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
3004 if (char_count == 0)
3007 if (char_count == 1)
3009 if (pwcChars[char_index[0]] == 0x0020) /* space */
3011 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
3012 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3014 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
3015 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
3016 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
3018 if (!isInit && !isFinal)
3019 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
3021 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
3023 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3027 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
3028 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
3029 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
3030 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
3031 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
3032 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
3033 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
3034 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
3036 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3038 else if (!isInit && !isFinal)
3039 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3041 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3043 else if (char_count == 2)
3045 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
3046 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
3048 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3050 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3052 else if (!isInit && !isFinal)
3053 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3055 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3058 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3059 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3060 HeapFree(GetProcessHeap(),0,spaces);
3063 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 )
3070 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
3071 memset(spaces,0,cGlyphs);
3073 if (!psa->fLogicalOrder && psa->fRTL)
3080 finaGlyph = cGlyphs-1;
3084 for (i = 0; i < cGlyphs; i++)
3086 for (k = 0; k < cChars; k++)
3087 if (pwLogClust[k] == i)
3089 if (pwcChars[k] == 0x0020)
3094 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3096 for (i = 0; i < cGlyphs; i++)
3101 for (k = 0; k < cChars; k++)
3103 if (pwLogClust[k] == i)
3105 char_index[char_count] = k;
3110 if (char_count == 0)
3113 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3115 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3116 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3118 else if (i == finaGlyph)
3119 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3121 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3123 /* handle Thai SARA AM (U+0E33) differently than GDEF */
3124 if (char_count == 1 && pwcChars[char_index[0]] == 0x0e33)
3125 pGlyphProp[i].sva.fClusterStart = 0;
3128 HeapFree(GetProcessHeap(),0,spaces);
3129 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3131 /* Do not allow justification between marks and their base */
3132 for (i = 0; i < cGlyphs; i++)
3134 if (!pGlyphProp[i].sva.fClusterStart)
3135 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3139 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)
3143 for (i = 0; i < cGlyphs; i++)
3148 for (k = 0; k < cChars; k++)
3150 if (pwLogClust[k] == i)
3152 char_index[char_count] = k;
3157 if (char_count == 0)
3160 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3162 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3163 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3166 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3168 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3169 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3172 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)
3176 for (i = 0; i < cGlyphs; i++)
3181 for (k = 0; k < cChars; k++)
3183 if (pwLogClust[k] == i)
3185 char_index[char_count] = k;
3190 if (char_count == 0)
3193 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3195 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3196 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3199 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3201 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3202 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3204 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3205 for (i = 0; i < cGlyphs; i++)
3207 if (!pGlyphProp[i].sva.fClusterStart)
3209 pGlyphProp[i].sva.fDiacritic = 0;
3210 pGlyphProp[i].sva.fZeroWidth = 0;
3215 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)
3219 OpenType_GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, cChars, pGlyphProp);
3220 for (i = 0; i < cGlyphs; i++)
3225 for (k = 0; k < cChars; k++)
3227 if (pwLogClust[k] == i)
3229 char_index[char_count] = k;
3236 /* Most indic scripts do not set fDiacritic or fZeroWidth */
3237 pGlyphProp[i].sva.fDiacritic = FALSE;
3238 pGlyphProp[i].sva.fZeroWidth = FALSE;
3241 if (char_count == 0)
3244 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3246 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3247 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3250 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3252 pGlyphProp[i].sva.fClusterStart = 0;
3253 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
3254 switch (lexical(pwcChars[char_index[k]]))
3257 case lex_Matra_post:
3258 case lex_Matra_above:
3259 case lex_Matra_below:
3265 /* check for dangling joiners */
3266 if (pwcChars[char_index[k]-1] == 0x0020 || pwcChars[char_index[k]+1] == 0x0020)
3267 pGlyphProp[i].sva.fClusterStart = 1;
3272 pGlyphProp[i].sva.fClusterStart = 1;
3279 IndicSyllable *syllables = NULL;
3280 int syllable_count = 0;
3281 BOOL modern = get_GSUB_Indic2(psa, psc);
3283 Indic_ParseSyllables( hdc, psa, psc, pwcChars, cChars, &syllables, &syllable_count, lexical, modern);
3285 for (i = 0; i < syllable_count; i++)
3288 WORD g = pwLogClust[syllables[i].start];
3289 for (j = syllables[i].start+1; j <= syllables[i].end; j++)
3291 if (pwLogClust[j] != g)
3293 pGlyphProp[pwLogClust[j]].sva.fClusterStart = 0;
3299 HeapFree(GetProcessHeap(), 0, syllables);
3302 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3305 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 )
3307 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, sinhala_lex, FALSE, FALSE);
3310 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 )
3312 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex, TRUE, TRUE);
3315 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 )
3317 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex, TRUE, TRUE);
3320 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 )
3322 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex, TRUE, TRUE);
3325 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 )
3327 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex, TRUE, TRUE);
3330 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 )
3332 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex, TRUE, TRUE);
3335 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 )
3337 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, tamil_lex, TRUE, TRUE);
3340 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 )
3342 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, telugu_lex, TRUE, TRUE);
3345 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 )
3347 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, kannada_lex, TRUE, TRUE);
3350 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 )
3352 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, malayalam_lex, TRUE, TRUE);
3355 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 )
3357 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, khmer_lex, TRUE, TRUE);
3360 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)
3362 if (ShapingData[psa->eScript].charGlyphPropProc)
3363 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3365 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3368 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
3370 if (!psc->GSUB_Table)
3371 psc->GSUB_Table = load_gsub_table(hdc);
3373 if (ShapingData[psa->eScript].contextProc)
3374 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
3377 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)
3382 if (!rpRangeProperties)
3385 if (!psc->GSUB_Table)
3386 psc->GSUB_Table = load_gsub_table(hdc);
3388 if (!psc->GSUB_Table)
3391 if (!psa->fLogicalOrder && psa->fRTL)
3396 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3398 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3399 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
3403 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
3405 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3406 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
3408 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
3411 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
3413 LoadedFeature *feature;
3416 if (!ShapingData[psa->eScript].requiredFeatures)
3419 if (!psc->GSUB_Table)
3420 psc->GSUB_Table = load_gsub_table(hdc);
3422 /* we need to have at least one of the required features */
3424 while (ShapingData[psa->eScript].requiredFeatures[i])
3426 feature = load_GSUB_feature(hdc, psa, psc, ShapingData[psa->eScript].requiredFeatures[i]);
3432 return USP_E_SCRIPT_NOT_IN_FONT;
3435 static void GSUB_initialize_script_cache(ScriptCache *psc)
3439 if (!psc->script_count)
3441 const GSUB_ScriptList *script;
3442 const GSUB_Header* header = (const GSUB_Header*)psc->GSUB_Table;
3443 script = (const GSUB_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
3444 psc->script_count = GET_BE_WORD(script->ScriptCount);
3445 TRACE("initializing %i scripts in this font\n",psc->script_count);
3446 psc->scripts = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(LoadedScript) * psc->script_count);
3447 for (i = 0; i < psc->script_count; i++)
3449 int offset = GET_BE_WORD(script->ScriptRecord[i].Script);
3450 psc->scripts[i].tag = MS_MAKE_TAG(script->ScriptRecord[i].ScriptTag[0], script->ScriptRecord[i].ScriptTag[1], script->ScriptRecord[i].ScriptTag[2], script->ScriptRecord[i].ScriptTag[3]);
3451 psc->scripts[i].table = ((const BYTE*)script + offset);
3456 static HRESULT GSUB_GetFontScriptTags(ScriptCache *psc, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pScriptTags, int *pcTags, LPCVOID* script_table)
3461 GSUB_initialize_script_cache(psc);
3462 *pcTags = psc->script_count;
3464 if (!searchingFor && cMaxTags < *pcTags)
3466 else if (searchingFor)
3467 rc = USP_E_SCRIPT_NOT_IN_FONT;
3469 for (i = 0; i < psc->script_count; i++)
3472 pScriptTags[i] = psc->scripts[i].tag;
3476 if (searchingFor == psc->scripts[i].tag)
3478 pScriptTags[0] = psc->scripts[i].tag;
3481 *script_table = psc->scripts[i].table;
3490 static void GSUB_initialize_language_cache(LoadedScript *script)
3494 if (!script->language_count)
3496 const GSUB_Script* table = script->table;
3497 script->language_count = GET_BE_WORD(table->LangSysCount);
3498 script->default_language.tag = MS_MAKE_TAG('d','f','l','t');
3499 script->default_language.table = (const BYTE*)table + GET_BE_WORD(table->DefaultLangSys);
3501 TRACE("Deflang %p, LangCount %i\n",script->default_language.table, script->language_count);
3503 script->languages = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LoadedLanguage) * script->language_count);
3505 for (i = 0; i < script->language_count; i++)
3507 int offset = GET_BE_WORD(table->LangSysRecord[i].LangSys);
3508 script->languages[i].tag = MS_MAKE_TAG(table->LangSysRecord[i].LangSysTag[0], table->LangSysRecord[i].LangSysTag[1], table->LangSysRecord[i].LangSysTag[2], table->LangSysRecord[i].LangSysTag[3]);
3509 script->languages[i].table = ((const BYTE*)table + offset);
3514 static HRESULT GSUB_GetFontLanguageTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pLanguageTags, int *pcTags, LPCVOID* language_table)
3518 LoadedScript *script = NULL;
3520 GSUB_initialize_script_cache(psc);
3522 for (i = 0; i < psc->script_count; i++)
3524 if (psc->scripts[i].tag == script_tag)
3526 script = &psc->scripts[i];
3532 return E_INVALIDARG;
3534 GSUB_initialize_language_cache(script);
3536 if (!searchingFor && cMaxTags < script->language_count)
3538 else if (searchingFor)
3541 *pcTags = script->language_count;
3543 for (i = 0; i < script->language_count; i++)
3546 pLanguageTags[i] = script->languages[i].tag;
3550 if (searchingFor == script->languages[i].tag)
3552 pLanguageTags[0] = script->languages[i].tag;
3555 *language_table = script->languages[i].table;
3562 if (script->default_language.table)
3565 pLanguageTags[i] = script->default_language.tag;
3567 if (searchingFor && FAILED(rc))
3569 pLanguageTags[0] = script->default_language.tag;
3571 *language_table = script->default_language.table;
3574 *pcTags = (*pcTags) + 1;
3580 static void GSUB_initialize_feature_cache(LPCVOID table, LoadedLanguage *language)
3584 if (!language->feature_count)
3586 const GSUB_LangSys *lang= language->table;
3587 const GSUB_Header *header = (const GSUB_Header *)table;
3588 const GSUB_FeatureList *feature_list;
3590 language->feature_count = GET_BE_WORD(lang->FeatureCount);
3591 TRACE("%i features\n",language->feature_count);
3593 language->features = HeapAlloc(GetProcessHeap(),0,sizeof(LoadedFeature)*language->feature_count);
3595 feature_list = (const GSUB_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
3597 for (i = 0; i < language->feature_count; i++)
3599 const GSUB_Feature *feature;
3601 int index = GET_BE_WORD(lang->FeatureIndex[i]);
3603 language->features[i].tag = MS_MAKE_TAG(feature_list->FeatureRecord[index].FeatureTag[0], feature_list->FeatureRecord[index].FeatureTag[1], feature_list->FeatureRecord[index].FeatureTag[2], feature_list->FeatureRecord[index].FeatureTag[3]);
3604 language->features[i].feature = ((const BYTE*)feature_list + GET_BE_WORD(feature_list->FeatureRecord[index].Feature));
3605 feature = (const GSUB_Feature*)language->features[i].feature;
3606 language->features[i].lookup_count = GET_BE_WORD(feature->LookupCount);
3607 language->features[i].lookups = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * language->features[i].lookup_count);
3608 for (j = 0; j < language->features[i].lookup_count; j++)
3609 language->features[i].lookups[j] = GET_BE_WORD(feature->LookupListIndex[j]);
3614 static HRESULT GSUB_GetFontFeatureTags(ScriptCache *psc, OPENTYPE_TAG script_tag, OPENTYPE_TAG language_tag, BOOL filtered, OPENTYPE_TAG searchingFor, int cMaxTags, OPENTYPE_TAG *pFeatureTags, int *pcTags, LoadedFeature** feature)
3618 LoadedScript *script = NULL;
3619 LoadedLanguage *language = NULL;
3621 GSUB_initialize_script_cache(psc);
3623 for (i = 0; i < psc->script_count; i++)
3625 if (psc->scripts[i].tag == script_tag)
3627 script = &psc->scripts[i];
3638 return E_INVALIDARG;
3641 GSUB_initialize_language_cache(script);
3643 if (script->default_language.table && script->default_language.tag == language_tag)
3644 language = &script->default_language;
3647 for (i = 0; i < script->language_count; i++)
3649 if (script->languages[i].tag == language_tag)
3651 language = &script->languages[i];
3663 GSUB_initialize_feature_cache(psc->GSUB_Table, language);
3665 *pcTags = language->feature_count;
3667 if (!searchingFor && cMaxTags < *pcTags)
3669 else if (searchingFor)
3672 for (i = 0; i < language->feature_count; i++)
3675 pFeatureTags[i] = language->features[i].tag;
3679 if (searchingFor == language->features[i].tag)
3681 pFeatureTags[0] = language->features[i].tag;
3684 *feature = &language->features[i];
3693 HRESULT SHAPE_GetFontScriptTags( HDC hdc, ScriptCache *psc,
3694 SCRIPT_ANALYSIS *psa, int cMaxTags,
3695 OPENTYPE_TAG *pScriptTags, int *pcTags)
3698 OPENTYPE_TAG searching = 0x00000000;
3700 if (!psc->GSUB_Table)
3701 psc->GSUB_Table = load_gsub_table(hdc);
3703 if (psa && scriptInformation[psa->eScript].scriptTag)
3704 searching = scriptInformation[psa->eScript].scriptTag;
3706 hr = GSUB_GetFontScriptTags(psc, searching, cMaxTags, pScriptTags, pcTags, NULL);
3712 HRESULT SHAPE_GetFontLanguageTags( HDC hdc, ScriptCache *psc,
3713 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
3714 int cMaxTags, OPENTYPE_TAG *pLangSysTags,
3718 OPENTYPE_TAG searching = 0x00000000;
3719 BOOL fellback = FALSE;
3721 if (!psc->GSUB_Table)
3722 psc->GSUB_Table = load_gsub_table(hdc);
3724 if (psa && psc->userLang != 0)
3725 searching = psc->userLang;
3727 hr = GSUB_GetFontLanguageTags(psc, tagScript, searching, cMaxTags, pLangSysTags, pcTags, NULL);
3731 hr = GSUB_GetFontLanguageTags(psc, MS_MAKE_TAG('l','a','t','n'), searching, cMaxTags, pLangSysTags, pcTags, NULL);
3734 if (FAILED(hr) || fellback)
3736 if (SUCCEEDED(hr) && fellback && psa)
3741 HRESULT SHAPE_GetFontFeatureTags( HDC hdc, ScriptCache *psc,
3742 SCRIPT_ANALYSIS *psa, OPENTYPE_TAG tagScript,
3743 OPENTYPE_TAG tagLangSys, int cMaxTags,
3744 OPENTYPE_TAG *pFeatureTags, int *pcTags)
3747 BOOL filter = FALSE;
3749 if (!psc->GSUB_Table)
3750 psc->GSUB_Table = load_gsub_table(hdc);
3752 if (psa && scriptInformation[psa->eScript].scriptTag)
3754 FIXME("Filtering not implemented\n");
3758 hr = GSUB_GetFontFeatureTags(psc, tagScript, tagLangSys, filter, 0x00000000, cMaxTags, pFeatureTags, pcTags, NULL);