Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/marlin/TextClipErrorTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 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.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Font;
27
import java.awt.Graphics2D;
28
import java.awt.RenderingHints;
29
import java.awt.Shape;
30
import java.awt.font.FontRenderContext;
31
import java.awt.font.GlyphVector;
32
import java.awt.geom.AffineTransform;
33
import java.awt.geom.Line2D;
34
import java.awt.geom.Path2D;
35
import java.awt.geom.PathIterator;
36
import static java.awt.geom.PathIterator.SEG_CLOSE;
37
import static java.awt.geom.PathIterator.SEG_CUBICTO;
38
import static java.awt.geom.PathIterator.SEG_LINETO;
39
import static java.awt.geom.PathIterator.SEG_MOVETO;
40
import static java.awt.geom.PathIterator.SEG_QUADTO;
41
import java.awt.image.BufferedImage;
42
import java.io.File;
43
import java.io.IOException;
44
import java.util.ArrayList;
45
import java.util.Arrays;
46
import java.util.Locale;
47
import java.util.logging.Handler;
48
import java.util.logging.LogRecord;
49
import java.util.logging.Logger;
50
import javax.imageio.ImageIO;
51
52
/**
53
* @test
54
* @bug 8144718
55
* @summary Check the Stroker.drawBezApproxForArc() bug (stoke with round
56
* joins): if cosext2 > 0.5, it generates curves with NaN coordinates
57
* @run main TextClipErrorTest
58
*/
59
public class TextClipErrorTest {
60
61
static final boolean SAVE_IMAGE = false;
62
static final boolean SERIALIZE = false;
63
64
public static void main(String[] args) {
65
Locale.setDefault(Locale.US);
66
67
// initialize j.u.l Looger:
68
final Logger log = Logger.getLogger("sun.java2d.marlin");
69
log.addHandler(new Handler() {
70
@Override
71
public void publish(LogRecord record) {
72
Throwable th = record.getThrown();
73
// detect any Throwable:
74
if (th != null) {
75
System.out.println("Test failed:\n" + record.getMessage());
76
th.printStackTrace(System.out);
77
78
throw new RuntimeException("Test failed: ", th);
79
}
80
}
81
82
@Override
83
public void flush() {
84
}
85
86
@Override
87
public void close() throws SecurityException {
88
}
89
});
90
91
log.info("TextClipErrorTest: start");
92
93
// enable Marlin logging & internal checks:
94
System.setProperty("sun.java2d.renderer.log", "true");
95
System.setProperty("sun.java2d.renderer.useLogger", "true");
96
System.setProperty("sun.java2d.renderer.doChecks", "true");
97
98
BufferedImage image = new BufferedImage(256, 256,
99
BufferedImage.TYPE_INT_ARGB);
100
101
Graphics2D g2d = image.createGraphics();
102
g2d.setColor(Color.red);
103
try {
104
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
105
RenderingHints.VALUE_ANTIALIAS_ON);
106
107
Font font = g2d.getFont();
108
FontRenderContext frc = new FontRenderContext(
109
new AffineTransform(), true, true);
110
111
g2d.setStroke(new BasicStroke(4.0f,
112
BasicStroke.CAP_ROUND,
113
BasicStroke.JOIN_ROUND));
114
115
final Shape badShape;
116
if (SERIALIZE) {
117
final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
118
final Shape textShape = gv1.getOutline();
119
120
final AffineTransform at1 = AffineTransform.getTranslateInstance(
121
-2091202.554154681, 5548.601436981691);
122
badShape = at1.createTransformedShape(textShape);
123
serializeShape(badShape);
124
} else {
125
badShape = deserializeShape();
126
}
127
128
g2d.draw(badShape);
129
130
// Draw anything within bounds and it fails:
131
g2d.draw(new Line2D.Double(10, 20, 30, 40));
132
133
if (SAVE_IMAGE) {
134
final File file = new File("TextClipErrorTest.png");
135
System.out.println("Writing file: " + file.getAbsolutePath());
136
ImageIO.write(image, "PNG", file);
137
}
138
} catch (IOException ex) {
139
ex.printStackTrace();
140
} finally {
141
g2d.dispose();
142
log.info("TextClipErrorTest: end");
143
}
144
}
145
146
private static void serializeShape(Shape shape) {
147
final double[] coords = new double[6];
148
149
final int len = 32;
150
final ArrayList<Integer> typeList = new ArrayList<Integer>(len);
151
final ArrayList<double[]> coordsList = new ArrayList<double[]>(len);
152
153
for (PathIterator pi = shape.getPathIterator(null);
154
!pi.isDone(); pi.next())
155
{
156
switch (pi.currentSegment(coords)) {
157
case SEG_MOVETO:
158
typeList.add(SEG_MOVETO);
159
coordsList.add(Arrays.copyOf(coords, 2));
160
break;
161
case SEG_LINETO:
162
typeList.add(SEG_LINETO);
163
coordsList.add(Arrays.copyOf(coords, 2));
164
break;
165
case SEG_QUADTO:
166
typeList.add(SEG_QUADTO);
167
coordsList.add(Arrays.copyOf(coords, 4));
168
break;
169
case SEG_CUBICTO:
170
typeList.add(SEG_CUBICTO);
171
coordsList.add(Arrays.copyOf(coords, 6));
172
break;
173
case SEG_CLOSE:
174
typeList.add(SEG_CLOSE);
175
coordsList.add(null);
176
break;
177
default:
178
}
179
}
180
181
final StringBuilder sb = new StringBuilder(1024);
182
// types:
183
sb.append("private static final int[] SHAPE_TYPES = new int[]{\n");
184
for (Integer i : typeList) {
185
sb.append(i).append(",\n");
186
}
187
sb.append("};\n");
188
189
// coords:
190
sb.append("private static final double[][] SHAPE_COORDS = new double[][]{\n");
191
for (double[] c : coordsList) {
192
if (c == null) {
193
sb.append("null,\n");
194
} else {
195
sb.append("new double[]{");
196
for (int i = 0; i < c.length; i++) {
197
sb.append(c[i]).append(",");
198
}
199
sb.append("},\n");
200
}
201
}
202
sb.append("};\n");
203
204
System.out.println("Shape size: " + typeList.size());
205
System.out.println("Serialized shape:\n" + sb.toString());
206
}
207
208
private static Shape deserializeShape() {
209
final Path2D.Double path = new Path2D.Double();
210
211
for (int i = 0; i < SHAPE_TYPES.length; i++) {
212
double[] coords = SHAPE_COORDS[i];
213
214
switch (SHAPE_TYPES[i]) {
215
case SEG_MOVETO:
216
path.moveTo(coords[0], coords[1]);
217
break;
218
case SEG_LINETO:
219
path.lineTo(coords[0], coords[1]);
220
break;
221
case SEG_QUADTO:
222
path.quadTo(coords[0], coords[1],
223
coords[2], coords[3]);
224
break;
225
case SEG_CUBICTO:
226
path.curveTo(coords[0], coords[1],
227
coords[2], coords[3],
228
coords[4], coords[5]);
229
break;
230
case SEG_CLOSE:
231
path.closePath();
232
break;
233
default:
234
}
235
}
236
237
return path;
238
}
239
240
// generated code:
241
private static final int[] SHAPE_TYPES = new int[]{
242
0,
243
2,
244
2,
245
2,
246
2,
247
2,
248
2,
249
2,
250
2,
251
4,
252
0,
253
2,
254
2,
255
2,
256
2,
257
2,
258
2,
259
2,
260
2,
261
4,
262
0,
263
1,
264
1,
265
1,
266
1,
267
4,
268
0,
269
1,
270
1,
271
1,
272
1,
273
4,
274
};
275
276
private static final double[][] SHAPE_COORDS = new double[][]{
277
new double[]{-2091197.819779681, 5540.648311981691,},
278
new double[]{-2091199.116654681, 5540.648311981691, -2091199.874467181, 5541.609249481691,},
279
new double[]{-2091200.632279681, 5542.570186981691, -2091200.632279681, 5544.242061981691,},
280
new double[]{-2091200.632279681, 5545.882686981691, -2091199.874467181, 5546.843624481691,},
281
new double[]{-2091199.116654681, 5547.804561981691, -2091197.819779681, 5547.804561981691,},
282
new double[]{-2091196.538529681, 5547.804561981691, -2091195.780717181, 5546.843624481691,},
283
new double[]{-2091195.022904681, 5545.882686981691, -2091195.022904681, 5544.242061981691,},
284
new double[]{-2091195.022904681, 5542.570186981691, -2091195.780717181, 5541.609249481691,},
285
new double[]{-2091196.538529681, 5540.648311981691, -2091197.819779681, 5540.648311981691,},
286
null,
287
new double[]{-2091197.819779681, 5539.695186981691,},
288
new double[]{-2091195.991654681, 5539.695186981691, -2091194.890092181, 5540.929561981691,},
289
new double[]{-2091193.788529681, 5542.163936981691, -2091193.788529681, 5544.242061981691,},
290
new double[]{-2091193.788529681, 5546.304561981691, -2091194.890092181, 5547.538936981691,},
291
new double[]{-2091195.991654681, 5548.773311981691, -2091197.819779681, 5548.773311981691,},
292
new double[]{-2091199.663529681, 5548.773311981691, -2091200.772904681, 5547.538936981691,},
293
new double[]{-2091201.882279681, 5546.304561981691, -2091201.882279681, 5544.242061981691,},
294
new double[]{-2091201.882279681, 5542.163936981691, -2091200.772904681, 5540.929561981691,},
295
new double[]{-2091199.663529681, 5539.695186981691, -2091197.819779681, 5539.695186981691,},
296
null,
297
new double[]{-2091197.210404681, 5537.835811981691,},
298
new double[]{-2091196.022904681, 5537.835811981691,},
299
new double[]{-2091196.022904681, 5539.023311981691,},
300
new double[]{-2091197.210404681, 5539.023311981691,},
301
new double[]{-2091197.210404681, 5537.835811981691,},
302
null,
303
new double[]{-2091199.632279681, 5537.835811981691,},
304
new double[]{-2091198.444779681, 5537.835811981691,},
305
new double[]{-2091198.444779681, 5539.023311981691,},
306
new double[]{-2091199.632279681, 5539.023311981691,},
307
new double[]{-2091199.632279681, 5537.835811981691,},
308
null,
309
};
310
311
}
312
313