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 extern const unsigned short wine_shaping_table
[];
41 extern const unsigned short wine_shaping_forms
[LAST_ARABIC_CHAR
- FIRST_ARABIC_CHAR
+ 1][4];
59 #ifdef WORDS_BIGENDIAN
60 #define GET_BE_WORD(x) (x)
62 #define GET_BE_WORD(x) RtlUshortByteSwap(x)
65 /* These are all structures needed for the GSUB table */
66 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
67 ( ( (ULONG)_x4 << 24 ) | \
68 ( (ULONG)_x3 << 16 ) | \
69 ( (ULONG)_x2 << 8 ) | \
72 #define GSUB_TAG MS_MAKE_TAG('G', 'S', 'U', 'B')
73 #define GSUB_E_NOFEATURE -2
74 #define GSUB_E_NOGLYPH -1
90 GSUB_ScriptRecord ScriptRecord
[1];
101 GSUB_LangSysRecord LangSysRecord
[1];
105 WORD LookupOrder
; /* Reserved */
106 WORD ReqFeatureIndex
;
108 WORD FeatureIndex
[1];
114 } GSUB_FeatureRecord
;
118 GSUB_FeatureRecord FeatureRecord
[1];
122 WORD FeatureParams
; /* Reserved */
124 WORD LookupListIndex
[1];
143 } GSUB_CoverageFormat1
;
148 WORD StartCoverageIndex
;
154 GSUB_RangeRecord RangeRecord
[1];
155 } GSUB_CoverageFormat2
;
158 WORD SubstFormat
; /* = 1 */
161 } GSUB_SingleSubstFormat1
;
164 WORD SubstFormat
; /* = 2 */
168 }GSUB_SingleSubstFormat2
;
171 WORD SubstFormat
; /* = 1 */
175 }GSUB_LigatureSubstFormat1
;
190 WORD LookupListIndex
;
192 }GSUB_SubstLookupRecord
;
195 WORD SubstFormat
; /* = 1 */
197 WORD ChainSubRuleSetCount
;
198 WORD ChainSubRuleSet
[1];
199 }GSUB_ChainContextSubstFormat1
;
202 WORD SubstFormat
; /* = 3 */
203 WORD BacktrackGlyphCount
;
205 }GSUB_ChainContextSubstFormat3_1
;
208 WORD InputGlyphCount
;
210 }GSUB_ChainContextSubstFormat3_2
;
213 WORD LookaheadGlyphCount
;
215 }GSUB_ChainContextSubstFormat3_3
;
219 GSUB_SubstLookupRecord SubstLookupRecord
[1];
220 }GSUB_ChainContextSubstFormat3_4
;
222 static INT
GSUB_apply_lookup(const GSUB_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
);
224 /* the orders of joined_forms and contextual_features need to line up */
225 static const char* contextual_features
[] =
233 static const char* arabic_GSUB_features
[] =
244 static INT
GSUB_is_glyph_covered(LPCVOID table
, UINT glyph
)
246 const GSUB_CoverageFormat1
* cf1
;
250 if (GET_BE_WORD(cf1
->CoverageFormat
) == 1)
252 int count
= GET_BE_WORD(cf1
->GlyphCount
);
254 TRACE("Coverage Format 1, %i glyphs\n",count
);
255 for (i
= 0; i
< count
; i
++)
256 if (glyph
== GET_BE_WORD(cf1
->GlyphArray
[i
]))
260 else if (GET_BE_WORD(cf1
->CoverageFormat
) == 2)
262 const GSUB_CoverageFormat2
* cf2
;
265 cf2
= (const GSUB_CoverageFormat2
*)cf1
;
267 count
= GET_BE_WORD(cf2
->RangeCount
);
268 TRACE("Coverage Format 2, %i ranges\n",count
);
269 for (i
= 0; i
< count
; i
++)
271 if (glyph
< GET_BE_WORD(cf2
->RangeRecord
[i
].Start
))
273 if ((glyph
>= GET_BE_WORD(cf2
->RangeRecord
[i
].Start
)) &&
274 (glyph
<= GET_BE_WORD(cf2
->RangeRecord
[i
].End
)))
276 return (GET_BE_WORD(cf2
->RangeRecord
[i
].StartCoverageIndex
) +
277 glyph
- GET_BE_WORD(cf2
->RangeRecord
[i
].Start
));
283 ERR("Unknown CoverageFormat %i\n",GET_BE_WORD(cf1
->CoverageFormat
));
288 static const GSUB_Script
* GSUB_get_script_table( const GSUB_Header
* header
, const char* tag
)
290 const GSUB_ScriptList
*script
;
291 const GSUB_Script
*deflt
= NULL
;
293 script
= (const GSUB_ScriptList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->ScriptList
));
295 TRACE("%i scripts in this font\n",GET_BE_WORD(script
->ScriptCount
));
296 for (i
= 0; i
< GET_BE_WORD(script
->ScriptCount
); i
++)
298 const GSUB_Script
*scr
;
301 offset
= GET_BE_WORD(script
->ScriptRecord
[i
].Script
);
302 scr
= (const GSUB_Script
*)((const BYTE
*)script
+ offset
);
304 if (strncmp(script
->ScriptRecord
[i
].ScriptTag
, tag
,4)==0)
306 if (strncmp(script
->ScriptRecord
[i
].ScriptTag
, "dflt",4)==0)
312 static const GSUB_LangSys
* GSUB_get_lang_table( const GSUB_Script
* script
, const char* tag
)
316 const GSUB_LangSys
*Lang
;
318 TRACE("Deflang %x, LangCount %i\n",GET_BE_WORD(script
->DefaultLangSys
), GET_BE_WORD(script
->LangSysCount
));
320 for (i
= 0; i
< GET_BE_WORD(script
->LangSysCount
) ; i
++)
322 offset
= GET_BE_WORD(script
->LangSysRecord
[i
].LangSys
);
323 Lang
= (const GSUB_LangSys
*)((const BYTE
*)script
+ offset
);
325 if ( strncmp(script
->LangSysRecord
[i
].LangSysTag
,tag
,4)==0)
328 offset
= GET_BE_WORD(script
->DefaultLangSys
);
331 Lang
= (const GSUB_LangSys
*)((const BYTE
*)script
+ offset
);
337 static const GSUB_Feature
* GSUB_get_feature(const GSUB_Header
*header
, const GSUB_LangSys
*lang
, const char* tag
)
340 const GSUB_FeatureList
*feature
;
341 feature
= (const GSUB_FeatureList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->FeatureList
));
343 TRACE("%i features\n",GET_BE_WORD(lang
->FeatureCount
));
344 for (i
= 0; i
< GET_BE_WORD(lang
->FeatureCount
); i
++)
346 int index
= GET_BE_WORD(lang
->FeatureIndex
[i
]);
347 if (strncmp(feature
->FeatureRecord
[index
].FeatureTag
,tag
,4)==0)
349 const GSUB_Feature
*feat
;
350 feat
= (const GSUB_Feature
*)((const BYTE
*)feature
+ GET_BE_WORD(feature
->FeatureRecord
[index
].Feature
));
357 static INT
GSUB_apply_SingleSubst(const GSUB_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
360 TRACE("Single Substitution Subtable\n");
362 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
365 const GSUB_SingleSubstFormat1
*ssf1
;
366 offset
= GET_BE_WORD(look
->SubTable
[j
]);
367 ssf1
= (const GSUB_SingleSubstFormat1
*)((const BYTE
*)look
+offset
);
368 if (GET_BE_WORD(ssf1
->SubstFormat
) == 1)
370 int offset
= GET_BE_WORD(ssf1
->Coverage
);
371 TRACE(" subtype 1, delta %i\n", GET_BE_WORD(ssf1
->DeltaGlyphID
));
372 if (GSUB_is_glyph_covered((const BYTE
*)ssf1
+offset
, glyphs
[glyph_index
]) != -1)
374 TRACE(" Glyph 0x%x ->",glyphs
[glyph_index
]);
375 glyphs
[glyph_index
] = glyphs
[glyph_index
] + GET_BE_WORD(ssf1
->DeltaGlyphID
);
376 TRACE(" 0x%x\n",glyphs
[glyph_index
]);
377 return glyph_index
+ 1;
382 const GSUB_SingleSubstFormat2
*ssf2
;
386 ssf2
= (const GSUB_SingleSubstFormat2
*)ssf1
;
387 offset
= GET_BE_WORD(ssf1
->Coverage
);
388 TRACE(" subtype 2, glyph count %i\n", GET_BE_WORD(ssf2
->GlyphCount
));
389 index
= GSUB_is_glyph_covered((const BYTE
*)ssf2
+offset
, glyphs
[glyph_index
]);
390 TRACE(" Coverage index %i\n",index
);
393 TRACE(" Glyph is 0x%x ->",glyphs
[glyph_index
]);
394 glyphs
[glyph_index
] = GET_BE_WORD(ssf2
->Substitute
[index
]);
395 TRACE("0x%x\n",glyphs
[glyph_index
]);
396 return glyph_index
+ 1;
400 return GSUB_E_NOGLYPH
;
403 static INT
GSUB_apply_LigatureSubst(const GSUB_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
407 TRACE("Ligature Substitution Subtable\n");
408 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
); j
++)
410 const GSUB_LigatureSubstFormat1
*lsf1
;
413 offset
= GET_BE_WORD(look
->SubTable
[j
]);
414 lsf1
= (const GSUB_LigatureSubstFormat1
*)((const BYTE
*)look
+offset
);
415 offset
= GET_BE_WORD(lsf1
->Coverage
);
416 index
= GSUB_is_glyph_covered((const BYTE
*)lsf1
+offset
, glyphs
[glyph_index
]);
417 TRACE(" Coverage index %i\n",index
);
420 const GSUB_LigatureSet
*ls
;
423 offset
= GET_BE_WORD(lsf1
->LigatureSet
[index
]);
424 ls
= (const GSUB_LigatureSet
*)((const BYTE
*)lsf1
+offset
);
425 count
= GET_BE_WORD(ls
->LigatureCount
);
426 TRACE(" LigatureSet has %i members\n",count
);
427 for (k
= 0; k
< count
; k
++)
429 const GSUB_Ligature
*lig
;
430 int CompCount
,l
,CompIndex
;
432 offset
= GET_BE_WORD(ls
->Ligature
[k
]);
433 lig
= (const GSUB_Ligature
*)((const BYTE
*)ls
+offset
);
434 CompCount
= GET_BE_WORD(lig
->CompCount
) - 1;
435 CompIndex
= glyph_index
+write_dir
;
436 for (l
= 0; l
< CompCount
&& CompIndex
>= 0 && CompIndex
< *glyph_count
; l
++)
439 CompGlyph
= GET_BE_WORD(lig
->Component
[l
]);
440 if (CompGlyph
!= glyphs
[CompIndex
])
442 CompIndex
+= write_dir
;
446 int replaceIdx
= glyph_index
;
448 replaceIdx
= glyph_index
- CompCount
;
450 TRACE(" Glyph is 0x%x (+%i) ->",glyphs
[glyph_index
],CompCount
);
451 glyphs
[replaceIdx
] = GET_BE_WORD(lig
->LigGlyph
);
452 TRACE("0x%x\n",glyphs
[replaceIdx
]);
456 for (j
= replaceIdx
+ 1; j
< *glyph_count
; j
++)
457 glyphs
[j
] =glyphs
[j
+CompCount
];
458 *glyph_count
= *glyph_count
- CompCount
;
460 return replaceIdx
+ 1;
465 return GSUB_E_NOGLYPH
;
468 static INT
GSUB_apply_ChainContextSubst(const GSUB_LookupList
* lookup
, const GSUB_LookupTable
*look
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
473 TRACE("Chaining Contextual Substitution Subtable\n");
474 for (j
= 0; j
< GET_BE_WORD(look
->SubTableCount
) && !done
; j
++)
476 const GSUB_ChainContextSubstFormat1
*ccsf1
;
478 int dirLookahead
= write_dir
;
479 int dirBacktrack
= -1 * write_dir
;
481 offset
= GET_BE_WORD(look
->SubTable
[j
]);
482 ccsf1
= (const GSUB_ChainContextSubstFormat1
*)((const BYTE
*)look
+offset
);
483 if (GET_BE_WORD(ccsf1
->SubstFormat
) == 1)
485 FIXME(" TODO: subtype 1 (Simple context glyph substitution)\n");
488 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 2)
490 FIXME(" TODO: subtype 2 (Class-based Chaining Context Glyph Substitution)\n");
493 else if (GET_BE_WORD(ccsf1
->SubstFormat
) == 3)
497 const GSUB_ChainContextSubstFormat3_1
*ccsf3_1
;
498 const GSUB_ChainContextSubstFormat3_2
*ccsf3_2
;
499 const GSUB_ChainContextSubstFormat3_3
*ccsf3_3
;
500 const GSUB_ChainContextSubstFormat3_4
*ccsf3_4
;
501 int newIndex
= glyph_index
;
503 ccsf3_1
= (const GSUB_ChainContextSubstFormat3_1
*)ccsf1
;
505 TRACE(" subtype 3 (Coverage-based Chaining Context Glyph Substitution)\n");
507 for (k
= 0; k
< GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
); k
++)
509 offset
= GET_BE_WORD(ccsf3_1
->Coverage
[k
]);
510 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirBacktrack
* (k
+1))]) == -1)
513 if (k
!= GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
))
515 TRACE("Matched Backtrack\n");
517 ccsf3_2
= (const GSUB_ChainContextSubstFormat3_2
*)(((LPBYTE
)ccsf1
)+sizeof(GSUB_ChainContextSubstFormat3_1
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_1
->BacktrackGlyphCount
)-1)));
519 indexGlyphs
= GET_BE_WORD(ccsf3_2
->InputGlyphCount
);
520 for (k
= 0; k
< indexGlyphs
; k
++)
522 offset
= GET_BE_WORD(ccsf3_2
->Coverage
[k
]);
523 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (write_dir
* k
)]) == -1)
526 if (k
!= indexGlyphs
)
528 TRACE("Matched IndexGlyphs\n");
530 ccsf3_3
= (const GSUB_ChainContextSubstFormat3_3
*)(((LPBYTE
)ccsf3_2
)+sizeof(GSUB_ChainContextSubstFormat3_2
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_2
->InputGlyphCount
)-1)));
532 for (k
= 0; k
< GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
); k
++)
534 offset
= GET_BE_WORD(ccsf3_3
->Coverage
[k
]);
535 if (GSUB_is_glyph_covered((const BYTE
*)ccsf3_1
+offset
, glyphs
[glyph_index
+ (dirLookahead
* (indexGlyphs
+ k
+1))]) == -1)
538 if (k
!= GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
))
540 TRACE("Matched LookAhead\n");
542 ccsf3_4
= (const GSUB_ChainContextSubstFormat3_4
*)(((LPBYTE
)ccsf3_3
)+sizeof(GSUB_ChainContextSubstFormat3_3
) + (sizeof(WORD
) * (GET_BE_WORD(ccsf3_3
->LookaheadGlyphCount
)-1)));
544 for (k
= 0; k
< GET_BE_WORD(ccsf3_4
->SubstCount
); k
++)
546 int lookupIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].LookupListIndex
);
547 int SequenceIndex
= GET_BE_WORD(ccsf3_4
->SubstLookupRecord
[k
].SequenceIndex
) * write_dir
;
549 TRACE("SUBST: %i -> %i %i\n",k
, SequenceIndex
, lookupIndex
);
550 newIndex
= GSUB_apply_lookup(lookup
, lookupIndex
, glyphs
, glyph_index
+ SequenceIndex
, write_dir
, glyph_count
);
553 ERR("Chain failed to generate a glyph\n");
563 static INT
GSUB_apply_lookup(const GSUB_LookupList
* lookup
, INT lookup_index
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
566 const GSUB_LookupTable
*look
;
568 offset
= GET_BE_WORD(lookup
->Lookup
[lookup_index
]);
569 look
= (const GSUB_LookupTable
*)((const BYTE
*)lookup
+ offset
);
570 TRACE("type %i, flag %x, subtables %i\n",GET_BE_WORD(look
->LookupType
),GET_BE_WORD(look
->LookupFlag
),GET_BE_WORD(look
->SubTableCount
));
571 switch(GET_BE_WORD(look
->LookupType
))
574 return GSUB_apply_SingleSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
576 return GSUB_apply_LigatureSubst(look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
578 return GSUB_apply_ChainContextSubst(lookup
, look
, glyphs
, glyph_index
, write_dir
, glyph_count
);
580 FIXME("We do not handle SubType %i\n",GET_BE_WORD(look
->LookupType
));
582 return GSUB_E_NOGLYPH
;
585 static INT
GSUB_apply_feature(const GSUB_Header
* header
, const GSUB_Feature
* feature
, WORD
*glyphs
, INT glyph_index
, INT write_dir
, INT
*glyph_count
)
588 int out_index
= GSUB_E_NOGLYPH
;
589 const GSUB_LookupList
*lookup
;
591 lookup
= (const GSUB_LookupList
*)((const BYTE
*)header
+ GET_BE_WORD(header
->LookupList
));
593 TRACE("%i lookups\n", GET_BE_WORD(feature
->LookupCount
));
594 for (i
= 0; i
< GET_BE_WORD(feature
->LookupCount
); i
++)
596 out_index
= GSUB_apply_lookup(lookup
, GET_BE_WORD(feature
->LookupListIndex
[i
]), glyphs
, glyph_index
, write_dir
, glyph_count
);
597 if (out_index
!= GSUB_E_NOGLYPH
)
600 if (out_index
== GSUB_E_NOGLYPH
)
601 TRACE("lookups found no glyphs\n");
605 static const char* get_opentype_script(HDC hdc
, SCRIPT_ANALYSIS
*psa
)
609 switch (psa
->eScript
)
625 * fall back to the font charset
627 charset
= GetTextCharsetInfo(hdc
, NULL
, 0x0);
630 case ANSI_CHARSET
: return "latn";
631 case BALTIC_CHARSET
: return "latn"; /* ?? */
632 case CHINESEBIG5_CHARSET
: return "hani";
633 case EASTEUROPE_CHARSET
: return "latn"; /* ?? */
634 case GB2312_CHARSET
: return "hani";
635 case GREEK_CHARSET
: return "grek";
636 case HANGUL_CHARSET
: return "hang";
637 case RUSSIAN_CHARSET
: return "cyrl";
638 case SHIFTJIS_CHARSET
: return "kana";
639 case TURKISH_CHARSET
: return "latn"; /* ?? */
640 case VIETNAMESE_CHARSET
: return "latn";
641 case JOHAB_CHARSET
: return "latn"; /* ?? */
642 case ARABIC_CHARSET
: return "arab";
643 case HEBREW_CHARSET
: return "hebr";
644 case THAI_CHARSET
: return "thai";
645 default: return "latn";
649 static INT
apply_GSUB_feature_to_glyph(HDC hdc
, SCRIPT_ANALYSIS
*psa
, void* GSUB_Table
, WORD
*glyphs
, INT index
, INT write_dir
, INT
* glyph_count
, const char* feat
)
651 const GSUB_Header
*header
;
652 const GSUB_Script
*script
;
653 const GSUB_LangSys
*language
;
654 const GSUB_Feature
*feature
;
657 return GSUB_E_NOFEATURE
;
661 script
= GSUB_get_script_table(header
, get_opentype_script(hdc
,psa
));
664 TRACE("Script not found\n");
665 return GSUB_E_NOFEATURE
;
667 language
= GSUB_get_lang_table(script
, "xxxx"); /* Need to get Lang tag */
670 TRACE("Language not found\n");
671 return GSUB_E_NOFEATURE
;
673 feature
= GSUB_get_feature(header
, language
, feat
);
676 TRACE("%s feature not found\n",feat
);
677 return GSUB_E_NOFEATURE
;
679 TRACE("applying feature %s\n",feat
);
680 return GSUB_apply_feature(header
, feature
, glyphs
, index
, write_dir
, glyph_count
);
683 static VOID
*load_gsub_table(HDC hdc
)
685 VOID
* GSUB_Table
= NULL
;
686 int length
= GetFontData(hdc
, GSUB_TAG
, 0, NULL
, 0);
687 if (length
!= GDI_ERROR
)
689 GSUB_Table
= HeapAlloc(GetProcessHeap(),0,length
);
690 GetFontData(hdc
, GSUB_TAG
, 0, GSUB_Table
, length
);
691 TRACE("Loaded GSUB table of %i bytes\n",length
);
696 static int apply_GSUB_feature(HDC hdc
, SCRIPT_ANALYSIS
*psa
, void* GSUB_Table
, WORD
*pwOutGlyphs
, int write_dir
, INT
* pcGlyphs
, const char* feat
)
702 const GSUB_Header
*header
;
703 const GSUB_Script
*script
;
704 const GSUB_LangSys
*language
;
705 const GSUB_Feature
*feature
;
708 return GSUB_E_NOFEATURE
;
712 script
= GSUB_get_script_table(header
, get_opentype_script(hdc
,psa
));
715 TRACE("Script not found\n");
716 return GSUB_E_NOFEATURE
;
718 language
= GSUB_get_lang_table(script
, "xxxx");
721 TRACE("Language not found\n");
722 return GSUB_E_NOFEATURE
;
724 feature
= GSUB_get_feature(header
, language
, feat
);
727 TRACE("%s feature not found\n",feat
);
728 return GSUB_E_NOFEATURE
;
732 TRACE("applying feature %s\n",feat
);
736 nextIndex
= GSUB_apply_feature(header
, feature
, pwOutGlyphs
, i
, write_dir
, pcGlyphs
);
737 if (nextIndex
> GSUB_E_NOGLYPH
)
744 return GSUB_E_NOFEATURE
;
747 static CHAR
neighbour_joining_type(int i
, int delta
, const CHAR
* context_type
, INT cchLen
, SCRIPT_ANALYSIS
*psa
)
751 if (psa
->fLinkBefore
)
756 if ( i
+ delta
>= cchLen
)
766 if (context_type
[i
] == jtT
)
767 return neighbour_joining_type(i
,delta
,context_type
,cchLen
,psa
);
769 return context_type
[i
];
772 static inline BOOL
right_join_causing(CHAR joining_type
)
774 return (joining_type
== jtL
|| joining_type
== jtD
|| joining_type
== jtC
);
777 static inline BOOL
left_join_causing(CHAR joining_type
)
779 return (joining_type
== jtR
|| joining_type
== jtD
|| joining_type
== jtC
);
782 /* SHAPE_ShapeArabicGlyphs
784 void SHAPE_ShapeArabicGlyphs(HDC hdc
, ScriptCache
*psc
, SCRIPT_ANALYSIS
*psa
, WCHAR
* pwcChars
, INT cChars
, WORD
* pwOutGlyphs
, INT
* pcGlyphs
, INT cMaxGlyphs
)
791 if (psa
->eScript
!= Script_Arabic
)
794 if (*pcGlyphs
!= cChars
)
796 ERR("Number of Glyphs and Chars need to match at the beginning\n");
801 if (!psa
->fLogicalOrder
&& psa
->fRTL
)
812 if (!psc
->GSUB_Table
)
813 psc
->GSUB_Table
= load_gsub_table(hdc
);
815 context_type
= HeapAlloc(GetProcessHeap(),0,cChars
);
816 context_shape
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * cChars
);
818 for (i
= 0; i
< cChars
; i
++)
819 context_type
[i
] = wine_shaping_table
[wine_shaping_table
[pwcChars
[i
] >> 8] + (pwcChars
[i
] & 0xff)];
821 for (i
= 0; i
< cChars
; i
++)
823 if (context_type
[i
] == jtR
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
824 context_shape
[i
] = Xr
;
825 else if (context_type
[i
] == jtL
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
826 context_shape
[i
] = Xl
;
827 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
)))
828 context_shape
[i
] = Xm
;
829 else if (context_type
[i
] == jtD
&& right_join_causing(neighbour_joining_type(i
,dirR
,context_type
,cChars
,psa
)))
830 context_shape
[i
] = Xr
;
831 else if (context_type
[i
] == jtD
&& left_join_causing(neighbour_joining_type(i
,dirL
,context_type
,cChars
,psa
)))
832 context_shape
[i
] = Xl
;
834 context_shape
[i
] = Xn
;
837 /* Contextual Shaping */
846 nextIndex
= apply_GSUB_feature_to_glyph(hdc
, psa
, psc
->GSUB_Table
, pwOutGlyphs
, i
, dirL
, pcGlyphs
, contextual_features
[context_shape
[i
]]);
847 if (nextIndex
> GSUB_E_NOGLYPH
)
849 shaped
= (nextIndex
> GSUB_E_NOGLYPH
);
854 WORD newGlyph
= pwOutGlyphs
[i
];
855 if (pwcChars
[i
] >= FIRST_ARABIC_CHAR
&& pwcChars
[i
] <= LAST_ARABIC_CHAR
)
857 /* fall back to presentation form B */
858 WCHAR context_char
= wine_shaping_forms
[pwcChars
[i
] - FIRST_ARABIC_CHAR
][context_shape
[i
]];
859 if (context_char
!= pwcChars
[i
] && GetGlyphIndicesW(hdc
, &context_char
, 1, &newGlyph
, 0) != GDI_ERROR
&& newGlyph
!= 0x0000)
860 pwOutGlyphs
[i
] = newGlyph
;
867 while (arabic_GSUB_features
[i
] != NULL
)
869 apply_GSUB_feature(hdc
, psa
, psc
->GSUB_Table
, pwOutGlyphs
, dirL
, pcGlyphs
, arabic_GSUB_features
[i
]);
873 HeapFree(GetProcessHeap(),0,context_shape
);
874 HeapFree(GetProcessHeap(),0,context_type
);