Skip to content

Commit b539fb0

Browse files
author
Abhishek Kumar
committed
8352877: Opensource Several Font related tests - Batch 1
Reviewed-by: aivanov, serb
1 parent 5d97608 commit b539fb0

File tree

3 files changed

+417
-0
lines changed

3 files changed

+417
-0
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2004, 2025, 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+
import java.awt.Font;
25+
import java.awt.GraphicsEnvironment;
26+
27+
import javax.swing.JFrame;
28+
import javax.swing.JTextArea;
29+
30+
/*
31+
* @test
32+
* @bug 5014727
33+
* @summary Display Devanagari text and make sure the character
34+
* that appears after the nukta (dot) isn't duplicated.
35+
* @library /java/awt/regtesthelpers /test/lib
36+
* @build PassFailJFrame jtreg.SkippedException
37+
* @run main/manual TestDevanagari
38+
*/
39+
40+
public class TestDevanagari {
41+
42+
private static final String text = """
43+
Ra Nukta Ra
44+
\u0930\u093c\u0930""";
45+
private static final Font font = getPhysicalFontForText(text, Font.PLAIN, 20);
46+
47+
public static void main(String[] args) throws Exception {
48+
if (font == null) {
49+
throw new jtreg.SkippedException("No Devanagari font found. Test Skipped.");
50+
}
51+
52+
final String INSTRUCTIONS = """
53+
You should see two Devanagari Letters 'Ra':
54+
The first with Nukta sign (dot under it), the second without.
55+
The second character (after the Nukta sign) shouldn't be visible twice
56+
57+
Pass the test if this is true.
58+
""";
59+
60+
PassFailJFrame.builder()
61+
.title("TestDevanagari Instruction")
62+
.instructions(INSTRUCTIONS)
63+
.columns(40)
64+
.testUI(TestDevanagari::createUI)
65+
.build()
66+
.awaitAndCheck();
67+
}
68+
69+
private static JFrame createUI() {
70+
JFrame frame = new JFrame("TestDevanagari UI");
71+
JTextArea textArea = new JTextArea();
72+
textArea.setFont(font);
73+
textArea.setText(text);
74+
75+
frame.add(textArea);
76+
frame.setSize(300, 200);
77+
return frame;
78+
}
79+
80+
private static Font getPhysicalFontForText(String text, int style, int size) {
81+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
82+
String[] names = ge.getAvailableFontFamilyNames();
83+
84+
for (String n : names) {
85+
switch (n.toLowerCase()) {
86+
case "dialog":
87+
case "dialoginput":
88+
case "serif":
89+
case "sansserif":
90+
case "monospaced":
91+
break;
92+
default:
93+
Font f = new Font(n, style, size);
94+
if (f.canDisplayUpTo(text) == -1) {
95+
return f;
96+
}
97+
}
98+
}
99+
return null;
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
import java.awt.Color;
25+
import java.awt.Dimension;
26+
import java.awt.Font;
27+
import java.awt.FontMetrics;
28+
import java.awt.Frame;
29+
import java.awt.Graphics;
30+
import java.awt.Graphics2D;
31+
import java.awt.Insets;
32+
import java.awt.Panel;
33+
import java.awt.ScrollPane;
34+
import java.awt.font.FontRenderContext;
35+
import java.awt.font.TextLayout;
36+
37+
/*
38+
* @test
39+
* @bug 4517298
40+
* @summary Display special control characters using both TextLayout.draw and
41+
* Graphics.drawString. In no case should a missing glyph appear.
42+
* Also display the advance of the control characters, in all cases
43+
* these should be 0. The space character is also displayed as a reference.
44+
* Note, the character is rendered between '><' but owing to the directional
45+
* properties of two of the characters, the second '<' is rendered as '>'.
46+
* This is correct behavior.
47+
* @library /java/awt/regtesthelpers
48+
* @build PassFailJFrame
49+
* @run main/manual TestControls
50+
*/
51+
52+
public class TestControls {
53+
private static String fontName = Font.DIALOG;
54+
55+
public static void main(String[] args) throws Exception {
56+
final String INSTRUCTIONS = """
57+
A number of control characters are displayed, one per line.
58+
Each line displays the hex value of the character, the character
59+
between '><' as rendered by TextLayout, the character between '><'
60+
as rendered by drawString, and the advance of the character.
61+
The first line renders the space character, as a reference.
62+
The following lines all render the controls.
63+
All controls should not render (even as space) and report a zero advance.
64+
65+
Pass the test if this is true.
66+
67+
Note: two of the control characters have the effect of changing the '<'
68+
following the control character so that it renders as '>'.
69+
This is not an error.""";
70+
71+
PassFailJFrame.builder()
72+
.title("TestControls Instruction")
73+
.instructions(INSTRUCTIONS)
74+
.columns(45)
75+
.testUI(TestControls::createUI)
76+
.build()
77+
.awaitAndCheck();
78+
}
79+
80+
private static Frame createUI() {
81+
Frame f = new Frame("TestControls Test UI");
82+
Panel panel = new ControlPanel(fontName);
83+
ScrollPane sp = new ScrollPane();
84+
sp.add("Center", panel);
85+
f.add(sp);
86+
f.setSize(450, 400);
87+
return f;
88+
}
89+
90+
static class ControlPanel extends Panel {
91+
92+
static final char[] chars = {
93+
(char)0x0020, (char)0x0009,
94+
(char)0x000A, (char)0x000D, (char)0x200C, (char)0x200D, (char)0x200E,
95+
(char)0x200F, (char)0x2028, (char)0x2029, (char)0x202A, (char)0x202B,
96+
(char)0x202C, (char)0x202D, (char)0x202E, (char)0x206A, (char)0x206B,
97+
(char)0x206C, (char)0x206D, (char)0x206E, (char)0x206F
98+
};
99+
100+
ControlPanel(String fontName) {
101+
Font font = new Font(fontName, Font.PLAIN, 24);
102+
System.out.println("using font: " + font);
103+
setFont(font);
104+
setForeground(Color.BLACK);
105+
setBackground(Color.WHITE);
106+
}
107+
108+
@Override
109+
public Dimension getPreferredSize() {
110+
return new Dimension(400, 750);
111+
}
112+
113+
@Override
114+
public Dimension getMaximumSize() {
115+
return getPreferredSize();
116+
}
117+
118+
@Override
119+
public void paint(Graphics g) {
120+
Graphics2D g2d = (Graphics2D)g;
121+
FontRenderContext frc = g2d.getFontRenderContext();
122+
Font font = g2d.getFont();
123+
FontMetrics fm = g2d.getFontMetrics();
124+
Insets insets = getInsets();
125+
126+
String jvmString = System.getProperty("java.version");
127+
String osString = System.getProperty("os.name") + " / " +
128+
System.getProperty("os.arch") + " / " +
129+
System.getProperty("os.version");
130+
131+
int x = insets.left + 10;
132+
int y = insets.top;
133+
134+
y += 30;
135+
g2d.drawString("jvm: " + jvmString, x, y);
136+
137+
y += 30;
138+
g2d.drawString("os: " + osString, x, y);
139+
140+
y += 30;
141+
g2d.drawString("font: " + font.getFontName(), x, y);
142+
143+
for (int i = 0; i < chars.length; ++i) {
144+
String s = ">" + chars[i] + "<";
145+
x = insets.left + 10;
146+
y += 30;
147+
148+
g2d.drawString(Integer.toHexString(chars[i]), x, y);
149+
x += 100;
150+
151+
new TextLayout(s, font, frc).draw(g2d, x, y);
152+
x += 100;
153+
154+
g2d.drawString(s, x, y);
155+
x += 100;
156+
157+
g2d.drawString(Integer.toString(fm.charWidth(chars[i])), x, y);
158+
}
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)