301N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
301N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
301N/A *
301N/A * This code is free software; you can redistribute it and/or modify it
301N/A * under the terms of the GNU General Public License version 2 only, as
301N/A * published by the Free Software Foundation.
301N/A *
301N/A * This code is distributed in the hope that it will be useful, but WITHOUT
301N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
301N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
301N/A * version 2 for more details (a copy is included in the LICENSE file that
301N/A * accompanied this code).
301N/A *
301N/A * You should have received a copy of the GNU General Public License version
301N/A * 2 along with this work; if not, write to the Free Software Foundation,
301N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
301N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
301N/A */
301N/A
301N/A/**
301N/A * @test
301N/A * @bug 6685312
301N/A * @summary Check advance of LCD text on a scaled graphics.
301N/A */
301N/A
301N/Aimport javax.swing.*;
301N/Aimport java.awt.*;
301N/Aimport static java.awt.RenderingHints.*;
301N/A
301N/Apublic class ScaledLCDTextMetrics extends Component {
301N/A
301N/A public static void main(String[] args) {
301N/A JFrame f = new JFrame();
301N/A f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
301N/A f.add("Center", new ScaledLCDTextMetrics());
301N/A f.pack();
301N/A f.setVisible(true);
301N/A }
301N/A
301N/A public Dimension getPreferredSize() {
301N/A return new Dimension(200,100);
301N/A }
301N/A public void paint(Graphics g) {
301N/A Graphics2D g2 = (Graphics2D)g;
301N/A
301N/A Font f = new Font("Tahoma", Font.PLAIN, 11);
301N/A g.setFont(f);
301N/A g.setColor(Color.white);
301N/A g.fillRect(0,0,400,300);
301N/A g.setColor(Color.black);
301N/A g2.setRenderingHint(KEY_TEXT_ANTIALIASING,VALUE_TEXT_ANTIALIAS_LCD_HRGB);
301N/A String text = "ABCDEFGHIJKLI";
301N/A
301N/A FontMetrics fm1 = g2.getFontMetrics();
301N/A int adv1 = fm1.stringWidth(text);
301N/A g.drawString(text, 5, 20);
301N/A
301N/A g2.scale(2,2);
301N/A
301N/A FontMetrics fm2 = g2.getFontMetrics();
301N/A int adv2 = fm2.stringWidth(text);
301N/A g.drawString(text, 5, 40);
301N/A
301N/A double frac = Math.abs(adv1/(double)adv2);
301N/A
301N/A System.out.println("scalex1: " + adv1);
301N/A System.out.println("scalex2: " + adv2);
301N/A System.out.println("Fraction : "+ frac);
301N/A
301N/A // adv1 will not be exactly the same as adv2, but should differ
301N/A // only by a fraction.
301N/A
301N/A if (frac < 0.8 || frac > 1.2) {
301N/A throw new RuntimeException("Metrics differ " +
301N/A "Adv1="+adv1+" Adv2="+adv2+" Fraction="+frac);
301N/A }
301N/A }
301N/A}