]> git.saurik.com Git - apple/icu.git/blob - icuSources/layout/ClassDefinitionTables.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / layout / ClassDefinitionTables.cpp
1 /*
2 * @(#)ClassDefinitionTables.cpp 1.5 00/03/15
3 *
4 * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
5 *
6 */
7
8 #include "LETypes.h"
9 #include "OpenTypeTables.h"
10 #include "OpenTypeUtilities.h"
11 #include "ClassDefinitionTables.h"
12 #include "LESwaps.h"
13
14 U_NAMESPACE_BEGIN
15
16 le_int32 ClassDefinitionTable::getGlyphClass(LEGlyphID glyphID) const
17 {
18 switch(SWAPW(classFormat)) {
19 case 0:
20 return 0;
21
22 case 1:
23 {
24 const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
25
26 return f1Table->getGlyphClass(glyphID);
27 }
28
29 case 2:
30 {
31 const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
32
33 return f2Table->getGlyphClass(glyphID);
34 }
35
36 default:
37 return 0;
38 }
39 }
40
41 le_bool ClassDefinitionTable::hasGlyphClass(le_int32 glyphClass) const
42 {
43 switch(SWAPW(classFormat)) {
44 case 0:
45 return 0;
46
47 case 1:
48 {
49 const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this;
50
51 return f1Table->hasGlyphClass(glyphClass);
52 }
53
54 case 2:
55 {
56 const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this;
57
58 return f2Table->hasGlyphClass(glyphClass);
59 }
60
61 default:
62 return 0;
63 }
64 }
65
66 le_int32 ClassDefFormat1Table::getGlyphClass(LEGlyphID glyphID) const
67 {
68 TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID);
69 TTGlyphID firstGlyph = SWAPW(startGlyph);
70 TTGlyphID lastGlyph = firstGlyph + SWAPW(glyphCount);
71
72 if (ttGlyphID > firstGlyph && ttGlyphID < lastGlyph) {
73 return SWAPW(classValueArray[ttGlyphID - firstGlyph]);
74 }
75
76 return 0;
77 }
78
79 le_bool ClassDefFormat1Table::hasGlyphClass(le_int32 glyphClass) const
80 {
81 le_uint16 count = SWAPW(glyphCount);
82 int i;
83
84 for (i = 0; i < count; i += 1) {
85 if (SWAPW(classValueArray[i]) == glyphClass) {
86 return true;
87 }
88 }
89
90 return false;
91 }
92
93 le_int32 ClassDefFormat2Table::getGlyphClass(LEGlyphID glyphID) const
94 {
95 TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID);
96 le_uint16 rangeCount = SWAPW(classRangeCount);
97 le_int32 rangeIndex =
98 OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArray, rangeCount);
99
100 if (rangeIndex < 0) {
101 return 0;
102 }
103
104 return SWAPW(classRangeRecordArray[rangeIndex].rangeValue);
105 }
106
107 le_bool ClassDefFormat2Table::hasGlyphClass(le_int32 glyphClass) const
108 {
109 le_uint16 rangeCount = SWAPW(classRangeCount);
110 int i;
111
112 for (i = 0; i < rangeCount; i += 1) {
113 if (SWAPW(classRangeRecordArray[i].rangeValue) == glyphClass) {
114 return true;
115 }
116 }
117
118 return false;
119 }
120
121 U_NAMESPACE_END