jdk/src/share/native/sun/font/layout/StateTableProcessor2.cpp
changeset 16889 3df90f344221
child 16890 36b30720a997
equal deleted inserted replaced
16888:4a32a7e572d1 16889:3df90f344221
       
     1 /*
       
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.  Oracle designates this
       
     7  * particular file as subject to the "Classpath" exception as provided
       
     8  * by Oracle in the LICENSE file that accompanied this code.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  *
       
    24  */
       
    25 
       
    26 /*
       
    27  *
       
    28  * (C) Copyright IBM Corp.  and others 1998-2013 - All Rights Reserved
       
    29  *
       
    30  */
       
    31 
       
    32 #include "LETypes.h"
       
    33 #include "MorphTables.h"
       
    34 #include "StateTables.h"
       
    35 #include "MorphStateTables.h"
       
    36 #include "SubtableProcessor2.h"
       
    37 #include "StateTableProcessor2.h"
       
    38 #include "LEGlyphStorage.h"
       
    39 #include "LESwaps.h"
       
    40 #include "LookupTables.h"
       
    41 #include <stdio.h>
       
    42 
       
    43 U_NAMESPACE_BEGIN
       
    44 
       
    45 StateTableProcessor2::StateTableProcessor2()
       
    46 {
       
    47 }
       
    48 
       
    49 StateTableProcessor2::StateTableProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
       
    50   : SubtableProcessor2(morphSubtableHeader)
       
    51 {
       
    52     stateTableHeader = (const MorphStateTableHeader2 *) morphSubtableHeader;
       
    53     nClasses = SWAPL(stateTableHeader->stHeader.nClasses);
       
    54     classTableOffset = SWAPL(stateTableHeader->stHeader.classTableOffset);
       
    55     stateArrayOffset = SWAPL(stateTableHeader->stHeader.stateArrayOffset);
       
    56     entryTableOffset = SWAPL(stateTableHeader->stHeader.entryTableOffset);
       
    57 
       
    58     classTable = (LookupTable *) ((char *) &stateTableHeader->stHeader + classTableOffset);
       
    59     format = SWAPW(classTable->format);
       
    60 
       
    61     stateArray = (const EntryTableIndex2 *) ((char *) &stateTableHeader->stHeader + stateArrayOffset);
       
    62 }
       
    63 
       
    64 StateTableProcessor2::~StateTableProcessor2()
       
    65 {
       
    66 }
       
    67 
       
    68 void StateTableProcessor2::process(LEGlyphStorage &glyphStorage)
       
    69 {
       
    70     // Start at state 0
       
    71     // XXX: How do we know when to start at state 1?
       
    72     le_uint16 currentState = 0;
       
    73     le_int32 glyphCount = glyphStorage.getGlyphCount();
       
    74 
       
    75     le_int32 currGlyph = 0;
       
    76     if ((coverage & scfReverse2) != 0) {  // process glyphs in descending order
       
    77         currGlyph = glyphCount - 1;
       
    78         dir = -1;
       
    79     } else {
       
    80         dir = 1;
       
    81     }
       
    82 
       
    83     beginStateTable();
       
    84     switch (format) {
       
    85         case ltfSimpleArray: {
       
    86 #ifdef TEST_FORMAT
       
    87             SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) classTable;
       
    88             while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
       
    89                 LookupValue classCode = classCodeOOB;
       
    90                 if (currGlyph == glyphCount || currGlyph == -1) {
       
    91                     // XXX: How do we handle EOT vs. EOL?
       
    92                     classCode = classCodeEOT;
       
    93                 } else {
       
    94                     LEGlyphID gid = glyphStorage[currGlyph];
       
    95                     TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
       
    96 
       
    97                     if (glyphCode == 0xFFFF) {
       
    98                         classCode = classCodeDEL;
       
    99                     } else {
       
   100                         classCode = SWAPW(lookupTable0->valueArray[gid]);
       
   101                     }
       
   102                 }
       
   103                 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
       
   104                 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); // return a zero-based index instead of a byte offset
       
   105             }
       
   106 #endif
       
   107             break;
       
   108         }
       
   109         case ltfSegmentSingle: {
       
   110             SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) classTable;
       
   111             while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
       
   112                 LookupValue classCode = classCodeOOB;
       
   113                 if (currGlyph == glyphCount || currGlyph == -1) {
       
   114                     // XXX: How do we handle EOT vs. EOL?
       
   115                     classCode = classCodeEOT;
       
   116                 } else {
       
   117                     LEGlyphID gid = glyphStorage[currGlyph];
       
   118                     TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
       
   119 
       
   120                     if (glyphCode == 0xFFFF) {
       
   121                         classCode = classCodeDEL;
       
   122                     } else {
       
   123                         const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
       
   124                         if (segment != NULL) {
       
   125                             classCode = SWAPW(segment->value);
       
   126                         }
       
   127                     }
       
   128                 }
       
   129                 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
       
   130                 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
       
   131             }
       
   132             break;
       
   133         }
       
   134         case ltfSegmentArray: {
       
   135             printf("Lookup Table Format4: specific interpretation needed!\n");
       
   136             break;
       
   137         }
       
   138         case ltfSingleTable: {
       
   139             SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) classTable;
       
   140             while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
       
   141                 LookupValue classCode = classCodeOOB;
       
   142                 if (currGlyph == glyphCount || currGlyph == -1) {
       
   143                     // XXX: How do we handle EOT vs. EOL?
       
   144                     classCode = classCodeEOT;
       
   145                 } else {
       
   146                     LEGlyphID gid = glyphStorage[currGlyph];
       
   147                     TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
       
   148 
       
   149                     if (glyphCode == 0xFFFF) {
       
   150                         classCode = classCodeDEL;
       
   151                     } else {
       
   152                         const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
       
   153                         if (segment != NULL) {
       
   154                             classCode = SWAPW(segment->value);
       
   155                         }
       
   156                     }
       
   157                 }
       
   158                 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
       
   159                 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
       
   160             }
       
   161             break;
       
   162         }
       
   163         case ltfTrimmedArray: {
       
   164             TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) classTable;
       
   165             TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
       
   166             TTGlyphID lastGlyph  = firstGlyph + SWAPW(lookupTable8->glyphCount);
       
   167 
       
   168             while ((dir == 1 && currGlyph <= glyphCount) || (dir == -1 && currGlyph >= -1)) {
       
   169                 LookupValue classCode = classCodeOOB;
       
   170                 if (currGlyph == glyphCount || currGlyph == -1) {
       
   171                     // XXX: How do we handle EOT vs. EOL?
       
   172                     classCode = classCodeEOT;
       
   173                 } else {
       
   174                     TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(glyphStorage[currGlyph]);
       
   175                     if (glyphCode == 0xFFFF) {
       
   176                         classCode = classCodeDEL;
       
   177                     } else if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
       
   178                         classCode = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
       
   179                     }
       
   180                 }
       
   181                 EntryTableIndex2 entryTableIndex = SWAPW(stateArray[classCode + currentState * nClasses]);
       
   182                 currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex);
       
   183             }
       
   184             break;
       
   185         }
       
   186         default:
       
   187             break;
       
   188     }
       
   189 
       
   190     endStateTable();
       
   191 }
       
   192 
       
   193 U_NAMESPACE_END