1 /* 2 * Copyright (c) 2007, 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 /* @test 24 * @summary verify TextLayout handles Hebrew marks correctly 25 * @bug 6529141 26 */ 27 28 import java.awt.*; 29 import java.awt.font.*; 30 import java.awt.geom.*; 31 32 public class TestHebrewMark { 33 main(String args[])34 public static void main(String args[]) { 35 FontRenderContext frc = new FontRenderContext(null,false,false); 36 final String fonts[] = { "Arial", "Arial Hebrew", "Arial Unicode" }; 37 final char ALEF = '\u05D0'; // a letter 38 final char QAMATS = '\u05B8'; // a combining mark, should show up UNDER the alef (no advance) 39 final String string1 = "\u05DE\u05B8\u05E9\u05C1\u05B0\u05DB\u05B5\u05E0\u05B4\u05D9\u05D0\u05B7\u05D7\u05B2\u05E8\u05B6\u05D9\u05DA\u05B8\u05E0\u05BC\u05B8\u05E8\u05D5\u05BC\u05E6\u05B8\u05D4\u05D4\u05B1\u05D1\u05B4\u05D9\u05D0\u05B7\u05E0\u05B4\u05D9\u05D4\u05B7\u05DE\u05BC\u05B6\u05DC\u05B6\u05DA\u05B0\u05D7\u05B2\u05D3\u05B8\u05E8\u05B8\u05D9\u05D5\u05E0\u05B8\u05D2\u05B4\u05D9\u05DC\u05B8\u05D4\u05D5\u05B0\u05E0\u05B4\u05E9\u05C2\u05B0\u05DE\u05B0\u05D7\u05B8\u05D4\u0020\u05D1\u05BC\u05B8\u05DA\u05B0\u05E0\u05B7\u05D6\u05B0\u05DB\u05BC\u05B4\u05D9\u05E8\u05B8\u05D4\u05D3\u05B9\u05D3\u05B6\u05D9\u05DA\u05B8\u05DE\u05B4\u05D9\u05BC\u05B7\u05D9\u05B4\u05DF\u05DE\u05B5\u05D9\u05E9\u05C1\u05B8\u05E8\u05B4\u05D9\u05DD\u05D0\u05B2\u05D4\u05B5\u05D1\u05D5\u05BC\u05DA\u05B8"; 40 final String string2 = string1.replaceAll("\u05B8", ""); // remove qamats 41 int string1len = string1.length(); 42 int string2len = string2.length(); 43 System.out.println("String1 has " + string1len+" chars, and string2 (without the QAMATS) has " + string2.length()); 44 if(string1len == string2len) { 45 throw new RuntimeException("Hey, string1 and string2 are both " + string1len + " chars long - shouldn't happen."); 46 } 47 Font f = null; 48 // try to find a font that will work 49 for(String fontname : fonts ) { 50 System.err.println("trying: " +fontname); 51 Font afont = new Font(fontname,Font.PLAIN,18); 52 if(!afont.getFontName().equals(fontname)) { 53 System.out.println(fontname + ": is actually " + afont.getFontName() + " - skipping this font."); 54 continue; 55 } 56 if(!afont.canDisplay(ALEF) || !afont.canDisplay(QAMATS)) { 57 System.out.println(fontname + ": can't display ALEF or QAMATS - skipping this font"); 58 continue; 59 } 60 f = afont; 61 System.err.println("Might be OK: " + fontname); 62 System.out.println("Using font " + f.getFontName()); 63 TextLayout tl = new TextLayout(string1, f, frc); 64 TextLayout tl2 = new TextLayout(string2, f, frc); 65 Rectangle2D tlBounds = tl.getBounds(); 66 Rectangle2D tlBounds2 = tl2.getBounds(); 67 System.out.println("tlbounds="+tlBounds); 68 System.out.println("tl.getAdvance()="+tl.getAdvance()); 69 System.out.println("tl2bounds="+tlBounds2); 70 System.out.println("tl2.getAdvance()="+tl2.getAdvance()); 71 72 if(tl.getAdvance() != tl2.getAdvance()) { 73 throw new RuntimeException("Advance of string with and without QAMATS differs: " + tl.getAdvance() + " vs. " + tl2.getAdvance()); 74 } else { 75 System.out.println("6529141 OK, widths are same."); 76 } 77 } 78 // print a notice if none of them worked. 79 if(f == null) { 80 System.out.println("Could not find a suitable font - skipping this test."); 81 return; 82 } 83 } 84 } 85