author | prr |
Thu, 07 Mar 2013 10:02:20 -0800 | |
changeset 16891 | 91e99bed64ae |
parent 16890 | 36b30720a997 |
child 18219 | d4cd832b9802 |
permissions | -rw-r--r-- |
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 |
* |
|
16889 | 28 |
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved |
2 | 29 |
* |
30 |
*/ |
|
31 |
||
32 |
#include "LETypes.h" |
|
33 |
#include "OpenTypeUtilities.h" |
|
34 |
#include "LEFontInstance.h" |
|
35 |
#include "OpenTypeTables.h" |
|
7486 | 36 |
#include "ICUFeatures.h" |
2 | 37 |
#include "Lookups.h" |
38 |
#include "ScriptAndLanguage.h" |
|
39 |
#include "GlyphDefinitionTables.h" |
|
40 |
#include "GlyphIterator.h" |
|
41 |
#include "LookupProcessor.h" |
|
42 |
#include "LEGlyphStorage.h" |
|
43 |
#include "LESwaps.h" |
|
44 |
||
3935 | 45 |
U_NAMESPACE_BEGIN |
46 |
||
16891 | 47 |
le_uint32 LookupProcessor::applyLookupTable(const LEReferenceTo<LookupTable> &lookupTable, GlyphIterator *glyphIterator, |
7486 | 48 |
const LEFontInstance *fontInstance, LEErrorCode& success) const |
2 | 49 |
{ |
7486 | 50 |
if (LE_FAILURE(success)) { |
51 |
return 0; |
|
52 |
} |
|
53 |
||
2 | 54 |
le_uint16 lookupType = SWAPW(lookupTable->lookupType); |
55 |
le_uint16 subtableCount = SWAPW(lookupTable->subTableCount); |
|
56 |
le_int32 startPosition = glyphIterator->getCurrStreamPosition(); |
|
57 |
le_uint32 delta; |
|
58 |
||
59 |
for (le_uint16 subtable = 0; subtable < subtableCount; subtable += 1) { |
|
16891 | 60 |
LEReferenceTo<LookupSubtable> lookupSubtable = lookupTable->getLookupSubtable(lookupTable, subtable, success); |
2 | 61 |
|
7486 | 62 |
delta = applySubtable(lookupSubtable, lookupType, glyphIterator, fontInstance, success); |
2 | 63 |
|
7486 | 64 |
if (delta > 0 && LE_FAILURE(success)) { |
2 | 65 |
return 1; |
66 |
} |
|
67 |
||
68 |
glyphIterator->setCurrStreamPosition(startPosition); |
|
69 |
} |
|
70 |
||
71 |
return 1; |
|
72 |
} |
|
73 |
||
3935 | 74 |
le_int32 LookupProcessor::process(LEGlyphStorage &glyphStorage, GlyphPositionAdjustments *glyphPositionAdjustments, |
16891 | 75 |
le_bool rightToLeft, const LEReferenceTo<GlyphDefinitionTableHeader> &glyphDefinitionTableHeader, |
7486 | 76 |
const LEFontInstance *fontInstance, LEErrorCode& success) const |
2 | 77 |
{ |
7486 | 78 |
if (LE_FAILURE(success)) { |
79 |
return 0; |
|
80 |
} |
|
81 |
||
2 | 82 |
le_int32 glyphCount = glyphStorage.getGlyphCount(); |
83 |
||
84 |
if (lookupSelectArray == NULL) { |
|
85 |
return glyphCount; |
|
86 |
} |
|
87 |
||
88 |
GlyphIterator glyphIterator(glyphStorage, glyphPositionAdjustments, |
|
89 |
rightToLeft, 0, 0, glyphDefinitionTableHeader); |
|
90 |
le_int32 newGlyphCount = glyphCount; |
|
91 |
||
16891 | 92 |
for (le_uint16 order = 0; order < lookupOrderCount && LE_SUCCESS(success); order += 1) { |
2 | 93 |
le_uint16 lookup = lookupOrderArray[order]; |
94 |
FeatureMask selectMask = lookupSelectArray[lookup]; |
|
95 |
||
96 |
if (selectMask != 0) { |
|
16891 | 97 |
const LEReferenceTo<LookupTable> lookupTable = lookupListTable->getLookupTable(lookupListTable, lookup, success); |
98 |
if (!lookupTable.isValid() ||LE_FAILURE(success) ) { |
|
13036 | 99 |
continue; |
16889 | 100 |
} |
2 | 101 |
le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags); |
102 |
||
103 |
glyphIterator.reset(lookupFlags, selectMask); |
|
104 |
||
105 |
while (glyphIterator.findFeatureTag()) { |
|
16891 | 106 |
applyLookupTable(lookupTable, &glyphIterator, fontInstance, success); // TODO |
7486 | 107 |
if (LE_FAILURE(success)) { |
108 |
return 0; |
|
2 | 109 |
} |
110 |
} |
|
111 |
||
112 |
newGlyphCount = glyphIterator.applyInsertions(); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
return newGlyphCount; |
|
117 |
} |
|
118 |
||
119 |
le_uint32 LookupProcessor::applySingleLookup(le_uint16 lookupTableIndex, GlyphIterator *glyphIterator, |
|
7486 | 120 |
const LEFontInstance *fontInstance, LEErrorCode& success) const |
2 | 121 |
{ |
7486 | 122 |
if (LE_FAILURE(success)) { |
123 |
return 0; |
|
124 |
} |
|
125 |
||
16891 | 126 |
const LEReferenceTo<LookupTable> lookupTable = lookupListTable->getLookupTable(lookupListTable, lookupTableIndex, success); |
127 |
if (!lookupTable.isValid()) { |
|
15967
688298c47675
8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents:
13036
diff
changeset
|
128 |
success = LE_INTERNAL_ERROR; |
688298c47675
8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents:
13036
diff
changeset
|
129 |
return 0; |
688298c47675
8005191: [parfait] #384 sun/font/layout/LookupProcessor.cpp Null pointer dereference
jgodinez
parents:
13036
diff
changeset
|
130 |
} |
2 | 131 |
le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags); |
132 |
GlyphIterator tempIterator(*glyphIterator, lookupFlags); |
|
7486 | 133 |
le_uint32 delta = applyLookupTable(lookupTable, &tempIterator, fontInstance, success); |
2 | 134 |
|
135 |
return delta; |
|
136 |
} |
|
137 |
||
16891 | 138 |
le_int32 LookupProcessor::selectLookups(const LEReferenceTo<FeatureTable> &featureTable, FeatureMask featureMask, le_int32 order, LEErrorCode &success) |
2 | 139 |
{ |
16891 | 140 |
le_uint16 lookupCount = featureTable.isValid()? SWAPW(featureTable->lookupCount) : 0; |
2 | 141 |
le_int32 store = order; |
142 |
||
16891 | 143 |
LEReferenceToArrayOf<le_uint16> lookupListIndexArray(featureTable, success, featureTable->lookupListIndexArray, lookupCount); |
13036 | 144 |
|
16891 | 145 |
for (le_uint16 lookup = 0; LE_SUCCESS(success) && lookup < lookupCount; lookup += 1) { |
146 |
le_uint16 lookupListIndex = SWAPW(lookupListIndexArray.getObject(lookup,success)); |
|
147 |
if (lookupListIndex >= lookupSelectCount) { |
|
148 |
continue; |
|
149 |
} |
|
150 |
||
151 |
lookupSelectArray[lookupListIndex] |= featureMask; |
|
152 |
lookupOrderArray[store++] = lookupListIndex; |
|
2 | 153 |
} |
154 |
||
155 |
return store - order; |
|
156 |
} |
|
157 |
||
16891 | 158 |
LookupProcessor::LookupProcessor(const LETableReference &baseAddress, |
2 | 159 |
Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset, |
7486 | 160 |
LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures, |
161 |
LEErrorCode& success) |
|
16891 | 162 |
: lookupListTable(), featureListTable(), lookupSelectArray(NULL), lookupSelectCount(0), |
163 |
lookupOrderArray(NULL), lookupOrderCount(0), fReference(baseAddress) |
|
2 | 164 |
{ |
16891 | 165 |
LEReferenceTo<ScriptListTable> scriptListTable; |
166 |
LEReferenceTo<LangSysTable> langSysTable; |
|
2 | 167 |
le_uint16 featureCount = 0; |
168 |
le_uint16 lookupListCount = 0; |
|
169 |
le_uint16 requiredFeatureIndex; |
|
170 |
||
7486 | 171 |
if (LE_FAILURE(success)) { |
172 |
return; |
|
173 |
} |
|
174 |
||
2 | 175 |
if (scriptListOffset != 0) { |
16891 | 176 |
scriptListTable = LEReferenceTo<ScriptListTable>(baseAddress, success, scriptListOffset); |
177 |
langSysTable = scriptListTable->findLanguage(scriptListTable, scriptTag, languageTag, success); |
|
2 | 178 |
|
16891 | 179 |
if (langSysTable.isValid() && LE_SUCCESS(success)) { |
180 |
featureCount = SWAPW(langSysTable->featureCount); |
|
181 |
} |
|
2 | 182 |
} |
183 |
||
184 |
if (featureListOffset != 0) { |
|
16891 | 185 |
featureListTable = LEReferenceTo<FeatureListTable>(baseAddress, success, featureListOffset); |
2 | 186 |
} |
187 |
||
188 |
if (lookupListOffset != 0) { |
|
16891 | 189 |
lookupListTable = LEReferenceTo<LookupListTable>(baseAddress,success, lookupListOffset); |
190 |
if(LE_SUCCESS(success) && lookupListTable.isValid()) { |
|
2 | 191 |
lookupListCount = SWAPW(lookupListTable->lookupCount); |
16891 | 192 |
} |
2 | 193 |
} |
194 |
||
16891 | 195 |
if (langSysTable.isEmpty() || featureListTable.isEmpty() || lookupListTable.isEmpty() || |
2 | 196 |
featureCount == 0 || lookupListCount == 0) { |
197 |
return; |
|
198 |
} |
|
199 |
||
16891 | 200 |
if(langSysTable.isValid()) { |
201 |
requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex); |
|
202 |
} |
|
2 | 203 |
|
204 |
lookupSelectArray = LE_NEW_ARRAY(FeatureMask, lookupListCount); |
|
7486 | 205 |
if (lookupSelectArray == NULL) { |
206 |
success = LE_MEMORY_ALLOCATION_ERROR; |
|
207 |
return; |
|
208 |
} |
|
2 | 209 |
|
210 |
for (int i = 0; i < lookupListCount; i += 1) { |
|
211 |
lookupSelectArray[i] = 0; |
|
212 |
} |
|
213 |
||
13036 | 214 |
lookupSelectCount = lookupListCount; |
215 |
||
2 | 216 |
le_int32 count, order = 0; |
16890 | 217 |
le_uint32 featureReferences = 0; |
16891 | 218 |
LEReferenceTo<FeatureTable> featureTable; |
2 | 219 |
LETag featureTag; |
220 |
||
16891 | 221 |
LEReferenceTo<FeatureTable> requiredFeatureTable; |
2 | 222 |
LETag requiredFeatureTag = 0x00000000U; |
223 |
||
224 |
// Count the total number of lookups referenced by all features. This will |
|
225 |
// be the maximum number of entries in the lookupOrderArray. We can't use |
|
226 |
// lookupListCount because some lookups might be referenced by more than |
|
227 |
// one feature. |
|
16891 | 228 |
if(featureListTable.isValid() && LE_SUCCESS(success)) { |
229 |
LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount); |
|
2 | 230 |
|
16891 | 231 |
for (le_uint32 feature = 0; LE_SUCCESS(success)&&(feature < featureCount); feature += 1) { |
232 |
le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature, success)); |
|
233 |
||
234 |
featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success); |
|
235 |
if (!featureTable.isValid() || LE_FAILURE(success)) { |
|
236 |
continue; |
|
16889 | 237 |
} |
238 |
featureReferences += SWAPW(featureTable->lookupCount); |
|
16891 | 239 |
} |
16889 | 240 |
} |
13036 | 241 |
|
16891 | 242 |
if (!featureTable.isValid() || LE_FAILURE(success)) { |
16889 | 243 |
success = LE_INTERNAL_ERROR; |
244 |
return; |
|
2 | 245 |
} |
246 |
||
247 |
if (requiredFeatureIndex != 0xFFFF) { |
|
16891 | 248 |
requiredFeatureTable = featureListTable->getFeatureTable(featureListTable, requiredFeatureIndex, &requiredFeatureTag, success); |
249 |
featureReferences += SWAPW(featureTable->lookupCount); |
|
2 | 250 |
} |
251 |
||
252 |
lookupOrderArray = LE_NEW_ARRAY(le_uint16, featureReferences); |
|
7486 | 253 |
if (lookupOrderArray == NULL) { |
254 |
success = LE_MEMORY_ALLOCATION_ERROR; |
|
255 |
return; |
|
256 |
} |
|
2 | 257 |
|
258 |
for (le_int32 f = 0; f < featureMapCount; f += 1) { |
|
259 |
FeatureMap fm = featureMap[f]; |
|
260 |
count = 0; |
|
261 |
||
262 |
// If this is the required feature, add its lookups |
|
263 |
if (requiredFeatureTag == fm.tag) { |
|
16891 | 264 |
count += selectLookups(requiredFeatureTable, fm.mask, order, success); |
2 | 265 |
} |
266 |
||
267 |
if (orderFeatures) { |
|
268 |
// If we added lookups from the required feature, sort them |
|
269 |
if (count > 1) { |
|
270 |
OpenTypeUtilities::sort(lookupOrderArray, order); |
|
271 |
} |
|
272 |
||
273 |
for (le_uint16 feature = 0; feature < featureCount; feature += 1) { |
|
16891 | 274 |
LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount); |
275 |
le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature,success)); |
|
2 | 276 |
|
277 |
// don't add the required feature to the list more than once... |
|
278 |
// TODO: Do we need this check? (Spec. says required feature won't be in feature list...) |
|
279 |
if (featureIndex == requiredFeatureIndex) { |
|
280 |
continue; |
|
281 |
} |
|
282 |
||
16891 | 283 |
featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success); |
2 | 284 |
|
285 |
if (featureTag == fm.tag) { |
|
16891 | 286 |
count += selectLookups(featureTable, fm.mask, order + count, success); |
2 | 287 |
} |
288 |
} |
|
289 |
||
290 |
if (count > 1) { |
|
291 |
OpenTypeUtilities::sort(&lookupOrderArray[order], count); |
|
292 |
} |
|
293 |
||
294 |
order += count; |
|
16891 | 295 |
} else if(langSysTable.isValid()) { |
296 |
LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount); |
|
297 |
for (le_uint16 feature = 0; LE_SUCCESS(success)&& (feature < featureCount); feature += 1) { |
|
298 |
le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature,success)); |
|
2 | 299 |
|
300 |
// don't add the required feature to the list more than once... |
|
301 |
// NOTE: This check is commented out because the spec. says that |
|
302 |
// the required feature won't be in the feature list, and because |
|
303 |
// any duplicate entries will be removed below. |
|
304 |
#if 0 |
|
305 |
if (featureIndex == requiredFeatureIndex) { |
|
306 |
continue; |
|
307 |
} |
|
308 |
#endif |
|
309 |
||
16891 | 310 |
featureTable = featureListTable->getFeatureTable(featureListTable, featureIndex, &featureTag, success); |
2 | 311 |
|
312 |
if (featureTag == fm.tag) { |
|
16891 | 313 |
order += selectLookups(featureTable, fm.mask, order, success); |
2 | 314 |
} |
315 |
} |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
if (!orderFeatures && (order > 1)) { |
|
320 |
OpenTypeUtilities::sort(lookupOrderArray, order); |
|
321 |
||
322 |
// If there's no specified feature order, |
|
323 |
// we will apply the lookups in the order |
|
324 |
// that they're in the font. If a particular |
|
325 |
// lookup may be referenced by more than one feature, |
|
326 |
// it will apprear in the lookupOrderArray more than |
|
327 |
// once, so remove any duplicate entries in the sorted array. |
|
328 |
le_int32 out = 1; |
|
329 |
||
330 |
for (le_int32 in = 1; in < order; in += 1) { |
|
331 |
if (lookupOrderArray[out - 1] != lookupOrderArray[in]) { |
|
332 |
if (out != in) { |
|
333 |
lookupOrderArray[out] = lookupOrderArray[in]; |
|
334 |
} |
|
335 |
||
336 |
out += 1; |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
order = out; |
|
341 |
} |
|
342 |
||
343 |
lookupOrderCount = order; |
|
344 |
} |
|
345 |
||
346 |
LookupProcessor::LookupProcessor() |
|
347 |
{ |
|
7486 | 348 |
lookupOrderArray = NULL; |
349 |
lookupSelectArray = NULL; |
|
2 | 350 |
} |
351 |
||
352 |
LookupProcessor::~LookupProcessor() |
|
353 |
{ |
|
354 |
LE_DELETE_ARRAY(lookupOrderArray); |
|
355 |
LE_DELETE_ARRAY(lookupSelectArray); |
|
356 |
} |
|
3935 | 357 |
|
358 |
U_NAMESPACE_END |