3 * (C) Copyright IBM Corp. 1998-2008 - 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(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(glyph
);
37 le_uint16 seqCount
= SWAPW(sequenceCount
);
39 if (coverageIndex
>= 0 && coverageIndex
< seqCount
) {
40 Offset sequenceTableOffset
= SWAPW(sequenceTableOffsetArray
[coverageIndex
]);
41 const SequenceTable
*sequenceTable
= (const SequenceTable
*) ((char *) this + sequenceTableOffset
);
42 le_uint16 glyphCount
= SWAPW(sequenceTable
->glyphCount
);
44 if (glyphCount
== 0) {
45 glyphIterator
->setCurrGlyphID(0xFFFF);
47 } else if (glyphCount
== 1) {
48 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[0]);
50 if (filter
!= NULL
&& ! filter
->accept(LE_SET_GLYPH(glyph
, substitute
))) {
54 glyphIterator
->setCurrGlyphID(substitute
);
57 // If there's a filter, make sure all of the output glyphs
60 for (le_int32 i
= 0; i
< glyphCount
; i
+= 1) {
61 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[i
]);
63 if (! filter
->accept(substitute
)) {
69 LEGlyphID
*newGlyphs
= glyphIterator
->insertGlyphs(glyphCount
, success
);
70 if (LE_FAILURE(success
)) {
74 le_int32 insert
= 0, direction
= 1;
76 if (glyphIterator
->isRightToLeft()) {
77 insert
= glyphCount
- 1;
81 for (le_int32 i
= 0; i
< glyphCount
; i
+= 1) {
82 TTGlyphID substitute
= SWAPW(sequenceTable
->substituteArray
[i
]);
84 newGlyphs
[insert
] = LE_SET_GLYPH(glyph
, substitute
);