|
1 /* |
|
2 * Copyright (c) 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. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8233097 |
|
27 * @summary Test we get non-zero metrics with large sizes. |
|
28 * @run main MassiveMetricsTest |
|
29 */ |
|
30 |
|
31 import java.awt.Font; |
|
32 import java.awt.FontMetrics; |
|
33 import java.awt.Graphics2D; |
|
34 import java.awt.GraphicsEnvironment; |
|
35 import java.awt.image.BufferedImage; |
|
36 |
|
37 public class MassiveMetricsTest { |
|
38 |
|
39 public static void main(String [] args) { |
|
40 |
|
41 GraphicsEnvironment ge = |
|
42 GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
43 Font[] fonts = ge.getAllFonts(); |
|
44 BufferedImage bi = new BufferedImage(1,1,1); |
|
45 Graphics2D g2d = bi.createGraphics(); |
|
46 int[] sizes = { 80, 100, 120, 600, 1600, 2400, 3600, 7200, 12000 }; |
|
47 String s = "m"; |
|
48 |
|
49 for (Font f : fonts) { |
|
50 Font sz12Font = f.deriveFont(Font.PLAIN, 12); |
|
51 FontMetrics sz12 = g2d.getFontMetrics(sz12Font); |
|
52 if (sz12.stringWidth(s) == 0) { |
|
53 continue; // code point not supported or similar. |
|
54 } |
|
55 boolean fail = false; |
|
56 for (int sz : sizes) { |
|
57 Font font = f.deriveFont(Font.PLAIN, sz); |
|
58 FontMetrics fm = g2d.getFontMetrics(font); |
|
59 if (fm.stringWidth(s) == 0) { |
|
60 fail = true; |
|
61 System.err.println("zero for " + font); |
|
62 } |
|
63 } |
|
64 if (fail) { |
|
65 throw new RuntimeException("Zero stringwidth"); |
|
66 } |
|
67 } |
|
68 } |
|
69 } |