|
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 "CoverageTables.h" |
|
36 #include "LESwaps.h" |
|
37 |
|
38 le_int32 CoverageTable::getGlyphCoverage(LEGlyphID glyphID) const |
|
39 { |
|
40 switch(SWAPW(coverageFormat)) |
|
41 { |
|
42 case 0: |
|
43 return -1; |
|
44 |
|
45 case 1: |
|
46 { |
|
47 const CoverageFormat1Table *f1Table = (const CoverageFormat1Table *) this; |
|
48 |
|
49 return f1Table->getGlyphCoverage(glyphID); |
|
50 } |
|
51 |
|
52 case 2: |
|
53 { |
|
54 const CoverageFormat2Table *f2Table = (const CoverageFormat2Table *) this; |
|
55 |
|
56 return f2Table->getGlyphCoverage(glyphID); |
|
57 } |
|
58 |
|
59 default: |
|
60 return -1; |
|
61 } |
|
62 } |
|
63 |
|
64 le_int32 CoverageFormat1Table::getGlyphCoverage(LEGlyphID glyphID) const |
|
65 { |
|
66 TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); |
|
67 le_uint16 count = SWAPW(glyphCount); |
|
68 le_uint8 bit = OpenTypeUtilities::highBit(count); |
|
69 le_uint16 power = 1 << bit; |
|
70 le_uint16 extra = count - power; |
|
71 le_uint16 probe = power; |
|
72 le_uint16 index = 0; |
|
73 |
|
74 if (SWAPW(glyphArray[extra]) <= ttGlyphID) { |
|
75 index = extra; |
|
76 } |
|
77 |
|
78 while (probe > (1 << 0)) { |
|
79 probe >>= 1; |
|
80 |
|
81 if (SWAPW(glyphArray[index + probe]) <= ttGlyphID) { |
|
82 index += probe; |
|
83 } |
|
84 } |
|
85 |
|
86 if (SWAPW(glyphArray[index]) == ttGlyphID) { |
|
87 return index; |
|
88 } |
|
89 |
|
90 return -1; |
|
91 } |
|
92 |
|
93 le_int32 CoverageFormat2Table::getGlyphCoverage(LEGlyphID glyphID) const |
|
94 { |
|
95 TTGlyphID ttGlyphID = (TTGlyphID) LE_GET_GLYPH(glyphID); |
|
96 le_uint16 count = SWAPW(rangeCount); |
|
97 le_int32 rangeIndex = |
|
98 OpenTypeUtilities::getGlyphRangeIndex(ttGlyphID, rangeRecordArray, count); |
|
99 |
|
100 if (rangeIndex < 0) { |
|
101 return -1; |
|
102 } |
|
103 |
|
104 TTGlyphID firstInRange = SWAPW(rangeRecordArray[rangeIndex].firstGlyph); |
|
105 le_uint16 startCoverageIndex = SWAPW(rangeRecordArray[rangeIndex].rangeValue); |
|
106 |
|
107 return startCoverageIndex + (ttGlyphID - firstInRange); |
|
108 } |