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