3543N/A/*
3543N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
3543N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3543N/A *
3543N/A * This code is free software; you can redistribute it and/or modify it
3543N/A * under the terms of the GNU General Public License version 2 only, as
3543N/A * published by the Free Software Foundation.
3543N/A *
3543N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3543N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3543N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3543N/A * version 2 for more details (a copy is included in the LICENSE file that
3543N/A * accompanied this code).
3543N/A *
3543N/A * You should have received a copy of the GNU General Public License version
3543N/A * 2 along with this work; if not, write to the Free Software Foundation,
3543N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3543N/A *
3543N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3543N/A * or visit www.oracle.com if you need additional information or have any
3543N/A * questions.
3543N/A */
3543N/A
3543N/A/*
3543N/A @test
3543N/A @bug 6686365 7017637
3543N/A @summary Confirm that styling does not affect metrics of zero advance glyphs
3543N/A*/
3543N/A
3543N/Aimport java.awt.*;
3543N/Aimport java.awt.image.*;
3543N/A
3543N/Apublic class BoldSpace {
3543N/A public static void main(String[] s) {
3543N/A BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
3543N/A
3543N/A String errMsg = "ZWJ Space char should have 0 advance\n";
3543N/A
3543N/A Graphics g = bi.getGraphics();
3543N/A
3543N/A // It turns out that some fonts inexplicably treat this as
3543N/A // a standard character. In this 14 pt font, if we see an advance
3543N/A // that's clearly bigger than we'd have introduced in bolding we'll
3543N/A // not error out this test, presuming that its a consequence of
3543N/A // the actual font data. A Linux font 'TLwg Type Bold' is the case
3543N/A // in point.
3543N/A int errorMargin = 4;
3543N/A g.setFont(new Font("monospaced", Font.BOLD, 14));
3543N/A //g.setFont(new Font("Lucida Sans Regular", Font.BOLD, 14));
3543N/A FontMetrics fm = g.getFontMetrics();
3543N/A System.out.println("Bold: " + fm.charWidth('\u200b'));
3543N/A int cwid = fm.charWidth('\u200b');
3543N/A if (cwid > 0 && cwid < errorMargin) {
3543N/A throw new RuntimeException(errMsg);
3543N/A }
3543N/A
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
3543N/A RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
3543N/A fm = g.getFontMetrics();
3543N/A System.out.println("Bold + LCD: "+fm.charWidth('\u200b'));
3543N/A cwid = fm.charWidth('\u200b');
3543N/A if (cwid > 0 && cwid < errorMargin) {
3543N/A throw new RuntimeException(errMsg);
3543N/A }
3543N/A
3543N/A
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
3543N/A RenderingHints.VALUE_FRACTIONALMETRICS_ON);
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
3543N/A RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
3543N/A fm = g.getFontMetrics();
3543N/A System.out.println("Bold FM OFF + AA: " + fm.charWidth('\u200b'));
3543N/A cwid = fm.charWidth('\u200b');
3543N/A if (cwid > 0 && cwid < errorMargin) {
3543N/A throw new RuntimeException(errMsg);
3543N/A }
3543N/A
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
3543N/A RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
3543N/A RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
3543N/A fm = g.getFontMetrics();
3543N/A System.out.println("Bold FM ON + AA: " + fm.charWidth('\u200b'));
3543N/A cwid = fm.charWidth('\u200b');
3543N/A if (cwid > 0 && cwid < errorMargin) {
3543N/A throw new RuntimeException(errMsg);
3543N/A }
3543N/A
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
3543N/A RenderingHints.VALUE_FRACTIONALMETRICS_ON);
3543N/A ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
3543N/A RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
3543N/A fm = g.getFontMetrics();
3543N/A System.out.println("Bold FM ON + nonAA: " + fm.charWidth('\u200b'));
3543N/A cwid = fm.charWidth('\u200b');
3543N/A if (cwid > 0 && cwid < errorMargin) {
3543N/A throw new RuntimeException(errMsg);
3543N/A }
3543N/A
3543N/A System.out.println("All printed values should be 0 to PASS");
3543N/A }
3543N/A}