2000-11-28 20:56:52 +00:00
|
|
|
/*
|
|
|
|
* @(#)CoverageTables.cpp 1.5 00/03/15
|
|
|
|
*
|
2003-06-03 20:58:22 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "OpenTypeUtilities.h"
|
|
|
|
#include "CoverageTables.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_int32 CoverageTable::getGlyphCoverage(LEGlyphID glyphID) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
switch(SWAPW(coverageFormat))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const CoverageFormat1Table *f1Table = (const CoverageFormat1Table *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return f1Table->getGlyphCoverage(glyphID);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
2001-01-19 00:30:17 +00:00
|
|
|
const CoverageFormat2Table *f2Table = (const CoverageFormat2Table *) this;
|
2000-11-28 20:56:52 +00:00
|
|
|
|
|
|
|
return f2Table->getGlyphCoverage(glyphID);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_int32 CoverageFormat1Table::getGlyphCoverage(LEGlyphID glyphID) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 count = SWAPW(glyphCount);
|
|
|
|
le_uint8 bit = OpenTypeUtilities::highBit(count);
|
|
|
|
le_uint16 power = 1 << bit;
|
|
|
|
le_uint16 extra = count - power;
|
|
|
|
le_uint16 probe = power;
|
|
|
|
le_uint16 index = 0;
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
if (SWAPW(glyphArray[extra]) <= ttGlyphID) {
|
2000-11-28 20:56:52 +00:00
|
|
|
index = extra;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
while (probe > (1 << 0)) {
|
2000-11-28 20:56:52 +00:00
|
|
|
probe >>= 1;
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) {
|
2000-11-28 20:56:52 +00:00
|
|
|
index += probe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
if (SWAPW(glyphArray[index]) == ttGlyphID) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_int32 CoverageFormat2Table::getGlyphCoverage(LEGlyphID glyphID) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
2003-02-05 00:05:40 +00:00
|
|
|
TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 count = SWAPW(rangeCount);
|
|
|
|
le_int32 rangeIndex =
|
2003-02-05 00:05:40 +00:00
|
|
|
OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArray, count);
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
if (rangeIndex < 0) {
|
2000-11-28 20:56:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph);
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue);
|
|
|
|
|
2003-02-05 00:05:40 +00:00
|
|
|
return startCoverageIndex + (ttGlyphID - firstInRange);
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|