Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/RotTransText.java
41153 views
1
/*
2
* Copyright (c) 2008, 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
/**
25
* @test
26
* @bug 6683472 6687298 8197797
27
* @summary Transformed fonts using drawString and TextLayout should be in
28
* the same position.
29
*/
30
31
import java.awt.*;
32
import java.awt.font.*;
33
import java.awt.geom.*;
34
import java.awt.image.*;
35
import java.util.HashMap;
36
37
public class RotTransText {
38
39
public static void main(String[] args) {
40
41
testIt(false);
42
testIt(true);
43
44
}
45
46
public static void testIt(boolean fmOn) {
47
48
int wid=400, hgt=400;
49
BufferedImage bi =
50
new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB);
51
52
Graphics2D g2d = bi.createGraphics();
53
54
if (fmOn) {
55
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
56
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
57
}
58
59
int x=130, y=130;
60
String s = "Text";
61
62
int xt=90, yt=50;
63
for (int angle=0;angle<360;angle+=30) {
64
65
g2d.setColor(Color.white);
66
g2d.fillRect(0, 0, wid, hgt);
67
68
AffineTransform aff = AffineTransform.getTranslateInstance(50,90);
69
aff.rotate(angle * Math.PI/180.0);
70
71
Font fnt = new Font("SansSerif", Font.PLAIN, 60);
72
fnt = fnt.deriveFont(Font.PLAIN, aff);
73
g2d.setFont(fnt);
74
g2d.setColor(Color.blue);
75
g2d.drawString(s, x, y);
76
77
g2d.setColor(Color.red);
78
FontRenderContext frc = g2d.getFontRenderContext();
79
HashMap attrMap = new HashMap();
80
attrMap.put(TextAttribute.STRIKETHROUGH,
81
TextAttribute.STRIKETHROUGH_ON);
82
fnt = fnt.deriveFont(attrMap);
83
TextLayout tl = new TextLayout(s, fnt, frc);
84
tl.draw(g2d, (float)x, (float)y);
85
86
// Test BI: should be minimal blue relative to red.
87
int redCount = 0;
88
int blueCount = 0;
89
int red = Color.red.getRGB();
90
int blue = Color.blue.getRGB();
91
for (int px=0;px<wid;px++) {
92
for (int py=0;py<hgt;py++) {
93
int rgb = bi.getRGB(px, py);
94
if (rgb == red) {
95
redCount++;
96
} else if (rgb == blue) {
97
blueCount++;
98
}
99
}
100
}
101
if (redCount == 0 || (blueCount/(double)redCount) > 0.1) {
102
throw new
103
RuntimeException("Ratio of blue to red is too great: " +
104
(blueCount/(double)redCount));
105
}
106
}
107
}
108
}
109
110