2
|
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
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
23 |
*
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
*
|
16890
|
28 |
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
|
2
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include "LETypes.h"
|
|
33 |
#include "MorphTables.h"
|
|
34 |
#include "StateTables.h"
|
|
35 |
#include "MorphStateTables.h"
|
|
36 |
#include "SubtableProcessor.h"
|
|
37 |
#include "StateTableProcessor.h"
|
|
38 |
#include "LigatureSubstProc.h"
|
|
39 |
#include "LEGlyphStorage.h"
|
|
40 |
#include "LESwaps.h"
|
|
41 |
|
3935
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
2
|
44 |
#define ExtendedComplement(m) ((le_int32) (~((le_uint32) (m))))
|
|
45 |
#define SignBit(m) ((ExtendedComplement(m) >> 1) & (le_int32)(m))
|
|
46 |
#define SignExtend(v,m) (((v) & SignBit(m))? ((v) | ExtendedComplement(m)): (v))
|
|
47 |
|
3935
|
48 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor)
|
|
49 |
|
16891
|
50 |
LigatureSubstitutionProcessor::LigatureSubstitutionProcessor(const LEReferenceTo<MorphSubtableHeader> &morphSubtableHeader, LEErrorCode &success)
|
|
51 |
: StateTableProcessor(morphSubtableHeader, success), ligatureSubstitutionHeader(morphSubtableHeader, success)
|
2
|
52 |
{
|
16891
|
53 |
if(LE_FAILURE(success)) return;
|
2
|
54 |
ligatureActionTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureActionTableOffset);
|
|
55 |
componentTableOffset = SWAPW(ligatureSubstitutionHeader->componentTableOffset);
|
|
56 |
ligatureTableOffset = SWAPW(ligatureSubstitutionHeader->ligatureTableOffset);
|
|
57 |
|
16891
|
58 |
entryTable = LEReferenceToArrayOf<LigatureSubstitutionStateEntry>(stHeader, success, entryTableOffset, LE_UNBOUNDED_ARRAY);
|
2
|
59 |
}
|
|
60 |
|
|
61 |
LigatureSubstitutionProcessor::~LigatureSubstitutionProcessor()
|
|
62 |
{
|
|
63 |
}
|
|
64 |
|
|
65 |
void LigatureSubstitutionProcessor::beginStateTable()
|
|
66 |
{
|
|
67 |
m = -1;
|
|
68 |
}
|
|
69 |
|
3935
|
70 |
ByteOffset LigatureSubstitutionProcessor::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex index)
|
2
|
71 |
{
|
16891
|
72 |
LEErrorCode success = LE_NO_ERROR;
|
|
73 |
const LigatureSubstitutionStateEntry *entry = entryTable.getAlias(index, success);
|
|
74 |
|
2
|
75 |
ByteOffset newState = SWAPW(entry->newStateOffset);
|
|
76 |
le_int16 flags = SWAPW(entry->flags);
|
|
77 |
|
|
78 |
if (flags & lsfSetComponent) {
|
|
79 |
if (++m >= nComponents) {
|
|
80 |
m = 0;
|
|
81 |
}
|
|
82 |
|
|
83 |
componentStack[m] = currGlyph;
|
16890
|
84 |
} else if ( m == -1) {
|
|
85 |
// bad font- skip this glyph.
|
|
86 |
currGlyph++;
|
|
87 |
return newState;
|
2
|
88 |
}
|
|
89 |
|
|
90 |
ByteOffset actionOffset = flags & lsfActionOffsetMask;
|
|
91 |
|
|
92 |
if (actionOffset != 0) {
|
16891
|
93 |
LEReferenceTo<LigatureActionEntry> ap(stHeader, success, actionOffset);
|
2
|
94 |
LigatureActionEntry action;
|
|
95 |
le_int32 offset, i = 0;
|
|
96 |
le_int32 stack[nComponents];
|
|
97 |
le_int16 mm = -1;
|
|
98 |
|
|
99 |
do {
|
|
100 |
le_uint32 componentGlyph = componentStack[m--];
|
|
101 |
|
16891
|
102 |
action = SWAPL(*ap.getAlias());
|
|
103 |
ap.addObject(success); // ap++
|
2
|
104 |
|
|
105 |
if (m < 0) {
|
|
106 |
m = nComponents - 1;
|
|
107 |
}
|
|
108 |
|
|
109 |
offset = action & lafComponentOffsetMask;
|
|
110 |
if (offset != 0) {
|
16891
|
111 |
LEReferenceToArrayOf<le_int16> offsetTable(stHeader, success, 2 * SignExtend(offset, lafComponentOffsetMask), LE_UNBOUNDED_ARRAY);
|
2
|
112 |
|
16891
|
113 |
if(LE_FAILURE(success)) {
|
16890
|
114 |
currGlyph++;
|
|
115 |
LE_DEBUG_BAD_FONT("off end of ligature substitution header");
|
|
116 |
return newState; // get out! bad font
|
16891
|
117 |
}
|
|
118 |
if(componentGlyph > glyphStorage.getGlyphCount()) {
|
|
119 |
LE_DEBUG_BAD_FONT("preposterous componentGlyph");
|
|
120 |
currGlyph++;
|
|
121 |
return newState; // get out! bad font
|
|
122 |
}
|
|
123 |
i += SWAPW(offsetTable.getObject(LE_GET_GLYPH(glyphStorage[componentGlyph]), success));
|
2
|
124 |
|
|
125 |
if (action & (lafLast | lafStore)) {
|
16891
|
126 |
LEReferenceTo<TTGlyphID> ligatureOffset(stHeader, success, i);
|
|
127 |
TTGlyphID ligatureGlyph = SWAPW(*ligatureOffset.getAlias());
|
2
|
128 |
|
16891
|
129 |
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
|
|
130 |
if(mm==nComponents) {
|
|
131 |
LE_DEBUG_BAD_FONT("exceeded nComponents");
|
|
132 |
mm--; // don't overrun the stack.
|
|
133 |
}
|
|
134 |
stack[++mm] = componentGlyph;
|
|
135 |
i = 0;
|
2
|
136 |
} else {
|
16891
|
137 |
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
|
2
|
138 |
}
|
|
139 |
}
|
16890
|
140 |
#if LE_ASSERT_BAD_FONT
|
|
141 |
if(m<0) {
|
|
142 |
LE_DEBUG_BAD_FONT("m<0")
|
|
143 |
}
|
|
144 |
#endif
|
|
145 |
} while (!(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items
|
2
|
146 |
|
|
147 |
while (mm >= 0) {
|
16891
|
148 |
if (++m >= nComponents) {
|
|
149 |
m = 0;
|
|
150 |
}
|
2
|
151 |
|
16891
|
152 |
componentStack[m] = stack[mm--];
|
2
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
if (!(flags & lsfDontAdvance)) {
|
|
157 |
// should handle reverse too!
|
|
158 |
currGlyph += 1;
|
|
159 |
}
|
|
160 |
|
|
161 |
return newState;
|
|
162 |
}
|
|
163 |
|
|
164 |
void LigatureSubstitutionProcessor::endStateTable()
|
|
165 |
{
|
|
166 |
}
|
3935
|
167 |
|
|
168 |
U_NAMESPACE_END
|