os/textandloc/fontservices/textshaperplugin/IcuSource/layout/ThaiLayoutEngine.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/ThaiLayoutEngine.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +
     1.5 +/*
     1.6 + *
     1.7 + * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
     1.8 + *
     1.9 + */
    1.10 +
    1.11 +#include "LETypes.h"
    1.12 +#include "LayoutEngine.h"
    1.13 +#include "ThaiLayoutEngine.h"
    1.14 +#include "ScriptAndLanguageTags.h"
    1.15 +#include "LEGlyphStorage.h"
    1.16 +
    1.17 +#include "ThaiShaping.h"
    1.18 +
    1.19 +U_NAMESPACE_BEGIN
    1.20 +
    1.21 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine)
    1.22 +
    1.23 +ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
    1.24 +    : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
    1.25 +{
    1.26 +    fErrorChar = 0x25CC;
    1.27 +
    1.28 +    // Figure out which presentation forms the font uses
    1.29 +    if (fontInstance->canDisplay(0x0E64)) {
    1.30 +        // WorldType uses reserved space in Thai block
    1.31 +        fGlyphSet = 0;
    1.32 +    } else if (fontInstance->canDisplay(0xF701)) {
    1.33 +        // Microsoft corporate zone
    1.34 +        fGlyphSet = 1;
    1.35 +
    1.36 +        if (!fontInstance->canDisplay(fErrorChar)) {
    1.37 +            fErrorChar = 0xF71B;
    1.38 +        }
    1.39 +    } else if (fontInstance->canDisplay(0xF885)) {
    1.40 +        // Apple corporate zone
    1.41 +        fGlyphSet = 2;
    1.42 +    } else {
    1.43 +        // no presentation forms in the font
    1.44 +        fGlyphSet = 3;
    1.45 +    }
    1.46 +}
    1.47 +
    1.48 +ThaiLayoutEngine::~ThaiLayoutEngine()
    1.49 +{
    1.50 +    // nothing to do
    1.51 +}
    1.52 +
    1.53 +// Input: characters (0..max provided for context)
    1.54 +// Output: glyphs, char indices
    1.55 +// Returns: the glyph count
    1.56 +// NOTE: this assumes that ThaiShaping::compose will allocate the outChars array...
    1.57 +le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
    1.58 +{
    1.59 +    if (LE_FAILURE(success)) {
    1.60 +        return 0;
    1.61 +    }
    1.62 +
    1.63 +    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
    1.64 +        success = LE_ILLEGAL_ARGUMENT_ERROR;
    1.65 +        return 0;
    1.66 +    }
    1.67 +
    1.68 +    LEUnicode *outChars;
    1.69 +    le_int32 glyphCount;
    1.70 +    
    1.71 +    // This is enough room for the worst-case expansion
    1.72 +    // (it says here...)
    1.73 +    outChars = LE_NEW_ARRAY(LEUnicode, count * 2);
    1.74 +
    1.75 +    if (outChars == NULL) {
    1.76 +        success = LE_MEMORY_ALLOCATION_ERROR;
    1.77 +        return 0;
    1.78 +    }
    1.79 +
    1.80 +    glyphStorage.allocateGlyphArray(count * 2, FALSE, success);
    1.81 +
    1.82 +    if (LE_FAILURE(success)) {
    1.83 +        LE_DELETE_ARRAY(outChars);
    1.84 +        success = LE_MEMORY_ALLOCATION_ERROR;
    1.85 +        return 0;
    1.86 +    }
    1.87 +
    1.88 +    glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage);
    1.89 +    mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success);
    1.90 +
    1.91 +    LE_DELETE_ARRAY(outChars);
    1.92 +
    1.93 +    glyphStorage.adoptGlyphCount(glyphCount);
    1.94 +    return glyphCount;
    1.95 +}
    1.96 +
    1.97 +U_NAMESPACE_END