]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layout/OpenTypeUtilities.cpp
2 * @(#)OpenTypeUtilities.cpp 1.6 00/03/15
4 * (C) Copyright IBM Corp. 1998-2003 - 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
)
27 if (value
>= 1 << 16) {
32 if (value
>= 1 << 8) {
37 if (value
>= 1 << 4) {
42 if (value
>= 1 << 2) {
47 if (value
>= 1 << 1) {
55 Offset
OpenTypeUtilities::getTagOffset(LETag tag
, const TagAndOffsetRecord
*records
, le_int32 recordCount
)
57 le_uint8 bit
= highBit(recordCount
);
58 le_int32 power
= 1 << bit
;
59 le_int32 extra
= recordCount
- power
;
60 le_int32 probe
= power
;
63 if (SWAPT(records
[extra
].tag
) <= tag
) {
67 while (probe
> (1 << 0)) {
70 if (SWAPT(records
[index
+ probe
].tag
) <= tag
) {
75 if (SWAPT(records
[index
].tag
) == tag
) {
76 return SWAPW(records
[index
].offset
);
82 le_int32
OpenTypeUtilities::getGlyphRangeIndex(TTGlyphID glyphID
, const GlyphRangeRecord
*records
, le_int32 recordCount
)
84 le_uint8 bit
= highBit(recordCount
);
85 le_int32 power
= 1 << bit
;
86 le_int32 extra
= recordCount
- power
;
87 le_int32 probe
= power
;
90 if (SWAPW(records
[extra
].firstGlyph
) <= glyphID
) {
94 while (probe
> (1 << 0)) {
97 if (SWAPW(records
[range
+ probe
].firstGlyph
) <= glyphID
) {
102 if (SWAPW(records
[range
].firstGlyph
) <= glyphID
&& SWAPW(records
[range
].lastGlyph
) >= glyphID
) {
109 le_int32
OpenTypeUtilities::search(le_uint32 value
, const le_uint32 array
[], le_int32 count
)
111 le_int32 power
= 1 << highBit(count
);
112 le_int32 extra
= count
- power
;
113 le_int32 probe
= power
;
116 if (value
>= array
[extra
]) {
120 while (probe
> (1 << 0)) {
123 if (value
>= array
[index
+ probe
]) {
131 le_int32
OpenTypeUtilities::search(le_uint16 value
, const le_uint16 array
[], le_int32 count
)
133 le_int32 power
= 1 << highBit(count
);
134 le_int32 extra
= count
- power
;
135 le_int32 probe
= power
;
138 if (value
>= array
[extra
]) {
142 while (probe
> (1 << 0)) {
145 if (value
>= array
[index
+ probe
]) {
154 // Straight insertion sort from Knuth vol. III, pg. 81
156 void OpenTypeUtilities::sort(le_uint16
*array
, le_int32 count
)
158 for (le_int32 j
= 1; j
< count
; j
+= 1) {
160 le_uint16 v
= array
[j
];
162 for (i
= j
- 1; i
>= 0; i
-= 1) {
167 array
[i
+ 1] = array
[i
];