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