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 |
|
2
|
44 |
le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
|
|
45 |
{
|
|
46 |
switch(SWAPW(subtableFormat))
|
|
47 |
{
|
|
48 |
case 0:
|
|
49 |
return 0;
|
|
50 |
|
|
51 |
case 1:
|
|
52 |
{
|
|
53 |
const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
|
|
54 |
|
|
55 |
return subtable->process(glyphIterator, fontInstance);
|
|
56 |
}
|
|
57 |
|
|
58 |
case 2:
|
|
59 |
{
|
|
60 |
const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
|
|
61 |
|
|
62 |
return subtable->process(glyphIterator, fontInstance);
|
|
63 |
}
|
|
64 |
|
|
65 |
default:
|
|
66 |
return 0;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
|
|
71 |
{
|
|
72 |
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
|
73 |
le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
|
|
74 |
GlyphIterator tempIterator(*glyphIterator);
|
|
75 |
|
|
76 |
if (coverageIndex >= 0 && glyphIterator->next()) {
|
|
77 |
Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
|
|
78 |
PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
|
|
79 |
le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
|
|
80 |
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
81 |
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
82 |
le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
|
|
83 |
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
|
84 |
const PairValueRecord *pairValueRecord = NULL;
|
|
85 |
|
|
86 |
if (pairValueCount != 0) {
|
3935
|
87 |
pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
|
2
|
88 |
}
|
|
89 |
|
|
90 |
if (pairValueRecord == NULL) {
|
|
91 |
return 0;
|
|
92 |
}
|
|
93 |
|
|
94 |
if (valueFormat1 != 0) {
|
3935
|
95 |
pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
2
|
96 |
}
|
|
97 |
|
|
98 |
if (valueFormat2 != 0) {
|
|
99 |
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
|
|
100 |
|
|
101 |
valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
|
|
102 |
}
|
|
103 |
|
|
104 |
return 2;
|
|
105 |
}
|
|
106 |
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
|
|
110 |
le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
|
|
111 |
{
|
|
112 |
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
|
113 |
le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
|
|
114 |
GlyphIterator tempIterator(*glyphIterator);
|
|
115 |
|
|
116 |
if (coverageIndex >= 0 && glyphIterator->next()) {
|
|
117 |
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
|
118 |
const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
|
|
119 |
const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
|
|
120 |
le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
|
|
121 |
le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
|
|
122 |
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
123 |
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
124 |
le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
|
|
125 |
le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
|
|
126 |
const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
|
|
127 |
const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
|
|
128 |
|
|
129 |
|
|
130 |
if (valueFormat1 != 0) {
|
|
131 |
class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
|
132 |
}
|
|
133 |
|
|
134 |
if (valueFormat2 != 0) {
|
|
135 |
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
|
|
136 |
|
|
137 |
valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
|
|
138 |
}
|
|
139 |
|
|
140 |
return 2;
|
|
141 |
}
|
|
142 |
|
|
143 |
return 0;
|
|
144 |
}
|
|
145 |
|
|
146 |
const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
|
|
147 |
{
|
|
148 |
le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
|
|
149 |
le_uint16 power = 1 << bit;
|
|
150 |
le_uint16 extra = (recordCount - power) * recordSize;
|
|
151 |
le_uint16 probe = power * recordSize;
|
|
152 |
const PairValueRecord *record = records;
|
|
153 |
const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
|
|
154 |
|
|
155 |
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
156 |
record = trial;
|
|
157 |
}
|
|
158 |
|
|
159 |
while (probe > recordSize) {
|
|
160 |
probe >>= 1;
|
|
161 |
trial = (const PairValueRecord *) ((char *) record + probe);
|
|
162 |
|
|
163 |
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
164 |
record = trial;
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
if (SWAPW(record->secondGlyph) == glyphID) {
|
|
169 |
return record;
|
|
170 |
}
|
|
171 |
|
|
172 |
return NULL;
|
|
173 |
}
|
3935
|
174 |
|
|
175 |
U_NAMESPACE_END
|