2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
* %W% %E%
|
|
|
|
*
|
2003-06-03 20:58:22 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2003 - 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"
|
|
|
|
#include "GlyphPositionAdjustments.h"
|
|
|
|
#include "LookupProcessor.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-03-27 00:34:56 +00:00
|
|
|
const LETag LookupProcessor::notSelected = 0x00000000;
|
|
|
|
const LETag LookupProcessor::defaultFeature = 0xFFFFFFFF;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-03-27 00:34:56 +00:00
|
|
|
const LETag emptyTag = 0x00000000;
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2000-11-28 20:56:52 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-09-24 21:05:40 +00:00
|
|
|
le_int32 LookupProcessor::process(LEGlyphID *&glyphs, GlyphPositionAdjustment *glyphPositionAdjustments, const LETag **&glyphTags, le_int32 *&charIndices, le_int32 glyphCount,
|
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
|
|
|
{
|
|
|
|
if (lookupSelectArray == NULL) {
|
2003-09-24 21:05:40 +00:00
|
|
|
return glyphCount;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 21:05:40 +00:00
|
|
|
GlyphIterator glyphIterator(glyphs, glyphPositionAdjustments, charIndices, glyphCount,
|
|
|
|
rightToLeft, 0, 0, glyphTags, glyphDefinitionTableHeader);
|
|
|
|
le_int32 newGlyphCount = glyphCount;
|
|
|
|
|
2002-03-01 22:24:10 +00:00
|
|
|
for (le_uint16 order = 0; order < lookupOrderCount; order += 1) {
|
|
|
|
le_uint16 lookup = lookupOrderArray[order];
|
2000-11-28 20:56:52 +00:00
|
|
|
LETag selectTag = lookupSelectArray[lookup];
|
|
|
|
|
|
|
|
if (selectTag != notSelected) {
|
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
|
|
|
|
|
|
|
glyphIterator.reset(lookupFlags, selectTag);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
while (glyphIterator.findFeatureTag()) {
|
|
|
|
le_uint32 delta = 1;
|
|
|
|
|
|
|
|
while (glyphIterator.next(delta)) {
|
|
|
|
delta = applyLookupTable(lookupTable, &glyphIterator, fontInstance);
|
|
|
|
}
|
|
|
|
}
|
2003-09-24 21:05:40 +00:00
|
|
|
|
|
|
|
newGlyphCount = glyphIterator.applyInsertions();
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-24 21:05:40 +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;
|
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
le_int32 LookupProcessor::selectLookups(const FeatureTable *featureTable, LETag featureTag, le_int32 order)
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 lookupCount = featureTable? SWAPW(featureTable->lookupCount) : 0;
|
|
|
|
|
|
|
|
for (le_uint16 lookup = 0; lookup < lookupCount; lookup += 1) {
|
|
|
|
le_uint16 lookupListIndex = SWAPW(featureTable->lookupListIndexArray[lookup]);
|
|
|
|
|
|
|
|
lookupSelectArray[lookupListIndex] = featureTag;
|
2002-03-14 21:51:40 +00:00
|
|
|
lookupOrderArray[order + lookup] = lookupListIndex;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
return lookupCount;
|
|
|
|
}
|
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,
|
2002-03-01 22:24:10 +00:00
|
|
|
LETag scriptTag, LETag languageTag, const LETag *featureOrder)
|
2003-05-13 00:44:54 +00:00
|
|
|
: lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL),
|
|
|
|
requiredFeatureTag(notSelected), 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);
|
|
|
|
|
2003-01-07 22:47:19 +00:00
|
|
|
lookupSelectArray = LE_NEW_ARRAY(LETag, lookupListCount);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < lookupListCount; i += 1) {
|
|
|
|
lookupSelectArray[i] = notSelected;
|
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
le_int32 count, order = 0;
|
|
|
|
const FeatureTable *featureTable = 0;
|
|
|
|
LETag featureTag;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2003-01-07 22:47:19 +00:00
|
|
|
lookupOrderArray = LE_NEW_ARRAY(le_uint16, lookupListCount);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
if (requiredFeatureIndex != 0xFFFF) {
|
|
|
|
featureTable = featureListTable->getFeatureTable(requiredFeatureIndex, &featureTag);
|
|
|
|
order += selectLookups(featureTable, defaultFeature, order);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
if (featureOrder != NULL) {
|
|
|
|
if (order > 1) {
|
|
|
|
OpenTypeUtilities::sort(lookupOrderArray, order);
|
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
for (le_int32 tag = 0; featureOrder[tag] != emptyTag; tag += 1) {
|
|
|
|
featureTag = featureOrder[tag];
|
2002-12-23 23:50:58 +00:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
|
|
|
|
le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
|
|
|
|
|
|
|
|
featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
|
|
|
|
|
|
|
|
if (featureTag == featureOrder[tag]) {
|
|
|
|
count += selectLookups(featureTable, featureTag, order + count);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
2002-03-01 22:24:10 +00:00
|
|
|
} else {
|
2002-03-14 21:51:40 +00:00
|
|
|
for (le_uint16 feature = 0; feature < featureCount; feature += 1) {
|
|
|
|
le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
|
|
|
|
|
|
|
|
featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
|
|
|
|
count = selectLookups(featureTable, featureTag, order);
|
|
|
|
order += count;
|
2002-03-01 22:24:10 +00:00
|
|
|
}
|
|
|
|
|
2002-03-14 21:51:40 +00:00
|
|
|
if (order > 1) {
|
|
|
|
OpenTypeUtilities::sort(lookupOrderArray, order);
|
|
|
|
}
|
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);
|
2000-11-28 20:56:52 +00:00
|
|
|
};
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_END
|