JDK-8328896 : Fontmetrics for large Fonts has zero width
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 14,17.0.5,22,23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2024-03-21
  • Updated: 2024-04-29
  • Resolved: 2024-04-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23 b20Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Occurs on Windows and Linux.

A DESCRIPTION OF THE PROBLEM :
In Java 17.0.10 the font metrics returns a string width of zero for large font size. Moreover, every subsequent call for that font metrics with "normal" size will also return zero width, unless that size was requested before the "breaking" one.

Seems to be related to https://bugs.openjdk.org/browse/JDK-8233097

REGRESSION : Last worked in version 11

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Build and run the source code


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
size 12 width 58.02
size 100,000 width 24,744.094
size 7 width 33.845
size 8 width 38.68
size 9 width 43.515
size 10 width 48.35
size 11 width 53.185
size 12 width 58.02
size 14 width 67.689
size 16 width 77.359
size 18 width 87.029
size 20 width 96.699
size 24 width 116.039
ACTUAL -
size 12 width 58.02
size 100,000 width 0
size 7 width 0
size 8 width 0
size 9 width 0
size 10 width 0
size 11 width 0
size 12 width 58.02
size 14 width 0
size 16 width 0
size 18 width 0
size 20 width 0
size 24 width 0

---------- BEGIN SOURCE ----------
    public static void main(String[] args) {
        String testString = "Test String";
        Font font = new Font("SansSerif", Font.PLAIN, 12);
        FontRenderContext frc = new FontRenderContext(null, false, true);
        System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
        // breaking size
        font = font.deriveFont(100000f);
        System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
        float[] sizes = new float[] {7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24};
        for (float size: sizes) {
            font = font.deriveFont(size);
            System.out.println(MessageFormat.format("size {0} width {1}", font.getSize(), font.getStringBounds(testString, frc).getWidth()));
        }
    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None, unless using JDK11 is an option

FREQUENCY : always



Comments
Changeset: 25871af3 Author: Phil Race <prr@openjdk.org> Date: 2024-04-24 17:54:10 +0000 URL: https://git.openjdk.org/jdk/commit/25871af36b1397bdc3715ab0edc589f0483ea0b1
24-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/18703 Date: 2024-04-09 18:50:17 +0000
09-04-2024

A call to set up freetype with the large size fails. As a result we incorrectly flag a problem with the scaler so it installs the null scaler. The fix for https://bugs.openjdk.org/browse/JDK-8233097 resolved an earlier problem with getting zero metrics, but that was at sizes that freetype was willing to accept. Once you get to point sizes like 100000 FT just flags an error. The JDK handling of this needs to be limited to the specific size / strike, not the whole font. TBD: what to report if FT won't handle it ? Is it reasonable to accept a font size of 100000 ? Perhaps we can use a smaller size and apply a scale afterwards.
27-03-2024

As per submission, in Windows and Linux, with JDK 17.0.10, font metrics return zero width for large font sizes. Subsequent calls for normal size also yield zero width unless it is requested prior to the problematic size. The issue seems to be related to JDK-8233097, which has a fix to an earlier issue reported with JDK 11.0.5 where the font metrics return a string width of zero for large (Fontsize > 1950) objects. The fix was integrated into JDK 11.0.5.0.3 and 13.0.2. The new aspect of the case is that, even concerning normal size, it produces zero width unless specifically requested prior to encountering the problematic size. Checked this with the attached test case against reported JDK version 17.0.10 and could confirm the issue as reported. Detailed verification confirms that the issue started appearing from JDK 17.0.5 b01 onwards, including JDK versions 21.0.2 GA build 13, JDK 22 GA build 36, as well as JDK 23 ea b15. ============================================================== Checked on Windows 11 (64-bit) with respective JDK versions: Pass: JDK 11 b28, JDK 14.0.2 b11, JDK 15.0.2 b07, JDK 16.0.2 b07, JDK 17 b35, JDK 17.0.4 b11, JDK 17.0.4.1.1 b01, JDK 14.0.2, JDK 15.0.2 b07, JDK 16.0.2 b07, JDK 17 b35, JDk 17.0.4 b11, JDK 17.0.4.1.1 b01 Fail: JDK 11.0.22 b09, JDK 17.0.5.b01, JDK 17.0.10 b11, JDK 21.0.2 GA build 13, JDK 22 GA build 36 and JDK 23 ea b15 Out put with JDK 11 b28 .... JDK 17.0.4.1.1. b01: $ java FontMetricsExample size 12 width 58.02 size 100,000 width 24,744.094 size 7 width 33.845 size 8 width 38.68 size 9 width 43.515 size 10 width 48.35 size 11 width 53.185 size 12 width 58.02 size 14 width 67.689 size 16 width 77.359 size 18 width 87.029 size 20 width 96.699 size 24 width 116.039 Output with JDK 11.0.22 b09 .... JDK 17.0.5.b01, JDK 17.0.10 b11, JDK 21.0.2 GA build 13, JDK 22 GA build 36 and JDK 23 ea b15: $ java FontMetricsExample size 12 width 58.02 size 100,000 width 0 size 7 width 0 size 8 width 0 size 9 width 0 size 10 width 0 size 11 width 0 size 12 width 58.02 size 14 width 0 size 16 width 0 size 18 width 0 size 20 width 0 size 24 width 0 =========================================================================
25-03-2024