X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/efa1e6592fb03ce23b15276b2b91d885a3ee7da5..57a6839dcb3bba09e8228b822b290604668416fe:/icuSources/layout/OpenTypeUtilities.cpp diff --git a/icuSources/layout/OpenTypeUtilities.cpp b/icuSources/layout/OpenTypeUtilities.cpp index 29c38ddc..d77c63e0 100644 --- a/icuSources/layout/OpenTypeUtilities.cpp +++ b/icuSources/layout/OpenTypeUtilities.cpp @@ -1,6 +1,6 @@ /* * - * (C) Copyright IBM Corp. 1998-2006 - All Rights Reserved + * (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved * */ @@ -51,58 +51,75 @@ le_int8 OpenTypeUtilities::highBit(le_int32 value) return bit; } -Offset OpenTypeUtilities::getTagOffset(LETag tag, const TagAndOffsetRecord *records, le_int32 recordCount) -{ - le_uint8 bit = highBit(recordCount); - le_int32 power = 1 << bit; - le_int32 extra = recordCount - power; - le_int32 probe = power; - le_int32 index = 0; - - if (SWAPT(records[extra].tag) <= tag) { - index = extra; - } - - while (probe > (1 << 0)) { - probe >>= 1; - - if (SWAPT(records[index + probe].tag) <= tag) { - index += probe; - } - } - if (SWAPT(records[index].tag) == tag) { - return SWAPW(records[index].offset); - } - - return 0; +Offset OpenTypeUtilities::getTagOffset(LETag tag, const LEReferenceToArrayOf &records, LEErrorCode &success) +{ + const TagAndOffsetRecord *r0 = (const TagAndOffsetRecord*)records.getAlias(); + if(LE_FAILURE(success)) return 0; + + le_uint32 recordCount = records.getCount(); + le_uint8 bit = highBit(recordCount); + le_int32 power = 1 << bit; + le_int32 extra = recordCount - power; + le_int32 probe = power; + le_int32 index = 0; + + { + const ATag &aTag = (r0+extra)->tag; + if (SWAPT(aTag) <= tag) { + index = extra; + } + } + + while (probe > (1 << 0)) { + probe >>= 1; + + { + const ATag &aTag = (r0+index+probe)->tag; + if (SWAPT(aTag) <= tag) { + index += probe; + } + } + } + + { + const ATag &aTag = (r0+index)->tag; + if (SWAPT(aTag) == tag) { + return SWAPW((r0+index)->offset); + } + } + + return 0; } -le_int32 OpenTypeUtilities::getGlyphRangeIndex(TTGlyphID glyphID, const GlyphRangeRecord *records, le_int32 recordCount) +le_int32 OpenTypeUtilities::getGlyphRangeIndex(TTGlyphID glyphID, const LEReferenceToArrayOf &records, LEErrorCode &success) { + if(LE_FAILURE(success)) return -1; + + le_uint32 recordCount = records.getCount(); le_uint8 bit = highBit(recordCount); le_int32 power = 1 << bit; le_int32 extra = recordCount - power; le_int32 probe = power; le_int32 range = 0; - if (recordCount == 0) { - return -1; - } + if (recordCount == 0) { + return -1; + } - if (SWAPW(records[extra].firstGlyph) <= glyphID) { + if (SWAPW(records(extra,success).firstGlyph) <= glyphID) { range = extra; } - while (probe > (1 << 0)) { + while (probe > (1 << 0) && LE_SUCCESS(success)) { probe >>= 1; - if (SWAPW(records[range + probe].firstGlyph) <= glyphID) { + if (SWAPW(records(range + probe,success).firstGlyph) <= glyphID) { range += probe; } } - if (SWAPW(records[range].firstGlyph) <= glyphID && SWAPW(records[range].lastGlyph) >= glyphID) { + if (SWAPW(records(range,success).firstGlyph) <= glyphID && SWAPW(records(range,success).lastGlyph) >= glyphID) { return range; } @@ -174,6 +191,38 @@ void OpenTypeUtilities::sort(le_uint16 *array, le_int32 count) } } - - U_NAMESPACE_END + +#if LE_ASSERT_BAD_FONT +#include + +static const char *letagToStr(LETag tag, char *str) { + str[0]= 0xFF & (tag>>24); + str[1]= 0xFF & (tag>>16); + str[2]= 0xFF & (tag>>8); + str[3]= 0xFF & (tag>>0); + str[4]= 0; + return str; +} + +U_CAPI void U_EXPORT2 _debug_LETableReference(const char *f, int l, const char *msg, const LETableReference *what, const void *ptr, size_t len) { + char tagbuf[5]; + + fprintf(stderr, "%s:%d: LETableReference@0x%p: ", f, l, what); + fprintf(stderr, msg, ptr, len); + fprintf(stderr, "\n"); + + for(int depth=0;depth<10&&(what!=NULL);depth++) { + for(int i=0;iisValid()) { + fprintf(stderr, "(invalid)"); + } + fprintf(stderr, "@%p: tag (%s) font (0x%p), [0x%p+0x%lx]\n", what, letagToStr(what->getTag(), tagbuf), what->getFont(), + what->getAlias(), what->getLength()); + + what = what->getParent(); + } +} +#endif