blob: 18cefc44634eab912fd38096b986ed88dfe2e1de [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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. Sun designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
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
42le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
43{
44 switch(SWAPW(subtableFormat))
45 {
46 case 0:
47 return 0;
48
49 case 1:
50 {
51 const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
52
53 return subtable->process(glyphIterator, fontInstance);
54 }
55
56 case 2:
57 {
58 const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
59
60 return subtable->process(glyphIterator, fontInstance);
61 }
62
63 default:
64 return 0;
65 }
66}
67
68le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
69{
70 LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
71 le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
72 GlyphIterator tempIterator(*glyphIterator);
73
74 if (coverageIndex >= 0 && glyphIterator->next()) {
75 Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
76 PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
77 le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
78 le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
79 le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
80 le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
81 LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
82 const PairValueRecord *pairValueRecord = NULL;
83
84 if (pairValueCount != 0) {
85 pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph),
86 pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
87 }
88
89 if (pairValueRecord == NULL) {
90 return 0;
91 }
92
93 if (valueFormat1 != 0) {
94 pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this,
95 tempIterator, fontInstance);
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
110le_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
146const 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}