Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
66645 views
/*1* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 6996867 822354326* @requires (os.family == "windows")27* @summary Render as LCD Text in SrcEa composite mode.28*/2930import java.awt.AlphaComposite;31import java.awt.Color;32import java.awt.Graphics2D;33import java.awt.RenderingHints;34import java.awt.image.BufferedImage;3536public class LCDTextSrcEa {3738public static void main(String[] args) {39String os = System.getProperty("os.name");40if (os.toLowerCase().startsWith("mac")) {41System.out.println("macOS doesn't support LCD any more. Skipping");42return;43}44/* Sometimes freetype on Linux is built without LCD support, so45* it can't be relied upon to test there.46*/47if (os.toLowerCase().startsWith("linux")) {48System.out.println("Linux freetype may not do LCD. Skipping");49return;50}51int SZ=200;52BufferedImage target =53new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);54Graphics2D g2d = (Graphics2D) target.getGraphics();55g2d.setColor(Color.white);56g2d.fillRect(0, 0, SZ, SZ);5758g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));59g2d.setRenderingHint(60RenderingHints.KEY_TEXT_ANTIALIASING,61RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);62g2d.setRenderingHint(63RenderingHints.KEY_ANTIALIASING,64RenderingHints.VALUE_ANTIALIAS_ON);6566g2d.setColor(Color.black);67g2d.drawString("Some sample text.", 10, 20);68boolean nongrey = false;69//Test BI: should be some non-greyscale color70for (int px=0;px<SZ;px++) {71for (int py=0;py<SZ;py++) {72int rgb = target.getRGB(px, py);73int r = (rgb & 0xff0000) >> 16;74int g = (rgb & 0x00ff00) >> 8;75int b = (rgb & 0x0000ff);76if (r != g || r !=b || g != b) {77nongrey=true;78break;79}80}81}82if (!nongrey) {83throw new RuntimeException("No LCD text found");84}85}86}878889