jdk/src/java.desktop/share/native/libfontmanager/layout/IndicLayoutEngine.cpp
author prr
Wed, 29 Jul 2015 11:04:39 -0700
changeset 33299 78f5508cde89
parent 25859 3317bb8137f4
permissions -rw-r--r--
8132042: Preserve layout presentation Reviewed-by: mschoene, srl, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    29
 * (C) Copyright IBM Corp. 1998-2009 - All Rights Reserved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "LayoutEngine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "OpenTypeLayoutEngine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "IndicLayoutEngine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "ScriptAndLanguageTags.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "GlyphSubstitutionTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "GlyphDefinitionTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "GlyphPositioningTables.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "GDEFMarkFilter.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "IndicReordering.h"
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    47
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    48
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    49
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    50
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IndicOpenTypeLayoutEngine)
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    51
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    52
IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode,
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
    53
                                                     le_int32 typoFlags, le_bool version2, const LEReferenceTo<GlyphSubstitutionTableHeader> &gsubTable, LEErrorCode &success)
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    54
    : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, gsubTable, success), fMPreFixups(NULL)
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    55
{
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    56
  if ( version2 ) {
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    57
    fFeatureMap = IndicReordering::getv2FeatureMap(fFeatureMapCount);
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    58
  } else {
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    59
    fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    60
  }
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    61
  fFeatureOrder = TRUE;
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    62
  fVersion2 = version2;
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    63
  fFilterZeroWidth = IndicReordering::getFilterZeroWidth(fScriptCode);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    64
}
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    65
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    66
IndicOpenTypeLayoutEngine::IndicOpenTypeLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, LEErrorCode &success)
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    67
    : OpenTypeLayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success), fMPreFixups(NULL)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    fFeatureMap = IndicReordering::getFeatureMap(fFeatureMapCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    fFeatureOrder = TRUE;
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    71
    fVersion2 =  FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
IndicOpenTypeLayoutEngine::~IndicOpenTypeLayoutEngine()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // nothing to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
// Input: characters, tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
// Output: glyphs, char indices
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    81
le_int32 IndicOpenTypeLayoutEngine::glyphProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    82
                    LEGlyphStorage &glyphStorage, LEErrorCode &success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        success = LE_ILLEGAL_ARGUMENT_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
    93
    _LETRACE("IOTLE::gp, calling parent");
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    94
    le_int32 retCount = OpenTypeLayoutEngine::glyphProcessing(chars, offset, count, max, rightToLeft, glyphStorage, success);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   100
    if (fVersion2) {
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   101
      _LETRACE("IOTLE::gp, v2 final,");
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   102
      IndicReordering::finalReordering(glyphStorage,retCount);
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   103
      _LETRACE("IOTLE::gp, v2 pres");
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   104
      IndicReordering::applyPresentationForms(glyphStorage,retCount);
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   105
      _LETRACE("IOTLE::gp, parent gsub");
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   106
      OpenTypeLayoutEngine::glyphSubstitution(count,max, rightToLeft, glyphStorage, success);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   107
    } else {
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   108
      _LETRACE("IOTLE::gp, adjust mpres");
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   109
      IndicReordering::adjustMPres(fMPreFixups, glyphStorage, success);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   110
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    return retCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
// Input: characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
// Output: characters, char indices, tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
// Returns: output character count
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   117
le_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool rightToLeft,
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   118
        LEUnicode *&outChars, LEGlyphStorage &glyphStorage, LEErrorCode &success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   124
    _LETRACE("IOTLE: charProc");
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   125
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        success = LE_ILLEGAL_ARGUMENT_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    outChars = LE_NEW_ARRAY(LEUnicode, worstCase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (outChars == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        success = LE_MEMORY_ALLOCATION_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    glyphStorage.allocateGlyphArray(worstCase, rightToLeft, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    glyphStorage.allocateAuxData(success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        LE_DELETE_ARRAY(outChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // NOTE: assumes this allocates featureTags...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // (probably better than doing the worst case stuff here...)
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   150
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   151
    le_int32 outCharCount;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   152
    if (fVersion2) {
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   153
        _LETRACE("v2process");
25101
2b07b28079a1 8042855: [parfait] Potential null pointer dereference in IndicLayoutEngine.cpp
prr
parents: 22330
diff changeset
   154
        outCharCount = IndicReordering::v2process(&chars[offset], count, fScriptCode, outChars, glyphStorage, success);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   155
    } else {
22330
cafb826672bd 8024530: Enhance font process resilience
prr
parents: 16891
diff changeset
   156
        _LETRACE("reorder");
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   157
        outCharCount = IndicReordering::reorder(&chars[offset], count, fScriptCode, outChars, glyphStorage, &fMPreFixups, success);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   158
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   159
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   160
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   161
        LE_DELETE_ARRAY(outChars);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   162
        return 0;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   163
    }
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   164
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    glyphStorage.adoptGlyphCount(outCharCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return outCharCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   168
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   169
U_NAMESPACE_END