Path: blob/master/test/jdk/java/awt/FontClass/GlyphRotationTest.java
41149 views
/*1* Copyright (c) 2018, 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* @test25* @bug 820492926* @summary test rotation of font with embedded bitmaps27* @run main GlyphRotationTest28*/2930import java.awt.Color;31import java.awt.Font;32import java.awt.Graphics2D;33import java.awt.geom.AffineTransform;34import java.awt.image.BufferedImage;35import javax.imageio.ImageIO;3637public class GlyphRotationTest {3839public static final String fontName = "MS UI Gothic";40public static Font font;41public static final int SZ = 50;4243public static void main(String[] args) {44font = new Font(fontName, Font.PLAIN, 15);45if (!font.getFamily(java.util.Locale.ENGLISH).equals(fontName)) {46return;47}48BufferedImage bi = new BufferedImage(SZ,SZ,BufferedImage.TYPE_INT_RGB);49Graphics2D g2d = bi.createGraphics();50g2d.setColor(Color.white);51g2d.fillRect(0, 0, SZ, SZ);52g2d.setColor(Color.black);53g2d.setFont(font);54g2d.drawString("1", SZ/2, SZ/2);55int pixCnt1 = countPixels(bi);56AffineTransform at = AffineTransform.getRotateInstance(Math.PI/2);57font = font.deriveFont(Font.PLAIN, at);58g2d.setFont(font);59g2d.drawString("1", SZ/2, SZ/2);60int pixCnt2 = countPixels(bi);61if (args.length > 0) {62try {63ImageIO.write(bi, "png", new java.io.File("im.png"));64} catch (Exception e) {}65}66if (pixCnt1 == pixCnt2) {67String msg = "cnt 1 = " + pixCnt1 + " cnt 2 = " + pixCnt2;68throw new RuntimeException(msg);69}70}7172static int countPixels(BufferedImage bi) {73int cnt = 0;74int w = bi.getWidth(null);75int h = bi.getHeight(null);76for (int i=0; i<w; i++) {77for (int j=0; j<w; j++) {78int rgb = bi.getRGB(i, j) & 0xFFFFFF;79if (rgb == 0) {80cnt++;81}82}83}84return cnt;85}86}878889