1963N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1963N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1963N/A *
1963N/A * This code is free software; you can redistribute it and/or modify it
1963N/A * under the terms of the GNU General Public License version 2 only, as
1963N/A * published by the Free Software Foundation.
1963N/A *
1963N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1963N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1963N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1963N/A * version 2 for more details (a copy is included in the LICENSE file that
1963N/A * accompanied this code).
1963N/A *
1963N/A * You should have received a copy of the GNU General Public License version
1963N/A * 2 along with this work; if not, write to the Free Software Foundation,
1963N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1963N/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.
1963N/A */
1963N/A
1963N/A/* @test
1963N/A * @summary leading and trailing spaces must not affect visual bounds
1963N/A * @bug 6904962
1963N/A */
1963N/A
1963N/A
1963N/Aimport java.awt.*;
1963N/Aimport java.awt.font.*;
1963N/Aimport java.awt.geom.*;
1963N/A
1963N/Apublic class VisualBounds {
1963N/A
1963N/A public static void main(String args[]) {
1963N/A
1963N/A String s1 = "a";
1963N/A String s2 = s1+" ";
1963N/A String s3 = " "+s1;
1963N/A Font f = new Font("Dialog", Font.PLAIN, 12);
1963N/A FontRenderContext frc = new FontRenderContext(null, false, false);
1963N/A GlyphVector gv1 = f.createGlyphVector(frc, s1);
1963N/A GlyphVector gv2 = f.createGlyphVector(frc, s2);
1963N/A GlyphVector gv3 = f.createGlyphVector(frc, s3);
1963N/A Rectangle2D bds1 = gv1.getVisualBounds();
1963N/A Rectangle2D bds2 = gv2.getVisualBounds();
1963N/A Rectangle2D bds3 = gv3.getVisualBounds();
1963N/A GlyphVector gv4 = f.createGlyphVector(frc, " ");
1963N/A Rectangle2D bds4 = gv4.getVisualBounds();
1963N/A System.out.println(bds1);
1963N/A System.out.println(bds2);
1963N/A System.out.println(bds3);
1963N/A System.out.println(bds4);
1963N/A
1963N/A if (!bds1.equals(bds2)) {
1963N/A throw new RuntimeException("Trailing space: Visual bounds differ");
1963N/A }
1963N/A if (bds2.getWidth() != bds3.getWidth()) {
1963N/A throw new RuntimeException("Leading space: Visual widths differ");
1963N/A }
1963N/A if (!bds4.isEmpty()) {
1963N/A throw new RuntimeException("Non empty bounds for space");
1963N/A }
1963N/A }
1963N/A}