Skip to content

Commit 5d35e72

Browse files
committed
JBR-1761 Printing a comment block in landscape mode results in oddly rotated italic letters
1 parent cf7d535 commit 5d35e72

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,40 @@ static void setupLoadRenderFlags(FTScalerContext *context, int fcHintStyle, FcBo
662662
}
663663
#endif
664664

665+
// values used by FreeType (as of version 2.10.1) for italics transformation matrix in FT_GlyphSlot_Oblique
666+
#define FT_MATRIX_ONE 0x10000
667+
#define FT_MATRIX_OBLIQUE_XY 0x0366A
668+
669+
static void setupTransform(FT_Matrix* target, FTScalerContext *context) {
670+
FT_Matrix* transform = &context->transform;
671+
if (context->doItalize) {
672+
// we cannot use FT_GlyphSlot_Oblique as it doesn't work well with arbitrary transforms,
673+
// so we add corresponding shear transform to the requested glyph transformation
674+
target->xx = FT_MATRIX_ONE;
675+
target->xy = FT_MATRIX_OBLIQUE_XY;
676+
target->yx = 0;
677+
target->yy = FT_MATRIX_ONE;
678+
FT_Matrix_Multiply(transform, target);
679+
} else {
680+
target->xx = transform->xx;
681+
target->xy = transform->xy;
682+
target->yx = transform->yx;
683+
target->yy = transform->yy;
684+
}
685+
}
686+
665687
static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo, FTScalerContext *context,
666688
FT_Bool configureFont) {
689+
FT_Matrix matrix;
667690
int errCode = 0;
668691
scalerInfo->env = env;
669692
scalerInfo->font2D = font2D;
670693

671694
if (context != NULL) {
672-
FT_UInt dpi = (FT_UInt) getScreenResolution(env);
673-
FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
695+
setupTransform(&matrix, context);
696+
FT_Set_Transform(scalerInfo->face, &matrix, NULL);
674697

698+
FT_UInt dpi = (FT_UInt) getScreenResolution(env);
675699
errCode = FT_Set_Char_Size(scalerInfo->face, 0, ADJUST_FONT_SIZE(context->ptsz, dpi), dpi, dpi);
676700
if (errCode) return errCode;
677701

@@ -869,11 +893,8 @@ static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo,
869893
return 0;
870894
}
871895

872-
/* ftsynth.c uses (0x10000, 0x0366A, 0x0, 0x10000) matrix to get oblique
873-
outline. Therefore x coordinate will change by 0x0366A*y.
874-
Note that y coordinate does not change. These values are based on
875-
libfreetype version 2.9.1. */
876-
#define OBLIQUE_MODIFIER(y) (context->doItalize ? ((y)*0x366A/0x10000) : 0)
896+
// using same values as for the transformation matrix
897+
#define OBLIQUE_MODIFIER(y) (context->doItalize ? ((y)*FT_MATRIX_OBLIQUE_XY/FT_MATRIX_ONE) : 0)
877898

878899
/* FT_GlyphSlot_Embolden (ftsynth.c) uses FT_MulFix(units_per_EM, y_scale) / 24
879900
* strength value when glyph format is FT_GLYPH_FORMAT_OUTLINE. This value has
@@ -1242,9 +1263,6 @@ Java_sun_font_FreetypeFontScaler_getGlyphImageNative(
12421263
if (context->doBold) { /* if bold style */
12431264
FT_GlyphSlot_Embolden(ftglyph);
12441265
}
1245-
if (context->doItalize) { /* if oblique */
1246-
FT_GlyphSlot_Oblique(ftglyph);
1247-
}
12481266

12491267
/* generate bitmap if it is not done yet
12501268
e.g. if algorithmic styling is performed and style was added to outline */
@@ -1470,9 +1488,6 @@ static FT_Outline* getFTOutline(JNIEnv* env, jobject font2D,
14701488
if (context->doBold) { /* if bold style */
14711489
FT_GlyphSlot_Embolden(ftglyph);
14721490
}
1473-
if (context->doItalize) { /* if oblique */
1474-
FT_GlyphSlot_Oblique(ftglyph);
1475-
}
14761491

14771492
FT_Outline_Translate(&ftglyph->outline,
14781493
FloatToF26Dot6(xpos),

0 commit comments

Comments
 (0)