os/textandloc/fontservices/textshaperplugin/IcuSource/layout/IndicLayoutEngine.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 
     2 /*
     3  *
     4  * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
     5  *
     6  */
     7 
     8 #include "LETypes.h"
     9 #include "LayoutEngine.h"
    10 #include "OpenTypeLayoutEngine.h"
    11 #include "IndicLayoutEngine.h"
    12 #include "ScriptAndLanguageTags.h"
    13 
    14 #include "GlyphSubstitutionTables.h"
    15 #include "GlyphDefinitionTables.h"
    16 #include "GlyphPositioningTables.h"
    17 
    18 #include "GDEFMarkFilter.h"
    19 #include "LEGlyphStorage.h"
    20 
    21 #include "IndicReordering.h"
    22 
    23 U_NAMESPACE_BEGIN
    24 
    25 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicOpenTypeLayoutEngine)
    26 
    27 IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
    28                     le_int32 typoFlags, const GlyphSubstitutionTableHeader *gsubTable)
    29     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable), fMPreFixups(NULL)
    30 {
    31     fFeatureOrder = IndicReordering::getFeatureOrder();
    32 }
    33 
    34 IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags)
    35     : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags), fMPreFixups(NULL)
    36 {
    37     fFeatureOrder = IndicReordering::getFeatureOrder();
    38 }
    39 
    40 IndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
    41 {
    42     // nothing to do
    43 }
    44 
    45 // Input: characters, tags
    46 // Output: glyphs, char indices
    47 le_int32 IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
    48                     LEGlyphStorage &glyphStorage, LEErrorCode &success)
    49 {
    50     if (LE_FAILURE(success)) {
    51         return 0;
    52     }
    53 
    54     if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
    55         success = LE_ILLEGAL_ARGUMENT_ERROR;
    56         return 0;
    57     }
    58 
    59     le_int32 retCount = OpenTypeLayoutEngine::glyphProcessing(chars, offset, count, max, rightToLeft, glyphStorage, success);
    60 
    61     if (LE_FAILURE(success)) {
    62         return 0;
    63     }
    64 
    65     IndicReordering::adjustMPres(fMPreFixups, glyphStorage, success);
    66 
    67     return retCount;
    68 }
    69 
    70 // Input: characters
    71 // Output: characters, char indices, tags
    72 // Returns: output character count
    73 le_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
    74         LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
    75 {
    76     if (LE_FAILURE(success)) {
    77         return 0;
    78     }
    79 
    80     if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
    81         success = LE_ILLEGAL_ARGUMENT_ERROR;
    82         return 0;
    83     }
    84 
    85     le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
    86 
    87     outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
    88 
    89     if (outChars == NULL) {
    90         success = LE_MEMORY_ALLOCATION_ERROR;
    91         return 0;
    92     }
    93 
    94     glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
    95     glyphStorage.allocateAuxData(success);
    96 
    97     if (LE_FAILURE(success)) {
    98         LE_DELETE_ARRAY(outChars);
    99         outChars = NULL;
   100         return 0;
   101     }
   102 
   103     // NOTE: assumes this allocates featureTags...
   104     // (probably better than doing the worst case stuff here...)
   105     le_int32 outCharCount = IndicReordering::reorder(&chars[offset], count,
   106         fScriptCode, outChars, glyphStorage, &fMPreFixups, success);
   107 
   108     if (LE_FAILURE(success)) {
   109         LE_DELETE_ARRAY(outChars);
   110         outChars = NULL;
   111         return 0;
   112     }
   113 
   114     glyphStorage.adoptGlyphCount(outCharCount);
   115     return outCharCount;
   116 }
   117 
   118 U_NAMESPACE_END