< prev index next >
src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m
Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion
*** 21,37 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
- #import <JavaNativeFoundation/JavaNativeFoundation.h>
#import "java_awt_geom_PathIterator.h"
#import "sun_font_CStrike.h"
#import "sun_font_CStrikeDisposer.h"
#import "CGGlyphImages.h"
#import "CGGlyphOutlines.h"
#import "CoreTextSupport.h"
#include "fontscalerdefs.h"
@implementation AWTStrike
static CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
--- 21,37 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import "java_awt_geom_PathIterator.h"
#import "sun_font_CStrike.h"
#import "sun_font_CStrikeDisposer.h"
#import "CGGlyphImages.h"
#import "CGGlyphOutlines.h"
#import "CoreTextSupport.h"
+ #import "JNIUtilities.h"
#include "fontscalerdefs.h"
@implementation AWTStrike
static CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
*** 101,111 ****
#define AWT_FONT_CLEANUP_FINISH \
if (_fontThrowJavaException == YES) { \
char s[512]; \
sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \
! [JNFException raise:env as:kRuntimeException reason:s]; \
}
/*
* Creates an affine transform from the corresponding doubles sent
--- 101,111 ----
#define AWT_FONT_CLEANUP_FINISH \
if (_fontThrowJavaException == YES) { \
char s[512]; \
sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \
! JNU_ThrowByName(env, "java/lang/RuntimeException", s); \
}
/*
* Creates an affine transform from the corresponding doubles sent
*** 141,151 ****
JNIEXPORT jfloat JNICALL
Java_sun_font_CStrike_getNativeGlyphAdvance
(JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode)
{
CGSize advance;
! JNF_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtFont = awtStrike->fAWTFont;
// negative glyph codes are really unicodes, which were placed there by the mapper
// to indicate we should use CoreText to substitute the character
--- 141,151 ----
JNIEXPORT jfloat JNICALL
Java_sun_font_CStrike_getNativeGlyphAdvance
(JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode)
{
CGSize advance;
! JNI_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtFont = awtStrike->fAWTFont;
// negative glyph codes are really unicodes, which were placed there by the mapper
// to indicate we should use CoreText to substitute the character
*** 156,166 ****
advance = CGSizeApplyAffineTransform(advance, awtStrike->fFontTx);
if (!JRSFontStyleUsesFractionalMetrics(awtStrike->fStyle)) {
advance.width = round(advance.width);
}
! JNF_COCOA_EXIT(env);
return advance.width;
}
/*
* Class: sun_font_CStrike
--- 156,166 ----
advance = CGSizeApplyAffineTransform(advance, awtStrike->fFontTx);
if (!JRSFontStyleUsesFractionalMetrics(awtStrike->fStyle)) {
advance.width = round(advance.width);
}
! JNI_COCOA_EXIT(env);
return advance.width;
}
/*
* Class: sun_font_CStrike
*** 171,181 ****
Java_sun_font_CStrike_getNativeGlyphImageBounds
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jint glyphCode,
jobject result /*Rectangle*/, jdouble x, jdouble y)
{
! JNF_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtFont = awtStrike->fAWTFont;
CGAffineTransform tx = awtStrike->fAltTx;
--- 171,181 ----
Java_sun_font_CStrike_getNativeGlyphImageBounds
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jint glyphCode,
jobject result /*Rectangle*/, jdouble x, jdouble y)
{
! JNI_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtFont = awtStrike->fAWTFont;
CGAffineTransform tx = awtStrike->fAltTx;
*** 194,208 ****
// the origin of this bounding box is relative to the bottom-left corner baseline
CGFloat decender = -bbox.origin.y;
bbox.origin.y = -bbox.size.height + decender;
// Rectangle2D.Float.setRect(float x, float y, float width, float height);
! static JNF_CLASS_CACHE(sjc_Rectangle2D_Float, "java/awt/geom/Rectangle2D$Float"); // cache class id for Rectangle
! static JNF_MEMBER_CACHE(sjr_Rectangle2DFloat_setRect, sjc_Rectangle2D_Float, "setRect", "(FFFF)V");
! JNFCallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect, (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height);
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: getNativeGlyphOutline
--- 194,210 ----
// the origin of this bounding box is relative to the bottom-left corner baseline
CGFloat decender = -bbox.origin.y;
bbox.origin.y = -bbox.size.height + decender;
// Rectangle2D.Float.setRect(float x, float y, float width, float height);
! DECLARE_CLASS(sjc_Rectangle2D_Float, "java/awt/geom/Rectangle2D$Float"); // cache class id for Rectangle
! DECLARE_METHOD(sjr_Rectangle2DFloat_setRect, sjc_Rectangle2D_Float, "setRect", "(FFFF)V");
! (*env)->CallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect,
! (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height);
! CHECK_EXCEPTION();
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: getNativeGlyphOutline
*** 213,228 ****
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jint glyphCode, jdouble xPos, jdouble yPos)
{
jobject generalPath = NULL;
! JNF_COCOA_ENTER(env);
AWTPathRef path = NULL;
jfloatArray pointCoords = NULL;
jbyteArray pointTypes = NULL;
AWT_FONT_CLEANUP_SETUP;
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtfont = awtStrike->fAWTFont;
--- 215,233 ----
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jint glyphCode, jdouble xPos, jdouble yPos)
{
jobject generalPath = NULL;
! JNI_COCOA_ENTER(env);
AWTPathRef path = NULL;
jfloatArray pointCoords = NULL;
jbyteArray pointTypes = NULL;
+ DECLARE_CLASS_RETURN(jc_GeneralPath, "java/awt/geom/GeneralPath", NULL);
+ DECLARE_METHOD_RETURN(jc_GeneralPath_ctor, jc_GeneralPath, "<init>", "(I[BI[FI)V", NULL);
+
AWT_FONT_CLEANUP_SETUP;
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
AWTFont *awtfont = awtStrike->fAWTFont;
*** 261,273 ****
pointTypes = (*env)->NewByteArray(env, path->fNumberOfSegments);
AWT_FONT_CLEANUP_CHECK(pointTypes);
(*env)->SetByteArrayRegion(env, pointTypes, 0, path->fNumberOfSegments, (jbyte*)path->fSegmentType);
! static JNF_CLASS_CACHE(jc_GeneralPath, "java/awt/geom/GeneralPath");
! static JNF_CTOR_CACHE(jc_GeneralPath_ctor, jc_GeneralPath, "(I[BI[FI)V");
! generalPath = JNFNewObject(env, jc_GeneralPath_ctor, java_awt_geom_PathIterator_WIND_NON_ZERO, pointTypes, path->fNumberOfSegments, pointCoords, path->fNumberOfDataElements); // AWT_THREADING Safe (known object)
// Cleanup
cleanup:
if (path != NULL) {
AWTPathFree(path);
--- 266,277 ----
pointTypes = (*env)->NewByteArray(env, path->fNumberOfSegments);
AWT_FONT_CLEANUP_CHECK(pointTypes);
(*env)->SetByteArrayRegion(env, pointTypes, 0, path->fNumberOfSegments, (jbyte*)path->fSegmentType);
! generalPath = (*env)->NewObject(env, jc_GeneralPath, jc_GeneralPath_ctor, java_awt_geom_PathIterator_WIND_NON_ZERO, pointTypes,
! path->fNumberOfSegments, pointCoords, path->fNumberOfDataElements); // AWT_THREADING Safe (known object)
// Cleanup
cleanup:
if (path != NULL) {
AWTPathFree(path);
*** 283,293 ****
(*env)->DeleteLocalRef(env, pointTypes);
pointTypes = NULL;
}
AWT_FONT_CLEANUP_FINISH;
! JNF_COCOA_EXIT(env);
return generalPath;
}
/*
* Class: sun_font_CStrike
--- 287,297 ----
(*env)->DeleteLocalRef(env, pointTypes);
pointTypes = NULL;
}
AWT_FONT_CLEANUP_FINISH;
! JNI_COCOA_EXIT(env);
return generalPath;
}
/*
* Class: sun_font_CStrike
*** 298,308 ****
Java_sun_font_CStrike_getGlyphImagePtrsNative
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jlongArray glyphInfoLongArray,
jintArray glyphCodes, jint len)
{
! JNF_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
jlong *glyphInfos =
(*env)->GetPrimitiveArrayCritical(env, glyphInfoLongArray, NULL);
--- 302,312 ----
Java_sun_font_CStrike_getGlyphImagePtrsNative
(JNIEnv *env, jclass clazz,
jlong awtStrikePtr, jlongArray glyphInfoLongArray,
jintArray glyphCodes, jint len)
{
! JNI_COCOA_ENTER(env);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
jlong *glyphInfos =
(*env)->GetPrimitiveArrayCritical(env, glyphInfoLongArray, NULL);
*** 326,336 ****
(*env)->ReleasePrimitiveArrayCritical(env, glyphInfoLongArray,
glyphInfos, 0);
}
}
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: createNativeStrikePtr
--- 330,340 ----
(*env)->ReleasePrimitiveArrayCritical(env, glyphInfoLongArray,
glyphInfos, 0);
}
}
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: createNativeStrikePtr
*** 338,348 ****
*/
JNIEXPORT jlong JNICALL Java_sun_font_CStrike_createNativeStrikePtr
(JNIEnv *env, jclass clazz, jlong nativeFontPtr, jdoubleArray glyphTxArray, jdoubleArray invDevTxArray, jint aaStyle, jint fmHint)
{
AWTStrike *awtStrike = nil;
! JNF_COCOA_ENTER(env);
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(nativeFontPtr);
JRSFontRenderingStyle style = JRSFontGetRenderingStyleForHints(fmHint, aaStyle);
CGAffineTransform glyphTx = GetTxFromDoubles(env, glyphTxArray);
--- 342,352 ----
*/
JNIEXPORT jlong JNICALL Java_sun_font_CStrike_createNativeStrikePtr
(JNIEnv *env, jclass clazz, jlong nativeFontPtr, jdoubleArray glyphTxArray, jdoubleArray invDevTxArray, jint aaStyle, jint fmHint)
{
AWTStrike *awtStrike = nil;
! JNI_COCOA_ENTER(env);
AWTFont *awtFont = (AWTFont *)jlong_to_ptr(nativeFontPtr);
JRSFontRenderingStyle style = JRSFontGetRenderingStyleForHints(fmHint, aaStyle);
CGAffineTransform glyphTx = GetTxFromDoubles(env, glyphTxArray);
*** 353,363 ****
if (awtStrike)
{
CFRetain(awtStrike); // GC
}
! JNF_COCOA_EXIT(env);
return ptr_to_jlong(awtStrike);
}
/*
* Class: sun_font_CStrike
--- 357,367 ----
if (awtStrike)
{
CFRetain(awtStrike); // GC
}
! JNI_COCOA_EXIT(env);
return ptr_to_jlong(awtStrike);
}
/*
* Class: sun_font_CStrike
*** 366,382 ****
*/
JNIEXPORT void JNICALL
Java_sun_font_CStrike_disposeNativeStrikePtr
(JNIEnv *env, jclass clazz, jlong awtStrike)
{
! JNF_COCOA_ENTER(env);
if (awtStrike) {
CFRelease((AWTStrike *)jlong_to_ptr(awtStrike)); // GC
}
! JNF_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: getFontMetrics
--- 370,386 ----
*/
JNIEXPORT void JNICALL
Java_sun_font_CStrike_disposeNativeStrikePtr
(JNIEnv *env, jclass clazz, jlong awtStrike)
{
! JNI_COCOA_ENTER(env);
if (awtStrike) {
CFRelease((AWTStrike *)jlong_to_ptr(awtStrike)); // GC
}
! JNI_COCOA_EXIT(env);
}
/*
* Class: sun_font_CStrike
* Method: getFontMetrics
*** 386,396 ****
Java_sun_font_CStrike_getFontMetrics
(JNIEnv *env, jclass clazz, jlong awtStrikePtr)
{
jobject metrics = NULL;
! JNF_COCOA_ENTER(env);
AWT_FONT_CLEANUP_SETUP;
AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;
AWT_FONT_CLEANUP_CHECK(awtfont);
--- 390,400 ----
Java_sun_font_CStrike_getFontMetrics
(JNIEnv *env, jclass clazz, jlong awtStrikePtr)
{
jobject metrics = NULL;
! JNI_COCOA_ENTER(env);
AWT_FONT_CLEANUP_SETUP;
AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;
AWT_FONT_CLEANUP_CHECK(awtfont);
*** 421,439 ****
* leadingX: no need to set leadingX - it will be zero.
* leadingY: made-up number, but being compatible with what 1.4.x did.
* advance: no need to set yMaxLinearAdvanceWidth - it will be zero.
*/
! JNF_CLASS_CACHE(sjc_StrikeMetrics, "sun/font/StrikeMetrics");
! JNF_CTOR_CACHE(strikeMetricsCtr, sjc_StrikeMetrics, "(FFFFFFFFFF)V");
! metrics = JNFNewObject(env, strikeMetricsCtr,
0.0, ay, 0.0, dy, 1.0,
0.0, 0.0, ly, mx, 0.0);
cleanup:
AWT_FONT_CLEANUP_FINISH;
! JNF_COCOA_EXIT(env);
return metrics;
}
extern void AccelGlyphCache_RemoveAllInfos(GlyphInfo* glyph);
--- 425,443 ----
* leadingX: no need to set leadingX - it will be zero.
* leadingY: made-up number, but being compatible with what 1.4.x did.
* advance: no need to set yMaxLinearAdvanceWidth - it will be zero.
*/
! DECLARE_CLASS_RETURN(sjc_StrikeMetrics, "sun/font/StrikeMetrics", NULL);
! DECLARE_METHOD_RETURN(strikeMetricsCtr, sjc_StrikeMetrics, "<init>", "(FFFFFFFFFF)V", NULL);
! metrics = (*env)->NewObject(env, sjc_StrikeMetrics, strikeMetricsCtr,
0.0, ay, 0.0, dy, 1.0,
0.0, 0.0, ly, mx, 0.0);
cleanup:
AWT_FONT_CLEANUP_FINISH;
! JNI_COCOA_EXIT(env);
return metrics;
}
extern void AccelGlyphCache_RemoveAllInfos(GlyphInfo* glyph);
*** 443,453 ****
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_sun_font_CStrikeDisposer_removeGlyphInfoFromCache
(JNIEnv *env, jclass cls, jlong glyphInfo)
{
! JNF_COCOA_ENTER(env);
AccelGlyphCache_RemoveAllCellInfos((GlyphInfo*)jlong_to_ptr(glyphInfo));
! JNF_COCOA_EXIT(env);
}
--- 447,457 ----
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_sun_font_CStrikeDisposer_removeGlyphInfoFromCache
(JNIEnv *env, jclass cls, jlong glyphInfo)
{
! JNI_COCOA_ENTER(env);
AccelGlyphCache_RemoveAllCellInfos((GlyphInfo*)jlong_to_ptr(glyphInfo));
! JNI_COCOA_EXIT(env);
}
< prev index next >