1 /* 2 * Copyright (c) 2010, 2016, 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 * @key headful 27 * @bug 6996867 28 * @summary Render as LCD Text in SrcEa composite mode. 29 */ 30 31 import java.awt.*; 32 import java.awt.event.*; 33 import java.awt.image.*; 34 35 public class LCDTextSrcEa extends Component { 36 37 static int SZ=150; 38 BufferedImage target = 39 new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB); 40 41 public static void main(String args[]) { 42 Frame f = new Frame("LCD Text SrcEa Test"); 43 f.addWindowListener(new WindowAdapter() { 44 @Override 45 public void windowClosing(WindowEvent e) { 46 System.exit(0); 47 } 48 }); 49 LCDTextSrcEa td = new LCDTextSrcEa(); 50 f.add("Center", td); 51 f.pack(); 52 f.setVisible(true); 53 } 54 55 public Dimension getPreferredSize() { 56 return new Dimension(SZ,SZ); 57 } 58 59 public void paint(Graphics gx) { 60 61 Graphics2D g2d = (Graphics2D) target.getGraphics(); 62 g2d.setColor(Color.white); 63 g2d.fillRect(0, 0, getWidth(), getHeight()); 64 65 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f)); 66 g2d.setRenderingHint( 67 RenderingHints.KEY_TEXT_ANTIALIASING, 68 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR); 69 g2d.setRenderingHint( 70 RenderingHints.KEY_ANTIALIASING, 71 RenderingHints.VALUE_ANTIALIAS_ON); 72 73 g2d.setColor(Color.black); 74 g2d.drawString("Some sample text.", 10, 20); 75 gx.drawImage(target, 0, 0, null); 76 boolean nongrey = false; 77 //Test BI: should be some non-greyscale color 78 for (int px=0;px<SZ;px++) { 79 for (int py=0;py<SZ;py++) { 80 int rgb = target.getRGB(px, py); 81 int r = (rgb & 0xff0000) >> 16; 82 int g = (rgb & 0x00ff00) >> 8; 83 int b = (rgb & 0x0000ff); 84 if (r != g || r !=b || g != b) { 85 nongrey=true; 86 break; 87 } 88 } 89 } 90 if (!nongrey) { 91 throw new RuntimeException("No LCD text found"); 92 } 93 } 94 }