jdk/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.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 "ContextualGlyphSubstProc2.h"
       
    39 #include "LEGlyphStorage.h"
       
    40 #include "LESwaps.h"
       
    41 #include <stdio.h>
       
    42 
       
    43 U_NAMESPACE_BEGIN
       
    44 
       
    45 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ContextualGlyphSubstitutionProcessor2)
       
    46 
       
    47 ContextualGlyphSubstitutionProcessor2::ContextualGlyphSubstitutionProcessor2(const MorphSubtableHeader2 *morphSubtableHeader)
       
    48   : StateTableProcessor2(morphSubtableHeader)
       
    49 {
       
    50     contextualGlyphHeader = (const ContextualGlyphHeader2 *) morphSubtableHeader;
       
    51     le_uint32 perGlyphTableOffset = SWAPL(contextualGlyphHeader->perGlyphTableOffset);
       
    52     perGlyphTable = ((le_uint32 *) ((char *)&stateTableHeader->stHeader + perGlyphTableOffset));
       
    53     entryTable = (const ContextualGlyphStateEntry2 *) ((char *) &stateTableHeader->stHeader + entryTableOffset);
       
    54 }
       
    55 
       
    56 ContextualGlyphSubstitutionProcessor2::~ContextualGlyphSubstitutionProcessor2()
       
    57 {
       
    58 }
       
    59 
       
    60 void ContextualGlyphSubstitutionProcessor2::beginStateTable()
       
    61 {
       
    62     markGlyph = 0;
       
    63 }
       
    64 
       
    65 le_uint16 ContextualGlyphSubstitutionProcessor2::processStateEntry(LEGlyphStorage &glyphStorage, le_int32 &currGlyph, EntryTableIndex2 index)
       
    66 {
       
    67     const ContextualGlyphStateEntry2 *entry = &entryTable[index];
       
    68     le_uint16 newState = SWAPW(entry->newStateIndex);
       
    69     le_uint16 flags = SWAPW(entry->flags);
       
    70     le_int16 markIndex = SWAPW(entry->markIndex);
       
    71     le_int16 currIndex = SWAPW(entry->currIndex);
       
    72 
       
    73     if (markIndex != -1) {
       
    74         le_uint32 offset = SWAPL(perGlyphTable[markIndex]);
       
    75         LEGlyphID mGlyph = glyphStorage[markGlyph];
       
    76         TTGlyphID newGlyph = lookup(offset, mGlyph);
       
    77         glyphStorage[markGlyph] = LE_SET_GLYPH(mGlyph, newGlyph);
       
    78     }
       
    79 
       
    80     if (currIndex != -1) {
       
    81         le_uint32 offset = SWAPL(perGlyphTable[currIndex]);
       
    82         LEGlyphID thisGlyph = glyphStorage[currGlyph];
       
    83         TTGlyphID newGlyph = lookup(offset, thisGlyph);
       
    84         glyphStorage[currGlyph] = LE_SET_GLYPH(thisGlyph, newGlyph);
       
    85     }
       
    86 
       
    87     if (flags & cgsSetMark) {
       
    88         markGlyph = currGlyph;
       
    89     }
       
    90 
       
    91     if (!(flags & cgsDontAdvance)) {
       
    92         currGlyph += dir;
       
    93     }
       
    94 
       
    95     return newState;
       
    96 }
       
    97 
       
    98 TTGlyphID ContextualGlyphSubstitutionProcessor2::lookup(le_uint32 offset, LEGlyphID gid)
       
    99 {
       
   100     LookupTable *lookupTable = ((LookupTable *) ((char *)perGlyphTable + offset));
       
   101     le_int16 format = SWAPW(lookupTable->format);
       
   102     TTGlyphID newGlyph = 0xFFFF;
       
   103 
       
   104     switch (format) {
       
   105         case ltfSimpleArray: {
       
   106 #ifdef TEST_FORMAT
       
   107             // Disabled pending for design review
       
   108             SimpleArrayLookupTable *lookupTable0 = (SimpleArrayLookupTable *) lookupTable;
       
   109             TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
       
   110             newGlyph = SWAPW(lookupTable0->valueArray[glyphCode]);
       
   111 #endif
       
   112             break;
       
   113         }
       
   114         case ltfSegmentSingle: {
       
   115 #ifdef TEST_FORMAT
       
   116             // Disabled pending for design review
       
   117             SegmentSingleLookupTable *lookupTable2 = (SegmentSingleLookupTable *) lookupTable;
       
   118             const LookupSegment *segment = lookupTable2->lookupSegment(lookupTable2->segments, gid);
       
   119             if (segment != NULL) {
       
   120                 newGlyph = SWAPW(segment->value);
       
   121             }
       
   122 #endif
       
   123             break;
       
   124         }
       
   125         case ltfSegmentArray: {
       
   126             printf("Context Lookup Table Format4: specific interpretation needed!\n");
       
   127             break;
       
   128         }
       
   129         case ltfSingleTable:
       
   130         {
       
   131 #ifdef TEST_FORMAT
       
   132             // Disabled pending for design review
       
   133             SingleTableLookupTable *lookupTable6 = (SingleTableLookupTable *) lookupTable;
       
   134             const LookupSingle *segment = lookupTable6->lookupSingle(lookupTable6->entries, gid);
       
   135             if (segment != NULL) {
       
   136                 newGlyph = SWAPW(segment->value);
       
   137             }
       
   138 #endif
       
   139             break;
       
   140         }
       
   141         case ltfTrimmedArray: {
       
   142             TrimmedArrayLookupTable *lookupTable8 = (TrimmedArrayLookupTable *) lookupTable;
       
   143             TTGlyphID firstGlyph = SWAPW(lookupTable8->firstGlyph);
       
   144             TTGlyphID lastGlyph  = firstGlyph + SWAPW(lookupTable8->glyphCount);
       
   145             TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid);
       
   146             if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) {
       
   147                 newGlyph = SWAPW(lookupTable8->valueArray[glyphCode - firstGlyph]);
       
   148             }
       
   149         }
       
   150         default:
       
   151             break;
       
   152     }
       
   153     return newGlyph;
       
   154 }
       
   155 
       
   156 void ContextualGlyphSubstitutionProcessor2::endStateTable()
       
   157 {
       
   158 }
       
   159 
       
   160 U_NAMESPACE_END