35 #include "ClassDefinitionTables.h" |
35 #include "ClassDefinitionTables.h" |
36 #include "LESwaps.h" |
36 #include "LESwaps.h" |
37 |
37 |
38 U_NAMESPACE_BEGIN |
38 U_NAMESPACE_BEGIN |
39 |
39 |
40 le_int32 ClassDefinitionTable::getGlyphClass(LEGlyphID glyphID) const |
40 le_int32 ClassDefinitionTable::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const |
41 { |
41 { |
|
42 LEReferenceTo<ClassDefinitionTable> thisRef(base, success); |
|
43 if (LE_FAILURE(success)) return 0; |
|
44 |
|
45 switch(SWAPW(classFormat)) { |
|
46 case 0: |
|
47 return 0; |
|
48 |
|
49 case 1: |
|
50 { |
|
51 const LEReferenceTo<ClassDefFormat1Table> f1Table(thisRef, success); |
|
52 return f1Table->getGlyphClass(f1Table, glyphID, success); |
|
53 } |
|
54 |
|
55 case 2: |
|
56 { |
|
57 const LEReferenceTo<ClassDefFormat2Table> f2Table(thisRef, success); |
|
58 return f2Table->getGlyphClass(f2Table, glyphID, success); |
|
59 } |
|
60 |
|
61 default: |
|
62 return 0; |
|
63 } |
|
64 } |
|
65 |
|
66 le_bool ClassDefinitionTable::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const |
|
67 { |
|
68 LEReferenceTo<ClassDefinitionTable> thisRef(base, success); |
|
69 if (LE_FAILURE(success)) return 0; |
|
70 |
42 switch(SWAPW(classFormat)) { |
71 switch(SWAPW(classFormat)) { |
43 case 0: |
72 case 0: |
44 return 0; |
73 return 0; |
45 |
74 |
46 case 1: |
75 case 1: |
47 { |
76 { |
48 const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this; |
77 const LEReferenceTo<ClassDefFormat1Table> f1Table(thisRef, success); |
49 |
78 return f1Table->hasGlyphClass(f1Table, glyphClass, success); |
50 return f1Table->getGlyphClass(glyphID); |
|
51 } |
79 } |
52 |
80 |
53 case 2: |
81 case 2: |
54 { |
82 { |
55 const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this; |
83 const LEReferenceTo<ClassDefFormat2Table> f2Table(thisRef, success); |
56 |
84 return f2Table->hasGlyphClass(f2Table, glyphClass, success); |
57 return f2Table->getGlyphClass(glyphID); |
|
58 } |
85 } |
59 |
86 |
60 default: |
87 default: |
61 return 0; |
88 return 0; |
62 } |
89 } |
63 } |
90 } |
64 |
91 |
65 le_bool ClassDefinitionTable::hasGlyphClass(le_int32 glyphClass) const |
92 le_int32 ClassDefFormat1Table::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const |
66 { |
93 { |
67 switch(SWAPW(classFormat)) { |
94 if(LE_FAILURE(success)) return 0; |
68 case 0: |
|
69 return 0; |
|
70 |
95 |
71 case 1: |
96 le_uint16 count = SWAPW(glyphCount); |
72 { |
97 LEReferenceToArrayOf<le_uint16> classValueArrayRef(base, success, &classValueArray[0], count); |
73 const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this; |
|
74 |
|
75 return f1Table->hasGlyphClass(glyphClass); |
|
76 } |
|
77 |
|
78 case 2: |
|
79 { |
|
80 const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this; |
|
81 |
|
82 return f2Table->hasGlyphClass(glyphClass); |
|
83 } |
|
84 |
|
85 default: |
|
86 return 0; |
|
87 } |
|
88 } |
|
89 |
|
90 le_int32 ClassDefFormat1Table::getGlyphClass(LEGlyphID glyphID) const |
|
91 { |
|
92 TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); |
98 TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); |
93 TTGlyphID firstGlyph = SWAPW(startGlyph); |
99 TTGlyphID firstGlyph = SWAPW(startGlyph); |
94 TTGlyphID lastGlyph = firstGlyph + SWAPW(glyphCount); |
100 TTGlyphID lastGlyph = firstGlyph + count; |
95 |
101 |
96 if (ttGlyphID >= firstGlyph && ttGlyphID < lastGlyph) { |
102 if (LE_SUCCESS(success) && ttGlyphID >= firstGlyph && ttGlyphID < lastGlyph) { |
97 return SWAPW(classValueArray[ttGlyphID - firstGlyph]); |
103 return SWAPW( classValueArrayRef(ttGlyphID - firstGlyph, success) ); |
98 } |
104 } |
99 |
105 |
100 return 0; |
106 return 0; |
101 } |
107 } |
102 |
108 |
103 le_bool ClassDefFormat1Table::hasGlyphClass(le_int32 glyphClass) const |
109 le_bool ClassDefFormat1Table::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const |
104 { |
110 { |
105 le_uint16 count = SWAPW(glyphCount); |
111 if(LE_FAILURE(success)) return 0; |
|
112 le_uint16 count = SWAPW(glyphCount); |
|
113 LEReferenceToArrayOf<le_uint16> classValueArrayRef(base, success, &classValueArray[0], count); |
106 int i; |
114 int i; |
107 |
115 |
108 for (i = 0; i < count; i += 1) { |
116 for (i = 0; LE_SUCCESS(success)&& (i < count); i += 1) { |
109 if (SWAPW(classValueArray[i]) == glyphClass) { |
117 if (SWAPW(classValueArrayRef(i,success)) == glyphClass) { |
110 return TRUE; |
118 return TRUE; |
111 } |
119 } |
112 } |
120 } |
113 |
121 |
114 return FALSE; |
122 return FALSE; |
115 } |
123 } |
116 |
124 |
117 le_int32 ClassDefFormat2Table::getGlyphClass(LEGlyphID glyphID) const |
125 le_int32 ClassDefFormat2Table::getGlyphClass(const LETableReference& base, LEGlyphID glyphID, LEErrorCode &success) const |
118 { |
126 { |
|
127 if(LE_FAILURE(success)) return 0; |
119 TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID); |
128 TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID); |
120 le_uint16 rangeCount = SWAPW(classRangeCount); |
129 le_uint16 rangeCount = SWAPW(classRangeCount); |
|
130 LEReferenceToArrayOf<GlyphRangeRecord> classRangeRecordArrayRef(base, success, &classRangeRecordArray[0], rangeCount); |
121 le_int32 rangeIndex = |
131 le_int32 rangeIndex = |
122 OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArray, rangeCount); |
132 OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArrayRef, success); |
123 |
133 |
124 if (rangeIndex < 0) { |
134 if (rangeIndex < 0 || LE_FAILURE(success)) { |
125 return 0; |
135 return 0; |
126 } |
136 } |
127 |
137 |
128 return SWAPW(classRangeRecordArray[rangeIndex].rangeValue); |
138 return SWAPW(classRangeRecordArrayRef(rangeIndex, success).rangeValue); |
129 } |
139 } |
130 |
140 |
131 le_bool ClassDefFormat2Table::hasGlyphClass(le_int32 glyphClass) const |
141 le_bool ClassDefFormat2Table::hasGlyphClass(const LETableReference &base, le_int32 glyphClass, LEErrorCode &success) const |
132 { |
142 { |
|
143 if(LE_FAILURE(success)) return 0; |
133 le_uint16 rangeCount = SWAPW(classRangeCount); |
144 le_uint16 rangeCount = SWAPW(classRangeCount); |
|
145 LEReferenceToArrayOf<GlyphRangeRecord> classRangeRecordArrayRef(base, success, &classRangeRecordArray[0], rangeCount); |
134 int i; |
146 int i; |
135 |
147 |
136 for (i = 0; i < rangeCount; i += 1) { |
148 for (i = 0; i < rangeCount && LE_SUCCESS(success); i += 1) { |
137 if (SWAPW(classRangeRecordArray[i].rangeValue) == glyphClass) { |
149 if (SWAPW(classRangeRecordArrayRef(i,success).rangeValue) == glyphClass) { |
138 return TRUE; |
150 return TRUE; |
139 } |
151 } |
140 } |
152 } |
141 |
153 |
142 return FALSE; |
154 return FALSE; |