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('a','k','h','n'), 1},
379 { MS_MAKE_TAG('r','p','h','f'), 1},
380 { MS_MAKE_TAG('v','a','t','u'), 1},
381 { MS_MAKE_TAG('p','s','t','f'), 1},
382 /* Presentation forms */
383 { MS_MAKE_TAG('b','l','w','s'), 1},
384 { MS_MAKE_TAG('a','b','v','s'), 1},
385 { MS_MAKE_TAG('p','s','t','s'), 1},
388 static OPENTYPE_FEATURE_RECORD tibetan_features[] =
390 { MS_MAKE_TAG('a','b','v','s'), 1},
391 { MS_MAKE_TAG('b','l','w','s'), 1},
394 static OPENTYPE_FEATURE_RECORD thai_features[] =
396 { MS_MAKE_TAG('c','c','m','p'), 1},
399 static const char* required_lao_features[] =
405 static const char* required_devanagari_features[] =
421 static OPENTYPE_FEATURE_RECORD devanagari_features[] =
423 /* Localized forms */
424 { MS_MAKE_TAG('l','o','c','l'), 1},
426 { MS_MAKE_TAG('n','u','k','t'), 1},
427 { MS_MAKE_TAG('a','k','h','n'), 1},
428 { MS_MAKE_TAG('r','p','h','f'), 1},
429 { MS_MAKE_TAG('r','k','r','f'), 1},
430 { MS_MAKE_TAG('b','l','w','f'), 1},
431 { MS_MAKE_TAG('h','a','l','f'), 1},
432 { MS_MAKE_TAG('v','a','t','u'), 1},
433 { MS_MAKE_TAG('c','j','c','t'), 1},
434 /* Presentation forms */
435 { MS_MAKE_TAG('p','r','e','s'), 1},
436 { MS_MAKE_TAG('a','b','v','s'), 1},
437 { MS_MAKE_TAG('b','l','w','s'), 1},
438 { MS_MAKE_TAG('p','s','t','s'), 1},
439 { MS_MAKE_TAG('h','a','l','n'), 1},
440 { MS_MAKE_TAG('c','a','l','t'), 1},
443 static const char* required_bengali_features[] =
460 static OPENTYPE_FEATURE_RECORD bengali_features[] =
462 /* Localized forms */
463 { MS_MAKE_TAG('l','o','c','l'), 1},
465 { MS_MAKE_TAG('n','u','k','t'), 1},
466 { MS_MAKE_TAG('a','k','h','n'), 1},
467 { MS_MAKE_TAG('r','p','h','f'), 1},
468 { MS_MAKE_TAG('b','l','w','f'), 1},
469 { MS_MAKE_TAG('p','s','t','f'), 1},
470 { MS_MAKE_TAG('h','a','l','f'), 1},
471 { MS_MAKE_TAG('v','a','t','u'), 1},
472 { MS_MAKE_TAG('c','j','c','t'), 1},
473 /* Presentation forms */
474 { MS_MAKE_TAG('p','r','e','s'), 1},
475 { MS_MAKE_TAG('a','b','v','s'), 1},
476 { MS_MAKE_TAG('b','l','w','s'), 1},
477 { MS_MAKE_TAG('p','s','t','s'), 1},
478 { MS_MAKE_TAG('h','a','l','n'), 1},
479 { MS_MAKE_TAG('c','a','l','t'), 1},
482 static const char* required_gurmukhi_features[] =
501 static OPENTYPE_FEATURE_RECORD gurmukhi_features[] =
503 /* Localized forms */
504 { MS_MAKE_TAG('l','o','c','l'), 1},
506 { MS_MAKE_TAG('n','u','k','t'), 1},
507 { MS_MAKE_TAG('a','k','h','n'), 1},
508 { MS_MAKE_TAG('r','p','h','f'), 1},
509 { MS_MAKE_TAG('b','l','w','f'), 1},
510 { MS_MAKE_TAG('p','s','t','f'), 1},
511 { MS_MAKE_TAG('h','a','l','f'), 1},
512 { MS_MAKE_TAG('v','a','t','u'), 1},
513 { MS_MAKE_TAG('c','j','c','t'), 1},
514 /* Presentation forms */
515 { MS_MAKE_TAG('p','r','e','s'), 1},
516 { MS_MAKE_TAG('a','b','v','s'), 1},
517 { MS_MAKE_TAG('b','l','w','s'), 1},
518 { MS_MAKE_TAG('p','s','t','s'), 1},
519 { MS_MAKE_TAG('h','a','l','n'), 1},
520 { MS_MAKE_TAG('c','a','l','t'), 1},
523 static const char* required_oriya_features[] =
540 static OPENTYPE_FEATURE_RECORD oriya_features[] =
542 /* Localized forms */
543 { MS_MAKE_TAG('l','o','c','l'), 1},
545 { MS_MAKE_TAG('n','u','k','t'), 1},
546 { MS_MAKE_TAG('a','k','h','n'), 1},
547 { MS_MAKE_TAG('r','p','h','f'), 1},
548 { MS_MAKE_TAG('b','l','w','f'), 1},
549 { MS_MAKE_TAG('p','s','t','f'), 1},
550 { MS_MAKE_TAG('c','j','c','t'), 1},
551 /* Presentation forms */
552 { MS_MAKE_TAG('p','r','e','s'), 1},
553 { MS_MAKE_TAG('a','b','v','s'), 1},
554 { MS_MAKE_TAG('b','l','w','s'), 1},
555 { MS_MAKE_TAG('p','s','t','s'), 1},
556 { MS_MAKE_TAG('h','a','l','n'), 1},
557 { MS_MAKE_TAG('c','a','l','t'), 1},
560 static const char* required_tamil_features[] =
576 static OPENTYPE_FEATURE_RECORD tamil_features[] =
578 /* Localized forms */
579 { MS_MAKE_TAG('l','o','c','l'), 1},
581 { MS_MAKE_TAG('n','u','k','t'), 1},
582 { MS_MAKE_TAG('a','k','h','n'), 1},
583 { MS_MAKE_TAG('r','p','h','f'), 1},
584 { MS_MAKE_TAG('p','r','e','f'), 1},
585 { MS_MAKE_TAG('h','a','l','f'), 1},
586 /* Presentation forms */
587 { MS_MAKE_TAG('p','r','e','s'), 1},
588 { MS_MAKE_TAG('a','b','v','s'), 1},
589 { MS_MAKE_TAG('b','l','w','s'), 1},
590 { MS_MAKE_TAG('p','s','t','s'), 1},
591 { MS_MAKE_TAG('h','a','l','n'), 1},
592 { MS_MAKE_TAG('c','a','l','t'), 1},
595 static const char* required_telugu_features[] =
613 static OPENTYPE_FEATURE_RECORD telugu_features[] =
615 /* Localized forms */
616 { MS_MAKE_TAG('l','o','c','l'), 1},
618 { MS_MAKE_TAG('n','u','k','t'), 1},
619 { MS_MAKE_TAG('a','k','h','n'), 1},
620 { MS_MAKE_TAG('r','p','h','f'), 1},
621 { MS_MAKE_TAG('p','r','e','f'), 1},
622 { MS_MAKE_TAG('b','l','w','f'), 1},
623 { MS_MAKE_TAG('p','s','t','f'), 1},
624 { MS_MAKE_TAG('h','a','l','f'), 1},
625 { MS_MAKE_TAG('c','j','c','t'), 1},
626 /* Presentation forms */
627 { MS_MAKE_TAG('p','r','e','s'), 1},
628 { MS_MAKE_TAG('a','b','v','s'), 1},
629 { MS_MAKE_TAG('b','l','w','s'), 1},
630 { MS_MAKE_TAG('p','s','t','s'), 1},
631 { MS_MAKE_TAG('h','a','l','n'), 1},
632 { MS_MAKE_TAG('c','a','l','t'), 1},
635 typedef struct ScriptShapeDataTag {
636 TEXTRANGE_PROPERTIES defaultTextRange;
637 const char** requiredFeatures;
640 ContextualShapingProc contextProc;
641 ShapeCharGlyphPropProc charGlyphPropProc;
644 /* in order of scripts */
645 static const ScriptShapeData ShapingData[] =
647 {{ standard_features, 2}, NULL, "", "", NULL, NULL},
648 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
649 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
650 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
651 {{ standard_features, 2}, NULL, "" , "", NULL, NULL},
652 {{ standard_features, 2}, NULL, "latn", "", NULL, NULL},
653 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
654 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
655 {{ hebrew_features, 1}, NULL, "hebr", "", NULL, NULL},
656 {{ syriac_features, 4}, required_syriac_features, "syrc", "", ContextualShape_Syriac, ShapeCharGlyphProp_None},
657 {{ arabic_features, 6}, required_arabic_features, "arab", "", ContextualShape_Arabic, ShapeCharGlyphProp_Arabic},
658 {{ NULL, 0}, NULL, "thaa", "", NULL, ShapeCharGlyphProp_None},
659 {{ standard_features, 2}, NULL, "grek", "", NULL, NULL},
660 {{ standard_features, 2}, NULL, "cyrl", "", NULL, NULL},
661 {{ standard_features, 2}, NULL, "armn", "", NULL, NULL},
662 {{ standard_features, 2}, NULL, "geor", "", NULL, NULL},
663 {{ sinhala_features, 7}, NULL, "sinh", "", ContextualShape_Sinhala, NULL},
664 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
665 {{ tibetan_features, 2}, NULL, "tibt", "", NULL, ShapeCharGlyphProp_Tibet},
666 {{ tibetan_features, 2}, NULL, "phag", "", ContextualShape_Phags_pa, ShapeCharGlyphProp_Thai},
667 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
668 {{ thai_features, 1}, NULL, "thai", "", NULL, ShapeCharGlyphProp_Thai},
669 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
670 {{ thai_features, 1}, required_lao_features, "lao", "", NULL, ShapeCharGlyphProp_Thai},
671 {{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
672 {{ devanagari_features, 15}, required_devanagari_features, "deva", "dev2", ContextualShape_Devanagari, ShapeCharGlyphProp_Devanagari},
673 {{ bengali_features, 16}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
674 {{ bengali_features, 16}, required_bengali_features, "beng", "bng2", ContextualShape_Bengali, ShapeCharGlyphProp_Bengali},
675 {{ gurmukhi_features, 15}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
676 {{ gurmukhi_features, 15}, required_gurmukhi_features, "guru", "gur2", ContextualShape_Gurmukhi, ShapeCharGlyphProp_Gurmukhi},
677 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
678 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
679 {{ devanagari_features, 15}, required_devanagari_features, "gujr", "gjr2", ContextualShape_Gujarati, ShapeCharGlyphProp_Gujarati},
680 {{ oriya_features, 13}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
681 {{ oriya_features, 13}, required_oriya_features, "orya", "ory2", ContextualShape_Oriya, ShapeCharGlyphProp_Oriya},
682 {{ tamil_features, 12}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
683 {{ tamil_features, 12}, required_tamil_features, "taml", "tam2", ContextualShape_Tamil, ShapeCharGlyphProp_Tamil},
684 {{ telugu_features, 15}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
685 {{ telugu_features, 15}, required_telugu_features, "telu", "tel2", ContextualShape_Telugu, ShapeCharGlyphProp_Telugu},
686 {{ telugu_features, 15}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
687 {{ telugu_features, 15}, required_telugu_features, "knda", "knd2", ContextualShape_Kannada, ShapeCharGlyphProp_Kannada},
688 {{ telugu_features, 15}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
689 {{ telugu_features, 15}, required_telugu_features, "mlym", "mlm2", ContextualShape_Malayalam, ShapeCharGlyphProp_Malayalam},
692 static INT GSUB_is_glyph_covered(LPCVOID table , UINT glyph)
694 const GSUB_CoverageFormat1* cf1;
698 if (GET_BE_WORD(cf1->CoverageFormat) == 1)
700 int count = GET_BE_WORD(cf1->GlyphCount);
702 TRACE("Coverage Format 1, %i glyphs\n",count);
703 for (i = 0; i < count; i++)
704 if (glyph == GET_BE_WORD(cf1->GlyphArray[i]))
708 else if (GET_BE_WORD(cf1->CoverageFormat) == 2)
710 const GSUB_CoverageFormat2* cf2;
713 cf2 = (const GSUB_CoverageFormat2*)cf1;
715 count = GET_BE_WORD(cf2->RangeCount);
716 TRACE("Coverage Format 2, %i ranges\n",count);
717 for (i = 0; i < count; i++)
719 if (glyph < GET_BE_WORD(cf2->RangeRecord[i].Start))
721 if ((glyph >= GET_BE_WORD(cf2->RangeRecord[i].Start)) &&
722 (glyph <= GET_BE_WORD(cf2->RangeRecord[i].End)))
724 return (GET_BE_WORD(cf2->RangeRecord[i].StartCoverageIndex) +
725 glyph - GET_BE_WORD(cf2->RangeRecord[i].Start));
731 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1->CoverageFormat));
736 static const GSUB_Script* GSUB_get_script_table( const GSUB_Header* header, const char* tag)
738 const GSUB_ScriptList *script;
739 const GSUB_Script *deflt = NULL;
741 script = (const GSUB_ScriptList*)((const BYTE*)header + GET_BE_WORD(header->ScriptList));
743 TRACE("%i scripts in this font\n",GET_BE_WORD(script->ScriptCount));
744 for (i = 0; i < GET_BE_WORD(script->ScriptCount); i++)
746 const GSUB_Script *scr;
749 offset = GET_BE_WORD(script->ScriptRecord[i].Script);
750 scr = (const GSUB_Script*)((const BYTE*)script + offset);
752 if (strncmp(script->ScriptRecord[i].ScriptTag, tag,4)==0)
754 if (strncmp(script->ScriptRecord[i].ScriptTag, "dflt",4)==0)
760 static const GSUB_LangSys* GSUB_get_lang_table( const GSUB_Script* script, const char* tag)
764 const GSUB_LangSys *Lang;
766 TRACE("Deflang %x, LangCount %i\n",GET_BE_WORD(script->DefaultLangSys), GET_BE_WORD(script->LangSysCount));
768 for (i = 0; i < GET_BE_WORD(script->LangSysCount) ; i++)
770 offset = GET_BE_WORD(script->LangSysRecord[i].LangSys);
771 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
773 if ( strncmp(script->LangSysRecord[i].LangSysTag,tag,4)==0)
776 offset = GET_BE_WORD(script->DefaultLangSys);
779 Lang = (const GSUB_LangSys*)((const BYTE*)script + offset);
785 static const GSUB_Feature * GSUB_get_feature(const GSUB_Header *header, const GSUB_LangSys *lang, const char* tag)
788 const GSUB_FeatureList *feature;
789 feature = (const GSUB_FeatureList*)((const BYTE*)header + GET_BE_WORD(header->FeatureList));
791 TRACE("%i features\n",GET_BE_WORD(lang->FeatureCount));
792 for (i = 0; i < GET_BE_WORD(lang->FeatureCount); i++)
794 int index = GET_BE_WORD(lang->FeatureIndex[i]);
795 if (strncmp(feature->FeatureRecord[index].FeatureTag,tag,4)==0)
797 const GSUB_Feature *feat;
798 feat = (const GSUB_Feature*)((const BYTE*)feature + GET_BE_WORD(feature->FeatureRecord[index].Feature));
805 static INT GSUB_apply_SingleSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
808 TRACE("Single Substitution Subtable\n");
810 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
813 const GSUB_SingleSubstFormat1 *ssf1;
814 offset = GET_BE_WORD(look->SubTable[j]);
815 ssf1 = (const GSUB_SingleSubstFormat1*)((const BYTE*)look+offset);
816 if (GET_BE_WORD(ssf1->SubstFormat) == 1)
818 int offset = GET_BE_WORD(ssf1->Coverage);
819 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1->DeltaGlyphID));
820 if (GSUB_is_glyph_covered((const BYTE*)ssf1+offset, glyphs[glyph_index]) != -1)
822 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
823 glyphs[glyph_index] = glyphs[glyph_index] + GET_BE_WORD(ssf1->DeltaGlyphID);
824 TRACE(" 0x%x\n",glyphs[glyph_index]);
825 return glyph_index + 1;
830 const GSUB_SingleSubstFormat2 *ssf2;
834 ssf2 = (const GSUB_SingleSubstFormat2 *)ssf1;
835 offset = GET_BE_WORD(ssf1->Coverage);
836 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2->GlyphCount));
837 index = GSUB_is_glyph_covered((const BYTE*)ssf2+offset, glyphs[glyph_index]);
838 TRACE(" Coverage index %i\n",index);
841 if (glyphs[glyph_index] == GET_BE_WORD(ssf2->Substitute[index]))
842 return GSUB_E_NOGLYPH;
844 TRACE(" Glyph is 0x%x ->",glyphs[glyph_index]);
845 glyphs[glyph_index] = GET_BE_WORD(ssf2->Substitute[index]);
846 TRACE("0x%x\n",glyphs[glyph_index]);
847 return glyph_index + 1;
851 return GSUB_E_NOGLYPH;
854 static INT GSUB_apply_AlternateSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
857 TRACE("Alternate Substitution Subtable\n");
859 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
862 const GSUB_AlternateSubstFormat1 *asf1;
865 offset = GET_BE_WORD(look->SubTable[j]);
866 asf1 = (const GSUB_AlternateSubstFormat1*)((const BYTE*)look+offset);
867 offset = GET_BE_WORD(asf1->Coverage);
869 index = GSUB_is_glyph_covered((const BYTE*)asf1+offset, glyphs[glyph_index]);
872 const GSUB_AlternateSet *as;
873 offset = GET_BE_WORD(asf1->AlternateSet[index]);
874 as = (const GSUB_AlternateSet*)((const BYTE*)asf1+offset);
875 FIXME("%i alternates, picking index 0\n",GET_BE_WORD(as->GlyphCount));
876 if (glyphs[glyph_index] == GET_BE_WORD(as->Alternate[0]))
877 return GSUB_E_NOGLYPH;
879 TRACE(" Glyph 0x%x ->",glyphs[glyph_index]);
880 glyphs[glyph_index] = GET_BE_WORD(as->Alternate[0]);
881 TRACE(" 0x%x\n",glyphs[glyph_index]);
882 return glyph_index + 1;
885 return GSUB_E_NOGLYPH;
888 static INT GSUB_apply_LigatureSubst(const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
892 TRACE("Ligature Substitution Subtable\n");
893 for (j = 0; j < GET_BE_WORD(look->SubTableCount); j++)
895 const GSUB_LigatureSubstFormat1 *lsf1;
898 offset = GET_BE_WORD(look->SubTable[j]);
899 lsf1 = (const GSUB_LigatureSubstFormat1*)((const BYTE*)look+offset);
900 offset = GET_BE_WORD(lsf1->Coverage);
901 index = GSUB_is_glyph_covered((const BYTE*)lsf1+offset, glyphs[glyph_index]);
902 TRACE(" Coverage index %i\n",index);
905 const GSUB_LigatureSet *ls;
908 offset = GET_BE_WORD(lsf1->LigatureSet[index]);
909 ls = (const GSUB_LigatureSet*)((const BYTE*)lsf1+offset);
910 count = GET_BE_WORD(ls->LigatureCount);
911 TRACE(" LigatureSet has %i members\n",count);
912 for (k = 0; k < count; k++)
914 const GSUB_Ligature *lig;
915 int CompCount,l,CompIndex;
917 offset = GET_BE_WORD(ls->Ligature[k]);
918 lig = (const GSUB_Ligature*)((const BYTE*)ls+offset);
919 CompCount = GET_BE_WORD(lig->CompCount) - 1;
920 CompIndex = glyph_index+write_dir;
921 for (l = 0; l < CompCount && CompIndex >= 0 && CompIndex < *glyph_count; l++)
924 CompGlyph = GET_BE_WORD(lig->Component[l]);
925 if (CompGlyph != glyphs[CompIndex])
927 CompIndex += write_dir;
931 int replaceIdx = glyph_index;
933 replaceIdx = glyph_index - CompCount;
935 TRACE(" Glyph is 0x%x (+%i) ->",glyphs[glyph_index],CompCount);
936 glyphs[replaceIdx] = GET_BE_WORD(lig->LigGlyph);
937 TRACE("0x%x\n",glyphs[replaceIdx]);
941 for (j = replaceIdx + 1; j < *glyph_count; j++)
942 glyphs[j] =glyphs[j+CompCount];
943 *glyph_count = *glyph_count - CompCount;
945 return replaceIdx + 1;
950 return GSUB_E_NOGLYPH;
953 static INT GSUB_apply_ChainContextSubst(const GSUB_LookupList* lookup, const GSUB_LookupTable *look, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
958 TRACE("Chaining Contextual Substitution Subtable\n");
959 for (j = 0; j < GET_BE_WORD(look->SubTableCount) && !done; j++)
961 const GSUB_ChainContextSubstFormat1 *ccsf1;
963 int dirLookahead = write_dir;
964 int dirBacktrack = -1 * write_dir;
966 offset = GET_BE_WORD(look->SubTable[j]);
967 ccsf1 = (const GSUB_ChainContextSubstFormat1*)((const BYTE*)look+offset);
968 if (GET_BE_WORD(ccsf1->SubstFormat) == 1)
970 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
973 else if (GET_BE_WORD(ccsf1->SubstFormat) == 2)
975 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
978 else if (GET_BE_WORD(ccsf1->SubstFormat) == 3)
982 const GSUB_ChainContextSubstFormat3_1 *ccsf3_1;
983 const GSUB_ChainContextSubstFormat3_2 *ccsf3_2;
984 const GSUB_ChainContextSubstFormat3_3 *ccsf3_3;
985 const GSUB_ChainContextSubstFormat3_4 *ccsf3_4;
986 int newIndex = glyph_index;
988 ccsf3_1 = (const GSUB_ChainContextSubstFormat3_1 *)ccsf1;
990 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
992 for (k = 0; k < GET_BE_WORD(ccsf3_1->BacktrackGlyphCount); k++)
994 offset = GET_BE_WORD(ccsf3_1->Coverage[k]);
995 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirBacktrack * (k+1))]) == -1)
998 if (k != GET_BE_WORD(ccsf3_1->BacktrackGlyphCount))
1000 TRACE("Matched Backtrack\n");
1002 ccsf3_2 = (const GSUB_ChainContextSubstFormat3_2 *)(((LPBYTE)ccsf1)+sizeof(GSUB_ChainContextSubstFormat3_1) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_1->BacktrackGlyphCount)-1)));
1004 indexGlyphs = GET_BE_WORD(ccsf3_2->InputGlyphCount);
1005 for (k = 0; k < indexGlyphs; k++)
1007 offset = GET_BE_WORD(ccsf3_2->Coverage[k]);
1008 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (write_dir * k)]) == -1)
1011 if (k != indexGlyphs)
1013 TRACE("Matched IndexGlyphs\n");
1015 ccsf3_3 = (const GSUB_ChainContextSubstFormat3_3 *)(((LPBYTE)ccsf3_2)+sizeof(GSUB_ChainContextSubstFormat3_2) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_2->InputGlyphCount)-1)));
1017 for (k = 0; k < GET_BE_WORD(ccsf3_3->LookaheadGlyphCount); k++)
1019 offset = GET_BE_WORD(ccsf3_3->Coverage[k]);
1020 if (GSUB_is_glyph_covered((const BYTE*)ccsf3_1+offset, glyphs[glyph_index + (dirLookahead * (indexGlyphs + k))]) == -1)
1023 if (k != GET_BE_WORD(ccsf3_3->LookaheadGlyphCount))
1025 TRACE("Matched LookAhead\n");
1027 ccsf3_4 = (const GSUB_ChainContextSubstFormat3_4 *)(((LPBYTE)ccsf3_3)+sizeof(GSUB_ChainContextSubstFormat3_3) + (sizeof(WORD) * (GET_BE_WORD(ccsf3_3->LookaheadGlyphCount)-1)));
1029 for (k = 0; k < GET_BE_WORD(ccsf3_4->SubstCount); k++)
1031 int lookupIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].LookupListIndex);
1032 int SequenceIndex = GET_BE_WORD(ccsf3_4->SubstLookupRecord[k].SequenceIndex) * write_dir;
1034 TRACE("SUBST: %i -> %i %i\n",k, SequenceIndex, lookupIndex);
1035 newIndex = GSUB_apply_lookup(lookup, lookupIndex, glyphs, glyph_index + SequenceIndex, write_dir, glyph_count);
1038 ERR("Chain failed to generate a glyph\n");
1048 static INT GSUB_apply_lookup(const GSUB_LookupList* lookup, INT lookup_index, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1051 const GSUB_LookupTable *look;
1053 offset = GET_BE_WORD(lookup->Lookup[lookup_index]);
1054 look = (const GSUB_LookupTable*)((const BYTE*)lookup + offset);
1055 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look->LookupType),GET_BE_WORD(look->LookupFlag),GET_BE_WORD(look->SubTableCount));
1056 switch(GET_BE_WORD(look->LookupType))
1059 return GSUB_apply_SingleSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1061 return GSUB_apply_AlternateSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1063 return GSUB_apply_LigatureSubst(look, glyphs, glyph_index, write_dir, glyph_count);
1065 return GSUB_apply_ChainContextSubst(lookup, look, glyphs, glyph_index, write_dir, glyph_count);
1067 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look->LookupType));
1069 return GSUB_E_NOGLYPH;
1072 static INT GSUB_apply_feature(const GSUB_Header * header, const GSUB_Feature* feature, WORD *glyphs, INT glyph_index, INT write_dir, INT *glyph_count)
1075 int out_index = GSUB_E_NOGLYPH;
1076 const GSUB_LookupList *lookup;
1078 lookup = (const GSUB_LookupList*)((const BYTE*)header + GET_BE_WORD(header->LookupList));
1080 TRACE("%i lookups\n", GET_BE_WORD(feature->LookupCount));
1081 for (i = 0; i < GET_BE_WORD(feature->LookupCount); i++)
1083 out_index = GSUB_apply_lookup(lookup, GET_BE_WORD(feature->LookupListIndex[i]), glyphs, glyph_index, write_dir, glyph_count);
1084 if (out_index != GSUB_E_NOGLYPH)
1087 if (out_index == GSUB_E_NOGLYPH)
1088 TRACE("lookups found no glyphs\n");
1092 out2 = GSUB_apply_feature(header, feature, glyphs, glyph_index, write_dir, glyph_count);
1093 if (out2!=GSUB_E_NOGLYPH)
1099 static const char* get_opentype_script(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, BOOL tryNew)
1103 if (psc->userScript != 0)
1105 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0 && strncmp((char*)&psc->userScript,ShapingData[psa->eScript].otTag,4)==0)
1106 return ShapingData[psa->eScript].newOtTag;
1108 return (char*)&psc->userScript;
1111 if (tryNew && ShapingData[psa->eScript].newOtTag[0] != 0)
1112 return ShapingData[psa->eScript].newOtTag;
1114 if (ShapingData[psa->eScript].otTag[0] != 0)
1115 return ShapingData[psa->eScript].otTag;
1118 * fall back to the font charset
1120 charset = GetTextCharsetInfo(hdc, NULL, 0x0);
1123 case ANSI_CHARSET: return "latn";
1124 case BALTIC_CHARSET: return "latn"; /* ?? */
1125 case CHINESEBIG5_CHARSET: return "hani";
1126 case EASTEUROPE_CHARSET: return "latn"; /* ?? */
1127 case GB2312_CHARSET: return "hani";
1128 case GREEK_CHARSET: return "grek";
1129 case HANGUL_CHARSET: return "hang";
1130 case RUSSIAN_CHARSET: return "cyrl";
1131 case SHIFTJIS_CHARSET: return "kana";
1132 case TURKISH_CHARSET: return "latn"; /* ?? */
1133 case VIETNAMESE_CHARSET: return "latn";
1134 case JOHAB_CHARSET: return "latn"; /* ?? */
1135 case ARABIC_CHARSET: return "arab";
1136 case HEBREW_CHARSET: return "hebr";
1137 case THAI_CHARSET: return "thai";
1138 default: return "latn";
1142 static LPCVOID load_GSUB_feature(HDC hdc, SCRIPT_ANALYSIS *psa, ScriptCache *psc, const char* feat)
1144 const GSUB_Feature *feature;
1147 for (i = 0; i < psc->feature_count; i++)
1148 if (strncmp(psc->features[i].tag,feat,4)==0)
1149 return psc->features[i].feature;
1153 if (psc->GSUB_Table)
1155 const GSUB_Script *script;
1156 const GSUB_LangSys *language;
1161 script = GSUB_get_script_table(psc->GSUB_Table, get_opentype_script(hdc,psa,psc,(attempt==2)));
1165 if (psc->userLang != 0)
1166 language = GSUB_get_lang_table(script,(char*)&psc->userLang);
1168 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1170 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1172 } while(attempt && !feature);
1174 /* try in the default (latin) table */
1177 script = GSUB_get_script_table(psc->GSUB_Table, "latn");
1180 language = GSUB_get_lang_table(script, "xxxx"); /* Need to get Lang tag */
1182 feature = GSUB_get_feature(psc->GSUB_Table, language, feat);
1187 TRACE("Feature %s located at %p\n",debugstr_an(feat,4),feature);
1189 psc->feature_count++;
1192 psc->features = HeapReAlloc(GetProcessHeap(), 0, psc->features, psc->feature_count * sizeof(LoadedFeature));
1194 psc->features = HeapAlloc(GetProcessHeap(), 0, psc->feature_count * sizeof(LoadedFeature));
1196 lstrcpynA(psc->features[psc->feature_count - 1].tag, feat, 5);
1197 psc->features[psc->feature_count - 1].feature = feature;
1201 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)
1203 const GSUB_Feature *feature;
1205 feature = load_GSUB_feature(hdc, psa, psc, feat);
1207 return GSUB_E_NOFEATURE;
1209 TRACE("applying feature %s\n",feat);
1210 return GSUB_apply_feature(psc->GSUB_Table, feature, glyphs, index, write_dir, glyph_count);
1213 static VOID *load_gsub_table(HDC hdc)
1215 VOID* GSUB_Table = NULL;
1216 int length = GetFontData(hdc, GSUB_TAG , 0, NULL, 0);
1217 if (length != GDI_ERROR)
1219 GSUB_Table = HeapAlloc(GetProcessHeap(),0,length);
1220 GetFontData(hdc, GSUB_TAG , 0, GSUB_Table, length);
1221 TRACE("Loaded GSUB table of %i bytes\n",length);
1226 static WORD GDEF_get_glyph_class(const GDEF_Header *header, WORD glyph)
1230 const GDEF_ClassDefFormat1 *cf1;
1235 offset = GET_BE_WORD(header->GlyphClassDef);
1239 cf1 = (GDEF_ClassDefFormat1*)(((BYTE*)header)+offset);
1240 if (GET_BE_WORD(cf1->ClassFormat) == 1)
1242 if (glyph >= GET_BE_WORD(cf1->StartGlyph))
1244 int index = glyph - GET_BE_WORD(cf1->StartGlyph);
1245 if (index < GET_BE_WORD(cf1->GlyphCount))
1246 class = GET_BE_WORD(cf1->ClassValueArray[index]);
1249 else if (GET_BE_WORD(cf1->ClassFormat) == 2)
1251 const GDEF_ClassDefFormat2 *cf2 = (GDEF_ClassDefFormat2*)cf1;
1253 top = GET_BE_WORD(cf2->ClassRangeCount);
1254 for (i = 0; i < top; i++)
1256 if (glyph >= GET_BE_WORD(cf2->ClassRangeRecord[i].Start) &&
1257 glyph <= GET_BE_WORD(cf2->ClassRangeRecord[i].End))
1259 class = GET_BE_WORD(cf2->ClassRangeRecord[i].Class);
1265 ERR("Unknown Class Format %i\n",GET_BE_WORD(cf1->ClassFormat));
1270 static VOID *load_gdef_table(HDC hdc)
1272 VOID* GDEF_Table = NULL;
1273 int length = GetFontData(hdc, GDEF_TAG , 0, NULL, 0);
1274 if (length != GDI_ERROR)
1276 GDEF_Table = HeapAlloc(GetProcessHeap(),0,length);
1277 GetFontData(hdc, GDEF_TAG , 0, GDEF_Table, length);
1278 TRACE("Loaded GDEF table of %i bytes\n",length);
1283 static void GDEF_UpdateGlyphProps(HDC hdc, ScriptCache *psc, const WORD *pwGlyphs, const WORD cGlyphs, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1287 if (!psc->GDEF_Table)
1288 psc->GDEF_Table = load_gdef_table(hdc);
1290 for (i = 0; i < cGlyphs; i++)
1294 class = GDEF_get_glyph_class(psc->GDEF_Table, pwGlyphs[i]);
1300 pGlyphProp[i].sva.fClusterStart = 1;
1301 pGlyphProp[i].sva.fDiacritic = 0;
1302 pGlyphProp[i].sva.fZeroWidth = 0;
1305 pGlyphProp[i].sva.fClusterStart = 1;
1306 pGlyphProp[i].sva.fDiacritic = 0;
1307 pGlyphProp[i].sva.fZeroWidth = 0;
1310 pGlyphProp[i].sva.fClusterStart = 0;
1311 pGlyphProp[i].sva.fDiacritic = 1;
1312 pGlyphProp[i].sva.fZeroWidth = 1;
1314 case ComponentGlyph:
1315 pGlyphProp[i].sva.fClusterStart = 0;
1316 pGlyphProp[i].sva.fDiacritic = 0;
1317 pGlyphProp[i].sva.fZeroWidth = 0;
1320 ERR("Unknown glyph class %i\n",class);
1321 pGlyphProp[i].sva.fClusterStart = 1;
1322 pGlyphProp[i].sva.fDiacritic = 0;
1323 pGlyphProp[i].sva.fZeroWidth = 0;
1328 static void UpdateClustersFromGlyphProp(const int cGlyphs, const int cChars, WORD* pwLogClust, SCRIPT_GLYPHPROP *pGlyphProp)
1332 for (i = 0; i < cGlyphs; i++)
1334 if (!pGlyphProp[i].sva.fClusterStart)
1337 for (j = 0; j < cChars; j++)
1339 if (pwLogClust[j] == i)
1342 while (!pGlyphProp[pwLogClust[k]].sva.fClusterStart && k >= 0 && k <cChars)
1344 if (pGlyphProp[pwLogClust[k]].sva.fClusterStart)
1345 pwLogClust[j] = pwLogClust[k];
1352 static void UpdateClusters(int nextIndex, int changeCount, int write_dir, int chars, WORD* pwLogClust )
1354 if (changeCount == 0)
1359 int target_glyph = nextIndex - 1;
1360 int target_index = -1;
1361 int replacing_glyph = -1;
1365 for (i = 0; i < chars; i++)
1367 if (pwLogClust[i] == target_glyph)
1374 for (i = chars - 1; i >= 0; i--)
1376 if (pwLogClust[i] == target_glyph)
1382 if (target_index == -1)
1384 ERR("Unable to find target glyph\n");
1388 if (changeCount < 0)
1391 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1393 if (pwLogClust[i] == target_glyph)
1395 if(pwLogClust[i] == replacing_glyph)
1396 pwLogClust[i] = target_glyph;
1400 if (changed >= changeCount)
1402 replacing_glyph = pwLogClust[i];
1403 pwLogClust[i] = target_glyph;
1411 /* renumber trailing indexes*/
1412 for(i = target_index; i < chars && i >= 0; i+=write_dir)
1414 if (pwLogClust[i] != target_glyph)
1415 pwLogClust[i] += changeCount;
1420 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 )
1424 if (psc->GSUB_Table)
1426 const GSUB_Feature *feature;
1428 feature = load_GSUB_feature(hdc, psa, psc, feat);
1430 return GSUB_E_NOFEATURE;
1433 TRACE("applying feature %s\n",debugstr_an(feat,4));
1434 while(i < *pcGlyphs)
1437 INT prevCount = *pcGlyphs;
1438 nextIndex = GSUB_apply_feature(psc->GSUB_Table, feature, pwOutGlyphs, i, write_dir, pcGlyphs);
1439 if (nextIndex > GSUB_E_NOGLYPH)
1441 UpdateClusters(nextIndex, *pcGlyphs - prevCount, write_dir, cChars, pwLogClust);
1449 return GSUB_E_NOFEATURE;
1452 static WCHAR neighbour_char(int i, int delta, const WCHAR* chars, INT cchLen)
1456 if ( i+ delta >= cchLen)
1464 static CHAR neighbour_joining_type(int i, int delta, const CHAR* context_type, INT cchLen, SCRIPT_ANALYSIS *psa)
1468 if (psa->fLinkBefore)
1473 if ( i+ delta >= cchLen)
1475 if (psa->fLinkAfter)
1483 if (context_type[i] == jtT)
1484 return neighbour_joining_type(i,delta,context_type,cchLen,psa);
1486 return context_type[i];
1489 static inline BOOL right_join_causing(CHAR joining_type)
1491 return (joining_type == jtL || joining_type == jtD || joining_type == jtC);
1494 static inline BOOL left_join_causing(CHAR joining_type)
1496 return (joining_type == jtR || joining_type == jtD || joining_type == jtC);
1499 static inline BOOL word_break_causing(WCHAR chr)
1501 /* we are working within a string of characters already guareented to
1502 be within one script, Syriac, so we do not worry about any characers
1503 other than the space character outside of that range */
1504 return (chr == 0 || chr == 0x20 );
1508 * ContextualShape_Arabic
1510 static void ContextualShape_Arabic(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1517 if (*pcGlyphs != cChars)
1519 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1523 if (!psa->fLogicalOrder && psa->fRTL)
1534 if (!psc->GSUB_Table)
1535 psc->GSUB_Table = load_gsub_table(hdc);
1537 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1538 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1540 for (i = 0; i < cChars; i++)
1541 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1543 for (i = 0; i < cChars; i++)
1545 if (context_type[i] == jtR && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1546 context_shape[i] = Xr;
1547 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1548 context_shape[i] = Xl;
1549 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)))
1550 context_shape[i] = Xm;
1551 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1552 context_shape[i] = Xr;
1553 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1554 context_shape[i] = Xl;
1556 context_shape[i] = Xn;
1559 /* Contextual Shaping */
1561 while(i < *pcGlyphs)
1563 BOOL shaped = FALSE;
1565 if (psc->GSUB_Table)
1568 INT prevCount = *pcGlyphs;
1569 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1570 if (nextIndex > GSUB_E_NOGLYPH)
1573 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1575 shaped = (nextIndex > GSUB_E_NOGLYPH);
1580 WORD newGlyph = pwOutGlyphs[i];
1581 if (pwcChars[i] >= FIRST_ARABIC_CHAR && pwcChars[i] <= LAST_ARABIC_CHAR)
1583 /* fall back to presentation form B */
1584 WCHAR context_char = wine_shaping_forms[pwcChars[i] - FIRST_ARABIC_CHAR][context_shape[i]];
1585 if (context_char != pwcChars[i] && GetGlyphIndicesW(hdc, &context_char, 1, &newGlyph, 0) != GDI_ERROR && newGlyph != 0x0000)
1586 pwOutGlyphs[i] = newGlyph;
1592 HeapFree(GetProcessHeap(),0,context_shape);
1593 HeapFree(GetProcessHeap(),0,context_type);
1597 * ContextualShape_Syriac
1601 #define DALATH 0x715
1604 static void ContextualShape_Syriac(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1611 if (*pcGlyphs != cChars)
1613 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1617 if (!psa->fLogicalOrder && psa->fRTL)
1628 if (!psc->GSUB_Table)
1629 psc->GSUB_Table = load_gsub_table(hdc);
1631 if (!psc->GSUB_Table)
1634 context_type = HeapAlloc(GetProcessHeap(),0,cChars);
1635 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1637 for (i = 0; i < cChars; i++)
1638 context_type[i] = wine_shaping_table[wine_shaping_table[pwcChars[i] >> 8] + (pwcChars[i] & 0xff)];
1640 for (i = 0; i < cChars; i++)
1642 if (pwcChars[i] == ALAPH)
1644 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1646 if (left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1647 context_shape[i] = Afj;
1648 else if ( rchar != DALATH && rchar != RISH &&
1649 !left_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)) &&
1650 word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1651 context_shape[i] = Afn;
1652 else if ( (rchar == DALATH || rchar == RISH) && word_break_causing(neighbour_char(i,dirL,pwcChars,cChars)))
1653 context_shape[i] = Afx;
1655 context_shape[i] = Xn;
1657 else if (context_type[i] == jtR &&
1658 right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1659 context_shape[i] = Xr;
1660 else if (context_type[i] == jtL && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1661 context_shape[i] = Xl;
1662 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)))
1663 context_shape[i] = Xm;
1664 else if (context_type[i] == jtD && right_join_causing(neighbour_joining_type(i,dirR,context_type,cChars,psa)))
1665 context_shape[i] = Xr;
1666 else if (context_type[i] == jtD && left_join_causing(neighbour_joining_type(i,dirL,context_type,cChars,psa)))
1667 context_shape[i] = Xl;
1669 context_shape[i] = Xn;
1672 /* Contextual Shaping */
1674 while(i < *pcGlyphs)
1677 INT prevCount = *pcGlyphs;
1678 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1679 if (nextIndex > GSUB_E_NOGLYPH)
1681 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1688 HeapFree(GetProcessHeap(),0,context_shape);
1689 HeapFree(GetProcessHeap(),0,context_type);
1693 * ContextualShape_Phags_pa
1696 #define phags_pa_CANDRABINDU 0xA873
1697 #define phags_pa_START 0xA840
1698 #define phags_pa_END 0xA87F
1700 static void ContextualShape_Phags_pa(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
1706 if (*pcGlyphs != cChars)
1708 ERR("Number of Glyphs and Chars need to match at the beginning\n");
1712 if (!psa->fLogicalOrder && psa->fRTL)
1723 if (!psc->GSUB_Table)
1724 psc->GSUB_Table = load_gsub_table(hdc);
1726 if (!psc->GSUB_Table)
1729 context_shape = HeapAlloc(GetProcessHeap(),0,sizeof(INT) * cChars);
1731 for (i = 0; i < cChars; i++)
1733 if (pwcChars[i] >= phags_pa_START && pwcChars[i] <= phags_pa_END)
1735 WCHAR rchar = neighbour_char(i,dirR,pwcChars,cChars);
1736 WCHAR lchar = neighbour_char(i,dirL,pwcChars,cChars);
1737 BOOL jrchar = (rchar != phags_pa_CANDRABINDU && rchar >= phags_pa_START && rchar <= phags_pa_END);
1738 BOOL jlchar = (lchar != phags_pa_CANDRABINDU && lchar >= phags_pa_START && lchar <= phags_pa_END);
1740 if (jrchar && jlchar)
1741 context_shape[i] = Xm;
1743 context_shape[i] = Xr;
1745 context_shape[i] = Xl;
1747 context_shape[i] = Xn;
1750 context_shape[i] = -1;
1753 /* Contextual Shaping */
1755 while(i < *pcGlyphs)
1757 if (context_shape[i] >= 0)
1760 INT prevCount = *pcGlyphs;
1761 nextIndex = apply_GSUB_feature_to_glyph(hdc, psa, psc, pwOutGlyphs, i, dirL, pcGlyphs, contextual_features[context_shape[i]]);
1762 if (nextIndex > GSUB_E_NOGLYPH)
1764 UpdateClusters(nextIndex, *pcGlyphs - prevCount, dirL, cChars, pwLogClust);
1774 HeapFree(GetProcessHeap(),0,context_shape);
1777 static void ReplaceInsertChars(HDC hdc, INT cWalk, INT* pcChars, WCHAR *pwOutChars, const WCHAR *replacements)
1782 pwOutChars[cWalk] = replacements[0];
1786 for (i = 1; replacements[i] != 0x0000 && i < 3; i++)
1789 for (j = *pcChars; j > cWalk; j--)
1790 pwOutChars[j] = pwOutChars[j-1];
1791 *pcChars= *pcChars+1;
1792 pwOutChars[cWalk] = replacements[i];
1797 static void DecomposeVowels(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const VowelComponents vowels[])
1802 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1804 for (i = 0; vowels[i].base != 0x0; i++)
1806 if (pwOutChars[cWalk] == vowels[i].base)
1808 ReplaceInsertChars(hdc, cWalk, pcChars, pwOutChars, vowels[i].parts);
1809 if (vowels[i].parts[1]) cWalk++;
1810 if (vowels[i].parts[2]) cWalk++;
1817 static void ComposeConsonants(HDC hdc, WCHAR *pwOutChars, INT *pcChars, const ConsonantComponents consonants[])
1822 for (cWalk = 0; cWalk < *pcChars; cWalk++)
1824 for (i = 0; consonants[i].output!= 0x0; i++)
1827 for (j = 0; j + cWalk < *pcChars && consonants[i].parts[j]!=0x0; j++)
1828 if (pwOutChars[cWalk+j] != consonants[i].parts[j])
1831 if (consonants[i].parts[j]==0x0) /* matched all */
1835 pwOutChars[cWalk] = consonants[i].output;
1836 for(k = cWalk+1; k < *pcChars - j; k++)
1837 pwOutChars[k] = pwOutChars[k+j];
1838 *pcChars = *pcChars - j;
1846 static void Reorder_Ra_follows_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1848 if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
1851 WORD Ra = pwChar[start];
1852 WORD H = pwChar[start+1];
1854 TRACE("Doing reorder of Ra to %i\n",main);
1855 for (j = start; j < main-1; j++)
1856 pwChar[j] = pwChar[j+2];
1857 pwChar[main-1] = Ra;
1862 static void Reorder_Ra_follows_matra(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1864 if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
1867 WORD Ra = pwChar[start];
1868 WORD H = pwChar[start+1];
1869 for (loc = end; loc > main; loc--)
1870 if (lexical(pwChar[loc]) == lex_Matra_post || lexical(pwChar[loc]) == lex_Matra_below)
1873 TRACE("Doing reorder of Ra to %i\n",loc);
1874 for (j = start; j < loc-1; j++)
1875 pwChar[j] = pwChar[j+2];
1881 static void Reorder_Ra_follows_syllable(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1883 if (start != main && end > start+1 && lexical(pwChar[start]) == lex_Ra && lexical(pwChar[start+1]) == lex_Halant)
1886 WORD Ra = pwChar[start];
1887 WORD H = pwChar[start+1];
1889 TRACE("Doing reorder of Ra to %i\n",end-1);
1890 for (j = start; j < end-1; j++)
1891 pwChar[j] = pwChar[j+2];
1897 static void Reorder_Matra_precede_base(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1901 /* reorder Matras */
1904 for (i = 1; i <= end-main; i++)
1906 if (lexical(pwChar[main+i]) == lex_Matra_pre)
1909 WCHAR c = pwChar[main+i];
1910 TRACE("Doing reorder of %x %x\n",c,pwChar[main]);
1911 for (j = main+i; j > main; j--)
1912 pwChar[j] = pwChar[j-1];
1919 static void Reorder_Matra_precede_syllable(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1923 /* reorder Matras */
1926 for (i = 1; i <= end-main; i++)
1928 if (lexical(pwChar[main+i]) == lex_Matra_pre)
1931 WCHAR c = pwChar[main+i];
1932 TRACE("Doing reorder of %x to %i\n",c,start);
1933 for (j = main+i; j > start; j--)
1934 pwChar[j] = pwChar[j-1];
1941 static void Reorder_Like_Sinhala(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1943 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1944 if (start == main && main == end) return;
1946 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1947 if (lexical(pwChar[main]) == lex_Vowel) return;
1949 Reorder_Ra_follows_base(pwChar, start, main, end, lexical);
1950 Reorder_Matra_precede_base(pwChar, start, main, end, lexical);
1953 static void Reorder_Like_Devanagari(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1955 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1956 if (start == main && main == end) return;
1958 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1959 if (lexical(pwChar[main]) == lex_Vowel) return;
1961 Reorder_Ra_follows_matra(pwChar, start, main, end, lexical);
1962 Reorder_Matra_precede_syllable(pwChar, start, main, end, lexical);
1965 static void Reorder_Like_Bengali(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1967 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1968 if (start == main && main == end) return;
1970 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1971 if (lexical(pwChar[main]) == lex_Vowel) return;
1973 Reorder_Ra_follows_base(pwChar, start, main, end, lexical);
1974 Reorder_Matra_precede_syllable(pwChar, start, main, end, lexical);
1977 static void Reorder_Like_Kannada(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1979 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1980 if (start == main && main == end) return;
1982 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1983 if (lexical(pwChar[main]) == lex_Vowel) return;
1985 Reorder_Ra_follows_syllable(pwChar, start, main, end, lexical);
1986 Reorder_Matra_precede_syllable(pwChar, start, main, end, lexical);
1989 static void Reorder_Like_Malayalam(LPWSTR pwChar, INT start, INT main, INT end, lexical_function lexical)
1991 TRACE("Syllable (%i..%i..%i)\n",start,main,end);
1992 if (start == main && main == end) return;
1994 main = Indic_FindBaseConsonant(pwChar, start, main, end, lexical);
1995 if (lexical(pwChar[main]) == lex_Vowel) return;
1997 Reorder_Ra_follows_matra(pwChar, start, main, end, lexical);
1998 Reorder_Matra_precede_base(pwChar, start, main, end, lexical);
2001 static int sinhala_lex(WCHAR c)
2005 case 0x0DCA: return lex_Halant;
2008 case 0x0DD8: return lex_Matra_post;
2010 case 0x0DDB: return lex_Matra_pre;
2012 case 0x0DDC: return lex_Matra_post;
2013 case 0x200D: return lex_ZWJ;
2014 case 0x200C: return lex_ZWNJ;
2015 case 0x00A0: return lex_NBSP;
2017 if (c>=0x0D82 && c <=0x0D83) return lex_Modifier;
2018 else if (c>=0x0D85 && c <=0x0D96) return lex_Vowel;
2019 else if (c>=0x0D96 && c <=0x0DC6) return lex_Consonant;
2020 else if (c>=0x0DD0 && c <=0x0DD1) return lex_Matra_post;
2021 else if (c>=0x0DD2 && c <=0x0DD3) return lex_Matra_above;
2022 else if (c>=0x0DD4 && c <=0x0DD6) return lex_Matra_below;
2023 else if (c>=0x0DDD && c <=0x0DDE) return lex_Matra_post;
2024 else if (c>=0x0DF2 && c <=0x0DF3) return lex_Matra_post;
2025 else return lex_Generic;
2029 static const VowelComponents Sinhala_vowels[] = {
2030 {0x0DDA, {0x0DD9,0x0DDA,0x0}},
2031 {0x0DDC, {0x0DD9,0x0DDC,0x0}},
2032 {0x0DDD, {0x0DD9,0x0DDD,0x0}},
2033 {0x0DDE, {0x0DD9,0x0DDE,0x0}},
2034 {0x0000, {0x0000,0x0000,0x0}}};
2036 static void ContextualShape_Sinhala(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2038 int cCount = cChars;
2042 if (*pcGlyphs != cChars)
2044 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2048 input = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (cChars * 3));
2050 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2052 /* Step 1: Decompose multi part vowels */
2053 DecomposeVowels(hdc, input, &cCount, Sinhala_vowels);
2055 TRACE("New double vowel expanded string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2057 /* Step 2: Reorder within Syllables */
2058 Indic_ReorderCharacters( input, cCount, sinhala_lex, Reorder_Like_Sinhala);
2059 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2061 /* Step 3: Strip dangling joiners */
2062 for (i = 0; i < cCount; i++)
2064 if ((input[i] == 0x200D || input[i] == 0x200C) &&
2065 (i == 0 || input[i-1] == 0x0020 || i == cCount-1 || input[i+1] == 0x0020))
2069 /* Step 4: Get glyphs */
2070 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2073 HeapFree(GetProcessHeap(),0,input);
2076 static int devanagari_lex(WCHAR c)
2082 case 0x0903: return lex_Modifier;
2083 case 0x0930: return lex_Ra;
2084 case 0x093C: return lex_Nukta;
2086 case 0x093E: return lex_Matra_post;
2087 case 0x093F: return lex_Matra_pre;
2088 case 0x094D: return lex_Halant;
2089 case 0x0972: return lex_Vowel;
2090 case 0x200C: return lex_ZWNJ;
2091 case 0x200D: return lex_ZWJ;
2093 if (c>=0x0901 && c<=0x0902) return lex_Matra_above;
2094 else if (c>=0x0904 && c<=0x0914) return lex_Vowel;
2095 else if (c>=0x0915 && c<=0x0939) return lex_Consonant;
2096 else if (c>=0x0941 && c<=0x0944) return lex_Matra_below;
2097 else if (c>=0x0945 && c<=0x0948) return lex_Matra_above;
2098 else if (c>=0x0949 && c<=0x094C) return lex_Matra_post;
2099 else if (c>=0x0953 && c<=0x0954) return lex_Modifier;
2100 else if (c>=0x0958 && c<=0x095F) return lex_Consonant;
2101 else if (c>=0x0960 && c<=0x0961) return lex_Vowel;
2102 else if (c>=0x0962 && c<=0x0963) return lex_Matra_below;
2103 else if (c>=0x097B && c<=0x097C) return lex_Consonant;
2104 else if (c>=0x097E && c<=0x097F) return lex_Consonant;
2105 else return lex_Generic;
2109 static const ConsonantComponents Devanagari_consonants[] ={
2110 {{0x0928, 0x093C, 0x00000}, 0x0929},
2111 {{0x0930, 0x093C, 0x00000}, 0x0931},
2112 {{0x0933, 0x093C, 0x00000}, 0x0934},
2113 {{0x0915, 0x093C, 0x00000}, 0x0958},
2114 {{0x0916, 0x093C, 0x00000}, 0x0959},
2115 {{0x0917, 0x093C, 0x00000}, 0x095A},
2116 {{0x091C, 0x093C, 0x00000}, 0x095B},
2117 {{0x0921, 0x093C, 0x00000}, 0x095C},
2118 {{0x0922, 0x093C, 0x00000}, 0x095D},
2119 {{0x092B, 0x093C, 0x00000}, 0x095E},
2120 {{0x092F, 0x093C, 0x00000}, 0x095F}};
2122 static void ContextualShape_Devanagari(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2124 int cCount = cChars;
2127 if (*pcGlyphs != cChars)
2129 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2133 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2134 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2136 /* Step 1: Compose Consonant and Nukta */
2137 ComposeConsonants(hdc, input, &cCount, Devanagari_consonants);
2138 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2140 /* Step 2: Reorder within Syllables */
2141 Indic_ReorderCharacters( input, cCount, devanagari_lex, Reorder_Like_Devanagari);
2142 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2143 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2146 HeapFree(GetProcessHeap(),0,input);
2149 static int bengali_lex(WCHAR c)
2153 case 0x0981: return lex_Modifier;
2156 case 0x09CE: return lex_Consonant;
2157 case 0x09B0: return lex_Ra;
2158 case 0x09BC: return lex_Nukta;
2159 case 0x09BF: return lex_Matra_pre;
2162 case 0x09C0: return lex_Matra_post;
2163 case 0x09CD: return lex_Halant;
2164 case 0x200C: return lex_ZWNJ;
2165 case 0x200D: return lex_ZWJ;
2167 if (c>=0x0982 && c<=0x0983) return lex_Matra_post;
2168 else if (c>=0x0985 && c<=0x0994) return lex_Vowel;
2169 else if (c>=0x0995 && c<=0x09B9) return lex_Consonant;
2170 else if (c>=0x09C1 && c<=0x09C4) return lex_Matra_below;
2171 else if (c>=0x09C7 && c<=0x09C8) return lex_Matra_pre;
2172 else if (c>=0x09DC && c<=0x09DF) return lex_Consonant;
2173 else if (c>=0x09E0 && c<=0x09E1) return lex_Vowel;
2174 else if (c>=0x09E2 && c<=0x09E3) return lex_Matra_below;
2175 else if (c>=0x09F0 && c<=0x09F1) return lex_Consonant;
2176 else return lex_Generic;
2180 static const VowelComponents Bengali_vowels[] = {
2181 {0x09CB, {0x09C7,0x09BE,0x0000}},
2182 {0x09CC, {0x09C7,0x09D7,0x0000}},
2183 {0x0000, {0x0000,0x0000,0x0000}}};
2185 static const ConsonantComponents Bengali_consonants[] = {
2186 {{0x09A4,0x09CD,0x200D}, 0x09CE},
2187 {{0x09A1,0x09BC,0x0000}, 0x09DC},
2188 {{0x09A2,0x09BC,0x0000}, 0x09DD},
2189 {{0x09AF,0x09BC,0x0000}, 0x09DF},
2190 {{0x0000,0x0000,0x0000}, 0x0000}};
2192 static void ContextualShape_Bengali(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2194 int cCount = cChars;
2197 if (*pcGlyphs != cChars)
2199 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2203 input = HeapAlloc(GetProcessHeap(), 0, (cChars * 2) * sizeof(WCHAR));
2204 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2206 /* Step 1: Decompose Vowels and Compose Consonents */
2207 DecomposeVowels(hdc, input, &cCount, Bengali_vowels);
2208 ComposeConsonants(hdc, input, &cCount, Bengali_consonants);
2209 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2211 /* Step 2: Reorder within Syllables */
2212 Indic_ReorderCharacters( input, cCount, bengali_lex, Reorder_Like_Bengali);
2213 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2214 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2217 /* Step 3: Initial form is only applied to the beginning of words */
2218 for (cCount = cCount - 1 ; cCount >= 0; cCount --)
2220 if (cCount == 0 || input[cCount] == 0x0020) /* space */
2224 if (index > 0) index++;
2226 apply_GSUB_feature_to_glyph(hdc, psa, psc, &pwOutGlyphs[index], 0, 1, &gCount, "init");
2230 HeapFree(GetProcessHeap(),0,input);
2233 static int gurmukhi_lex(WCHAR c)
2240 case 0x0A2f: return lex_Consonant;
2241 case 0x0A3C: return lex_Nukta;
2242 case 0x0A3F: return lex_Matra_pre;
2245 case 0x0A40: return lex_Matra_post;
2246 case 0x0A4D: return lex_Halant;
2248 case 0x0A71: return lex_Modifier;
2249 case 0x200C: return lex_ZWNJ;
2250 case 0x200D: return lex_ZWJ;
2252 if (c>=0x0A01 && c<=0x0A02) return lex_Modifier;
2253 else if (c>=0x0A05 && c<=0x0A14) return lex_Vowel;
2254 else if (c>=0x0A15 && c<=0x0A38) return lex_Consonant;
2255 else if (c>=0x0A41 && c<=0x0A42) return lex_Matra_below;
2256 else if (c>=0x0A47 && c<=0x0A4C) return lex_Matra_above;
2257 else if (c>=0x0A59 && c<=0x0A5E) return lex_Consonant;
2258 else return lex_Generic;
2262 static const ConsonantComponents Gurmukhi_consonants[] = {
2263 {{0x0A32,0x0A3C,0x0000}, 0x0A33},
2264 {{0x0A38,0x0A3C,0x0000}, 0x0A36},
2265 {{0x0A16,0x0A3C,0x0000}, 0x0A59},
2266 {{0x0A17,0x0A3C,0x0000}, 0x0A5A},
2267 {{0x0A1C,0x0A3C,0x0000}, 0x0A5B},
2268 {{0x0A2B,0x0A3C,0x0000}, 0x0A5E},
2269 {{0x0000,0x0000,0x0000}, 0x0000}};
2271 static void ContextualShape_Gurmukhi(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2273 int cCount = cChars;
2276 if (*pcGlyphs != cChars)
2278 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2282 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2283 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2285 /* Step 1: Compose Consonents */
2286 ComposeConsonants(hdc, input, &cCount, Gurmukhi_consonants);
2287 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2289 /* Step 2: Reorder within Syllables */
2290 Indic_ReorderCharacters( input, cCount, gurmukhi_lex, Reorder_Like_Bengali);
2291 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2292 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2295 HeapFree(GetProcessHeap(),0,input);
2298 static int gujarati_lex(WCHAR c)
2302 case 0x0A83: return lex_Modifier;
2303 case 0x0AB0: return lex_Ra;
2304 case 0x0ABC: return lex_Nukta;
2305 case 0x0ABF: return lex_Matra_pre;
2307 case 0x0AC0: return lex_Matra_post;
2308 case 0x0ACD: return lex_Halant;
2309 case 0x200C: return lex_ZWNJ;
2310 case 0x200D: return lex_ZWJ;
2312 if (c>=0x0A81 && c<=0x0A82) return lex_Modifier;
2313 else if (c>=0x0A85 && c<=0x0A94) return lex_Vowel;
2314 else if (c>=0x0A95 && c<=0x0AB9) return lex_Consonant;
2315 else if (c>=0x0AC1 && c<=0x0AC4) return lex_Matra_below;
2316 else if (c>=0x0AC5 && c<=0x0AC8) return lex_Matra_above;
2317 else if (c>=0x0AC9 && c<=0x0ACC) return lex_Matra_post;
2318 else if (c>=0x0AE0 && c<=0x0AE1) return lex_Vowel;
2319 else if (c>=0x0AE2 && c<=0x0AE3) return lex_Matra_below;
2320 else return lex_Generic;
2324 static void ContextualShape_Gujarati(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2326 int cCount = cChars;
2329 if (*pcGlyphs != cChars)
2331 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2335 input = HeapAlloc(GetProcessHeap(), 0, cChars * sizeof(WCHAR));
2336 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2338 /* Step 1: Reorder within Syllables */
2339 Indic_ReorderCharacters( input, cCount, gujarati_lex, Reorder_Like_Devanagari);
2340 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2341 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2344 HeapFree(GetProcessHeap(),0,input);
2347 static int oriya_lex(WCHAR c)
2356 case 0x0B33: return lex_Consonant;
2357 case 0x0B30: return lex_Ra;
2358 case 0x0B3C: return lex_Nukta;
2360 case 0x0B56: return lex_Matra_above;
2363 case 0x0B40: return lex_Matra_post;
2364 case 0x0B47: return lex_Matra_pre;
2365 case 0x0B4D: return lex_Halant;
2366 case 0x200C: return lex_ZWNJ;
2367 case 0x200D: return lex_ZWJ;
2369 if (c>=0x0B01 && c<=0x0B03) return lex_Modifier;
2370 else if (c>=0x0B05 && c<=0x0B14) return lex_Vowel;
2371 else if (c>=0x0B15 && c<=0x0B39) return lex_Consonant;
2372 else if (c>=0x0B2C && c<=0x0B2E) return lex_Consonant;
2373 else if (c>=0x0B32 && c<=0x0B33) return lex_Consonant;
2374 else if (c>=0x0B41 && c<=0x0B44) return lex_Matra_below;
2375 else if (c>=0x0B48 && c<=0x0B4C) return lex_Composed_Vowel;
2376 else if (c>=0x0B5C && c<=0x0B5D) return lex_Consonant;
2377 else if (c>=0x0B60 && c<=0x0B61) return lex_Vowel;
2378 else if (c>=0x0B62 && c<=0x0B63) return lex_Matra_below;
2379 else return lex_Generic;
2383 static const VowelComponents Oriya_vowels[] = {
2384 {0x0B48, {0x0B47,0x0B56,0x0000}},
2385 {0x0B4B, {0x0B47,0x0B3E,0x0000}},
2386 {0x0B4C, {0x0B47,0x0B57,0x0000}},
2387 {0x0000, {0x0000,0x0000,0x0000}}};
2389 static const ConsonantComponents Oriya_consonants[] = {
2390 {{0x0B21,0x0B3C,0x0000}, 0x0B5C},
2391 {{0x0B22,0x0B3C,0x0000}, 0x0B5D},
2392 {{0x0000,0x0000,0x0000}, 0x0000}};
2394 static void ContextualShape_Oriya(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2396 int cCount = cChars;
2399 if (*pcGlyphs != cChars)
2401 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2405 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2406 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2408 /* Step 1: Decompose Vowels and Compose Consonents */
2409 DecomposeVowels(hdc, input, &cCount, Oriya_vowels);
2410 ComposeConsonants(hdc, input, &cCount, Oriya_consonants);
2411 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2413 /* Step 2: Reorder within Syllables */
2414 Indic_ReorderCharacters( input, cCount, oriya_lex, Reorder_Like_Bengali);
2415 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2416 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2419 HeapFree(GetProcessHeap(),0,input);
2422 static int tamil_lex(WCHAR c)
2426 case 0x0BC0: return lex_Matra_above;
2427 case 0x0BCD: return lex_Halant;
2428 case 0x0BD7: return lex_Matra_post;
2429 case 0x200C: return lex_ZWNJ;
2430 case 0x200D: return lex_ZWJ;
2432 if (c>=0x0B95 && c<=0x0BB9) return lex_Consonant;
2433 else if (c>=0x0BBE && c<=0x0BBF) return lex_Matra_post;
2434 else if (c>=0x0BC1 && c<=0x0BC2) return lex_Matra_below;
2435 else if (c>=0x0BC6 && c<=0x0BC8) return lex_Matra_pre;
2436 else return lex_Generic;
2440 static const VowelComponents Tamil_vowels[] = {
2441 {0x0BCA, {0x0BC6,0x0BBE,0x0000}},
2442 {0x0BCB, {0x0BC7,0x0BBE,0x0000}},
2443 {0x0BCB, {0x0BC6,0x0BD7,0x0000}},
2444 {0x0000, {0x0000,0x0000,0x0000}}};
2446 static const ConsonantComponents Tamil_consonants[] = {
2447 {{0x0B92,0x0BD7,0x0000}, 0x0B94},
2448 {{0x0000,0x0000,0x0000}, 0x0000}};
2450 static void ContextualShape_Tamil(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2452 int cCount = cChars;
2455 if (*pcGlyphs != cChars)
2457 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2461 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2462 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2464 /* Step 1: Decompose Vowels and Compose Consonents */
2465 DecomposeVowels(hdc, input, &cCount, Tamil_vowels);
2466 ComposeConsonants(hdc, input, &cCount, Tamil_consonants);
2467 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2469 /* Step 2: Reorder within Syllables */
2470 Indic_ReorderCharacters( input, cCount, tamil_lex, Reorder_Like_Sinhala);
2471 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2472 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2475 HeapFree(GetProcessHeap(),0,input);
2478 static int telugu_lex(WCHAR c)
2482 case 0x0C4D: return lex_Halant;
2483 case 0x0C55: return lex_Matra_above;
2484 case 0x0C56: return lex_Matra_below;
2485 case 0x200C: return lex_ZWNJ;
2486 case 0x200D: return lex_ZWJ;
2488 if (c>=0x0C01 && c<=0x0C03) return lex_Matra_post;
2489 else if (c>=0x0C05 && c<=0x0C14) return lex_Vowel;
2490 else if (c>=0x0C15 && c<=0x0C39) return lex_Consonant;
2491 else if (c>=0x0C3E && c<=0x0C40) return lex_Matra_above;
2492 else if (c>=0x0C41 && c<=0x0C44) return lex_Matra_post;
2493 else if (c>=0x0C46 && c<=0x0C47) return lex_Matra_above;
2494 else if (c>=0x0C4A && c<=0x0C4C) return lex_Matra_above;
2495 else if (c>=0x0C58 && c<=0x0C59) return lex_Consonant;
2496 else if (c>=0x0C60 && c<=0x0C61) return lex_Vowel;
2497 else if (c>=0x0C62 && c<=0x0C63) return lex_Matra_below;
2498 else return lex_Generic;
2502 static const VowelComponents Telugu_vowels[] = {
2503 {0x0C48, {0x0C46,0x0C56,0x0000}},
2504 {0x0000, {0x0000,0x0000,0x0000}}};
2506 static void ContextualShape_Telugu(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2508 int cCount = cChars;
2511 if (*pcGlyphs != cChars)
2513 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2517 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2518 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2520 /* Step 1: Decompose Vowels */
2521 DecomposeVowels(hdc, input, &cCount, Telugu_vowels);
2522 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2524 /* Step 2: Reorder within Syllables */
2525 Indic_ReorderCharacters( input, cCount, telugu_lex, Reorder_Like_Bengali);
2526 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2527 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2530 HeapFree(GetProcessHeap(),0,input);
2533 static int kannada_lex(WCHAR c)
2537 case 0x0CB0: return lex_Ra;
2538 case 0x0CBC: return lex_Nukta;
2539 case 0x0CBE: return lex_Matra_post;
2540 case 0x0CBF: return lex_Matra_above;
2541 case 0x0CC6: return lex_Matra_above;
2542 case 0x0CCC: return lex_Matra_above;
2543 case 0x0CCD: return lex_Halant;
2544 case 0x0CCE: return lex_Consonant;
2545 case 0x200C: return lex_ZWNJ;
2546 case 0x200D: return lex_ZWJ;
2548 if (c>=0x0C82 && c<=0x0C83) return lex_Modifier;
2549 else if (c>=0x0C85 && c<=0x0C94) return lex_Vowel;
2550 else if (c>=0x0C95 && c<=0x0CB9) return lex_Consonant;
2551 else if (c>=0x0CC1 && c<=0x0CC4) return lex_Matra_post;
2552 else if (c>=0x0CD5 && c<=0x0CD6) return lex_Modifier;
2553 else if (c>=0x0CE0 && c<=0x0CE1) return lex_Vowel;
2554 else if (c>=0x0CE2 && c<=0x0CE3) return lex_Matra_below;
2555 else return lex_Generic;
2559 static const VowelComponents Kannada_vowels[] = {
2560 {0x0CC0, {0x0CBF,0x0CD5,0x0000}},
2561 {0x0CC7, {0x0CC6,0x0CD5,0x0000}},
2562 {0x0CC8, {0x0CC6,0x0CD6,0x0000}},
2563 {0x0CCA, {0x0CC6,0x0CC2,0x0000}},
2564 {0x0CCB, {0x0CC6,0x0CC2,0x0CD5}},
2565 {0x0000, {0x0000,0x0000,0x0000}}};
2567 static void ContextualShape_Kannada(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2569 int cCount = cChars;
2572 if (*pcGlyphs != cChars)
2574 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2578 input = HeapAlloc(GetProcessHeap(), 0, (cChars*3) * sizeof(WCHAR));
2579 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2581 /* Step 1: Decompose Vowels */
2582 DecomposeVowels(hdc, input, &cCount, Kannada_vowels);
2583 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2585 /* Step 2: Reorder within Syllables */
2586 Indic_ReorderCharacters( input, cCount, kannada_lex, Reorder_Like_Kannada);
2587 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2588 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2591 HeapFree(GetProcessHeap(),0,input);
2594 static int malayalam_lex(WCHAR c)
2598 case 0x0D35: return lex_Consonant;
2599 case 0x0D4D: return lex_Halant;
2600 case 0x0D57: return lex_Matra_post;
2601 case 0x200C: return lex_ZWNJ;
2602 case 0x200D: return lex_ZWJ;
2604 if (c>=0x0D02 && c<=0x0D03) return lex_Modifier;
2605 else if (c>=0x0D05 && c<=0x0D14) return lex_Vowel;
2606 else if (c>=0x0D15 && c<=0x0D39) return lex_Consonant;
2607 else if (c>=0x0D3E && c<=0x0D44) return lex_Matra_post;
2608 else if (c>=0x0D46 && c<=0x0D48) return lex_Matra_pre;
2609 else if (c>=0x0D60 && c<=0x0D61) return lex_Vowel;
2610 else if (c>=0x0D62 && c<=0x0D63) return lex_Matra_below;
2611 else return lex_Generic;
2615 static const VowelComponents Malayalam_vowels[] = {
2616 {0x0D4A, {0x0D46,0x0D3E,0x0000}},
2617 {0x0D4B, {0x0D47,0x0D3E,0x0000}},
2618 {0x0D4C, {0x0D46,0x0D57,0x0000}},
2619 {0x0000, {0x0000,0x0000,0x0000}}};
2621 static void ContextualShape_Malayalam(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
2623 int cCount = cChars;
2626 if (*pcGlyphs != cChars)
2628 ERR("Number of Glyphs and Chars need to match at the beginning\n");
2632 input = HeapAlloc(GetProcessHeap(), 0, (cChars*2) * sizeof(WCHAR));
2633 memcpy(input, pwcChars, cChars * sizeof(WCHAR));
2635 /* Step 1: Decompose Vowels */
2636 DecomposeVowels(hdc, input, &cCount, Malayalam_vowels);
2637 TRACE("New composed string %s (%i)\n",debugstr_wn(input,cCount),cCount);
2639 /* Step 2: Reorder within Syllables */
2640 Indic_ReorderCharacters( input, cCount, malayalam_lex, Reorder_Like_Malayalam);
2641 TRACE("reordered string %s\n",debugstr_wn(input,cCount));
2642 GetGlyphIndicesW(hdc, input, cCount, pwOutGlyphs, 0);
2645 HeapFree(GetProcessHeap(),0,input);
2648 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)
2652 for (i = 0; i < cGlyphs; i++)
2657 for (k = 0; k < cChars; k++)
2659 if (pwLogClust[k] == i)
2661 char_index[char_count] = k;
2666 if (char_count == 0)
2668 FIXME("No chars in this glyph? Must be an error\n");
2672 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2674 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2675 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2678 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2681 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2682 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2685 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 )
2688 int initGlyph, finaGlyph;
2692 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2693 memset(spaces,0,cGlyphs);
2695 if (!psa->fLogicalOrder && psa->fRTL)
2697 initGlyph = cGlyphs-1;
2705 finaGlyph = cGlyphs-1;
2710 for (i = 0; i < cGlyphs; i++)
2712 for (k = 0; k < cChars; k++)
2713 if (pwLogClust[k] == i)
2715 if (pwcChars[k] == 0x0020)
2720 for (i = 0; i < cGlyphs; i++)
2724 BOOL isInit, isFinal;
2726 for (k = 0; k < cChars; k++)
2728 if (pwLogClust[k] == i)
2730 char_index[char_count] = k;
2735 isInit = (i == initGlyph || (i+dirR > 0 && i+dirR < cGlyphs && spaces[i+dirR]));
2736 isFinal = (i == finaGlyph || (i+dirL > 0 && i+dirL < cGlyphs && spaces[i+dirL]));
2738 if (char_count == 0)
2740 FIXME("No chars in this glyph? Must be an error\n");
2744 if (char_count == 1)
2746 if (pwcChars[char_index[0]] == 0x0020) /* space */
2748 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BLANK;
2749 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2751 else if (pwcChars[char_index[0]] == 0x0640) /* kashida */
2752 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_KASHIDA;
2753 else if (pwcChars[char_index[0]] == 0x0633) /* SEEN */
2755 if (!isInit && !isFinal)
2756 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN_M;
2758 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_SEEN;
2760 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2764 if (pwcChars[char_index[0]] == 0x0628 ) /* BA */
2765 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BA;
2766 else if (pwcChars[char_index[0]] == 0x0631 ) /* RA */
2767 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_RA;
2768 else if (pwcChars[char_index[0]] == 0x0647 ) /* HA */
2769 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_HA;
2770 else if ((pwcChars[char_index[0]] == 0x0627 || pwcChars[char_index[0]] == 0x0625 || pwcChars[char_index[0]] == 0x0623 || pwcChars[char_index[0]] == 0x0622) ) /* alef-like */
2771 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_ALEF;
2773 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2775 else if (!isInit && !isFinal)
2776 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2778 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2780 else if (char_count == 2)
2782 if ((pwcChars[char_index[0]] == 0x0628 && pwcChars[char_index[1]]== 0x0631) || (pwcChars[char_index[0]] == 0x0631 && pwcChars[char_index[1]]== 0x0628)) /* BA+RA */
2783 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_BARA;
2785 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2787 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2789 else if (!isInit && !isFinal)
2790 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_ARABIC_NORMAL;
2792 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2795 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2796 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2797 HeapFree(GetProcessHeap(),0,spaces);
2800 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 )
2807 spaces = HeapAlloc(GetProcessHeap(),0,cGlyphs);
2808 memset(spaces,0,cGlyphs);
2810 if (!psa->fLogicalOrder && psa->fRTL)
2817 finaGlyph = cGlyphs-1;
2821 for (i = 0; i < cGlyphs; i++)
2823 for (k = 0; k < cChars; k++)
2824 if (pwLogClust[k] == i)
2826 if (pwcChars[k] == 0x0020)
2831 for (i = 0; i < cGlyphs; i++)
2836 for (k = 0; k < cChars; k++)
2838 if (pwLogClust[k] == i)
2840 char_index[char_count] = k;
2845 if (char_count == 0)
2847 FIXME("No chars in this glyph? Must be an error\n");
2851 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2853 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2854 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2856 else if (i == finaGlyph)
2857 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2859 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2862 HeapFree(GetProcessHeap(),0,spaces);
2863 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2864 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2866 /* Do not allow justification between marks and their base */
2867 for (i = 0; i < cGlyphs; i++)
2869 if (!pGlyphProp[i].sva.fClusterStart)
2870 pGlyphProp[i-dirL].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2874 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)
2878 for (i = 0; i < cGlyphs; i++)
2883 for (k = 0; k < cChars; k++)
2885 if (pwLogClust[k] == i)
2887 char_index[char_count] = k;
2892 if (char_count == 0)
2894 FIXME("No chars in this glyph? Must be an error\n");
2898 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2900 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_CHARACTER;
2901 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2904 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2906 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2907 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2910 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)
2914 for (i = 0; i < cGlyphs; i++)
2919 for (k = 0; k < cChars; k++)
2921 if (pwLogClust[k] == i)
2923 char_index[char_count] = k;
2928 if (char_count == 0)
2930 FIXME("No chars in this glyph? Must be an error\n");
2934 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2936 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2937 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2940 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2942 GDEF_UpdateGlyphProps(hdc, psc, pwGlyphs, cGlyphs, pwLogClust, pGlyphProp);
2943 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
2945 /* Tibeten script does not set sva.fDiacritic or sva.fZeroWidth */
2946 for (i = 0; i < cGlyphs; i++)
2948 if (!pGlyphProp[i].sva.fClusterStart)
2950 pGlyphProp[i].sva.fDiacritic = 0;
2951 pGlyphProp[i].sva.fZeroWidth = 0;
2956 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)
2960 for (i = 0; i < cGlyphs; i++)
2965 for (k = 0; k < cChars; k++)
2967 if (pwLogClust[k] == i)
2969 char_index[char_count] = k;
2974 if (char_count == 0)
2976 FIXME("No chars in this glyph? Must be an error\n");
2980 if (char_count ==1 && pwcChars[char_index[0]] == 0x0020) /* space */
2982 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_BLANK;
2983 pCharProp[char_index[0]].fCanGlyphAlone = 1;
2986 pGlyphProp[i].sva.uJustification = SCRIPT_JUSTIFY_NONE;
2988 pGlyphProp[i].sva.fClusterStart = 0;
2989 for (k = 0; k < char_count && !pGlyphProp[i].sva.fClusterStart; k++)
2990 switch (lexical(pwcChars[char_index[k]]))
2993 case lex_Matra_post:
2994 case lex_Matra_above:
2995 case lex_Matra_below:
2999 pGlyphProp[i].sva.fClusterStart = 1;
3003 UpdateClustersFromGlyphProp(cGlyphs, cChars, pwLogClust, pGlyphProp);
3006 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 )
3008 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, devanagari_lex);
3011 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 )
3013 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, bengali_lex);
3016 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 )
3018 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gurmukhi_lex);
3021 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 )
3023 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, gujarati_lex);
3026 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 )
3028 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, oriya_lex);
3031 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 )
3033 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, tamil_lex);
3036 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 )
3038 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, telugu_lex);
3041 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 )
3043 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, kannada_lex);
3046 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 )
3048 ShapeCharGlyphProp_BaseIndic(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp, malayalam_lex);
3051 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)
3053 if (ShapingData[psa->eScript].charGlyphPropProc)
3054 ShapingData[psa->eScript].charGlyphPropProc(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3056 ShapeCharGlyphProp_Default(hdc, psc, psa, pwcChars, cChars, pwGlyphs, cGlyphs, pwLogClust, pCharProp, pGlyphProp);
3059 void SHAPE_ContextualShaping(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WCHAR* pwcChars, INT cChars, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, WORD *pwLogClust)
3061 if (ShapingData[psa->eScript].contextProc)
3062 ShapingData[psa->eScript].contextProc(hdc, psc, psa, pwcChars, cChars, pwOutGlyphs, pcGlyphs, cMaxGlyphs, pwLogClust);
3065 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)
3070 if (!rpRangeProperties)
3073 if (!psc->GSUB_Table)
3074 psc->GSUB_Table = load_gsub_table(hdc);
3076 if (!psc->GSUB_Table)
3079 if (!psa->fLogicalOrder && psa->fRTL)
3084 for (i = 0; i < rpRangeProperties->cotfRecords; i++)
3086 if (rpRangeProperties->potfRecords[i].lParameter > 0)
3087 apply_GSUB_feature(hdc, psa, psc, pwOutGlyphs, dirL, pcGlyphs, cChars, (const char*)&rpRangeProperties->potfRecords[i].tagFeature, pwLogClust);
3091 void SHAPE_ApplyDefaultOpentypeFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa, WORD* pwOutGlyphs, INT* pcGlyphs, INT cMaxGlyphs, INT cChars, WORD *pwLogClust)
3093 const TEXTRANGE_PROPERTIES *rpRangeProperties;
3094 rpRangeProperties = &ShapingData[psa->eScript].defaultTextRange;
3096 SHAPE_ApplyOpenTypeFeatures(hdc, psc, psa, pwOutGlyphs, pcGlyphs, cMaxGlyphs, cChars, rpRangeProperties, pwLogClust);
3099 HRESULT SHAPE_CheckFontForRequiredFeatures(HDC hdc, ScriptCache *psc, SCRIPT_ANALYSIS *psa)
3101 const GSUB_Feature *feature;
3104 if (!ShapingData[psa->eScript].requiredFeatures)
3107 if (!psc->GSUB_Table)
3108 psc->GSUB_Table = load_gsub_table(hdc);
3110 /* we need to have at least one of the required features */
3112 while (ShapingData[psa->eScript].requiredFeatures[i])
3114 feature = load_GSUB_feature(hdc, psa, psc, ShapingData[psa->eScript].requiredFeatures[i]);
3120 return USP_E_SCRIPT_NOT_IN_FONT;