os/textandloc/fontservices/textshaperplugin/IcuSource/layout/CanonShaping.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/CanonShaping.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,81 @@
     1.4 +/*
     1.5 + *
     1.6 + * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
     1.7 + *
     1.8 + */
     1.9 +
    1.10 +#include "LETypes.h"
    1.11 +#include "LEGlyphStorage.h"
    1.12 +#include "CanonShaping.h"
    1.13 +#include "GlyphDefinitionTables.h"
    1.14 +#include "ClassDefinitionTables.h"
    1.15 +
    1.16 +U_NAMESPACE_BEGIN
    1.17 +
    1.18 +void CanonShaping::sortMarks(le_int32 *indices, const le_int32 *combiningClasses, le_int32 index, le_int32 limit)
    1.19 +{
    1.20 +    for (le_int32 j = index + 1; j < limit; j += 1) {
    1.21 +        le_int32 i;
    1.22 +        le_int32 v = indices[j];
    1.23 +        le_int32 c = combiningClasses[v];
    1.24 +
    1.25 +        for (i = j - 1; i >= index; i -= 1) {
    1.26 +            if (c >= combiningClasses[indices[i]]) {
    1.27 +                break;
    1.28 +            }
    1.29 +
    1.30 +            indices[i + 1] = indices[i];
    1.31 +        }
    1.32 +
    1.33 +        indices[i + 1] = v;
    1.34 +    }
    1.35 +}
    1.36 +
    1.37 +void CanonShaping::reorderMarks(const LEUnicode *inChars, le_int32 charCount, le_bool rightToLeft,
    1.38 +                                LEUnicode *outChars, LEGlyphStorage &glyphStorage)
    1.39 +{
    1.40 +    const GlyphDefinitionTableHeader *gdefTable = (const GlyphDefinitionTableHeader *) glyphDefinitionTable;
    1.41 +    const ClassDefinitionTable *classTable = gdefTable->getMarkAttachClassDefinitionTable();
    1.42 +    le_int32 *combiningClasses = LE_NEW_ARRAY(le_int32, charCount);
    1.43 +    le_int32 *indices = LE_NEW_ARRAY(le_int32, charCount);
    1.44 +    LEErrorCode status = LE_NO_ERROR;
    1.45 +    le_int32 i;
    1.46 +
    1.47 +    for (i = 0; i < charCount; i += 1) {
    1.48 +        combiningClasses[i] = classTable->getGlyphClass((LEGlyphID) inChars[i]);
    1.49 +        indices[i] = i;
    1.50 +    }
    1.51 +
    1.52 +    for (i = 0; i < charCount; i += 1) {
    1.53 +        if (combiningClasses[i] != 0) {
    1.54 +            le_int32 mark;
    1.55 +
    1.56 +            for (mark = i; mark < charCount; mark += 1) {
    1.57 +                if (combiningClasses[mark] == 0) {
    1.58 +                    break;
    1.59 +                }
    1.60 +            }
    1.61 +
    1.62 +            sortMarks(indices, combiningClasses, i, mark);
    1.63 +        }
    1.64 +    }
    1.65 +
    1.66 +    le_int32 out = 0, dir = 1;
    1.67 +
    1.68 +    if (rightToLeft) {
    1.69 +        out = charCount - 1;
    1.70 +        dir = -1;
    1.71 +    }
    1.72 +
    1.73 +    for (i = 0; i < charCount; i += 1, out += dir) {
    1.74 +        le_int32 index = indices[i];
    1.75 +
    1.76 +        outChars[i] = inChars[index];
    1.77 +        glyphStorage.setCharIndex(out, index, status);
    1.78 +    }
    1.79 +
    1.80 +    LE_DELETE_ARRAY(indices);
    1.81 +    LE_DELETE_ARRAY(combiningClasses);
    1.82 +}
    1.83 +
    1.84 +U_NAMESPACE_END