0 values for Font.getStringBounds()

Peter Felix felix at imagic.ch
Mon Aug 10 09:15:20 UTC 2020


I’d like to report a bug based on Font.getStringBounds().

With the following lines it is reproducible:

String test = "abcdefghijklmnopqrstuvwxyz ";
Font f = new Font("Arial", 0, 1560);
int[] widths = new int[test.length()];
for (int i = 0; i < widths.length; i++) {
    FontRenderContext context = new FontRenderContext(new AffineTransform(1, 0, 0, 1, 0, 0), true, true);
    double w = f.getStringBounds(test, i, i + 1, context).getWidth();
     widths[i] = (int) w;
}

for (int i = 0; i < widths.length; i++) {
    System.out.print(widths[i] + " ");
}


Output ok (with Amazon Corretto 8.202):
867 867 780 867 867 433 867 867 346 346 780 346 1299 867 867 867 867 519 780 433 867 780 1126 780 780 780 433
If I set the font size to 3000 instead of 1560 then the output is
1668 1668 1500 1668 1668 833 1668 1668 666 666 1500 666 2499 1668 1668 1668 1668 999 1500 833 1668 1500 2166 1500 1500 1500 833
If I set the font size to 100 instead of 1560 then the output is
55 55 50 55 55 27 55 55 22 22 50 22 83 55 55 55 55 33 50 27 55 50 72 50 50 50 27


Output nok (with Amazon Corretto 8.232, 8.252, 8.265 and with AdoptOpenJDK 8.265):
867 0 780 0 867 0 0 0 0 0 0 0 0 867 867 0 0 519 780 0 867 780 0 780 0 780 433
If I set the font size to 3000 instead of 1560 then the output is
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 833
If I set the font size to 100 instead of 1560 then the output is (with this size the values are ok)
55 55 50 55 55 27 55 55 22 22 50 22 83 55 55 55 55 33 50 27 55 50 72 50 50 50 27

Thanks,

Peter Felix

Software-Entwickler



Telefon:

+41 44 809 40 60

E-Mail: felix at imagic.ch<mailto:felix at imagic.ch>



Imagic Bildverarbeitung AG

Europa-Strasse 27

CH-8152 Glattbrugg



www.imagic.ch<http://www.imagic.ch>

[LinkedIn]<https://www.linkedin.com/company/imagic-ch/>  [xing_share_button3] <https://www.xing.com/companies/imagicbildverarbeitungag/updates>





More information about the jdk8u-dev mailing list