Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/DrawRotatedString.java
41153 views
1
/*
2
* Copyright (c) 2013, 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.Graphics2D;
26
import java.awt.RenderingHints;
27
import java.awt.image.BufferedImage;
28
import java.io.File;
29
import java.io.IOException;
30
31
import javax.imageio.ImageIO;
32
33
/**
34
* @test
35
* @bug 7190349
36
* @summary Verifies that we get correct direction, when draw rotated string.
37
* @author Sergey Bylokhov
38
* @run main/othervm DrawRotatedString
39
*/
40
public final class DrawRotatedString {
41
42
private static final int SIZE = 500;
43
44
public static void main(final String[] args) throws IOException {
45
BufferedImage bi = createBufferedImage(true);
46
verify(bi);
47
bi = createBufferedImage(false);
48
verify(bi);
49
System.out.println("Passed");
50
}
51
52
private static void verify(BufferedImage bi) throws IOException {
53
for (int i = 0; i < SIZE; ++i) {
54
for (int j = 0; j < 99; ++j) {
55
//Text should not appear before 100
56
if (bi.getRGB(i, j) != Color.RED.getRGB()) {
57
ImageIO.write(bi, "png", new File("image.png"));
58
throw new RuntimeException("Failed: wrong text location");
59
}
60
}
61
}
62
}
63
64
private static BufferedImage createBufferedImage(final boolean aa) {
65
final BufferedImage bi = new BufferedImage(SIZE, SIZE,
66
BufferedImage.TYPE_INT_RGB);
67
final Graphics2D bg = bi.createGraphics();
68
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
69
aa ? RenderingHints.VALUE_ANTIALIAS_ON
70
: RenderingHints.VALUE_ANTIALIAS_OFF);
71
bg.setColor(Color.RED);
72
bg.fillRect(0, 0, SIZE, SIZE);
73
bg.translate(100, 100);
74
bg.rotate(Math.toRadians(90));
75
bg.setColor(Color.BLACK);
76
bg.setFont(bg.getFont().deriveFont(20.0f));
77
bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);
78
bg.dispose();
79
return bi;
80
}
81
}
82
83