Path: blob/master/test/jdk/java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
41153 views
/*1* Copyright (c) 2010, 2016, 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* @key headful26* @bug 699686727* @summary Render as LCD Text in SrcEa composite mode.28*/2930import java.awt.*;31import java.awt.event.*;32import java.awt.image.*;3334public class LCDTextSrcEa extends Component {3536static int SZ=150;37BufferedImage target =38new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);3940public static void main(String args[]) {41Frame f = new Frame("LCD Text SrcEa Test");42f.addWindowListener(new WindowAdapter() {43@Override44public void windowClosing(WindowEvent e) {45System.exit(0);46}47});48LCDTextSrcEa td = new LCDTextSrcEa();49f.add("Center", td);50f.pack();51f.setVisible(true);52}5354public Dimension getPreferredSize() {55return new Dimension(SZ,SZ);56}5758public void paint(Graphics gx) {5960Graphics2D g2d = (Graphics2D) target.getGraphics();61g2d.setColor(Color.white);62g2d.fillRect(0, 0, getWidth(), getHeight());6364g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));65g2d.setRenderingHint(66RenderingHints.KEY_TEXT_ANTIALIASING,67RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);68g2d.setRenderingHint(69RenderingHints.KEY_ANTIALIASING,70RenderingHints.VALUE_ANTIALIAS_ON);7172g2d.setColor(Color.black);73g2d.drawString("Some sample text.", 10, 20);74gx.drawImage(target, 0, 0, null);75boolean nongrey = false;76//Test BI: should be some non-greyscale color77for (int px=0;px<SZ;px++) {78for (int py=0;py<SZ;py++) {79int rgb = target.getRGB(px, py);80int r = (rgb & 0xff0000) >> 16;81int g = (rgb & 0x00ff00) >> 8;82int b = (rgb & 0x0000ff);83if (r != g || r !=b || g != b) {84nongrey=true;85break;86}87}88}89if (!nongrey) {90throw new RuntimeException("No LCD text found");91}92}93}949596