os/textandloc/fontservices/textshaperplugin/IcuSource/layout/PairPositioningSubtables.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 *
sl@0
     3
 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
sl@0
     4
 *
sl@0
     5
 */
sl@0
     6
sl@0
     7
#include "LETypes.h"
sl@0
     8
#include "LEFontInstance.h"
sl@0
     9
#include "OpenTypeTables.h"
sl@0
    10
#include "GlyphPositioningTables.h"
sl@0
    11
#include "PairPositioningSubtables.h"
sl@0
    12
#include "ValueRecords.h"
sl@0
    13
#include "GlyphIterator.h"
sl@0
    14
#include "OpenTypeUtilities.h"
sl@0
    15
#include "LESwaps.h"
sl@0
    16
sl@0
    17
U_NAMESPACE_BEGIN
sl@0
    18
sl@0
    19
le_uint32 PairPositioningSubtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
sl@0
    20
{
sl@0
    21
    switch(SWAPW(subtableFormat))
sl@0
    22
    {
sl@0
    23
    case 0:
sl@0
    24
        return 0;
sl@0
    25
sl@0
    26
    case 1:
sl@0
    27
    {
sl@0
    28
        const PairPositioningFormat1Subtable *subtable = (const PairPositioningFormat1Subtable *) this;
sl@0
    29
sl@0
    30
        return subtable->process(glyphIterator, fontInstance);
sl@0
    31
    }
sl@0
    32
sl@0
    33
    case 2:
sl@0
    34
    {
sl@0
    35
        const PairPositioningFormat2Subtable *subtable = (const PairPositioningFormat2Subtable *) this;
sl@0
    36
sl@0
    37
        return subtable->process(glyphIterator, fontInstance);
sl@0
    38
    }
sl@0
    39
sl@0
    40
    default:
sl@0
    41
        return 0;
sl@0
    42
    }
sl@0
    43
}
sl@0
    44
sl@0
    45
le_uint32 PairPositioningFormat1Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
sl@0
    46
{
sl@0
    47
    LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
sl@0
    48
    le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
sl@0
    49
    GlyphIterator tempIterator(*glyphIterator);
sl@0
    50
sl@0
    51
    if (coverageIndex >= 0 && glyphIterator->next()) {
sl@0
    52
        Offset pairSetTableOffset = SWAPW(pairSetTableOffsetArray[coverageIndex]);
sl@0
    53
        PairSetTable *pairSetTable = (PairSetTable *) ((char *) this + pairSetTableOffset);
sl@0
    54
        le_uint16 pairValueCount = SWAPW(pairSetTable->pairValueCount);
sl@0
    55
        le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
sl@0
    56
        le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
sl@0
    57
        le_int16 recordSize = sizeof(PairValueRecord) - sizeof(ValueRecord) + valueRecord1Size + valueRecord2Size;
sl@0
    58
        LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
sl@0
    59
        const PairValueRecord *pairValueRecord = NULL;
sl@0
    60
sl@0
    61
        if (pairValueCount != 0) {
sl@0
    62
            pairValueRecord = findPairValueRecord((TTGlyphID) LE_GET_GLYPH(secondGlyph), pairSetTable->pairValueRecordArray, pairValueCount, recordSize);
sl@0
    63
        }
sl@0
    64
sl@0
    65
        if (pairValueRecord == NULL) {
sl@0
    66
            return 0;
sl@0
    67
        }
sl@0
    68
sl@0
    69
        if (valueFormat1 != 0) {
sl@0
    70
            pairValueRecord->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
sl@0
    71
        }
sl@0
    72
sl@0
    73
        if (valueFormat2 != 0) {
sl@0
    74
            const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &pairValueRecord->valueRecord1 + valueRecord1Size);
sl@0
    75
sl@0
    76
            valueRecord2->adjustPosition(SWAPW(valueFormat2), (char *) this, *glyphIterator, fontInstance);
sl@0
    77
        }
sl@0
    78
sl@0
    79
        return 2;
sl@0
    80
    }
sl@0
    81
sl@0
    82
    return 0;
sl@0
    83
}
sl@0
    84
sl@0
    85
