X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..08b89b0a244153b9f5bbb2f49c55ab0f7298122e:/icuSources/layout/LEGlyphStorage.cpp diff --git a/icuSources/layout/LEGlyphStorage.cpp b/icuSources/layout/LEGlyphStorage.cpp index 36da0f7e..bac403a4 100644 --- a/icuSources/layout/LEGlyphStorage.cpp +++ b/icuSources/layout/LEGlyphStorage.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (C) 1998-2004, International Business Machines + * Copyright (C) 1998-2009, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -13,6 +13,11 @@ U_NAMESPACE_BEGIN UOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEGlyphStorage) +LEInsertionCallback::~LEInsertionCallback() +{ + // nothing to do... +} + LEGlyphStorage::LEGlyphStorage() : fGlyphCount(0), fGlyphs(NULL), fCharIndices(NULL), fPositions(NULL), fAuxData(NULL), fInsertionList(NULL), fSrcIndex(0), fDestIndex(0) @@ -104,6 +109,16 @@ void LEGlyphStorage::allocateGlyphArray(le_int32 initialGlyphCount, le_bool righ if (fInsertionList == NULL) { // FIXME: check this for failure? fInsertionList = new LEInsertionList(rightToLeft); + if (fInsertionList == NULL) { + LE_DELETE_ARRAY(fCharIndices); + fCharIndices = NULL; + + LE_DELETE_ARRAY(fGlyphs); + fGlyphs = NULL; + + success = LE_MEMORY_ALLOCATION_ERROR; + return; + } } } @@ -114,6 +129,11 @@ le_int32 LEGlyphStorage::allocatePositions(LEErrorCode &success) return -1; } + if (fPositions != NULL) { + success = LE_INTERNAL_ERROR; + return -1; + } + fPositions = LE_NEW_ARRAY(float, 2 * (fGlyphCount + 1)); if (fPositions == NULL) { @@ -131,7 +151,12 @@ le_int32 LEGlyphStorage::allocateAuxData(LEErrorCode &success) return -1; } - fAuxData = LE_NEW_ARRAY(void *, fGlyphCount); + if (fAuxData != NULL) { + success = LE_INTERNAL_ERROR; + return -1; + } + + fAuxData = LE_NEW_ARRAY(le_uint32, fGlyphCount); if (fAuxData == NULL) { success = LE_MEMORY_ALLOCATION_ERROR; @@ -302,7 +327,7 @@ void LEGlyphStorage::setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErr fCharIndices[glyphIndex] = charIndex; } -void LEGlyphStorage::getAuxData(void *auxData[], LEErrorCode &success) const +void LEGlyphStorage::getAuxData(le_uint32 auxData[], LEErrorCode &success) const { if (LE_FAILURE(success)) { return; @@ -321,26 +346,26 @@ void LEGlyphStorage::getAuxData(void *auxData[], LEErrorCode &success) const LE_ARRAY_COPY(auxData, fAuxData, fGlyphCount); } -void *LEGlyphStorage::getAuxData(le_int32 glyphIndex, LEErrorCode &success) const +le_uint32 LEGlyphStorage::getAuxData(le_int32 glyphIndex, LEErrorCode &success) const { if (LE_FAILURE(success)) { - return NULL; + return 0; } if (fAuxData == NULL) { success = LE_NO_LAYOUT_ERROR; - return NULL; + return 0; } if (glyphIndex < 0 || glyphIndex >= fGlyphCount) { success = LE_INDEX_OUT_OF_BOUNDS_ERROR; - return NULL; + return 0; } return fAuxData[glyphIndex]; } -void LEGlyphStorage::setAuxData(le_int32 glyphIndex, void *auxData, LEErrorCode &success) +void LEGlyphStorage::setAuxData(le_int32 glyphIndex, le_uint32 auxData, LEErrorCode &success) { if (LE_FAILURE(success)) { return; @@ -485,10 +510,49 @@ void LEGlyphStorage::adoptGlyphCount(le_int32 newGlyphCount) fGlyphCount = newGlyphCount; } -// FIXME: add error checking? +// Move a glyph to a different position in the LEGlyphStorage ( used for Indic v2 processing ) + +void LEGlyphStorage::moveGlyph(le_int32 fromPosition, le_int32 toPosition, le_uint32 marker ) +{ + + LEErrorCode success = LE_NO_ERROR; + + LEGlyphID holdGlyph = getGlyphID(fromPosition,success); + le_int32 holdCharIndex = getCharIndex(fromPosition,success); + le_uint32 holdAuxData = getAuxData(fromPosition,success); + + if ( fromPosition < toPosition ) { + for ( le_int32 i = fromPosition ; i < toPosition ; i++ ) { + setGlyphID(i,getGlyphID(i+1,success),success); + setCharIndex(i,getCharIndex(i+1,success),success); + setAuxData(i,getAuxData(i+1,success),success); + } + } else { + for ( le_int32 i = toPosition ; i > fromPosition ; i-- ) { + setGlyphID(i,getGlyphID(i-1,success),success); + setCharIndex(i,getCharIndex(i-1,success),success); + setAuxData(i,getAuxData(i-1,success),success); + + } + } + + setGlyphID(toPosition,holdGlyph,success); + setCharIndex(toPosition,holdCharIndex,success); + setAuxData(toPosition,holdAuxData | marker,success); + +} + +// Glue code for existing stable API LEGlyphID *LEGlyphStorage::insertGlyphs(le_int32 atIndex, le_int32 insertCount) { - return fInsertionList->insert(atIndex, insertCount); + LEErrorCode ignored = LE_NO_LAYOUT_ERROR; + return insertGlyphs(atIndex, insertCount, ignored); +} + +// FIXME: add error checking? +LEGlyphID *LEGlyphStorage::insertGlyphs(le_int32 atIndex, le_int32 insertCount, LEErrorCode& success) +{ + return fInsertionList->insert(atIndex, insertCount, success); } le_int32 LEGlyphStorage::applyInsertions() @@ -501,11 +565,27 @@ le_int32 LEGlyphStorage::applyInsertions() le_int32 newGlyphCount = fGlyphCount + growAmount; - fGlyphs = (LEGlyphID *) LE_GROW_ARRAY(fGlyphs, newGlyphCount); - fCharIndices = (le_int32 *) LE_GROW_ARRAY(fCharIndices, newGlyphCount); - - if (fAuxData != NULL) { - fAuxData = (void **) LE_GROW_ARRAY(fAuxData, newGlyphCount); + LEGlyphID *newGlyphs = (LEGlyphID *) LE_GROW_ARRAY(fGlyphs, newGlyphCount); + if (newGlyphs == NULL) { + // Could not grow the glyph array + return fGlyphCount; + } + fGlyphs = newGlyphs; + + le_int32 *newCharIndices = (le_int32 *) LE_GROW_ARRAY(fCharIndices, newGlyphCount); + if (newCharIndices == NULL) { + // Could not grow the glyph array + return fGlyphCount; + } + fCharIndices = newCharIndices; + + if (fAuxData != NULL) { + le_uint32 *newAuxData = (le_uint32 *) LE_GROW_ARRAY(fAuxData, newGlyphCount); + if (newAuxData == NULL) { + // could not grow the aux data array + return fGlyphCount; + } + fAuxData = (le_uint32 *)newAuxData; } fSrcIndex = fGlyphCount - 1;