Package: openjdk-7-jre
Version: 7~b147-2.0-1
Severity: normal
Dear Maintainer,
OpenJDK returns incorrect TrueType font height (greater than real value)
under some conditions, this makes JasperReports (Java reporting library)
not to work correctly on OpenJDK 6/7.
Problem
=======
On OpenJDK JRE and using some TrueType font, JasperReports does not
display text element which height is just the same as the font size
eg. { height="8", size="8", font="IPA mincho" }.
JasperReports checks the text size before drawing the text elements.
If (ascent + descent) of text is greater than the height of text
element, this text is not drawn.
In above case, Sun Java returns the same height (ascent + descent =
fontsize), but OpenJDK returns the text height greater than font size,
so not drawn.
Sample code (includes Japanese char)
===================================
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
public class JavaApplication1 {
public static void main(String[] args) throws Exception {
Font f = new Font("IPA明朝",Font.PLAIN, 8);
TextLayout layout = new TextLayout("IPA明朝", f,
new FontRenderContext(null, true, true));
System.out.println("Ascent: " + layout.getAscent());
System.out.println("Descent: " + layout.getDescent());
}
}
Result of this code
===================
Sun Java 6 (sun-java6-jre 6.26-0squeeze1)
> Ascent: 7.0390625
> Descent: 0.9609375
OpenJDK 6 (openjdk-6-jre 6b24~pre2-1)
> Ascent: 7.046875
> Descent: 0.96875
OpenJDK 7 (openjdk-7-jre 7~b147-2.0-1)
> Ascent: 7.046875
> Descent: 0.96875
Sun Java returns correct height, but OpenJDK returns greater value
than Sun's.
Analysis of Source code
=======================
In OpenJDK6/7 native method sun.font.FreetypeFontScaler.getFontMetricsNative():
jdk/src/share/native/sun/font/freetypeScaler.c
>JNIEXPORT jobject JNICALL
>Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
> JNIEnv *env, jobject scaler, jobject font2D,
> jlong pScalerContext, jlong pScaler) {
(snip)
> /* ascent */
> ax = 0;
> ay = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
> ((jlong) scalerInfo->face->ascender + bmodifier/2),
> (jlong) scalerInfo->face->size->metrics.y_scale));
> /* descent */
> dx = 0;
> dy = -(jfloat) FT26Dot6ToFloat(FT_MulFix(
> ((jlong) scalerInfo->face->descender + bmodifier/2),
> (jlong) scalerInfo->face->size->metrics.y_scale));
(snip)
> metrics = (*env)->NewObject(env,
> sunFontIDs.strikeMetricsClass,
> sunFontIDs.strikeMetricsCtr,
> ax, ay, dx, dy, bx, by, lx, ly, mx, my);
>
> return metrics;
>}
This code uses FT_MulFix to convert size. But FT_MulFix sometimes rounds
up and loses precision.
In FreeType2's FT_MulFix:
freetype-2.4.8/src/base/ftcalc.c
> c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
If both ascent and descent are rounded up, (ascent + descent) is greater
than original height.
In the sample case (IPA mincho font),
bmodifier = 0
scalerInfo->face->ascender = 1802L
scalerInfo->face->descender = -246L
scalerInfo->face->size->metrics.y_scale = 16384L
In this case, 1802 mod 4 = 2 and 246 mod 4 = 2, so both are rounded up.
This causes (ay + dy) > font-size.
(Note: (Sun) 1802.0/256.0 = 7.0390625, (OpenJDK) 1804.0/256.0 = 7.046875)
Suggested fix
=============
Fix to keep the precision in the font metrics conversion in
Java_sun_font_FreetypeFontScaler_getFontMetricsNative().
Version of packages
===================
OpenJDK:
see below.
JasperReports:
upstream 4.1.3 jar.
IPA TrueType fonts:
ii fonts-ipafont 00303-5
ii fonts-ipafont-gothic 00303-5
ii fonts-ipafont-mincho 00303-5
Reportbug output
================
-- System Information:
Debian Release: wheezy/sid
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 3.1.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages openjdk-7-jre depends on:
ii libaccess-bridge-java-jni 1.26.2-8
ii libasound2 1.0.24.1-4
ii libatk1.0-0 2.2.0-2
ii libc6 2.13-24
ii libcairo2 1.10.2-6.2
ii libcups2 1.5.0-13
ii libfontconfig1 2.8.0-3
ii libfreetype6 2.4.8-1
ii libgdk-pixbuf2.0-0 2.24.0-2
ii libgif4 4.1.6-9
ii libglib2.0-0 2.30.2-4
ii libgtk2.0-0 2.24.8-3
ii libjpeg8 8c-2
ii libpango1.0-0 1.29.4-2
ii libpng12-0 1.2.46-4
ii libpulse0 1.0-4
ii libx11-6 2:1.4.4-4
ii libxext6 2:1.3.0-3
ii libxi6 2:1.4.5-1
ii libxrender1 1:0.9.6-2
ii libxtst6 2:1.2.0-4
ii openjdk-7-jre-headless 7~b147-2.0-1
ii zlib1g 1:1.2.3.4.dfsg-3
Versions of packages openjdk-7-jre recommends:
ii ttf-dejavu-extra 2.33-2
Versions of packages openjdk-7-jre suggests:
pn icedtea6-plugin <none>
-- no debconf information
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]