os/textandloc/fontservices/textshaperplugin/IcuSource/layout/CoverageTables.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2  *
     3  * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
     4  *
     5  */
     6 
     7 #include "LETypes.h"
     8 #include "OpenTypeTables.h"
     9 #include "OpenTypeUtilities.h"
    10 #include "CoverageTables.h"
    11 #include "LESwaps.h"
    12 
    13 U_NAMESPACE_BEGIN
    14 
    15 le_int32 CoverageTable::getGlyphCoverage(LEGlyphID glyphID) const
    16 {
    17     switch(SWAPW(coverageFormat))
    18     {
    19     case 0:
    20         return -1;
    21 
    22     case 1:
    23     {
    24         const CoverageFormat1Table *f1Table = (const CoverageFormat1Table *) this;
    25 
    26         return f1Table->getGlyphCoverage(glyphID);
    27     }
    28 
    29     case 2:
    30     {
    31         const CoverageFormat2Table *f2Table = (const CoverageFormat2Table *) this;
    32 
    33         return f2Table->getGlyphCoverage(glyphID);
    34     }
    35 
    36     default:
    37         return -1;
    38     }
    39 }
    40 
    41 le_int32 CoverageFormat1Table::getGlyphCoverage(LEGlyphID glyphID) const
    42 {
    43     TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
    44     le_uint16 count = SWAPW(glyphCount);
    45     le_uint8 bit = OpenTypeUtilities::highBit(count);
    46     le_uint16 power = 1 << bit;
    47     le_uint16 extra = count - power;
    48     le_uint16 probe = power;
    49     le_uint16 index = 0;
    50 
    51     if (SWAPW(glyphArray[extra]) <= ttGlyphID) {
    52         index = extra;
    53     }
    54 
    55     while (probe > (1 << 0)) {
    56         probe >>= 1;
    57 
    58         if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) {
    59             index += probe;
    60         }
    61     }
    62 
    63     if (SWAPW(glyphArray[index]) == ttGlyphID) {
    64         return index;
    65     }
    66 
    67     return -1;
    68 }
    69 
    70 le_int32 CoverageFormat2Table::getGlyphCoverage(LEGlyphID glyphID) const
    71 {
    72     TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
    73     le_uint16 count = SWAPW(rangeCount);
    74     le_int32 rangeIndex =
    75         OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArray, count);
    76 
    77     if (rangeIndex < 0) {
    78         return -1;
    79     }
    80 
    81     TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph);
    82     le_uint16  startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue);
    83 
    84     return startCoverageIndex + (ttGlyphID - firstInRange);
    85 }
    86 
    87 U_NAMESPACE_END