fontservices/textshaperplugin/IcuSource/layout/KhmerLayoutEngine.cpp
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 
       
     2 /*
       
     3  *
       
     4  * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved 
       
     5  *
       
     6  * This file is a modification of the ICU file IndicLayoutEngine.cpp
       
     7  * by Jens Herden and Javier Sola for Khmer language 
       
     8  *
       
     9  */
       
    10 
       
    11 
       
    12 #include "OpenTypeLayoutEngine.h"
       
    13 #include "KhmerLayoutEngine.h"
       
    14 #include "LEGlyphStorage.h"
       
    15 #include "KhmerReordering.h"
       
    16 
       
    17 U_NAMESPACE_BEGIN
       
    18 
       
    19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(KhmerOpenTypeLayoutEngine)
       
    20 
       
    21 KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
       
    22                     le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
       
    23     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable)
       
    24 {
       
    25     fFeatureOrder = KhmerReordering::getFeatureOrder();
       
    26 }
       
    27 
       
    28 KhmerOpenTypeLayoutEngine::KhmerOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
       
    29 						     le_int32 typoFlags)
       
    30     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags)
       
    31 {
       
    32     fFeatureOrder = KhmerReordering::getFeatureOrder();
       
    33 }
       
    34 
       
    35 KhmerOpenTypeLayoutEngine::~KhmerOpenTypeLayoutEngine()
       
    36 {
       
    37     // nothing to do
       
    38 }
       
    39 
       
    40 // Input: characters
       
    41 // Output: characters, char indices, tags
       
    42 // Returns: output character count
       
    43 le_int32 KhmerOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
       
    44         LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
       
    45 {
       
    46     if (LE_FAILURE(success)) {
       
    47         return 0;
       
    48     }
       
    49 
       
    50     if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
       
    51         success = LE_ILLEGAL_ARGUMENT_ERROR;
       
    52         return 0;
       
    53     }
       
    54 
       
    55     le_int32 worstCase = count * 3;  // worst case is 3 for Khmer  TODO check if 2 is enough
       
    56 
       
    57     outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
       
    58 
       
    59     if (outChars == NULL) {
       
    60         success = LE_MEMORY_ALLOCATION_ERROR;
       
    61         return 0;
       
    62     }
       
    63 
       
    64     glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
       
    65     glyphStorage.allocateAuxData(success);
       
    66 
       
    67     if (LE_FAILURE(success)) {
       
    68         LE_DELETE_ARRAY(outChars);
       
    69         return 0;
       
    70     }
       
    71 
       
    72     // NOTE: assumes this allocates featureTags...
       
    73     // (probably better than doing the worst case stuff here...)
       
    74     le_int32 outCharCount = KhmerReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage);
       
    75 
       
    76     glyphStorage.adoptGlyphCount(outCharCount);
       
    77     return outCharCount;
       
    78 }
       
    79 
       
    80 U_NAMESPACE_END