author | ihse |
Tue, 09 May 2017 12:57:30 +0200 | |
changeset 45028 | b0ea3c0bfb81 |
parent 42711 | 1a4a75c37134 |
child 47147 | 857d25fae728 |
permissions | -rw-r--r-- |
42711 | 1 |
/* |
2 |
* Copyright (c) 2016, 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 |
|
45028
b0ea3c0bfb81
8179889: Fix typographic errors in copyright headers
ihse
parents:
42711
diff
changeset
|
21 |
* questions. |
42711 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @summary verify Arab Diacritic Positioning |
|
26 |
* @bug 8168759 |
|
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 JFrame frame; |
|
49 |
static final String FONT = "DejaVu Sans"; |
|
50 |
||
51 |
public static void main(String args[]) throws Exception { |
|
52 |
showText(); // for a human |
|
53 |
measureText(); // for the test harness |
|
54 |
Thread.sleep(5000); |
|
55 |
frame.dispose(); |
|
56 |
} |
|
57 |
||
58 |
static void showText() { |
|
59 |
SwingUtilities.invokeLater(() -> { |
|
60 |
frame = new JFrame(); |
|
61 |
JLabel label = new JLabel(SAMPLE); |
|
62 |
Font font = new Font(FONT, Font.PLAIN, 36); |
|
63 |
label.setFont(font); |
|
64 |
frame.setLayout(new GridLayout(3,1)); |
|
65 |
frame.add(label); |
|
66 |
label = new JLabel(STR1); |
|
67 |
label.setFont(font); |
|
68 |
frame.add(label); |
|
69 |
label = new JLabel(STR2); |
|
70 |
label.setFont(font); |
|
71 |
frame.add(label); |
|
72 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
73 |
frame.pack(); |
|
74 |
frame.setLocationRelativeTo(null); |
|
75 |
frame.setVisible(true); |
|
76 |
}); |
|
77 |
} |
|
78 |
||
79 |
static void measureText() { |
|
80 |
Font font = new Font(FONT, Font.PLAIN, 36); |
|
81 |
if (!font.getFamily(Locale.ENGLISH).equals(FONT)) { |
|
82 |
return; |
|
83 |
} |
|
84 |
FontRenderContext frc = new FontRenderContext(null, false, false); |
|
85 |
TextLayout tl1 = new TextLayout(STR1, font, frc); |
|
86 |
TextLayout tl2 = new TextLayout(STR2, font, frc); |
|
87 |
Rectangle r1 = tl1.getPixelBounds(frc, 0f, 0f); |
|
88 |
Rectangle r2 = tl2.getPixelBounds(frc, 0f, 0f); |
|
89 |
if (r1.height > r2.height) { |
|
90 |
System.out.println(font); |
|
91 |
System.out.println(r1); |
|
92 |
System.out.println(r2); |
|
93 |
throw new RuntimeException("BAD BOUNDS"); |
|
94 |
} |
|
95 |
} |
|
96 |
} |