1 /*
2  * Copyright (c) 2016, 2020, 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 /* @test
25  * @summary verify Arab Diacritic Positioning
26  * @bug 8168759 8248352
27  */
28 
29 import java.awt.Font;
30 import java.awt.GridLayout;
31 import java.awt.Rectangle;
32 import java.awt.font.FontRenderContext;
33 import java.awt.font.TextLayout;
34 import java.util.Locale;
35 import javax.swing.JFrame;
36 import javax.swing.JLabel;
37 import javax.swing.SwingUtilities;
38 import javax.swing.WindowConstants;
39 
40 public class ArabicDiacriticTest {
41 
42     static final String SAMPLE =
43      "\u0627\u0644\u0639\u064e\u0631\u064e\u0628\u0650\u064a\u064e\u0651\u0629";
44 
45     static final String STR1 = "\u0644\u0639\u064e\u0629";
46     static final String STR2 = "\u0644\u0639\u0629";
47 
48     static final String FONT = "DejaVu Sans";
49 
main(String[] args)50     public static void main(String[] args) throws Exception {
51         if ((args.length > 0) && (args[0].equals("-show"))) {
52             showText(); // for a human
53         }
54         measureText(); // for the test harness
55     }
56 
showText()57     static void showText() {
58         SwingUtilities.invokeLater(() -> {
59             JFrame frame = new JFrame();
60             JLabel label = new JLabel(SAMPLE);
61             Font font = new Font(FONT, Font.PLAIN, 36);
62             label.setFont(font);
63             frame.setLayout(new GridLayout(3,1));
64             frame.add(label);
65             label = new JLabel(STR1);
66             label.setFont(font);
67             frame.add(label);
68             label = new JLabel(STR2);
69             label.setFont(font);
70             frame.add(label);
71             frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
72             frame.pack();
73             frame.setLocationRelativeTo(null);
74             frame.setVisible(true);
75         });
76     }
77 
measureText()78     static void measureText() {
79         Font font = new Font(FONT, Font.PLAIN, 36);
80         if (!font.getFamily(Locale.ENGLISH).equals(FONT)) {
81             return;
82         }
83         FontRenderContext frc = new FontRenderContext(null, false, false);
84         TextLayout tl1 = new TextLayout(STR1, font, frc);
85         TextLayout tl2 = new TextLayout(STR2, font, frc);
86         Rectangle r1 = tl1.getPixelBounds(frc, 0f, 0f);
87         Rectangle r2 = tl2.getPixelBounds(frc, 0f, 0f);
88         if (r1.height > r2.height) {
89             System.out.println(font);
90             System.out.println(r1);
91             System.out.println(r2);
92             throw new RuntimeException("BAD BOUNDS");
93         }
94     }
95 }
96