]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layout/OpenTypeUtilities.cpp
3 * (C) Copyright IBM Corp. 1998-2006 - 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 (recordCount
== 0) {
93 if (SWAPW(records
[extra
].firstGlyph
) <= glyphID
) {
97 while (probe
> (1 << 0)) {
100 if (SWAPW(records
[range
+ probe
].firstGlyph
) <= glyphID
) {
105 if (SWAPW(records
[range
].firstGlyph
) <= glyphID
&& SWAPW(records
[range
].lastGlyph
) >= glyphID
) {
112 le_int32
OpenTypeUtilities::search(le_uint32 value
, const le_uint32 array
[], le_int32 count
)
114 le_int32 power
= 1 << highBit(count
);
115 le_int32 extra
= count
- power
;
116 le_int32 probe
= power
;
119 if (value
>= array
[extra
]) {
123 while (probe
> (1 << 0)) {
126 if (value
>= array
[index
+ probe
]) {
134 le_int32
OpenTypeUtilities::search(le_uint16 value
, const le_uint16 array
[], le_int32 count
)
136 le_int32 power
= 1 << highBit(count
);
137 le_int32 extra
= count
- power
;
138 le_int32 probe
= power
;
141 if (value
>= array
[extra
]) {
145 while (probe
> (1 << 0)) {
148 if (value
>= array
[index
+ probe
]) {
157 // Straight insertion sort from Knuth vol. III, pg. 81
159 void OpenTypeUtilities::sort(le_uint16
*array
, le_int32 count
)
161 for (le_int32 j
= 1; j
< count
; j
+= 1) {
163 le_uint16 v
= array
[j
];
165 for (i
= j
- 1; i
>= 0; i
-= 1) {
170 array
[i
+ 1] = array
[i
];