os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ClassDefinitionTables.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
 *
sl@0
     3
 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
sl@0
     4
 *
sl@0
     5
 */
sl@0
     6
sl@0
     7
#include "LETypes.h"
sl@0
     8
#include "OpenTypeTables.h"
sl@0
     9
#include "OpenTypeUtilities.h"
sl@0
    10
#include "ClassDefinitionTables.h"
sl@0
    11
#include "LESwaps.h"
sl@0
    12
sl@0
    13
U_NAMESPACE_BEGIN
sl@0
    14
sl@0
    15
le_int32 ClassDefinitionTable::getGlyphClass(LEGlyphID glyphID) const
sl@0
    16
{
sl@0
    17
    switch(SWAPW(classFormat)) {
sl@0
    18
    case 0:
sl@0
    19
        return 0;
sl@0
    20
sl@0
    21
    case 1:
sl@0
    22
    {
sl@0
    23
        const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
sl@0
    24
sl@0
    25
        return f1Table->getGlyphClass(glyphID);
sl@0
    26
    }
sl@0
    27
sl@0
    28
    case 2:
sl@0
    29
    {
sl@0
    30
        const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
sl@0
    31
sl@0
    32
        return f2Table->getGlyphClass(glyphID);
sl@0
    33
    }
sl@0
    34
sl@0
    35
    default:
sl@0
    36
        return 0;
sl@0
    37
    }
sl@0
    38
}
sl@0
    39
sl@0
    40
le_bool ClassDefinitionTable::hasGlyphClass(le_int32 glyphClass) const
sl@0
    41
{
sl@0
    42
    switch(SWAPW(classFormat)) {
sl@0
    43
    case 0:
sl@0
    44
        return 0;
sl@0
    45
sl@0
    46
    case 1:
sl@0
    47
    {
sl@0
    48
        const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
sl@0
    49
sl@0
    50
        return f1Table->hasGlyphClass(glyphClass);
sl@0
    51
    }
sl@0
    52
sl@0
    53
    case 2:
sl@0
    54
    {
sl@0
    55
        const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
sl@0
    56
sl@0
    57
        return f2Table->hasGlyphClass(glyphClass);
sl@0
    58
    }
sl@0
    59
sl@0
    60
    default:
sl@0
    61
        return 0;
sl@0
    62
    }
sl@0
    63
}
sl@0
    64
sl@0
    65
le_int32 ClassDefFormat1Table::getGlyphClass(LEGlyphID glyphID) const
sl@0
    66
{
sl@0
    67
    TTGlyphID ttGlyphID  = (TTGlyphID) LE_GET_GLYPH(glyphID);
sl@0
    68
    TTGlyphID firstGlyph = SWAPW(startGlyph);
sl@0
    69
    TTGlyphID lastGlyph  = firstGlyph + SWAPW(glyphCount);
sl@0
    70
sl@0
    71
    if (ttGlyphID > firstGlyph && ttGlyphID < lastGlyph) {
sl@0
    72
        return SWAPW(classValueArray[ttGlyphID - firstGlyph]);
sl@0
    73
    }
sl@0
    74
sl@0
    75
    return 0;
sl@0
    76
}
sl@0
    77
sl@0
    78
le_bool ClassDefFormat1Table::hasGlyphClass(le_int32 glyphClass) const
sl@0
    79
{
sl@0
    80
    le_uint16 count  = SWAPW(glyphCount);
sl@0
    81
    int i;
sl@0
    82
sl@0
    83
    for (i = 0; i < count; i += 1) {
sl@0
    84
        if (SWAPW(classValueArray[i]) == glyphClass) {
sl@0
    85
            return TRUE;
sl@0
    86
        }
sl@0
    87
    }
sl@0
    88
sl@0
    89
    return FALSE;
sl@0
    90
}
sl@0
    91
sl@0
    92
le_int32 ClassDefFormat2Table::getGlyphClass(LEGlyphID glyphID) const
sl@0
    93
{
sl@0
    94
    TTGlyphID ttGlyph    = (TTGlyphID) LE_GET_GLYPH(glyphID);
sl@0
    95
    le_uint16 rangeCount = SWAPW(classRangeCount);
sl@0
    96
    le_int32  rangeIndex =
sl@0
    97
        OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArray, rangeCount);
sl@0
    98
sl@0
    99
    if (rangeIndex < 0) {
sl@0
   100
        return 0;
sl@0
   101
    }
sl@0
   102
sl@0
   103
    return SWAPW(classRangeRecordArray[rangeIndex].rangeValue);
sl@0
   104
}
sl@0
   105
sl@0
   106
le_bool ClassDefFormat2Table::hasGlyphClass(le_int32 glyphClass) const
sl@0
   107
{
sl@0
   108
    le_uint16 rangeCount = SWAPW(classRangeCount);
sl@0
   109
    int i;
sl@0
   110
sl@0
   111
    for (i = 0; i < rangeCount; i += 1) {
sl@0
   112
        if (SWAPW(classRangeRecordArray[i].rangeValue) == glyphClass) {
sl@0
   113
            return TRUE;
sl@0
   114
        }
sl@0
   115
    }
sl@0
   116
sl@0
   117
    return FALSE;
sl@0
   118
}
sl@0
   119
sl@0
   120
U_NAMESPACE_END