src/java.desktop/share/native/libfontmanager/layout/MPreFixups.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.desktop/share/native/libfontmanager/layout/MPreFixups.cpp@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
 *
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 9460
diff changeset
    28
 * (C) Copyright IBM Corp. 2002-2013 - All Rights Reserved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "MPreFixups.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    36
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
struct FixupData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    le_int32 fBaseIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    le_int32 fMPreIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
MPreFixups::MPreFixups(le_int32 charCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    : fFixupData(NULL), fFixupCount(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    fFixupData = LE_NEW_ARRAY(FixupData, charCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
MPreFixups::~MPreFixups()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    LE_DELETE_ARRAY(fFixupData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    fFixupData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
void MPreFixups::add(le_int32 baseIndex, le_int32 mpreIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // NOTE: don't add the fixup data if the mpre is right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // before the base consonant glyph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (baseIndex - mpreIndex > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        fFixupData[fFixupCount].fBaseIndex = baseIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        fFixupData[fFixupCount].fMPreIndex = mpreIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        fFixupCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 9460
diff changeset
    68
void MPreFixups::apply(LEGlyphStorage &glyphStorage, LEErrorCode& success)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
16889
3df90f344221 8008249: Sync ICU into JDK
prr
parents: 9460
diff changeset
    70
    if (LE_FAILURE(success)) {
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    71
        return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    72
    }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    for (le_int32 fixup = 0; fixup < fFixupCount; fixup += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        le_int32 baseIndex = fFixupData[fixup].fBaseIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        le_int32 mpreIndex = fFixupData[fixup].fMPreIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        le_int32 mpreLimit = mpreIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        while (glyphStorage[baseIndex] == 0xFFFF || glyphStorage[baseIndex] == 0xFFFE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            baseIndex -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        while (glyphStorage[mpreLimit] == 0xFFFF || glyphStorage[mpreLimit] == 0xFFFE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            mpreLimit += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (mpreLimit == baseIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        LEErrorCode success = LE_NO_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        le_int32   mpreCount = mpreLimit - mpreIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        le_int32   moveCount = baseIndex - mpreLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        le_int32   mpreDest  = baseIndex - mpreCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        LEGlyphID *mpreSave  = LE_NEW_ARRAY(LEGlyphID, mpreCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        le_int32  *indexSave = LE_NEW_ARRAY(le_int32, mpreCount);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    97
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    98
        if (mpreSave == NULL || indexSave == NULL) {
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    99
            LE_DELETE_ARRAY(mpreSave);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   100
            LE_DELETE_ARRAY(indexSave);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   101
            success = LE_MEMORY_ALLOCATION_ERROR;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   102
            return;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   103
        }
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        le_int32   i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        for (i = 0; i < mpreCount; i += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            mpreSave[i]  = glyphStorage[mpreIndex + i];
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   109
            indexSave[i] = glyphStorage.getCharIndex(mpreIndex + i, success); //charIndices[mpreIndex + i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        for (i = 0; i < moveCount; i += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            LEGlyphID glyph = glyphStorage[mpreLimit + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            le_int32 charIndex = glyphStorage.getCharIndex(mpreLimit + i, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            glyphStorage[mpreIndex + i] = glyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            glyphStorage.setCharIndex(mpreIndex + i, charIndex, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        for (i = 0; i < mpreCount; i += 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            glyphStorage[mpreDest + i] = mpreSave[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            glyphStorage.setCharIndex(mpreDest, indexSave[i], success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        LE_DELETE_ARRAY(indexSave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        LE_DELETE_ARRAY(mpreSave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   129
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   130
U_NAMESPACE_END