mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-2419 Improve performance of CStrike.getNativeGlyphOutlineBounds
Do not pass the result via java object. Use more straight api. (cherry picked from commit9f91fe91f5) (cherry picked from commitc0fd2daf5c)
This commit is contained in:
committed by
alexey.ushakov@jetbrains.com
parent
87b8abb4ea
commit
1c62928bad
@@ -62,8 +62,7 @@ public final class CStrike extends PhysicalStrike {
|
||||
|
||||
private static native void getNativeGlyphOutlineBounds(long nativeStrikePtr,
|
||||
int glyphCode,
|
||||
Rectangle.Float result,
|
||||
double x, double y);
|
||||
float [] rectData);
|
||||
|
||||
// returns the bounding rect for a glyph
|
||||
private static native void getNativeGlyphImageBounds(long nativeStrikePtr,
|
||||
@@ -178,9 +177,9 @@ public final class CStrike extends PhysicalStrike {
|
||||
}
|
||||
|
||||
Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) {
|
||||
Rectangle2D.Float r2df = new Rectangle2D.Float();
|
||||
getNativeGlyphOutlineBounds(getNativeStrikePtr(), glyphCode, r2df, 0, 0);
|
||||
return r2df;
|
||||
final float [] rectData = new float[4];
|
||||
getNativeGlyphOutlineBounds(getNativeStrikePtr(), glyphCode, rectData);
|
||||
return new Rectangle2D.Float(rectData[0], rectData[1], rectData[2], rectData[3]);
|
||||
}
|
||||
|
||||
// pt, result in device space
|
||||
|
||||
@@ -305,7 +305,7 @@ JNI_COCOA_EXIT(env);
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_sun_font_CStrike_getNativeGlyphOutlineBounds
|
||||
(JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode,
|
||||
jobject result, jdouble xPos, jdouble yPos)
|
||||
jfloatArray rectData)
|
||||
{
|
||||
JNI_COCOA_ENTER(env);
|
||||
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
|
||||
@@ -319,34 +319,30 @@ JNIEXPORT void JNICALL Java_sun_font_CStrike_getNativeGlyphOutlineBounds
|
||||
const CTFontRef font = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(
|
||||
awtfont, glyphCode, &glyph);
|
||||
|
||||
CGRect bbox = CTFontGetBoundingRectsForGlyphs(
|
||||
font, kCTFontOrientationDefault, &glyph, NULL, 1);
|
||||
|
||||
CGAffineTransform tx = CGAffineTransformConcat(awtStrike->fTx,
|
||||
sInverseTX);
|
||||
|
||||
CGPathRef cgPath = CTFontCreatePathForGlyph((CTFontRef) font, glyph,
|
||||
&tx);
|
||||
|
||||
CGRect bbox = CGPathGetPathBoundingBox(cgPath);
|
||||
bbox = CGRectApplyAffineTransform (bbox, tx);
|
||||
CFRelease(font);
|
||||
CGPathRelease(cgPath);
|
||||
jfloat *rawRectData =
|
||||
(*env)->GetPrimitiveArrayCritical(env, rectData, NULL);
|
||||
|
||||
if (CGRectIsNull(bbox)) {
|
||||
bbox.origin.x = 0;
|
||||
bbox.origin.y = 0;
|
||||
bbox.size.width = 0;
|
||||
bbox.size.height = 0;
|
||||
rawRectData[0] = 0.0f;
|
||||
rawRectData[1] = 0.0f;
|
||||
rawRectData[2] = 0.0f;
|
||||
rawRectData[3] = 0.0f;
|
||||
} else {
|
||||
rawRectData[0] = (jfloat) bbox.origin.x;
|
||||
rawRectData[1] = (jfloat) (-bbox.origin.y - bbox.size.height);
|
||||
rawRectData[2] = (jfloat) bbox.size.width;
|
||||
rawRectData[3] = (jfloat) bbox.size.height;
|
||||
}
|
||||
|
||||
DECLARE_CLASS(sjc_Rectangle2D_Float,
|
||||
"java/awt/geom/Rectangle2D$Float");
|
||||
DECLARE_METHOD(sjr_Rectangle2DFloat_setRect,
|
||||
sjc_Rectangle2D_Float, "setRect", "(FFFF)V");
|
||||
|
||||
(*env)->CallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect,
|
||||
(jfloat) (bbox.origin.x + xPos),
|
||||
(jfloat) (yPos - bbox.origin.y - bbox.size.height),
|
||||
(jfloat) bbox.size.width,
|
||||
(jfloat) bbox.size.height);
|
||||
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, rectData, rawRectData, 0);
|
||||
// Cleanup
|
||||
cleanup:
|
||||
AWT_FONT_CLEANUP_FINISH;
|
||||
|
||||
Reference in New Issue
Block a user