Skip to content

Commit b25b623

Browse files
author
Satyen Subramaniam
committed
8353552: Opensource Several Font related tests - Batch 3
8355048: ProblemList TestGlyphVectorLayout.java on all platforms Backport-of: f8f1be3
1 parent 985581a commit b25b623

File tree

6 files changed

+587
-0
lines changed

6 files changed

+587
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java 8172245 linux-all
809809
java/awt/Frame/FrameStateTest/FrameStateTest.java 8203920 macosx-all,linux-all
810810
java/awt/print/PrinterJob/ScaledText/ScaledText.java 8231226 macosx-all
811811
java/awt/print/PrinterJob/PrintTextTest.java 8148334 generic-all
812+
java/awt/font/GlyphVector/TestGlyphVectorLayout.java 8354987 generic-all
812813
java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all
813814
java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all
814815
java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all,linux-all
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.Frame;
26+
import java.awt.GridLayout;
27+
import java.awt.Label;
28+
29+
/*
30+
* @test
31+
* @bug 4935871
32+
* @summary Check that correct type faces are used regardless of bold/italic styles
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual/othervm -Duser.language=ja -Duser.country=JP BoldItalicFontTest
36+
*/
37+
38+
public class BoldItalicFontTest {
39+
40+
public static void main(String[] args) throws Exception {
41+
final String INSTRUCTIONS = """
42+
This test is reproduced with a non-English user locale only.
43+
All the letters "X" in the first line should be in serif font.
44+
All the letters "X" in the second line should be in sans-serif font.
45+
46+
If so, press Pass, else press Fail.""";
47+
48+
PassFailJFrame.builder()
49+
.instructions(INSTRUCTIONS)
50+
.columns(35)
51+
.testUI(BoldItalicFontTest::createUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
private static Frame createUI() {
57+
String[] faces = { Font.SERIF, Font.SANS_SERIF };
58+
int[] styles = { 0, Font.BOLD, Font.ITALIC, Font.BOLD | Font.ITALIC };
59+
60+
Frame f = new Frame("BoldItalicFontTest Test UI");
61+
f.setLayout(new GridLayout(faces.length, styles.length));
62+
for (int fn = 0; fn < faces.length; fn++) {
63+
for (int sn = 0; sn < styles.length; sn++) {
64+
Label l = new Label("X");
65+
Font f1 = new Font(faces[fn], styles[sn], 36);
66+
l.setFont(f1);
67+
f.add(l);
68+
}
69+
}
70+
f.setSize(300, 300);
71+
return f;
72+
}
73+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) 2002, 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.Graphics;
28+
import java.awt.Graphics2D;
29+
import java.awt.Rectangle;
30+
import java.awt.RenderingHints;
31+
import java.awt.font.GlyphVector;
32+
import java.awt.font.FontRenderContext;
33+
import java.awt.geom.AffineTransform;
34+
import java.awt.geom.Rectangle2D;
35+
36+
import javax.swing.JPanel;
37+
38+
/*
39+
* @test
40+
* @bug 4615017
41+
* @summary Display two GlyphVectors, and ensure they are of the same length.
42+
* @library /java/awt/regtesthelpers
43+
* @build PassFailJFrame
44+
* @run main/manual TestGlyphVectorLayout
45+
*/
46+
47+
public class TestGlyphVectorLayout extends JPanel {
48+
private final Font font;
49+
private final FontRenderContext frc;
50+
private final String text;
51+
52+
private GlyphVector aftergv;
53+
private Rectangle pbounds;
54+
private Rectangle2D vbounds;
55+
56+
public static void main(String[] args) throws Exception {
57+
final String INSTRUCTIONS = """
58+
Two lines of text should appear, the top one with boxes
59+
(red and blue) around it.
60+
The two lines should be of the same length, and the boxes around the
61+
top line should 'fit' the text with no empty space between the end
62+
of the text and the box.
63+
64+
Pass the test if this is true.""";
65+
66+
PassFailJFrame.builder()
67+
.instructions(INSTRUCTIONS)
68+
.columns(45)
69+
.testUI(TestGlyphVectorLayout::new)
70+
.build()
71+
.awaitAndCheck();
72+
}
73+
74+
private TestGlyphVectorLayout() {
75+
setBackground(Color.WHITE);
76+
font = new Font(Font.DIALOG, Font.PLAIN, 24);
77+
frc = new FontRenderContext(null, false, false);
78+
text = "this is a test of glyph vector";
79+
}
80+
81+
@Override
82+
public Dimension getPreferredSize() {
83+
return new Dimension(550, 150);
84+
}
85+
86+
@Override
87+
public void paint(Graphics g) {
88+
super.paint(g);
89+
Graphics2D g2d = (Graphics2D) g;
90+
91+
float x = 50;
92+
float y = 50;
93+
AffineTransform oldtx = g2d.getTransform();
94+
g2d.translate(x, y);
95+
g2d.scale(1.5, 1.5);
96+
97+
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
98+
RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
99+
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
100+
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
101+
102+
g2d.setColor(Color.BLACK);
103+
104+
GlyphVector gv = font.createGlyphVector(frc, text); // new each time
105+
g2d.drawGlyphVector(gv, 0, 0);
106+
107+
if (vbounds == null) {
108+
vbounds = gv.getVisualBounds();
109+
pbounds = gv.getPixelBounds(g2d.getFontRenderContext(), 0, 0);
110+
aftergv = gv;
111+
}
112+
g2d.drawGlyphVector(aftergv, 0, 30);
113+
114+
g2d.setColor(Color.BLUE);
115+
g2d.draw(vbounds);
116+
117+
g2d.setTransform(oldtx);
118+
g2d.setColor(Color.RED);
119+
g2d.draw(pbounds);
120+
}
121+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 1999, 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.Graphics;
28+
import java.awt.Graphics2D;
29+
import java.awt.font.GlyphVector;
30+
import java.awt.font.FontRenderContext;
31+
import java.awt.geom.Point2D;
32+
33+
import javax.swing.JPanel;
34+
35+
/*
36+
* @test
37+
* @bug 4180379
38+
* @summary set the positions of glyphs in the GlyphVector to other than
39+
* their default x, y positions, and verify that the rendered glyphs are
40+
* in the new positions, not the default positions.
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual TestSetGlyphPositions
44+
*/
45+
46+
public class TestSetGlyphPositions extends JPanel {
47+
GlyphVector gv = null;
48+
49+
public static void main(String[] args) throws Exception {
50+
final String INSTRUCTIONS = """
51+
'TopLeft text and >' should appear towards the top left of the frame,
52+
and '< and BottomRight text' should appear towards the bottom right.
53+
54+
There should be some space between the '>' and '<' symbols, both vertically
55+
and horizontally.
56+
57+
Pass the test if this is true.""";
58+
59+
PassFailJFrame.builder()
60+
.instructions(INSTRUCTIONS)
61+
.columns(45)
62+
.testUI(TestSetGlyphPositions::new)
63+
.build()
64+
.awaitAndCheck();
65+
}
66+
67+
public TestSetGlyphPositions() {
68+
setBackground(Color.WHITE);
69+
setSize(550, 150);
70+
}
71+
72+
@Override
73+
public Dimension getPreferredSize() {
74+
return new Dimension(550, 150);
75+
}
76+
77+
@Override
78+
public void paint(Graphics g) {
79+
super.paint(g);
80+
Graphics2D g2d = (Graphics2D) g;
81+
82+
if (gv == null) {
83+
Font font = new Font(Font.DIALOG, Font.PLAIN, 36);
84+
FontRenderContext frc = g2d.getFontRenderContext();
85+
String str = "TopLeft><BottomRight";
86+
87+
gv = font.createGlyphVector(frc, str);
88+
for (int i = str.indexOf("<"); i < gv.getNumGlyphs(); ++i) {
89+
Point2D loc = gv.getGlyphPosition(i);
90+
loc.setLocation(loc.getX() + 50, loc.getY() + 50);
91+
gv.setGlyphPosition(i, loc);
92+
}
93+
}
94+
g2d.drawGlyphVector(gv, 50f, 50f);
95+
}
96+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 1999, 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.Graphics;
27+
import java.awt.Graphics2D;
28+
import java.text.AttributedString;
29+
import java.awt.font.TextAttribute;
30+
31+
import javax.swing.JPanel;
32+
33+
/*
34+
* @test
35+
* @bug 4188328
36+
* @summary In this bug, a text string is displayed rotated. Without the
37+
* fix, on Windows, the string was not displayed (boxes were
38+
* displayed which denote an unprintable character). On Solaris
39+
* 2.5.1, the characters were displayed, but not rotated. Now
40+
* on all platforms, the string is displayed correctly rotated.
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual RotateTest1
44+
*/
45+
46+
public class RotateTest1 extends JPanel {
47+
public static void main(String[] args) throws Exception {
48+
final String INSTRUCTIONS = """
49+
In this test, a text string is displayed rotated.
50+
51+
Without the fix, on Windows, the string was not displayed
52+
(boxes were displayed which denote an unprintable character).
53+
54+
On Solaris 2.5.1, the characters were displayed, but not rotated.
55+
56+
Now on all platforms, the string is displayed rotated.""";
57+
58+
PassFailJFrame.builder()
59+
.instructions(INSTRUCTIONS)
60+
.columns(45)
61+
.testUI(RotateTest1::new)
62+
.build()
63+
.awaitAndCheck();
64+
}
65+
66+
public RotateTest1() {
67+
setBackground(Color.WHITE);
68+
setDoubleBuffered(true);
69+
}
70+
71+
@Override
72+
public Dimension getPreferredSize() {
73+
return new Dimension(400, 520);
74+
}
75+
76+
@Override
77+
public void paint(Graphics g) {
78+
Graphics2D g2d = (Graphics2D) g;
79+
Dimension d = getSize();
80+
81+
g.setColor(getBackground());
82+
g.fillRect(0, 0, d.width, d.height);
83+
84+
// start java2d test code
85+
paintRotatedTextTest(g2d);
86+
}
87+
88+
private void paintRotatedTextTest(Graphics2D g2d) {
89+
AttributedString testString =
90+
new AttributedString("This is some text. Blablablabla");
91+
testString.addAttribute(TextAttribute.SIZE, 32f);
92+
93+
g2d.setPaint(Color.BLACK);
94+
g2d.rotate(Math.PI / 3);
95+
g2d.drawString(testString.getIterator(), 100.0f, 10.0f);
96+
}
97+
}

0 commit comments

Comments
 (0)