os/textandloc/fontservices/textshaperplugin/IcuSource/layout/PairPositioningSubtables.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/PairPositioningSubtables.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,150 @@
1.4 +/*
1.5 + *
1.6 + * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
1.7 + *
1.8 + */
1.9 +
1.10 +#include "LETypes.h"
1.11 +#include "LEFontInstance.h"
1.12 +#include "OpenTypeTables.h"
1.13 +#include "GlyphPositioningTables.h"
1.14 +#include "PairPositioningSubtables.h"
1.15 +#include "ValueRecords.h"
1.16 +#include "GlyphIterator.h"
1.17 +#include "OpenTypeUtilities.h"
1.18 +#include "LESwaps.h"
1.19 +
1.20 +U_NAMESPACE_BEGIN
1.21 +
1.22 +le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
1.23 +{
1.24 + switch(SWAPW(subtableFormat))
1.25 + {
1.26 + case 0:
1.27 + return 0;
1.28 +
1.29 + case 1:
1.30 + {
1.31 + const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
1.32 +
1.33 + return subtable->process(glyphIterator, fontInstance);
1.34 + }
1.35 +
1.36 + case 2:
1.37 + {
1.38 + const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
1.39 +
1.40 + return subtable->process(glyphIterator, fontInstance);
1.41 + }
1.42 +
1.43 + default:
1.44 + return 0;
1.45 + }
1.46 +}
1.47 +
1.48 +le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
1.49 +{
1.50 + LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
1.51 + le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
1.52 + GlyphIterator tempIterator(*glyphIterator);
1.53 +
1.54 + if (coverageIndex >= 0 && glyphIterator->next()) {
1.55 + Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
1.56 + PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
1.57 + le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
1.58 + le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
1.59 + le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
1.60 + le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
1.61 + LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
1.62 + const PairValueRecord *pairValueRecord = NULL;
1.63 +
1.64 + if (pairValueCount != 0) {
1.65 + pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
1.66 + }
1.67 +
1.68 + if (pairValueRecord == NULL) {
1.69 + return 0;
1.70 + }
1.71 +
1.72 + if (valueFormat1 != 0) {
1.73 + pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
1.74 + }
1.75 +
1.76 + if (valueFormat2 != 0) {
1.77 + const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
1.78 +
1.79 + valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
1.80 + }
1.81 +
1.82 + return 2;
1.83 + }
1.84 +
1.85 + return 0;
1.86 +}
1.87 +
1.88 +le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
1.89 +{
1.90 + LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
1.91 + le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
1.92 + GlyphIterator tempIterator(*glyphIterator);
1.93 +
1.94 + if (coverageIndex >= 0 && glyphIterator->next()) {
1.95 + LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
1.96 + const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
1.97 + const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
1.98 + le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
1.99 + le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
1.100 + le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
1.101 + le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
1.102 + le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
1.103 + le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
1.104 + const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
1.105 + const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
1.106 +
1.107 +
1.108 + if (valueFormat1 != 0) {
1.109 + class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
1.110 + }
1.111 +
1.112 + if (valueFormat2 != 0) {
1.113 + const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
1.114 +
1.115 + valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
1.116 + }
1.117 +
1.118 + return 2;
1.119 + }
1.120 +
1.121 + return 0;
1.122 +}
1.123 +
1.124 +const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
1.125 +{
1.126 + le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
1.127 + le_uint16 power = 1 << bit;
1.128 + le_uint16 extra = (recordCount - power) * recordSize;
1.129 + le_uint16 probe = power * recordSize;
1.130 + const PairValueRecord *record = records;
1.131 + const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
1.132 +
1.133 + if (SWAPW(trial->secondGlyph) <= glyphID) {
1.134 + record = trial;
1.135 + }
1.136 +
1.137 + while (probe > recordSize) {
1.138 + probe >>= 1;
1.139 + trial = (const PairValueRecord *) ((char *) record + probe);
1.140 +
1.141 + if (SWAPW(trial->secondGlyph) <= glyphID) {
1.142 + record = trial;
1.143 + }
1.144 + }
1.145 +
1.146 + if (SWAPW(record->secondGlyph) == glyphID) {
1.147 + return record;
1.148 + }
1.149 +
1.150 + return NULL;
1.151 +}
1.152 +
1.153 +U_NAMESPACE_END