1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 * |
|
4 * This code is free software; you can redistribute it and/or modify it |
|
5 * under the terms of the GNU General Public License version 2 only, as |
|
6 * published by the Free Software Foundation. Oracle designates this |
|
7 * particular file as subject to the "Classpath" exception as provided |
|
8 * by Oracle in the LICENSE file that accompanied this code. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 * |
|
24 */ |
|
25 |
|
26 /* |
|
27 * |
|
28 * |
|
29 * (C) Copyright IBM Corp. 1998-2006 - All Rights Reserved |
|
30 * |
|
31 */ |
|
32 |
|
33 #include "LETypes.h" |
|
34 #include "LEGlyphFilter.h" |
|
35 #include "OpenTypeTables.h" |
|
36 #include "GlyphSubstitutionTables.h" |
|
37 #include "LigatureSubstSubtables.h" |
|
38 #include "GlyphIterator.h" |
|
39 #include "LESwaps.h" |
|
40 |
|
41 U_NAMESPACE_BEGIN |
|
42 |
|
43 le_uint32 LigatureSubstitutionSubtable::process(const LETableReference &base, GlyphIterator *glyphIterator, LEErrorCode &success, const LEGlyphFilter *filter) const |
|
44 { |
|
45 LEGlyphID glyph = glyphIterator->getCurrGlyphID(); |
|
46 le_int32 coverageIndex = getGlyphCoverage(base, glyph, success); |
|
47 |
|
48 if (LE_FAILURE(success)) { |
|
49 return 0; |
|
50 } |
|
51 |
|
52 LEReferenceToArrayOf<Offset> ligSetTableOffsetArrayRef(base, success, ligSetTableOffsetArray, SWAPW(ligSetCount)); |
|
53 |
|
54 if (coverageIndex >= 0 && LE_SUCCESS(success) && (le_uint32)coverageIndex < ligSetTableOffsetArrayRef.getCount()) { |
|
55 Offset ligSetTableOffset = SWAPW(ligSetTableOffsetArray[coverageIndex]); |
|
56 LEReferenceTo<LigatureSetTable> ligSetTable(base, success, ligSetTableOffset); |
|
57 |
|
58 if( LE_FAILURE(success) ) { return 0; } |
|
59 le_uint16 ligCount = SWAPW(ligSetTable->ligatureCount); |
|
60 |
|
61 LEReferenceToArrayOf<Offset> ligatureTableOffsetArray(base, success, ligSetTable->ligatureTableOffsetArray, ligCount); |
|
62 for (le_uint16 lig = 0; LE_SUCCESS(success) && lig < ligCount; lig += 1) { |
|
63 Offset ligTableOffset = SWAPW(ligSetTable->ligatureTableOffsetArray[lig]); |
|
64 LEReferenceTo<LigatureTable> ligTable(ligSetTable, success, ligTableOffset); |
|
65 if(LE_FAILURE(success)) { return 0; } |
|
66 le_uint16 compCount = SWAPW(ligTable->compCount) - 1; |
|
67 LEReferenceToArrayOf<TTGlyphID> |
|
68 componentArrayRef(base, success, ligTable->componentArray, compCount); |
|
69 if (LE_FAILURE(success)) { return 0; } |
|
70 le_int32 startPosition = glyphIterator->getCurrStreamPosition(); |
|
71 TTGlyphID ligGlyph = SWAPW(ligTable->ligGlyph); |
|
72 le_uint16 comp; |
|
73 |
|
74 for (comp = 0; comp < compCount; comp += 1) { |
|
75 if (! glyphIterator->next()) { |
|
76 break; |
|
77 } |
|
78 |
|
79 if (LE_GET_GLYPH(glyphIterator->getCurrGlyphID()) != SWAPW(ligTable->componentArray[comp])) { |
|
80 break; |
|
81 } |
|
82 } |
|
83 |
|
84 if (comp == compCount && (filter == NULL || filter->accept(LE_SET_GLYPH(glyph, ligGlyph), success))) { |
|
85 GlyphIterator tempIterator(*glyphIterator); |
|
86 TTGlyphID deletedGlyph = tempIterator.ignoresMarks()? 0xFFFE : 0xFFFF; |
|
87 |
|
88 while (comp > 0) { |
|
89 tempIterator.setCurrGlyphID(deletedGlyph); |
|
90 tempIterator.prev(); |
|
91 |
|
92 comp -= 1; |
|
93 } |
|
94 |
|
95 tempIterator.setCurrGlyphID(ligGlyph); |
|
96 |
|
97 return compCount + 1; |
|
98 } |
|
99 |
|
100 glyphIterator->setCurrStreamPosition(startPosition); |
|
101 } |
|
102 |
|
103 } |
|
104 |
|
105 return 0; |
|
106 } |
|
107 |
|
108 U_NAMESPACE_END |
|