2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-04-18 21:24:51 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "LEFontInstance.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "GlyphPositioningTables.h"
|
|
|
|
#include "PairPositioningSubtables.h"
|
|
|
|
#include "ValueRecords.h"
|
|
|
|
#include "GlyphIterator.h"
|
|
|
|
#include "OpenTypeUtilities.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
le_uint32 PairPositioningSubtable::process(const LEReferenceTo<PairPositioningSubtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
switch(SWAPW(subtableFormat))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
2013-04-18 21:24:51 +00:00
|
|
|
const LEReferenceTo<PairPositioningFormat1Subtable> subtable(base, success, (const PairPositioningFormat1Subtable *) this);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
if(LE_SUCCESS(success))
|
|
|
|
return subtable->process(subtable, glyphIterator, fontInstance, success);
|
|
|
|
else
|
|
|
|
return 0;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
2013-04-18 21:24:51 +00:00
|
|
|
const LEReferenceTo<PairPositioningFormat2Subtable> subtable(base, success, (const PairPositioningFormat2Subtable *) this);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
if(LE_SUCCESS(success))
|
|
|
|
return subtable->process(subtable, glyphIterator, fontInstance, success);
|
|
|
|
else
|
|
|
|
return 0;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
default:
|
2013-04-18 21:24:51 +00:00
|
|
|
return 0;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
le_uint32 PairPositioningFormat1Subtable::process(const LEReferenceTo<PairPositioningFormat1Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
2013-04-18 21:24:51 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
|
2000-11-28 20:56:52 +00:00
|
|
|
GlyphIterator tempIterator(*glyphIterator);
|
|
|
|
|
|
|
|
if (coverageIndex >= 0 && glyphIterator->next()) {
|
|
|
|
Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
|
|
|
|
PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
|
2004-10-29 19:24:42 +00:00
|
|
|
le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
|
|
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
|
|
le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
2004-10-29 19:24:42 +00:00
|
|
|
const PairValueRecord *pairValueRecord = NULL;
|
|
|
|
|
|
|
|
if (pairValueCount != 0) {
|
|
|
|
pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
|
|
|
|
}
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
if (pairValueRecord == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valueFormat1 != 0) {
|
2005-01-14 17:25:11 +00:00
|
|
|
pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (valueFormat2 != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2005-01-14 17:25:11 +00:00
|
|
|
valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 01:55:33 +00:00
|
|
|
// back up glyphIterator so second glyph can be
|
|
|
|
// first glyph in the next pair
|
|
|
|
glyphIterator->prev();
|
|
|
|
return 1;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-18 21:24:51 +00:00
|
|
|
le_uint32 PairPositioningFormat2Subtable::process(const LEReferenceTo<PairPositioningFormat2Subtable> &base, GlyphIterator *glyphIterator, const LEFontInstance *fontInstance, LEErrorCode &success) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
|
2013-04-18 21:24:51 +00:00
|
|
|
le_int32 coverageIndex = getGlyphCoverage(base, firstGlyph, success);
|
2000-11-28 20:56:52 +00:00
|
|
|
GlyphIterator tempIterator(*glyphIterator);
|
|
|
|
|
|
|
|
if (coverageIndex >= 0 && glyphIterator->next()) {
|
2003-02-05 00:05:40 +00:00
|
|
|
LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
|
2001-01-19 00:30:17 +00:00
|
|
|
const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
|
|
|
|
const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
|
2000-11-28 20:56:52 +00:00
|
|
|
le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
|
|
|
|
le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
|
|
|
|
le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
|
|
|
|
le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
|
|
|
|
le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
|
|
|
|
le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
|
2001-01-19 00:30:17 +00:00
|
|
|
const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
|
|
|
|
const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (valueFormat1 != 0) {
|
2005-01-14 17:25:11 +00:00
|
|
|
class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (valueFormat2 != 0) {
|
2001-01-19 00:30:17 +00:00
|
|
|
const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2005-01-14 17:25:11 +00:00
|
|
|
valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 01:55:33 +00:00
|
|
|
// back up glyphIterator so second glyph can be
|
|
|
|
// first glyph in the next pair
|
|
|
|
glyphIterator->prev();
|
|
|
|
return 1;
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2006-11-10 19:30:16 +00:00
|
|
|
#if 1
|
|
|
|
// The OpenType spec. says that the ValueRecord table is
|
|
|
|
// sorted by secondGlyph. Unfortunately, there are fonts
|
|
|
|
// around that have an unsorted ValueRecord table.
|
|
|
|
const PairValueRecord *record = records;
|
|
|
|
|
|
|
|
for(le_int32 r = 0; r < recordCount; r += 1) {
|
|
|
|
if (SWAPW(record->secondGlyph) == glyphID) {
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
|
|
|
record = (const PairValueRecord *) ((char *) record + recordSize);
|
|
|
|
}
|
|
|
|
#else
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
|
|
|
|
le_uint16 power = 1 << bit;
|
|
|
|
le_uint16 extra = (recordCount - power) * recordSize;
|
|
|
|
le_uint16 probe = power * recordSize;
|
2001-01-19 00:30:17 +00:00
|
|
|
const PairValueRecord *record = records;
|
|
|
|
const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
|
|
record = trial;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (probe > recordSize) {
|
|
|
|
probe >>= 1;
|
2001-01-19 00:30:17 +00:00
|
|
|
trial = (const PairValueRecord *) ((char *) record + probe);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
if (SWAPW(trial->secondGlyph) <= glyphID) {
|
|
|
|
record = trial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SWAPW(record->secondGlyph) == glyphID) {
|
|
|
|
return record;
|
|
|
|
}
|
2006-11-10 19:30:16 +00:00
|
|
|
#endif
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|