author | erikj |
Mon, 01 Oct 2018 11:02:33 -0700 | |
branch | JEP-230-microbenchmarks-branch |
changeset 56912 | d434fc4d10aa |
parent 47216 | 71c04702a3d5 |
child 54590 | 98473958d49a |
permissions | -rw-r--r-- |
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 | 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 | 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 | 74 |
jboolean storeGVData(JNIEnv* env, |
75 |
jobject gvdata, jint slot, |
|
76 |
jint baseIndex, int offset, jobject startPt, |
|
77 |
int charCount, int glyphCount, hb_glyph_info_t *glyphInfo, |
|
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 | 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 | 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 | 86 |
int initialCount, glyphArrayLen, posArrayLen, maxGlyphs, storeadv, maxStore; |
34813 | 87 |
unsigned int* indices; |
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 | 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 | 94 |
initialCount = (*env)->GetIntField(env, gvdata, gvdCountFID); |
40992 | 95 |
do { |
96 |
glyphArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdGlyphsFID); |
|
97 |
posArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdPositionsFID); |
|
98 |
inxArray = (jarray)(*env)->GetObjectField(env, gvdata, gvdIndicesFID); |
|
99 |
if (glyphArray == NULL || posArray == NULL || inxArray == NULL) { |
|
100 |
JNU_ThrowArrayIndexOutOfBoundsException(env, ""); |
|
101 |
return JNI_FALSE; |
|
102 |
} |
|
103 |
glyphArrayLen = (*env)->GetArrayLength(env, glyphArray); |
|
104 |
posArrayLen = (*env)->GetArrayLength(env, posArray); |
|
105 |
maxGlyphs = (charCount > glyphCount) ? charCount : glyphCount; |
|
106 |
maxStore = maxGlyphs + initialCount; |
|
107 |
needToGrow = (maxStore > glyphArrayLen) || |
|
108 |
(maxStore * 2 + 2 > posArrayLen); |
|
109 |
if (needToGrow) { |
|
110 |
(*env)->CallVoidMethod(env, gvdata, gvdGrowMID); |
|
111 |
if ((*env)->ExceptionCheck(env)) { |
|
112 |
return JNI_FALSE; |
|
113 |
} |
|
114 |
} |
|
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 | 121 |
if (glyphs == NULL) { |
122 |
return JNI_FALSE; |
|
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 | 125 |
if (positions == NULL) { |
126 |
(*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0); |
|
127 |
return JNI_FALSE; |
|
128 |
} |
|
129 |
indices = |
|
130 |
(unsigned int*)(*env)->GetPrimitiveArrayCritical(env, inxArray, NULL); |
|
131 |
if (indices == NULL) { |
|
132 |
(*env)->ReleasePrimitiveArrayCritical(env, glyphArray, glyphs, 0); |
|
133 |
(*env)->ReleasePrimitiveArrayCritical(env, posArray, positions, 0); |
|
134 |
return JNI_FALSE; |
|
135 |
} |
|
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 | 139 |
int cluster = glyphInfo[i].cluster - offset; |
140 |
indices[storei] = baseIndex + cluster; |
|
141 |
glyphs[storei] = (unsigned int)(glyphInfo[i].codepoint | slot); |
|
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 | 146 |
storei++; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
147 |
} |
40992 | 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 | 156 |
advX = startX + x; |
157 |
advY = startY + y; |
|
158 |
positions[(storeadv*2)] = advX; |
|
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 | 163 |
putFloat(env, startPt, advX, advY); |
164 |
(*env)->SetIntField(env, gvdata, gvdCountFID, storeadv); |
|
165 |
||
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 | 225 |
if (!aat && (getenv("HB_NODEVTX") != NULL)) { |
226 |
fi->devScale = fi->xPtSize / fi->ptSize; |
|
227 |
} else { |
|
228 |
fi->devScale = 1.0f; |
|
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 | 234 |
#define TYPO_KERN 0x00000001 |
235 |
#define TYPO_LIGA 0x00000002 |
|
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 | 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 | 268 |
char* kern = (flags & TYPO_KERN) ? "kern" : "-kern"; |
269 |
char* liga = (flags & TYPO_LIGA) ? "liga" : "-liga"; |
|
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 | 293 |
hb_buffer_set_cluster_level(buffer, |
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 | 297 |
if ((*env)->ExceptionCheck(env)) { |
298 |
hb_buffer_destroy(buffer); |
|
299 |
hb_font_destroy(hbfont); |
|
300 |
free((void*)jdkFontInfo); |
|
301 |
return JNI_FALSE; |
|
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 | 307 |
features = calloc(2, sizeof(hb_feature_t)); |
308 |
if (features) { |
|
309 |
hb_feature_from_string(kern, -1, &features[featureCount++]); |
|
310 |
hb_feature_from_string(liga, -1, &features[featureCount++]); |
|
311 |
} |
|
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 | 318 |
ret = storeGVData(env, gvdata, slot, baseIndex, offset, startPt, |
319 |
limit - offset, glyphCount, glyphInfo, glyphPos, |
|
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 | 326 |
(*env)->ReleaseCharArrayElements(env, text, chars, JNI_ABORT); |
40992 | 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 |