src/share/native/sun/font/freetypeScaler.c

Print this page




 425 }
 426 
 427 /* ftsynth.c uses (0x10000, 0x06000, 0x0, 0x10000) matrix to get oblique
 428    outline.  Therefore x coordinate will change by 0x06000*y.
 429    Note that y coordinate does not change. */
 430 #define OBLIQUE_MODIFIER(y)  (context->doItalize ? ((y)*6/16) : 0)
 431 
 432 /*
 433  * Class:     sun_font_FreetypeFontScaler
 434  * Method:    getFontMetricsNative
 435  * Signature: (Lsun/font/Font2D;J)Lsun/font/StrikeMetrics;
 436  */
 437 JNIEXPORT jobject JNICALL
 438 Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
 439         JNIEnv *env, jobject scaler, jobject font2D,
 440         jlong pScalerContext, jlong pScaler) {
 441 
 442     jobject metrics;
 443     jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my;
 444     jfloat f0 = 0.0;
 445     FT_Pos bmodifier = 0;
 446     FTScalerContext *context =
 447         (FTScalerContext*) jlong_to_ptr(pScalerContext);
 448     FTScalerInfo *scalerInfo =
 449              (FTScalerInfo*) jlong_to_ptr(pScaler);
 450 
 451     int errCode;
 452 
 453     if (isNullScalerContext(context) || scalerInfo == NULL) {
 454         return (*env)->NewObject(env,
 455                                  sunFontIDs.strikeMetricsClass,
 456                                  sunFontIDs.strikeMetricsCtr,
 457                                  f0, f0, f0, f0, f0, f0, f0, f0, f0, f0);
 458     }
 459 
 460     errCode = setupFTContext(env, font2D, scalerInfo, context);
 461 
 462     if (errCode) {
 463         metrics = (*env)->NewObject(env,
 464                                  sunFontIDs.strikeMetricsClass,
 465                                  sunFontIDs.strikeMetricsCtr,
 466                                  f0, f0, f0, f0, f0, f0, f0, f0, f0, f0);
 467         invalidateJavaScaler(env, scaler, scalerInfo);
 468         return metrics;
 469     }
 470 
 471     /* This is ugly and has to be reworked.
 472        Freetype provide means to add style to glyph but
 473        it seems there is no way to adjust metrics accordingly.
 474 
 475        So, we have to do adust them explicitly and stay consistent with what
 476        freetype does to outlines. */
 477 
 478     /* For bolding glyphs are not just widened. Height is also changed
 479        (see ftsynth.c).
 480 
 481        TODO: In vertical direction we could do better job and adjust metrics
 482        proportionally to glyoh shape. */
 483     if (context->doBold) {
 484         bmodifier = FT_MulFix(
 485                        scalerInfo->face->units_per_EM,
 486                        scalerInfo->face->size->metrics.y_scale)/24;
 487     }
 488 
 489 
 490     /**** Note: only some metrics are affected by styling ***/
 491 







 492     /* ascent */
 493     ax = 0;
 494     ay = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
 495                        ((jlong) scalerInfo->face->ascender + bmodifier/2),
 496                        (jlong) scalerInfo->face->size->metrics.y_scale));
 497     /* descent */
 498     dx = 0;
 499     dy = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
 500                        ((jlong) scalerInfo->face->descender + bmodifier/2),
 501                        (jlong) scalerInfo->face->size->metrics.y_scale));
 502     /* baseline */
 503     bx = by = 0;
 504 
 505     /* leading */
 506     lx = 0;
 507     ly = (jfloat) FT26Dot6ToFloat(FT_MulFix(
 508                       (jlong) scalerInfo->face->height + bmodifier,
 509                       (jlong) scalerInfo->face->size->metrics.y_scale))
 510                   + ay - dy;
 511     /* max advance */
 512     mx = (jfloat) FT26Dot6ToFloat(
 513                      scalerInfo->face->size->metrics.max_advance +
 514                      2*bmodifier +
 515                      OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height));
 516     my = 0;
 517 
 518     metrics = (*env)->NewObject(env,
 519                                 sunFontIDs.strikeMetricsClass,
 520                                 sunFontIDs.strikeMetricsCtr,
 521                                 ax, ay, dx, dy, bx, by, lx, ly, mx, my);
 522 
 523     return metrics;
 524 }
 525 
 526 /*
 527  * Class:     sun_font_FreetypeFontScaler
 528  * Method:    getGlyphAdvanceNative
 529  * Signature: (Lsun/font/Font2D;JI)F
 530  */
 531 JNIEXPORT jfloat JNICALL
 532 Java_sun_font_FreetypeFontScaler_getGlyphAdvanceNative(
 533         JNIEnv *env, jobject scaler, jobject font2D,
 534         jlong pScalerContext, jlong pScaler, jint glyphCode) {




 425 }
 426 
 427 /* ftsynth.c uses (0x10000, 0x06000, 0x0, 0x10000) matrix to get oblique
 428    outline.  Therefore x coordinate will change by 0x06000*y.
 429    Note that y coordinate does not change. */
 430 #define OBLIQUE_MODIFIER(y)  (context->doItalize ? ((y)*6/16) : 0)
 431 
 432 /*
 433  * Class:     sun_font_FreetypeFontScaler
 434  * Method:    getFontMetricsNative
 435  * Signature: (Lsun/font/Font2D;J)Lsun/font/StrikeMetrics;
 436  */
 437 JNIEXPORT jobject JNICALL
 438 Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
 439         JNIEnv *env, jobject scaler, jobject font2D,
 440         jlong pScalerContext, jlong pScaler) {
 441 
 442     jobject metrics;
 443     jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my;
 444     jfloat f0 = 0.0;

 445     FTScalerContext *context =
 446         (FTScalerContext*) jlong_to_ptr(pScalerContext);
 447     FTScalerInfo *scalerInfo =
 448              (FTScalerInfo*) jlong_to_ptr(pScaler);
 449 
 450     int errCode;
 451 
 452     if (isNullScalerContext(context) || scalerInfo == NULL) {
 453         return (*env)->NewObject(env,
 454                                  sunFontIDs.strikeMetricsClass,
 455                                  sunFontIDs.strikeMetricsCtr,
 456                                  f0, f0, f0, f0, f0, f0, f0, f0, f0, f0);
 457     }
 458 
 459     errCode = setupFTContext(env, font2D, scalerInfo, context);
 460 
 461     if (errCode) {
 462         metrics = (*env)->NewObject(env,
 463                                  sunFontIDs.strikeMetricsClass,
 464                                  sunFontIDs.strikeMetricsCtr,
 465                                  f0, f0, f0, f0, f0, f0, f0, f0, f0, f0);
 466         invalidateJavaScaler(env, scaler, scalerInfo);
 467         return metrics;
 468     }
 469 
 470     /* This is ugly and has to be reworked.
 471        Freetype provide means to add style to glyph but
 472        it seems there is no way to adjust metrics accordingly.
 473 
 474        So, we have to do adust them explicitly and stay consistent with what
 475        freetype does to outlines. */
 476 











 477 
 478     /**** Note: only some metrics are affected by styling ***/
 479 
 480     /* See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657854 */
 481 #define FT_MulFixFloatShift6(a, b) (((float) (a)) * ((float) (b)) / 65536.0 / 64.0)
 482 
 483     /*
 484      * See FreeType source code: src/base/ftobjs.c ft_recompute_scaled_metrics()
 485      * http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1659
 486      */
 487     /* ascent */
 488     ax = 0;
 489     ay = -(jfloat) (FT_MulFixFloatShift6(
 490                        ((jlong) scalerInfo->face->ascender),
 491                        (jlong) scalerInfo->face->size->metrics.y_scale));
 492     /* descent */
 493     dx = 0;
 494     dy = -(jfloat) (FT_MulFixFloatShift6(
 495                        ((jlong) scalerInfo->face->descender),
 496                        (jlong) scalerInfo->face->size->metrics.y_scale));
 497     /* baseline */
 498     bx = by = 0;
 499 
 500     /* leading */
 501     lx = 0;
 502     ly = (jfloat) (FT_MulFixFloatShift6(
 503                       (jlong) scalerInfo->face->height,
 504                       (jlong) scalerInfo->face->size->metrics.y_scale))
 505                   + ay - dy;
 506     /* max advance */
 507     mx = (jfloat) FT26Dot6ToFloat(
 508                      scalerInfo->face->size->metrics.max_advance +

 509                      OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height));
 510     my = 0;
 511 
 512     metrics = (*env)->NewObject(env,
 513                                 sunFontIDs.strikeMetricsClass,
 514                                 sunFontIDs.strikeMetricsCtr,
 515                                 ax, ay, dx, dy, bx, by, lx, ly, mx, my);
 516 
 517     return metrics;
 518 }
 519 
 520 /*
 521  * Class:     sun_font_FreetypeFontScaler
 522  * Method:    getGlyphAdvanceNative
 523  * Signature: (Lsun/font/Font2D;JI)F
 524  */
 525 JNIEXPORT jfloat JNICALL
 526 Java_sun_font_FreetypeFontScaler_getGlyphAdvanceNative(
 527         JNIEnv *env, jobject scaler, jobject font2D,
 528         jlong pScalerContext, jlong pScaler, jint glyphCode) {