le_uint32 PairPositioningFormat2Subtable::process(GlyphIterator *glyphIterator, const LEFontInstance *fontInstance) const
sl@0
    86
{
sl@0
    87
    LEGlyphID firstGlyph = glyphIterator->getCurrGlyphID();
sl@0
    88
    le_int32 coverageIndex = getGlyphCoverage(firstGlyph);
sl@0
    89
    GlyphIterator tempIterator(*glyphIterator);
sl@0
    90
sl@0
    91
    if (coverageIndex >= 0 && glyphIterator->next()) {
sl@0
    92
        LEGlyphID secondGlyph = glyphIterator->getCurrGlyphID();
sl@0
    93
        const ClassDefinitionTable *classDef1 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef1Offset));
sl@0
    94
        const ClassDefinitionTable *classDef2 = (const ClassDefinitionTable *) ((char *) this + SWAPW(classDef2Offset));
sl@0
    95
        le_int32 class1 = classDef1->getGlyphClass(firstGlyph);
sl@0
    96
        le_int32 class2 = classDef2->getGlyphClass(secondGlyph);
sl@0
    97
        le_int16 valueRecord1Size = ValueRecord::getSize(SWAPW(valueFormat1));
sl@0
    98
        le_int16 valueRecord2Size = ValueRecord::getSize(SWAPW(valueFormat2));
sl@0
    99
        le_int16 class2RecordSize = valueRecord1Size + valueRecord2Size;
sl@0
   100
        le_int16 class1RecordSize = class2RecordSize * SWAPW(class2Count);
sl@0
   101
        const Class1Record *class1Record = (const Class1Record *) ((char *) class1RecordArray + (class1RecordSize * class1));
sl@0
   102
        const Class2Record *class2Record = (const Class2Record *) ((char *) class1Record->class2RecordArray + (class2RecordSize * class2));
sl@0
   103
sl@0
   104
sl@0
   105
        if (valueFormat1 != 0) {
sl@0
   106
            class2Record->valueRecord1.adjustPosition(SWAPW(valueFormat1), (char *) this, tempIterator, fontInstance);
sl@0
   107
        }
sl@0
   108
sl@0
   109
        if (valueFormat2 != 0) {
sl@0
   110
            const ValueRecord *valueRecord2 = (const ValueRecord *) ((char *) &class2Record->valueRecord1 + valueRecord1Size);
sl@0
   111
sl@0
   112
            valueRecord2->adjustPosition(SWAPW(valueFormat2), (const char *) this, *glyphIterator, fontInstance);
sl@0
   113
        }
sl@0
   114
sl@0
   115
        return 2;
sl@0
   116
    }
sl@0
   117
sl@0
   118
    return 0;
sl@0
   119
}
sl@0
   120
sl@0
   121
const PairValueRecord *PairPositioningFormat1Subtable::findPairValueRecord(TTGlyphID glyphID, const PairValueRecord *records, le_uint16 recordCount, le_uint16 recordSize) const
sl@0
   122
{
sl@0
   123
    le_uint8 bit = OpenTypeUtilities::highBit(recordCount);
sl@0
   124
    le_uint16 power = 1 << bit;
sl@0
   125
    le_uint16 extra = (recordCount - power) * recordSize;
sl@0
   126
    le_uint16 probe = power * recordSize;
sl@0
   127
    const PairValueRecord *record = records;
sl@0
   128
    const PairValueRecord *trial = (const PairValueRecord *) ((char *) record + extra);
sl@0
   129
sl@0
   130
    if (SWAPW(trial->secondGlyph) <= glyphID) {
sl@0
   131
        record = trial;
sl@0
   132
    }
sl@0
   133
sl@0
   134
    while (probe > recordSize) {
sl@0
   135
        probe >>= 1;
sl@0
   136
        trial = (const PairValueRecord *) ((char *) record + probe);
sl@0
   137
sl@0
   138
        if (SWAPW(trial->secondGlyph) <= glyphID) {
sl@0
   139
            record = trial;
sl@0
   140
        }
sl@0
   141
    }
sl@0
   142
sl@0
   143
    if (SWAPW(record->secondGlyph) == glyphID) {
sl@0
   144
        return record;
sl@0
   145
    }
sl@0
   146
sl@0
   147
    return NULL;
sl@0
   148
}
sl@0
   149
sl@0
   150
U_NAMESPACE_END