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 |
*
|
|
28 |
* (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include "LETypes.h"
|
|
33 |
#include "LEFontInstance.h"
|
|
34 |
#include "OpenTypeTables.h"
|
|
35 |
#include "GlyphPositioningTables.h"
|
|
36 |
#include "PairPositioningSubtables.h"
|
|
37 |
#include "ValueRecords.h"
|
|
38 |
#include "GlyphIterator.h"
|
|
39 |
#include "OpenTypeUtilities.h"
|
|
40 |
#include "LESwaps.h"
|
|
41 |
|
3935
|
42 |
U_NAMESPACE_BEGIN
|
|
43 |
|
16891
|
44 |
le_uint32 PairPositioningSubtable::process(const LEReferenceTo<PairPositioningSubtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2
|
45 |
{
|
|
46 |
switch(SWAPW(subtableFormat))
|
|
47 |
{
|
|
48 |
case 0:
|
|
49 |
return 0;
|
|
50 |
|
|
51 |
case 1:
|
|
52 |
{
|
16891
|
53 |
const LEReferenceTo<PairPositioningFormat1Subtable> subtable(base, success, (const PairPositioningFormat1Subtable *) this);
|
2
|
54 |
|
16891
|
55 |
if(LE_SUCCESS(success))
|
|
56 |
return subtable->process(subtable, glyphIterator, fontInstance, success);
|
|
57 |
else
|
|
58 |
return 0;
|
2
|
59 |
}
|
|
60 |
|
|
61 |
case 2:
|
|
62 |
{
|
16891
|
63 |
const LEReferenceTo<PairPositioningFormat2Subtable> subtable(base, success, (const PairPositioningFormat2Subtable *) this);
|
2
|
64 |
|
16891
|
65 |
if(LE_SUCCESS(success))
|
|
66 |
return subtable->process(subtable, glyphIterator, fontInstance, success);
|
|
67 |
else
|
|
68 |
return 0;
|
2
|
69 |
}
|
|
70 |
default:
|
16891
|
71 |
return 0;
|
2
|
72 |
}
|
|
73 |
}
|
|
74 |
|
16891
|
75 |
le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo<PairPositioningFormat1Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2
|
76 |
{
|
|
77 |
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
16891
|
78 |
le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
|
18254
|
79 |
|
|
80 |
if (LE_FAILURE(success)) {
|
|
81 |
return 0;
|
|
82 |
}
|
2
|
83 |
GlyphIterator tempIterator(*glyphIterator);
|
|
84 |
|
|
85 |
if (coverageIndex >= 0 && glyphIterator->next()) {
|
|
86 |
Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
|
18254
|
87 |
LEReferenceTo<PairSetTable> pairSetTable(base, success, ((char *) this + pairSetTableOffset));
|
|
88 |
if (LE_FAILURE(success)) {
|
|
89 |
return 0;
|
|
90 |
}
|
2
|
91 |
le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
|
|
92 |
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
93 |
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
94 |
le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
|
|
95 |
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
18254
|
96 |
LEReferenceTo<PairValueRecord> pairValueRecord;
|
2
|
97 |
|
|
98 |
if (pairValueCount != 0) {
|
18254
|
99 |
pairValueRecord = findPairValueRecord(base, (TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize, success);
|
2
|
100 |
}
|
|
101 |
|
18254
|
102 |
if (pairValueRecord.isEmpty()) {
|
2
|
103 |
return 0;
|
|
104 |
}
|
|
105 |
|
|
106 |
if (valueFormat1 != 0) {
|
3935
|
107 |
pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
2
|
108 |
}
|
|
109 |
|
|
110 |
if (valueFormat2 != 0) {
|
|
111 |
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
|
|
112 |
|
|
113 |
valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
|
|
114 |
}
|
|
115 |
|
7486
|
116 |
// back up glyphIterator so second glyph can be
|
|
117 |
// first glyph in the next pair
|
|
118 |
glyphIterator->prev();
|
|
119 |
return 1;
|
2
|
120 |
}
|
|
121 |
|
|
122 |
return 0;
|
|
123 |
}
|
|
124 |
|
16891
|
125 |
le_uint32 PairPositioningFormat2Subtable::process(const LEReferenceTo<PairPositioningFormat2Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2
|
126 |
{
|
|
127 |
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
16891
|
128 |
le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
|
2
|
129 |
GlyphIterator tempIterator(*glyphIterator);
|
|
130 |
|
|
131 |
if (coverageIndex >= 0 && glyphIterator->next()) {
|
|
132 |
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
|
133 |
const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
|
|
134 |
const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
|
|
135 |
le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
|
|
136 |
le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
|
|
137 |
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
138 |
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
139 |
le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
|
|
140 |
le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
|
|
141 |
const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
|
|
142 |
const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
|
|
143 |
|
|
144 |
|
|
145 |
if (valueFormat1 != 0) {
|
|
146 |
class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
|
147 |
}
|
|
148 |
|
|
149 |
if (valueFormat2 != 0) {
|
|
150 |
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
|
|
151 |
|
|
152 |
valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
|
|
153 |
}
|
|
154 |
|
7486
|
155 |
// back up glyphIterator so second glyph can be
|
|
156 |
// first glyph in the next pair
|
|
157 |
glyphIterator->prev();
|
|
158 |
return 1;
|
2
|
159 |
}
|
|
160 |
|
|
161 |
return 0;
|
|
162 |
}
|
|
163 |
|
18254
|
164 |
LEReferenceTo<PairValueRecord> PairPositioningFormat1Subtable::findPairValueRecord(const LETableReference &base, TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize, LEErrorCode &success) const
|
2
|
165 |
{
|
7486
|
166 |
#if 1
|
|
167 |
// The OpenType spec. says that the ValueRecord table is
|
|
168 |
// sorted by secondGlyph. Unfortunately, there are fonts
|
|
169 |
// around that have an unsorted ValueRecord table.
|
18254
|
170 |
LEReferenceTo<PairValueRecord> record(base, success, records);
|
|
171 |
record.verifyLength(0, recordSize, success);
|
7486
|
172 |
|
|
173 |
for(le_int32 r = 0; r < recordCount; r += 1) {
|
18254
|
174 |
if (LE_FAILURE(success)) return (const PairValueRecord*)NULL;
|
7486
|
175 |
if (SWAPW(record->secondGlyph) == glyphID) {
|
|
176 |
return record;
|
|
177 |
}
|
|
178 |
|
18254
|
179 |
record = LEReferenceTo<PairValueRecord>(base, success, ((const char*)record.getAlias())+ recordSize);
|
|
180 |
record.verifyLength(0, recordSize, success);
|
7486
|
181 |
}
|
|
182 |
#else
|
18254
|
183 |
#error dead code - not updated.
|
2
|
184 |
le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
|
|
185 |
le_uint16 power = 1 << bit;
|
|
186 |
le_uint16 extra = (recordCount - power) * recordSize;
|
|
187 |
le_uint16 probe = power * recordSize;
|
|
188 |
const PairValueRecord *record = records;
|
|
189 |
const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
|
|
190 |
|
|
191 |
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
192 |
record = trial;
|
|
193 |
}
|
|
194 |
|
|
195 |
while (probe > recordSize) {
|
|
196 |
probe >>= 1;
|
|
197 |
trial = (const PairValueRecord *) ((char *) record + probe);
|
|
198 |
|
|
199 |
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
200 |
record = trial;
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
if (SWAPW(record->secondGlyph) == glyphID) {
|
|
205 |
return record;
|
|
206 |
}
|
7486
|
207 |
#endif
|
2
|
208 |
|
18254
|
209 |
return (const PairValueRecord*)NULL;
|
2
|
210 |
}
|
3935
|
211 |
|
|
212 |
U_NAMESPACE_END
|