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);
54 typedef VOID (*ShapeCharGlyphPropProc)( HDC , ScriptCache*, SCRIPT_ANALYSIS*, const WCHAR*, const INT, const WORD*, const INT, WORD*, SCRIPT_CHARPROP*, SCRIPT_GLYPHPROP*);
56 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);
57 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 );
58 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 );
59 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 );
60 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 );
61 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 );
62 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 );
63 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 );
64 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 );
65 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 );
67 extern const unsigned short wine_shaping_table[];
68 extern const unsigned short wine_shaping_forms[LAST_ARABIC_CHAR - FIRST_ARABIC_CHAR + 1][4];
90 #ifdef WORDS_BIGENDIAN
91 #define GET_BE_WORD(x) (x)
93 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
96 /* These are all structures needed for the GSUB table */
97 #define GSUB_TAG MS_MAKE_TAG('G', 'S', 'U', 'B')
98 #define GSUB_E_NOFEATURE -2
99 #define GSUB_E_NOGLYPH -1
115 GSUB_ScriptRecord ScriptRecord[1];
121 } GSUB_LangSysRecord;
126 GSUB_LangSysRecord LangSysRecord[1];
130 WORD LookupOrder; /* Reserved */
131 WORD ReqFeatureIndex;
133 WORD FeatureIndex[1];
139 } GSUB_FeatureRecord;
143 GSUB_FeatureRecord FeatureRecord[1];
147 WORD FeatureParams; /* Reserved */
149 WORD LookupListIndex[1];
168 } GSUB_CoverageFormat1;
173 WORD StartCoverageIndex;
179 GSUB_RangeRecord RangeRecord[1];
180 } GSUB_CoverageFormat2;
183 WORD SubstFormat; /* = 1 */
186 } GSUB_SingleSubstFormat1;
189 WORD SubstFormat; /* = 2 */
193 }GSUB_SingleSubstFormat2;
196 WORD SubstFormat; /* = 1 */
200 }GSUB_LigatureSubstFormat1;
215 WORD LookupListIndex;
217 }GSUB_SubstLookupRecord;
220 WORD SubstFormat; /* = 1 */
222 WORD ChainSubRuleSetCount;
223 WORD ChainSubRuleSet[1];
224 }GSUB_ChainContextSubstFormat1;
227 WORD SubstFormat; /* = 3 */
228 WORD BacktrackGlyphCount;
230 }GSUB_ChainContextSubstFormat3_1;
233 WORD InputGlyphCount;
235 }GSUB_ChainContextSubstFormat3_2;
238 WORD LookaheadGlyphCount;
240 }GSUB_ChainContextSubstFormat3_3;
244 GSUB_SubstLookupRecord SubstLookupRecord[1];
245 }GSUB_ChainContextSubstFormat3_4;
248 WORD SubstFormat; /* = 1 */
250 WORD AlternateSetCount;
251 WORD AlternateSet[1];
252 } GSUB_AlternateSubstFormat1;
259 /* These are all structures needed for the GDEF table */
260 #define GDEF_TAG MS_MAKE_TAG('G', 'D', 'E', 'F')
262 enum {BaseGlyph=1, LigatureGlyph, MarkGlyph, ComponentGlyph};
269 WORD MarkAttachClassDef;
276 WORD ClassValueArray[1];
277 } GDEF_ClassDefFormat1;
283 } GDEF_ClassRangeRecord;
287 WORD ClassRangeCount;
288 GDEF_ClassRangeRecord ClassRangeRecord[1];
289 } GDEF_ClassDefFormat2;
291 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count);
293 typedef struct tagVowelComponents
299 typedef struct tagConsonantComponents
303 } ConsonantComponents;
305 /* the orders of joined_forms and contextual_features need to line up */
306 static const char* contextual_features[] =
318 static OPENTYPE_FEATURE_RECORD standard_features[] =
320 { MS_MAKE_TAG('l','i','g','a'), 1},
321 { MS_MAKE_TAG('c','l','i','g'), 1},
324 static OPENTYPE_FEATURE_RECORD arabic_features[] =
326 { MS_MAKE_TAG('r','l','i','g'), 1},
327 { MS_MAKE_TAG('c','a','l','t'), 1},
328 { MS_MAKE_TAG('l','i','g','a'), 1},
329 { MS_MAKE_TAG('d','l','i','g'), 1},
330 { MS_MAKE_TAG('c','s','w','h'), 1},
331 { MS_MAKE_TAG('m','s','e','t'), 1},
334 static const char* required_arabic_features[] =
343 static OPENTYPE_FEATURE_RECORD hebrew_features[] =
345 { MS_MAKE_TAG('d','l','i','g'), 1},
348 static OPENTYPE_FEATURE_RECORD syriac_features[] =
350 { MS_MAKE_TAG('r','l','i','g'), 1},
351 { MS_MAKE_TAG('c','a','l','t'), 1},
352 { MS_MAKE_TAG('l','i','g','a'), 1},
353 { MS_MAKE_TAG('d','l','i','g'), 1},
356 static const char* required_syriac_features[] =
368 static OPENTYPE_FEATURE_RECORD sinhala_features[] =
371 { MS_MAKE_TAG('a','k','h','n'), 1},
372 { MS_MAKE_TAG('r','p','h','f'), 1},
373 { MS_MAKE_TAG('v','a','t','u'), 1},
374 { MS_MAKE_TAG('p','s','t','f'), 1},
375 /* Presentation forms */
376 { MS_MAKE_TAG('b','l','w','s'), 1},
377 { MS_MAKE_TAG('a','b','v','s'), 1},
378 { MS_MAKE_TAG('p','s','t','s'), 1},
381 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
383 { MS_MAKE_TAG('a','b','v','s'), 1},
384 { MS_MAKE_TAG('b','l','w','s'), 1},
387 static OPENTYPE_FEATURE_RECORD thai_features[] =
389 { MS_MAKE_TAG('c','c','m','p'), 1},
392 static const char* required_lao_features[] =
398 static const char* required_devanagari_features[] =
414 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
416 /* Localized forms */
417 { MS_MAKE_TAG('l','o','c','l'), 1},
419 { MS_MAKE_TAG('n','u','k','t'), 1},
420 { MS_MAKE_TAG('a','k','h','n'), 1},
421 { MS_MAKE_TAG('r','p','h','f'), 1},
422 { MS_MAKE_TAG('r','k','r','f'), 1},
423 { MS_MAKE_TAG('b','l','w','f'), 1},
424 { MS_MAKE_TAG('h','a','l','f'), 1},
425 { MS_MAKE_TAG('v','a','t','u'), 1},
426 { MS_MAKE_TAG('c','j','c','t'), 1},
427 /* Presentation forms */
428 { MS_MAKE_TAG('p','r','e','s'), 1},
429 { MS_MAKE_TAG('a','b','v','s'), 1},
430 { MS_MAKE_TAG('b','l','w','s'), 1},
431 { MS_MAKE_TAG('p','s','t','s'), 1},
432 { MS_MAKE_TAG('h','a','l','n'), 1},
433 { MS_MAKE_TAG('c','a','l','t'), 1},
436 static const char* required_bengali_features[] =
453 static OPENTYPE_FEATURE_RECORD bengali_features[] =
455 /* Localized forms */
456 { MS_MAKE_TAG('l','o','c','l'), 1},
458 { MS_MAKE_TAG('n','u','k','t'), 1},
459 { MS_MAKE_TAG('a','k','h','n'), 1},
460 { MS_MAKE_TAG('r','p','h','f'), 1},
461 { MS_MAKE_TAG('b','l','w','f'), 1},
462 { MS_MAKE_TAG('h','a','l','f'), 1},
463 { MS_MAKE_TAG('p','s','t','f'), 1},
464 { MS_MAKE_TAG('v','a','t','u'), 1},
465 { MS_MAKE_TAG('c','j','c','t'), 1},
466 /* Presentation forms */
467 { MS_MAKE_TAG('i','n','i','t'), 1},
468 { MS_MAKE_TAG('p','r','e','s'), 1},
469 { MS_MAKE_TAG('a','b','v','s'), 1},
470 { MS_MAKE_TAG('b','l','w','s'), 1},
471 { MS_MAKE_TAG('p','s','t','s'), 1},
472 { MS_MAKE_TAG('h','a','l','n'), 1},
473 { MS_MAKE_TAG('c','a','l','t'), 1},
476 static const char* required_gurmukhi_features[] =
495 static OPENTYPE_FEATURE_RECORD gurmukhi_features[] =
497 /* Localized forms */
498 { MS_MAKE_TAG('l','o','c','l'), 1},
500 { MS_MAKE_TAG('n','u','k','t'), 1},
501 { MS_MAKE_TAG('a','k','h','n'), 1},
502 { MS_MAKE_TAG('r','p','h','f'), 1},
503 { MS_MAKE_TAG('b','l','w','f'), 1},
504 { MS_MAKE_TAG('h','a','l','f'), 1},
505 { MS_MAKE_TAG('p','s','t','f'), 1},
506 { MS_MAKE_TAG('v','a','t','u'), 1},
507 { MS_MAKE_TAG('c','j','c','t'), 1},
508 /* Presentation forms */
509 { MS_MAKE_TAG('p','r','e','s'), 1},
510 { MS_MAKE_TAG('a','b','v','s'), 1},
511 { MS_MAKE_TAG('b','l','w','s'), 1},
512 { MS_MAKE_TAG('p','s','t','s'), 1},
513 { MS_MAKE_TAG('h','a','l','n'), 1},
514 { MS_MAKE_TAG('c','a','l','t'), 1},
517 static const char* required_oriya_features[] =
534 static OPENTYPE_FEATURE_RECORD oriya_features[] =
536 /* Localized forms */
537 { MS_MAKE_TAG('l','o','c','l'), 1},
539 { MS_MAKE_TAG('n','u','k','t'), 1},
540 { MS_MAKE_TAG('a','k','h','n'), 1},
541 { MS_MAKE_TAG('r','p','h','f'), 1},
542 { MS_MAKE_TAG('b','l','w','f'), 1},
543 { MS_MAKE_TAG('p','s','t','f'), 1},
544 { MS_MAKE_TAG('c','j','c','t'), 1},
545 /* Presentation forms */
546 { MS_MAKE_TAG('p','r','e','s'), 1},
547 { MS_MAKE_TAG('a','b','v','s'), 1},
548 { MS_MAKE_TAG('b','l','w','s'), 1},
549 { MS_MAKE_TAG('p','s','t','s'), 1},
550 { MS_MAKE_TAG('h','a','l','n'), 1},
551 { MS_MAKE_TAG('c','a','l','t'), 1},
554 typedef struct ScriptShapeDataTag {
555 TEXTRANGE_PROPERTIES defaultTextRange;
556 const char** requiredFeatures;
559 ContextualShapingProc contextProc;
560 ShapeCharGlyphPropProc charGlyphPropProc;
563 /* in order of scripts */
564 static const ScriptShapeData ShapingData[] =
566 {{ standard_features, 2}, NULL, "", "", NULL, NULL},
567 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
568 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
569 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
570 {{ standard_features, 2}, NULL, "" , "", NULL, NULL},
571 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
572 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
573 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
574 {{ hebrew_features, 1}, NULL, "hebr", "", NULL, NULL},
575 {{ syriac_features, 4}, required_syriac_features, "syrc", "", ContextualShape_Syriac, ShapeCharGlyphProp_None},
576 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
577 {{ NULL, 0}, NULL, "thaa", "", NULL, ShapeCharGlyphProp_None},
578 {{ standard_features, 2}, NULL, "grek", "", NULL, NULL},
579 {{ standard_features, 2}, NULL, "cyrl", "", NULL, NULL},
580 {{ standard_features, 2}, NULL, "armn", "", NULL, NULL},
581 {{ standard_features, 2}, NULL, "geor", "", NULL, NULL},
582 {{ sinhala_features, 7}, NULL, "sinh", "", ContextualShape_Sinhala, NULL},
583 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
584 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
585 {{ tibetan_features, 2}, NULL, "phag", "", ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
586 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
587 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
588 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
589 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
590 {{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
591 {{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
592 {{ bengali_features, 16}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
593 {{ bengali_features, 16}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
594 {{ gurmukhi_features, 15}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
595 {{ gurmukhi_features, 15}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
596 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
597 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
598 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
599 {{ oriya_features, 13}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
600 {{ oriya_features, 13}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
603 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
605 const GSUB_CoverageFormat1* cf1;
609 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
611 int count = GET_BE_WORD(cf1->GlyphCount);
613 TRACE("Coverage Format 1, %i glyphs\n",count);
614 for (i = 0; i < count; i++)
615 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
619 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
621 const GSUB_CoverageFormat2* cf2;
624 cf2 = (const GSUB_CoverageFormat2*)cf1;
626 count = GET_BE_WORD(cf2->RangeCount);
627 TRACE("Coverage Format 2, %i ranges\n",count);
628 for (i = 0; i < count; i++)
630 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
632 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
633 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
635 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
636 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
642 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
647 static const GSUB_Script* GSUB_get_script_table( const GSUB_Header* header, const char* tag)
649 const GSUB_ScriptList *script;
650 const GSUB_Script *deflt = NULL;
652 script = (const GSUB_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
654 TRACE("%i scripts in this font\n",GET_BE_WORD(script->ScriptCount));
655 for (i = 0; i < GET_BE_WORD(script->ScriptCount); i++)
657 const GSUB_Script *scr;
660 offset = GET_BE_WORD(script->ScriptRecord[i].Script);
661 scr = (const GSUB_Script*)((const BYTE*)script + offset);
663 if (strncmp(script->ScriptRecord[i].ScriptTag, tag,4)==0)
665 if (strncmp(script->ScriptRecord[i].ScriptTag, "dflt",4)==0)
671 static const GSUB_LangSys* GSUB_get_lang_table( const GSUB_Script* script, const char* tag)
675 const GSUB_LangSys *Lang;
677 TRACE("Deflang %x, LangCount %i\n",GET_BE_WORD(script->DefaultLangSys), GET_BE_WORD(script->LangSysCount));
679 for (i = 0; i < GET_BE_WORD(script->LangSysCount) ; i++)
681 offset = GET_BE_WORD(script->LangSysRecord[i].LangSys);
682 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
684 if ( strncmp(script->LangSysRecord[i].LangSysTag,tag,4)==0)
687 offset = GET_BE_WORD(script->DefaultLangSys);
690 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
696 static const GSUB_Feature * GSUB_get_feature(const GSUB_Header *header, const GSUB_LangSys *lang, const char* tag)
699 const GSUB_FeatureList *feature;
700 feature = (const GSUB_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
702 TRACE("%i features\n",GET_BE_WORD(lang->FeatureCount));
703 for (i = 0; i < GET_BE_WORD(lang->FeatureCount); i++)
705 int index = GET_BE_WORD(lang->FeatureIndex[i]);
706 if (strncmp(feature->FeatureRecord[index].FeatureTag,tag,4)==0)
708 const GSUB_Feature *feat;
709 feat = (const GSUB_Feature*)((const BYTE*)feature + GET_BE_WORD(feature->FeatureRecord[index].Feature));
716 static INT GSUB_apply_SingleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
719 TRACE("Single Substitution Subtable\n");
721 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
724 const GSUB_SingleSubstFormat1 *ssf1;
725 offset = GET_BE_WORD(look->SubTable[j]);
726 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
727 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
729 int offset = GET_BE_WORD(ssf1->Coverage);
730 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
731 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
733 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
734 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
735 TRACE(" 0x%x\n",glyphs[glyph_index]);
736 return glyph_index + 1;
741 const GSUB_SingleSubstFormat2 *ssf2;
745 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
746 offset = GET_BE_WORD(ssf1->Coverage);
747 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
748 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
749 TRACE(" Coverage index %i\n",index);
752 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
753 return GSUB_E_NOGLYPH;
755 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
756 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
757 TRACE("0x%x\n",glyphs[glyph_index]);
758 return glyph_index + 1;
762 return GSUB_E_NOGLYPH;
765 static INT GSUB_apply_AlternateSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
768 TRACE("Alternate Substitution Subtable\n");
770 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
773 const GSUB_AlternateSubstFormat1 *asf1;
776 offset = GET_BE_WORD(look->SubTable[j]);
777 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
778 offset = GET_BE_WORD(asf1->Coverage);
780 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
783 const GSUB_AlternateSet *as;
784 offset = GET_BE_WORD(asf1->AlternateSet[index]);
785 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
786 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
787 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
788 return GSUB_E_NOGLYPH;
790 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
791 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
792 TRACE(" 0x%x\n",glyphs[glyph_index]);
793 return glyph_index + 1;
796 return GSUB_E_NOGLYPH;
799 static INT GSUB_apply_LigatureSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
803 TRACE("Ligature Substitution Subtable\n");
804 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
806 const GSUB_LigatureSubstFormat1 *lsf1;
809 offset = GET_BE_WORD(look->SubTable[j]);
810 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
811 offset = GET_BE_WORD(lsf1->Coverage);
812 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
813 TRACE(" Coverage index %i\n",index);
816 const GSUB_LigatureSet *ls;
819 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
820 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
821 count = GET_BE_WORD(ls->LigatureCount);
822 TRACE(" LigatureSet has %i members\n",count);
823 for (k = 0; k < count; k++)
825 const GSUB_Ligature *lig;
826 int CompCount,l,CompIndex;
828 offset = GET_BE_WORD(ls->Ligature[k]);
829 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
830 CompCount = GET_BE_WORD(lig->CompCount) - 1;
831 CompIndex = glyph_index+write_dir;
832 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
835 CompGlyph = GET_BE_WORD(lig->Component[l]);
836 if (CompGlyph != glyphs[CompIndex])
838 CompIndex += write_dir;
842 int replaceIdx = glyph_index;
844 replaceIdx = glyph_index - CompCount;
846 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
847 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
848 TRACE("0x%x\n",glyphs[replaceIdx]);
852 for (j = replaceIdx + 1; j < *glyph_count; j++)
853 glyphs[j] =glyphs[j+CompCount];
854 *glyph_count = *glyph_count - CompCount;
856 return replaceIdx + 1;
861 return GSUB_E_NOGLYPH;
864 static INT GSUB_apply_ChainContextSubst(const GSUB_LookupList* lookup, const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
869 TRACE("Chaining Contextual Substitution Subtable\n");
870 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
872 const GSUB_ChainContextSubstFormat1 *ccsf1;
874 int dirLookahead = write_dir;
875 int dirBacktrack = -1 * write_dir;
877 offset = GET_BE_WORD(look->SubTable[j]);
878 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
879 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
881 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
884 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
886 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
889 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
893 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
894 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
895 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
896 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
897 int newIndex = glyph_index;
899 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
901 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
903 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
905 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
906 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
909 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
911 TRACE("Matched Backtrack\n");
913 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)(((LPBYTE)ccsf1)+sizeof(GSUB_ChainContextSubstFormat3_1) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)-1)));
915 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
916 for (k = 0; k < indexGlyphs; k++)
918 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
919 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
922 if (k != indexGlyphs)
924 TRACE("Matched IndexGlyphs\n");
926 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)(((LPBYTE)ccsf3_2)+sizeof(GSUB_ChainContextSubstFormat3_2) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_2->InputGlyphCount)-1)));
928 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
930 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
931 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
934 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
936 TRACE("Matched LookAhead\n");
938 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)(((LPBYTE)ccsf3_3)+sizeof(GSUB_ChainContextSubstFormat3_3) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)-1)));
940 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
942 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
943 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
945 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
946 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
949 ERR("Chain failed to generate a glyph\n");
959 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
962 const GSUB_LookupTable *look;
964 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
965 look = (const GSUB_LookupTable*)((const BYTE*)lookup + offset);
966 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
967 switch(GET_BE_WORD(look->LookupType))
970 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
972 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
974 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
976 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
978 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
980 return GSUB_E_NOGLYPH;
983 static INT GSUB_apply_feature(const GSUB_Header * header, const GSUB_Feature* feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
986 int out_index = GSUB_E_NOGLYPH;
987 const GSUB_LookupList *lookup;
989 lookup = (const GSUB_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
991 TRACE("%i lookups\n", GET_BE_WORD(feature->LookupCount));
992 for (i = 0; i < GET_BE_WORD(feature->LookupCount); i++)
994 out_index = GSUB_apply_lookup(lookup, GET_BE_WORD(feature->LookupListIndex[i]), glyphs, glyph_index, write_dir, glyph_count);
995 if (out_index != GSUB_E_NOGLYPH)
998 if (out_index == GSUB_E_NOGLYPH)
999 TRACE("lookups found no glyphs\n");
1003 out2 = GSUB_apply_feature(header, feature, glyphs, glyph_index, write_dir, glyph_count);
1004 if (out2!=GSUB_E_NOGLYPH)
1010 static const char* get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
1014 if (psc->userScript != 0)
1016 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0 && strncmp((char*)&psc->userScript,ShapingData[psa->eScript].otTag,4)==0)
1017 return ShapingData[psa->eScript].newOtTag;
1019 return (char*)&psc->userScript;
1022 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0)
1023 return ShapingData[psa->eScript].newOtTag;
1025 if (ShapingData[psa->eScript].otTag[0] != 0)
1026 return ShapingData[psa->eScript].otTag;
1029 * fall back to the font charset
1031 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
1034 case ANSI_CHARSET: return "latn";
1035 case BALTIC_CHARSET: return "latn"; /* ?? */
1036 case CHINESEBIG5_CHARSET: return "hani";
1037 case EASTEUROPE_CHARSET: return "latn"; /* ?? */
1038 case GB2312_CHARSET: return "hani";
1039 case GREEK_CHARSET: return "grek";
1040 case HANGUL_CHARSET: return "hang";
1041 case RUSSIAN_CHARSET: return "cyrl";
1042 case SHIFTJIS_CHARSET: return "kana";
1043 case TURKISH_CHARSET: return "latn"; /* ?? */
1044 case VIETNAMESE_CHARSET: return "latn";
1045 case JOHAB_CHARSET: return "latn"; /* ?? */
1046 case ARABIC_CHARSET: return "arab";
1047 case HEBREW_CHARSET: return "hebr";
1048 case THAI_CHARSET: return "thai";
1049 default: return "latn";
1053 static LPCVOID load_GSUB_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, const char* feat)
1055 const GSUB_Feature *feature;
1058 for (i = 0; i < psc->feature_count; i++)
1059 if (strncmp(psc->features[i].tag,feat,4)==0)
1060 return psc->features[i].feature;
1064 if (psc->GSUB_Table)
1066 const GSUB_Script *script;
1067 const GSUB_LangSys *language;
1072 script = GSUB_get_script_table(psc->GSUB_Table, get_opentype_script(hdc,psa,psc,(attempt==2)));
1076 if (psc->userLang != 0)
1077 language = GSUB_get_lang_table(script,(char*)&psc->userLang);
1079 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1081 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1083 } while(attempt && !feature);
1085 /* try in the default (latin) table */
1088 script = GSUB_get_script_table(psc->GSUB_Table, "latn");
1091 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1093 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1098 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
1100 psc->feature_count++;
1103 psc->features = HeapReAlloc(GetProcessHeap(), 0, psc->features, psc->feature_count * sizeof(LoadedFeature));
1105 psc->features = HeapAlloc(GetProcessHeap(), 0, psc->feature_count * sizeof(LoadedFeature));
1107 lstrcpynA(psc->features[psc->feature_count - 1].tag, feat, 5);
1108 psc->features[psc->feature_count - 1].feature = feature;
1112 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)
1114 const GSUB_Feature *feature;
1116 feature = load_GSUB_feature(hdc, psa, psc, feat);
1118 return GSUB_E_NOFEATURE;
1120 TRACE("applying feature %s\n",feat);
1121 return GSUB_apply_feature(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
1124 static VOID *load_gsub_table(HDC hdc)
1126 VOID* GSUB_Table = NULL;
1127 int length = GetFontData(hdc, GSUB_TAG , 0, NULL, 0);
1128 if (length != GDI_ERROR)
1130 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
1131 GetFontData(hdc, GSUB_TAG , 0, GSUB_Table, length);
1132 TRACE("Loaded GSUB table of %i bytes\n",length);
1137 static WORD GDEF_get_glyph_class(const GDEF_Header *header, WORD glyph)
1141 const GDEF_ClassDefFormat1 *cf1;
1146 offset = GET_BE_WORD(header->GlyphClassDef);
1150 cf1 = (GDEF_ClassDefFormat1*)(((BYTE*)header)+offset);
1151 if (GET_BE_WORD(cf1->ClassFormat) == 1)
1153 if (glyph >= GET_BE_WORD(cf1->StartGlyph))
1155 int index = glyph - GET_BE_WORD(cf1->StartGlyph);
1156 if (index < GET_BE_WORD(cf1->GlyphCount))
1157 class = GET_BE_WORD(cf1->ClassValueArray[index]);
1160 else if (GET_BE_WORD(cf1->ClassFormat) == 2)
1162 const GDEF_ClassDefFormat2 *cf2 = (GDEF_ClassDefFormat2*)cf1;
1164 top = GET_BE_WORD(cf2->ClassRangeCount);
1165 for (i = 0; i < top; i++)
1167 if (glyph >= GET_BE_WORD(cf2->ClassRangeRecord[i].Start) &&
1168 glyph <= GET_BE_WORD(cf2->ClassRangeRecord[i].End))
1170 class = GET_BE_WORD(cf2->ClassRangeRecord[i].Class);
1176 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1->ClassFormat));
1181 static VOID *load_gdef_table(HDC hdc)
1183 VOID* GDEF_Table = NULL;
1184 int length = GetFontData(hdc, GDEF_TAG , 0, NULL, 0);
1185 if (length != GDI_ERROR)
1187 GDEF_Table = HeapAlloc(GetProcessHeap(),0,length);
1188 GetFontData(hdc, GDEF_TAG , 0, GDEF_Table, length);
1189 TRACE("Loaded GDEF table of %i bytes\n",length);
1194 static void GDEF_UpdateGlyphProps(HDC hdc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1196 VOID* header = load_gdef_table(hdc);
1199 for (i = 0; i < cGlyphs; i++)
1203 class = GDEF_get_glyph_class(header, pwGlyphs[i]);
1209 pGlyphProp[i].sva.fClusterStart = 1;
1210 pGlyphProp[i].sva.fDiacritic = 0;
1211 pGlyphProp[i].sva.fZeroWidth = 0;
1214 pGlyphProp[i].sva.fClusterStart = 1;
1215 pGlyphProp[i].sva.fDiacritic = 0;
1216 pGlyphProp[i].sva.fZeroWidth = 0;
1219 pGlyphProp[i].sva.fClusterStart = 0;
1220 pGlyphProp[i].sva.fDiacritic = 1;
1221 pGlyphProp[i].sva.fZeroWidth = 1;
1223 case ComponentGlyph:
1224 pGlyphProp[i].sva.fClusterStart = 0;
1225 pGlyphProp[i].sva.fDiacritic = 0;
1226 pGlyphProp[i].sva.fZeroWidth = 0;
1229 ERR("Unknown glyph class %i\n",class);
1230 pGlyphProp[i].sva.fClusterStart = 1;
1231 pGlyphProp[i].sva.fDiacritic = 0;
1232 pGlyphProp[i].sva.fZeroWidth = 0;
1237 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1241 for (i = 0; i < cGlyphs; i++)
1243 if (!pGlyphProp[i].sva.fClusterStart)
1246 for (j = 0; j < cChars; j++)
1248 if (pwLogClust[j] == i)
1251 while (!pGlyphProp[pwLogClust[k]].sva.fClusterStart && k >= 0 && k <cChars)
1253 if (pGlyphProp[pwLogClust[k]].sva.fClusterStart)
1254 pwLogClust[j] = pwLogClust[k];
1261 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
1263 if (changeCount == 0)
1268 int target_glyph = nextIndex - 1;
1269 int target_index = -1;
1270 int replacing_glyph = -1;
1274 for (i = 0; i < chars; i++)
1276 if (pwLogClust[i] == target_glyph)
1283 for (i = chars - 1; i >= 0; i--)
1285 if (pwLogClust[i] == target_glyph)
1291 if (target_index == -1)
1293 ERR("Unable to find target glyph\n");
1297 if (changeCount < 0)
1300 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1302 if (pwLogClust[i] == target_glyph)
1304 if(pwLogClust[i] == replacing_glyph)
1305 pwLogClust[i] = target_glyph;
1309 if (changed >= changeCount)
1311 replacing_glyph = pwLogClust[i];
1312 pwLogClust[i] = target_glyph;
1320 /* renumber trailing indexes*/
1321 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1323 if (pwLogClust[i] != target_glyph)
1324 pwLogClust[i] += changeCount;
1329 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 )
1333 if (psc->GSUB_Table)
1335 const GSUB_Feature *feature;
1337 feature = load_GSUB_feature(hdc, psa, psc, feat);
1339 return GSUB_E_NOFEATURE;
1342 TRACE("applying feature %s\n",debugstr_an(feat,4));
1343 while(i < *pcGlyphs)
1346 INT prevCount = *pcGlyphs;
1347 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, i, write_dir, pcGlyphs);
1348 if (nextIndex > GSUB_E_NOGLYPH)
1350 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
1358 return GSUB_E_NOFEATURE;
1361 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
1365 if ( i+ delta >= cchLen)
1373 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
1377 if (psa->fLinkBefore)
1382 if ( i+ delta >= cchLen)
1384 if (psa->fLinkAfter)
1392 if (context_type[i] == jtT)
1393 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
1395 return context_type[i];
1398 static inline BOOL right_join_causing(CHAR joining_type)
1400 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
1403 static inline BOOL left_join_causing(CHAR joining_type)
1405 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
1408 static inline BOOL word_break_causing(WCHAR chr)
1410 /* we are working within a string of characters already guareented to
1411 be within one script, Syriac, so we do not worry about any characers
1412 other than the space character outside of that range */
1413 return (chr == 0 || chr == 0x20 );
1417 * ContextualShape_Arabic
1419 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1426 if (*pcGlyphs != cChars)
1428 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1432 if (!psa->fLogicalOrder && psa->fRTL)
1443 if (!psc->GSUB_Table)
1444 psc->GSUB_Table = load_gsub_table(hdc);
1446 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1447 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1449 for (i = 0; i < cChars; i++)
1450 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1452 for (i = 0; i < cChars; i++)
1454 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1455 context_shape[i] = Xr;
1456 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1457 context_shape[i] = Xl;
1458 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)))
1459 context_shape[i] = Xm;
1460 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1461 context_shape[i] = Xr;
1462 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1463 context_shape[i] = Xl;
1465 context_shape[i] = Xn;
1468 /* Contextual Shaping */
1470 while(i < *pcGlyphs)
1472 BOOL shaped = FALSE;
1474 if (psc->GSUB_Table)
1477 INT prevCount = *pcGlyphs;
1478 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1479 if (nextIndex > GSUB_E_NOGLYPH)
1482 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1484 shaped = (nextIndex > GSUB_E_NOGLYPH);
1489 WORD newGlyph = pwOutGlyphs[i];
1490 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1492 /* fall back to presentation form B */
1493 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1494 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1495 pwOutGlyphs[i] = newGlyph;
1501 HeapFree(GetProcessHeap(),0,context_shape);
1502 HeapFree(GetProcessHeap(),0,context_type);
1506 * ContextualShape_Syriac
1510 #define DALATH 0x715
1513 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1520 if (*pcGlyphs != cChars)
1522 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1526 if (!psa->fLogicalOrder && psa->fRTL)
1537 if (!psc->GSUB_Table)
1538 psc->GSUB_Table = load_gsub_table(hdc);
1540 if (!psc->GSUB_Table)
1543 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1544 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1546 for (i = 0; i < cChars; i++)
1547 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1549 for (i = 0; i < cChars; i++)
1551 if (pwcChars[i] == ALAPH)
1553 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1555 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1556 context_shape[i] = Afj;
1557 else if ( rchar != DALATH && rchar != RISH &&
1558 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1559 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1560 context_shape[i] = Afn;
1561 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1562 context_shape[i] = Afx;
1564 context_shape[i] = Xn;
1566 else if (context_type[i] == jtR &&
1567 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1568 context_shape[i] = Xr;
1569 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1570 context_shape[i] = Xl;
1571 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)))
1572 context_shape[i] = Xm;
1573 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1574 context_shape[i] = Xr;
1575 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1576 context_shape[i] = Xl;
1578 context_shape[i] = Xn;
1581 /* Contextual Shaping */
1583 while(i < *pcGlyphs)
1586 INT prevCount = *pcGlyphs;
1587 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1588 if (nextIndex > GSUB_E_NOGLYPH)
1590 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1597 HeapFree(GetProcessHeap(),0,context_shape);
1598 HeapFree(GetProcessHeap(),0,context_type);
1602 * ContextualShape_Phags_pa
1605 #define phags_pa_CANDRABINDU 0xA873
1606 #define phags_pa_START 0xA840
1607 #define phags_pa_END 0xA87F
1609 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1615 if (*pcGlyphs != cChars)
1617 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1621 if (!psa->fLogicalOrder && psa->fRTL)
1632 if (!psc->GSUB_Table)
1633 psc->GSUB_Table = load_gsub_table(hdc);
1635 if (!psc->GSUB_Table)
1638 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1640 for (i = 0; i < cChars; i++)
1642 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1644 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1645 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1646 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1647 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1649 if (jrchar && jlchar)
1650 context_shape[i] = Xm;
1652 context_shape[i] = Xr;
1654 context_shape[i] = Xl;
1656 context_shape[i] = Xn;
1659 context_shape[i] = -1;
1662 /* Contextual Shaping */
1664 while(i < *pcGlyphs)
1666 if (context_shape[i] >= 0)
1669 INT prevCount = *pcGlyphs;
1670 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1671 if (nextIndex > GSUB_E_NOGLYPH)
1673 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1683 HeapFree(GetProcessHeap(),0,context_shape);
1686 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1691 pwOutChars[cWalk] = replacements[0];
1695 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1698 for (j = *pcChars; j > cWalk; j--)
1699 pwOutChars[j] = pwOutChars[j-1];
1700 *pcChars= *pcChars+1;
1701 pwOutChars[cWalk] = replacements[i];
1706 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[])
1711 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1713 for (i = 0; vowels[i].base != 0x0; i++)
1715 if (pwOutChars[cWalk] == vowels[i].base)
1717 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1724 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[])
1729 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1731 for (i = 0; consonants[i].output!= 0x0; i++)
1734 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1735 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1738 if (consonants[i].parts[j]==0x0) /* matched all */
1742 pwOutChars[cWalk] = consonants[i].output;
1743 for(k = cWalk+1; k < *pcChars - j; k++)
1744 pwOutChars[k] = pwOutChars[k+j];
1745 *pcChars = *pcChars - j;
1753 static void Reorder_Ra_follows_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1755 if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
1758 WORD Ra = pwChar[start];
1759 WORD H = pwChar[start+1];
1761 TRACE("Doing reorder of Ra to %i\n",main);
1762 for (j = start; j < main-1; j++)
1763 pwChar[j] = pwChar[j+2];
1764 pwChar[main-1] = Ra;
1769 static void Reorder_Ra_follows_mantra_post(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1771 if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
1774 WORD Ra = pwChar[start];
1775 WORD H = pwChar[start+1];
1776 for (loc = main; loc > end; loc++)
1777 if (lexical(pwChar[loc]) == lex_Mantra_post)
1779 if (loc == end) loc = main;
1781 TRACE("Doing reorder of Ra to %i\n",loc);
1782 for (j = start; j < loc-1; j++)
1783 pwChar[j] = pwChar[j+2];
1789 static void Reorder_Mantra_precede_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1793 /* reorder Mantras */
1796 for (i = 1; i <= end-main; i++)
1798 if (lexical(pwChar[main+i]) == lex_Mantra_pre)
1801 WCHAR c = pwChar[main+i];
1802 TRACE("Doing reorder of %x %x\n",c,pwChar[main]);
1803 for (j = main+i; j > main; j--)
1804 pwChar[j] = pwChar[j-1];
1811 static void Reorder_Mantra_precede_syllable(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1815 /* reorder Mantras */
1818 for (i = 1; i <= end-main; i++)
1820 if (lexical(pwChar[main+i]) == lex_Mantra_pre)
1823 WCHAR c = pwChar[main+i];
1824 TRACE("Doing reorder of %x to %i\n",c,start);
1825 for (j = main+i; j > start; j--)
1826 pwChar[j] = pwChar[j-1];
1833 static void Reorder_Like_Sinhala(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1835 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1836 if (start == main && main == end) return;
1838 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1839 if (lexical(pwChar[main]) == lex_Vowel) return;
1841 Reorder_Ra_follows_base(pwChar, start, main, end, lexical);
1842 Reorder_Mantra_precede_base(pwChar, start, main, end, lexical);
1845 static void Reorder_Like_Devanagari(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1847 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1848 if (start == main && main == end) return;
1850 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1851 if (lexical(pwChar[main]) == lex_Vowel) return;
1853 Reorder_Ra_follows_mantra_post(pwChar, start, main, end, lexical);
1854 Reorder_Mantra_precede_syllable(pwChar, start, main, end, lexical);
1857 static void Reorder_Like_Bengali(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1859 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1860 if (start == main && main == end) return;
1862 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1863 if (lexical(pwChar[main]) == lex_Vowel) return;
1865 Reorder_Ra_follows_base(pwChar, start, main, end, lexical);
1866 Reorder_Mantra_precede_syllable(pwChar, start, main, end, lexical);
1869 static int sinhala_lex(WCHAR c)
1873 case 0x0DCA: return lex_Halant;
1876 case 0x0DD8: return lex_Mantra_post;
1878 case 0x0DDB: return lex_Mantra_pre;
1880 case 0x0DDC: return lex_Composed_Vowel;
1881 case 0x200D: return lex_ZWJ;
1882 case 0x200C: return lex_ZWNJ;
1883 case 0x00A0: return lex_NBSP;
1885 if (c>=0x0D82 && c <=0x0D83) return lex_Modifier;
1886 else if (c>=0x0D85 && c <=0x0D96) return lex_Vowel;
1887 else if (c>=0x0D96 && c <=0x0DC6) return lex_Consonant;
1888 else if (c>=0x0DD0 && c <=0x0DD1) return lex_Mantra_post;
1889 else if (c>=0x0DD2 && c <=0x0DD3) return lex_Mantra_above;
1890 else if (c>=0x0DD4 && c <=0x0DD6) return lex_Mantra_below;
1891 else if (c>=0x0DDD && c <=0x0DDE) return lex_Composed_Vowel;
1892 else if (c>=0x0DF2 && c <=0x0DF3) return lex_Mantra_post;
1893 else return lex_Generic;
1897 static const VowelComponents Sinhala_vowels[] = {
1898 {0x0DDA, {0x0DD9,0x0DCA,0x0}},
1899 {0x0DDC, {0x0DD9,0x0DCF,0x0}},
1900 {0x0DDD, {0x0DD9,0x0DCF,0x0DCA}},
1901 {0x0DDE, {0x0DD9,0x0DDF,0x0}},
1902 {0x0000, {0x0000,0x0000,0x0}}};
1904 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1906 int cCount = cChars;
1909 if (*pcGlyphs != cChars)
1911 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1915 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
1917 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
1919 /* Step 1: Decompose multi part vowels */
1920 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels);
1922 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
1924 /* Step 2: Reorder within Syllables */
1925 Indic_ReorderCharacters( input, cCount, sinhala_lex, Reorder_Like_Sinhala);
1926 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
1928 /* Step 3: Get glyphs */
1929 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
1932 HeapFree(GetProcessHeap(),0,input);
1935 static int devanagari_lex(WCHAR c)
1941 case 0x0903: return lex_Modifier;
1942 case 0x0930: return lex_Ra;
1943 case 0x093C: return lex_Nukta;
1945 case 0x093E: return lex_Mantra_post;
1946 case 0x093F: return lex_Mantra_pre;
1947 case 0x094D: return lex_Halant;
1948 case 0x0972: return lex_Vowel;
1949 case 0x200C: return lex_ZWNJ;
1950 case 0x200D: return lex_ZWJ;
1952 if (c>=0x0901 && c<=0x0902) return lex_Mantra_above;
1953 else if (c>=0x0904 && c<=0x0914) return lex_Vowel;
1954 else if (c>=0x0915 && c<=0x0939) return lex_Consonant;
1955 else if (c>=0x0941 && c<=0x0944) return lex_Mantra_below;
1956 else if (c>=0x0945 && c<=0x0948) return lex_Mantra_above;
1957 else if (c>=0x0949 && c<=0x094C) return lex_Mantra_post;
1958 else if (c>=0x0953 && c<=0x0954) return lex_Modifier;
1959 else if (c>=0x0958 && c<=0x095F) return lex_Consonant;
1960 else if (c>=0x0960 && c<=0x0961) return lex_Vowel;
1961 else if (c>=0x0962 && c<=0x0963) return lex_Mantra_below;
1962 else if (c>=0x097B && c<=0x097C) return lex_Consonant;
1963 else if (c>=0x097E && c<=0x097F) return lex_Consonant;
1964 else return lex_Generic;
1968 static const ConsonantComponents Devanagari_consonants[] ={
1969 {{0x0928, 0x093C, 0x00000}, 0x0929},
1970 {{0x0930, 0x093C, 0x00000}, 0x0931},
1971 {{0x0933, 0x093C, 0x00000}, 0x0934},
1972 {{0x0915, 0x093C, 0x00000}, 0x0958},
1973 {{0x0916, 0x093C, 0x00000}, 0x0959},
1974 {{0x0917, 0x093C, 0x00000}, 0x095A},
1975 {{0x091C, 0x093C, 0x00000}, 0x095B},
1976 {{0x0921, 0x093C, 0x00000}, 0x095C},
1977 {{0x0922, 0x093C, 0x00000}, 0x095D},
1978 {{0x092B, 0x093C, 0x00000}, 0x095E},
1979 {{0x092F, 0x093C, 0x00000}, 0x095F}};
1981 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1983 int cCount = cChars;
1986 if (*pcGlyphs != cChars)
1988 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1992 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
1993 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
1995 /* Step 1: Compose Consonant and Nukta */
1996 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants);
1997 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
1999 /* Step 2: Reorder within Syllables */
2000 Indic_ReorderCharacters( input, cCount, devanagari_lex, Reorder_Like_Devanagari);
2001 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2002 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2005 HeapFree(GetProcessHeap(),0,input);
2008 static int bengali_lex(WCHAR c)
2012 case 0x0981: return lex_Modifier;
2015 case 0x09CE: return lex_Consonant;
2016 case 0x09B0: return lex_Ra;
2017 case 0x09BC: return lex_Nukta;
2018 case 0x09BF: return lex_Mantra_pre;
2021 case 0x09C0: return lex_Mantra_post;
2022 case 0x09CD: return lex_Halant;
2023 case 0x200C: return lex_ZWNJ;
2024 case 0x200D: return lex_ZWJ;
2026 if (c>=0x0982 && c<=0x0983) return lex_Mantra_post;
2027 else if (c>=0x0985 && c<=0x0994) return lex_Vowel;
2028 else if (c>=0x0995 && c<=0x09B9) return lex_Consonant;
2029 else if (c>=0x09C1 && c<=0x09C4) return lex_Mantra_below;
2030 else if (c>=0x09C7 && c<=0x09C8) return lex_Mantra_pre;
2031 else if (c>=0x09DC && c<=0x09DF) return lex_Consonant;
2032 else if (c>=0x09E0 && c<=0x09E1) return lex_Vowel;
2033 else if (c>=0x09E2 && c<=0x09E3) return lex_Mantra_below;
2034 else if (c>=0x09F0 && c<=0x09F1) return lex_Consonant;
2035 else return lex_Generic;
2039 static const VowelComponents Bengali_vowels[] = {
2040 {0x09CB, {0x09C7,0x09BE,0x0000}},
2041 {0x09CC, {0x09C7,0x09D7,0x0000}},
2042 {0x0000, {0x0000,0x0000,0x0000}}};
2044 static const ConsonantComponents Bengali_consonants[] = {
2045 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2046 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2047 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2048 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2049 {{0x0000,0x0000,0x0000}, 0x0000}};
2051 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2053 int cCount = cChars;
2056 if (*pcGlyphs != cChars)
2058 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2062 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2063 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2065 /* Step 1: Decompose Vowels and Compose Consonents */
2066 DecomposeVowels(hdc, input, &cCount, Bengali_vowels);
2067 ComposeConsonants(hdc, input, &cCount, Bengali_consonants);
2068 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2070 /* Step 2: Reorder within Syllables */
2071 Indic_ReorderCharacters( input, cCount, bengali_lex, Reorder_Like_Bengali);
2072 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2073 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2076 HeapFree(GetProcessHeap(),0,input);
2079 static int gurmukhi_lex(WCHAR c)
2083 case 0x0A2f: return lex_Consonant;
2086 case 0x0A39: return lex_Ra;
2087 case 0x0A3C: return lex_Nukta;
2088 case 0x0A3F: return lex_Mantra_pre;
2091 case 0x0A40: return lex_Mantra_post;
2092 case 0x0A4D: return lex_Halant;
2094 case 0x0A71: return lex_Modifier;
2095 case 0x200C: return lex_ZWNJ;
2096 case 0x200D: return lex_ZWJ;
2098 if (c>=0x0A01 && c<=0x0A02) return lex_Modifier;
2099 else if (c>=0x0A05 && c<=0x0A14) return lex_Vowel;
2100 else if (c>=0x0A15 && c<=0x0A38) return lex_Consonant;
2101 else if (c>=0x0A41 && c<=0x0A42) return lex_Mantra_below;
2102 else if (c>=0x0A47 && c<=0x0A4C) return lex_Mantra_above;
2103 else if (c>=0x0A59 && c<=0x0A5E) return lex_Consonant;
2104 else return lex_Generic;
2108 static const ConsonantComponents Gurmukhi_consonants[] = {
2109 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2110 {{0x0A38,0x0A3C,0x0000}, 0x0A36},
2111 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2112 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2113 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2114 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2115 {{0x0000,0x0000,0x0000}, 0x0000}};
2117 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2119 int cCount = cChars;
2122 if (*pcGlyphs != cChars)
2124 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2128 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2129 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2131 /* Step 1: Compose Consonents */
2132 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants);
2133 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2135 /* Step 2: Reorder within Syllables */
2136 Indic_ReorderCharacters( input, cCount, gurmukhi_lex, Reorder_Like_Bengali);
2137 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2138 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2141 HeapFree(GetProcessHeap(),0,input);
2144 static int gujarati_lex(WCHAR c)
2148 case 0x0A83: return lex_Modifier;
2149 case 0x0AB0: return lex_Ra;
2150 case 0x0ABC: return lex_Nukta;
2151 case 0x0ABF: return lex_Mantra_pre;
2153 case 0x0AC0: return lex_Mantra_post;
2154 case 0x0ACD: return lex_Halant;
2155 case 0x200C: return lex_ZWNJ;
2156 case 0x200D: return lex_ZWJ;
2158 if (c>=0x0A81 && c<=0x0A82) return lex_Modifier;
2159 else if (c>=0x0A85 && c<=0x0A94) return lex_Vowel;
2160 else if (c>=0x0A95 && c<=0x0AB9) return lex_Consonant;
2161 else if (c>=0x0AC1 && c<=0x0AC4) return lex_Mantra_below;
2162 else if (c>=0x0AC5 && c<=0x0AC8) return lex_Mantra_above;
2163 else if (c>=0x0AC9 && c<=0x0ACC) return lex_Mantra_post;
2164 else if (c>=0x0AE0 && c<=0x0AE1) return lex_Vowel;
2165 else if (c>=0x0AE2 && c<=0x0AE3) return lex_Mantra_below;
2166 else return lex_Generic;
2170 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2172 int cCount = cChars;
2175 if (*pcGlyphs != cChars)
2177 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2181 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2182 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2184 /* Step 1: Reorder within Syllables */
2185 Indic_ReorderCharacters( input, cCount, gujarati_lex, Reorder_Like_Devanagari);
2186 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2187 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2190 HeapFree(GetProcessHeap(),0,input);
2193 static int oriya_lex(WCHAR c)
2202 case 0x0B33: return lex_Consonant;
2203 case 0x0B30: return lex_Ra;
2204 case 0x0B3C: return lex_Nukta;
2206 case 0x0B56: return lex_Mantra_above;
2208 case 0x0B40: return lex_Mantra_post;
2210 case 0x0B57: return lex_Mantra_pre;
2211 case 0x0B4D: return lex_Halant;
2212 case 0x200C: return lex_ZWNJ;
2213 case 0x200D: return lex_ZWJ;
2215 if (c>=0x0B01 && c<=0x0B03) return lex_Modifier;
2216 else if (c>=0x0B05 && c<=0x0B14) return lex_Vowel;
2217 else if (c>=0x0B15 && c<=0x0B39) return lex_Consonant;
2218 else if (c>=0x0B2C && c<=0x0B2E) return lex_Consonant;
2219 else if (c>=0x0B32 && c<=0x0B33) return lex_Consonant;
2220 else if (c>=0x0B41 && c<=0x0B44) return lex_Mantra_below;
2221 else if (c>=0x0B48 && c<=0x0B4C) return lex_Composed_Vowel;
2222 else if (c>=0x0B5C && c<=0x0B5D) return lex_Consonant;
2223 else if (c>=0x0B60 && c<=0x0B61) return lex_Vowel;
2224 else if (c>=0x0B62 && c<=0x0B63) return lex_Mantra_below;
2225 else return lex_Generic;
2229 static const VowelComponents Oriya_vowels[] = {
2230 {0x0B48, {0x0B47,0x0B56,0x0000}},
2231 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2232 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2233 {0x0000, {0x0000,0x0000,0x0000}}};
2235 static const ConsonantComponents Oriya_consonants[] = {
2236 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2237 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2238 {{0x0000,0x0000,0x0000}, 0x0000}};
2240 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2242 int cCount = cChars;
2245 if (*pcGlyphs != cChars)
2247 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2251 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2252 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2254 /* Step 1: Decompose Vowels and Compose Consonents */
2255 DecomposeVowels(hdc, input, &cCount, Oriya_vowels);
2256 ComposeConsonants(hdc, input, &cCount, Oriya_consonants);
2257 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2259 /* Step 2: Reorder within Syllables */
2260 Indic_ReorderCharacters( input, cCount, oriya_lex, Reorder_Like_Bengali);
2261 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2262 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2265 HeapFree(GetProcessHeap(),0,input);
2268 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)
2272 for (i = 0; i < cGlyphs; i++)
2277 for (k = 0; k < cChars; k++)
2279 if (pwLogClust[k] == i)
2281 char_index[char_count] = k;
2286 if (char_count == 0)
2288 FIXME("No chars in this glyph? Must be an error\n");
2292 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2294 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2295 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2298 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2301 GDEF_UpdateGlyphProps(hdc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2302 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2305 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 )
2308 int initGlyph, finaGlyph;
2312 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2313 memset(spaces,0,cGlyphs);
2315 if (!psa->fLogicalOrder && psa->fRTL)
2317 initGlyph = cGlyphs-1;
2325 finaGlyph = cGlyphs-1;
2330 for (i = 0; i < cGlyphs; i++)
2332 for (k = 0; k < cChars; k++)
2333 if (pwLogClust[k] == i)
2335 if (pwcChars[k] == 0x0020)
2340 for (i = 0; i < cGlyphs; i++)
2344 BOOL isInit, isFinal;
2346 for (k = 0; k < cChars; k++)
2348 if (pwLogClust[k] == i)
2350 char_index[char_count] = k;
2355 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
2356 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
2358 if (char_count == 0)
2360 FIXME("No chars in this glyph? Must be an error\n");
2364 if (char_count == 1)
2366 if (pwcChars[char_index[0]] == 0x0020) /* space */
2368 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
2369 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2371 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
2372 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
2373 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
2375 if (!isInit && !isFinal)
2376 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
2378 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
2380 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2384 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
2385 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
2386 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
2387 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
2388 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
2389 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
2390 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
2391 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
2393 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2395 else if (!isInit && !isFinal)
2396 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2398 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2400 else if (char_count == 2)
2402 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
2403 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
2405 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2407 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2409 else if (!isInit && !isFinal)
2410 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2412 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2415 GDEF_UpdateGlyphProps(hdc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2416 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2417 HeapFree(GetProcessHeap(),0,spaces);
2420 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 )
2427 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2428 memset(spaces,0,cGlyphs);
2430 if (!psa->fLogicalOrder && psa->fRTL)
2437 finaGlyph = cGlyphs-1;
2441 for (i = 0; i < cGlyphs; i++)
2443 for (k = 0; k < cChars; k++)
2444 if (pwLogClust[k] == i)
2446 if (pwcChars[k] == 0x0020)
2451 for (i = 0; i < cGlyphs; i++)
2456 for (k = 0; k < cChars; k++)
2458 if (pwLogClust[k] == i)
2460 char_index[char_count] = k;
2465 if (char_count == 0)
2467 FIXME("No chars in this glyph? Must be an error\n");
2471 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2473 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2474 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2476 else if (i == finaGlyph)
2477 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2479 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2482 HeapFree(GetProcessHeap(),0,spaces);
2483 GDEF_UpdateGlyphProps(hdc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2484 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2486 /* Do not allow justification between marks and their base */
2487 for (i = 0; i < cGlyphs; i++)
2489 if (!pGlyphProp[i].sva.fClusterStart)
2490 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2494 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)
2498 for (i = 0; i < cGlyphs; i++)
2503 for (k = 0; k < cChars; k++)
2505 if (pwLogClust[k] == i)
2507 char_index[char_count] = k;
2512 if (char_count == 0)
2514 FIXME("No chars in this glyph? Must be an error\n");
2518 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2520 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2521 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2524 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2526 GDEF_UpdateGlyphProps(hdc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2527 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2530 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)
2534 for (i = 0; i < cGlyphs; i++)
2539 for (k = 0; k < cChars; k++)
2541 if (pwLogClust[k] == i)
2543 char_index[char_count] = k;
2548 if (char_count == 0)
2550 FIXME("No chars in this glyph? Must be an error\n");
2554 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2556 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2557 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2560 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2562 GDEF_UpdateGlyphProps(hdc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2563 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2565 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
2566 for (i = 0; i < cGlyphs; i++)
2568 if (!pGlyphProp[i].sva.fClusterStart)
2570 pGlyphProp[i].sva.fDiacritic = 0;
2571 pGlyphProp[i].sva.fZeroWidth = 0;
2576 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)
2580 for (i = 0; i < cGlyphs; i++)
2585 for (k = 0; k < cChars; k++)
2587 if (pwLogClust[k] == i)
2589 char_index[char_count] = k;
2594 if (char_count == 0)
2596 FIXME("No chars in this glyph? Must be an error\n");
2600 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2602 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2603 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2606 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2608 pGlyphProp[i].sva.fClusterStart = 0;
2609 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
2610 switch (lexical(pwcChars[char_index[k]]))
2612 case lex_Mantra_pre:
2613 case lex_Mantra_post:
2614 case lex_Mantra_above:
2615 case lex_Mantra_below:
2619 pGlyphProp[i].sva.fClusterStart = 1;
2623 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2626 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 )
2628 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex);
2631 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 )
2633 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex);
2636 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 )
2638 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex);
2641 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 )
2643 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex);
2646 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 )
2648 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex);
2651 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)
2653 if (ShapingData[psa->eScript].charGlyphPropProc)
2654 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
2656 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
2659 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2661 if (ShapingData[psa->eScript].contextProc)
2662 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
2665 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)
2670 if (!rpRangeProperties)
2673 if (!psc->GSUB_Table)
2674 psc->GSUB_Table = load_gsub_table(hdc);
2676 if (!psc->GSUB_Table)
2679 if (!psa->fLogicalOrder && psa->fRTL)
2684 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
2686 if (rpRangeProperties->potfRecords[i].lParameter > 0)
2687 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
2691 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
2693 const TEXTRANGE_PROPERTIES *rpRangeProperties;
2694 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
2696 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
2699 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
2701 const GSUB_Feature *feature;
2704 if (!ShapingData[psa->eScript].requiredFeatures)
2707 if (!psc->GSUB_Table)
2708 psc->GSUB_Table = load_gsub_table(hdc);
2710 /* we need to have at least one of the required features */
2712 while (ShapingData[psa->eScript].requiredFeatures[i])
2714 feature = load_GSUB_feature(hdc, psa, psc, ShapingData[psa->eScript].requiredFeatures[i]);
2720 return USP_E_SCRIPT_NOT_IN_FONT;