1 /* 2 * Copyright (c) 2010, 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 * 26 * @bug 6925760 27 * @summary Scaled graphics causes overlapped LCD glyphs on Windows 28 */ 29 30 import java.awt.*; 31 import java.awt.font.*; 32 import java.awt.geom.*; 33 34 public class LCDScale extends Component { 35 36 public static void main(String args[]) { 37 Frame f = new Frame("TL TEST"); 38 LCDScale td = new LCDScale(); 39 f.add("Center", td); 40 f.pack(); f.setVisible(true); 41 } 42 43 44 public LCDScale() { 45 super(); 46 } 47 48 public Dimension getPreferredSize() { 49 return new Dimension(500,500); 50 } 51 52 public void paint(Graphics g) { 53 Graphics2D g2d = (Graphics2D)g; 54 g2d.setRenderingHint( 55 RenderingHints.KEY_TEXT_ANTIALIASING, 56 RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); 57 58 Font f = new Font("Dialog", Font.PLAIN, 40); 59 g.setFont(f); 60 FontRenderContext frc = g2d.getFontRenderContext(); 61 GlyphVector gv = f.createGlyphVector(frc, "Help"); 62 g2d.drawGlyphVector(gv, 10f, 50f); 63 Rectangle2D bds1 = gv.getLogicalBounds(); 64 65 f = new Font("Arial", Font.PLAIN, 25); 66 g.setFont(f); 67 double s = 2.0; 68 AffineTransform tx = AffineTransform.getScaleInstance(s,s); 69 g2d.transform(tx); 70 frc = g2d.getFontRenderContext(); 71 gv = f.createGlyphVector(frc, "Help"); 72 g2d.drawGlyphVector(gv, 10f, 100f); 73 Rectangle2D bds2 = gv.getLogicalBounds(); 74 75 System.out.println(bds1); 76 System.out.println(bds2); 77 if (bds2.getWidth()*s < bds1.getWidth()) { 78 throw new RuntimeException("Bounds too small"); 79 } 80 } 81 } 82 83