16889
|
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 |
* (C) Copyright IBM Corp and Others. 1998-2013 - All Rights Reserved
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include "LETypes.h"
|
|
33 |
#include "MorphTables.h"
|
|
34 |
#include "StateTables.h"
|
|
35 |
#include "MorphStateTables.h"
|
|
36 |
#include "SubtableProcessor2.h"
|
|
37 |
#include "StateTableProcessor2.h"
|
|
38 |
#include "LigatureSubstProc2.h"
|
|
39 |
#include "LEGlyphStorage.h"
|
|
40 |
#include "LESwaps.h"
|
|
41 |
|
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
|
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 |
|
|
48 |
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LigatureSubstitutionProcessor2)
|
|
49 |
|
|
50 |
LigatureSubstitutionProcessor2::LigatureSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
|
|
51 |
: StateTableProcessor2(morphSubtableHeader)
|
|
52 |
{
|
|
53 |
ligatureSubstitutionHeader = (const LigatureSubstitutionHeader2 *) morphSubtableHeader;
|
|
54 |
ligActionOffset = SWAPL(ligatureSubstitutionHeader->ligActionOffset);
|
|
55 |
componentOffset = SWAPL(ligatureSubstitutionHeader->componentOffset);
|
|
56 |
ligatureOffset = SWAPL(ligatureSubstitutionHeader->ligatureOffset);
|
|
57 |
|
|
58 |
entryTable = (const LigatureSubstitutionStateEntry2 *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
|
|
59 |
}
|
|
60 |
|
|
61 |
LigatureSubstitutionProcessor2::~LigatureSubstitutionProcessor2()
|
|
62 |
{
|
|
63 |
}
|
|
64 |
|
|
65 |
void LigatureSubstitutionProcessor2::beginStateTable()
|
|
66 |
{
|
|
67 |
m = -1;
|
|
68 |
}
|
|
69 |
|
|
70 |
le_uint16 LigatureSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index)
|
|
71 |
{
|
|
72 |
const LigatureSubstitutionStateEntry2 *entry = &entryTable[index];
|
|
73 |
le_uint16 nextStateIndex = SWAPW(entry->nextStateIndex);
|
|
74 |
le_uint16 flags = SWAPW(entry->entryFlags);
|
|
75 |
le_uint16 ligActionIndex = SWAPW(entry->ligActionIndex);
|
|
76 |
|
|
77 |
if (flags & lsfSetComponent) {
|
|
78 |
if (++m >= nComponents) {
|
|
79 |
m = 0;
|
|
80 |
}
|
|
81 |
componentStack[m] = currGlyph;
|
|
82 |
}
|
|
83 |
|
|
84 |
ByteOffset actionOffset = flags & lsfPerformAction;
|
|
85 |
|
|
86 |
if (actionOffset != 0) {
|
|
87 |
const LigatureActionEntry *ap = (const LigatureActionEntry *) ((char *) &ligatureSubstitutionHeader->stHeader + ligActionOffset) + ligActionIndex;
|
|
88 |
const TTGlyphID *ligatureTable = (const TTGlyphID *) ((char *) &ligatureSubstitutionHeader->stHeader + ligatureOffset);
|
|
89 |
LigatureActionEntry action;
|
|
90 |
le_int32 offset, i = 0;
|
|
91 |
le_int32 stack[nComponents];
|
|
92 |
le_int16 mm = -1;
|
|
93 |
|
|
94 |
const le_uint16 *componentTable = (const le_uint16 *)((char *) &ligatureSubstitutionHeader->stHeader + componentOffset);
|
|
95 |
|
|
96 |
do {
|
|
97 |
le_uint32 componentGlyph = componentStack[m--]; // pop off
|
|
98 |
|
|
99 |
action = SWAPL(*ap++);
|
|
100 |
|
|
101 |
if (m < 0) {
|
|
102 |
m = nComponents - 1;
|
|
103 |
}
|
|
104 |
|
|
105 |
offset = action & lafComponentOffsetMask;
|
|
106 |
if (offset != 0) {
|
|
107 |
|
|
108 |
i += SWAPW(componentTable[LE_GET_GLYPH(glyphStorage[componentGlyph]) + (SignExtend(offset, lafComponentOffsetMask))]);
|
|
109 |
|
|
110 |
if (action & (lafLast | lafStore)) {
|
|
111 |
TTGlyphID ligatureGlyph = SWAPW(ligatureTable[i]);
|
|
112 |
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], ligatureGlyph);
|
|
113 |
stack[++mm] = componentGlyph;
|
|
114 |
i = 0;
|
|
115 |
} else {
|
|
116 |
glyphStorage[componentGlyph] = LE_SET_GLYPH(glyphStorage[componentGlyph], 0xFFFF);
|
|
117 |
}
|
|
118 |
}
|
|
119 |
} while (!(action & lafLast));
|
|
120 |
|
|
121 |
while (mm >= 0) {
|
|
122 |
if (++m >= nComponents) {
|
|
123 |
m = 0;
|
|
124 |
}
|
|
125 |
|
|
126 |
componentStack[m] = stack[mm--];
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
if (!(flags & lsfDontAdvance)) {
|
|
131 |
currGlyph += dir;
|
|
132 |
}
|
|
133 |
|
|
134 |
return nextStateIndex;
|
|
135 |
}
|
|
136 |
|
|
137 |
void LigatureSubstitutionProcessor2::endStateTable()
|
|
138 |
{
|
|
139 |
}
|
|
140 |
|
|
141 |
U_NAMESPACE_END
|