Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
38828 views
/*1* Copyright (c) 2010, 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 699686726* @summary Render as LCD Text in SrcEa composite mode.27*/2829import java.awt.*;30import java.awt.event.*;31import java.awt.image.*;3233public class LCDTextSrcEa extends Component {3435static int SZ=150;36BufferedImage target =37new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);3839public static void main(String args[]) {40Frame f = new Frame("LCD Text SrcEa Test");41f.addWindowListener(new WindowAdapter() {42@Override43public void windowClosing(WindowEvent e) {44System.exit(0);45}46});47LCDTextSrcEa td = new LCDTextSrcEa();48f.add("Center", td);49f.pack();50f.setVisible(true);51}5253public Dimension getPreferredSize() {54return new Dimension(SZ,SZ);55}5657public void paint(Graphics gx) {5859Graphics2D g2d = (Graphics2D) target.getGraphics();60g2d.setColor(Color.white);61g2d.fillRect(0, 0, getWidth(), getHeight());6263g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));64g2d.setRenderingHint(65RenderingHints.KEY_TEXT_ANTIALIASING,66RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);67g2d.setRenderingHint(68RenderingHints.KEY_ANTIALIASING,69RenderingHints.VALUE_ANTIALIAS_ON);7071g2d.setColor(Color.black);72g2d.drawString("Some sample text.", 10, 20);73gx.drawImage(target, 0, 0, null);74boolean nongrey = false;75//Test BI: should be some non-greyscale color76for (int px=0;px<SZ;px++) {77for (int py=0;py<SZ;py++) {78int rgb = target.getRGB(px, py);79int r = (rgb & 0xff0000) >> 16;80int g = (rgb & 0x00ff00) >> 8;81int b = (rgb & 0x0000ff);82if (r != g || r !=b || g != b) {83nongrey=true;84break;85}86}87}88if (!nongrey) {89throw new RuntimeException("No LCD text found");90}91}92}939495