1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (C) Copyright IBM Corp. 1998-2006 - All Rights Reserved 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LETypes.h" 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "OpenTypeTables.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "OpenTypeUtilities.h" 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "CoverageTables.h" 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LESwaps.h" 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_int32 CoverageTable::getGlyphCoverage(LEGlyphID glyphID) const 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch(SWAPW(coverageFormat)) 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 0: 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 1: 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const CoverageFormat1Table *f1Table = (const CoverageFormat1Table *) this; 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return f1Table->getGlyphCoverage(glyphID); 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 2: 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const CoverageFormat2Table *f2Table = (const CoverageFormat2Table *) this; 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return f2Table->getGlyphCoverage(glyphID); 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_int32 CoverageFormat1Table::getGlyphCoverage(LEGlyphID glyphID) const 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 count = SWAPW(glyphCount); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint8 bit = OpenTypeUtilities::highBit(count); 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 power = 1 << bit; 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 extra = count - power; 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 probe = power; 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 index = 0; 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (count == 0) { 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (SWAPW(glyphArray[extra]) <= ttGlyphID) { 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru index = extra; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (probe > (1 << 0)) { 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru probe >>= 1; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) { 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru index += probe; 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (SWAPW(glyphArray[index]) == ttGlyphID) { 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return index; 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_int32 CoverageFormat2Table::getGlyphCoverage(LEGlyphID glyphID) const 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 count = SWAPW(rangeCount); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_int32 rangeIndex = 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArray, count); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (rangeIndex < 0) { 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph); 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_uint16 startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue); 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return startCoverageIndex + (ttGlyphID - firstInRange); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 92