src/java.desktop/share/native/libfontmanager/HBShaper.c
author erikj
Mon, 01 Oct 2018 11:02:33 -0700
branchJEP-230-microbenchmarks-branch
changeset 56912 d434fc4d10aa
parent 47216 71c04702a3d5
child 54590 98473958d49a
permissions -rw-r--r--
Add jmh to jib profiles config
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     1
/*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     4
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    10
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    15
 * accompanied this code).
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    16
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    20
 *
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    23
 * questions.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    24
 */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    25
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    26
#include <jni_util.h>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    27
#include <stdlib.h>
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    28
#include "hb.h"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    29
#include "hb-jdk.h"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    30
#include "hb-ot.h"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    31
#ifdef MACOSX
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    32
#include "hb-coretext.h"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    33
#endif
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    34
#include "scriptMapping.h"
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    35
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    36
static jclass gvdClass = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    37
static const char* gvdClassName = "sun/font/GlyphLayout$GVData";
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    38
static jfieldID gvdCountFID = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    39
static jfieldID gvdFlagsFID = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    40
static jfieldID gvdGlyphsFID = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    41
static jfieldID gvdPositionsFID = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    42
static jfieldID gvdIndicesFID = 0;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    43
static jmethodID gvdGrowMID = 0;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    44
static int jniInited = 0;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    45
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    46
static void getFloat(JNIEnv* env, jobject pt, jfloat *x, jfloat *y) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    47
    *x = (*env)->GetFloatField(env, pt, sunFontIDs.xFID);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    48
    *y = (*env)->GetFloatField(env, pt, sunFontIDs.yFID);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    49
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    50
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    51
static void putFloat(JNIEnv* env, jobject pt, jfloat x, jfloat y) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    52
    (*env)->SetFloatField(env, pt, sunFontIDs.xFID, x);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    53
    (*env)->SetFloatField(env, pt, sunFontIDs.yFID, y);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    54
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    55
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    56
static int init_JNI_IDs(JNIEnv *env) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    57
    if (jniInited) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    58
        return jniInited;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    59
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    60
    CHECK_NULL_RETURN(gvdClass = (*env)->FindClass(env, gvdClassName), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    61
    CHECK_NULL_RETURN(gvdClass = (jclass)(*env)->NewGlobalRef(env, gvdClass), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    62
    CHECK_NULL_RETURN(gvdCountFID = (*env)->GetFieldID(env, gvdClass, "_count", "I"), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    63
    CHECK_NULL_RETURN(gvdFlagsFID = (*env)->GetFieldID(env, gvdClass, "_flags", "I"), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    64
    CHECK_NULL_RETURN(gvdGlyphsFID = (*env)->GetFieldID(env, gvdClass, "_glyphs", "[I"), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    65
    CHECK_NULL_RETURN(gvdPositionsFID = (*env)->GetFieldID(env, gvdClass, "_positions", "[F"), 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    66
    CHECK_NULL_RETURN(gvdIndicesFID = (*env)->GetFieldID(env, gvdClass, "_indices", "[I"), 0);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    67
    CHECK_NULL_RETURN(gvdGrowMID = (*env)->GetMethodID(env, gvdClass, "grow", "()V"), 0);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    68
    jniInited = 1;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    69
    return jniInited;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    70
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    71
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    72
// gmask is the composite font slot mask
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    73
// baseindex is to be added to the character (code point) index.
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    74
jboolean storeGVData(JNIEnv* env,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    75
                     jobject gvdata, jint slot,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    76
                     jint baseIndex, int offset, jobject startPt,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    77
                     int charCount, int glyphCount, hb_glyph_info_t *glyphInfo,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    78
                     hb_glyph_position_t *glyphPos, float devScale) {
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    79
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    80
    int i, needToGrow;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    81
    float x=0, y=0;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    82
    float startX, startY, advX, advY;
41003
054df19db18c 8165345: JDK macro definition re-defined by MacOS core framework
prr
parents: 40992
diff changeset
    83
    float scale = 1.0f / HBFloatToFixedScale / devScale;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    84
    unsigned int* glyphs;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    85
    float* positions;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    86
    int initialCount, glyphArrayLen, posArrayLen, maxGlyphs, storeadv, maxStore;
34813
b3a2fa246c32 8144858: HBShaper.c does not compiler with VS2010
prr
parents: 34414
diff changeset
    87
    unsigned int* indices;
b3a2fa246c32 8144858: HBShaper.c does not compiler with VS2010
prr
parents: 34414
diff changeset
    88
    jarray glyphArray, posArray, inxArray;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    89
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    90
    if (!init_JNI_IDs(env)) {
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    91
        return JNI_FALSE;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    92
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
    93
34813
b3a2fa246c32 8144858: HBShaper.c does not compiler with VS2010
prr
parents: 34414
diff changeset
    94
    initialCount = (*env)->GetIntField(env, gvdata, gvdCountFID);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    95
    do {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    96
        glyphArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdGlyphsFID);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    97
        posArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdPositionsFID);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    98
        inxArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdIndicesFID);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
    99
        if (glyphArray == NULL || posArray == NULL || inxArray == NULL) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   100
            JNU_ThrowArrayIndexOutOfBoundsException(env, "");
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   101
            return JNI_FALSE;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   102
        }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   103
        glyphArrayLen = (*env)->GetArrayLength(env, glyphArray);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   104
        posArrayLen = (*env)->GetArrayLength(env, posArray);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   105
        maxGlyphs = (charCount > glyphCount) ? charCount : glyphCount;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   106
        maxStore = maxGlyphs + initialCount;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   107
        needToGrow = (maxStore > glyphArrayLen) ||
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   108
                     (maxStore * 2 + 2 >  posArrayLen);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   109
        if (needToGrow) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   110
            (*env)->CallVoidMethod(env, gvdata, gvdGrowMID);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   111
            if ((*env)->ExceptionCheck(env)) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   112
                return JNI_FALSE;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   113
            }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   114
        }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   115
    } while (needToGrow);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   116
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   117
    getFloat(env, startPt, &startX, &startY);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   118
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   119
    glyphs =
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   120
        (unsigned int*)(*env)->GetPrimitiveArrayCritical(env, glyphArray, NULL);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   121
    if (glyphs == NULL) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   122
        return JNI_FALSE;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   123
    }
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   124
    positions = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   125
    if (positions == NULL) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   126
        (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   127
        return JNI_FALSE;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   128
    }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   129
    indices =
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   130
        (unsigned int*)(*env)->GetPrimitiveArrayCritical(env, inxArray, NULL);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   131
    if (indices == NULL) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   132
        (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   133
        (*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, 0);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   134
        return JNI_FALSE;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   135
    }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   136
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   137
    for (i = 0; i < glyphCount; i++) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   138
        int storei = i + initialCount;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   139
        int cluster = glyphInfo[i].cluster - offset;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   140
        indices[storei] = baseIndex + cluster;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   141
        glyphs[storei] = (unsigned int)(glyphInfo[i].codepoint | slot);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   142
        positions[storei*2] = startX + x + glyphPos[i].x_offset * scale;
42711
1a4a75c37134 8168759: Incorrect vertical positioning of diacritics
prr
parents: 41003
diff changeset
   143
        positions[(storei*2)+1] = startY + y - glyphPos[i].y_offset * scale;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   144
        x += glyphPos[i].x_advance * scale;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   145
        y += glyphPos[i].y_advance * scale;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   146
        storei++;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   147
    }
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   148
    storeadv = initialCount + glyphCount;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   149
    // The final slot in the positions array is important
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   150
    // because when the GlyphVector is created from this
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   151
    // data it determines the overall advance of the glyphvector
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   152
    // and this is used in positioning the next glyphvector
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   153
    // during rendering where text is broken into runs.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   154
    // We also need to report it back into "pt", so layout can
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   155
    // pass it back down for that next run in this code.
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   156
    advX = startX + x;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   157
    advY = startY + y;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   158
    positions[(storeadv*2)] = advX;
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   159
    positions[(storeadv*2)+1] = advY;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   160
    (*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   161
    (*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   162
    (*env)->ReleasePrimitiveArrayCritical(env, inxArray, indices, 0);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   163
    putFloat(env, startPt, advX, advY);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   164
    (*env)->SetIntField(env, gvdata, gvdCountFID, storeadv);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   165
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   166
    return JNI_TRUE;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   167
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   168
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   169
static float euclidianDistance(float a, float b)
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   170
{
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   171
    float root;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   172
    if (a < 0) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   173
        a = -a;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   174
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   175
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   176
    if (b < 0) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   177
        b = -b;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   178
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   179
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   180
    if (a == 0) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   181
        return b;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   182
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   183
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   184
    if (b == 0) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   185
        return a;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   186
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   187
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   188
    /* Do an initial approximation, in root */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   189
    root = a > b ? a + (b / 2) : b + (a / 2);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   190
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   191
    /* An unrolled Newton-Raphson iteration sequence */
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   192
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   193
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   194
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   195
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   196
    return root;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   197
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   198
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   199
JDKFontInfo*
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   200
     createJDKFontInfo(JNIEnv *env,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   201
                       jobject font2D,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   202
                       jobject fontStrike,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   203
                       jfloat ptSize,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   204
                       jlong pScaler,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   205
                       jlong pNativeFont,
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 42711
diff changeset
   206
                       jlong layoutTables,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   207
                       jfloatArray matrix,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   208
                       jboolean aat) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   209
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   210
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   211
    JDKFontInfo *fi = (JDKFontInfo*)malloc(sizeof(JDKFontInfo));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   212
    if (!fi) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   213
       return NULL;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   214
    }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   215
    fi->env = env; // this is valid only for the life of this JNI call.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   216
    fi->font2D = font2D;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   217
    fi->fontStrike = fontStrike;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   218
    fi->nativeFont = pNativeFont;
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 42711
diff changeset
   219
    fi->layoutTables = (TTLayoutTableCache*)layoutTables;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   220
    fi->aat = aat;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   221
    (*env)->GetFloatArrayRegion(env, matrix, 0, 4, fi->matrix);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   222
    fi->ptSize = ptSize;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   223
    fi->xPtSize = euclidianDistance(fi->matrix[0], fi->matrix[1]);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   224
    fi->yPtSize = euclidianDistance(fi->matrix[2], fi->matrix[3]);
40712
0ff80fba9c97 8145901: Printed content is overlapping.
prr
parents: 40155
diff changeset
   225
    if (!aat && (getenv("HB_NODEVTX") != NULL)) {
0ff80fba9c97 8145901: Printed content is overlapping.
prr
parents: 40155
diff changeset
   226
        fi->devScale = fi->xPtSize / fi->ptSize;
0ff80fba9c97 8145901: Printed content is overlapping.
prr
parents: 40155
diff changeset
   227
    } else {
0ff80fba9c97 8145901: Printed content is overlapping.
prr
parents: 40155
diff changeset
   228
        fi->devScale = 1.0f;
0ff80fba9c97 8145901: Printed content is overlapping.
prr
parents: 40155
diff changeset
   229
    }
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   230
    return fi;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   231
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   232
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   233
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   234
#define TYPO_KERN 0x00000001
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   235
#define TYPO_LIGA 0x00000002
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   236
#define TYPO_RTL  0x80000000
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   237
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   238
JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   239
    (JNIEnv *env, jclass cls,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   240
     jobject font2D,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   241
     jobject fontStrike,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   242
     jfloat ptSize,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   243
     jfloatArray matrix,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   244
     jlong pScaler,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   245
     jlong pNativeFont,
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 42711
diff changeset
   246
     jlong layoutTables,
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   247
     jboolean aat,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   248
     jcharArray text,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   249
     jobject gvdata,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   250
     jint script,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   251
     jint offset,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   252
     jint limit,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   253
     jint baseIndex,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   254
     jobject startPt,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   255
     jint flags,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   256
     jint slot) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   257
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   258
     hb_buffer_t *buffer;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   259
     hb_font_t* hbfont;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   260
     jchar  *chars;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   261
     jsize len;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   262
     int glyphCount;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   263
     hb_glyph_info_t *glyphInfo;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   264
     hb_glyph_position_t *glyphPos;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   265
     hb_direction_t direction = HB_DIRECTION_LTR;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   266
     hb_feature_t *features = NULL;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   267
     int featureCount = 0;
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   268
     char* kern = (flags & TYPO_KERN) ? "kern" : "-kern";
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   269
     char* liga = (flags & TYPO_LIGA) ? "liga" : "-liga";
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   270
     jboolean ret;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   271
     unsigned int buflen;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   272
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   273
     JDKFontInfo *jdkFontInfo =
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   274
         createJDKFontInfo(env, font2D, fontStrike, ptSize,
47188
0048f025c993 8186317: Cache font layout tables for use by harfbuzz
prr
parents: 42711
diff changeset
   275
                           pScaler, pNativeFont, layoutTables, matrix, aat);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   276
     if (!jdkFontInfo) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   277
        return JNI_FALSE;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   278
     }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   279
     jdkFontInfo->env = env; // this is valid only for the life of this JNI call.
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   280
     jdkFontInfo->font2D = font2D;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   281
     jdkFontInfo->fontStrike = fontStrike;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   282
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   283
     hbfont = hb_jdk_font_create(jdkFontInfo, NULL);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   284
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   285
     buffer = hb_buffer_create();
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   286
     hb_buffer_set_script(buffer, getHBScriptCode(script));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   287
     hb_buffer_set_language(buffer,
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   288
                            hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE));
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   289
     if ((flags & TYPO_RTL) != 0) {
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   290
         direction = HB_DIRECTION_RTL;
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   291
     }
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   292
     hb_buffer_set_direction(buffer, direction);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   293
     hb_buffer_set_cluster_level(buffer,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   294
                                 HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   295
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   296
     chars = (*env)->GetCharArrayElements(env, text, NULL);
40155
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   297
     if ((*env)->ExceptionCheck(env)) {
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   298
         hb_buffer_destroy(buffer);
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   299
         hb_font_destroy(hbfont);
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   300
         free((void*)jdkFontInfo);
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   301
         return JNI_FALSE;
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   302
     }
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   303
     len = (*env)->GetArrayLength(env, text);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   304
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   305
     hb_buffer_add_utf16(buffer, chars, len, offset, limit-offset);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   306
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   307
     features = calloc(2, sizeof(hb_feature_t));
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   308
     if (features) {
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   309
         hb_feature_from_string(kern, -1, &features[featureCount++]);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   310
         hb_feature_from_string(liga, -1, &features[featureCount++]);
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   311
     }
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   312
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   313
     hb_shape_full(hbfont, buffer, features, featureCount, 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   314
     glyphCount = hb_buffer_get_length(buffer);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   315
     glyphInfo = hb_buffer_get_glyph_infos(buffer, 0);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   316
     glyphPos = hb_buffer_get_glyph_positions(buffer, &buflen);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   317
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   318
     ret = storeGVData(env, gvdata, slot, baseIndex, offset, startPt,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   319
                       limit - offset, glyphCount, glyphInfo, glyphPos,
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   320
                       jdkFontInfo->devScale);
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   321
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   322
     hb_buffer_destroy (buffer);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   323
     hb_font_destroy(hbfont);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   324
     free((void*)jdkFontInfo);
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   325
     if (features != NULL) free(features);
40155
b909b3a9277c 8148477: Native memory leak in font layout subsystem
prr
parents: 34813
diff changeset
   326
     (*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT);
40992
788c9cca556f 8144015: [PIT] failures of text layout font tests
prr
parents: 40988
diff changeset
   327
     return ret;
34414
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   328
}
e496a8d8fc8a 8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff changeset
   329