sl@0: sl@0: /* sl@0: * sl@0: * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved sl@0: * sl@0: */ sl@0: sl@0: #include "LETypes.h" sl@0: #include "LayoutEngine.h" sl@0: #include "ThaiLayoutEngine.h" sl@0: #include "ScriptAndLanguageTags.h" sl@0: #include "LEGlyphStorage.h" sl@0: sl@0: #include "ThaiShaping.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine) sl@0: sl@0: ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags) sl@0: : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags) sl@0: { sl@0: fErrorChar = 0x25CC; sl@0: sl@0: // Figure out which presentation forms the font uses sl@0: if (fontInstance->canDisplay(0x0E64)) { sl@0: // WorldType uses reserved space in Thai block sl@0: fGlyphSet = 0; sl@0: } else if (fontInstance->canDisplay(0xF701)) { sl@0: // Microsoft corporate zone sl@0: fGlyphSet = 1; sl@0: sl@0: if (!fontInstance->canDisplay(fErrorChar)) { sl@0: fErrorChar = 0xF71B; sl@0: } sl@0: } else if (fontInstance->canDisplay(0xF885)) { sl@0: // Apple corporate zone sl@0: fGlyphSet = 2; sl@0: } else { sl@0: // no presentation forms in the font sl@0: fGlyphSet = 3; sl@0: } sl@0: } sl@0: sl@0: ThaiLayoutEngine::~ThaiLayoutEngine() sl@0: { sl@0: // nothing to do sl@0: } sl@0: sl@0: // Input: characters (0..max provided for context) sl@0: // Output: glyphs, char indices sl@0: // Returns: the glyph count sl@0: // NOTE: this assumes that ThaiShaping::compose will allocate the outChars array... sl@0: le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success) sl@0: { sl@0: if (LE_FAILURE(success)) { sl@0: return 0; sl@0: } sl@0: sl@0: if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) { sl@0: success = LE_ILLEGAL_ARGUMENT_ERROR; sl@0: return 0; sl@0: } sl@0: sl@0: LEUnicode *outChars; sl@0: le_int32 glyphCount; sl@0: sl@0: // This is enough room for the worst-case expansion sl@0: // (it says here...) sl@0: outChars = LE_NEW_ARRAY(LEUnicode, count * 2); sl@0: sl@0: if (outChars == NULL) { sl@0: success = LE_MEMORY_ALLOCATION_ERROR; sl@0: return 0; sl@0: } sl@0: sl@0: glyphStorage.allocateGlyphArray(count * 2, FALSE, success); sl@0: sl@0: if (LE_FAILURE(success)) { sl@0: LE_DELETE_ARRAY(outChars); sl@0: success = LE_MEMORY_ALLOCATION_ERROR; sl@0: return 0; sl@0: } sl@0: sl@0: glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage); sl@0: mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success); sl@0: sl@0: LE_DELETE_ARRAY(outChars); sl@0: sl@0: glyphStorage.adoptGlyphCount(glyphCount); sl@0: return glyphCount; sl@0: } sl@0: sl@0: U_NAMESPACE_END