1 /*
2  * Copyright 2017 JetBrains s.r.o.
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 /* @test
25  * @bug 8170552
26  * @summary verify enabling text layout for complex text on macOS
27  * @requires os.family == "mac"
28  */
29 
30 import java.awt.Color;
31 import java.awt.Font;
32 import java.awt.Graphics;
33 import java.awt.image.BufferedImage;
34 
35 public class DiacriticsDrawingTest {
36     private static final Font FONT = new Font("Menlo", Font.PLAIN, 12);
37     private static final int IMAGE_WIDTH = 20;
38     private static final int IMAGE_HEIGHT = 20;
39     private static final int TEXT_X = 5;
40     private static final int TEXT_Y = 15;
41 
main(String[] args)42     public static void main(String[] args) {
43         BufferedImage composed = drawString("\u00e1"); // latin small letter a with acute
44         BufferedImage decomposed = drawString("a\u0301"); // same letter in decomposed form
45 
46         if (!imagesAreEqual(composed, decomposed)) {
47             throw new RuntimeException("Text rendering is supposed to be the same");
48         }
49     }
50 
drawString(String text)51     private static BufferedImage drawString(String text) {
52         BufferedImage image = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
53         Graphics g = image.createGraphics();
54         g.setColor(Color.white);
55         g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
56         g.setColor(Color.black);
57         g.setFont(FONT);
58         g.drawString(text, TEXT_X, TEXT_Y);
59         g.dispose();
60         return image;
61     }
62 
imagesAreEqual(BufferedImage i1, BufferedImage i2)63     private static boolean imagesAreEqual(BufferedImage i1, BufferedImage i2) {
64         if (i1.getWidth() != i2.getWidth() || i1.getHeight() != i2.getHeight()) return false;
65         for (int i = 0; i < i1.getWidth(); i++) {
66             for (int j = 0; j < i1.getHeight(); j++) {
67                 if (i1.getRGB(i, j) != i2.getRGB(i, j)) {
68                     return false;
69                 }
70             }
71         }
72         return true;
73     }
74 }
75