]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layout/OpenTypeUtilities.cpp
3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
8 #include "OpenTypeTables.h"
9 #include "OpenTypeUtilities.h"
15 // Finds the high bit by binary searching
16 // through the bits in n.
18 le_int8
OpenTypeUtilities::highBit(le_int32 value
)
26 if (value
>= 1 << 16) {
31 if (value
>= 1 << 8) {
36 if (value
>= 1 << 4) {
41 if (value
>= 1 << 2) {
46 if (value
>= 1 << 1) {
54 Offset
OpenTypeUtilities::getTagOffset(LETag tag
, const TagAndOffsetRecord
*records
, le_int32 recordCount
)
56 le_uint8 bit
= highBit(recordCount
);
57 le_int32 power
= 1 << bit
;
58 le_int32 extra
= recordCount
- power
;
59 le_int32 probe
= power
;
62 if (SWAPT(records
[extra
].tag
) <= tag
) {
66 while (probe
> (1 << 0)) {
69 if (SWAPT(records
[index
+ probe
].tag
) <= tag
) {
74 if (SWAPT(records
[index
].tag
) == tag
) {
75 return SWAPW(records
[index
].offset
);
81 le_int32
OpenTypeUtilities::getGlyphRangeIndex(TTGlyphID glyphID
, const GlyphRangeRecord
*records
, le_int32 recordCount
)
83 le_uint8 bit
= highBit(recordCount
);
84 le_int32 power
= 1 << bit
;
85 le_int32 extra
= recordCount
- power
;
86 le_int32 probe
= power
;
89 if (SWAPW(records
[extra
].firstGlyph
) <= glyphID
) {
93 while (probe
> (1 << 0)) {
96 if (SWAPW(records
[range
+ probe
].firstGlyph
) <= glyphID
) {
101 if (SWAPW(records
[range
].firstGlyph
) <= glyphID
&& SWAPW(records
[range
].lastGlyph
) >= glyphID
) {
108 le_int32
OpenTypeUtilities::search(le_uint32 value
, const le_uint32 array
[], le_int32 count
)
110 le_int32 power
= 1 << highBit(count
);
111 le_int32 extra
= count
- power
;
112 le_int32 probe
= power
;
115 if (value
>= array
[extra
]) {
119 while (probe
> (1 << 0)) {
122 if (value
>= array
[index
+ probe
]) {
130 le_int32
OpenTypeUtilities::search(le_uint16 value
, const le_uint16 array
[], le_int32 count
)
132 le_int32 power
= 1 << highBit(count
);
133 le_int32 extra
= count
- power
;
134 le_int32 probe
= power
;
137 if (value
>= array
[extra
]) {
141 while (probe
> (1 << 0)) {
144 if (value
>= array
[index
+ probe
]) {
153 // Straight insertion sort from Knuth vol. III, pg. 81
155 void OpenTypeUtilities::sort(le_uint16
*array
, le_int32 count
)
157 for (le_int32 j
= 1; j
< count
; j
+= 1) {
159 le_uint16 v
= array
[j
];
161 for (i
= j
- 1; i
>= 0; i
-= 1) {
166 array
[i
+ 1] = array
[i
];