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
31 #include "usp10_internal.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
37 #define FIRST_ARABIC_CHAR 0x0600
38 #define LAST_ARABIC_CHAR 0x06ff
40 typedef VOID (*ContextualShapingProc)(HDC, ScriptCache*, SCRIPT_ANALYSIS*,
41 WCHAR*, INT, WORD*, INT*, INT, WORD*);
43 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
44 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
45 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
46 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
47 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
48 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
49 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
50 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
51 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
52 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
53 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
54 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
55 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust);
57 typedef VOID (*ShapeCharGlyphPropProc)( HDC , ScriptCache*, SCRIPT_ANALYSIS*, const WCHAR*, const INT, const WORD*, const INT, WORD*, SCRIPT_CHARPROP*, SCRIPT_GLYPHPROP*);
59 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);
60 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 );
61 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 );
62 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 );
63 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 );
64 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 );
65 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 );
66 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 );
67 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 );
68 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 );
69 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 );
70 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 );
71 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 );
72 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 );
73 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 );
75 extern const unsigned short indic_syllabic_table[];
76 extern const unsigned short wine_shaping_table[];
77 extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
99 #ifdef WORDS_BIGENDIAN
100 #define GET_BE_WORD(x) (x)
102 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
105 /* These are all structures needed for the GSUB table */
106 #define GSUB_TAG MS_MAKE_TAG('G', 'S', 'U', 'B')
107 #define GSUB_E_NOFEATURE -2
108 #define GSUB_E_NOGLYPH -1
124 GSUB_ScriptRecord ScriptRecord[1];
130 } GSUB_LangSysRecord;
135 GSUB_LangSysRecord LangSysRecord[1];
139 WORD LookupOrder; /* Reserved */
140 WORD ReqFeatureIndex;
142 WORD FeatureIndex[1];
148 } GSUB_FeatureRecord;
152 GSUB_FeatureRecord FeatureRecord[1];
156 WORD FeatureParams; /* Reserved */
158 WORD LookupListIndex[1];
177 } GSUB_CoverageFormat1;
182 WORD StartCoverageIndex;
188 GSUB_RangeRecord RangeRecord[1];
189 } GSUB_CoverageFormat2;
192 WORD SubstFormat; /* = 1 */
195 } GSUB_SingleSubstFormat1;
198 WORD SubstFormat; /* = 2 */
202 }GSUB_SingleSubstFormat2;
205 WORD SubstFormat; /* = 1 */
209 }GSUB_MultipleSubstFormat1;
217 WORD SubstFormat; /* = 1 */
221 }GSUB_LigatureSubstFormat1;
236 WORD LookupListIndex;
238 }GSUB_SubstLookupRecord;
241 WORD SubstFormat; /* = 1 */
243 WORD ChainSubRuleSetCount;
244 WORD ChainSubRuleSet[1];
245 }GSUB_ChainContextSubstFormat1;
248 WORD SubstFormat; /* = 3 */
249 WORD BacktrackGlyphCount;
251 }GSUB_ChainContextSubstFormat3_1;
254 WORD InputGlyphCount;
256 }GSUB_ChainContextSubstFormat3_2;
259 WORD LookaheadGlyphCount;
261 }GSUB_ChainContextSubstFormat3_3;
265 GSUB_SubstLookupRecord SubstLookupRecord[1];
266 }GSUB_ChainContextSubstFormat3_4;
269 WORD SubstFormat; /* = 1 */
271 WORD AlternateSetCount;
272 WORD AlternateSet[1];
273 } GSUB_AlternateSubstFormat1;
280 /* These are all structures needed for the GDEF table */
281 #define GDEF_TAG MS_MAKE_TAG('G', 'D', 'E', 'F')
283 enum {BaseGlyph=1, LigatureGlyph, MarkGlyph, ComponentGlyph};
290 WORD MarkAttachClassDef;
297 WORD ClassValueArray[1];
298 } GDEF_ClassDefFormat1;
304 } GDEF_ClassRangeRecord;
308 WORD ClassRangeCount;
309 GDEF_ClassRangeRecord ClassRangeRecord[1];
310 } GDEF_ClassDefFormat2;
312 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count);
314 typedef struct tagVowelComponents
320 typedef struct tagConsonantComponents
324 } ConsonantComponents;
326 typedef void (*second_reorder_function)(LPWSTR pwChar, IndicSyllable *syllable,WORD* pwGlyphs, IndicSyllable* glyph_index, lexical_function lex);
328 /* the orders of joined_forms and contextual_features need to line up */
329 static const char* contextual_features[] =
341 static OPENTYPE_FEATURE_RECORD standard_features[] =
343 { MS_MAKE_TAG('l','i','g','a'), 1},
344 { MS_MAKE_TAG('c','l','i','g'), 1},
347 static OPENTYPE_FEATURE_RECORD arabic_features[] =
349 { MS_MAKE_TAG('r','l','i','g'), 1},
350 { MS_MAKE_TAG('c','a','l','t'), 1},
351 { MS_MAKE_TAG('l','i','g','a'), 1},
352 { MS_MAKE_TAG('d','l','i','g'), 1},
353 { MS_MAKE_TAG('c','s','w','h'), 1},
354 { MS_MAKE_TAG('m','s','e','t'), 1},
357 static const char* required_arabic_features[] =
366 static OPENTYPE_FEATURE_RECORD hebrew_features[] =
368 { MS_MAKE_TAG('d','l','i','g'), 1},
371 static OPENTYPE_FEATURE_RECORD syriac_features[] =
373 { MS_MAKE_TAG('r','l','i','g'), 1},
374 { MS_MAKE_TAG('c','a','l','t'), 1},
375 { MS_MAKE_TAG('l','i','g','a'), 1},
376 { MS_MAKE_TAG('d','l','i','g'), 1},
379 static const char* required_syriac_features[] =
391 static OPENTYPE_FEATURE_RECORD sinhala_features[] =
393 /* Presentation forms */
394 { MS_MAKE_TAG('b','l','w','s'), 1},
395 { MS_MAKE_TAG('a','b','v','s'), 1},
396 { MS_MAKE_TAG('p','s','t','s'), 1},
399 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
401 { MS_MAKE_TAG('a','b','v','s'), 1},
402 { MS_MAKE_TAG('b','l','w','s'), 1},
405 static OPENTYPE_FEATURE_RECORD thai_features[] =
407 { MS_MAKE_TAG('c','c','m','p'), 1},
410 static const char* required_lao_features[] =
416 static const char* required_devanagari_features[] =
432 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
434 { MS_MAKE_TAG('p','r','e','s'), 1},
435 { MS_MAKE_TAG('a','b','v','s'), 1},
436 { MS_MAKE_TAG('b','l','w','s'), 1},
437 { MS_MAKE_TAG('p','s','t','s'), 1},
438 { MS_MAKE_TAG('h','a','l','n'), 1},
439 { MS_MAKE_TAG('c','a','l','t'), 1},
442 static const char* required_bengali_features[] =
459 static const char* required_gurmukhi_features[] =
478 static const char* required_oriya_features[] =
495 static const char* required_tamil_features[] =
511 static const char* required_telugu_features[] =
529 typedef struct ScriptShapeDataTag {
530 TEXTRANGE_PROPERTIES defaultTextRange;
531 const char** requiredFeatures;
534 ContextualShapingProc contextProc;
535 ShapeCharGlyphPropProc charGlyphPropProc;
538 /* in order of scripts */
539 static const ScriptShapeData ShapingData[] =
541 {{ standard_features, 2}, NULL, "", "", NULL, NULL},
542 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
543 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
544 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
545 {{ standard_features, 2}, NULL, "" , "", NULL, NULL},
546 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
547 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
548 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
549 {{ hebrew_features, 1}, NULL, "hebr", "", NULL, NULL},
550 {{ syriac_features, 4}, required_syriac_features, "syrc", "", ContextualShape_Syriac, ShapeCharGlyphProp_None},
551 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
552 {{ NULL, 0}, NULL, "thaa", "", NULL, ShapeCharGlyphProp_None},
553 {{ standard_features, 2}, NULL, "grek", "", NULL, NULL},
554 {{ standard_features, 2}, NULL, "cyrl", "", NULL, NULL},
555 {{ standard_features, 2}, NULL, "armn", "", NULL, NULL},
556 {{ standard_features, 2}, NULL, "geor", "", NULL, NULL},
557 {{ sinhala_features, 3}, NULL, "sinh", "", ContextualShape_Sinhala, ShapeCharGlyphProp_Sinhala},
558 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
559 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
560 {{ tibetan_features, 2}, NULL, "phag", "", ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
561 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
562 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
563 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
564 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
565 {{ devanagari_features, 6}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
566 {{ devanagari_features, 6}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
567 {{ devanagari_features, 6}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
568 {{ devanagari_features, 6}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
569 {{ devanagari_features, 6}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
570 {{ devanagari_features, 6}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
571 {{ devanagari_features, 6}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
572 {{ devanagari_features, 6}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
573 {{ devanagari_features, 6}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
574 {{ devanagari_features, 6}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
575 {{ devanagari_features, 6}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
576 {{ devanagari_features, 6}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
577 {{ devanagari_features, 6}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
578 {{ devanagari_features, 6}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
579 {{ devanagari_features, 6}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
580 {{ devanagari_features, 6}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
581 {{ devanagari_features, 6}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
582 {{ devanagari_features, 6}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
583 {{ devanagari_features, 6}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
584 {{ devanagari_features, 6}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
587 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
589 const GSUB_CoverageFormat1* cf1;
593 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
595 int count = GET_BE_WORD(cf1->GlyphCount);
597 TRACE("Coverage Format 1, %i glyphs\n",count);
598 for (i = 0; i < count; i++)
599 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
603 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
605 const GSUB_CoverageFormat2* cf2;
608 cf2 = (const GSUB_CoverageFormat2*)cf1;
610 count = GET_BE_WORD(cf2->RangeCount);
611 TRACE("Coverage Format 2, %i ranges\n",count);
612 for (i = 0; i < count; i++)
614 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
616 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
617 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
619 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
620 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
626 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
631 static const GSUB_Script* GSUB_get_script_table( const GSUB_Header* header, const char* tag)
633 const GSUB_ScriptList *script;
634 const GSUB_Script *deflt = NULL;
636 script = (const GSUB_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
638 TRACE("%i scripts in this font\n",GET_BE_WORD(script->ScriptCount));
639 for (i = 0; i < GET_BE_WORD(script->ScriptCount); i++)
641 const GSUB_Script *scr;
644 offset = GET_BE_WORD(script->ScriptRecord[i].Script);
645 scr = (const GSUB_Script*)((const BYTE*)script + offset);
647 if (strncmp(script->ScriptRecord[i].ScriptTag, tag,4)==0)
649 if (strncmp(script->ScriptRecord[i].ScriptTag, "dflt",4)==0)
655 static const GSUB_LangSys* GSUB_get_lang_table( const GSUB_Script* script, const char* tag)
659 const GSUB_LangSys *Lang;
661 TRACE("Deflang %x, LangCount %i\n",GET_BE_WORD(script->DefaultLangSys), GET_BE_WORD(script->LangSysCount));
663 for (i = 0; i < GET_BE_WORD(script->LangSysCount) ; i++)
665 offset = GET_BE_WORD(script->LangSysRecord[i].LangSys);
666 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
668 if ( strncmp(script->LangSysRecord[i].LangSysTag,tag,4)==0)
671 offset = GET_BE_WORD(script->DefaultLangSys);
674 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
680 static const GSUB_Feature * GSUB_get_feature(const GSUB_Header *header, const GSUB_LangSys *lang, const char* tag)
683 const GSUB_FeatureList *feature;
684 feature = (const GSUB_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
686 TRACE("%i features\n",GET_BE_WORD(lang->FeatureCount));
687 for (i = 0; i < GET_BE_WORD(lang->FeatureCount); i++)
689 int index = GET_BE_WORD(lang->FeatureIndex[i]);
690 if (strncmp(feature->FeatureRecord[index].FeatureTag,tag,4)==0)
692 const GSUB_Feature *feat;
693 feat = (const GSUB_Feature*)((const BYTE*)feature + GET_BE_WORD(feature->FeatureRecord[index].Feature));
700 static INT GSUB_apply_SingleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
703 TRACE("Single Substitution Subtable\n");
705 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
708 const GSUB_SingleSubstFormat1 *ssf1;
709 offset = GET_BE_WORD(look->SubTable[j]);
710 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
711 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
713 int offset = GET_BE_WORD(ssf1->Coverage);
714 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
715 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
717 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
718 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
719 TRACE(" 0x%x\n",glyphs[glyph_index]);
720 return glyph_index + 1;
725 const GSUB_SingleSubstFormat2 *ssf2;
729 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
730 offset = GET_BE_WORD(ssf1->Coverage);
731 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
732 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
733 TRACE(" Coverage index %i\n",index);
736 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
737 return GSUB_E_NOGLYPH;
739 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
740 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
741 TRACE("0x%x\n",glyphs[glyph_index]);
742 return glyph_index + 1;
746 return GSUB_E_NOGLYPH;
749 static INT GSUB_apply_MultipleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
752 TRACE("Multiple Substitution Subtable\n");
754 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
757 const GSUB_MultipleSubstFormat1 *msf1;
758 offset = GET_BE_WORD(look->SubTable[j]);
759 msf1 = (const GSUB_MultipleSubstFormat1*)((const BYTE*)look+offset);
761 offset = GET_BE_WORD(msf1->Coverage);
762 index = GSUB_is_glyph_covered((const BYTE*)msf1+offset, glyphs[glyph_index]);
765 const GSUB_Sequence *seq;
768 offset = GET_BE_WORD(msf1->Sequence[index]);
769 seq = (const GSUB_Sequence*)((const BYTE*)msf1+offset);
770 sub_count = GET_BE_WORD(seq->GlyphCount);
771 TRACE(" Glyph 0x%x (+%i)->",glyphs[glyph_index],(sub_count-1));
773 for (j = (*glyph_count)+(sub_count-1); j > glyph_index; j--)
774 glyphs[j] =glyphs[j-(sub_count-1)];
776 for (j = 0; j < sub_count; j++)
778 glyphs[glyph_index + (sub_count-1) - j] = GET_BE_WORD(seq->Substitute[j]);
780 glyphs[glyph_index + j] = GET_BE_WORD(seq->Substitute[j]);
782 *glyph_count = *glyph_count + (sub_count - 1);
784 if (TRACE_ON(uniscribe))
786 for (j = 0; j < sub_count; j++)
787 TRACE(" 0x%x",glyphs[glyph_index+j]);
791 return glyph_index + sub_count;
794 return GSUB_E_NOGLYPH;
797 static INT GSUB_apply_AlternateSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
800 TRACE("Alternate Substitution Subtable\n");
802 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
805 const GSUB_AlternateSubstFormat1 *asf1;
808 offset = GET_BE_WORD(look->SubTable[j]);
809 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
810 offset = GET_BE_WORD(asf1->Coverage);
812 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
815 const GSUB_AlternateSet *as;
816 offset = GET_BE_WORD(asf1->AlternateSet[index]);
817 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
818 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
819 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
820 return GSUB_E_NOGLYPH;
822 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
823 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
824 TRACE(" 0x%x\n",glyphs[glyph_index]);
825 return glyph_index + 1;
828 return GSUB_E_NOGLYPH;
831 static INT GSUB_apply_LigatureSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
835 TRACE("Ligature Substitution Subtable\n");
836 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
838 const GSUB_LigatureSubstFormat1 *lsf1;
841 offset = GET_BE_WORD(look->SubTable[j]);
842 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
843 offset = GET_BE_WORD(lsf1->Coverage);
844 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
845 TRACE(" Coverage index %i\n",index);
848 const GSUB_LigatureSet *ls;
851 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
852 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
853 count = GET_BE_WORD(ls->LigatureCount);
854 TRACE(" LigatureSet has %i members\n",count);
855 for (k = 0; k < count; k++)
857 const GSUB_Ligature *lig;
858 int CompCount,l,CompIndex;
860 offset = GET_BE_WORD(ls->Ligature[k]);
861 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
862 CompCount = GET_BE_WORD(lig->CompCount) - 1;
863 CompIndex = glyph_index+write_dir;
864 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
867 CompGlyph = GET_BE_WORD(lig->Component[l]);
868 if (CompGlyph != glyphs[CompIndex])
870 CompIndex += write_dir;
874 int replaceIdx = glyph_index;
876 replaceIdx = glyph_index - CompCount;
878 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
879 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
880 TRACE("0x%x\n",glyphs[replaceIdx]);
884 for (j = replaceIdx + 1; j < *glyph_count; j++)
885 glyphs[j] =glyphs[j+CompCount];
886 *glyph_count = *glyph_count - CompCount;
888 return replaceIdx + 1;
893 return GSUB_E_NOGLYPH;
896 static INT GSUB_apply_ChainContextSubst(const GSUB_LookupList* lookup, const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
901 TRACE("Chaining Contextual Substitution Subtable\n");
902 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
904 const GSUB_ChainContextSubstFormat1 *ccsf1;
906 int dirLookahead = write_dir;
907 int dirBacktrack = -1 * write_dir;
909 offset = GET_BE_WORD(look->SubTable[j]);
910 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
911 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
913 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
916 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
918 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
921 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
925 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
926 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
927 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
928 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
929 int newIndex = glyph_index;
931 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
933 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
935 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
937 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
938 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
941 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
943 TRACE("Matched Backtrack\n");
945 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)(((LPBYTE)ccsf1)+sizeof(GSUB_ChainContextSubstFormat3_1) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)-1)));
947 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
948 for (k = 0; k < indexGlyphs; k++)
950 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
951 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
954 if (k != indexGlyphs)
956 TRACE("Matched IndexGlyphs\n");
958 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)(((LPBYTE)ccsf3_2)+sizeof(GSUB_ChainContextSubstFormat3_2) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_2->InputGlyphCount)-1)));
960 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
962 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
963 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
966 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
968 TRACE("Matched LookAhead\n");
970 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)(((LPBYTE)ccsf3_3)+sizeof(GSUB_ChainContextSubstFormat3_3) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)-1)));
972 if (GET_BE_WORD(ccsf3_4->SubstCount))
974 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
976 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
977 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
979 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
980 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
983 ERR("Chain failed to generate a glyph\n");
989 else return GSUB_E_NOGLYPH;
995 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
998 const GSUB_LookupTable *look;
1000 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1001 look = (const GSUB_LookupTable*)((const BYTE*)lookup + offset);
1002 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1003 switch(GET_BE_WORD(look->LookupType))
1006 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1008 return GSUB_apply_MultipleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1010 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1012 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1014 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
1016 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1018 return GSUB_E_NOGLYPH;
1021 static INT GSUB_apply_feature(const GSUB_Header * header, const GSUB_Feature* feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1024 int out_index = GSUB_E_NOGLYPH;
1025 const GSUB_LookupList *lookup;
1027 lookup = (const GSUB_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1029 TRACE("%i lookups\n", GET_BE_WORD(feature->LookupCount));
1030 for (i = 0; i < GET_BE_WORD(feature->LookupCount); i++)
1032 out_index = GSUB_apply_lookup(lookup, GET_BE_WORD(feature->LookupListIndex[i]), glyphs, glyph_index, write_dir, glyph_count);
1033 if (out_index != GSUB_E_NOGLYPH)
1036 if (out_index == GSUB_E_NOGLYPH)
1037 TRACE("lookups found no glyphs\n");
1041 out2 = GSUB_apply_feature(header, feature, glyphs, glyph_index, write_dir, glyph_count);
1042 if (out2!=GSUB_E_NOGLYPH)
1048 static const char* get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
1052 if (psc->userScript != 0)
1054 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0 && strncmp((char*)&psc->userScript,ShapingData[psa->eScript].otTag,4)==0)
1055 return ShapingData[psa->eScript].newOtTag;
1057 return (char*)&psc->userScript;
1060 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0)
1061 return ShapingData[psa->eScript].newOtTag;
1063 if (ShapingData[psa->eScript].otTag[0] != 0)
1064 return ShapingData[psa->eScript].otTag;
1067 * fall back to the font charset
1069 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
1072 case ANSI_CHARSET: return "latn";
1073 case BALTIC_CHARSET: return "latn"; /* ?? */
1074 case CHINESEBIG5_CHARSET: return "hani";
1075 case EASTEUROPE_CHARSET: return "latn"; /* ?? */
1076 case GB2312_CHARSET: return "hani";
1077 case GREEK_CHARSET: return "grek";
1078 case HANGUL_CHARSET: return "hang";
1079 case RUSSIAN_CHARSET: return "cyrl";
1080 case SHIFTJIS_CHARSET: return "kana";
1081 case TURKISH_CHARSET: return "latn"; /* ?? */
1082 case VIETNAMESE_CHARSET: return "latn";
1083 case JOHAB_CHARSET: return "latn"; /* ?? */
1084 case ARABIC_CHARSET: return "arab";
1085 case HEBREW_CHARSET: return "hebr";
1086 case THAI_CHARSET: return "thai";
1087 default: return "latn";
1091 static LPCVOID load_GSUB_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, const char* feat)
1093 const GSUB_Feature *feature;
1096 for (i = 0; i < psc->feature_count; i++)
1097 if (strncmp(psc->features[i].tag,feat,4)==0)
1098 return psc->features[i].feature;
1102 if (psc->GSUB_Table)
1104 const GSUB_Script *script;
1105 const GSUB_LangSys *language;
1110 script = GSUB_get_script_table(psc->GSUB_Table, get_opentype_script(hdc,psa,psc,(attempt==2)));
1114 if (psc->userLang != 0)
1115 language = GSUB_get_lang_table(script,(char*)&psc->userLang);
1117 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1119 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1121 } while(attempt && !feature);
1123 /* try in the default (latin) table */
1126 script = GSUB_get_script_table(psc->GSUB_Table, "latn");
1129 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1131 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1136 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
1138 psc->feature_count++;
1141 psc->features = HeapReAlloc(GetProcessHeap(), 0, psc->features, psc->feature_count * sizeof(LoadedFeature));
1143 psc->features = HeapAlloc(GetProcessHeap(), 0, psc->feature_count * sizeof(LoadedFeature));
1145 lstrcpynA(psc->features[psc->feature_count - 1].tag, feat, 5);
1146 psc->features[psc->feature_count - 1].feature = feature;
1150 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)
1152 const GSUB_Feature *feature;
1154 feature = load_GSUB_feature(hdc, psa, psc, feat);
1156 return GSUB_E_NOFEATURE;
1158 TRACE("applying feature %s\n",feat);
1159 return GSUB_apply_feature(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
1162 static VOID *load_gsub_table(HDC hdc)
1164 VOID* GSUB_Table = NULL;
1165 int length = GetFontData(hdc, GSUB_TAG , 0, NULL, 0);
1166 if (length != GDI_ERROR)
1168 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
1169 GetFontData(hdc, GSUB_TAG , 0, GSUB_Table, length);
1170 TRACE("Loaded GSUB table of %i bytes\n",length);
1175 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)
1178 INT glyph_count = count;
1181 glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*(count*2));
1182 GetGlyphIndicesW(hdc, chars, count, glyphs, 0);
1183 rc = apply_GSUB_feature_to_glyph(hdc, psa, psc, glyphs, 0, write_dir, &glyph_count, feature);
1184 if (rc > GSUB_E_NOGLYPH)
1185 rc = count - glyph_count;
1189 HeapFree(GetProcessHeap(),0,glyphs);
1193 static WORD GDEF_get_glyph_class(const GDEF_Header *header, WORD glyph)
1197 const GDEF_ClassDefFormat1 *cf1;
1202 offset = GET_BE_WORD(header->GlyphClassDef);
1206 cf1 = (GDEF_ClassDefFormat1*)(((BYTE*)header)+offset);
1207 if (GET_BE_WORD(cf1->ClassFormat) == 1)
1209 if (glyph >= GET_BE_WORD(cf1->StartGlyph))
1211 int index = glyph - GET_BE_WORD(cf1->StartGlyph);
1212 if (index < GET_BE_WORD(cf1->GlyphCount))
1213 class = GET_BE_WORD(cf1->ClassValueArray[index]);
1216 else if (GET_BE_WORD(cf1->ClassFormat) == 2)
1218 const GDEF_ClassDefFormat2 *cf2 = (GDEF_ClassDefFormat2*)cf1;
1220 top = GET_BE_WORD(cf2->ClassRangeCount);
1221 for (i = 0; i < top; i++)
1223 if (glyph >= GET_BE_WORD(cf2->ClassRangeRecord[i].Start) &&
1224 glyph <= GET_BE_WORD(cf2->ClassRangeRecord[i].End))
1226 class = GET_BE_WORD(cf2->ClassRangeRecord[i].Class);
1232 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1->ClassFormat));
1237 static VOID *load_gdef_table(HDC hdc)
1239 VOID* GDEF_Table = NULL;
1240 int length = GetFontData(hdc, GDEF_TAG , 0, NULL, 0);
1241 if (length != GDI_ERROR)
1243 GDEF_Table = HeapAlloc(GetProcessHeap(),0,length);
1244 GetFontData(hdc, GDEF_TAG , 0, GDEF_Table, length);
1245 TRACE("Loaded GDEF table of %i bytes\n",length);
1250 static void GDEF_UpdateGlyphProps(HDC hdc, ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1254 if (!psc->GDEF_Table)
1255 psc->GDEF_Table = load_gdef_table(hdc);
1257 for (i = 0; i < cGlyphs; i++)
1261 class = GDEF_get_glyph_class(psc->GDEF_Table, pwGlyphs[i]);
1267 pGlyphProp[i].sva.fClusterStart = 1;
1268 pGlyphProp[i].sva.fDiacritic = 0;
1269 pGlyphProp[i].sva.fZeroWidth = 0;
1272 pGlyphProp[i].sva.fClusterStart = 1;
1273 pGlyphProp[i].sva.fDiacritic = 0;
1274 pGlyphProp[i].sva.fZeroWidth = 0;
1277 pGlyphProp[i].sva.fClusterStart = 0;
1278 pGlyphProp[i].sva.fDiacritic = 1;
1279 pGlyphProp[i].sva.fZeroWidth = 1;
1281 case ComponentGlyph:
1282 pGlyphProp[i].sva.fClusterStart = 0;
1283 pGlyphProp[i].sva.fDiacritic = 0;
1284 pGlyphProp[i].sva.fZeroWidth = 0;
1287 ERR("Unknown glyph class %i\n",class);
1288 pGlyphProp[i].sva.fClusterStart = 1;
1289 pGlyphProp[i].sva.fDiacritic = 0;
1290 pGlyphProp[i].sva.fZeroWidth = 0;
1295 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1299 for (i = 0; i < cGlyphs; i++)
1301 if (!pGlyphProp[i].sva.fClusterStart)
1304 for (j = 0; j < cChars; j++)
1306 if (pwLogClust[j] == i)
1309 while (!pGlyphProp[pwLogClust[k]].sva.fClusterStart && k >= 0 && k <cChars)
1311 if (pGlyphProp[pwLogClust[k]].sva.fClusterStart)
1312 pwLogClust[j] = pwLogClust[k];
1319 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
1321 if (changeCount == 0)
1326 int target_glyph = nextIndex - 1;
1328 int target_index = -1;
1329 int replacing_glyph = -1;
1333 if (changeCount > 0)
1334 target_glyph = nextIndex - (changeCount+1);
1336 seeking_glyph = target_glyph;
1340 for (i = 0; i < chars; i++)
1342 if (pwLogClust[i] == seeking_glyph)
1349 for (i = chars - 1; i >= 0; i--)
1351 if (pwLogClust[i] == seeking_glyph)
1357 if (target_index == -1)
1360 while (target_index == -1 && seeking_glyph < chars);
1362 if (target_index == -1)
1364 ERR("Unable to find target glyph\n");
1368 if (changeCount < 0)
1371 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1373 if (pwLogClust[i] == target_glyph)
1375 if(pwLogClust[i] == replacing_glyph)
1376 pwLogClust[i] = target_glyph;
1380 if (changed >= changeCount)
1382 replacing_glyph = pwLogClust[i];
1383 pwLogClust[i] = target_glyph;
1390 /* renumber trailing indexes*/
1391 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1393 if (pwLogClust[i] != target_glyph)
1394 pwLogClust[i] += changeCount;
1399 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1400 pwLogClust[i] += changeCount;
1405 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 )
1409 if (psc->GSUB_Table)
1411 const GSUB_Feature *feature;
1413 feature = load_GSUB_feature(hdc, psa, psc, feat);
1415 return GSUB_E_NOFEATURE;
1418 TRACE("applying feature %s\n",debugstr_an(feat,4));
1419 while(i < *pcGlyphs)
1422 INT prevCount = *pcGlyphs;
1423 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, i, write_dir, pcGlyphs);
1424 if (nextIndex > GSUB_E_NOGLYPH)
1426 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
1434 return GSUB_E_NOFEATURE;
1437 static inline BOOL get_GSUB_Indic2(SCRIPT_ANALYSIS *psa, ScriptCache *psc)
1439 return(GSUB_get_script_table(psc->GSUB_Table,ShapingData[psa->eScript].newOtTag)!=NULL);
1442 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
1446 if ( i+ delta >= cchLen)
1454 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
1458 if (psa->fLinkBefore)
1463 if ( i+ delta >= cchLen)
1465 if (psa->fLinkAfter)
1473 if (context_type[i] == jtT)
1474 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
1476 return context_type[i];
1479 static inline BOOL right_join_causing(CHAR joining_type)
1481 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
1484 static inline BOOL left_join_causing(CHAR joining_type)
1486 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
1489 static inline BOOL word_break_causing(WCHAR chr)
1491 /* we are working within a string of characters already guareented to
1492 be within one script, Syriac, so we do not worry about any character
1493 other than the space character outside of that range */
1494 return (chr == 0 || chr == 0x20 );
1498 * ContextualShape_Arabic
1500 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1507 if (*pcGlyphs != cChars)
1509 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1513 if (!psa->fLogicalOrder && psa->fRTL)
1524 if (!psc->GSUB_Table)
1525 psc->GSUB_Table = load_gsub_table(hdc);
1527 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1528 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1530 for (i = 0; i < cChars; i++)
1531 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1533 for (i = 0; i < cChars; i++)
1535 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1536 context_shape[i] = Xr;
1537 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1538 context_shape[i] = Xl;
1539 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)))
1540 context_shape[i] = Xm;
1541 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1542 context_shape[i] = Xr;
1543 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1544 context_shape[i] = Xl;
1546 context_shape[i] = Xn;
1549 /* Contextual Shaping */
1551 while(i < *pcGlyphs)
1553 BOOL shaped = FALSE;
1555 if (psc->GSUB_Table)
1558 INT prevCount = *pcGlyphs;
1559 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1560 if (nextIndex > GSUB_E_NOGLYPH)
1563 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1565 shaped = (nextIndex > GSUB_E_NOGLYPH);
1570 WORD newGlyph = pwOutGlyphs[i];
1571 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1573 /* fall back to presentation form B */
1574 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1575 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1576 pwOutGlyphs[i] = newGlyph;
1582 HeapFree(GetProcessHeap(),0,context_shape);
1583 HeapFree(GetProcessHeap(),0,context_type);
1587 * ContextualShape_Syriac
1591 #define DALATH 0x715
1594 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1601 if (*pcGlyphs != cChars)
1603 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1607 if (!psa->fLogicalOrder && psa->fRTL)
1618 if (!psc->GSUB_Table)
1619 psc->GSUB_Table = load_gsub_table(hdc);
1621 if (!psc->GSUB_Table)
1624 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1625 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1627 for (i = 0; i < cChars; i++)
1628 context_type[i] = get_table_entry( wine_shaping_table, pwcChars[i] );
1630 for (i = 0; i < cChars; i++)
1632 if (pwcChars[i] == ALAPH)
1634 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1636 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1637 context_shape[i] = Afj;
1638 else if ( rchar != DALATH && rchar != RISH &&
1639 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1640 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1641 context_shape[i] = Afn;
1642 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1643 context_shape[i] = Afx;
1645 context_shape[i] = Xn;
1647 else if (context_type[i] == jtR &&
1648 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1649 context_shape[i] = Xr;
1650 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1651 context_shape[i] = Xl;
1652 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)))
1653 context_shape[i] = Xm;
1654 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1655 context_shape[i] = Xr;
1656 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1657 context_shape[i] = Xl;
1659 context_shape[i] = Xn;
1662 /* Contextual Shaping */
1664 while(i < *pcGlyphs)
1667 INT prevCount = *pcGlyphs;
1668 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1669 if (nextIndex > GSUB_E_NOGLYPH)
1671 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1678 HeapFree(GetProcessHeap(),0,context_shape);
1679 HeapFree(GetProcessHeap(),0,context_type);
1683 * ContextualShape_Phags_pa
1686 #define phags_pa_CANDRABINDU 0xA873
1687 #define phags_pa_START 0xA840
1688 #define phags_pa_END 0xA87F
1690 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1696 if (*pcGlyphs != cChars)
1698 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1702 if (!psa->fLogicalOrder && psa->fRTL)
1713 if (!psc->GSUB_Table)
1714 psc->GSUB_Table = load_gsub_table(hdc);
1716 if (!psc->GSUB_Table)
1719 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1721 for (i = 0; i < cChars; i++)
1723 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1725 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1726 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1727 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1728 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1730 if (jrchar && jlchar)
1731 context_shape[i] = Xm;
1733 context_shape[i] = Xr;
1735 context_shape[i] = Xl;
1737 context_shape[i] = Xn;
1740 context_shape[i] = -1;
1743 /* Contextual Shaping */
1745 while(i < *pcGlyphs)
1747 if (context_shape[i] >= 0)
1750 INT prevCount = *pcGlyphs;
1751 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1752 if (nextIndex > GSUB_E_NOGLYPH)
1754 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1764 HeapFree(GetProcessHeap(),0,context_shape);
1767 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1772 pwOutChars[cWalk] = replacements[0];
1776 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1779 for (j = *pcChars; j > cWalk; j--)
1780 pwOutChars[j] = pwOutChars[j-1];
1781 *pcChars= *pcChars+1;
1782 pwOutChars[cWalk] = replacements[i];
1787 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[], WORD* pwLogClust)
1793 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1795 for (i = 0; vowels[i].base != 0x0; i++)
1797 if (pwOutChars[cWalk] == vowels[i].base)
1801 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1802 if (vowels[i].parts[1]) { cWalk++; o++; }
1803 if (vowels[i].parts[2]) { cWalk++; o++; }
1805 for (j = (cWalk - offset) + 1; j < *pcChars - offset; j ++)
1813 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[], WORD* pwLogClust)
1819 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1821 for (i = 0; consonants[i].output!= 0x0; i++)
1824 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1825 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1828 if (consonants[i].parts[j]==0x0) /* matched all */
1832 pwOutChars[cWalk] = consonants[i].output;
1833 for(k = cWalk+1; k < *pcChars - j; k++)
1834 pwOutChars[k] = pwOutChars[k+j];
1835 *pcChars = *pcChars - j;
1836 for (k = j ; k > 0; k--)
1837 pwLogClust[cWalk + k + offset] = pwLogClust[cWalk + offset];
1839 for (k = cWalk + j + offset; k < *pcChars + offset; k++)
1848 static void Reorder_Ra_follows_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1853 WORD Ra = pwChar[s->start];
1854 WORD H = pwChar[s->start+1];
1856 TRACE("Doing reorder of Ra to %i\n",s->base);
1857 for (j = s->start; j < s->base-1; j++)
1858 pwChar[j] = pwChar[j+2];
1859 pwChar[s->base-1] = Ra;
1860 pwChar[s->base] = H;
1862 s->ralf = s->base-1;
1867 static void Reorder_Ra_follows_matra(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1872 int stop = (s->blwf >=0)? s->blwf+1 : s->base;
1873 WORD Ra = pwChar[s->start];
1874 WORD H = pwChar[s->start+1];
1875 for (loc = s->end; loc > stop; loc--)
1876 if (lexical(pwChar[loc]) == lex_Matra_post || lexical(pwChar[loc]) == lex_Matra_below)
1879 TRACE("Doing reorder of Ra to %i\n",loc);
1880 for (j = s->start; j < loc-1; j++)
1881 pwChar[j] = pwChar[j+2];
1887 if (s->blwf >= 0) s->blwf -= 2;
1888 if (s->pref >= 0) s->pref -= 2;
1892 static void Reorder_Ra_follows_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1897 WORD Ra = pwChar[s->start];
1898 WORD H = pwChar[s->start+1];
1900 TRACE("Doing reorder of Ra to %i\n",s->end-1);
1901 for (j = s->start; j < s->end-1; j++)
1902 pwChar[j] = pwChar[j+2];
1903 pwChar[s->end-1] = Ra;
1908 if (s->blwf >= 0) s->blwf -= 2;
1909 if (s->pref >= 0) s->pref -= 2;
1913 static void Reorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1917 /* reorder Matras */
1918 if (s->end > s->base)
1920 for (i = 1; i <= s->end-s->base; i++)
1922 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1925 WCHAR c = pwChar[s->base+i];
1926 TRACE("Doing reorder of %x %x\n",c,pwChar[s->base]);
1927 for (j = s->base+i; j > s->base; j--)
1928 pwChar[j] = pwChar[j-1];
1929 pwChar[s->base] = c;
1931 if (s->ralf >= s->base) s->ralf++;
1932 if (s->blwf >= s->base) s->blwf++;
1933 if (s->pref >= s->base) s->pref++;
1940 static void Reorder_Matra_precede_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1944 /* reorder Matras */
1945 if (s->end > s->base)
1947 for (i = 1; i <= s->end-s->base; i++)
1949 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1952 WCHAR c = pwChar[s->base+i];
1953 TRACE("Doing reorder of %x to %i\n",c,s->start);
1954 for (j = s->base+i; j > s->start; j--)
1955 pwChar[j] = pwChar[j-1];
1956 pwChar[s->start] = c;
1958 if (s->ralf >= 0) s->ralf++;
1959 if (s->blwf >= 0) s->blwf++;
1960 if (s->pref >= 0) s->pref++;
1967 static void SecondReorder_Blwf_follows_matra(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1969 if (s->blwf >= 0 && g->blwf > g->base)
1973 for (loc = s->end; loc > s->blwf; loc--)
1974 if (lexical(pwChar[loc]) == lex_Matra_below || lexical(pwChar[loc]) == lex_Matra_above || lexical(pwChar[loc]) == lex_Matra_post)
1977 g_offset = (loc - s->blwf) - 1;
1981 WORD blwf = glyphs[g->blwf];
1982 TRACE("Doing reorder of Below-base to %i (glyph offset %i)\n",loc,g_offset);
1983 /* do not care about the pwChar array anymore, just the glyphs */
1984 for (j = 0; j < g_offset; j++)
1985 glyphs[g->blwf + j] = glyphs[g->blwf + j + 1];
1986 glyphs[g->blwf + g_offset] = blwf;
1991 static void SecondReorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
1995 /* reorder previously moved Matras to correct position*/
1996 for (i = s->start; i < s->base; i++)
1998 if (lexical(pwChar[i]) == lex_Matra_pre)
2001 int g_start = g->start + i - s->start;
2002 if (g_start < g->base -1 )
2004 WCHAR og = glyphs[g_start];
2005 TRACE("Doing reorder of matra from %i to %i\n",g_start,g->base);
2006 for (j = g_start; j < g->base-1; j++)
2007 glyphs[j] = glyphs[j+1];
2008 glyphs[g->base-1] = og;
2014 static void SecondReorder_Pref_precede_base(LPWSTR pwChar, IndicSyllable *s, WORD *glyphs, IndicSyllable *g, lexical_function lexical)
2016 if (s->pref >= 0 && g->pref > g->base)
2019 WCHAR og = glyphs[g->pref];
2020 TRACE("Doing reorder of pref from %i to %i\n",g->pref,g->base);
2021 for (j = g->pref; j > g->base; j--)
2022 glyphs[j] = glyphs[j-1];
2023 glyphs[g->base] = og;
2027 static void Reorder_Like_Sinhala(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
2029 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2030 if (s->start == s->base && s->base == s->end) return;
2031 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2033 Reorder_Ra_follows_base(pwChar, s, lexical);
2034 Reorder_Matra_precede_base(pwChar, s, lexical);
2037 static void Reorder_Like_Devanagari(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
2039 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2040 if (s->start == s->base && s->base == s->end) return;
2041 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2043 Reorder_Ra_follows_matra(pwChar, s, lexical);
2044 Reorder_Matra_precede_syllable(pwChar, s, lexical);
2047 static void Reorder_Like_Bengali(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
2049 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2050 if (s->start == s->base && s->base == s->end) return;
2051 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2053 Reorder_Ra_follows_base(pwChar, s, lexical);
2054 Reorder_Matra_precede_syllable(pwChar, s, lexical);
2057 static void Reorder_Like_Kannada(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
2059 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2060 if (s->start == s->base && s->base == s->end) return;
2061 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2063 Reorder_Ra_follows_syllable(pwChar, s, lexical);
2064 Reorder_Matra_precede_syllable(pwChar, s, lexical);
2067 static void SecondReorder_Like_Telugu(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
2069 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2070 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
2071 if (s->start == s->base && s->base == s->end) return;
2072 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2074 SecondReorder_Blwf_follows_matra(pwChar, s, pwGlyphs, g, lexical);
2077 static void SecondReorder_Like_Tamil(LPWSTR pwChar, IndicSyllable *s, WORD* pwGlyphs, IndicSyllable *g, lexical_function lexical)
2079 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
2080 TRACE("Glyphs (%i..%i..%i)\n",g->start,g->base,g->end);
2081 if (s->start == s->base && s->base == s->end) return;
2082 if (lexical(pwChar[s->base]) == lex_Vowel) return;
2084 SecondReorder_Matra_precede_base(pwChar, s, pwGlyphs, g, lexical);
2085 SecondReorder_Pref_precede_base(pwChar, s, pwGlyphs, g, lexical);
2089 static inline void shift_syllable_glyph_indexs(IndicSyllable *glyph_index, INT index, INT shift)
2094 if (glyph_index->start > index)
2095 glyph_index->start += shift;
2096 if (glyph_index->base > index)
2097 glyph_index->base+= shift;
2098 if (glyph_index->end > index)
2099 glyph_index->end+= shift;
2100 if (glyph_index->ralf > index)
2101 glyph_index->ralf+= shift;
2102 if (glyph_index->blwf > index)
2103 glyph_index->blwf+= shift;
2104 if (glyph_index->pref > index)
2105 glyph_index->pref+= shift;
2108 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, const GSUB_Feature *feature )
2110 int index = glyph_index->start;
2115 while(index <= glyph_index->end)
2118 INT prevCount = *pcGlyphs;
2119 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, index, 1, pcGlyphs);
2120 if (nextIndex > GSUB_E_NOGLYPH)
2122 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2123 shift_syllable_glyph_indexs(glyph_index,index,*pcGlyphs - prevCount);
2131 static inline INT find_consonant_halant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2134 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)))))
2136 if (index + i <= end-1)
2142 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)
2144 INT index, nextIndex;
2147 count = syllable->base - syllable->start;
2150 index = find_consonant_halant(&pwChars[syllable->start], 0, count, lexical);
2151 while (index >= 0 && index + g_offset < (glyph_index->base - glyph_index->start))
2153 INT prevCount = *pcGlyphs;
2154 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->start+g_offset, 1, pcGlyphs, feature);
2155 if (nextIndex > GSUB_E_NOGLYPH)
2157 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2158 shift_syllable_glyph_indexs(glyph_index, index + glyph_index->start + g_offset, (*pcGlyphs - prevCount));
2159 g_offset += (*pcGlyphs - prevCount);
2163 index = find_consonant_halant(&pwChars[syllable->start], index, count, lexical);
2167 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)
2170 INT prevCount = *pcGlyphs;
2172 if (syllable->ralf >= 0)
2174 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, glyph_index->ralf, 1, pcGlyphs, "rphf");
2175 if (nextIndex > GSUB_E_NOGLYPH)
2177 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2178 shift_syllable_glyph_indexs(glyph_index,glyph_index->ralf,*pcGlyphs - prevCount);
2183 static inline INT find_halant_consonant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2186 while (index + i < end-1 && !(lexical(pwChars[index+i]) == lex_Halant &&
2187 ((index + i < end-2 && lexical(pwChars[index+i]) == lex_Nukta && is_consonant(lexical(pwChars[index+i+1]))) ||
2188 is_consonant(lexical(pwChars[index+i+1])))))
2190 if (index + i <= end-1)
2196 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)
2198 INT index, nextIndex;
2199 INT count, g_offset=0;
2200 INT ralf = syllable->ralf;
2202 count = syllable->end - syllable->base;
2204 index = find_halant_consonant(&pwChars[syllable->base], 0, count, lexical);
2208 INT prevCount = *pcGlyphs;
2209 if (ralf >=0 && ralf < index)
2217 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
2218 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
2219 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2222 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->base+g_offset, 1, pcGlyphs, feat);
2223 if (nextIndex > GSUB_E_NOGLYPH)
2225 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2226 shift_syllable_glyph_indexs(glyph_index,index+glyph_index->start+g_offset, (*pcGlyphs - prevCount));
2227 g_offset += (*pcGlyphs - prevCount);
2231 WORD g = pwOutGlyphs[index+glyph_index->base+g_offset];
2232 pwOutGlyphs[index+glyph_index->base+g_offset] = pwOutGlyphs[index+glyph_index->base+g_offset+1];
2233 pwOutGlyphs[index+glyph_index->base+g_offset+1] = g;
2237 index = find_halant_consonant(&pwChars[syllable->base], index, count, lexical);
2241 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)
2244 int overall_shift = 0;
2245 const GSUB_Feature *locl = (modern)?load_GSUB_feature(hdc, psa, psc, "locl"):NULL;
2246 const GSUB_Feature *nukt = load_GSUB_feature(hdc, psa, psc, "nukt");
2247 const GSUB_Feature *akhn = load_GSUB_feature(hdc, psa, psc, "akhn");
2248 const GSUB_Feature *rkrf = (modern)?load_GSUB_feature(hdc, psa, psc, "rkrf"):NULL;
2249 const GSUB_Feature *pstf = load_GSUB_feature(hdc, psa, psc, "pstf");
2250 const GSUB_Feature *vatu = (!rkrf)?load_GSUB_feature(hdc, psa, psc, "vatu"):NULL;
2251 const GSUB_Feature *cjct = (modern)?load_GSUB_feature(hdc, psa, psc, "cjct"):NULL;
2252 BOOL rphf = (load_GSUB_feature(hdc, psa, psc, "rphf") != NULL);
2253 BOOL pref = (load_GSUB_feature(hdc, psa, psc, "pref") != NULL);
2254 BOOL blwf = (load_GSUB_feature(hdc, psa, psc, "blwf") != NULL);
2255 BOOL half = (load_GSUB_feature(hdc, psa, psc, "half") != NULL);
2256 IndicSyllable glyph_indexs;
2258 for (c = 0; c < syllable_count; c++)
2261 memcpy(&glyph_indexs, &syllables[c], sizeof(IndicSyllable));
2262 shift_syllable_glyph_indexs(&glyph_indexs, -1, overall_shift);
2263 old_end = glyph_indexs.end;
2267 TRACE("applying feature locl\n");
2268 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, locl);
2272 TRACE("applying feature nukt\n");
2273 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, nukt);
2277 TRACE("applying feature akhn\n");
2278 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, akhn);
2282 Apply_Indic_Rphf(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs);
2285 TRACE("applying feature rkrf\n");
2286 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, rkrf);
2289 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "pref");
2293 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "blwf");
2295 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, modern, "blwf");
2299 Apply_Indic_PreBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "half");
2302 TRACE("applying feature pstf\n");
2303 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, pstf);
2307 TRACE("applying feature vatu\n");
2308 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, vatu);
2312 TRACE("applying feature cjct\n");
2313 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, cjct);
2317 second_reorder(pwChars, &syllables[c], pwOutGlyphs, &glyph_indexs, lexical);
2319 overall_shift += glyph_indexs.end - old_end;
2323 static inline int unicode_lex(WCHAR c)
2327 if (!c) return lex_Generic;
2328 if (c == 0x200D) return lex_ZWJ;
2329 if (c == 0x200C) return lex_ZWNJ;
2330 if (c == 0x00A0) return lex_NBSP;
2332 type = get_table_entry( indic_syllabic_table, c );
2334 if ((type & 0x00ff) != 0x0007) type = type & 0x00ff;
2338 case 0x0d07: /* Unknown */
2339 case 0x0e07: /* Unknwon */
2340 default: return lex_Generic;
2346 case 0x0014: return lex_Modifier;
2354 case 0x0010: return lex_Consonant;
2355 case 0x0004: return lex_Nukta;
2356 case 0x0005: return lex_Halant;
2358 case 0x0008: return lex_Vowel;
2360 case 0x0107: return lex_Matra_post;
2362 case 0x0307: return lex_Matra_pre;
2368 case 0x0407: return lex_Composed_Vowel;
2369 case 0x0507: return lex_Matra_above;
2370 case 0x0607: return lex_Matra_below;
2371 case 0x000c: return lex_Ra;
2375 static int sinhala_lex(WCHAR c)
2382 case 0x0DDE: return lex_Matra_post;
2384 return unicode_lex(c);
2388 static const VowelComponents Sinhala_vowels[] = {
2389 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2390 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2391 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2392 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2393 {0x0000, {0x0000,0x0000,0x0}}};
2395 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2397 int cCount = cChars;
2400 IndicSyllable *syllables = NULL;
2401 int syllable_count = 0;
2403 if (*pcGlyphs != cChars)
2405 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2409 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
2411 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2413 /* Step 1: Decompose multi part vowels */
2414 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels, pwLogClust);
2416 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2418 /* Step 2: Reorder within Syllables */
2419 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, sinhala_lex, Reorder_Like_Sinhala, TRUE);
2420 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2422 /* Step 3: Strip dangling joiners */
2423 for (i = 0; i < cCount; i++)
2425 if ((input[i] == 0x200D || input[i] == 0x200C) &&
2426 (i == 0 || input[i-1] == 0x0020 || i == cCount-1 || input[i+1] == 0x0020))
2430 /* Step 4: Base Form application to syllables */
2431 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2433 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, sinhala_lex, NULL, TRUE);
2435 HeapFree(GetProcessHeap(),0,input);
2436 HeapFree(GetProcessHeap(),0,syllables);
2439 static int devanagari_lex(WCHAR c)
2443 case 0x0930: return lex_Ra;
2445 return unicode_lex(c);
2449 static const ConsonantComponents Devanagari_consonants[] ={
2450 {{0x0928, 0x093C, 0x00000}, 0x0929},
2451 {{0x0930, 0x093C, 0x00000}, 0x0931},
2452 {{0x0933, 0x093C, 0x00000}, 0x0934},
2453 {{0x0915, 0x093C, 0x00000}, 0x0958},
2454 {{0x0916, 0x093C, 0x00000}, 0x0959},
2455 {{0x0917, 0x093C, 0x00000}, 0x095A},
2456 {{0x091C, 0x093C, 0x00000}, 0x095B},
2457 {{0x0921, 0x093C, 0x00000}, 0x095C},
2458 {{0x0922, 0x093C, 0x00000}, 0x095D},
2459 {{0x092B, 0x093C, 0x00000}, 0x095E},
2460 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2462 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2464 int cCount = cChars;
2466 IndicSyllable *syllables = NULL;
2467 int syllable_count = 0;
2468 BOOL modern = get_GSUB_Indic2(psa, psc);
2470 if (*pcGlyphs != cChars)
2472 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2476 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2477 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2479 /* Step 1: Compose Consonant and Nukta */
2480 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants, pwLogClust);
2481 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2483 /* Step 2: Reorder within Syllables */
2484 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, devanagari_lex, Reorder_Like_Devanagari, modern);
2485 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2486 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2489 /* Step 3: Base Form application to syllables */
2490 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, devanagari_lex, NULL, modern);
2492 HeapFree(GetProcessHeap(),0,input);
2493 HeapFree(GetProcessHeap(),0,syllables);
2496 static int bengali_lex(WCHAR c)
2500 case 0x09B0: return lex_Ra;
2502 return unicode_lex(c);
2506 static const VowelComponents Bengali_vowels[] = {
2507 {0x09CB, {0x09C7,0x09BE,0x0000}},
2508 {0x09CC, {0x09C7,0x09D7,0x0000}},
2509 {0x0000, {0x0000,0x0000,0x0000}}};
2511 static const ConsonantComponents Bengali_consonants[] = {
2512 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2513 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2514 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2515 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2516 {{0x0000,0x0000,0x0000}, 0x0000}};
2518 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2520 int cCount = cChars;
2522 IndicSyllable *syllables = NULL;
2523 int syllable_count = 0;
2524 BOOL modern = get_GSUB_Indic2(psa, psc);
2526 if (*pcGlyphs != cChars)
2528 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2532 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2533 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2535 /* Step 1: Decompose Vowels and Compose Consonents */
2536 DecomposeVowels(hdc, input, &cCount, Bengali_vowels, pwLogClust);
2537 ComposeConsonants(hdc, input, &cCount, Bengali_consonants, pwLogClust);
2538 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2540 /* Step 2: Reorder within Syllables */
2541 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, bengali_lex, Reorder_Like_Bengali, modern);
2542 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2543 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2546 /* Step 3: Initial form is only applied to the beginning of words */
2547 for (cCount = cCount - 1 ; cCount >= 0; cCount --)
2549 if (cCount == 0 || input[cCount] == 0x0020) /* space */
2553 if (index > 0) index++;
2555 apply_GSUB_feature_to_glyph(hdc, psa, psc, &pwOutGlyphs[index], 0, 1, &gCount, "init");
2559 /* Step 4: Base Form application to syllables */
2560 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, bengali_lex, NULL, modern);
2562 HeapFree(GetProcessHeap(),0,input);
2563 HeapFree(GetProcessHeap(),0,syllables);
2566 static int gurmukhi_lex(WCHAR c)
2568 return unicode_lex(c);
2571 static const ConsonantComponents Gurmukhi_consonants[] = {
2572 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2573 {{0x0A38,0x0A3C,0x0000}, 0x0A36},
2574 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2575 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2576 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2577 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2578 {{0x0000,0x0000,0x0000}, 0x0000}};
2580 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2582 int cCount = cChars;
2584 IndicSyllable *syllables = NULL;
2585 int syllable_count = 0;
2586 BOOL modern = get_GSUB_Indic2(psa, psc);
2588 if (*pcGlyphs != cChars)
2590 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2594 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2595 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2597 /* Step 1: Compose Consonents */
2598 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants, pwLogClust);
2599 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2601 /* Step 2: Reorder within Syllables */
2602 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gurmukhi_lex, Reorder_Like_Bengali, modern);
2603 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2604 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2607 /* Step 3: Base Form application to syllables */
2608 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gurmukhi_lex, NULL, modern);
2610 HeapFree(GetProcessHeap(),0,input);
2611 HeapFree(GetProcessHeap(),0,syllables);
2614 static int gujarati_lex(WCHAR c)
2618 case 0x0AB0: return lex_Ra;
2620 return unicode_lex(c);
2624 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2626 int cCount = cChars;
2628 IndicSyllable *syllables = NULL;
2629 int syllable_count = 0;
2630 BOOL modern = get_GSUB_Indic2(psa, psc);
2632 if (*pcGlyphs != cChars)
2634 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2638 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2639 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2641 /* Step 1: Reorder within Syllables */
2642 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gujarati_lex, Reorder_Like_Devanagari, modern);
2643 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2644 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2647 /* Step 2: Base Form application to syllables */
2648 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gujarati_lex, NULL, modern);
2650 HeapFree(GetProcessHeap(),0,input);
2651 HeapFree(GetProcessHeap(),0,syllables);
2654 static int oriya_lex(WCHAR c)
2658 case 0x0B30: return lex_Ra;
2660 return unicode_lex(c);
2664 static const VowelComponents Oriya_vowels[] = {
2665 {0x0B48, {0x0B47,0x0B56,0x0000}},
2666 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2667 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2668 {0x0000, {0x0000,0x0000,0x0000}}};
2670 static const ConsonantComponents Oriya_consonants[] = {
2671 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2672 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2673 {{0x0000,0x0000,0x0000}, 0x0000}};
2675 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2677 int cCount = cChars;
2679 IndicSyllable *syllables = NULL;
2680 int syllable_count = 0;
2681 BOOL modern = get_GSUB_Indic2(psa, psc);
2683 if (*pcGlyphs != cChars)
2685 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2689 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2690 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2692 /* Step 1: Decompose Vowels and Compose Consonents */
2693 DecomposeVowels(hdc, input, &cCount, Oriya_vowels, pwLogClust);
2694 ComposeConsonants(hdc, input, &cCount, Oriya_consonants, pwLogClust);
2695 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2697 /* Step 2: Reorder within Syllables */
2698 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, oriya_lex, Reorder_Like_Bengali, modern);
2699 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2700 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2703 /* Step 3: Base Form application to syllables */
2704 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, oriya_lex, NULL, modern);
2706 HeapFree(GetProcessHeap(),0,input);
2707 HeapFree(GetProcessHeap(),0,syllables);
2710 static int tamil_lex(WCHAR c)
2712 return unicode_lex(c);
2715 static const VowelComponents Tamil_vowels[] = {
2716 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2717 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2718 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2719 {0x0000, {0x0000,0x0000,0x0000}}};
2721 static const ConsonantComponents Tamil_consonants[] = {
2722 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2723 {{0x0000,0x0000,0x0000}, 0x0000}};
2725 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2727 int cCount = cChars;
2729 IndicSyllable *syllables = NULL;
2730 int syllable_count = 0;
2731 BOOL modern = get_GSUB_Indic2(psa, psc);
2733 if (*pcGlyphs != cChars)
2735 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2739 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2740 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2742 /* Step 1: Decompose Vowels and Compose Consonents */
2743 DecomposeVowels(hdc, input, &cCount, Tamil_vowels, pwLogClust);
2744 ComposeConsonants(hdc, input, &cCount, Tamil_consonants, pwLogClust);
2745 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2747 /* Step 2: Reorder within Syllables */
2748 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, tamil_lex, Reorder_Like_Bengali, modern);
2749 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2750 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2753 /* Step 3: Base Form application to syllables */
2754 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, tamil_lex, SecondReorder_Like_Tamil, modern);
2756 HeapFree(GetProcessHeap(),0,input);
2757 HeapFree(GetProcessHeap(),0,syllables);
2760 static int telugu_lex(WCHAR c)
2765 case 0x0C44: return lex_Modifier;
2767 return unicode_lex(c);
2771 static const VowelComponents Telugu_vowels[] = {
2772 {0x0C48, {0x0C46,0x0C56,0x0000}},
2773 {0x0000, {0x0000,0x0000,0x0000}}};
2775 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2777 int cCount = cChars;
2779 IndicSyllable *syllables = NULL;
2780 int syllable_count = 0;
2781 BOOL modern = get_GSUB_Indic2(psa, psc);
2783 if (*pcGlyphs != cChars)
2785 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2789 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2790 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2792 /* Step 1: Decompose Vowels */
2793 DecomposeVowels(hdc, input, &cCount, Telugu_vowels, pwLogClust);
2794 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2796 /* Step 2: Reorder within Syllables */
2797 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, telugu_lex, Reorder_Like_Bengali, modern);
2798 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2799 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2802 /* Step 3: Base Form application to syllables */
2803 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, telugu_lex, SecondReorder_Like_Telugu, modern);
2805 HeapFree(GetProcessHeap(),0,input);
2806 HeapFree(GetProcessHeap(),0,syllables);
2809 static int kannada_lex(WCHAR c)
2813 case 0x0CB0: return lex_Ra;
2815 return unicode_lex(c);
2819 static const VowelComponents Kannada_vowels[] = {
2820 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2821 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2822 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2823 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2824 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2825 {0x0000, {0x0000,0x0000,0x0000}}};
2827 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2829 int cCount = cChars;
2831 IndicSyllable *syllables = NULL;
2832 int syllable_count = 0;
2833 BOOL modern = get_GSUB_Indic2(psa, psc);
2835 if (*pcGlyphs != cChars)
2837 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2841 input = HeapAlloc(GetProcessHeap(), 0, (cChars*3) * sizeof(WCHAR));
2842 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2844 /* Step 1: Decompose Vowels */
2845 DecomposeVowels(hdc, input, &cCount, Kannada_vowels, pwLogClust);
2846 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2848 /* Step 2: Reorder within Syllables */
2849 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, kannada_lex, Reorder_Like_Kannada, modern);
2850 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2851 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2854 /* Step 3: Base Form application to syllables */
2855 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, kannada_lex, SecondReorder_Like_Telugu, modern);
2857 HeapFree(GetProcessHeap(),0,input);
2858 HeapFree(GetProcessHeap(),0,syllables);
2861 static int malayalam_lex(WCHAR c)
2863 return unicode_lex(c);
2866 static const VowelComponents Malayalam_vowels[] = {
2867 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2868 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2869 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2870 {0x0000, {0x0000,0x0000,0x0000}}};
2872 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2874 int cCount = cChars;
2876 IndicSyllable *syllables = NULL;
2877 int syllable_count = 0;
2878 BOOL modern = get_GSUB_Indic2(psa, psc);
2880 if (*pcGlyphs != cChars)
2882 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2886 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2887 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2889 /* Step 1: Decompose Vowels */
2890 DecomposeVowels(hdc, input, &cCount, Malayalam_vowels, pwLogClust);
2891 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2893 /* Step 2: Reorder within Syllables */
2894 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, malayalam_lex, Reorder_Like_Devanagari, modern);
2895 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2896 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2899 /* Step 3: Base Form application to syllables */
2900 ShapeIndicSyllables(hdc, psc, psa, input, cChars, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, malayalam_lex, SecondReorder_Like_Tamil, modern);
2902 HeapFree(GetProcessHeap(),0,input);
2903 HeapFree(GetProcessHeap(),0,syllables);
2906 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)
2910 for (i = 0; i < cGlyphs; i++)
2915 for (k = 0; k < cChars; k++)
2917 if (pwLogClust[k] == i)
2919 char_index[char_count] = k;
2924 if (char_count == 0)
2926 FIXME("No chars in this glyph? Must be an error\n");
2930 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2932 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2933 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2936 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2939 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2940 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2943 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 )
2946 int initGlyph, finaGlyph;
2950 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2951 memset(spaces,0,cGlyphs);
2953 if (!psa->fLogicalOrder && psa->fRTL)
2955 initGlyph = cGlyphs-1;
2963 finaGlyph = cGlyphs-1;
2968 for (i = 0; i < cGlyphs; i++)
2970 for (k = 0; k < cChars; k++)
2971 if (pwLogClust[k] == i)
2973 if (pwcChars[k] == 0x0020)
2978 for (i = 0; i < cGlyphs; i++)
2982 BOOL isInit, isFinal;
2984 for (k = 0; k < cChars; k++)
2986 if (pwLogClust[k] == i)
2988 char_index[char_count] = k;
2993 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
2994 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
2996 if (char_count == 0)
2998 FIXME("No chars in this glyph? Must be an error\n");
3002 if (char_count == 1)
3004 if (pwcChars[char_index[0]] == 0x0020) /* space */
3006 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
3007 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3009 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
3010 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
3011 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
3013 if (!isInit && !isFinal)
3014 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
3016 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
3018 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3022 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
3023 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
3024 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
3025 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
3026 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
3027 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
3028 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
3029 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
3031 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3033 else if (!isInit && !isFinal)
3034 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3036 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3038 else if (char_count == 2)
3040 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
3041 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
3043 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3045 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3047 else if (!isInit && !isFinal)
3048 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3050 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3053 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3054 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3055 HeapFree(GetProcessHeap(),0,spaces);
3058 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 )
3065 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
3066 memset(spaces,0,cGlyphs);
3068 if (!psa->fLogicalOrder && psa->fRTL)
3075 finaGlyph = cGlyphs-1;
3079 for (i = 0; i < cGlyphs; i++)
3081 for (k = 0; k < cChars; k++)
3082 if (pwLogClust[k] == i)
3084 if (pwcChars[k] == 0x0020)
3089 for (i = 0; i < cGlyphs; i++)
3094 for (k = 0; k < cChars; k++)
3096 if (pwLogClust[k] == i)
3098 char_index[char_count] = k;
3103 if (char_count == 0)
3105 FIXME("No chars in this glyph? Must be an error\n");
3109 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3111 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3112 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3114 else if (i == finaGlyph)
3115 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3117 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3120 HeapFree(GetProcessHeap(),0,spaces);
3121 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3122 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3124 /* Do not allow justification between marks and their base */
3125 for (i = 0; i < cGlyphs; i++)
3127 if (!pGlyphProp[i].sva.fClusterStart)
3128 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3132 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)
3136 for (i = 0; i < cGlyphs; i++)
3141 for (k = 0; k < cChars; k++)
3143 if (pwLogClust[k] == i)
3145 char_index[char_count] = k;
3150 if (char_count == 0)
3152 FIXME("No chars in this glyph? Must be an error\n");
3156 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3158 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3159 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3162 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3164 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3165 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3168 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)
3172 for (i = 0; i < cGlyphs; i++)
3177 for (k = 0; k < cChars; k++)
3179 if (pwLogClust[k] == i)
3181 char_index[char_count] = k;
3186 if (char_count == 0)
3188 FIXME("No chars in this glyph? Must be an error\n");
3192 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3194 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3195 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3198 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3200 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3201 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3203 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3204 for (i = 0; i < cGlyphs; i++)
3206 if (!pGlyphProp[i].sva.fClusterStart)
3208 pGlyphProp[i].sva.fDiacritic = 0;
3209 pGlyphProp[i].sva.fZeroWidth = 0;
3214 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)
3217 IndicSyllable *syllables = NULL;
3218 int syllable_count = 0;
3219 BOOL modern = get_GSUB_Indic2(psa, psc);
3221 for (i = 0; i < cGlyphs; i++)
3226 for (k = 0; k < cChars; k++)
3228 if (pwLogClust[k] == i)
3230 char_index[char_count] = k;
3235 if (char_count == 0)
3237 FIXME("No chars in this glyph? Must be an error\n");
3241 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3243 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3244 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3247 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3249 pGlyphProp[i].sva.fClusterStart = 0;
3250 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
3251 switch (lexical(pwcChars[char_index[k]]))
3254 case lex_Matra_post:
3255 case lex_Matra_above:
3256 case lex_Matra_below:
3260 pGlyphProp[i].sva.fClusterStart = 1;
3265 Indic_ParseSyllables( hdc, psa, psc, pwcChars, cChars, &syllables, &syllable_count, lexical, modern);
3267 for (i = 0; i < syllable_count; i++)
3270 WORD g = pwLogClust[syllables[i].start];
3271 for (j = syllables[i].start+1; j <= syllables[i].end; j++)
3273 if (pwLogClust[j] != g)
3275 pGlyphProp[pwLogClust[j]].sva.fClusterStart = 0;
3281 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3282 HeapFree(GetProcessHeap(), 0, syllables);
3285 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 )
3287 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, sinhala_lex);
3290 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 )
3292 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex);
3295 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 )
3297 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex);
3300 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 )
3302 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex);
3305 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 )
3307 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex);
3310 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 )
3312 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex);
3315 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 )
3317 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, tamil_lex);
3320 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 )
3322 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, telugu_lex);
3325 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 )
3327 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, kannada_lex);
3330 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 )
3332 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, malayalam_lex);
3335 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)
3337 if (ShapingData[psa->eScript].charGlyphPropProc)
3338 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3340 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3343 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
3345 if (ShapingData[psa->eScript].contextProc)
3346 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
3349 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)
3354 if (!rpRangeProperties)
3357 if (!psc->GSUB_Table)
3358 psc->GSUB_Table = load_gsub_table(hdc);
3360 if (!psc->GSUB_Table)
3363 if (!psa->fLogicalOrder && psa->fRTL)
3368 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3370 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3371 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
3375 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
3377 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3378 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
3380 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
3383 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
3385 const GSUB_Feature *feature;
3388 if (!ShapingData[psa->eScript].requiredFeatures)
3391 if (!psc->GSUB_Table)
3392 psc->GSUB_Table = load_gsub_table(hdc);
3394 /* we need to have at least one of the required features */
3396 while (ShapingData[psa->eScript].requiredFeatures[i])
3398 feature = load_GSUB_feature(hdc, psa, psc, ShapingData[psa->eScript].requiredFeatures[i]);
3404 return USP_E_SCRIPT_NOT_IN_FONT;