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