1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8204929 27 * @summary test rotation of font with embedded bitmaps 28 * @run main GlyphRotationTest 29 */ 30 31 import java.awt.Color; 32 import java.awt.Font; 33 import java.awt.Graphics2D; 34 import java.awt.geom.AffineTransform; 35 import java.awt.image.BufferedImage; 36 import javax.imageio.ImageIO; 37 38 public class GlyphRotationTest { 39 40 public static final String fontName = "MS UI Gothic"; 41 public static Font font; 42 public static final int SZ = 50; 43 44 public static void main(String[] args) { 45 font = new Font(fontName, Font.PLAIN, 15); 46 if (!font.getFamily(java.util.Locale.ENGLISH).equals(fontName)) { 47 return; 48 } 49 BufferedImage bi = new BufferedImage(SZ,SZ,BufferedImage.TYPE_INT_RGB); 50 Graphics2D g2d = bi.createGraphics(); 51 g2d.setColor(Color.white); 52 g2d.fillRect(0, 0, SZ, SZ); 53 g2d.setColor(Color.black); 54 g2d.setFont(font); 55 g2d.drawString("1", SZ/2, SZ/2); 56 int pixCnt1 = countPixels(bi); 57 AffineTransform at = AffineTransform.getRotateInstance(Math.PI/2); 58 font = font.deriveFont(Font.PLAIN, at); 59 g2d.setFont(font); 60 g2d.drawString("1", SZ/2, SZ/2); 61 int pixCnt2 = countPixels(bi); 62 if (args.length > 0) { 63 try { 64 ImageIO.write(bi, "png", new java.io.File("im.png")); 65 } catch (Exception e) {} 66 } 67 if (pixCnt1 == pixCnt2) { 68 String msg = "cnt 1 = " + pixCnt1 + " cnt 2 = " + pixCnt2; 69 throw new RuntimeException(msg); 70 } 71 } 72 73 static int countPixels(BufferedImage bi) { 74 int cnt = 0; 75 int w = bi.getWidth(null); 76 int h = bi.getHeight(null); 77 for (int i=0; i<w; i++) { 78 for (int j=0; j<w; j++) { 79 int rgb = bi.getRGB(i, j) & 0xFFFFFF; 80 if (rgb == 0) { 81 cnt++; 82 } 83 } 84 } 85 return cnt; 86 } 87 }