]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/CoverageTables.cpp
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / layout / CoverageTables.cpp
CommitLineData
b75a7d8f 1/*
b75a7d8f 2 *
374ca955 3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
b75a7d8f
A
4 *
5 */
6
7#include "LETypes.h"
8#include "OpenTypeTables.h"
9#include "OpenTypeUtilities.h"
10#include "CoverageTables.h"
11#include "LESwaps.h"
12
13U_NAMESPACE_BEGIN
14
15le_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
41le_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
70le_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
87U_NAMESPACE_END