os/textandloc/fontservices/textshaperplugin/IcuSource/layout/MPreFixups.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/MPreFixups.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +/*
     1.5 + *
     1.6 + * (C) Copyright IBM Corp. 2002-2004 - All Rights Reserved
     1.7 + *
     1.8 + */
     1.9 +
    1.10 +#include "LETypes.h"
    1.11 +#include "LEGlyphStorage.h"
    1.12 +#include "MPreFixups.h"
    1.13 +
    1.14 +U_NAMESPACE_BEGIN
    1.15 +
    1.16 +struct FixupData
    1.17 +{
    1.18 +    le_int32 fBaseIndex;
    1.19 +    le_int32 fMPreIndex;
    1.20 +};
    1.21 +
    1.22 +MPreFixups::MPreFixups(le_int32 charCount)
    1.23 +    : fFixupData(NULL), fFixupCount(0)
    1.24 +{
    1.25 +    fFixupData = LE_NEW_ARRAY(FixupData, charCount);
    1.26 +}
    1.27 +
    1.28 +MPreFixups::~MPreFixups()
    1.29 +{
    1.30 +    LE_DELETE_ARRAY(fFixupData);
    1.31 +    fFixupData = NULL;
    1.32 +}
    1.33 +
    1.34 +void MPreFixups::add(le_int32 baseIndex, le_int32 mpreIndex)
    1.35 +{
    1.36 +    // NOTE: don't add the fixup data if the mpre is right
    1.37 +    // before the base consonant glyph.
    1.38 +    if (baseIndex - mpreIndex > 1) {
    1.39 +        fFixupData[fFixupCount].fBaseIndex = baseIndex;
    1.40 +        fFixupData[fFixupCount].fMPreIndex = mpreIndex;
    1.41 +
    1.42 +        fFixupCount += 1;
    1.43 +    }
    1.44 +}
    1.45 +
    1.46 +void MPreFixups::apply(LEGlyphStorage &glyphStorage, LEErrorCode& success)
    1.47 +{
    1.48 +    if (LE_FAILURE(success)) {
    1.49 +        return;
    1.50 +    }
    1.51 +
    1.52 +    for (le_int32 fixup = 0; fixup < fFixupCount; fixup += 1) {
    1.53 +        le_int32 baseIndex = fFixupData[fixup].fBaseIndex;
    1.54 +        le_int32 mpreIndex = fFixupData[fixup].fMPreIndex;
    1.55 +        le_int32 mpreLimit = mpreIndex + 1;
    1.56 +
    1.57 +        while (glyphStorage[baseIndex] == 0xFFFF || glyphStorage[baseIndex] == 0xFFFE) {
    1.58 +            baseIndex -= 1;
    1.59 +        }
    1.60 +
    1.61 +        while (glyphStorage[mpreLimit] == 0xFFFF || glyphStorage[mpreLimit] == 0xFFFE) {
    1.62 +            mpreLimit += 1;
    1.63 +        }
    1.64 +
    1.65 +        if (mpreLimit == baseIndex) {
    1.66 +            continue;
    1.67 +        }
    1.68 +
    1.69 +        LEErrorCode success = LE_NO_ERROR;
    1.70 +        le_int32   mpreCount = mpreLimit - mpreIndex;
    1.71 +        le_int32   moveCount = baseIndex - mpreLimit;
    1.72 +        le_int32   mpreDest  = baseIndex - mpreCount;
    1.73 +        LEGlyphID *mpreSave  = LE_NEW_ARRAY(LEGlyphID, mpreCount);
    1.74 +        le_int32  *indexSave = LE_NEW_ARRAY(le_int32, mpreCount);
    1.75 +        if (!mpreSave || !indexSave) {
    1.76 +            LE_DELETE_ARRAY(mpreSave);
    1.77 +            LE_DELETE_ARRAY(indexSave);
    1.78 +            success = LE_MEMORY_ALLOCATION_ERROR;
    1.79 +            return;
    1.80 +        }
    1.81 +        le_int32   i;
    1.82 +
    1.83 +        for (i = 0; i < mpreCount; i += 1) {
    1.84 +            mpreSave[i]  = glyphStorage[mpreIndex + i];
    1.85 +            indexSave[i] = glyphStorage.getCharIndex(mpreIndex + i, success); //charIndices[mpreIndex + i];
    1.86 +        }
    1.87 +
    1.88 +        for (i = 0; i < moveCount; i += 1) {
    1.89 +            LEGlyphID glyph = glyphStorage[mpreLimit + i];
    1.90 +            le_int32 charIndex = glyphStorage.getCharIndex(mpreLimit + i, success);
    1.91 +
    1.92 +            glyphStorage[mpreIndex + i] = glyph;
    1.93 +            glyphStorage.setCharIndex(mpreIndex + i, charIndex, success);
    1.94 +        }
    1.95 +
    1.96 +        for (i = 0; i < mpreCount; i += 1) {
    1.97 +            glyphStorage[mpreDest + i] = mpreSave[i];
    1.98 +            glyphStorage.setCharIndex(mpreDest, indexSave[i], success);
    1.99 +        }
   1.100 +        
   1.101 +        LE_DELETE_ARRAY(indexSave);
   1.102 +        LE_DELETE_ARRAY(mpreSave);
   1.103 +    }
   1.104 +}
   1.105 +
   1.106 +U_NAMESPACE_END