Path: blob/master/test/jdk/java/awt/FontClass/LCDScale.java
41152 views
/*1* Copyright (c) 2010, 2011, 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*25* @bug 692576026* @summary Scaled graphics causes overlapped LCD glyphs on Windows27*/2829import java.awt.*;30import java.awt.font.*;31import java.awt.geom.*;3233public class LCDScale extends Component {3435public static void main(String args[]) {36Frame f = new Frame("TL TEST");37LCDScale td = new LCDScale();38f.add("Center", td);39f.pack(); f.setVisible(true);40}414243public LCDScale() {44super();45}4647public Dimension getPreferredSize() {48return new Dimension(500,500);49}5051public void paint(Graphics g) {52Graphics2D g2d = (Graphics2D)g;53g2d.setRenderingHint(54RenderingHints.KEY_TEXT_ANTIALIASING,55RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);5657Font f = new Font("Dialog", Font.PLAIN, 40);58g.setFont(f);59FontRenderContext frc = g2d.getFontRenderContext();60GlyphVector gv = f.createGlyphVector(frc, "Help");61g2d.drawGlyphVector(gv, 10f, 50f);62Rectangle2D bds1 = gv.getLogicalBounds();6364f = new Font("Arial", Font.PLAIN, 25);65g.setFont(f);66double s = 2.0;67AffineTransform tx = AffineTransform.getScaleInstance(s,s);68g2d.transform(tx);69frc = g2d.getFontRenderContext();70gv = f.createGlyphVector(frc, "Help");71g2d.drawGlyphVector(gv, 10f, 100f);72Rectangle2D bds2 = gv.getLogicalBounds();7374System.out.println(bds1);75System.out.println(bds2);76if (bds2.getWidth()*s < bds1.getWidth()) {77throw new RuntimeException("Bounds too small");78}79}80}818283