os/textandloc/fontservices/textshaperplugin/IcuSource/layout/CoverageTables.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/CoverageTables.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +/*
     1.5 + *
     1.6 + * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
     1.7 + *
     1.8 + */
     1.9 +
    1.10 +#include "LETypes.h"
    1.11 +#include "OpenTypeTables.h"
    1.12 +#include "OpenTypeUtilities.h"
    1.13 +#include "CoverageTables.h"
    1.14 +#include "LESwaps.h"
    1.15 +
    1.16 +U_NAMESPACE_BEGIN
    1.17 +
    1.18 +le_int32 CoverageTable::getGlyphCoverage(LEGlyphID glyphID) const
    1.19 +{
    1.20 +    switch(SWAPW(coverageFormat))
    1.21 +    {
    1.22 +    case 0:
    1.23 +        return -1;
    1.24 +
    1.25 +    case 1:
    1.26 +    {
    1.27 +        const CoverageFormat1Table *f1Table = (const CoverageFormat1Table *) this;
    1.28 +
    1.29 +        return f1Table->getGlyphCoverage(glyphID);
    1.30 +    }
    1.31 +
    1.32 +    case 2:
    1.33 +    {
    1.34 +        const CoverageFormat2Table *f2Table = (const CoverageFormat2Table *) this;
    1.35 +
    1.36 +        return f2Table->getGlyphCoverage(glyphID);
    1.37 +    }
    1.38 +
    1.39 +    default:
    1.40 +        return -1;
    1.41 +    }
    1.42 +}
    1.43 +
    1.44 +le_int32 CoverageFormat1Table::getGlyphCoverage(LEGlyphID glyphID) const
    1.45 +{
    1.46 +    TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
    1.47 +    le_uint16 count = SWAPW(glyphCount);
    1.48 +    le_uint8 bit = OpenTypeUtilities::highBit(count);
    1.49 +    le_uint16 power = 1 << bit;
    1.50 +    le_uint16 extra = count - power;
    1.51 +    le_uint16 probe = power;
    1.52 +    le_uint16 index = 0;
    1.53 +
    1.54 +    if (SWAPW(glyphArray[extra]) <= ttGlyphID) {
    1.55 +        index = extra;
    1.56 +    }
    1.57 +
    1.58 +    while (probe > (1 << 0)) {
    1.59 +        probe >>= 1;
    1.60 +
    1.61 +        if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) {
    1.62 +            index += probe;
    1.63 +        }
    1.64 +    }
    1.65 +
    1.66 +    if (SWAPW(glyphArray[index]) == ttGlyphID) {
    1.67 +        return index;
    1.68 +    }
    1.69 +
    1.70 +    return -1;
    1.71 +}
    1.72 +
    1.73 +le_int32 CoverageFormat2Table::getGlyphCoverage(LEGlyphID glyphID) const
    1.74 +{
    1.75 +    TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
    1.76 +    le_uint16 count = SWAPW(rangeCount);
    1.77 +    le_int32 rangeIndex =
    1.78 +        OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArray, count);
    1.79 +
    1.80 +    if (rangeIndex < 0) {
    1.81 +        return -1;
    1.82 +    }
    1.83 +
    1.84 +    TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph);
    1.85 +    le_uint16  startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue);
    1.86 +
    1.87 +    return startCoverageIndex + (ttGlyphID - firstInRange);
    1.88 +}
    1.89 +
    1.90 +U_NAMESPACE_END