< prev index next >

src/java.desktop/share/native/libfontmanager/freetypeScaler.c

Print this page
rev 53953 : 8218854: FontMetrics.getMaxAdvance may be less than the maximum FontMetrics.charWidth
Summary: Consider algorithmic bold in FontMetrics.getMaxAdvance value and update obliqueness.
Reviewed-by: prr, serb
   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 388     int errCode = 0;
 389 
 390     scalerInfo->env = env;
 391     scalerInfo->font2D = font2D;
 392 
 393     if (context != NULL) {
 394         FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
 395 
 396         errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
 397 
 398         if (errCode == 0) {
 399             errCode = FT_Activate_Size(scalerInfo->face->size);
 400         }
 401 
 402         FT_Library_SetLcdFilter(scalerInfo->library, FT_LCD_FILTER_DEFAULT);
 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;


 478     ay = -(jfloat) (FT_MulFixFloatShift6(
 479                        ((jlong) scalerInfo->face->ascender),
 480                        (jlong) scalerInfo->face->size->metrics.y_scale));
 481     /* descent */
 482     dx = 0;
 483     dy = -(jfloat) (FT_MulFixFloatShift6(
 484                        ((jlong) scalerInfo->face->descender),
 485                        (jlong) scalerInfo->face->size->metrics.y_scale));
 486     /* baseline */
 487     bx = by = 0;
 488 
 489     /* leading */
 490     lx = 0;
 491     ly = (jfloat) (FT_MulFixFloatShift6(
 492                       (jlong) scalerInfo->face->height,
 493                       (jlong) scalerInfo->face->size->metrics.y_scale))
 494                   + ay - dy;
 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,
 502         sunFontIDs.strikeMetricsClass,
 503         sunFontIDs.strikeMetricsCtr,
 504         contextAwareMetricsX(ax, ay), contextAwareMetricsY(ax, ay),
 505         contextAwareMetricsX(dx, dy), contextAwareMetricsY(dx, dy),
 506         bx, by,
 507         contextAwareMetricsX(lx, ly), contextAwareMetricsY(lx, ly),
 508         contextAwareMetricsX(mx, my), contextAwareMetricsY(mx, my));
 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


   1 /*
   2  * Copyright (c) 2007, 2019, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 388     int errCode = 0;
 389 
 390     scalerInfo->env = env;
 391     scalerInfo->font2D = font2D;
 392 
 393     if (context != NULL) {
 394         FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
 395 
 396         errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
 397 
 398         if (errCode == 0) {
 399             errCode = FT_Activate_Size(scalerInfo->face->size);
 400         }
 401 
 402         FT_Library_SetLcdFilter(scalerInfo->library, FT_LCD_FILTER_DEFAULT);
 403     }
 404 
 405     return errCode;
 406 }
 407 
 408 /* ftsynth.c uses (0x10000, 0x0366A, 0x0, 0x10000) matrix to get oblique
 409    outline.  Therefore x coordinate will change by 0x0366A*y.
 410    Note that y coordinate does not change. These values are based on
 411    libfreetype version 2.9.1. */
 412 #define OBLIQUE_MODIFIER(y)  (context->doItalize ? ((y)*0x366A/0x10000) : 0)
 413 
 414 /* FT_GlyphSlot_Embolden (ftsynth.c) uses FT_MulFix(units_per_EM, y_scale) / 24
 415  * strength value when glyph format is FT_GLYPH_FORMAT_OUTLINE. This value has
 416  * been taken from libfreetype version 2.6 and remain valid at least up to
 417  * 2.9.1. */
 418 #define BOLD_MODIFIER(units_per_EM, y_scale) \
 419     (context->doBold ? FT_MulFix(units_per_EM, y_scale) / 24 : 0)
 420 
 421 /*
 422  * Class:     sun_font_FreetypeFontScaler
 423  * Method:    getFontMetricsNative
 424  * Signature: (Lsun/font/Font2D;J)Lsun/font/StrikeMetrics;
 425  */
 426 JNIEXPORT jobject JNICALL
 427 Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
 428         JNIEnv *env, jobject scaler, jobject font2D,
 429         jlong pScalerContext, jlong pScaler) {
 430 
 431     jobject metrics;
 432     jfloat ax, ay, dx, dy, bx, by, lx, ly, mx, my;
 433     jfloat f0 = 0.0;
 434     FTScalerContext *context =
 435         (FTScalerContext*) jlong_to_ptr(pScalerContext);
 436     FTScalerInfo *scalerInfo =
 437              (FTScalerInfo*) jlong_to_ptr(pScaler);
 438 
 439     int errCode;


 486     ay = -(jfloat) (FT_MulFixFloatShift6(
 487                        ((jlong) scalerInfo->face->ascender),
 488                        (jlong) scalerInfo->face->size->metrics.y_scale));
 489     /* descent */
 490     dx = 0;
 491     dy = -(jfloat) (FT_MulFixFloatShift6(
 492                        ((jlong) scalerInfo->face->descender),
 493                        (jlong) scalerInfo->face->size->metrics.y_scale));
 494     /* baseline */
 495     bx = by = 0;
 496 
 497     /* leading */
 498     lx = 0;
 499     ly = (jfloat) (FT_MulFixFloatShift6(
 500                       (jlong) scalerInfo->face->height,
 501                       (jlong) scalerInfo->face->size->metrics.y_scale))
 502                   + ay - dy;
 503     /* max advance */
 504     mx = (jfloat) FT26Dot6ToFloat(
 505                      scalerInfo->face->size->metrics.max_advance +
 506                      OBLIQUE_MODIFIER(scalerInfo->face->size->metrics.height) +
 507                      BOLD_MODIFIER(scalerInfo->face->units_per_EM,
 508                              scalerInfo->face->size->metrics.y_scale));
 509     my = 0;
 510 
 511     metrics = (*env)->NewObject(env,
 512         sunFontIDs.strikeMetricsClass,
 513         sunFontIDs.strikeMetricsCtr,
 514         contextAwareMetricsX(ax, ay), contextAwareMetricsY(ax, ay),
 515         contextAwareMetricsX(dx, dy), contextAwareMetricsY(dx, dy),
 516         bx, by,
 517         contextAwareMetricsX(lx, ly), contextAwareMetricsY(lx, ly),
 518         contextAwareMetricsX(mx, my), contextAwareMetricsY(mx, my));
 519 
 520     return metrics;
 521 }
 522 
 523 /*
 524  * Class:     sun_font_FreetypeFontScaler
 525  * Method:    getGlyphAdvanceNative
 526  * Signature: (Lsun/font/Font2D;JI)F
 527  */
 528 JNIEXPORT jfloat JNICALL


< prev index next >