2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2007-10-09 19:40:14 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2007 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
2002-03-01 22:24:10 +00:00
|
|
|
#include "OpenTypeUtilities.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "LEFontInstance.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "Features.h"
|
|
|
|
#include "Lookups.h"
|
|
|
|
#include "ScriptAndLanguage.h"
|
|
|
|
#include "GlyphDefinitionTables.h"
|
2005-01-14 17:25:11 +00:00
|
|
|
#include "GlyphIterator.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "LookupProcessor.h"
|
2004-04-12 18:51:31 +00:00
|
|
|
#include "LEGlyphStorage.h"
|
2000-11-28 20:56:52 +00:00
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_uint32 LookupProcessor::applyLookupTable(const LookupTable *lookupTable, GlyphIterator *glyphIterator,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 lookupType = SWAPW(lookupTable->lookupType);
|
|
|
|
le_uint16 subtableCount = SWAPW(lookupTable->subTableCount);
|
|
|
|
le_int32 startPosition = glyphIterator->getCurrStreamPosition();
|
|
|
|
le_uint32 delta;
|
|
|
|
|
|
|
|
for (le_uint16 subtable = 0; subtable < subtableCount; subtable += 1) {
|
2001-01-19 00:30:17 +00:00
|
|
|
const LookupSubtable *lookupSubtable = lookupTable->getLookupSubtable(subtable);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
delta = applySubtable(lookupSubtable, lookupType, glyphIterator, fontInstance);
|
|
|
|
|
|
|
|
if (delta > 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glyphIterator->setCurrStreamPosition(startPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-01-14 17:25:11 +00:00
|
|
|
le_int32 LookupProcessor::process(LEGlyphStorage &glyphStorage, GlyphPositionAdjustments *glyphPositionAdjustments,
|
2001-01-19 00:30:17 +00:00
|
|
|
le_bool rightToLeft, const GlyphDefinitionTableHeader *glyphDefinitionTableHeader,
|
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2004-05-15 00:47:55 +00:00
|
|
|
le_int32 glyphCount = glyphStorage.getGlyphCount();
|
2004-04-12 18:51:31 +00:00
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
if (lookupSelectArray == NULL) {
|
2003-09-24 21:05:40 +00:00
|
|
|
return glyphCount;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2004-05-15 00:47:55 +00:00
|
|
|
GlyphIterator glyphIterator(glyphStorage, glyphPositionAdjustments,
|
|
|
|
rightToLeft, 0, 0, glyphDefinitionTableHeader);
|
|
|
|
le_int32 newGlyphCount = glyphCount;
|
2003-09-24 21:05:40 +00:00
|
|
|
|
2002-03-01 22:24:10 +00:00
|
|
|
for (le_uint16 order = 0; order < lookupOrderCount; order += 1) {
|
|
|
|
le_uint16 lookup = lookupOrderArray[order];
|
2005-08-06 00:48:27 +00:00
|
|
|
FeatureMask selectMask = lookupSelectArray[lookup];
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
if (selectMask != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
const LookupTable *lookupTable = lookupListTable->getLookupTable(lookup);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
|
2003-09-24 21:05:40 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
glyphIterator.reset(lookupFlags, selectMask);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
while (glyphIterator.findFeatureTag()) {
|
2007-10-09 19:40:14 +00:00
|
|
|
applyLookupTable(lookupTable, &glyphIterator, fontInstance);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
2003-09-24 21:05:40 +00:00
|
|
|
|
2004-05-15 00:47:55 +00:00
|
|
|
newGlyphCount = glyphIterator.applyInsertions();
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-24 21:05:40 +00:00
|
|
|
|
2004-05-15 00:47:55 +00:00
|
|
|
return newGlyphCount;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
le_uint32 LookupProcessor::applySingleLookup(le_uint16 lookupTableIndex, GlyphIterator *glyphIterator,
|
2001-01-19 00:30:17 +00:00
|
|
|
const LEFontInstance *fontInstance) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const LookupTable *lookupTable = lookupListTable->getLookupTable(lookupTableIndex);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
|
|
|
|
GlyphIterator tempIterator(*glyphIterator, lookupFlags);
|
|
|
|
le_uint32 delta = applyLookupTable(lookupTable, &tempIterator, fontInstance);
|
|
|
|
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
le_int32 LookupProcessor::selectLookups(const FeatureTable *featureTable, FeatureMask featureMask, le_int32 order)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 lookupCount = featureTable? SWAPW(featureTable->lookupCount) : 0;
|
2004-10-18 20:44:55 +00:00
|
|
|
le_int32 store = order;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
for (le_uint16 lookup = 0; lookup < lookupCount; lookup += 1) {
|
|
|
|
le_uint16 lookupListIndex = SWAPW(featureTable->lookupListIndexArray[lookup]);
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
lookupSelectArray[lookupListIndex] |= featureMask;
|
|
|
|
lookupOrderArray[store++] = lookupListIndex;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2004-10-18 20:44:55 +00:00
|
|
|
return store - order;
|
2002-03-14 21:51:40 +00:00
|
|
|
}
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
LookupProcessor::LookupProcessor(const char *baseAddress,
|
2000-11-28 20:56:52 +00:00
|
|
|
Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset,
|
2005-08-06 00:48:27 +00:00
|
|
|
LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures)
|
2003-05-13 00:44:54 +00:00
|
|
|
: lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL),
|
2005-08-06 00:48:27 +00:00
|
|
|
lookupOrderArray(NULL), lookupOrderCount(0)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const ScriptListTable *scriptListTable = NULL;
|
|
|
|
const LangSysTable *langSysTable = NULL;
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 featureCount = 0;
|
|
|
|
le_uint16 lookupListCount = 0;
|
|
|
|
le_uint16 requiredFeatureIndex;
|
|
|
|
|
|
|
|
if (scriptListOffset != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
scriptListTable = (const ScriptListTable *) (baseAddress + scriptListOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
langSysTable = scriptListTable->findLanguage(scriptTag, languageTag);
|
|
|
|
|
2002-03-27 00:34:56 +00:00
|
|
|
if (langSysTable != 0) {
|
|
|
|
featureCount = SWAPW(langSysTable->featureCount);
|
|
|
|
}
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featureListOffset != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
featureListTable = (const FeatureListTable *) (baseAddress + featureListOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lookupListOffset != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
lookupListTable = (const LookupListTable *) (baseAddress + lookupListOffset);
|
2000-11-28 20:56:52 +00:00
|
|
|
lookupListCount = SWAPW(lookupListTable->lookupCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (langSysTable == NULL || featureListTable == NULL || lookupListTable == NULL ||
|
|
|
|
featureCount == 0 || lookupListCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex);
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
lookupSelectArray = LE_NEW_ARRAY(FeatureMask, lookupListCount);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < lookupListCount; i += 1) {
|
2005-08-06 00:48:27 +00:00
|
|
|
lookupSelectArray[i] = 0;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
le_int32 count, order = 0;
|
2005-08-06 00:48:27 +00:00
|
|
|
le_int32 featureReferences = 0;
|
2005-08-16 23:48:31 +00:00
|
|
|
const FeatureTable *featureTable = NULL;
|
2002-03-14 21:51:40 +00:00
|
|
|
LETag featureTag;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2005-08-25 22:20:16 +00:00
|
|
|
const FeatureTable *requiredFeatureTable = NULL;
|
2005-08-16 23:48:31 +00:00
|
|
|
LETag requiredFeatureTag = 0x00000000U;
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
// Count the total number of lookups referenced by all features. This will
|
|
|
|
// be the maximum number of entries in the lookupOrderArray. We can't use
|
|
|
|
// lookupListCount because some lookups might be referenced by more than
|
|
|
|
// one feature.
|
|
|
|
for (le_int32 feature = 0; feature < featureCount; feature += 1) {
|
|
|
|
le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
|
|
|
|
|
|
|
|
featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
|
|
|
|
featureReferences += SWAPW(featureTable->lookupCount);
|
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
if (requiredFeatureIndex != 0xFFFF) {
|
2005-08-16 23:48:31 +00:00
|
|
|
requiredFeatureTable = featureListTable->getFeatureTable(requiredFeatureIndex, &requiredFeatureTag);
|
|
|
|
featureReferences += SWAPW(featureTable->lookupCount);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2005-08-16 23:48:31 +00:00
|
|
|
lookupOrderArray = LE_NEW_ARRAY(le_uint16, featureReferences);
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
for (le_int32 f = 0; f < featureMapCount; f += 1) {
|
|
|
|
FeatureMap fm = featureMap[f];
|
|
|
|
count = 0;
|
2002-12-23 23:50:58 +00:00
|
|
|
|
2005-08-16 23:48:31 +00:00
|
|
|
// If this is the required feature, add its lookups
|
|
|
|
if (requiredFeatureTag == fm.tag) {
|
|
|
|
count += selectLookups(requiredFeatureTable, fm.mask, order);
|
|
|
|
}
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
if (orderFeatures) {
|
2005-08-16 23:48:31 +00:00
|
|
|
// If we added lookups from the required feature, sort them
|
|
|
|
if (count > 1) {
|
|
|
|
OpenTypeUtilities::sort(lookupOrderArray, order);
|
|
|
|
}
|
|
|
|
|
2002-12-23 23:50:58 +00:00
|
|
|
for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
|
|
|
|
le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
|
2005-08-06 00:48:27 +00:00
|
|
|
|
|
|
|
// don't add the required feature to the list more than once...
|
2005-08-16 23:48:31 +00:00
|
|
|
// TODO: Do we need this check? (Spec. says required feature won't be in feature list...)
|
2005-08-06 00:48:27 +00:00
|
|
|
if (featureIndex == requiredFeatureIndex) {
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-23 23:50:58 +00:00
|
|
|
|
|
|
|
featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
|
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
if (featureTag == fm.tag) {
|
|
|
|
count += selectLookups(featureTable, fm.mask, order + count);
|
2002-12-23 23:50:58 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
if (count > 1) {
|
|
|
|
OpenTypeUtilities::sort(&lookupOrderArray[order], count);
|
2002-03-01 22:24:10 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
order += count;
|
2005-08-06 00:48:27 +00:00
|
|
|
} else {
|
|
|
|
for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
|
|
|
|
le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
|
2002-03-14 21:51:40 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
// don't add the required feature to the list more than once...
|
2005-08-16 23:48:31 +00:00
|
|
|
// NOTE: This check is commented out because the spec. says that
|
|
|
|
// the required feature won't be in the feature list, and because
|
|
|
|
// any duplicate entries will be removed below.
|
|
|
|
#if 0
|
2005-08-06 00:48:27 +00:00
|
|
|
if (featureIndex == requiredFeatureIndex) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-08-16 23:48:31 +00:00
|
|
|
#endif
|
2004-08-20 18:14:29 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
|
|
|
|
|
|
|
|
if (featureTag == fm.tag) {
|
|
|
|
order += selectLookups(featureTable, fm.mask, order);
|
|
|
|
}
|
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
}
|
2005-08-06 00:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!orderFeatures && (order > 1)) {
|
|
|
|
OpenTypeUtilities::sort(lookupOrderArray, order);
|
|
|
|
|
|
|
|
// If there's no specified feature order,
|
|
|
|
// we will apply the lookups in the order
|
|
|
|
// that they're in the font. If a particular
|
|
|
|
// lookup may be referenced by more than one feature,
|
|
|
|
// it will apprear in the lookupOrderArray more than
|
|
|
|
// once, so remove any duplicate entries in the sorted array.
|
|
|
|
le_int32 out = 1;
|
|
|
|
|
|
|
|
for (le_int32 in = 1; in < order; in += 1) {
|
|
|
|
if (lookupOrderArray[out - 1] != lookupOrderArray[in]) {
|
|
|
|
if (out != in) {
|
|
|
|
lookupOrderArray[out] = lookupOrderArray[in];
|
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2005-08-06 00:48:27 +00:00
|
|
|
out += 1;
|
|
|
|
}
|
2002-03-14 21:51:40 +00:00
|
|
|
}
|
2005-08-06 00:48:27 +00:00
|
|
|
|
|
|
|
order = out;
|
2002-03-01 22:24:10 +00:00
|
|
|
}
|
2002-03-14 21:51:40 +00:00
|
|
|
|
|
|
|
lookupOrderCount = order;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LookupProcessor::LookupProcessor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LookupProcessor::~LookupProcessor()
|
|
|
|
{
|
2003-01-07 22:47:19 +00:00
|
|
|
LE_DELETE_ARRAY(lookupOrderArray);
|
|
|
|
LE_DELETE_ARRAY(lookupSelectArray);
|
2004-12-30 07:25:51 +00:00
|
|
|
}
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_END
|