Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
66645 views
1
/*
2
* Copyright (c) 2010, 2022, 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 6996867 8223543
27
* @requires (os.family == "windows")
28
* @summary Render as LCD Text in SrcEa composite mode.
29
*/
30
31
import java.awt.AlphaComposite;
32
import java.awt.Color;
33
import java.awt.Graphics2D;
34
import java.awt.RenderingHints;
35
import java.awt.image.BufferedImage;
36
37
public class LCDTextSrcEa {
38
39
public static void main(String[] args) {
40
String os = System.getProperty("os.name");
41
if (os.toLowerCase().startsWith("mac")) {
42
System.out.println("macOS doesn't support LCD any more. Skipping");
43
return;
44
}
45
/* Sometimes freetype on Linux is built without LCD support, so
46
* it can't be relied upon to test there.
47
*/
48
if (os.toLowerCase().startsWith("linux")) {
49
System.out.println("Linux freetype may not do LCD. Skipping");
50
return;
51
}
52
int SZ=200;
53
BufferedImage target =
54
new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);
55
Graphics2D g2d = (Graphics2D) target.getGraphics();
56
g2d.setColor(Color.white);
57
g2d.fillRect(0, 0, SZ, SZ);
58
59
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));
60
g2d.setRenderingHint(
61
RenderingHints.KEY_TEXT_ANTIALIASING,
62
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);
63
g2d.setRenderingHint(
64
RenderingHints.KEY_ANTIALIASING,
65
RenderingHints.VALUE_ANTIALIAS_ON);
66
67
g2d.setColor(Color.black);
68
g2d.drawString("Some sample text.", 10, 20);
69
boolean nongrey = false;
70
//Test BI: should be some non-greyscale color
71
for (int px=0;px<SZ;px++) {
72
for (int py=0;py<SZ;py++) {
73
int rgb = target.getRGB(px, py);
74
int r = (rgb & 0xff0000) >> 16;
75
int g = (rgb & 0x00ff00) >> 8;
76
int b = (rgb & 0x0000ff);
77
if (r != g || r !=b || g != b) {
78
nongrey=true;
79
break;
80
}
81
}
82
}
83
if (!nongrey) {
84
throw new RuntimeException("No LCD text found");
85
}
86
}
87
}
88
89