jdk/src/share/native/sun/font/layout/ThaiLayoutEngine.cpp
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 7486 6a36b1ebc620
permissions -rw-r--r--
8001031: Better font processing Reviewed-by: srl, vadim
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-2010 - 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 "ThaiLayoutEngine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "ScriptAndLanguageTags.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    39
#include "KernTable.h"
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "ThaiShaping.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    43
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    44
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    45
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ThaiLayoutEngine)
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    46
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    47
ThaiLayoutEngine::ThaiLayoutEngine(const LEFontInstance *fontInstance, le_int32 scriptCode, le_int32 languageCode, le_int32 typoFlags, LEErrorCode &success)
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    48
    : LayoutEngine(fontInstance, scriptCode, languageCode, typoFlags, success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    fErrorChar = 0x25CC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // Figure out which presentation forms the font uses
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    53
    if (! fontInstance->canDisplay(0x0E01)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    54
        // No Thai in font; don't use presentation forms.
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    55
        fGlyphSet = 3;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    56
    } else if (fontInstance->canDisplay(0x0E64)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // WorldType uses reserved space in Thai block
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        fGlyphSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    } else if (fontInstance->canDisplay(0xF701)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        // Microsoft corporate zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        fGlyphSet = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (!fontInstance->canDisplay(fErrorChar)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            fErrorChar = 0xF71B;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    } else if (fontInstance->canDisplay(0xF885)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        // Apple corporate zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        fGlyphSet = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        // no presentation forms in the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        fGlyphSet = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
ThaiLayoutEngine::~ThaiLayoutEngine()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // nothing to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
// Input: characters (0..max provided for context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
// Output: glyphs, char indices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
// Returns: the glyph count
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
// NOTE: this assumes that ThaiShaping::compose will allocate the outChars array...
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    84
le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_int32 max, le_bool /*rightToLeft*/, LEGlyphStorage &glyphStorage, LEErrorCode &success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    90
    if (chars == NULL || offset < 0 || count < 0 || max < 0 || offset >= max || offset + count > max) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        success = LE_ILLEGAL_ARGUMENT_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    LEUnicode *outChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    le_int32 glyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // This is enough room for the worst-case expansion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // (it says here...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    outChars = LE_NEW_ARRAY(LEUnicode, count * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    if (outChars == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        success = LE_MEMORY_ALLOCATION_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    glyphStorage.allocateGlyphArray(count * 2, FALSE, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (LE_FAILURE(success)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        LE_DELETE_ARRAY(outChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        success = LE_MEMORY_ALLOCATION_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   115
    glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, glyphStorage);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    mapCharsToGlyphs(outChars, 0, glyphCount, FALSE, FALSE, glyphStorage, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    LE_DELETE_ARRAY(outChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    glyphStorage.adoptGlyphCount(glyphCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    return glyphCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   123
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   124
// This is the same as LayoutEngline::adjustGlyphPositions() except that it doesn't call adjustMarkGlyphs
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   125
void ThaiLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool  /*reverse*/,
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   126
                                        LEGlyphStorage &glyphStorage, LEErrorCode &success)
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   127
{
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   128
    if (LE_FAILURE(success)) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   129
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   130
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   131
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   132
    if (chars == NULL || offset < 0 || count < 0) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   133
        success = LE_ILLEGAL_ARGUMENT_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   134
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   135
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   136
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   137
    if (fTypoFlags & LE_Kerning_FEATURE_FLAG) { /* kerning enabled */
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   138
      LETableReference kernTable(fFontInstance, LE_KERN_TABLE_TAG, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   139
      KernTable kt(kernTable, success);
91e99bed64ae 8001031: Better font processing
prr
parents: 7486
diff changeset
   140
      kt.process(glyphStorage, success);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   141
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   142
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   143
    // default is no adjustments
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   144
    return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   145
}
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   146
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   147
U_NAMESPACE_END