1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/LookupTables.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,85 @@
1.4 +/*
1.5 + *
1.6 + * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
1.7 + *
1.8 + */
1.9 +
1.10 +#include "LETypes.h"
1.11 +#include "LayoutTables.h"
1.12 +#include "LookupTables.h"
1.13 +#include "LESwaps.h"
1.14 +
1.15 +U_NAMESPACE_BEGIN
1.16 +
1.17 +/*
1.18 + These are the rolled-up versions of the uniform binary search.
1.19 + Someday, if we need more performance, we can un-roll them.
1.20 +
1.21 + Note: I put these in the base class, so they only have to
1.22 + be written once. Since the base class doesn't define the
1.23 + segment table, these routines assume that it's right after
1.24 + the binary search header.
1.25 +
1.26 + Another way to do this is to put each of these routines in one
1.27 + of the derived classes, and implement it in the others by casting
1.28 + the "this" pointer to the type that has the implementation.
1.29 +*/
1.30 +const LookupSegment *BinarySearchLookupTable::lookupSegment(const LookupSegment *segments, LEGlyphID glyph) const
1.31 +{
1.32 + le_int16 unity = SWAPW(unitSize);
1.33 + le_int16 probe = SWAPW(searchRange);
1.34 + le_int16 extra = SWAPW(rangeShift);
1.35 + TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph);
1.36 + const LookupSegment *entry = segments;
1.37 + const LookupSegment *trial = (const LookupSegment *) ((char *) entry + extra);
1.38 +
1.39 + if (SWAPW(trial->lastGlyph) <= ttGlyph) {
1.40 + entry = trial;
1.41 + }
1.42 +
1.43 + while (probe > unity) {
1.44 + probe >>= 1;
1.45 + trial = (const LookupSegment *) ((char *) entry + probe);
1.46 +
1.47 + if (SWAPW(trial->lastGlyph) <= ttGlyph) {
1.48 + entry = trial;
1.49 + }
1.50 + }
1.51 +
1.52 + if (SWAPW(entry->firstGlyph) <= ttGlyph) {
1.53 + return entry;
1.54 + }
1.55 +
1.56 + return NULL;
1.57 +}
1.58 +
1.59 +const LookupSingle *BinarySearchLookupTable::lookupSingle(const LookupSingle *entries, LEGlyphID glyph) const
1.60 +{
1.61 + le_int16 unity = SWAPW(unitSize);
1.62 + le_int16 probe = SWAPW(searchRange);
1.63 + le_int16 extra = SWAPW(rangeShift);
1.64 + TTGlyphID ttGlyph = (TTGlyphID) LE_GET_GLYPH(glyph);
1.65 + const LookupSingle *entry = entries;
1.66 + const LookupSingle *trial = (const LookupSingle *) ((char *) entry + extra);
1.67 +
1.68 + if (SWAPW(trial->glyph) <= ttGlyph) {
1.69 + entry = trial;
1.70 + }
1.71 +
1.72 + while (probe > unity) {
1.73 + probe >>= 1;
1.74 + trial = (const LookupSingle *) ((char *) entry + probe);
1.75 +
1.76 + if (SWAPW(trial->glyph) <= ttGlyph) {
1.77 + entry = trial;
1.78 + }
1.79 + }
1.80 +
1.81 + if (SWAPW(entry->glyph) == ttGlyph) {
1.82 + return entry;
1.83 + }
1.84 +
1.85 + return NULL;
1.86 +}
1.87 +
1.88 +U_NAMESPACE_END