J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun in the LICENSE file that accompanied this code. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | * accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License version |
| 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * |
| 28 | * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #include "LETypes.h" |
| 33 | #include "OpenTypeTables.h" |
| 34 | #include "OpenTypeUtilities.h" |
| 35 | #include "ClassDefinitionTables.h" |
| 36 | #include "LESwaps.h" |
| 37 | |
| 38 | le_int32 ClassDefinitionTable::getGlyphClass(LEGlyphID glyphID) const |
| 39 | { |
| 40 | switch(SWAPW(classFormat)) { |
| 41 | case 0: |
| 42 | return 0; |
| 43 | |
| 44 | case 1: |
| 45 | { |
| 46 | const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this; |
| 47 | |
| 48 | return f1Table->getGlyphClass(glyphID); |
| 49 | } |
| 50 | |
| 51 | case 2: |
| 52 | { |
| 53 | const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this; |
| 54 | |
| 55 | return f2Table->getGlyphClass(glyphID); |
| 56 | } |
| 57 | |
| 58 | default: |
| 59 | return 0; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | le_bool ClassDefinitionTable::hasGlyphClass(le_int32 glyphClass) const |
| 64 | { |
| 65 | switch(SWAPW(classFormat)) { |
| 66 | case 0: |
| 67 | return 0; |
| 68 | |
| 69 | case 1: |
| 70 | { |
| 71 | const ClassDefFormat1Table *f1Table = (const ClassDefFormat1Table *) this; |
| 72 | |
| 73 | return f1Table->hasGlyphClass(glyphClass); |
| 74 | } |
| 75 | |
| 76 | case 2: |
| 77 | { |
| 78 | const ClassDefFormat2Table *f2Table = (const ClassDefFormat2Table *) this; |
| 79 | |
| 80 | return f2Table->hasGlyphClass(glyphClass); |
| 81 | } |
| 82 | |
| 83 | default: |
| 84 | return 0; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | le_int32 ClassDefFormat1Table::getGlyphClass(LEGlyphID glyphID) const |
| 89 | { |
| 90 | TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); |
| 91 | TTGlyphID firstGlyph = SWAPW(startGlyph); |
| 92 | TTGlyphID lastGlyph = firstGlyph + SWAPW(glyphCount); |
| 93 | |
| 94 | if (ttGlyphID > firstGlyph && ttGlyphID < lastGlyph) { |
| 95 | return SWAPW(classValueArray[ttGlyphID - firstGlyph]); |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | le_bool ClassDefFormat1Table::hasGlyphClass(le_int32 glyphClass) const |
| 102 | { |
| 103 | le_uint16 count = SWAPW(glyphCount); |
| 104 | int i; |
| 105 | |
| 106 | for (i = 0; i < count; i += 1) { |
| 107 | if (SWAPW(classValueArray[i]) == glyphClass) { |
| 108 | return TRUE; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return FALSE; |
| 113 | } |
| 114 | |
| 115 | le_int32 ClassDefFormat2Table::getGlyphClass(LEGlyphID glyphID) const |
| 116 | { |
| 117 | TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyphID); |
| 118 | le_uint16 rangeCount = SWAPW(classRangeCount); |
| 119 | le_int32 rangeIndex = |
| 120 | OpenTypeUtilities::getGlyphRangeIndex(ttGlyph, classRangeRecordArray, rangeCount); |
| 121 | |
| 122 | if (rangeIndex < 0) { |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | return SWAPW(classRangeRecordArray[rangeIndex].rangeValue); |
| 127 | } |
| 128 | |
| 129 | le_bool ClassDefFormat2Table::hasGlyphClass(le_int32 glyphClass) const |
| 130 | { |
| 131 | le_uint16 rangeCount = SWAPW(classRangeCount); |
| 132 | int i; |
| 133 | |
| 134 | for (i = 0; i < rangeCount; i += 1) { |
| 135 | if (SWAPW(classRangeRecordArray[i].rangeValue) == glyphClass) { |
| 136 | return TRUE; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return FALSE; |
| 141 | } |