1 /*
2  * Copyright (c) 2018, 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 8214002
27  * @requires (os.family == "windows")
28  * @summary verify MS Mincho's Plain & Italic style
29  */
30 
31 import java.awt.Font;
32 import java.awt.Color;
33 import java.awt.Graphics;
34 import java.awt.Graphics2D;
35 import java.awt.RenderingHints;
36 import java.awt.image.BufferedImage;
37 
38 public class FontGlyphCompare {
39 
getFontImage(Font font, String text)40     static BufferedImage getFontImage(Font font, String text) {
41         int x = 1;
42         int y = 15;
43         int w = 10;
44         int h = 18;
45         BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
46         Graphics2D g = (Graphics2D)bi.getGraphics();
47         g.setColor(Color.black);
48         g.fillRect(0, 0, w, h);
49         g.setColor(Color.white);
50         g.setFont(font);
51         g.drawString(text, x, y);
52         return bi;
53     }
54 
main(String[] args)55     public static void main(String[] args) throws Exception {
56         String osName = System.getProperty("os.name");
57         System.out.println("OS is " + osName);
58         osName = osName.toLowerCase();
59         if (!osName.startsWith("windows")) {
60             return;
61         }
62         Font msMincho = new Font("MS Mincho", Font.PLAIN, 16);
63         String family = msMincho.getFamily(java.util.Locale.ENGLISH);
64         if (!family.equalsIgnoreCase("MS Mincho")) {
65             System.out.println("Japanese fonts not installed");
66             return;
67         }
68         String s = "|";
69         BufferedImage bi1 = getFontImage(new Font("MS Mincho", Font.PLAIN, 16), s);
70         int h1 = bi1.getHeight();
71         int w1 = bi1.getWidth();
72         BufferedImage bi2 = getFontImage(new Font("MS Mincho", Font.ITALIC, 16), s);
73         int h2 = bi2.getHeight();
74         int w2 = bi2.getWidth();
75         if ((h1 == h2) && (w1 == w2)) {
76             int cnt = 0;
77             for(int yy = 0; yy < h1; yy++) {
78                 for(int xx = 0; xx < w1; xx++) {
79                     if (bi1.getRGB(xx, yy) != bi2.getRGB(xx, yy)) {
80                         cnt++;
81                     }
82                 }
83             }
84             if (cnt == 0) {
85                 throw new Exception("Test failed");
86             }
87         }
88     }
89 }
90