diff --git a/icu4c/source/layout/ArabicLayoutEngine.cpp b/icu4c/source/layout/ArabicLayoutEngine.cpp index 9976b689cc..95c189aa05 100644 --- a/icu4c/source/layout/ArabicLayoutEngine.cpp +++ b/icu4c/source/layout/ArabicLayoutEngine.cpp @@ -24,16 +24,38 @@ U_NAMESPACE_BEGIN -class CharSubstitutionFilter : public LEGlyphFilter +class CharSubstitutionFilter : public UObject, public LEGlyphFilter { private: const LEFontInstance *fFontInstance; + /** + * The address of this static class variable serves as this class's ID + * for ICU "poor man's RTTI". + */ + static const char fgClassID; + public: CharSubstitutionFilter(const LEFontInstance *fontInstance); le_bool accept(LEGlyphID glyph) const; + + /** + * ICU "poor man's RTTI", returns a UClassID for the actual class. + * + * @draft ICU 2.2 + */ + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + + /** + * ICU "poor man's RTTI", returns a UClassID for this class. + * + * @draft ICU 2.2 + */ + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } }; +const char CharSubstitutionFilter::fgClassID=0; + CharSubstitutionFilter::CharSubstitutionFilter(const LEFontInstance *fontInstance) : fFontInstance(fontInstance) { @@ -80,7 +102,7 @@ le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[] return 0; } - featureTags = new const LETag*[count]; + featureTags = (const LETag **)uprv_malloc(count * sizeof(const LETag *)); if (featureTags == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; @@ -154,7 +176,7 @@ UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFon UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine() { - delete fSubstitutionFilter; + delete (CharSubstitutionFilter *)fSubstitutionFilter; } // "glyphs", "indices" -> glyphs, indices @@ -199,17 +221,17 @@ void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[] dir = -1; } - glyphs = new LEGlyphID[count]; + glyphs = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID)); if (glyphs == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; return; } - charIndices = new le_int32[count]; + charIndices = (le_int32 *)uprv_malloc(count * sizeof(le_int32)); if (charIndices == NULL) { - delete [] glyphs; + uprv_free(glyphs); success = LE_MEMORY_ALLOCATION_ERROR; return; } diff --git a/icu4c/source/layout/GDEFMarkFilter.cpp b/icu4c/source/layout/GDEFMarkFilter.cpp index 256d7d98ac..c1593a8501 100644 --- a/icu4c/source/layout/GDEFMarkFilter.cpp +++ b/icu4c/source/layout/GDEFMarkFilter.cpp @@ -12,6 +12,8 @@ U_NAMESPACE_BEGIN +const char GDEFMarkFilter::fgClassID=0; + GDEFMarkFilter::GDEFMarkFilter(const GlyphDefinitionTableHeader *gdefTable) { classDefTable = gdefTable->getGlyphClassDefinitionTable(); diff --git a/icu4c/source/layout/GDEFMarkFilter.h b/icu4c/source/layout/GDEFMarkFilter.h index 15bbf6eab7..34e07c5456 100644 --- a/icu4c/source/layout/GDEFMarkFilter.h +++ b/icu4c/source/layout/GDEFMarkFilter.h @@ -14,16 +14,36 @@ U_NAMESPACE_BEGIN -class GDEFMarkFilter : public LEGlyphFilter +class GDEFMarkFilter : public UObject, public LEGlyphFilter { private: const GlyphClassDefinitionTable *classDefTable; + /** + * The address of this static class variable serves as this class's ID + * for ICU "poor man's RTTI". + */ + static const char fgClassID; + public: GDEFMarkFilter(const GlyphDefinitionTableHeader *gdefTable); virtual ~GDEFMarkFilter(); virtual le_bool accept(LEGlyphID glyph) const; + + /** + * ICU "poor man's RTTI", returns a UClassID for the actual class. + * + * @draft ICU 2.2 + */ + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + + /** + * ICU "poor man's RTTI", returns a UClassID for this class. + * + * @draft ICU 2.2 + */ + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } }; U_NAMESPACE_END diff --git a/icu4c/source/layout/IndicLayoutEngine.cpp b/icu4c/source/layout/IndicLayoutEngine.cpp index 7a362023df..7406eaa03e 100644 --- a/icu4c/source/layout/IndicLayoutEngine.cpp +++ b/icu4c/source/layout/IndicLayoutEngine.cpp @@ -79,25 +79,25 @@ le_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode); - outChars = new LEUnicode[worstCase]; + outChars = (LEUnicode *)uprv_malloc(worstCase * sizeof(LEUnicode)); if (outChars == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; return 0; } - charIndices = new le_int32[worstCase]; + charIndices = (le_int32 *)uprv_malloc(worstCase * sizeof(le_int32)); if (charIndices == NULL) { - delete[] outChars; + uprv_free(outChars); success = LE_MEMORY_ALLOCATION_ERROR; return 0; } - featureTags = new const LETag*[worstCase]; + featureTags = (const LETag **)uprv_malloc(worstCase * sizeof(const LETag *)); if (featureTags == NULL) { - delete[] charIndices; - delete[] outChars; + uprv_free(charIndices); + uprv_free(outChars); success = LE_MEMORY_ALLOCATION_ERROR; return 0; } diff --git a/icu4c/source/layout/LETypes.h b/icu4c/source/layout/LETypes.h index ea22b290a5..697795387b 100644 --- a/icu4c/source/layout/LETypes.h +++ b/icu4c/source/layout/LETypes.h @@ -11,6 +11,7 @@ #include "unicode/utypes.h" #include "unicode/uobject.h" +#include "cmemory.h" U_NAMESPACE_BEGIN diff --git a/icu4c/source/layout/LayoutEngine.cpp b/icu4c/source/layout/LayoutEngine.cpp index c52885f354..c3662f7ca4 100644 --- a/icu4c/source/layout/LayoutEngine.cpp +++ b/icu4c/source/layout/LayoutEngine.cpp @@ -166,7 +166,7 @@ void LayoutEngine::positionGlyphs(const LEGlyphID glyphs[], le_int32 glyphCount, } if (positions == NULL) { - positions = new float[2 * (glyphCount + 1)]; + positions = (float *)uprv_malloc((2 * (glyphCount + 1)) * sizeof(float)); if (positions == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; @@ -243,7 +243,7 @@ void LayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le } if (glyphs == NULL) { - glyphs = new LEGlyphID[count]; + glyphs = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID)); if (glyphs == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; @@ -259,7 +259,7 @@ void LayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le dir = -1; } - charIndices = new le_int32[count]; + charIndices = (le_int32 *)uprv_malloc(count * sizeof(le_int32)); if (charIndices == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; @@ -303,17 +303,17 @@ void LayoutEngine::reset() fGlyphCount = 0; if (fGlyphs != NULL) { - delete[] fGlyphs; + uprv_free(fGlyphs); fGlyphs = NULL; } if (fCharIndices != NULL) { - delete[] fCharIndices; + uprv_free(fCharIndices); fCharIndices = NULL; } if (fPositions != NULL) { - delete[] fPositions; + uprv_free(fPositions); fPositions = NULL; } } diff --git a/icu4c/source/layout/LookupProcessor.cpp b/icu4c/source/layout/LookupProcessor.cpp index 9d74cc621d..9ab422fcf3 100644 --- a/icu4c/source/layout/LookupProcessor.cpp +++ b/icu4c/source/layout/LookupProcessor.cpp @@ -142,7 +142,7 @@ LookupProcessor::LookupProcessor(const char *baseAddress, requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex); - lookupSelectArray = new LETag[lookupListCount]; + lookupSelectArray = (LETag *)uprv_malloc(lookupListCount * sizeof(LETag)); for (int i = 0; i < lookupListCount; i += 1) { lookupSelectArray[i] = notSelected; @@ -152,7 +152,7 @@ LookupProcessor::LookupProcessor(const char *baseAddress, const FeatureTable *featureTable = 0; LETag featureTag; - lookupOrderArray = new le_uint16[lookupListCount]; + lookupOrderArray = (le_uint16 *)uprv_malloc(lookupListCount * sizeof(le_uint16)); if (requiredFeatureIndex != 0xFFFF) { featureTable = featureListTable->getFeatureTable(requiredFeatureIndex, &featureTag); @@ -198,8 +198,8 @@ LookupProcessor::LookupProcessor() LookupProcessor::~LookupProcessor() { - delete[] lookupOrderArray; - delete[] lookupSelectArray; + uprv_free(lookupOrderArray); + uprv_free(lookupSelectArray); }; U_NAMESPACE_END diff --git a/icu4c/source/layout/OpenTypeLayoutEngine.cpp b/icu4c/source/layout/OpenTypeLayoutEngine.cpp index f5f920cd14..f0efe5a899 100644 --- a/icu4c/source/layout/OpenTypeLayoutEngine.cpp +++ b/icu4c/source/layout/OpenTypeLayoutEngine.cpp @@ -48,7 +48,7 @@ void OpenTypeLayoutEngine::reset() // method that's called from here and // from our destructor if (fFeatureTags != NULL) { - delete[] fFeatureTags; + uprv_free(fFeatureTags); fFeatureTags = NULL; } } @@ -142,15 +142,15 @@ le_int32 OpenTypeLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 o outGlyphCount = glyphPostProcessing(fakeGlyphs, tempCharIndices, fakeGlyphCount, glyphs, charIndices, success); if (outChars != chars) { - delete[] outChars; + uprv_free(outChars); } if (fakeGlyphs != glyphs) { - delete[] fakeGlyphs; + uprv_free(fakeGlyphs); } if (tempCharIndices != charIndices) { - delete[] tempCharIndices; + uprv_free(tempCharIndices); } return outGlyphCount; @@ -211,7 +211,7 @@ void OpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int3 delete[] adjustments; } - delete[] fFeatureTags; + uprv_free(fFeatureTags); fFeatureTags = NULL; } diff --git a/icu4c/source/layout/ThaiLayoutEngine.cpp b/icu4c/source/layout/ThaiLayoutEngine.cpp index dc27ba766a..702c26f887 100644 --- a/icu4c/source/layout/ThaiLayoutEngine.cpp +++ b/icu4c/source/layout/ThaiLayoutEngine.cpp @@ -67,17 +67,17 @@ le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offse // This is enough room for the worst-case expansion // (it says here...) - outChars = new LEUnicode[count * 2]; + outChars = (LEUnicode *)uprv_malloc((count * 2) * sizeof(LEUnicode)); if (outChars == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; return 0; } - charIndices = new le_int32[count * 2]; + charIndices = (le_int32 *)uprv_malloc((count * 2) * sizeof(le_int32)); if (charIndices == NULL) { - delete[] outChars; + uprv_free(outChars); success = LE_MEMORY_ALLOCATION_ERROR; return 0; } @@ -85,7 +85,7 @@ le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offse glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, charIndices); mapCharsToGlyphs(outChars, 0, glyphCount, false, false, glyphs, charIndices, success); - delete[] outChars; + uprv_free(outChars); return glyphCount; } diff --git a/icu4c/source/layout/ThaiShaping.cpp b/icu4c/source/layout/ThaiShaping.cpp index 229e2128b1..6a1ea6eb05 100644 --- a/icu4c/source/layout/ThaiShaping.cpp +++ b/icu4c/source/layout/ThaiShaping.cpp @@ -302,6 +302,8 @@ le_int32 ThaiShaping::compose(const LEUnicode *input, le_int32 offset, le_int32 return outputIndex; } +const char ThaiMarkFilter::fgClassID=0; + ThaiMarkFilter::ThaiMarkFilter(le_uint8 glyphSet) : rangeList(NULL) { diff --git a/icu4c/source/layout/ThaiShaping.h b/icu4c/source/layout/ThaiShaping.h index 02ea2cd04d..424c5089f4 100644 --- a/icu4c/source/layout/ThaiShaping.h +++ b/icu4c/source/layout/ThaiShaping.h @@ -14,7 +14,7 @@ U_NAMESPACE_BEGIN -class ThaiMarkFilter : public LEGlyphFilter +class ThaiMarkFilter : public UObject, public LEGlyphFilter { private: struct MarkRange @@ -25,11 +25,31 @@ private: MarkRange *rangeList; + /** + * The address of this static class variable serves as this class's ID + * for ICU "poor man's RTTI". + */ + static const char fgClassID; + public: ThaiMarkFilter(le_uint8 glyphSet); ~ThaiMarkFilter(); virtual le_bool filter(LEGlyphID glyph); + + /** + * ICU "poor man's RTTI", returns a UClassID for the actual class. + * + * @draft ICU 2.2 + */ + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + + /** + * ICU "poor man's RTTI", returns a UClassID for this class. + * + * @draft ICU 2.2 + */ + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } }; class ThaiShaping /* not : public UObject because all methods are static */ { diff --git a/icu4c/source/layout/unicode/loengine.h b/icu4c/source/layout/unicode/loengine.h index 6dc402f5fb..12c6579ce5 100644 --- a/icu4c/source/layout/unicode/loengine.h +++ b/icu4c/source/layout/unicode/loengine.h @@ -287,31 +287,15 @@ inline int32_t ICULayoutEngine::layoutString(const UnicodeString &str, float x, float y, UErrorCode &success) { - int32_t glyphCount = 0; - int32_t max = str.length(); - UChar *chars = new UChar[max]; - - /* test for NULL */ - if(chars == 0) { - success = U_MEMORY_ALLOCATION_ERROR; - return 0; - } - - str.extract(0, max, chars); - // NOTE: call reset() so that clients can safely reuse fLayoutEngine->reset(); - glyphCount = fLayoutEngine->layoutChars(chars, + return fLayoutEngine->layoutChars(str.getBuffer(), startOffset, endOffset - startOffset, - max, + str.length(), rightToLeft, x, y, (LEErrorCode &) success); - - delete[] chars; - - return glyphCount; } inline int32_t ICULayoutEngine::countGlyphs() const