3 * (C) Copyright IBM Corp. 1998-2015 - All Rights Reserved
8 #include "LEGlyphFilter.h"
9 #include "OpenTypeTables.h"
10 #include "GlyphSubstitutionTables.h"
11 #include "MultipleSubstSubtables.h"
12 #include "GlyphIterator.h"
17 le_uint32
MultipleSubstitutionSubtable::process(const LETableReference
&base
, GlyphIterator
*glyphIterator
, LEErrorCode
& success
, const LEGlyphFilter
*filter
) const
19 if (LE_FAILURE(success
)) {
23 LEGlyphID glyph
= glyphIterator
->getCurrGlyphID();
25 // If there's a filter, we only want to do the
26 // substitution if the *input* glyphs doesn't
29 // FIXME: is this always the right thing to do?
30 // FIXME: should this only be done for a non-zero
32 if (filter
!= NULL
&& filter
->accept(glyph
)) {
36 le_int32 coverageIndex
= getGlyphCoverage(base
, glyph
, success
);
37 le_uint16 seqCount
= SWAPW(sequenceCount
);
38 LEReferenceToArrayOf
<Offset
>
39 sequenceTableOffsetArrayRef(base
, success
, sequenceTableOffsetArray
, seqCount
);
41 if (LE_FAILURE(success
)) {
44 if (coverageIndex
>= 0 && coverageIndex
< seqCount
) {
45 Offset sequenceTableOffset
= SWAPW(sequenceTableOffsetArray
[coverageIndex
]);
46 const SequenceTable
*sequenceTable
= (const SequenceTable
*) ((char *) this + sequenceTableOffset
);
47 le_uint16 glyphCount
= SWAPW(sequenceTable
->glyphCount
);
49 if (glyphCount
== 0) {
50 glyphIterator
->setCurrGlyphID(0xFFFF);
52 } else if (glyphCount
== 1) {
53 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[0]);
55 if (filter
!= NULL
&& ! filter
->accept(LE_SET_GLYPH(glyph
, substitute
))) {
59 glyphIterator
->setCurrGlyphID(substitute
);
62 // If there's a filter, make sure all of the output glyphs
65 for (le_int32 i
= 0; i
< glyphCount
; i
+= 1) {
66 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[i
]);
68 if (! filter
->accept(substitute
)) {
74 LEGlyphID
*newGlyphs
= glyphIterator
->insertGlyphs(glyphCount
, success
);
75 if (LE_FAILURE(success
)) {
79 le_int32 insert
= 0, direction
= 1;
81 if (glyphIterator
->isRightToLeft()) {
82 insert
= glyphCount
- 1;
86 for (le_int32 i
= 0; i
< glyphCount
; i
+= 1) {
87 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[i
]);
89 newGlyphs
[insert
] = LE_SET_GLYPH(glyph
, substitute
);