view j2se/test/java/awt/font/TextLayout/TestHebrewMark.java @ 2:16f2b6c91171 trunk

[svn] Load openjdk/jdk7/b14 into jdk/trunk.
author xiomara
date Fri, 22 Jun 2007 00:46:43 +0000
parents
children
line wrap: on
line source

/*
 * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
/* @test
 * @summary verify TextLayout handles Hebrew marks correctly
 * @bug 6529141
 */

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;

public class TestHebrewMark {

    public static void main(String args[]) {
       FontRenderContext frc = new FontRenderContext(null,false,false);
       final String fonts[] = { "Arial", "Lucida Sans", "Lucida Sans Regular" };
       final char ALEF = '\u05D0';
       final char QAMATS = '\u05B8';  // a combining mark, should show up UNDER the alef (no advance)
       final char chars1[] = { ALEF };
       final char chars2[] = { ALEF, QAMATS };
       final String string1 = new String(chars1);
       final String string2 = new String(chars2);
       Font f = null;
       // try to find a font that will work
       for(String fontname : fonts ) {
           Font afont = new Font(fontname,Font.PLAIN,32);
           if(!afont.getFontName().equals(fontname)) {
             System.out.println(fontname + ": is actually  " + afont.getFontName() + " - skipping this font.");
             continue;
           }
           if(!afont.canDisplay(ALEF) || !afont.canDisplay(QAMATS)) {
             System.out.println(fontname + ": can't display ALEF or QAMATS - skipping this font");
             continue;
           }
           f = afont;
       } 

       if(f == null) {
           System.out.println("Could not find a suitable font - skipping this test.");
           return;
       }
       System.out.println("Using font " + f.getFontName());
       TextLayout tl = new TextLayout(string1, f, frc);
       TextLayout tl2 = new TextLayout(string2, f, frc);
       Rectangle2D tlBounds = tl.getBounds();
       Rectangle2D tlBounds2 = tl2.getBounds();
       System.out.println("tlbounds="+tlBounds);
       System.out.println("tl.getAdvance()="+tl.getAdvance());
       System.out.println("tl2bounds="+tlBounds2);
       System.out.println("tl2.getAdvance()="+tl2.getAdvance());

       if(tl.getAdvance() != tl2.getAdvance()) {
          throw new RuntimeException("Advance of alef with and without QAMATS differs: " + tl.getAdvance() + " vs. " + tl2.getAdvance());
       } else {
          System.out.println("6529141 OK, widths are same.");
       }
    }
}