2
* @(#)OpenTypeUtilities.cpp 1.6 00/03/15
4
* (C) Copyright IBM Corp. 1998, 1999, 2000, 2001 - All Rights Reserved
9
#include "OpenTypeTables.h"
10
#include "OpenTypeUtilities.h"
16
// Finds the high bit by binary searching
17
// through the bits in n.
19
le_int8 OpenTypeUtilities::highBit(le_int32 value)
61
Offset OpenTypeUtilities::getTagOffset(LETag tag, const TagAndOffsetRecord *records, le_int32 recordCount)
63
le_uint8 bit = highBit(recordCount);
64
le_int32 power = 1 << bit;
65
le_int32 extra = recordCount - power;
66
le_int32 probe = power;
69
if (SWAPT(records[extra].tag) <= tag)
74
while (probe > (1 << 0))
78
if (SWAPT(records[index + probe].tag) <= tag)
84
if (SWAPT(records[index].tag) == tag)
86
return SWAPW(records[index].offset);
92
le_int32 OpenTypeUtilities::getGlyphRangeIndex(LEGlyphID glyphID, const GlyphRangeRecord *records, le_int32 recordCount)
94
le_uint8 bit = highBit(recordCount);
95
le_int32 power = 1 << bit;
96
le_int32 extra = recordCount - power;
97
le_int32 probe = power;
100
if (SWAPW(records[extra].firstGlyph) <= glyphID)
105
while (probe > (1 << 0))
109
if (SWAPW(records[range + probe].firstGlyph) <= glyphID)
115
if (SWAPW(records[range].firstGlyph) <= glyphID && SWAPW(records[range].lastGlyph) >= glyphID)
123
le_int32 OpenTypeUtilities::search(le_uint32 value, const le_uint32 array[], le_int32 count)
125
le_int32 power = 1 << highBit(count);
126
le_int32 extra = count - power;
127
le_int32 probe = power;
130
if (value >= array[extra]) {
134
while (probe > (1 << 0)) {
137
if (value >= array[index + probe]) {
145
le_int32 OpenTypeUtilities::search(le_uint16 value, const le_uint16 array[], le_int32 count)
147
le_int32 power = 1 << highBit(count);
148
le_int32 extra = count - power;
149
le_int32 probe = power;
152
if (value >= array[extra]) {
156
while (probe > (1 << 0)) {
159
if (value >= array[index + probe]) {
168
// Straight insertion sort from Knuth vol. III, pg. 81
170
void OpenTypeUtilities::sort(le_uint16 *array, le_int32 count)
172
for (le_int32 j = 1; j < count; j += 1) {
174
le_uint16 v = array[j];
176
for (i = j - 1; i >= 0; i -= 1) {
181
array[i + 1] = array[i];