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_Devanagari( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
65 static void ShapeCharGlyphProp_Bengali( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
66 static void ShapeCharGlyphProp_Gurmukhi( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
67 static void ShapeCharGlyphProp_Gujarati( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
68 static void ShapeCharGlyphProp_Oriya( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
69 static void ShapeCharGlyphProp_Tamil( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
70 static void ShapeCharGlyphProp_Telugu( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
71 static void ShapeCharGlyphProp_Kannada( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
72 static void ShapeCharGlyphProp_Malayalam( HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, const WCHAR* pwcChars, const INT cChars, const WORD* pwGlyphs, const INT cGlyphs, WORD *pwLogClust, SCRIPT_CHARPROP *pCharProp, SCRIPT_GLYPHPROP *pGlyphProp );
74 extern const unsigned short wine_shaping_table[];
75 extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
97 #ifdef WORDS_BIGENDIAN
98 #define GET_BE_WORD(x) (x)
100 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
103 /* These are all structures needed for the GSUB table */
104 #define GSUB_TAG MS_MAKE_TAG('G', 'S', 'U', 'B')
105 #define GSUB_E_NOFEATURE -2
106 #define GSUB_E_NOGLYPH -1
122 GSUB_ScriptRecord ScriptRecord[1];
128 } GSUB_LangSysRecord;
133 GSUB_LangSysRecord LangSysRecord[1];
137 WORD LookupOrder; /* Reserved */
138 WORD ReqFeatureIndex;
140 WORD FeatureIndex[1];
146 } GSUB_FeatureRecord;
150 GSUB_FeatureRecord FeatureRecord[1];
154 WORD FeatureParams; /* Reserved */
156 WORD LookupListIndex[1];
175 } GSUB_CoverageFormat1;
180 WORD StartCoverageIndex;
186 GSUB_RangeRecord RangeRecord[1];
187 } GSUB_CoverageFormat2;
190 WORD SubstFormat; /* = 1 */
193 } GSUB_SingleSubstFormat1;
196 WORD SubstFormat; /* = 2 */
200 }GSUB_SingleSubstFormat2;
203 WORD SubstFormat; /* = 1 */
207 }GSUB_LigatureSubstFormat1;
222 WORD LookupListIndex;
224 }GSUB_SubstLookupRecord;
227 WORD SubstFormat; /* = 1 */
229 WORD ChainSubRuleSetCount;
230 WORD ChainSubRuleSet[1];
231 }GSUB_ChainContextSubstFormat1;
234 WORD SubstFormat; /* = 3 */
235 WORD BacktrackGlyphCount;
237 }GSUB_ChainContextSubstFormat3_1;
240 WORD InputGlyphCount;
242 }GSUB_ChainContextSubstFormat3_2;
245 WORD LookaheadGlyphCount;
247 }GSUB_ChainContextSubstFormat3_3;
251 GSUB_SubstLookupRecord SubstLookupRecord[1];
252 }GSUB_ChainContextSubstFormat3_4;
255 WORD SubstFormat; /* = 1 */
257 WORD AlternateSetCount;
258 WORD AlternateSet[1];
259 } GSUB_AlternateSubstFormat1;
266 /* These are all structures needed for the GDEF table */
267 #define GDEF_TAG MS_MAKE_TAG('G', 'D', 'E', 'F')
269 enum {BaseGlyph=1, LigatureGlyph, MarkGlyph, ComponentGlyph};
276 WORD MarkAttachClassDef;
283 WORD ClassValueArray[1];
284 } GDEF_ClassDefFormat1;
290 } GDEF_ClassRangeRecord;
294 WORD ClassRangeCount;
295 GDEF_ClassRangeRecord ClassRangeRecord[1];
296 } GDEF_ClassDefFormat2;
298 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count);
300 typedef struct tagVowelComponents
306 typedef struct tagConsonantComponents
310 } ConsonantComponents;
312 /* the orders of joined_forms and contextual_features need to line up */
313 static const char* contextual_features[] =
325 static OPENTYPE_FEATURE_RECORD standard_features[] =
327 { MS_MAKE_TAG('l','i','g','a'), 1},
328 { MS_MAKE_TAG('c','l','i','g'), 1},
331 static OPENTYPE_FEATURE_RECORD arabic_features[] =
333 { MS_MAKE_TAG('r','l','i','g'), 1},
334 { MS_MAKE_TAG('c','a','l','t'), 1},
335 { MS_MAKE_TAG('l','i','g','a'), 1},
336 { MS_MAKE_TAG('d','l','i','g'), 1},
337 { MS_MAKE_TAG('c','s','w','h'), 1},
338 { MS_MAKE_TAG('m','s','e','t'), 1},
341 static const char* required_arabic_features[] =
350 static OPENTYPE_FEATURE_RECORD hebrew_features[] =
352 { MS_MAKE_TAG('d','l','i','g'), 1},
355 static OPENTYPE_FEATURE_RECORD syriac_features[] =
357 { MS_MAKE_TAG('r','l','i','g'), 1},
358 { MS_MAKE_TAG('c','a','l','t'), 1},
359 { MS_MAKE_TAG('l','i','g','a'), 1},
360 { MS_MAKE_TAG('d','l','i','g'), 1},
363 static const char* required_syriac_features[] =
375 static OPENTYPE_FEATURE_RECORD sinhala_features[] =
378 { MS_MAKE_TAG('v','a','t','u'), 1},
379 { MS_MAKE_TAG('p','s','t','f'), 1},
380 /* Presentation forms */
381 { MS_MAKE_TAG('b','l','w','s'), 1},
382 { MS_MAKE_TAG('a','b','v','s'), 1},
383 { MS_MAKE_TAG('p','s','t','s'), 1},
386 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
388 { MS_MAKE_TAG('a','b','v','s'), 1},
389 { MS_MAKE_TAG('b','l','w','s'), 1},
392 static OPENTYPE_FEATURE_RECORD thai_features[] =
394 { MS_MAKE_TAG('c','c','m','p'), 1},
397 static const char* required_lao_features[] =
403 static const char* required_devanagari_features[] =
419 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
422 { MS_MAKE_TAG('v','a','t','u'), 1},
423 { MS_MAKE_TAG('c','j','c','t'), 1},
424 /* Presentation forms */
425 { MS_MAKE_TAG('p','r','e','s'), 1},
426 { MS_MAKE_TAG('a','b','v','s'), 1},
427 { MS_MAKE_TAG('b','l','w','s'), 1},
428 { MS_MAKE_TAG('p','s','t','s'), 1},
429 { MS_MAKE_TAG('h','a','l','n'), 1},
430 { MS_MAKE_TAG('c','a','l','t'), 1},
433 static const char* required_bengali_features[] =
450 static OPENTYPE_FEATURE_RECORD bengali_features[] =
453 { MS_MAKE_TAG('p','s','t','f'), 1},
454 { MS_MAKE_TAG('v','a','t','u'), 1},
455 { MS_MAKE_TAG('c','j','c','t'), 1},
456 /* Presentation forms */
457 { MS_MAKE_TAG('p','r','e','s'), 1},
458 { MS_MAKE_TAG('a','b','v','s'), 1},
459 { MS_MAKE_TAG('b','l','w','s'), 1},
460 { MS_MAKE_TAG('p','s','t','s'), 1},
461 { MS_MAKE_TAG('h','a','l','n'), 1},
462 { MS_MAKE_TAG('c','a','l','t'), 1},
465 static const char* required_gurmukhi_features[] =
484 static OPENTYPE_FEATURE_RECORD gurmukhi_features[] =
487 { MS_MAKE_TAG('p','s','t','f'), 1},
488 { MS_MAKE_TAG('v','a','t','u'), 1},
489 { MS_MAKE_TAG('c','j','c','t'), 1},
490 /* Presentation forms */
491 { MS_MAKE_TAG('p','r','e','s'), 1},
492 { MS_MAKE_TAG('a','b','v','s'), 1},
493 { MS_MAKE_TAG('b','l','w','s'), 1},
494 { MS_MAKE_TAG('p','s','t','s'), 1},
495 { MS_MAKE_TAG('h','a','l','n'), 1},
496 { MS_MAKE_TAG('c','a','l','t'), 1},
499 static const char* required_oriya_features[] =
516 static OPENTYPE_FEATURE_RECORD oriya_features[] =
519 { MS_MAKE_TAG('p','s','t','f'), 1},
520 { MS_MAKE_TAG('c','j','c','t'), 1},
521 /* Presentation forms */
522 { MS_MAKE_TAG('p','r','e','s'), 1},
523 { MS_MAKE_TAG('a','b','v','s'), 1},
524 { MS_MAKE_TAG('b','l','w','s'), 1},
525 { MS_MAKE_TAG('p','s','t','s'), 1},
526 { MS_MAKE_TAG('h','a','l','n'), 1},
527 { MS_MAKE_TAG('c','a','l','t'), 1},
530 static const char* required_tamil_features[] =
546 static OPENTYPE_FEATURE_RECORD tamil_features[] =
548 /* Presentation forms */
549 { MS_MAKE_TAG('p','r','e','s'), 1},
550 { MS_MAKE_TAG('a','b','v','s'), 1},
551 { MS_MAKE_TAG('b','l','w','s'), 1},
552 { MS_MAKE_TAG('p','s','t','s'), 1},
553 { MS_MAKE_TAG('h','a','l','n'), 1},
554 { MS_MAKE_TAG('c','a','l','t'), 1},
557 static const char* required_telugu_features[] =
575 static OPENTYPE_FEATURE_RECORD telugu_features[] =
578 { MS_MAKE_TAG('p','s','t','f'), 1},
579 { MS_MAKE_TAG('c','j','c','t'), 1},
580 /* Presentation forms */
581 { MS_MAKE_TAG('p','r','e','s'), 1},
582 { MS_MAKE_TAG('a','b','v','s'), 1},
583 { MS_MAKE_TAG('b','l','w','s'), 1},
584 { MS_MAKE_TAG('p','s','t','s'), 1},
585 { MS_MAKE_TAG('h','a','l','n'), 1},
586 { MS_MAKE_TAG('c','a','l','t'), 1},
589 typedef struct ScriptShapeDataTag {
590 TEXTRANGE_PROPERTIES defaultTextRange;
591 const char** requiredFeatures;
594 ContextualShapingProc contextProc;
595 ShapeCharGlyphPropProc charGlyphPropProc;
598 /* in order of scripts */
599 static const ScriptShapeData ShapingData[] =
601 {{ standard_features, 2}, NULL, "", "", NULL, NULL},
602 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
603 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
604 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
605 {{ standard_features, 2}, NULL, "" , "", NULL, NULL},
606 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
607 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
608 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
609 {{ hebrew_features, 1}, NULL, "hebr", "", NULL, NULL},
610 {{ syriac_features, 4}, required_syriac_features, "syrc", "", ContextualShape_Syriac, ShapeCharGlyphProp_None},
611 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
612 {{ NULL, 0}, NULL, "thaa", "", NULL, ShapeCharGlyphProp_None},
613 {{ standard_features, 2}, NULL, "grek", "", NULL, NULL},
614 {{ standard_features, 2}, NULL, "cyrl", "", NULL, NULL},
615 {{ standard_features, 2}, NULL, "armn", "", NULL, NULL},
616 {{ standard_features, 2}, NULL, "geor", "", NULL, NULL},
617 {{ sinhala_features, 5}, NULL, "sinh", "", ContextualShape_Sinhala, NULL},
618 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
619 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
620 {{ tibetan_features, 2}, NULL, "phag", "", ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
621 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
622 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
623 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
624 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
625 {{ devanagari_features, 8}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
626 {{ devanagari_features, 8}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
627 {{ bengali_features, 9}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
628 {{ bengali_features, 9}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
629 {{ gurmukhi_features, 9}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
630 {{ gurmukhi_features, 9}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
631 {{ devanagari_features, 8}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
632 {{ devanagari_features, 8}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
633 {{ devanagari_features, 8}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
634 {{ oriya_features, 8}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
635 {{ oriya_features, 8}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
636 {{ tamil_features, 6}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
637 {{ tamil_features, 6}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
638 {{ telugu_features, 8}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
639 {{ telugu_features, 8}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
640 {{ telugu_features, 8}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
641 {{ telugu_features, 8}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
642 {{ telugu_features, 8}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
643 {{ telugu_features, 8}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
646 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
648 const GSUB_CoverageFormat1* cf1;
652 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
654 int count = GET_BE_WORD(cf1->GlyphCount);
656 TRACE("Coverage Format 1, %i glyphs\n",count);
657 for (i = 0; i < count; i++)
658 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
662 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
664 const GSUB_CoverageFormat2* cf2;
667 cf2 = (const GSUB_CoverageFormat2*)cf1;
669 count = GET_BE_WORD(cf2->RangeCount);
670 TRACE("Coverage Format 2, %i ranges\n",count);
671 for (i = 0; i < count; i++)
673 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
675 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
676 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
678 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
679 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
685 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
690 static const GSUB_Script* GSUB_get_script_table( const GSUB_Header* header, const char* tag)
692 const GSUB_ScriptList *script;
693 const GSUB_Script *deflt = NULL;
695 script = (const GSUB_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
697 TRACE("%i scripts in this font\n",GET_BE_WORD(script->ScriptCount));
698 for (i = 0; i < GET_BE_WORD(script->ScriptCount); i++)
700 const GSUB_Script *scr;
703 offset = GET_BE_WORD(script->ScriptRecord[i].Script);
704 scr = (const GSUB_Script*)((const BYTE*)script + offset);
706 if (strncmp(script->ScriptRecord[i].ScriptTag, tag,4)==0)
708 if (strncmp(script->ScriptRecord[i].ScriptTag, "dflt",4)==0)
714 static const GSUB_LangSys* GSUB_get_lang_table( const GSUB_Script* script, const char* tag)
718 const GSUB_LangSys *Lang;
720 TRACE("Deflang %x, LangCount %i\n",GET_BE_WORD(script->DefaultLangSys), GET_BE_WORD(script->LangSysCount));
722 for (i = 0; i < GET_BE_WORD(script->LangSysCount) ; i++)
724 offset = GET_BE_WORD(script->LangSysRecord[i].LangSys);
725 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
727 if ( strncmp(script->LangSysRecord[i].LangSysTag,tag,4)==0)
730 offset = GET_BE_WORD(script->DefaultLangSys);
733 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
739 static const GSUB_Feature * GSUB_get_feature(const GSUB_Header *header, const GSUB_LangSys *lang, const char* tag)
742 const GSUB_FeatureList *feature;
743 feature = (const GSUB_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
745 TRACE("%i features\n",GET_BE_WORD(lang->FeatureCount));
746 for (i = 0; i < GET_BE_WORD(lang->FeatureCount); i++)
748 int index = GET_BE_WORD(lang->FeatureIndex[i]);
749 if (strncmp(feature->FeatureRecord[index].FeatureTag,tag,4)==0)
751 const GSUB_Feature *feat;
752 feat = (const GSUB_Feature*)((const BYTE*)feature + GET_BE_WORD(feature->FeatureRecord[index].Feature));
759 static INT GSUB_apply_SingleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
762 TRACE("Single Substitution Subtable\n");
764 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
767 const GSUB_SingleSubstFormat1 *ssf1;
768 offset = GET_BE_WORD(look->SubTable[j]);
769 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
770 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
772 int offset = GET_BE_WORD(ssf1->Coverage);
773 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
774 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
776 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
777 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
778 TRACE(" 0x%x\n",glyphs[glyph_index]);
779 return glyph_index + 1;
784 const GSUB_SingleSubstFormat2 *ssf2;
788 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
789 offset = GET_BE_WORD(ssf1->Coverage);
790 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
791 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
792 TRACE(" Coverage index %i\n",index);
795 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
796 return GSUB_E_NOGLYPH;
798 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
799 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
800 TRACE("0x%x\n",glyphs[glyph_index]);
801 return glyph_index + 1;
805 return GSUB_E_NOGLYPH;
808 static INT GSUB_apply_AlternateSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
811 TRACE("Alternate Substitution Subtable\n");
813 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
816 const GSUB_AlternateSubstFormat1 *asf1;
819 offset = GET_BE_WORD(look->SubTable[j]);
820 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
821 offset = GET_BE_WORD(asf1->Coverage);
823 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
826 const GSUB_AlternateSet *as;
827 offset = GET_BE_WORD(asf1->AlternateSet[index]);
828 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
829 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
830 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
831 return GSUB_E_NOGLYPH;
833 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
834 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
835 TRACE(" 0x%x\n",glyphs[glyph_index]);
836 return glyph_index + 1;
839 return GSUB_E_NOGLYPH;
842 static INT GSUB_apply_LigatureSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
846 TRACE("Ligature Substitution Subtable\n");
847 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
849 const GSUB_LigatureSubstFormat1 *lsf1;
852 offset = GET_BE_WORD(look->SubTable[j]);
853 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
854 offset = GET_BE_WORD(lsf1->Coverage);
855 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
856 TRACE(" Coverage index %i\n",index);
859 const GSUB_LigatureSet *ls;
862 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
863 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
864 count = GET_BE_WORD(ls->LigatureCount);
865 TRACE(" LigatureSet has %i members\n",count);
866 for (k = 0; k < count; k++)
868 const GSUB_Ligature *lig;
869 int CompCount,l,CompIndex;
871 offset = GET_BE_WORD(ls->Ligature[k]);
872 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
873 CompCount = GET_BE_WORD(lig->CompCount) - 1;
874 CompIndex = glyph_index+write_dir;
875 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
878 CompGlyph = GET_BE_WORD(lig->Component[l]);
879 if (CompGlyph != glyphs[CompIndex])
881 CompIndex += write_dir;
885 int replaceIdx = glyph_index;
887 replaceIdx = glyph_index - CompCount;
889 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
890 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
891 TRACE("0x%x\n",glyphs[replaceIdx]);
895 for (j = replaceIdx + 1; j < *glyph_count; j++)
896 glyphs[j] =glyphs[j+CompCount];
897 *glyph_count = *glyph_count - CompCount;
899 return replaceIdx + 1;
904 return GSUB_E_NOGLYPH;
907 static INT GSUB_apply_ChainContextSubst(const GSUB_LookupList* lookup, const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
912 TRACE("Chaining Contextual Substitution Subtable\n");
913 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
915 const GSUB_ChainContextSubstFormat1 *ccsf1;
917 int dirLookahead = write_dir;
918 int dirBacktrack = -1 * write_dir;
920 offset = GET_BE_WORD(look->SubTable[j]);
921 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
922 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
924 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
927 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
929 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
932 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
936 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
937 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
938 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
939 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
940 int newIndex = glyph_index;
942 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
944 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
946 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
948 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
949 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
952 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
954 TRACE("Matched Backtrack\n");
956 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)(((LPBYTE)ccsf1)+sizeof(GSUB_ChainContextSubstFormat3_1) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)-1)));
958 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
959 for (k = 0; k < indexGlyphs; k++)
961 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
962 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
965 if (k != indexGlyphs)
967 TRACE("Matched IndexGlyphs\n");
969 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)(((LPBYTE)ccsf3_2)+sizeof(GSUB_ChainContextSubstFormat3_2) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_2->InputGlyphCount)-1)));
971 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
973 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
974 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
977 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
979 TRACE("Matched LookAhead\n");
981 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)(((LPBYTE)ccsf3_3)+sizeof(GSUB_ChainContextSubstFormat3_3) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)-1)));
983 if (GET_BE_WORD(ccsf3_4->SubstCount))
985 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
987 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
988 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
990 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
991 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
994 ERR("Chain failed to generate a glyph\n");
1000 else return GSUB_E_NOGLYPH;
1006 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1009 const GSUB_LookupTable *look;
1011 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1012 look = (const GSUB_LookupTable*)((const BYTE*)lookup + offset);
1013 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1014 switch(GET_BE_WORD(look->LookupType))
1017 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1019 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1021 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1023 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
1025 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1027 return GSUB_E_NOGLYPH;
1030 static INT GSUB_apply_feature(const GSUB_Header * header, const GSUB_Feature* feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1033 int out_index = GSUB_E_NOGLYPH;
1034 const GSUB_LookupList *lookup;
1036 lookup = (const GSUB_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1038 TRACE("%i lookups\n", GET_BE_WORD(feature->LookupCount));
1039 for (i = 0; i < GET_BE_WORD(feature->LookupCount); i++)
1041 out_index = GSUB_apply_lookup(lookup, GET_BE_WORD(feature->LookupListIndex[i]), glyphs, glyph_index, write_dir, glyph_count);
1042 if (out_index != GSUB_E_NOGLYPH)
1045 if (out_index == GSUB_E_NOGLYPH)
1046 TRACE("lookups found no glyphs\n");
1050 out2 = GSUB_apply_feature(header, feature, glyphs, glyph_index, write_dir, glyph_count);
1051 if (out2!=GSUB_E_NOGLYPH)
1057 static const char* get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
1061 if (psc->userScript != 0)
1063 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0 && strncmp((char*)&psc->userScript,ShapingData[psa->eScript].otTag,4)==0)
1064 return ShapingData[psa->eScript].newOtTag;
1066 return (char*)&psc->userScript;
1069 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0)
1070 return ShapingData[psa->eScript].newOtTag;
1072 if (ShapingData[psa->eScript].otTag[0] != 0)
1073 return ShapingData[psa->eScript].otTag;
1076 * fall back to the font charset
1078 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
1081 case ANSI_CHARSET: return "latn";
1082 case BALTIC_CHARSET: return "latn"; /* ?? */
1083 case CHINESEBIG5_CHARSET: return "hani";
1084 case EASTEUROPE_CHARSET: return "latn"; /* ?? */
1085 case GB2312_CHARSET: return "hani";
1086 case GREEK_CHARSET: return "grek";
1087 case HANGUL_CHARSET: return "hang";
1088 case RUSSIAN_CHARSET: return "cyrl";
1089 case SHIFTJIS_CHARSET: return "kana";
1090 case TURKISH_CHARSET: return "latn"; /* ?? */
1091 case VIETNAMESE_CHARSET: return "latn";
1092 case JOHAB_CHARSET: return "latn"; /* ?? */
1093 case ARABIC_CHARSET: return "arab";
1094 case HEBREW_CHARSET: return "hebr";
1095 case THAI_CHARSET: return "thai";
1096 default: return "latn";
1100 static LPCVOID load_GSUB_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, const char* feat)
1102 const GSUB_Feature *feature;
1105 for (i = 0; i < psc->feature_count; i++)
1106 if (strncmp(psc->features[i].tag,feat,4)==0)
1107 return psc->features[i].feature;
1111 if (psc->GSUB_Table)
1113 const GSUB_Script *script;
1114 const GSUB_LangSys *language;
1119 script = GSUB_get_script_table(psc->GSUB_Table, get_opentype_script(hdc,psa,psc,(attempt==2)));
1123 if (psc->userLang != 0)
1124 language = GSUB_get_lang_table(script,(char*)&psc->userLang);
1126 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1128 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1130 } while(attempt && !feature);
1132 /* try in the default (latin) table */
1135 script = GSUB_get_script_table(psc->GSUB_Table, "latn");
1138 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1140 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1145 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
1147 psc->feature_count++;
1150 psc->features = HeapReAlloc(GetProcessHeap(), 0, psc->features, psc->feature_count * sizeof(LoadedFeature));
1152 psc->features = HeapAlloc(GetProcessHeap(), 0, psc->feature_count * sizeof(LoadedFeature));
1154 lstrcpynA(psc->features[psc->feature_count - 1].tag, feat, 5);
1155 psc->features[psc->feature_count - 1].feature = feature;
1159 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)
1161 const GSUB_Feature *feature;
1163 feature = load_GSUB_feature(hdc, psa, psc, feat);
1165 return GSUB_E_NOFEATURE;
1167 TRACE("applying feature %s\n",feat);
1168 return GSUB_apply_feature(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
1171 static VOID *load_gsub_table(HDC hdc)
1173 VOID* GSUB_Table = NULL;
1174 int length = GetFontData(hdc, GSUB_TAG , 0, NULL, 0);
1175 if (length != GDI_ERROR)
1177 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
1178 GetFontData(hdc, GSUB_TAG , 0, GSUB_Table, length);
1179 TRACE("Loaded GSUB table of %i bytes\n",length);
1184 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)
1187 INT glyph_count = count;
1190 glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD)*(count*2));
1191 GetGlyphIndicesW(hdc, chars, count, glyphs, 0);
1192 rc = apply_GSUB_feature_to_glyph(hdc, psa, psc, glyphs, 0, write_dir, &glyph_count, feature);
1193 if (rc > GSUB_E_NOGLYPH)
1194 rc = count - glyph_count;
1198 HeapFree(GetProcessHeap(),0,glyphs);
1202 static WORD GDEF_get_glyph_class(const GDEF_Header *header, WORD glyph)
1206 const GDEF_ClassDefFormat1 *cf1;
1211 offset = GET_BE_WORD(header->GlyphClassDef);
1215 cf1 = (GDEF_ClassDefFormat1*)(((BYTE*)header)+offset);
1216 if (GET_BE_WORD(cf1->ClassFormat) == 1)
1218 if (glyph >= GET_BE_WORD(cf1->StartGlyph))
1220 int index = glyph - GET_BE_WORD(cf1->StartGlyph);
1221 if (index < GET_BE_WORD(cf1->GlyphCount))
1222 class = GET_BE_WORD(cf1->ClassValueArray[index]);
1225 else if (GET_BE_WORD(cf1->ClassFormat) == 2)
1227 const GDEF_ClassDefFormat2 *cf2 = (GDEF_ClassDefFormat2*)cf1;
1229 top = GET_BE_WORD(cf2->ClassRangeCount);
1230 for (i = 0; i < top; i++)
1232 if (glyph >= GET_BE_WORD(cf2->ClassRangeRecord[i].Start) &&
1233 glyph <= GET_BE_WORD(cf2->ClassRangeRecord[i].End))
1235 class = GET_BE_WORD(cf2->ClassRangeRecord[i].Class);
1241 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1->ClassFormat));
1246 static VOID *load_gdef_table(HDC hdc)
1248 VOID* GDEF_Table = NULL;
1249 int length = GetFontData(hdc, GDEF_TAG , 0, NULL, 0);
1250 if (length != GDI_ERROR)
1252 GDEF_Table = HeapAlloc(GetProcessHeap(),0,length);
1253 GetFontData(hdc, GDEF_TAG , 0, GDEF_Table, length);
1254 TRACE("Loaded GDEF table of %i bytes\n",length);
1259 static void GDEF_UpdateGlyphProps(HDC hdc, ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1263 if (!psc->GDEF_Table)
1264 psc->GDEF_Table = load_gdef_table(hdc);
1266 for (i = 0; i < cGlyphs; i++)
1270 class = GDEF_get_glyph_class(psc->GDEF_Table, pwGlyphs[i]);
1276 pGlyphProp[i].sva.fClusterStart = 1;
1277 pGlyphProp[i].sva.fDiacritic = 0;
1278 pGlyphProp[i].sva.fZeroWidth = 0;
1281 pGlyphProp[i].sva.fClusterStart = 1;
1282 pGlyphProp[i].sva.fDiacritic = 0;
1283 pGlyphProp[i].sva.fZeroWidth = 0;
1286 pGlyphProp[i].sva.fClusterStart = 0;
1287 pGlyphProp[i].sva.fDiacritic = 1;
1288 pGlyphProp[i].sva.fZeroWidth = 1;
1290 case ComponentGlyph:
1291 pGlyphProp[i].sva.fClusterStart = 0;
1292 pGlyphProp[i].sva.fDiacritic = 0;
1293 pGlyphProp[i].sva.fZeroWidth = 0;
1296 ERR("Unknown glyph class %i\n",class);
1297 pGlyphProp[i].sva.fClusterStart = 1;
1298 pGlyphProp[i].sva.fDiacritic = 0;
1299 pGlyphProp[i].sva.fZeroWidth = 0;
1304 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1308 for (i = 0; i < cGlyphs; i++)
1310 if (!pGlyphProp[i].sva.fClusterStart)
1313 for (j = 0; j < cChars; j++)
1315 if (pwLogClust[j] == i)
1318 while (!pGlyphProp[pwLogClust[k]].sva.fClusterStart && k >= 0 && k <cChars)
1320 if (pGlyphProp[pwLogClust[k]].sva.fClusterStart)
1321 pwLogClust[j] = pwLogClust[k];
1328 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
1330 if (changeCount == 0)
1335 int target_glyph = nextIndex - 1;
1336 int target_index = -1;
1337 int replacing_glyph = -1;
1341 for (i = 0; i < chars; i++)
1343 if (pwLogClust[i] == target_glyph)
1350 for (i = chars - 1; i >= 0; i--)
1352 if (pwLogClust[i] == target_glyph)
1358 if (target_index == -1)
1360 ERR("Unable to find target glyph\n");
1364 if (changeCount < 0)
1367 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1369 if (pwLogClust[i] == target_glyph)
1371 if(pwLogClust[i] == replacing_glyph)
1372 pwLogClust[i] = target_glyph;
1376 if (changed >= changeCount)
1378 replacing_glyph = pwLogClust[i];
1379 pwLogClust[i] = target_glyph;
1387 /* renumber trailing indexes*/
1388 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1390 if (pwLogClust[i] != target_glyph)
1391 pwLogClust[i] += changeCount;
1396 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 )
1400 if (psc->GSUB_Table)
1402 const GSUB_Feature *feature;
1404 feature = load_GSUB_feature(hdc, psa, psc, feat);
1406 return GSUB_E_NOFEATURE;
1409 TRACE("applying feature %s\n",debugstr_an(feat,4));
1410 while(i < *pcGlyphs)
1413 INT prevCount = *pcGlyphs;
1414 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, i, write_dir, pcGlyphs);
1415 if (nextIndex > GSUB_E_NOGLYPH)
1417 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
1425 return GSUB_E_NOFEATURE;
1428 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
1432 if ( i+ delta >= cchLen)
1440 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
1444 if (psa->fLinkBefore)
1449 if ( i+ delta >= cchLen)
1451 if (psa->fLinkAfter)
1459 if (context_type[i] == jtT)
1460 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
1462 return context_type[i];
1465 static inline BOOL right_join_causing(CHAR joining_type)
1467 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
1470 static inline BOOL left_join_causing(CHAR joining_type)
1472 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
1475 static inline BOOL word_break_causing(WCHAR chr)
1477 /* we are working within a string of characters already guareented to
1478 be within one script, Syriac, so we do not worry about any characers
1479 other than the space character outside of that range */
1480 return (chr == 0 || chr == 0x20 );
1484 * ContextualShape_Arabic
1486 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1493 if (*pcGlyphs != cChars)
1495 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1499 if (!psa->fLogicalOrder && psa->fRTL)
1510 if (!psc->GSUB_Table)
1511 psc->GSUB_Table = load_gsub_table(hdc);
1513 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1514 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1516 for (i = 0; i < cChars; i++)
1517 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1519 for (i = 0; i < cChars; i++)
1521 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1522 context_shape[i] = Xr;
1523 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1524 context_shape[i] = Xl;
1525 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)))
1526 context_shape[i] = Xm;
1527 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1528 context_shape[i] = Xr;
1529 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1530 context_shape[i] = Xl;
1532 context_shape[i] = Xn;
1535 /* Contextual Shaping */
1537 while(i < *pcGlyphs)
1539 BOOL shaped = FALSE;
1541 if (psc->GSUB_Table)
1544 INT prevCount = *pcGlyphs;
1545 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1546 if (nextIndex > GSUB_E_NOGLYPH)
1549 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1551 shaped = (nextIndex > GSUB_E_NOGLYPH);
1556 WORD newGlyph = pwOutGlyphs[i];
1557 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1559 /* fall back to presentation form B */
1560 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1561 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1562 pwOutGlyphs[i] = newGlyph;
1568 HeapFree(GetProcessHeap(),0,context_shape);
1569 HeapFree(GetProcessHeap(),0,context_type);
1573 * ContextualShape_Syriac
1577 #define DALATH 0x715
1580 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1587 if (*pcGlyphs != cChars)
1589 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1593 if (!psa->fLogicalOrder && psa->fRTL)
1604 if (!psc->GSUB_Table)
1605 psc->GSUB_Table = load_gsub_table(hdc);
1607 if (!psc->GSUB_Table)
1610 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1611 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1613 for (i = 0; i < cChars; i++)
1614 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1616 for (i = 0; i < cChars; i++)
1618 if (pwcChars[i] == ALAPH)
1620 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1622 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1623 context_shape[i] = Afj;
1624 else if ( rchar != DALATH && rchar != RISH &&
1625 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1626 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1627 context_shape[i] = Afn;
1628 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1629 context_shape[i] = Afx;
1631 context_shape[i] = Xn;
1633 else if (context_type[i] == jtR &&
1634 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1635 context_shape[i] = Xr;
1636 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1637 context_shape[i] = Xl;
1638 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)))
1639 context_shape[i] = Xm;
1640 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1641 context_shape[i] = Xr;
1642 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1643 context_shape[i] = Xl;
1645 context_shape[i] = Xn;
1648 /* Contextual Shaping */
1650 while(i < *pcGlyphs)
1653 INT prevCount = *pcGlyphs;
1654 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1655 if (nextIndex > GSUB_E_NOGLYPH)
1657 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1664 HeapFree(GetProcessHeap(),0,context_shape);
1665 HeapFree(GetProcessHeap(),0,context_type);
1669 * ContextualShape_Phags_pa
1672 #define phags_pa_CANDRABINDU 0xA873
1673 #define phags_pa_START 0xA840
1674 #define phags_pa_END 0xA87F
1676 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1682 if (*pcGlyphs != cChars)
1684 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1688 if (!psa->fLogicalOrder && psa->fRTL)
1699 if (!psc->GSUB_Table)
1700 psc->GSUB_Table = load_gsub_table(hdc);
1702 if (!psc->GSUB_Table)
1705 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1707 for (i = 0; i < cChars; i++)
1709 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1711 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1712 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1713 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1714 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1716 if (jrchar && jlchar)
1717 context_shape[i] = Xm;
1719 context_shape[i] = Xr;
1721 context_shape[i] = Xl;
1723 context_shape[i] = Xn;
1726 context_shape[i] = -1;
1729 /* Contextual Shaping */
1731 while(i < *pcGlyphs)
1733 if (context_shape[i] >= 0)
1736 INT prevCount = *pcGlyphs;
1737 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1738 if (nextIndex > GSUB_E_NOGLYPH)
1740 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1750 HeapFree(GetProcessHeap(),0,context_shape);
1753 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1758 pwOutChars[cWalk] = replacements[0];
1762 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1765 for (j = *pcChars; j > cWalk; j--)
1766 pwOutChars[j] = pwOutChars[j-1];
1767 *pcChars= *pcChars+1;
1768 pwOutChars[cWalk] = replacements[i];
1773 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[])
1778 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1780 for (i = 0; vowels[i].base != 0x0; i++)
1782 if (pwOutChars[cWalk] == vowels[i].base)
1784 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1785 if (vowels[i].parts[1]) cWalk++;
1786 if (vowels[i].parts[2]) cWalk++;
1793 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[])
1798 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1800 for (i = 0; consonants[i].output!= 0x0; i++)
1803 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1804 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1807 if (consonants[i].parts[j]==0x0) /* matched all */
1811 pwOutChars[cWalk] = consonants[i].output;
1812 for(k = cWalk+1; k < *pcChars - j; k++)
1813 pwOutChars[k] = pwOutChars[k+j];
1814 *pcChars = *pcChars - j;
1822 static void Reorder_Ra_follows_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1827 WORD Ra = pwChar[s->start];
1828 WORD H = pwChar[s->start+1];
1830 TRACE("Doing reorder of Ra to %i\n",s->base);
1831 for (j = s->start; j < s->base-1; j++)
1832 pwChar[j] = pwChar[j+2];
1833 pwChar[s->base-1] = Ra;
1834 pwChar[s->base] = H;
1836 s->ralf = s->base-1;
1841 static void Reorder_Ra_follows_matra(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1846 WORD Ra = pwChar[s->start];
1847 WORD H = pwChar[s->start+1];
1848 for (loc = s->end; loc > s->base; loc--)
1849 if (lexical(pwChar[loc]) == lex_Matra_post || lexical(pwChar[loc]) == lex_Matra_below)
1852 TRACE("Doing reorder of Ra to %i\n",loc);
1853 for (j = s->start; j < loc-1; j++)
1854 pwChar[j] = pwChar[j+2];
1863 static void Reorder_Ra_follows_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1868 WORD Ra = pwChar[s->start];
1869 WORD H = pwChar[s->start+1];
1871 TRACE("Doing reorder of Ra to %i\n",s->end-1);
1872 for (j = s->start; j < s->end-1; j++)
1873 pwChar[j] = pwChar[j+2];
1874 pwChar[s->end-1] = Ra;
1882 static void Reorder_Matra_precede_base(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1886 /* reorder Matras */
1887 if (s->end > s->base)
1889 for (i = 1; i <= s->end-s->base; i++)
1891 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1894 WCHAR c = pwChar[s->base+i];
1895 TRACE("Doing reorder of %x %x\n",c,pwChar[s->base]);
1896 for (j = s->base+i; j > s->base; j--)
1897 pwChar[j] = pwChar[j-1];
1898 pwChar[s->base] = c;
1900 if (s->ralf >= s->base) s->ralf++;
1907 static void Reorder_Matra_precede_syllable(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1911 /* reorder Matras */
1912 if (s->end > s->base)
1914 for (i = 1; i <= s->end-s->base; i++)
1916 if (lexical(pwChar[s->base+i]) == lex_Matra_pre)
1919 WCHAR c = pwChar[s->base+i];
1920 TRACE("Doing reorder of %x to %i\n",c,s->start);
1921 for (j = s->base+i; j > s->start; j--)
1922 pwChar[j] = pwChar[j-1];
1923 pwChar[s->start] = c;
1925 if (s->ralf >= 0) s->ralf++;
1932 static void Reorder_Like_Sinhala(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1934 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1935 if (s->start == s->base && s->base == s->end) return;
1936 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1938 Reorder_Ra_follows_base(pwChar, s, lexical);
1939 Reorder_Matra_precede_base(pwChar, s, lexical);
1942 static void Reorder_Like_Devanagari(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1944 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1945 if (s->start == s->base && s->base == s->end) return;
1946 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1948 Reorder_Ra_follows_matra(pwChar, s, lexical);
1949 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1952 static void Reorder_Like_Bengali(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1954 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1955 if (s->start == s->base && s->base == s->end) return;
1956 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1958 Reorder_Ra_follows_base(pwChar, s, lexical);
1959 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1962 static void Reorder_Like_Kannada(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1964 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1965 if (s->start == s->base && s->base == s->end) return;
1966 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1968 Reorder_Ra_follows_syllable(pwChar, s, lexical);
1969 Reorder_Matra_precede_syllable(pwChar, s, lexical);
1972 static void Reorder_Like_Malayalam(LPWSTR pwChar, IndicSyllable *s, lexical_function lexical)
1974 TRACE("Syllable (%i..%i..%i)\n",s->start,s->base,s->end);
1975 if (s->start == s->base && s->base == s->end) return;
1976 if (lexical(pwChar[s->base]) == lex_Vowel) return;
1978 Reorder_Ra_follows_matra(pwChar, s, lexical);
1979 Reorder_Matra_precede_base(pwChar, s, lexical);
1982 static inline void shift_syllable_glyph_indexs(IndicSyllable *glyph_index, INT index, INT shift)
1987 if (glyph_index->start > index)
1988 glyph_index->start += shift;
1989 if (glyph_index->base > index)
1990 glyph_index->base+= shift;
1991 if (glyph_index->end > index)
1992 glyph_index->end+= shift;
1993 if (glyph_index->ralf > index)
1994 glyph_index->ralf+= shift;
1997 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 )
1999 int index = glyph_index->start;
2004 while(index <= glyph_index->end)
2007 INT prevCount = *pcGlyphs;
2008 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, index, 1, pcGlyphs);
2009 if (nextIndex > GSUB_E_NOGLYPH)
2011 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2012 shift_syllable_glyph_indexs(glyph_index,index,*pcGlyphs - prevCount);
2020 static inline INT find_consonant_halant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2023 while (i + index < end - 1 && !(lexical(pwChars[index+i]) == lex_Consonant && (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)))))
2025 if (index + i <= end-1)
2031 static void Apply_Indic_Half(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)
2033 INT index, nextIndex;
2035 INT prevCount = *pcGlyphs;
2037 count = syllable->base - syllable->start;
2040 index = find_consonant_halant(&pwChars[syllable->start], 0, count, lexical);
2041 while (index >= 0 && index < (glyph_index->base - glyph_index->start))
2043 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->start+g_offset, 1, pcGlyphs, "half");
2044 if (nextIndex > GSUB_E_NOGLYPH)
2046 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2047 g_offset += (*pcGlyphs - prevCount);
2048 shift_syllable_glyph_indexs(glyph_index, index + glyph_index->start, g_offset);
2052 index = find_consonant_halant(&pwChars[syllable->start], index, count, lexical);
2056 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)
2059 INT prevCount = *pcGlyphs;
2061 if (syllable->ralf >= 0)
2063 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, glyph_index->ralf, 1, pcGlyphs, "rphf");
2064 if (nextIndex > GSUB_E_NOGLYPH)
2066 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2067 shift_syllable_glyph_indexs(glyph_index,glyph_index->ralf,*pcGlyphs - prevCount);
2072 static inline INT find_halant_consonant(WCHAR* pwChars, INT index, INT end, lexical_function lexical)
2075 while (index + i < end-1 && !(lexical(pwChars[index+i]) == lex_Halant &&
2076 ((index + i < end-2 && lexical(pwChars[index+i]) == lex_Nukta && is_consonant(lexical(pwChars[index+i+1]))) ||
2077 is_consonant(lexical(pwChars[index+i+1])))))
2079 if (index + i <= end-1)
2085 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, const char* feat)
2087 INT index, nextIndex;
2088 INT count, g_offset;
2089 INT prevCount = *pcGlyphs;
2091 count = syllable->end - syllable->base;
2094 index = find_halant_consonant(&pwChars[syllable->base], 0, count, lexical);
2098 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, index+glyph_index->base+g_offset, 1, pcGlyphs, feat);
2099 if (nextIndex > GSUB_E_NOGLYPH)
2101 UpdateClusters(nextIndex, *pcGlyphs - prevCount, 1, cChars, pwLogClust);
2102 g_offset += (*pcGlyphs - prevCount);
2103 shift_syllable_glyph_indexs(glyph_index,index+glyph_index->start, g_offset);
2107 index = find_halant_consonant(&pwChars[syllable->base], index, count, lexical);
2111 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)
2114 int overall_shift = 0;
2115 const GSUB_Feature *locl = load_GSUB_feature(hdc, psa, psc, "locl");
2116 const GSUB_Feature *nukt = load_GSUB_feature(hdc, psa, psc, "nukt");
2117 const GSUB_Feature *akhn = load_GSUB_feature(hdc, psa, psc, "akhn");
2118 const GSUB_Feature *rkrf = load_GSUB_feature(hdc, psa, psc, "rkrf");
2119 BOOL rphf = (load_GSUB_feature(hdc, psa, psc, "rphf") != NULL);
2120 BOOL pref = (load_GSUB_feature(hdc, psa, psc, "pref") != NULL);
2121 BOOL blwf = (load_GSUB_feature(hdc, psa, psc, "blwf") != NULL);
2122 BOOL half = (load_GSUB_feature(hdc, psa, psc, "half") != NULL);
2123 IndicSyllable glyph_indexs;
2125 for (c = 0; c < syllable_count; c++)
2128 memcpy(&glyph_indexs, &syllables[c], sizeof(IndicSyllable));
2129 shift_syllable_glyph_indexs(&glyph_indexs, -1, overall_shift);
2130 old_end = glyph_indexs.end;
2134 TRACE("applying feature locl\n");
2135 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, locl);
2139 TRACE("applying feature nukt\n");
2140 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, nukt);
2144 TRACE("applying feature akhn\n");
2145 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, akhn);
2148 Apply_Indic_Rphf(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs);
2151 TRACE("applying feature rkrf\n");
2152 Apply_Indic_BasicForm(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, rkrf);
2155 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "pref");
2157 Apply_Indic_PostBase(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs, "blwf");
2159 Apply_Indic_Half(hdc, psc, psa, pwChars, cChars, &syllables[c], pwOutGlyphs, pcGlyphs, pwLogClust, lexical, &glyph_indexs);
2161 overall_shift += glyph_indexs.end - old_end;
2165 static int sinhala_lex(WCHAR c)
2169 case 0x0DCA: return lex_Halant;
2172 case 0x0DD8: return lex_Matra_post;
2174 case 0x0DDB: return lex_Matra_pre;
2176 case 0x0DDC: return lex_Matra_post;
2177 case 0x200D: return lex_ZWJ;
2178 case 0x200C: return lex_ZWNJ;
2179 case 0x00A0: return lex_NBSP;
2181 if (c>=0x0D82 && c <=0x0D83) return lex_Modifier;
2182 else if (c>=0x0D85 && c <=0x0D96) return lex_Vowel;
2183 else if (c>=0x0D96 && c <=0x0DC6) return lex_Consonant;
2184 else if (c>=0x0DD0 && c <=0x0DD1) return lex_Matra_post;
2185 else if (c>=0x0DD2 && c <=0x0DD3) return lex_Matra_above;
2186 else if (c>=0x0DD4 && c <=0x0DD6) return lex_Matra_below;
2187 else if (c>=0x0DDD && c <=0x0DDE) return lex_Matra_post;
2188 else if (c>=0x0DF2 && c <=0x0DF3) return lex_Matra_post;
2189 else return lex_Generic;
2193 static const VowelComponents Sinhala_vowels[] = {
2194 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2195 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2196 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2197 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2198 {0x0000, {0x0000,0x0000,0x0}}};
2200 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2202 int cCount = cChars;
2205 IndicSyllable *syllables = NULL;
2206 int syllable_count = 0;
2208 if (*pcGlyphs != cChars)
2210 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2214 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
2216 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2218 /* Step 1: Decompose multi part vowels */
2219 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels);
2221 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2223 /* Step 2: Reorder within Syllables */
2224 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, sinhala_lex, Reorder_Like_Sinhala);
2225 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2227 /* Step 3: Strip dangling joiners */
2228 for (i = 0; i < cCount; i++)
2230 if ((input[i] == 0x200D || input[i] == 0x200C) &&
2231 (i == 0 || input[i-1] == 0x0020 || i == cCount-1 || input[i+1] == 0x0020))
2235 /* Step 4: Base Form application to syllables */
2236 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2238 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, sinhala_lex);
2240 HeapFree(GetProcessHeap(),0,input);
2241 HeapFree(GetProcessHeap(),0,syllables);
2244 static int devanagari_lex(WCHAR c)
2250 case 0x0903: return lex_Modifier;
2251 case 0x0930: return lex_Ra;
2252 case 0x093C: return lex_Nukta;
2254 case 0x093E: return lex_Matra_post;
2255 case 0x093F: return lex_Matra_pre;
2256 case 0x094D: return lex_Halant;
2257 case 0x0972: return lex_Vowel;
2258 case 0x200C: return lex_ZWNJ;
2259 case 0x200D: return lex_ZWJ;
2261 if (c>=0x0901 && c<=0x0902) return lex_Matra_above;
2262 else if (c>=0x0904 && c<=0x0914) return lex_Vowel;
2263 else if (c>=0x0915 && c<=0x0939) return lex_Consonant;
2264 else if (c>=0x0941 && c<=0x0944) return lex_Matra_below;
2265 else if (c>=0x0945 && c<=0x0948) return lex_Matra_above;
2266 else if (c>=0x0949 && c<=0x094C) return lex_Matra_post;
2267 else if (c>=0x0953 && c<=0x0954) return lex_Modifier;
2268 else if (c>=0x0958 && c<=0x095F) return lex_Consonant;
2269 else if (c>=0x0960 && c<=0x0961) return lex_Vowel;
2270 else if (c>=0x0962 && c<=0x0963) return lex_Matra_below;
2271 else if (c>=0x097B && c<=0x097C) return lex_Consonant;
2272 else if (c>=0x097E && c<=0x097F) return lex_Consonant;
2273 else return lex_Generic;
2277 static const ConsonantComponents Devanagari_consonants[] ={
2278 {{0x0928, 0x093C, 0x00000}, 0x0929},
2279 {{0x0930, 0x093C, 0x00000}, 0x0931},
2280 {{0x0933, 0x093C, 0x00000}, 0x0934},
2281 {{0x0915, 0x093C, 0x00000}, 0x0958},
2282 {{0x0916, 0x093C, 0x00000}, 0x0959},
2283 {{0x0917, 0x093C, 0x00000}, 0x095A},
2284 {{0x091C, 0x093C, 0x00000}, 0x095B},
2285 {{0x0921, 0x093C, 0x00000}, 0x095C},
2286 {{0x0922, 0x093C, 0x00000}, 0x095D},
2287 {{0x092B, 0x093C, 0x00000}, 0x095E},
2288 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2290 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2292 int cCount = cChars;
2294 IndicSyllable *syllables = NULL;
2295 int syllable_count = 0;
2297 if (*pcGlyphs != cChars)
2299 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2303 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2304 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2306 /* Step 1: Compose Consonant and Nukta */
2307 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants);
2308 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2310 /* Step 2: Reorder within Syllables */
2311 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, devanagari_lex, Reorder_Like_Devanagari);
2312 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2313 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2316 /* Step 3: Base Form application to syllables */
2317 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, devanagari_lex);
2319 HeapFree(GetProcessHeap(),0,input);
2320 HeapFree(GetProcessHeap(),0,syllables);
2323 static int bengali_lex(WCHAR c)
2327 case 0x0981: return lex_Modifier;
2330 case 0x09CE: return lex_Consonant;
2331 case 0x09B0: return lex_Ra;
2332 case 0x09BC: return lex_Nukta;
2333 case 0x09BF: return lex_Matra_pre;
2336 case 0x09C0: return lex_Matra_post;
2337 case 0x09CD: return lex_Halant;
2338 case 0x200C: return lex_ZWNJ;
2339 case 0x200D: return lex_ZWJ;
2341 if (c>=0x0982 && c<=0x0983) return lex_Matra_post;
2342 else if (c>=0x0985 && c<=0x0994) return lex_Vowel;
2343 else if (c>=0x0995 && c<=0x09B9) return lex_Consonant;
2344 else if (c>=0x09C1 && c<=0x09C4) return lex_Matra_below;
2345 else if (c>=0x09C7 && c<=0x09C8) return lex_Matra_pre;
2346 else if (c>=0x09DC && c<=0x09DF) return lex_Consonant;
2347 else if (c>=0x09E0 && c<=0x09E1) return lex_Vowel;
2348 else if (c>=0x09E2 && c<=0x09E3) return lex_Matra_below;
2349 else if (c>=0x09F0 && c<=0x09F1) return lex_Consonant;
2350 else return lex_Generic;
2354 static const VowelComponents Bengali_vowels[] = {
2355 {0x09CB, {0x09C7,0x09BE,0x0000}},
2356 {0x09CC, {0x09C7,0x09D7,0x0000}},
2357 {0x0000, {0x0000,0x0000,0x0000}}};
2359 static const ConsonantComponents Bengali_consonants[] = {
2360 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2361 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2362 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2363 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2364 {{0x0000,0x0000,0x0000}, 0x0000}};
2366 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2368 int cCount = cChars;
2370 IndicSyllable *syllables = NULL;
2371 int syllable_count = 0;
2373 if (*pcGlyphs != cChars)
2375 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2379 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2380 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2382 /* Step 1: Decompose Vowels and Compose Consonents */
2383 DecomposeVowels(hdc, input, &cCount, Bengali_vowels);
2384 ComposeConsonants(hdc, input, &cCount, Bengali_consonants);
2385 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2387 /* Step 2: Reorder within Syllables */
2388 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, bengali_lex, Reorder_Like_Bengali);
2389 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2390 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2393 /* Step 3: Initial form is only applied to the beginning of words */
2394 for (cCount = cCount - 1 ; cCount >= 0; cCount --)
2396 if (cCount == 0 || input[cCount] == 0x0020) /* space */
2400 if (index > 0) index++;
2402 apply_GSUB_feature_to_glyph(hdc, psa, psc, &pwOutGlyphs[index], 0, 1, &gCount, "init");
2406 /* Step 4: Base Form application to syllables */
2407 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, bengali_lex);
2409 HeapFree(GetProcessHeap(),0,input);
2410 HeapFree(GetProcessHeap(),0,syllables);
2413 static int gurmukhi_lex(WCHAR c)
2420 case 0x0A2f: return lex_Consonant;
2421 case 0x0A3C: return lex_Nukta;
2422 case 0x0A3F: return lex_Matra_pre;
2425 case 0x0A40: return lex_Matra_post;
2426 case 0x0A4D: return lex_Halant;
2428 case 0x0A71: return lex_Modifier;
2429 case 0x200C: return lex_ZWNJ;
2430 case 0x200D: return lex_ZWJ;
2432 if (c>=0x0A01 && c<=0x0A02) return lex_Modifier;
2433 else if (c>=0x0A05 && c<=0x0A14) return lex_Vowel;
2434 else if (c>=0x0A15 && c<=0x0A38) return lex_Consonant;
2435 else if (c>=0x0A41 && c<=0x0A42) return lex_Matra_below;
2436 else if (c>=0x0A47 && c<=0x0A4C) return lex_Matra_above;
2437 else if (c>=0x0A59 && c<=0x0A5E) return lex_Consonant;
2438 else return lex_Generic;
2442 static const ConsonantComponents Gurmukhi_consonants[] = {
2443 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2444 {{0x0A38,0x0A3C,0x0000}, 0x0A36},
2445 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2446 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2447 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2448 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2449 {{0x0000,0x0000,0x0000}, 0x0000}};
2451 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2453 int cCount = cChars;
2455 IndicSyllable *syllables = NULL;
2456 int syllable_count = 0;
2458 if (*pcGlyphs != cChars)
2460 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2464 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2465 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2467 /* Step 1: Compose Consonents */
2468 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants);
2469 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2471 /* Step 2: Reorder within Syllables */
2472 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gurmukhi_lex, Reorder_Like_Bengali);
2473 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2474 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2477 /* Step 3: Base Form application to syllables */
2478 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gurmukhi_lex);
2480 HeapFree(GetProcessHeap(),0,input);
2481 HeapFree(GetProcessHeap(),0,syllables);
2484 static int gujarati_lex(WCHAR c)
2488 case 0x0A83: return lex_Modifier;
2489 case 0x0AB0: return lex_Ra;
2490 case 0x0ABC: return lex_Nukta;
2491 case 0x0ABF: return lex_Matra_pre;
2493 case 0x0AC0: return lex_Matra_post;
2494 case 0x0ACD: return lex_Halant;
2495 case 0x200C: return lex_ZWNJ;
2496 case 0x200D: return lex_ZWJ;
2498 if (c>=0x0A81 && c<=0x0A82) return lex_Modifier;
2499 else if (c>=0x0A85 && c<=0x0A94) return lex_Vowel;
2500 else if (c>=0x0A95 && c<=0x0AB9) return lex_Consonant;
2501 else if (c>=0x0AC1 && c<=0x0AC4) return lex_Matra_below;
2502 else if (c>=0x0AC5 && c<=0x0AC8) return lex_Matra_above;
2503 else if (c>=0x0AC9 && c<=0x0ACC) return lex_Matra_post;
2504 else if (c>=0x0AE0 && c<=0x0AE1) return lex_Vowel;
2505 else if (c>=0x0AE2 && c<=0x0AE3) return lex_Matra_below;
2506 else return lex_Generic;
2510 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2512 int cCount = cChars;
2514 IndicSyllable *syllables = NULL;
2515 int syllable_count = 0;
2517 if (*pcGlyphs != cChars)
2519 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2523 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2524 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2526 /* Step 1: Reorder within Syllables */
2527 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, gujarati_lex, Reorder_Like_Devanagari);
2528 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2529 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2532 /* Step 2: Base Form application to syllables */
2533 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, gujarati_lex);
2535 HeapFree(GetProcessHeap(),0,input);
2536 HeapFree(GetProcessHeap(),0,syllables);
2539 static int oriya_lex(WCHAR c)
2548 case 0x0B33: return lex_Consonant;
2549 case 0x0B30: return lex_Ra;
2550 case 0x0B3C: return lex_Nukta;
2552 case 0x0B56: return lex_Matra_above;
2555 case 0x0B40: return lex_Matra_post;
2556 case 0x0B47: return lex_Matra_pre;
2557 case 0x0B4D: return lex_Halant;
2558 case 0x200C: return lex_ZWNJ;
2559 case 0x200D: return lex_ZWJ;
2561 if (c>=0x0B01 && c<=0x0B03) return lex_Modifier;
2562 else if (c>=0x0B05 && c<=0x0B14) return lex_Vowel;
2563 else if (c>=0x0B15 && c<=0x0B39) return lex_Consonant;
2564 else if (c>=0x0B2C && c<=0x0B2E) return lex_Consonant;
2565 else if (c>=0x0B32 && c<=0x0B33) return lex_Consonant;
2566 else if (c>=0x0B41 && c<=0x0B44) return lex_Matra_below;
2567 else if (c>=0x0B48 && c<=0x0B4C) return lex_Composed_Vowel;
2568 else if (c>=0x0B5C && c<=0x0B5D) return lex_Consonant;
2569 else if (c>=0x0B60 && c<=0x0B61) return lex_Vowel;
2570 else if (c>=0x0B62 && c<=0x0B63) return lex_Matra_below;
2571 else return lex_Generic;
2575 static const VowelComponents Oriya_vowels[] = {
2576 {0x0B48, {0x0B47,0x0B56,0x0000}},
2577 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2578 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2579 {0x0000, {0x0000,0x0000,0x0000}}};
2581 static const ConsonantComponents Oriya_consonants[] = {
2582 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2583 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2584 {{0x0000,0x0000,0x0000}, 0x0000}};
2586 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2588 int cCount = cChars;
2590 IndicSyllable *syllables = NULL;
2591 int syllable_count = 0;
2593 if (*pcGlyphs != cChars)
2595 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2599 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2600 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2602 /* Step 1: Decompose Vowels and Compose Consonents */
2603 DecomposeVowels(hdc, input, &cCount, Oriya_vowels);
2604 ComposeConsonants(hdc, input, &cCount, Oriya_consonants);
2605 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2607 /* Step 2: Reorder within Syllables */
2608 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, oriya_lex, Reorder_Like_Bengali);
2609 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2610 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2613 /* Step 3: Base Form application to syllables */
2614 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, oriya_lex);
2616 HeapFree(GetProcessHeap(),0,input);
2617 HeapFree(GetProcessHeap(),0,syllables);
2620 static int tamil_lex(WCHAR c)
2624 case 0x0BC0: return lex_Matra_above;
2625 case 0x0BCD: return lex_Halant;
2626 case 0x0BD7: return lex_Matra_post;
2627 case 0x200C: return lex_ZWNJ;
2628 case 0x200D: return lex_ZWJ;
2630 if (c>=0x0B95 && c<=0x0BB9) return lex_Consonant;
2631 else if (c>=0x0BBE && c<=0x0BBF) return lex_Matra_post;
2632 else if (c>=0x0BC1 && c<=0x0BC2) return lex_Matra_below;
2633 else if (c>=0x0BC6 && c<=0x0BC8) return lex_Matra_pre;
2634 else return lex_Generic;
2638 static const VowelComponents Tamil_vowels[] = {
2639 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2640 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2641 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2642 {0x0000, {0x0000,0x0000,0x0000}}};
2644 static const ConsonantComponents Tamil_consonants[] = {
2645 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2646 {{0x0000,0x0000,0x0000}, 0x0000}};
2648 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2650 int cCount = cChars;
2652 IndicSyllable *syllables = NULL;
2653 int syllable_count = 0;
2655 if (*pcGlyphs != cChars)
2657 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2661 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2662 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2664 /* Step 1: Decompose Vowels and Compose Consonents */
2665 DecomposeVowels(hdc, input, &cCount, Tamil_vowels);
2666 ComposeConsonants(hdc, input, &cCount, Tamil_consonants);
2667 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2669 /* Step 2: Reorder within Syllables */
2670 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, tamil_lex, Reorder_Like_Sinhala);
2671 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2672 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2675 /* Step 3: Base Form application to syllables */
2676 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, tamil_lex);
2678 HeapFree(GetProcessHeap(),0,input);
2679 HeapFree(GetProcessHeap(),0,syllables);
2682 static int telugu_lex(WCHAR c)
2686 case 0x0C4D: return lex_Halant;
2687 case 0x0C55: return lex_Matra_above;
2688 case 0x0C56: return lex_Matra_below;
2689 case 0x200C: return lex_ZWNJ;
2690 case 0x200D: return lex_ZWJ;
2692 if (c>=0x0C01 && c<=0x0C03) return lex_Matra_post;
2693 else if (c>=0x0C05 && c<=0x0C14) return lex_Vowel;
2694 else if (c>=0x0C15 && c<=0x0C39) return lex_Consonant;
2695 else if (c>=0x0C3E && c<=0x0C40) return lex_Matra_above;
2696 else if (c>=0x0C41 && c<=0x0C44) return lex_Matra_post;
2697 else if (c>=0x0C46 && c<=0x0C47) return lex_Matra_above;
2698 else if (c>=0x0C4A && c<=0x0C4C) return lex_Matra_above;
2699 else if (c>=0x0C58 && c<=0x0C59) return lex_Consonant;
2700 else if (c>=0x0C60 && c<=0x0C61) return lex_Vowel;
2701 else if (c>=0x0C62 && c<=0x0C63) return lex_Matra_below;
2702 else return lex_Generic;
2706 static const VowelComponents Telugu_vowels[] = {
2707 {0x0C48, {0x0C46,0x0C56,0x0000}},
2708 {0x0000, {0x0000,0x0000,0x0000}}};
2710 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2712 int cCount = cChars;
2714 IndicSyllable *syllables = NULL;
2715 int syllable_count = 0;
2717 if (*pcGlyphs != cChars)
2719 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2723 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2724 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2726 /* Step 1: Decompose Vowels */
2727 DecomposeVowels(hdc, input, &cCount, Telugu_vowels);
2728 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2730 /* Step 2: Reorder within Syllables */
2731 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, telugu_lex, Reorder_Like_Bengali);
2732 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2733 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2736 /* Step 3: Base Form application to syllables */
2737 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, telugu_lex);
2739 HeapFree(GetProcessHeap(),0,input);
2740 HeapFree(GetProcessHeap(),0,syllables);
2743 static int kannada_lex(WCHAR c)
2747 case 0x0CB0: return lex_Ra;
2748 case 0x0CBC: return lex_Nukta;
2749 case 0x0CBE: return lex_Matra_post;
2750 case 0x0CBF: return lex_Matra_above;
2751 case 0x0CC6: return lex_Matra_above;
2752 case 0x0CCC: return lex_Matra_above;
2753 case 0x0CCD: return lex_Halant;
2754 case 0x0CCE: return lex_Consonant;
2755 case 0x200C: return lex_ZWNJ;
2756 case 0x200D: return lex_ZWJ;
2758 if (c>=0x0C82 && c<=0x0C83) return lex_Modifier;
2759 else if (c>=0x0C85 && c<=0x0C94) return lex_Vowel;
2760 else if (c>=0x0C95 && c<=0x0CB9) return lex_Consonant;
2761 else if (c>=0x0CC1 && c<=0x0CC4) return lex_Matra_post;
2762 else if (c>=0x0CD5 && c<=0x0CD6) return lex_Modifier;
2763 else if (c>=0x0CE0 && c<=0x0CE1) return lex_Vowel;
2764 else if (c>=0x0CE2 && c<=0x0CE3) return lex_Matra_below;
2765 else return lex_Generic;
2769 static const VowelComponents Kannada_vowels[] = {
2770 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2771 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2772 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2773 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2774 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2775 {0x0000, {0x0000,0x0000,0x0000}}};
2777 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2779 int cCount = cChars;
2781 IndicSyllable *syllables = NULL;
2782 int syllable_count = 0;
2784 if (*pcGlyphs != cChars)
2786 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2790 input = HeapAlloc(GetProcessHeap(), 0, (cChars*3) * sizeof(WCHAR));
2791 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2793 /* Step 1: Decompose Vowels */
2794 DecomposeVowels(hdc, input, &cCount, Kannada_vowels);
2795 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2797 /* Step 2: Reorder within Syllables */
2798 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, kannada_lex, Reorder_Like_Kannada);
2799 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2800 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2803 /* Step 3: Base Form application to syllables */
2804 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, kannada_lex);
2806 HeapFree(GetProcessHeap(),0,input);
2807 HeapFree(GetProcessHeap(),0,syllables);
2810 static int malayalam_lex(WCHAR c)
2814 case 0x0D35: return lex_Consonant;
2815 case 0x0D4D: return lex_Halant;
2816 case 0x0D57: return lex_Matra_post;
2817 case 0x200C: return lex_ZWNJ;
2818 case 0x200D: return lex_ZWJ;
2820 if (c>=0x0D02 && c<=0x0D03) return lex_Modifier;
2821 else if (c>=0x0D05 && c<=0x0D14) return lex_Vowel;
2822 else if (c>=0x0D15 && c<=0x0D39) return lex_Consonant;
2823 else if (c>=0x0D3E && c<=0x0D44) return lex_Matra_post;
2824 else if (c>=0x0D46 && c<=0x0D48) return lex_Matra_pre;
2825 else if (c>=0x0D60 && c<=0x0D61) return lex_Vowel;
2826 else if (c>=0x0D62 && c<=0x0D63) return lex_Matra_below;
2827 else return lex_Generic;
2831 static const VowelComponents Malayalam_vowels[] = {
2832 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2833 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2834 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2835 {0x0000, {0x0000,0x0000,0x0000}}};
2837 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2839 int cCount = cChars;
2841 IndicSyllable *syllables = NULL;
2842 int syllable_count = 0;
2844 if (*pcGlyphs != cChars)
2846 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2850 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2851 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2853 /* Step 1: Decompose Vowels */
2854 DecomposeVowels(hdc, input, &cCount, Malayalam_vowels);
2855 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2857 /* Step 2: Reorder within Syllables */
2858 Indic_ReorderCharacters( hdc, psa, psc, input, cCount, &syllables, &syllable_count, malayalam_lex, Reorder_Like_Malayalam);
2859 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2860 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2863 /* Step 3: Base Form application to syllables */
2864 ShapeIndicSyllables(hdc, psc, psa, input, cCount, syllables, syllable_count, pwOutGlyphs, pcGlyphs, pwLogClust, malayalam_lex);
2866 HeapFree(GetProcessHeap(),0,input);
2867 HeapFree(GetProcessHeap(),0,syllables);
2870 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)
2874 for (i = 0; i < cGlyphs; i++)
2879 for (k = 0; k < cChars; k++)
2881 if (pwLogClust[k] == i)
2883 char_index[char_count] = k;
2888 if (char_count == 0)
2890 FIXME("No chars in this glyph? Must be an error\n");
2894 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2896 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2897 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2900 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2903 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2904 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2907 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 )
2910 int initGlyph, finaGlyph;
2914 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2915 memset(spaces,0,cGlyphs);
2917 if (!psa->fLogicalOrder && psa->fRTL)
2919 initGlyph = cGlyphs-1;
2927 finaGlyph = cGlyphs-1;
2932 for (i = 0; i < cGlyphs; i++)
2934 for (k = 0; k < cChars; k++)
2935 if (pwLogClust[k] == i)
2937 if (pwcChars[k] == 0x0020)
2942 for (i = 0; i < cGlyphs; i++)
2946 BOOL isInit, isFinal;
2948 for (k = 0; k < cChars; k++)
2950 if (pwLogClust[k] == i)
2952 char_index[char_count] = k;
2957 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
2958 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
2960 if (char_count == 0)
2962 FIXME("No chars in this glyph? Must be an error\n");
2966 if (char_count == 1)
2968 if (pwcChars[char_index[0]] == 0x0020) /* space */
2970 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
2971 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2973 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
2974 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
2975 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
2977 if (!isInit && !isFinal)
2978 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
2980 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
2982 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2986 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
2987 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
2988 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
2989 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
2990 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
2991 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
2992 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
2993 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
2995 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2997 else if (!isInit && !isFinal)
2998 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3000 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3002 else if (char_count == 2)
3004 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
3005 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
3007 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3009 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3011 else if (!isInit && !isFinal)
3012 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
3014 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3017 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3018 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3019 HeapFree(GetProcessHeap(),0,spaces);
3022 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 )
3029 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
3030 memset(spaces,0,cGlyphs);
3032 if (!psa->fLogicalOrder && psa->fRTL)
3039 finaGlyph = cGlyphs-1;
3043 for (i = 0; i < cGlyphs; i++)
3045 for (k = 0; k < cChars; k++)
3046 if (pwLogClust[k] == i)
3048 if (pwcChars[k] == 0x0020)
3053 for (i = 0; i < cGlyphs; i++)
3058 for (k = 0; k < cChars; k++)
3060 if (pwLogClust[k] == i)
3062 char_index[char_count] = k;
3067 if (char_count == 0)
3069 FIXME("No chars in this glyph? Must be an error\n");
3073 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3075 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3076 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3078 else if (i == finaGlyph)
3079 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3081 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3084 HeapFree(GetProcessHeap(),0,spaces);
3085 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3086 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3088 /* Do not allow justification between marks and their base */
3089 for (i = 0; i < cGlyphs; i++)
3091 if (!pGlyphProp[i].sva.fClusterStart)
3092 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3096 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)
3100 for (i = 0; i < cGlyphs; i++)
3105 for (k = 0; k < cChars; k++)
3107 if (pwLogClust[k] == i)
3109 char_index[char_count] = k;
3114 if (char_count == 0)
3116 FIXME("No chars in this glyph? Must be an error\n");
3120 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3122 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
3123 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3126 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3128 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
3129 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3132 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)
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_BLANK;
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);
3167 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
3168 for (i = 0; i < cGlyphs; i++)
3170 if (!pGlyphProp[i].sva.fClusterStart)
3172 pGlyphProp[i].sva.fDiacritic = 0;
3173 pGlyphProp[i].sva.fZeroWidth = 0;
3178 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)
3182 for (i = 0; i < cGlyphs; i++)
3187 for (k = 0; k < cChars; k++)
3189 if (pwLogClust[k] == i)
3191 char_index[char_count] = k;
3196 if (char_count == 0)
3198 FIXME("No chars in this glyph? Must be an error\n");
3202 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
3204 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
3205 pCharProp[char_index[0]].fCanGlyphAlone = 1;
3208 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
3210 pGlyphProp[i].sva.fClusterStart = 0;
3211 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
3212 switch (lexical(pwcChars[char_index[k]]))
3215 case lex_Matra_post:
3216 case lex_Matra_above:
3217 case lex_Matra_below:
3221 pGlyphProp[i].sva.fClusterStart = 1;
3225 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3228 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 )
3230 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex);
3233 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 )
3235 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex);
3238 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 )
3240 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex);
3243 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 )
3245 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex);
3248 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 )
3250 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex);
3253 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 )
3255 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, tamil_lex);
3258 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 )
3260 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, telugu_lex);
3263 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 )
3265 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, kannada_lex);
3268 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 )
3270 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, malayalam_lex);
3273 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)
3275 if (ShapingData[psa->eScript].charGlyphPropProc)
3276 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3278 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3281 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
3283 if (ShapingData[psa->eScript].contextProc)
3284 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
3287 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)
3292 if (!rpRangeProperties)
3295 if (!psc->GSUB_Table)
3296 psc->GSUB_Table = load_gsub_table(hdc);
3298 if (!psc->GSUB_Table)
3301 if (!psa->fLogicalOrder && psa->fRTL)
3306 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3308 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3309 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
3313 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
3315 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3316 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
3318 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
3321 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
3323 const GSUB_Feature *feature;
3326 if (!ShapingData[psa->eScript].requiredFeatures)
3329 if (!psc->GSUB_Table)
3330 psc->GSUB_Table = load_gsub_table(hdc);
3332 /* we need to have at least one of the required features */
3334 while (ShapingData[psa->eScript].requiredFeatures[i])
3336 feature = load_GSUB_feature(hdc, psa, psc, ShapingData[psa->eScript].requiredFeatures[i]);
3342 return USP_E_SCRIPT_NOT_IN_FONT;