os/textandloc/fontservices/textshaperplugin/IcuSource/layout/KhmerLayoutEngine.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/layout/KhmerLayoutEngine.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,80 @@
1.4 +
1.5 +/*
1.6 + *
1.7 + * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
1.8 + *
1.9 + * This file is a modification of the ICU file IndicLayoutEngine.cpp
1.10 + * by Jens Herden and Javier Sola for Khmer language
1.11 + *
1.12 + */
1.13 +
1.14 +
1.15 +#include "OpenTypeLayoutEngine.h"
1.16 +#include "KhmerLayoutEngine.h"
1.17 +#include "LEGlyphStorage.h"
1.18 +#include "KhmerReordering.h"
1.19 +
1.20 +U_NAMESPACE_BEGIN
1.21 +
1.22 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(KhmerOpenTypeLayoutEngine)
1.23 +
1.24 +KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
1.25 + le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
1.26 + : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable)
1.27 +{
1.28 + fFeatureOrder = KhmerReordering::getFeatureOrder();
1.29 +}
1.30 +
1.31 +KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
1.32 + le_int32 typoFlags)
1.33 + : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
1.34 +{
1.35 + fFeatureOrder = KhmerReordering::getFeatureOrder();
1.36 +}
1.37 +
1.38 +KhmerOpenTypeLayoutEngine::~KhmerOpenTypeLayoutEngine()
1.39 +{
1.40 + // nothing to do
1.41 +}
1.42 +
1.43 +// Input: characters
1.44 +// Output: characters, char indices, tags
1.45 +// Returns: output character count
1.46 +le_int32 KhmerOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
1.47 + LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
1.48 +{
1.49 + if (LE_FAILURE(success)) {
1.50 + return 0;
1.51 + }
1.52 +
1.53 + if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
1.54 + success = LE_ILLEGAL_ARGUMENT_ERROR;
1.55 + return 0;
1.56 + }
1.57 +
1.58 + le_int32 worstCase = count * 3; // worst case is 3 for Khmer TODO check if 2 is enough
1.59 +
1.60 + outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
1.61 +
1.62 + if (outChars == NULL) {
1.63 + success = LE_MEMORY_ALLOCATION_ERROR;
1.64 + return 0;
1.65 + }
1.66 +
1.67 + glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
1.68 + glyphStorage.allocateAuxData(success);
1.69 +
1.70 + if (LE_FAILURE(success)) {
1.71 + LE_DELETE_ARRAY(outChars);
1.72 + return 0;
1.73 + }
1.74 +
1.75 + // NOTE: assumes this allocates featureTags...
1.76 + // (probably better than doing the worst case stuff here...)
1.77 + le_int32 outCharCount = KhmerReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage);
1.78 +
1.79 + glyphStorage.adoptGlyphCount(outCharCount);
1.80 + return outCharCount;
1.81 +}
1.82 +
1.83 +U_NAMESPACE_END