1 // Copyright 2019 Azul Systems, Inc. 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 it under 5 // the terms of the GNU General Public License version 2 only, as published by 6 // the Free Software Foundation. 7 // 8 // This code is distributed in the hope that it will be useful, but WITHOUT ANY 9 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 // A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more 11 // details (a copy is included in the LICENSE file that accompanied this code). 12 // 13 // You should have received a copy of the GNU General Public License version 2 14 // along with this work; if not, write to the Free Software Foundation, Inc., 15 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16 // 17 // Please contact Azul Systems, 385 Moffett Park Drive, Suite 115, Sunnyvale, 18 // CA 94089 USA or visit www.azul.com if you need additional information or 19 // have any questions. 20 21 import java.awt.Font; 22 import java.awt.Color; 23 import java.awt.Graphics2D; 24 import java.awt.image.BufferedImage; 25 26 /* 27 * @test 28 * @summary Fix to 8215210 should not break RTL with AAT fonts. 29 * @run main/othervm -Dsun.font.layoutengine=icu HebrewIsRTLTest 30 */ 31 public class HebrewIsRTLTest { 32 static final String hebrewString = "\u05E9\u059E\u05E9\u0595\u05E9\u05A9\u05E9\u0592\u05E9\u0599\u05E9\u059E\u05E9\u0595\u05E9\u05A9\u05E9\u0592\u05E9\u0599 . \u05E9\u0599\u05E9\u05A1\u05E9\u0595\u05E9\u0593"; 33 public static void main(String args[]) { 34 if (!System.getProperty("os.name").startsWith("Mac")) { 35 return; 36 } 37 38 // calculate text size 39 BufferedImage biMetrics = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_RGB); 40 Graphics2D biMetricsGraphics = biMetrics.createGraphics(); 41 Font font = new Font("TimesRoman", Font.PLAIN, 40); 42 biMetricsGraphics.setFont(font); 43 int width = biMetricsGraphics.getFontMetrics().stringWidth(hebrewString); 44 int height = biMetricsGraphics.getFontMetrics().getHeight(); 45 46 // create minimal image 47 BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 48 Graphics2D biGraphics = bi.createGraphics(); 49 biGraphics.setColor(Color.white); 50 biGraphics.fillRect(0, 0, width, height); 51 biGraphics.setColor(Color.black); 52 biGraphics.setFont(font); 53 biGraphics.drawString(hebrewString, 0, height); 54 55 int y = bi.getHeight() / 2; 56 int x; 57 int rgb, rgbLeftCount = 0, rgbRightCount = 0; 58 59 for (x = 0; x < bi.getWidth()/2; x++) { 60 rgb = bi.getRGB(x, y); 61 if (rgb == Color.BLACK.getRGB()) { 62 rgbLeftCount++; 63 } 64 } 65 for (x = bi.getWidth()/2 + 1; x < bi.getWidth(); x++) { 66 rgb = bi.getRGB(x, y); 67 if (rgb == Color.BLACK.getRGB()) { 68 rgbRightCount++; 69 } 70 } 71 if (rgbLeftCount > rgbRightCount) { 72 throw new RuntimeException("Hebrew text seems drawn LTR"); 73 } 74 } 75 }