author | itakiguchi |
Wed, 05 Dec 2018 12:59:50 -0800 | |
changeset 52966 | 7ed5edf6ba0c |
parent 52838 | df92f1126c58 |
child 53454 | ba547b9b4996 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20424
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include "jni.h" |
|
27 |
#include "jni_util.h" |
|
28 |
#include "jlong.h" |
|
29 |
#include "sunfontids.h" |
|
30 |
#include "sun_font_FreetypeFontScaler.h" |
|
31 |
||
32 |
#include<stdlib.h> |
|
33 |
#include <math.h> |
|
34 |
#include "ft2build.h" |
|
35 |
#include FT_FREETYPE_H |
|
36 |
#include FT_GLYPH_H |
|
37 |
#include FT_BBOX_H |
|
38 |
#include FT_SIZES_H |
|
39 |
#include FT_OUTLINE_H |
|
40 |
#include FT_SYNTHESIS_H |
|
52258
02e4b0ab0f97
8212071: Need to set the FreeType LCD Filter to reduce fringing.
prr
parents:
51932
diff
changeset
|
41 |
#include FT_LCD_FILTER_H |
2 | 42 |
|
43 |
#include "fontscaler.h" |
|
44 |
||
45 |
#define ftFixed1 (FT_Fixed) (1 << 16) |
|
46 |
#define FloatToFTFixed(f) (FT_Fixed)((f) * (float)(ftFixed1)) |
|
47 |
#define FTFixedToFloat(x) ((x) / (float)(ftFixed1)) |
|
48 |
#define FT26Dot6ToFloat(x) ((x) / ((float) (1<<6))) |
|
50346
9e530b150333
8203485: [freetype] text rotated on 180 degrees is too narrow
bae
parents:
47216
diff
changeset
|
49 |
#define FT26Dot6ToInt(x) (((int)(x)) >> 6) |
2 | 50 |
|
51 |
typedef struct { |
|
52 |
/* Important note: |
|
53 |
JNI forbids sharing same env between different threads. |
|
54 |
We are safe, because pointer is overwritten every time we get into |
|
55 |
JNI call (see setupFTContext). |
|
56 |
||
57 |
Pointer is used by font data reading callbacks |
|
58 |
such as ReadTTFontFileFunc. |
|
59 |
||
60 |
NB: We may consider switching to JNI_GetEnv. */ |
|
61 |
JNIEnv* env; |
|
62 |
FT_Library library; |
|
63 |
FT_Face face; |
|
33250
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
64 |
FT_Stream faceStream; |
2 | 65 |
jobject font2D; |
66 |
jobject directBuffer; |
|
67 |
||
68 |
unsigned char* fontData; |
|
69 |
unsigned fontDataOffset; |
|
70 |
unsigned fontDataLength; |
|
71 |
unsigned fileSize; |
|
72 |
TTLayoutTableCache* layoutTables; |
|
73 |
} FTScalerInfo; |
|
74 |
||
75 |
typedef struct FTScalerContext { |
|
76 |
FT_Matrix transform; /* glyph transform, including device transform */ |
|
77 |
jboolean useSbits; /* sbit usage enabled? */ |
|
78 |
jint aaType; /* antialiasing mode (off/on/grey/lcd) */ |
|
79 |
jint fmType; /* fractional metrics - on/off */ |
|
80 |
jboolean doBold; /* perform algorithmic bolding? */ |
|
81 |
jboolean doItalize; /* perform algorithmic italicizing? */ |
|
82 |
int renderFlags; /* configuration specific to particular engine */ |
|
83 |
int pathType; |
|
84 |
int ptsz; /* size in points */ |
|
85 |
} FTScalerContext; |
|
86 |
||
87 |
#ifdef DEBUG |
|
88 |
/* These are referenced in the freetype sources if DEBUG macro is defined. |
|
89 |
To simplify work with debuging version of freetype we define |
|
90 |
them here. */ |
|
91 |
int z_verbose; |
|
92 |
void z_error(char *s) {} |
|
93 |
#endif |
|
94 |
||
95 |
/**************** Error handling utilities *****************/ |
|
96 |
||
97 |
static jmethodID invalidateScalerMID; |
|
98 |
||
99 |
JNIEXPORT void JNICALL |
|
100 |
Java_sun_font_FreetypeFontScaler_initIDs( |
|
101 |
JNIEnv *env, jobject scaler, jclass FFSClass) { |
|
102 |
invalidateScalerMID = |
|
103 |
(*env)->GetMethodID(env, FFSClass, "invalidateScaler", "()V"); |
|
104 |
} |
|
105 |
||
106 |
static void freeNativeResources(JNIEnv *env, FTScalerInfo* scalerInfo) { |
|
4243 | 107 |
|
2 | 108 |
if (scalerInfo == NULL) |
109 |
return; |
|
110 |
||
33250
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
111 |
// FT_Done_Face always closes the stream, but only frees the memory |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
112 |
// of the data structure if it was internally allocated by FT. |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
113 |
// We hold on to a pointer to the stream structure if we provide it |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
114 |
// ourselves, so that we can free it here. |
2 | 115 |
FT_Done_Face(scalerInfo->face); |
116 |
FT_Done_FreeType(scalerInfo->library); |
|
117 |
||
118 |
if (scalerInfo->directBuffer != NULL) { |
|
119 |
(*env)->DeleteGlobalRef(env, scalerInfo->directBuffer); |
|
120 |
} |
|
121 |
||
122 |
if (scalerInfo->fontData != NULL) { |
|
123 |
free(scalerInfo->fontData); |
|
124 |
} |
|
125 |
||
33250
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
126 |
if (scalerInfo->faceStream != NULL) { |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
127 |
free(scalerInfo->faceStream); |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
128 |
} |
2 | 129 |
free(scalerInfo); |
130 |
} |
|
131 |
||
132 |
/* invalidates state of java scaler object */ |
|
133 |
static void invalidateJavaScaler(JNIEnv *env, |
|
134 |
jobject scaler, |
|
135 |
FTScalerInfo* scalerInfo) { |
|
136 |
freeNativeResources(env, scalerInfo); |
|
137 |
(*env)->CallVoidMethod(env, scaler, invalidateScalerMID); |
|
138 |
} |
|
139 |
||
140 |
/******************* I/O handlers ***************************/ |
|
141 |
||
142 |
#define FILEDATACACHESIZE 1024 |
|
143 |
||
144 |
static unsigned long ReadTTFontFileFunc(FT_Stream stream, |
|
145 |
unsigned long offset, |
|
146 |
unsigned char* destBuffer, |
|
147 |
unsigned long numBytes) |
|
148 |
{ |
|
149 |
FTScalerInfo *scalerInfo = (FTScalerInfo *) stream->pathname.pointer; |
|
150 |
JNIEnv* env = scalerInfo->env; |
|
151 |
jobject bBuffer; |
|
152 |
int bread = 0; |
|
153 |
||
154 |
if (numBytes == 0) return 0; |
|
155 |
||
156 |
/* Large reads will bypass the cache and data copying */ |
|
157 |
if (numBytes > FILEDATACACHESIZE) { |
|
158 |
bBuffer = (*env)->NewDirectByteBuffer(env, destBuffer, numBytes); |
|
159 |
if (bBuffer != NULL) { |
|
25528 | 160 |
bread = (*env)->CallIntMethod(env, |
161 |
scalerInfo->font2D, |
|
162 |
sunFontIDs.ttReadBlockMID, |
|
163 |
bBuffer, offset, numBytes); |
|
2 | 164 |
return bread; |
165 |
} else { |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27053
diff
changeset
|
166 |
/* We probably hit bug 4845371. For reasons that |
2 | 167 |
* are currently unclear, the call stacks after the initial |
168 |
* createScaler call that read large amounts of data seem to |
|
169 |
* be OK and can create the byte buffer above, but this code |
|
170 |
* is here just in case. |
|
171 |
* 4845371 is fixed now so I don't expect this code path to |
|
172 |
* ever get called but its harmless to leave it here on the |
|
173 |
* small chance its needed. |
|
174 |
*/ |
|
175 |
jbyteArray byteArray = (jbyteArray) |
|
176 |
(*env)->CallObjectMethod(env, scalerInfo->font2D, |
|
177 |
sunFontIDs.ttReadBytesMID, |
|
178 |
offset, numBytes); |
|
179 |
(*env)->GetByteArrayRegion(env, byteArray, |
|
180 |
0, numBytes, (jbyte*)destBuffer); |
|
181 |
return numBytes; |
|
182 |
} |
|
183 |
} /* Do we have a cache hit? */ |
|
184 |
else if (scalerInfo->fontDataOffset <= offset && |
|
185 |
scalerInfo->fontDataOffset + scalerInfo->fontDataLength >= |
|
186 |
offset + numBytes) |
|
187 |
{ |
|
188 |
unsigned cacheOffset = offset - scalerInfo->fontDataOffset; |
|
189 |
||
190 |
memcpy(destBuffer, scalerInfo->fontData+(size_t)cacheOffset, numBytes); |
|
191 |
return numBytes; |
|
192 |
} else { |
|
193 |
/* Must fill the cache */ |
|
194 |
scalerInfo->fontDataOffset = offset; |
|
195 |
scalerInfo->fontDataLength = |
|
196 |
(offset + FILEDATACACHESIZE > scalerInfo->fileSize) ? |
|
197 |
scalerInfo->fileSize - offset : FILEDATACACHESIZE; |
|
198 |
bBuffer = scalerInfo->directBuffer; |
|
25528 | 199 |
bread = (*env)->CallIntMethod(env, scalerInfo->font2D, |
200 |
sunFontIDs.ttReadBlockMID, |
|
201 |
bBuffer, offset, |
|
202 |
scalerInfo->fontDataLength); |
|
2 | 203 |
memcpy(destBuffer, scalerInfo->fontData, numBytes); |
204 |
return numBytes; |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
/* |
|
209 |
* Class: sun_font_FreetypeFontScaler |
|
210 |
* Method: initNativeScaler |
|
211 |
* Signature: (Lsun/font/Font2D;IIZI)J |
|
212 |
*/ |
|
213 |
JNIEXPORT jlong JNICALL |
|
214 |
Java_sun_font_FreetypeFontScaler_initNativeScaler( |
|
215 |
JNIEnv *env, jobject scaler, jobject font2D, jint type, |
|
216 |
jint indexInCollection, jboolean supportsCJK, jint filesize) { |
|
217 |
FTScalerInfo* scalerInfo = NULL; |
|
218 |
FT_Open_Args ft_open_args; |
|
219 |
int error; |
|
220 |
jobject bBuffer; |
|
221 |
scalerInfo = (FTScalerInfo*) calloc(1, sizeof(FTScalerInfo)); |
|
222 |
||
223 |
if (scalerInfo == NULL) |
|
224 |
return 0; |
|
225 |
||
226 |
scalerInfo->env = env; |
|
227 |
scalerInfo->font2D = font2D; |
|
228 |
scalerInfo->fontDataOffset = 0; |
|
229 |
scalerInfo->fontDataLength = 0; |
|
230 |
scalerInfo->fileSize = filesize; |
|
231 |
||
232 |
/* |
|
233 |
We can consider sharing freetype library between different |
|
234 |
scalers. However, Freetype docs suggest to use different libraries |
|
235 |
for different threads. Also, our architecture implies that single |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27053
diff
changeset
|
236 |
FontScaler object is shared for different sizes/transforms/styles |
2 | 237 |
of the same font. |
238 |
||
239 |
On other hand these methods can not be concurrently executed |
|
240 |
becaused they are "synchronized" in java. |
|
241 |
*/ |
|
242 |
error = FT_Init_FreeType(&scalerInfo->library); |
|
243 |
if (error) { |
|
244 |
free(scalerInfo); |
|
245 |
return 0; |
|
246 |
} |
|
247 |
||
248 |
#define TYPE1_FROM_JAVA 2 |
|
249 |
||
250 |
error = 1; /* triggers memory freeing unless we clear it */ |
|
251 |
if (type == TYPE1_FROM_JAVA) { /* TYPE1 */ |
|
252 |
scalerInfo->fontData = (unsigned char*) malloc(filesize); |
|
253 |
scalerInfo->directBuffer = NULL; |
|
254 |
scalerInfo->layoutTables = NULL; |
|
255 |
scalerInfo->fontDataLength = filesize; |
|
256 |
||
257 |
if (scalerInfo->fontData != NULL) { |
|
258 |
bBuffer = (*env)->NewDirectByteBuffer(env, |
|
259 |
scalerInfo->fontData, |
|
260 |
scalerInfo->fontDataLength); |
|
261 |
if (bBuffer != NULL) { |
|
34786 | 262 |
(*env)->CallVoidMethod(env, font2D, |
2 | 263 |
sunFontIDs.readFileMID, bBuffer); |
264 |
||
265 |
error = FT_New_Memory_Face(scalerInfo->library, |
|
266 |
scalerInfo->fontData, |
|
267 |
scalerInfo->fontDataLength, |
|
268 |
indexInCollection, |
|
269 |
&scalerInfo->face); |
|
270 |
} |
|
271 |
} |
|
272 |
} else { /* Truetype */ |
|
273 |
scalerInfo->fontData = (unsigned char*) malloc(FILEDATACACHESIZE); |
|
274 |
||
20424
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
275 |
if (scalerInfo->fontData != NULL) { |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
276 |
FT_Stream ftstream = (FT_Stream) calloc(1, sizeof(FT_StreamRec)); |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
277 |
if (ftstream != NULL) { |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
278 |
scalerInfo->directBuffer = (*env)->NewDirectByteBuffer(env, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
279 |
scalerInfo->fontData, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
280 |
FILEDATACACHESIZE); |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
281 |
if (scalerInfo->directBuffer != NULL) { |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
282 |
scalerInfo->directBuffer = (*env)->NewGlobalRef(env, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
283 |
scalerInfo->directBuffer); |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
284 |
ftstream->base = NULL; |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
285 |
ftstream->size = filesize; |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
286 |
ftstream->pos = 0; |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
287 |
ftstream->read = (FT_Stream_IoFunc) ReadTTFontFileFunc; |
30494
a245f4430b4c
8078654: CloseTTFontFileFunc callback should be removed
adinn
parents:
28059
diff
changeset
|
288 |
ftstream->close = NULL; |
20424
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
289 |
ftstream->pathname.pointer = (void *) scalerInfo; |
2 | 290 |
|
20424
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
291 |
memset(&ft_open_args, 0, sizeof(FT_Open_Args)); |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
292 |
ft_open_args.flags = FT_OPEN_STREAM; |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
293 |
ft_open_args.stream = ftstream; |
2 | 294 |
|
20424
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
295 |
error = FT_Open_Face(scalerInfo->library, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
296 |
&ft_open_args, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
297 |
indexInCollection, |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
298 |
&scalerInfo->face); |
33250
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
299 |
if (!error) { |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
300 |
scalerInfo->faceStream = ftstream; |
047311011afe
8132985: Crash in freetypescaler.c due to double free
psadhukhan
parents:
30494
diff
changeset
|
301 |
} |
20424
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
302 |
} |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
303 |
if (error || scalerInfo->directBuffer == NULL) { |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
304 |
free(ftstream); |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
305 |
} |
eace1945b974
8025664: [parfait] warnings from b62 for jdk.src.share.native.sun.font
jchen
parents:
20414
diff
changeset
|
306 |
} |
2 | 307 |
} |
308 |
} |
|
309 |
||
310 |
if (error) { |
|
311 |
FT_Done_FreeType(scalerInfo->library); |
|
312 |
if (scalerInfo->directBuffer != NULL) { |
|
313 |
(*env)->DeleteGlobalRef(env, scalerInfo->directBuffer); |
|
314 |
} |
|
315 |
if (scalerInfo->fontData != NULL) |
|
316 |
free(scalerInfo->fontData); |
|
317 |
free(scalerInfo); |
|
318 |
return 0; |
|
319 |
} |
|
320 |
||
321 |
return ptr_to_jlong(scalerInfo); |
|
322 |
} |
|
323 |
||
324 |
static double euclidianDistance(double a, double b) { |
|
325 |
if (a < 0) a=-a; |
|
326 |
if (b < 0) b=-b; |
|
327 |
||
328 |
if (a == 0) return b; |
|
329 |
if (b == 0) return a; |
|
330 |
||
331 |
return sqrt(a*a+b*b); |
|
332 |
} |
|
333 |
||
334 |
JNIEXPORT jlong JNICALL |
|
335 |
Java_sun_font_FreetypeFontScaler_createScalerContextNative( |
|
336 |
JNIEnv *env, jobject scaler, jlong pScaler, jdoubleArray matrix, |
|
9761
a9315b1a26e9
7049874: OpenJDK Build breakage fix: freetypescaler.c needs to match updated signature
prr
parents:
7668
diff
changeset
|
337 |
jint aa, jint fm, jfloat boldness, jfloat italic) { |
2 | 338 |
double dmat[4], ptsz; |
339 |
FTScalerContext *context = |
|
340 |
(FTScalerContext*) calloc(1, sizeof(FTScalerContext)); |
|
341 |
FTScalerInfo *scalerInfo = |
|
342 |
(FTScalerInfo*) jlong_to_ptr(pScaler); |
|
343 |
||
344 |
if (context == NULL) { |
|
345 |
invalidateJavaScaler(env, scaler, NULL); |
|
346 |
return (jlong) 0; |
|
347 |
} |
|
348 |
(*env)->GetDoubleArrayRegion(env, matrix, 0, 4, dmat); |
|
349 |
ptsz = euclidianDistance(dmat[2], dmat[3]); //i.e. y-size |
|
350 |
if (ptsz < 1.0) { |
|
351 |
//text can not be smaller than 1 point |
|
352 |
ptsz = 1.0; |
|
353 |
} |
|
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
354 |
context->ptsz = (int)(ptsz * 64); |
2 | 355 |
context->transform.xx = FloatToFTFixed((float)dmat[0]/ptsz); |
356 |
context->transform.yx = -FloatToFTFixed((float)dmat[1]/ptsz); |
|
357 |
context->transform.xy = -FloatToFTFixed((float)dmat[2]/ptsz); |
|
358 |
context->transform.yy = FloatToFTFixed((float)dmat[3]/ptsz); |
|
359 |
context->aaType = aa; |
|
360 |
context->fmType = fm; |
|
361 |
||
362 |
/* If using algorithmic styling, the base values are |
|
363 |
* boldness = 1.0, italic = 0.0. |
|
364 |
*/ |
|
365 |
context->doBold = (boldness != 1.0); |
|
366 |
context->doItalize = (italic != 0); |
|
367 |
||
50658
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
368 |
/* freetype is very keen to use embedded bitmaps, even if it knows |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
369 |
* there is a rotation or you asked for antialiasing. |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
370 |
* In the rendering path we will check useSBits and disable |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
371 |
* bitmaps unless it is set. And here we set it only if none |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
372 |
* of the conditions invalidate using it. |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
373 |
* Note that we allow embedded bitmaps for the LCD case. |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
374 |
*/ |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
375 |
if ((aa != TEXT_AA_ON) && (fm != TEXT_FM_ON) && |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
376 |
!context->doBold && !context->doItalize && |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
377 |
(context->transform.yx == 0) && (context->transform.xy == 0)) |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
378 |
{ |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
379 |
context->useSbits = 1; |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
380 |
} |
2 | 381 |
return ptr_to_jlong(context); |
382 |
} |
|
383 |
||
384 |
static int setupFTContext(JNIEnv *env, |
|
385 |
jobject font2D, |
|
386 |
FTScalerInfo *scalerInfo, |
|
387 |
FTScalerContext *context) { |
|
388 |
int errCode = 0; |
|
389 |
||
390 |
scalerInfo->env = env; |
|
391 |
scalerInfo->font2D = font2D; |
|
392 |
||
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
393 |
if (context != NULL) { |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
394 |
FT_Set_Transform(scalerInfo->face, &context->transform, NULL); |
2 | 395 |
|
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
396 |
errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72); |
2 | 397 |
|
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
398 |
if (errCode == 0) { |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
399 |
errCode = FT_Activate_Size(scalerInfo->face->size); |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
400 |
} |
52258
02e4b0ab0f97
8212071: Need to set the FreeType LCD Filter to reduce fringing.
prr
parents:
51932
diff
changeset
|
401 |
|
02e4b0ab0f97
8212071: Need to set the FreeType LCD Filter to reduce fringing.
prr
parents:
51932
diff
changeset
|
402 |
FT_Library_SetLcdFilter(scalerInfo->library, FT_LCD_FILTER_DEFAULT); |
2 | 403 |
} |
404 |
||
405 |
return errCode; |
|
406 |
} |
|
407 |
||
408 |
/* ftsynth.c uses (0x10000, 0x06000, 0x0, 0x10000) matrix to get oblique |
|
409 |
outline. Therefore x coordinate will change by 0x06000*y. |
|
410 |
Note that y coordinate does not change. */ |
|
411 |
#define OBLIQUE_MODIFIER(y) (context->doItalize ? ((y)*6/16) : 0) |
|
412 |
||
413 |
/* |
|
414 |
* Class: sun_font_FreetypeFontScaler |
|
415 |
* Method: getFontMetricsNative |
|
416 |
* Signature: (Lsun/font/Font2D;J)Lsun/font/StrikeMetrics; |
|
417 |
*/ |
|
418 |
JNIEXPORT jobject JNICALL |
|
419 |
Java_sun_font_FreetypeFontScaler_getFontMetricsNative( |
|
420 |
JNIEnv *env, jobject scaler, jobject font2D, |
|
421 |
jlong pScalerContext, jlong pScaler) { |
|
422 |
||
423 |
jobject metrics; |
|
424 |
jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my; |
|
425 |
jfloat f0 = 0.0; |
|
426 |
FTScalerContext *context = |
|
427 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
428 |
FTScalerInfo *scalerInfo = |
|
429 |
(FTScalerInfo*) jlong_to_ptr(pScaler); |
|
430 |
||
431 |
int errCode; |
|
432 |
||
433 |
if (isNullScalerContext(context) || scalerInfo == NULL) { |
|
434 |
return (*env)->NewObject(env, |
|
435 |
sunFontIDs.strikeMetricsClass, |
|
436 |
sunFontIDs.strikeMetricsCtr, |
|
437 |
f0, f0, f0, f0, f0, f0, f0, f0, f0, f0); |
|
438 |
} |
|
439 |
||
440 |
errCode = setupFTContext(env, font2D, scalerInfo, context); |
|
441 |
||
442 |
if (errCode) { |
|
443 |
metrics = (*env)->NewObject(env, |
|
444 |
sunFontIDs.strikeMetricsClass, |
|
445 |
sunFontIDs.strikeMetricsCtr, |
|
446 |
f0, f0, f0, f0, f0, f0, f0, f0, f0, f0); |
|
447 |
invalidateJavaScaler(env, scaler, scalerInfo); |
|
448 |
return metrics; |
|
449 |
} |
|
450 |
||
451 |
/* This is ugly and has to be reworked. |
|
452 |
Freetype provide means to add style to glyph but |
|
453 |
it seems there is no way to adjust metrics accordingly. |
|
454 |
||
455 |
So, we have to do adust them explicitly and stay consistent with what |
|
456 |
freetype does to outlines. */ |
|
457 |
||
458 |
||
459 |
/**** Note: only some metrics are affected by styling ***/ |
|
460 |
||
27053
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
461 |
/* See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657854 */ |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
462 |
#define FT_MulFixFloatShift6(a, b) (((float) (a)) * ((float) (b)) / 65536.0 / 64.0) |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
463 |
|
52838
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
464 |
#define contextAwareMetricsX(x, y) \ |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
465 |
(FTFixedToFloat(context->transform.xx) * (x) - \ |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
466 |
FTFixedToFloat(context->transform.xy) * (y)) |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
467 |
|
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
468 |
#define contextAwareMetricsY(x, y) \ |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
469 |
(-FTFixedToFloat(context->transform.yx) * (x) + \ |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
470 |
FTFixedToFloat(context->transform.yy) * (y)) |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
471 |
|
27053
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
472 |
/* |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
473 |
* See FreeType source code: src/base/ftobjs.c ft_recompute_scaled_metrics() |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
474 |
* http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1659 |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
475 |
*/ |
2 | 476 |
/* ascent */ |
477 |
ax = 0; |
|
27053
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
478 |
ay = -(jfloat) (FT_MulFixFloatShift6( |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
479 |
((jlong) scalerInfo->face->ascender), |
5754
ef19a58b3c42
6961732: FontMetrics.getLeading() may be negative in freetype-based OpenJDK builds.
neugens
parents:
5580
diff
changeset
|
480 |
(jlong) scalerInfo->face->size->metrics.y_scale)); |
2 | 481 |
/* descent */ |
482 |
dx = 0; |
|
27053
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
483 |
dy = -(jfloat) (FT_MulFixFloatShift6( |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
484 |
((jlong) scalerInfo->face->descender), |
5754
ef19a58b3c42
6961732: FontMetrics.getLeading() may be negative in freetype-based OpenJDK builds.
neugens
parents:
5580
diff
changeset
|
485 |
(jlong) scalerInfo->face->size->metrics.y_scale)); |
2 | 486 |
/* baseline */ |
487 |
bx = by = 0; |
|
488 |
||
489 |
/* leading */ |
|
490 |
lx = 0; |
|
27053
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
491 |
ly = (jfloat) (FT_MulFixFloatShift6( |
b8def728da69
8017773: OpenJDK7 returns incorrect TrueType font metrics
ysuenaga
parents:
26617
diff
changeset
|
492 |
(jlong) scalerInfo->face->height, |
5754
ef19a58b3c42
6961732: FontMetrics.getLeading() may be negative in freetype-based OpenJDK builds.
neugens
parents:
5580
diff
changeset
|
493 |
(jlong) scalerInfo->face->size->metrics.y_scale)) |
ef19a58b3c42
6961732: FontMetrics.getLeading() may be negative in freetype-based OpenJDK builds.
neugens
parents:
5580
diff
changeset
|
494 |
+ ay - dy; |
2 | 495 |
/* max advance */ |
496 |
mx = (jfloat) FT26Dot6ToFloat( |
|
497 |
scalerInfo->face->size->metrics.max_advance + |
|
498 |
OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height)); |
|
499 |
my = 0; |
|
500 |
||
501 |
metrics = (*env)->NewObject(env, |
|
52838
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
502 |
sunFontIDs.strikeMetricsClass, |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
503 |
sunFontIDs.strikeMetricsCtr, |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
504 |
contextAwareMetricsX(ax, ay), contextAwareMetricsY(ax, ay), |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
505 |
contextAwareMetricsX(dx, dy), contextAwareMetricsY(dx, dy), |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
506 |
bx, by, |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
507 |
contextAwareMetricsX(lx, ly), contextAwareMetricsY(lx, ly), |
df92f1126c58
8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
bae
parents:
52258
diff
changeset
|
508 |
contextAwareMetricsX(mx, my), contextAwareMetricsY(mx, my)); |
2 | 509 |
|
510 |
return metrics; |
|
511 |
} |
|
512 |
||
513 |
/* |
|
514 |
* Class: sun_font_FreetypeFontScaler |
|
515 |
* Method: getGlyphAdvanceNative |
|
516 |
* Signature: (Lsun/font/Font2D;JI)F |
|
517 |
*/ |
|
518 |
JNIEXPORT jfloat JNICALL |
|
519 |
Java_sun_font_FreetypeFontScaler_getGlyphAdvanceNative( |
|
520 |
JNIEnv *env, jobject scaler, jobject font2D, |
|
521 |
jlong pScalerContext, jlong pScaler, jint glyphCode) { |
|
522 |
||
523 |
/* This method is rarely used because requests for metrics are usually |
|
524 |
coupled with request for bitmap and to large extend work can be reused |
|
525 |
(to find out metrics we need to hint glyph). |
|
526 |
So, we typically go through getGlyphImage code path. |
|
527 |
||
528 |
For initial freetype implementation we delegate |
|
529 |
all work to getGlyphImage but drop result image. |
|
530 |
This is waste of work related to scan conversion and conversion from |
|
531 |
freetype format to our format but for now this seems to be ok. |
|
532 |
||
533 |
NB: investigate performance benefits of refactoring code |
|
534 |
to avoid unnecesary work with bitmaps. */ |
|
535 |
||
536 |
GlyphInfo *info; |
|
537 |
jfloat advance; |
|
538 |
jlong image; |
|
539 |
||
540 |
image = Java_sun_font_FreetypeFontScaler_getGlyphImageNative( |
|
541 |
env, scaler, font2D, pScalerContext, pScaler, glyphCode); |
|
542 |
info = (GlyphInfo*) jlong_to_ptr(image); |
|
543 |
||
544 |
advance = info->advanceX; |
|
545 |
||
546 |
free(info); |
|
547 |
||
548 |
return advance; |
|
549 |
} |
|
550 |
||
551 |
/* |
|
552 |
* Class: sun_font_FreetypeFontScaler |
|
553 |
* Method: getGlyphMetricsNative |
|
554 |
* Signature: (Lsun/font/Font2D;JILjava/awt/geom/Point2D/Float;)V |
|
555 |
*/ |
|
556 |
JNIEXPORT void JNICALL |
|
557 |
Java_sun_font_FreetypeFontScaler_getGlyphMetricsNative( |
|
558 |
JNIEnv *env, jobject scaler, jobject font2D, jlong pScalerContext, |
|
559 |
jlong pScaler, jint glyphCode, jobject metrics) { |
|
560 |
||
561 |
/* As initial implementation we delegate all work to getGlyphImage |
|
562 |
but drop result image. This is clearly waste of resorces. |
|
563 |
||
564 |
TODO: investigate performance benefits of refactoring code |
|
565 |
by avoiding bitmap generation and conversion from FT |
|
566 |
bitmap format. */ |
|
567 |
GlyphInfo *info; |
|
568 |
||
569 |
jlong image = Java_sun_font_FreetypeFontScaler_getGlyphImageNative( |
|
570 |
env, scaler, font2D, |
|
571 |
pScalerContext, pScaler, glyphCode); |
|
572 |
info = (GlyphInfo*) jlong_to_ptr(image); |
|
573 |
||
574 |
(*env)->SetFloatField(env, metrics, sunFontIDs.xFID, info->advanceX); |
|
575 |
(*env)->SetFloatField(env, metrics, sunFontIDs.yFID, info->advanceY); |
|
576 |
||
577 |
free(info); |
|
578 |
} |
|
579 |
||
580 |
||
581 |
static GlyphInfo* getNullGlyphImage() { |
|
582 |
GlyphInfo *glyphInfo = (GlyphInfo*) calloc(1, sizeof(GlyphInfo)); |
|
583 |
return glyphInfo; |
|
584 |
} |
|
585 |
||
586 |
static void CopyBW2Grey8(const void* srcImage, int srcRowBytes, |
|
587 |
void* dstImage, int dstRowBytes, |
|
588 |
int width, int height) { |
|
589 |
const UInt8* srcRow = (UInt8*)srcImage; |
|
590 |
UInt8* dstRow = (UInt8*)dstImage; |
|
591 |
int wholeByteCount = width >> 3; |
|
592 |
int remainingBitsCount = width & 7; |
|
593 |
int i, j; |
|
594 |
||
595 |
while (height--) { |
|
596 |
const UInt8* src8 = srcRow; |
|
597 |
UInt8* dstByte = dstRow; |
|
598 |
unsigned srcValue; |
|
599 |
||
600 |
srcRow += srcRowBytes; |
|
601 |
dstRow += dstRowBytes; |
|
602 |
||
603 |
for (i = 0; i < wholeByteCount; i++) { |
|
604 |
srcValue = *src8++; |
|
605 |
for (j = 0; j < 8; j++) { |
|
606 |
*dstByte++ = (srcValue & 0x80) ? 0xFF : 0; |
|
607 |
srcValue <<= 1; |
|
608 |
} |
|
609 |
} |
|
610 |
if (remainingBitsCount) { |
|
611 |
srcValue = *src8; |
|
612 |
for (j = 0; j < remainingBitsCount; j++) { |
|
613 |
*dstByte++ = (srcValue & 0x80) ? 0xFF : 0; |
|
614 |
srcValue <<= 1; |
|
615 |
} |
|
616 |
} |
|
617 |
} |
|
618 |
} |
|
619 |
||
620 |
#define Grey4ToAlpha255(value) (((value) << 4) + ((value) >> 3)) |
|
621 |
||
622 |
static void CopyGrey4ToGrey8(const void* srcImage, int srcRowBytes, |
|
623 |
void* dstImage, int dstRowBytes, int width, int height) { |
|
624 |
const UInt8* srcRow = (UInt8*) srcImage; |
|
625 |
UInt8* dstRow = (UInt8*) dstImage; |
|
626 |
int i; |
|
627 |
||
628 |
while (height--) { |
|
629 |
const UInt8* src8 = srcRow; |
|
630 |
UInt8* dstByte = dstRow; |
|
631 |
unsigned srcValue; |
|
632 |
||
633 |
srcRow += srcRowBytes; |
|
634 |
dstRow += dstRowBytes; |
|
635 |
||
636 |
for (i = 0; i < width; i++) { |
|
637 |
srcValue = *src8++; |
|
638 |
*dstByte++ = Grey4ToAlpha255(srcValue & 0x0f); |
|
639 |
*dstByte++ = Grey4ToAlpha255(srcValue >> 4); |
|
640 |
} |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
/* We need it because FT rows are often padded to 4 byte boundaries |
|
645 |
and our internal format is not padded */ |
|
646 |
static void CopyFTSubpixelToSubpixel(const void* srcImage, int srcRowBytes, |
|
647 |
void* dstImage, int dstRowBytes, |
|
648 |
int width, int height) { |
|
649 |
unsigned char *srcRow = (unsigned char *) srcImage; |
|
650 |
unsigned char *dstRow = (unsigned char *) dstImage; |
|
651 |
||
652 |
while (height--) { |
|
653 |
memcpy(dstRow, srcRow, width); |
|
654 |
srcRow += srcRowBytes; |
|
655 |
dstRow += dstRowBytes; |
|
656 |
} |
|
657 |
} |
|
658 |
||
659 |
/* We need it because FT rows are often padded to 4 byte boundaries |
|
660 |
and our internal format is not padded */ |
|
661 |
static void CopyFTSubpixelVToSubpixel(const void* srcImage, int srcRowBytes, |
|
662 |
void* dstImage, int dstRowBytes, |
|
663 |
int width, int height) { |
|
664 |
unsigned char *srcRow = (unsigned char *) srcImage, *srcByte; |
|
665 |
unsigned char *dstRow = (unsigned char *) dstImage, *dstByte; |
|
666 |
int i; |
|
667 |
||
668 |
while (height > 0) { |
|
669 |
srcByte = srcRow; |
|
670 |
dstByte = dstRow; |
|
671 |
for (i = 0; i < width; i++) { |
|
672 |
*dstByte++ = *srcByte; |
|
673 |
*dstByte++ = *(srcByte + srcRowBytes); |
|
674 |
*dstByte++ = *(srcByte + 2*srcRowBytes); |
|
675 |
srcByte++; |
|
676 |
} |
|
677 |
srcRow += 3*srcRowBytes; |
|
678 |
dstRow += dstRowBytes; |
|
679 |
height -= 3; |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
||
684 |
/* |
|
685 |
* Class: sun_font_FreetypeFontScaler |
|
686 |
* Method: getGlyphImageNative |
|
687 |
* Signature: (Lsun/font/Font2D;JI)J |
|
688 |
*/ |
|
689 |
JNIEXPORT jlong JNICALL |
|
690 |
Java_sun_font_FreetypeFontScaler_getGlyphImageNative( |
|
691 |
JNIEnv *env, jobject scaler, jobject font2D, |
|
692 |
jlong pScalerContext, jlong pScaler, jint glyphCode) { |
|
693 |
||
694 |
int error, imageSize; |
|
695 |
UInt16 width, height; |
|
696 |
GlyphInfo *glyphInfo; |
|
52966
7ed5edf6ba0c
8214002: Cannot use italic font style if the font has embedded bitmap
itakiguchi
parents:
52838
diff
changeset
|
697 |
int renderFlags = FT_LOAD_DEFAULT, target; |
2 | 698 |
FT_GlyphSlot ftglyph; |
699 |
||
700 |
FTScalerContext* context = |
|
701 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
702 |
FTScalerInfo *scalerInfo = |
|
703 |
(FTScalerInfo*) jlong_to_ptr(pScaler); |
|
704 |
||
705 |
if (isNullScalerContext(context) || scalerInfo == NULL) { |
|
706 |
return ptr_to_jlong(getNullGlyphImage()); |
|
707 |
} |
|
708 |
||
709 |
error = setupFTContext(env, font2D, scalerInfo, context); |
|
710 |
if (error) { |
|
711 |
invalidateJavaScaler(env, scaler, scalerInfo); |
|
712 |
return ptr_to_jlong(getNullGlyphImage()); |
|
713 |
} |
|
714 |
||
50658
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
715 |
if (!context->useSbits) { |
db4f24a6cf34
8204929: Fonts with embedded bitmaps are not always rotated
prr
parents:
50346
diff
changeset
|
716 |
renderFlags |= FT_LOAD_NO_BITMAP; |
2 | 717 |
} |
718 |
||
719 |
/* NB: in case of non identity transform |
|
720 |
we might also prefer to disable transform before hinting, |
|
721 |
and apply it explicitly after hinting is performed. |
|
722 |
Or we can disable hinting. */ |
|
723 |
||
724 |
/* select appropriate hinting mode */ |
|
725 |
if (context->aaType == TEXT_AA_OFF) { |
|
726 |
target = FT_LOAD_TARGET_MONO; |
|
727 |
} else if (context->aaType == TEXT_AA_ON) { |
|
728 |
target = FT_LOAD_TARGET_NORMAL; |
|
729 |
} else if (context->aaType == TEXT_AA_LCD_HRGB || |
|
730 |
context->aaType == TEXT_AA_LCD_HBGR) { |
|
731 |
target = FT_LOAD_TARGET_LCD; |
|
732 |
} else { |
|
733 |
target = FT_LOAD_TARGET_LCD_V; |
|
734 |
} |
|
735 |
renderFlags |= target; |
|
736 |
||
737 |
error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderFlags); |
|
738 |
if (error) { |
|
739 |
//do not destroy scaler yet. |
|
740 |
//this can be problem of particular context (e.g. with bad transform) |
|
741 |
return ptr_to_jlong(getNullGlyphImage()); |
|
742 |
} |
|
743 |
||
744 |
ftglyph = scalerInfo->face->glyph; |
|
745 |
||
746 |
/* apply styles */ |
|
747 |
if (context->doBold) { /* if bold style */ |
|
748 |
FT_GlyphSlot_Embolden(ftglyph); |
|
749 |
} |
|
750 |
if (context->doItalize) { /* if oblique */ |
|
751 |
FT_GlyphSlot_Oblique(ftglyph); |
|
752 |
} |
|
753 |
||
754 |
/* generate bitmap if it is not done yet |
|
755 |
e.g. if algorithmic styling is performed and style was added to outline */ |
|
756 |
if (ftglyph->format == FT_GLYPH_FORMAT_OUTLINE) { |
|
757 |
FT_Render_Glyph(ftglyph, FT_LOAD_TARGET_MODE(target)); |
|
758 |
} |
|
759 |
||
760 |
width = (UInt16) ftglyph->bitmap.width; |
|
761 |
height = (UInt16) ftglyph->bitmap.rows; |
|
762 |
||
763 |
imageSize = width*height; |
|
764 |
glyphInfo = (GlyphInfo*) malloc(sizeof(GlyphInfo) + imageSize); |
|
765 |
if (glyphInfo == NULL) { |
|
766 |
glyphInfo = getNullGlyphImage(); |
|
767 |
return ptr_to_jlong(glyphInfo); |
|
768 |
} |
|
769 |
glyphInfo->cellInfo = NULL; |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
4243
diff
changeset
|
770 |
glyphInfo->managed = UNMANAGED_GLYPH; |
2 | 771 |
glyphInfo->rowBytes = width; |
772 |
glyphInfo->width = width; |
|
773 |
glyphInfo->height = height; |
|
774 |
glyphInfo->topLeftX = (float) ftglyph->bitmap_left; |
|
775 |
glyphInfo->topLeftY = (float) -ftglyph->bitmap_top; |
|
776 |
||
881
6aefebba2393
6587560: OpenJDK problem handling bitmaps returned when LCD text is requested
igor
parents:
561
diff
changeset
|
777 |
if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) { |
2 | 778 |
glyphInfo->width = width/3; |
881
6aefebba2393
6587560: OpenJDK problem handling bitmaps returned when LCD text is requested
igor
parents:
561
diff
changeset
|
779 |
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) { |
2 | 780 |
glyphInfo->height = glyphInfo->height/3; |
781 |
} |
|
782 |
||
783 |
if (context->fmType == TEXT_FM_ON) { |
|
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
784 |
double advh = FTFixedToFloat(ftglyph->linearHoriAdvance); |
2 | 785 |
glyphInfo->advanceX = |
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
786 |
(float) (advh * FTFixedToFloat(context->transform.xx)); |
2 | 787 |
glyphInfo->advanceY = |
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
788 |
(float) (advh * FTFixedToFloat(context->transform.xy)); |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
789 |
} else { |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
790 |
if (!ftglyph->advance.y) { |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
791 |
glyphInfo->advanceX = |
50346
9e530b150333
8203485: [freetype] text rotated on 180 degrees is too narrow
bae
parents:
47216
diff
changeset
|
792 |
(float) FT26Dot6ToInt(ftglyph->advance.x); |
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
793 |
glyphInfo->advanceY = 0; |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
794 |
} else if (!ftglyph->advance.x) { |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
795 |
glyphInfo->advanceX = 0; |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
796 |
glyphInfo->advanceY = |
50346
9e530b150333
8203485: [freetype] text rotated on 180 degrees is too narrow
bae
parents:
47216
diff
changeset
|
797 |
(float) FT26Dot6ToInt(-ftglyph->advance.y); |
554
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
798 |
} else { |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
799 |
glyphInfo->advanceX = FT26Dot6ToFloat(ftglyph->advance.x); |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
800 |
glyphInfo->advanceY = FT26Dot6ToFloat(-ftglyph->advance.y); |
88eb2812c2a4
6697721: OpenJDK: rotated text baseline different between TextLayout and drawString
prr
parents:
2
diff
changeset
|
801 |
} |
2 | 802 |
} |
803 |
||
804 |
if (imageSize == 0) { |
|
805 |
glyphInfo->image = NULL; |
|
806 |
} else { |
|
807 |
glyphInfo->image = (unsigned char*) glyphInfo + sizeof(GlyphInfo); |
|
808 |
//convert result to output format |
|
809 |
//output format is either 3 bytes per pixel (for subpixel modes) |
|
810 |
// or 1 byte per pixel for AA and B&W |
|
811 |
if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { |
|
812 |
/* convert from 8 pixels per byte to 1 byte per pixel */ |
|
813 |
CopyBW2Grey8(ftglyph->bitmap.buffer, |
|
814 |
ftglyph->bitmap.pitch, |
|
815 |
(void *) glyphInfo->image, |
|
816 |
width, |
|
817 |
width, |
|
818 |
height); |
|
819 |
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { |
|
820 |
/* byte per pixel to byte per pixel => just copy */ |
|
821 |
memcpy(glyphInfo->image, ftglyph->bitmap.buffer, imageSize); |
|
822 |
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY4) { |
|
823 |
/* 4 bits per pixel to byte per pixel */ |
|
824 |
CopyGrey4ToGrey8(ftglyph->bitmap.buffer, |
|
825 |
ftglyph->bitmap.pitch, |
|
826 |
(void *) glyphInfo->image, |
|
827 |
width, |
|
828 |
width, |
|
829 |
height); |
|
830 |
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) { |
|
831 |
/* 3 bytes per pixel to 3 bytes per pixel */ |
|
832 |
CopyFTSubpixelToSubpixel(ftglyph->bitmap.buffer, |
|
833 |
ftglyph->bitmap.pitch, |
|
834 |
(void *) glyphInfo->image, |
|
835 |
width, |
|
836 |
width, |
|
837 |
height); |
|
838 |
} else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) { |
|
839 |
/* 3 bytes per pixel to 3 bytes per pixel */ |
|
840 |
CopyFTSubpixelVToSubpixel(ftglyph->bitmap.buffer, |
|
841 |
ftglyph->bitmap.pitch, |
|
842 |
(void *) glyphInfo->image, |
|
843 |
width*3, |
|
844 |
width, |
|
845 |
height); |
|
846 |
glyphInfo->rowBytes *=3; |
|
847 |
} else { |
|
848 |
free(glyphInfo); |
|
849 |
glyphInfo = getNullGlyphImage(); |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
return ptr_to_jlong(glyphInfo); |
|
854 |
} |
|
855 |
||
856 |
||
857 |
/* |
|
858 |
* Class: sun_font_FreetypeFontScaler |
|
859 |
* Method: getLayoutTableCacheNative |
|
860 |
* Signature: (J)J |
|
861 |
*/ |
|
862 |
JNIEXPORT jlong JNICALL |
|
863 |
Java_sun_font_FreetypeFontScaler_getLayoutTableCacheNative( |
|
864 |
JNIEnv *env, jobject scaler, jlong pScaler) { |
|
865 |
FTScalerInfo *scalerInfo = (FTScalerInfo*) jlong_to_ptr(pScaler); |
|
866 |
||
867 |
if (scalerInfo == NULL) { |
|
868 |
invalidateJavaScaler(env, scaler, scalerInfo); |
|
869 |
return 0L; |
|
870 |
} |
|
871 |
||
872 |
// init layout table cache in font |
|
873 |
// we're assuming the font is a file font and moreover it is Truetype font |
|
874 |
// otherwise we shouldn't be able to get here... |
|
875 |
if (scalerInfo->layoutTables == NULL) { |
|
876 |
scalerInfo->layoutTables = newLayoutTableCache(); |
|
877 |
} |
|
878 |
||
879 |
return ptr_to_jlong(scalerInfo->layoutTables); |
|
880 |
} |
|
881 |
||
882 |
/* |
|
883 |
* Class: sun_font_FreetypeFontScaler |
|
884 |
* Method: disposeNativeScaler |
|
885 |
* Signature: (J)V |
|
886 |
*/ |
|
887 |
JNIEXPORT void JNICALL |
|
888 |
Java_sun_font_FreetypeFontScaler_disposeNativeScaler( |
|
20414
c43f5228a1f9
8020190: Fatal: Bug in native code: jfieldID must match object
prr
parents:
18198
diff
changeset
|
889 |
JNIEnv *env, jobject scaler, jobject font2D, jlong pScaler) { |
2 | 890 |
FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); |
891 |
||
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
892 |
/* Freetype functions *may* cause callback to java |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
893 |
that can use cached values. Make sure our cache is up to date. |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
894 |
NB: scaler context is not important at this point, can use NULL. */ |
20414
c43f5228a1f9
8020190: Fatal: Bug in native code: jfieldID must match object
prr
parents:
18198
diff
changeset
|
895 |
int errCode = setupFTContext(env, font2D, scalerInfo, NULL); |
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
896 |
if (errCode) { |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
897 |
return; |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
898 |
} |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
899 |
|
2 | 900 |
freeNativeResources(env, scalerInfo); |
901 |
} |
|
902 |
||
903 |
/* |
|
904 |
* Class: sun_font_FreetypeFontScaler |
|
905 |
* Method: getNumGlyphsNative |
|
906 |
* Signature: ()I |
|
907 |
*/ |
|
908 |
JNIEXPORT jint JNICALL |
|
909 |
Java_sun_font_FreetypeFontScaler_getNumGlyphsNative( |
|
910 |
JNIEnv *env, jobject scaler, jlong pScaler) { |
|
911 |
FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); |
|
912 |
||
913 |
if (scalerInfo == NULL || scalerInfo->face == NULL) { /* bad/null scaler */ |
|
914 |
/* null scaler can render 1 glyph - "missing glyph" with code 0 |
|
915 |
(all glyph codes requested by user are mapped to code 0 at |
|
916 |
validation step) */ |
|
917 |
invalidateJavaScaler(env, scaler, scalerInfo); |
|
918 |
return (jint) 1; |
|
919 |
} |
|
920 |
||
921 |
return (jint) scalerInfo->face->num_glyphs; |
|
922 |
} |
|
923 |
||
924 |
/* |
|
925 |
* Class: sun_font_FreetypeFontScaler |
|
926 |
* Method: getMissingGlyphCodeNative |
|
927 |
* Signature: ()I |
|
928 |
*/ |
|
929 |
JNIEXPORT jint JNICALL |
|
930 |
Java_sun_font_FreetypeFontScaler_getMissingGlyphCodeNative( |
|
931 |
JNIEnv *env, jobject scaler, jlong pScaler) { |
|
932 |
||
933 |
/* Is it always 0 for freetype? */ |
|
934 |
return 0; |
|
935 |
} |
|
936 |
||
937 |
/* |
|
938 |
* Class: sun_font_FreetypeFontScaler |
|
939 |
* Method: getGlyphCodeNative |
|
940 |
* Signature: (C)I |
|
941 |
*/ |
|
942 |
JNIEXPORT jint JNICALL |
|
943 |
Java_sun_font_FreetypeFontScaler_getGlyphCodeNative( |
|
20414
c43f5228a1f9
8020190: Fatal: Bug in native code: jfieldID must match object
prr
parents:
18198
diff
changeset
|
944 |
JNIEnv *env, jobject scaler, |
c43f5228a1f9
8020190: Fatal: Bug in native code: jfieldID must match object
prr
parents:
18198
diff
changeset
|
945 |
jobject font2D, jlong pScaler, jchar charCode) { |
2 | 946 |
|
947 |
FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); |
|
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
948 |
int errCode; |
2 | 949 |
|
950 |
if (scaler == NULL || scalerInfo->face == NULL) { /* bad/null scaler */ |
|
951 |
invalidateJavaScaler(env, scaler, scalerInfo); |
|
952 |
return 0; |
|
953 |
} |
|
954 |
||
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
955 |
/* Freetype functions *may* cause callback to java |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
956 |
that can use cached values. Make sure our cache is up to date. |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
957 |
Scaler context is not important here, can use NULL. */ |
20414
c43f5228a1f9
8020190: Fatal: Bug in native code: jfieldID must match object
prr
parents:
18198
diff
changeset
|
958 |
errCode = setupFTContext(env, font2D, scalerInfo, NULL); |
2369
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
959 |
if (errCode) { |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
960 |
return 0; |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
961 |
} |
b58cdc0321f5
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
igor
parents:
1733
diff
changeset
|
962 |
|
2 | 963 |
return FT_Get_Char_Index(scalerInfo->face, charCode); |
964 |
} |
|
965 |
||
966 |
||
967 |
#define FloatToF26Dot6(x) ((unsigned int) ((x)*64)) |
|
968 |
||
969 |
static FT_Outline* getFTOutline(JNIEnv* env, jobject font2D, |
|
970 |
FTScalerContext *context, FTScalerInfo* scalerInfo, |
|
971 |
jint glyphCode, jfloat xpos, jfloat ypos) { |
|
972 |
int renderFlags; |
|
973 |
FT_Error error; |
|
974 |
FT_GlyphSlot ftglyph; |
|
975 |
||
976 |
if (glyphCode >= INVISIBLE_GLYPHS || |
|
977 |
isNullScalerContext(context) || scalerInfo == NULL) { |
|
978 |
return NULL; |
|
979 |
} |
|
980 |
||
981 |
error = setupFTContext(env, font2D, scalerInfo, context); |
|
982 |
if (error) { |
|
983 |
return NULL; |
|
984 |
} |
|
985 |
||
986 |
renderFlags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; |
|
987 |
||
988 |
error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderFlags); |
|
989 |
if (error) { |
|
990 |
return NULL; |
|
991 |
} |
|
992 |
||
993 |
ftglyph = scalerInfo->face->glyph; |
|
994 |
||
995 |
/* apply styles */ |
|
996 |
if (context->doBold) { /* if bold style */ |
|
997 |
FT_GlyphSlot_Embolden(ftglyph); |
|
998 |
} |
|
999 |
if (context->doItalize) { /* if oblique */ |
|
1000 |
FT_GlyphSlot_Oblique(ftglyph); |
|
1001 |
} |
|
1002 |
||
1003 |
FT_Outline_Translate(&ftglyph->outline, |
|
1004 |
FloatToF26Dot6(xpos), |
|
561
977a2ff62fc9
6703377: freetype: glyph vector outline is not translated correctly
igor
parents:
554
diff
changeset
|
1005 |
-FloatToF26Dot6(ypos)); |
2 | 1006 |
|
1007 |
return &ftglyph->outline; |
|
1008 |
} |
|
1009 |
||
1010 |
#define F26Dot6ToFloat(n) (((float)(n))/((float) 64)) |
|
1011 |
||
1012 |
/* Types of GeneralPath segments. |
|
1013 |
TODO: pull constants from other place? */ |
|
1014 |
||
1015 |
#define SEG_UNKNOWN -1 |
|
1016 |
#define SEG_MOVETO 0 |
|
1017 |
#define SEG_LINETO 1 |
|
1018 |
#define SEG_QUADTO 2 |
|
1019 |
#define SEG_CUBICTO 3 |
|
1020 |
#define SEG_CLOSE 4 |
|
1021 |
||
1022 |
#define WIND_NON_ZERO 0 |
|
1023 |
#define WIND_EVEN_ODD 1 |
|
1024 |
||
1025 |
/* Placeholder to accumulate GeneralPath data */ |
|
1026 |
typedef struct { |
|
1027 |
jint numTypes; |
|
1028 |
jint numCoords; |
|
1029 |
jint lenTypes; |
|
1030 |
jint lenCoords; |
|
1031 |
jint wr; |
|
1032 |
jbyte* pointTypes; |
|
1033 |
jfloat* pointCoords; |
|
1034 |
} GPData; |
|
1035 |
||
1036 |
/* returns 0 on failure */ |
|
1037 |
static int allocateSpaceForGP(GPData* gpdata, int npoints, int ncontours) { |
|
1038 |
int maxTypes, maxCoords; |
|
1039 |
||
1040 |
/* we may have up to N intermediate points per contour |
|
1041 |
(and for each point can actually cause new curve to be generated) |
|
1042 |
In addition we can also have 2 extra point per outline. |
|
1043 |
*/ |
|
1044 |
maxTypes = 2*npoints + 2*ncontours; |
|
1045 |
maxCoords = 4*(npoints + 2*ncontours); //we may need to insert |
|
1046 |
//up to n-1 intermediate points |
|
1047 |
||
1048 |
/* first usage - allocate space and intialize all fields */ |
|
1049 |
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) { |
|
1050 |
gpdata->lenTypes = maxTypes; |
|
1051 |
gpdata->lenCoords = maxCoords; |
|
1052 |
gpdata->pointTypes = (jbyte*) |
|
1053 |
malloc(gpdata->lenTypes*sizeof(jbyte)); |
|
1054 |
gpdata->pointCoords = (jfloat*) |
|
1055 |
malloc(gpdata->lenCoords*sizeof(jfloat)); |
|
1056 |
gpdata->numTypes = 0; |
|
1057 |
gpdata->numCoords = 0; |
|
1058 |
gpdata->wr = WIND_NON_ZERO; /* By default, outlines are filled |
|
1059 |
using the non-zero winding rule. */ |
|
1060 |
} else { |
|
1061 |
/* do we have enough space? */ |
|
1062 |
if (gpdata->lenTypes - gpdata->numTypes < maxTypes) { |
|
1063 |
gpdata->lenTypes += maxTypes; |
|
1064 |
gpdata->pointTypes = (jbyte*) |
|
1065 |
realloc(gpdata->pointTypes, gpdata->lenTypes*sizeof(jbyte)); |
|
1066 |
} |
|
1067 |
||
1068 |
if (gpdata->lenCoords - gpdata->numCoords < maxCoords) { |
|
1069 |
gpdata->lenCoords += maxCoords; |
|
1070 |
gpdata->pointCoords = (jfloat*) |
|
1071 |
realloc(gpdata->pointCoords, gpdata->lenCoords*sizeof(jfloat)); |
|
1072 |
} |
|
1073 |
} |
|
1074 |
||
1075 |
/* failure if any of mallocs failed */ |
|
1076 |
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) |
|
1077 |
return 0; |
|
1078 |
else |
|
1079 |
return 1; |
|
1080 |
} |
|
1081 |
||
26617
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1082 |
static void addSeg(GPData *gp, jbyte type) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1083 |
gp->pointTypes[gp->numTypes++] = type; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1084 |
} |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1085 |
|
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1086 |
static void addCoords(GPData *gp, FT_Vector *p) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1087 |
gp->pointCoords[gp->numCoords++] = F26Dot6ToFloat(p->x); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1088 |
gp->pointCoords[gp->numCoords++] = -F26Dot6ToFloat(p->y); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1089 |
} |
2 | 1090 |
|
26617
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1091 |
static int moveTo(FT_Vector *to, GPData *gp) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1092 |
if (gp->numCoords) |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1093 |
addSeg(gp, SEG_CLOSE); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1094 |
addCoords(gp, to); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1095 |
addSeg(gp, SEG_MOVETO); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1096 |
return FT_Err_Ok; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1097 |
} |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1098 |
|
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1099 |
static int lineTo(FT_Vector *to, GPData *gp) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1100 |
addCoords(gp, to); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1101 |
addSeg(gp, SEG_LINETO); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1102 |
return FT_Err_Ok; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1103 |
} |
2 | 1104 |
|
26617
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1105 |
static int conicTo(FT_Vector *control, FT_Vector *to, GPData *gp) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1106 |
addCoords(gp, control); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1107 |
addCoords(gp, to); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1108 |
addSeg(gp, SEG_QUADTO); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1109 |
return FT_Err_Ok; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1110 |
} |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1111 |
|
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1112 |
static int cubicTo(FT_Vector *control1, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1113 |
FT_Vector *control2, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1114 |
FT_Vector *to, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1115 |
GPData *gp) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1116 |
addCoords(gp, control1); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1117 |
addCoords(gp, control2); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1118 |
addCoords(gp, to); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1119 |
addSeg(gp, SEG_CUBICTO); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1120 |
return FT_Err_Ok; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1121 |
} |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1122 |
|
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1123 |
static void addToGP(GPData* gpdata, FT_Outline*outline) { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1124 |
static const FT_Outline_Funcs outline_funcs = { |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1125 |
(FT_Outline_MoveToFunc) moveTo, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1126 |
(FT_Outline_LineToFunc) lineTo, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1127 |
(FT_Outline_ConicToFunc) conicTo, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1128 |
(FT_Outline_CubicToFunc) cubicTo, |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1129 |
0, /* shift */ |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1130 |
0, /* delta */ |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1131 |
}; |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1132 |
|
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1133 |
FT_Outline_Decompose(outline, &outline_funcs, gpdata); |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1134 |
if (gpdata->numCoords) |
ca6dcc52ff1c
8057986: freetype code to get glyph outline does not handle initial control point properly
martin
parents:
25859
diff
changeset
|
1135 |
addSeg(gpdata, SEG_CLOSE); |
2 | 1136 |
|
1137 |
/* If set to 1, the outline will be filled using the even-odd fill rule */ |
|
1138 |
if (outline->flags & FT_OUTLINE_EVEN_ODD_FILL) { |
|
1139 |
gpdata->wr = WIND_EVEN_ODD; |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
1143 |
static void freeGP(GPData* gpdata) { |
|
1144 |
if (gpdata->pointCoords != NULL) { |
|
1145 |
free(gpdata->pointCoords); |
|
1146 |
gpdata->pointCoords = NULL; |
|
1147 |
gpdata->numCoords = 0; |
|
1148 |
gpdata->lenCoords = 0; |
|
1149 |
} |
|
1150 |
if (gpdata->pointTypes != NULL) { |
|
1151 |
free(gpdata->pointTypes); |
|
1152 |
gpdata->pointTypes = NULL; |
|
1153 |
gpdata->numTypes = 0; |
|
1154 |
gpdata->lenTypes = 0; |
|
1155 |
} |
|
1156 |
} |
|
1157 |
||
1158 |
static jobject getGlyphGeneralPath(JNIEnv* env, jobject font2D, |
|
1159 |
FTScalerContext *context, FTScalerInfo *scalerInfo, |
|
1160 |
jint glyphCode, jfloat xpos, jfloat ypos) { |
|
1161 |
||
1162 |
FT_Outline* outline; |
|
1163 |
jobject gp = NULL; |
|
1164 |
jbyteArray types; |
|
1165 |
jfloatArray coords; |
|
1166 |
GPData gpdata; |
|
1167 |
||
1168 |
outline = getFTOutline(env, font2D, context, scalerInfo, |
|
1169 |
glyphCode, xpos, ypos); |
|
1170 |
||
1171 |
if (outline == NULL || outline->n_points == 0) { |
|
1172 |
return gp; |
|
1173 |
} |
|
1174 |
||
1175 |
gpdata.pointTypes = NULL; |
|
1176 |
gpdata.pointCoords = NULL; |
|
1177 |
if (!allocateSpaceForGP(&gpdata, outline->n_points, outline->n_contours)) { |
|
1178 |
return gp; |
|
1179 |
} |
|
1180 |
||
1181 |
addToGP(&gpdata, outline); |
|
1182 |
||
1183 |
types = (*env)->NewByteArray(env, gpdata.numTypes); |
|
1184 |
coords = (*env)->NewFloatArray(env, gpdata.numCoords); |
|
1185 |
||
1186 |
if (types && coords) { |
|
1187 |
(*env)->SetByteArrayRegion(env, types, 0, |
|
1188 |
gpdata.numTypes, |
|
1189 |
gpdata.pointTypes); |
|
1190 |
(*env)->SetFloatArrayRegion(env, coords, 0, |
|
1191 |
gpdata.numCoords, |
|
1192 |
gpdata.pointCoords); |
|
1193 |
gp = (*env)->NewObject(env, |
|
1194 |
sunFontIDs.gpClass, |
|
1195 |
sunFontIDs.gpCtr, |
|
1196 |
gpdata.wr, |
|
1197 |
types, |
|
1198 |
gpdata.numTypes, |
|
1199 |
coords, |
|
1200 |
gpdata.numCoords); |
|
1201 |
} |
|
1202 |
||
1203 |
freeGP(&gpdata); |
|
1204 |
||
1205 |
return gp; |
|
1206 |
} |
|
1207 |
||
1208 |
/* |
|
1209 |
* Class: sun_font_FreetypeFontScaler |
|
1210 |
* Method: getGlyphOutlineNative |
|
1211 |
* Signature: (Lsun/font/Font2D;JIFF)Ljava/awt/geom/GeneralPath; |
|
1212 |
*/ |
|
1213 |
JNIEXPORT jobject JNICALL |
|
1214 |
Java_sun_font_FreetypeFontScaler_getGlyphOutlineNative( |
|
1215 |
JNIEnv *env, jobject scaler, jobject font2D, jlong pScalerContext, |
|
1216 |
jlong pScaler, jint glyphCode, jfloat xpos, jfloat ypos) { |
|
1217 |
||
1218 |
FTScalerContext *context = |
|
1219 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
1220 |
FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); |
|
1221 |
||
1222 |
jobject gp = getGlyphGeneralPath(env, |
|
1223 |
font2D, |
|
1224 |
context, |
|
1225 |
scalerInfo, |
|
1226 |
glyphCode, |
|
1227 |
xpos, |
|
1228 |
ypos); |
|
1229 |
if (gp == NULL) { /* can be legal */ |
|
1230 |
gp = (*env)->NewObject(env, |
|
1231 |
sunFontIDs.gpClass, |
|
1232 |
sunFontIDs.gpCtrEmpty); |
|
1233 |
} |
|
1234 |
return gp; |
|
1235 |
} |
|
1236 |
||
1237 |
/* |
|
1238 |
* Class: sun_font_FreetypeFontScaler |
|
1239 |
* Method: getGlyphOutlineBoundsNative |
|
1240 |
* Signature: (Lsun/font/Font2D;JI)Ljava/awt/geom/Rectangle2D/Float; |
|
1241 |
*/ |
|
1242 |
JNIEXPORT jobject JNICALL |
|
1243 |
Java_sun_font_FreetypeFontScaler_getGlyphOutlineBoundsNative( |
|
1244 |
JNIEnv *env, jobject scaler, jobject font2D, |
|
1245 |
jlong pScalerContext, jlong pScaler, jint glyphCode) { |
|
1246 |
||
1247 |
FT_Outline *outline; |
|
1248 |
FT_BBox bbox; |
|
1249 |
int error; |
|
1250 |
jobject bounds; |
|
1251 |
||
1252 |
FTScalerContext *context = |
|
1253 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
1254 |
FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler); |
|
1255 |
||
1256 |
outline = getFTOutline(env, font2D, context, scalerInfo, glyphCode, 0, 0); |
|
1257 |
if (outline == NULL || outline->n_points == 0) { |
|
1258 |
/* it is legal case, e.g. invisible glyph */ |
|
1259 |
bounds = (*env)->NewObject(env, |
|
1260 |
sunFontIDs.rect2DFloatClass, |
|
1261 |
sunFontIDs.rect2DFloatCtr); |
|
1262 |
return bounds; |
|
1263 |
} |
|
1264 |
||
1265 |
error = FT_Outline_Get_BBox(outline, &bbox); |
|
1266 |
||
1267 |
//convert bbox |
|
1268 |
if (error || bbox.xMin >= bbox.xMax || bbox.yMin >= bbox.yMax) { |
|
1269 |
bounds = (*env)->NewObject(env, |
|
1270 |
sunFontIDs.rect2DFloatClass, |
|
1271 |
sunFontIDs.rect2DFloatCtr); |
|
1272 |
} else { |
|
1273 |
bounds = (*env)->NewObject(env, |
|
1274 |
sunFontIDs.rect2DFloatClass, |
|
1275 |
sunFontIDs.rect2DFloatCtr4, |
|
1276 |
F26Dot6ToFloat(bbox.xMin), |
|
1733
95c41a86eac9
6761856: OpenJDK: vertical text metrics may be significanly different from those returned by Sun JDK
igor
parents:
881
diff
changeset
|
1277 |
F26Dot6ToFloat(-bbox.yMax), |
2 | 1278 |
F26Dot6ToFloat(bbox.xMax-bbox.xMin), |
1279 |
F26Dot6ToFloat(bbox.yMax-bbox.yMin)); |
|
1280 |
} |
|
1281 |
||
1282 |
return bounds; |
|
1283 |
} |
|
1284 |
||
1285 |
/* |
|
1286 |
* Class: sun_font_FreetypeFontScaler |
|
1287 |
* Method: getGlyphVectorOutlineNative |
|
1288 |
* Signature: (Lsun/font/Font2D;J[IIFF)Ljava/awt/geom/GeneralPath; |
|
1289 |
*/ |
|
1290 |
JNIEXPORT jobject |
|
1291 |
JNICALL |
|
1292 |
Java_sun_font_FreetypeFontScaler_getGlyphVectorOutlineNative( |
|
1293 |
JNIEnv *env, jobject scaler, jobject font2D, |
|
1294 |
jlong pScalerContext, jlong pScaler, |
|
1295 |
jintArray glyphArray, jint numGlyphs, jfloat xpos, jfloat ypos) { |
|
1296 |
||
1297 |
FT_Outline* outline; |
|
1298 |
jobject gp = NULL; |
|
1299 |
jbyteArray types; |
|
1300 |
jfloatArray coords; |
|
1301 |
GPData gpdata; |
|
1302 |
int i; |
|
1303 |
jint *glyphs; |
|
1304 |
||
1305 |
FTScalerContext *context = |
|
1306 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
1307 |
FTScalerInfo *scalerInfo = |
|
1308 |
(FTScalerInfo*) jlong_to_ptr(pScaler); |
|
1309 |
||
18198 | 1310 |
glyphs = NULL; |
1311 |
if (numGlyphs > 0 && 0xffffffffu / sizeof(jint) >= numGlyphs) { |
|
1312 |
glyphs = (jint*) malloc(numGlyphs*sizeof(jint)); |
|
1313 |
} |
|
2 | 1314 |
if (glyphs == NULL) { |
18198 | 1315 |
// We reach here if: |
1316 |
// 1. numGlyphs <= 0, |
|
1317 |
// 2. overflow check failed, or |
|
1318 |
// 3. malloc failed. |
|
2 | 1319 |
gp = (*env)->NewObject(env, sunFontIDs.gpClass, sunFontIDs.gpCtrEmpty); |
1320 |
return gp; |
|
1321 |
} |
|
1322 |
||
1323 |
(*env)->GetIntArrayRegion(env, glyphArray, 0, numGlyphs, glyphs); |
|
1324 |
||
18198 | 1325 |
gpdata.numCoords = 0; |
2 | 1326 |
for (i=0; i<numGlyphs;i++) { |
1327 |
if (glyphs[i] >= INVISIBLE_GLYPHS) { |
|
1328 |
continue; |
|
1329 |
} |
|
1330 |
outline = getFTOutline(env, |
|
1331 |
font2D, |
|
1332 |
context, |
|
1333 |
scalerInfo, |
|
1334 |
glyphs[i], |
|
1335 |
xpos, ypos); |
|
1336 |
||
1337 |
if (outline == NULL || outline->n_points == 0) { |
|
1338 |
continue; |
|
1339 |
} |
|
1340 |
||
1341 |
gpdata.pointTypes = NULL; |
|
1342 |
gpdata.pointCoords = NULL; |
|
1343 |
if (!allocateSpaceForGP(&gpdata, outline->n_points, |
|
1344 |
outline->n_contours)) { |
|
1345 |
break; |
|
1346 |
} |
|
1347 |
||
1348 |
addToGP(&gpdata, outline); |
|
1349 |
} |
|
1350 |
free(glyphs); |
|
1351 |
||
1352 |
if (gpdata.numCoords != 0) { |
|
1353 |
types = (*env)->NewByteArray(env, gpdata.numTypes); |
|
1354 |
coords = (*env)->NewFloatArray(env, gpdata.numCoords); |
|
1355 |
||
1356 |
if (types && coords) { |
|
1357 |
(*env)->SetByteArrayRegion(env, types, 0, |
|
1358 |
gpdata.numTypes, gpdata.pointTypes); |
|
1359 |
(*env)->SetFloatArrayRegion(env, coords, 0, |
|
1360 |
gpdata.numCoords, gpdata.pointCoords); |
|
1361 |
||
1362 |
gp=(*env)->NewObject(env, |
|
1363 |
sunFontIDs.gpClass, |
|
1364 |
sunFontIDs.gpCtr, |
|
1365 |
gpdata.wr, |
|
1366 |
types, |
|
1367 |
gpdata.numTypes, |
|
1368 |
coords, |
|
1369 |
gpdata.numCoords); |
|
1370 |
return gp; |
|
1371 |
} |
|
1372 |
} |
|
1373 |
return (*env)->NewObject(env, sunFontIDs.gpClass, sunFontIDs.gpCtrEmpty); |
|
1374 |
} |
|
1375 |
||
1376 |
JNIEXPORT jlong JNICALL |
|
1377 |
Java_sun_font_FreetypeFontScaler_getUnitsPerEMNative( |
|
1378 |
JNIEnv *env, jobject scaler, jlong pScaler) { |
|
1379 |
||
1380 |
FTScalerInfo *s = (FTScalerInfo* ) jlong_to_ptr(pScaler); |
|
1381 |
||
1382 |
/* Freetype doc says: |
|
1383 |
The number of font units per EM square for this face. |
|
1384 |
This is typically 2048 for TrueType fonts, and 1000 for Type 1 fonts. |
|
1385 |
Only relevant for scalable formats. |
|
1386 |
However, layout engine might be not tested with anything but 2048. |
|
1387 |
||
1388 |
NB: test it! */ |
|
1389 |
if (s != NULL) { |
|
1390 |
return s->face->units_per_EM; |
|
1391 |
} |
|
1392 |
return 2048; |
|
1393 |
} |
|
1394 |
||
1395 |
/* This native method is called by the OpenType layout engine. */ |
|
1396 |
JNIEXPORT jobject JNICALL |
|
1397 |
Java_sun_font_FreetypeFontScaler_getGlyphPointNative( |
|
1398 |
JNIEnv *env, jobject scaler, jobject font2D, jlong pScalerContext, |
|
1399 |
jlong pScaler, jint glyphCode, jint pointNumber) { |
|
1400 |
||
1401 |
FT_Outline* outline; |
|
1402 |
jobject point = NULL; |
|
1403 |
jfloat x=0, y=0; |
|
1404 |
FTScalerContext *context = |
|
1405 |
(FTScalerContext*) jlong_to_ptr(pScalerContext); |
|
1406 |
FTScalerInfo *scalerInfo = (FTScalerInfo*) jlong_to_ptr(pScaler); |
|
1407 |
||
1408 |
outline = getFTOutline(env, font2D, context, scalerInfo, glyphCode, 0, 0); |
|
1409 |
||
1410 |
if (outline != NULL && outline->n_points > pointNumber) { |
|
1411 |
x = F26Dot6ToFloat(outline->points[pointNumber].x); |
|
1412 |
y = -F26Dot6ToFloat(outline->points[pointNumber].y); |
|
1413 |
} |
|
1414 |
||
1415 |
return (*env)->NewObject(env, sunFontIDs.pt2DFloatClass, |
|
1416 |
sunFontIDs.pt2DFloatCtr, x, y); |
|
1417 |
} |