< prev index next >

test/java/awt/font/GlyphVector/TestLayoutFlags.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2015, 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 4328745 5090704
  27    @summary exercise getLayoutFlags, getGlyphCharIndex, getGlyphCharIndices
  28  */
  29 
  30 import java.awt.*;
  31 import java.awt.event.*;
  32 import java.awt.font.*;
  33 import java.awt.geom.*;
  34 
  35 public class TestLayoutFlags {
  36 
  37     static public void main(String[] args) {
  38         new TestLayoutFlags().runTest();
  39     }
  40 
  41     void runTest() {
  42 
  43         Font font = new Font("Lucida Sans", Font.PLAIN, 24);
  44 
  45         String latin1 = "This is a latin1 string"; // none
  46         String hebrew = "\u05d0\u05d1\u05d2\u05d3"; // rtl


  65           }
  66         }
  67 
  68         GlyphVector latinGV = makeGlyphVector("Lucida Sans", frc, latin1, false, 1 /* ScriptRun.LATIN */);
  69         GlyphVector hebrewGV = makeGlyphVector("Lucida Sans", frc, hebrew, true, 5 /* ScriptRun.HEBREW */);
  70         GlyphVector arabicGV = makeGlyphVector("Lucida Sans", frc, arabic, true, 6 /* ScriptRun.ARABIC */);
  71         GlyphVector hindiGV = makeGlyphVector("Lucida Sans", frc, hindi, false, 7 /* ScriptRun.DEVANAGARI */);
  72         //      GlyphVector tamilGV = makeGlyphVector("Devanagari MT for IBM", frc, tamil, false, 12 /* ScriptRun.TAMIL */);
  73 
  74         GlyphVector latinPos = font.createGlyphVector(frc, latin1);
  75         Point2D pt = latinPos.getGlyphPosition(0);
  76         pt.setLocation(pt.getX(), pt.getY() + 1.0);
  77         latinPos.setGlyphPosition(0, pt);
  78 
  79         GlyphVector latinTrans = font.createGlyphVector(frc, latin1);
  80         latinTrans.setGlyphTransform(0, AffineTransform.getRotateInstance(.15));
  81 
  82         test("latin", latinGV, GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  83         test("hebrew", hebrewGV, GlyphVector.FLAG_RUN_RTL |
  84              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  85         test("arabic", arabicGV, GlyphVector.FLAG_RUN_RTL |
  86              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  87         test("hindi", hindiGV, GlyphVector.FLAG_COMPLEX_GLYPHS |
  88              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  89         //      test("tamil", tamilGV, GlyphVector.FLAG_COMPLEX_GLYPHS);
  90         test("pos", latinPos, GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  91         test("trans", latinTrans, GlyphVector.FLAG_HAS_TRANSFORMS);
  92     }
  93 
  94     GlyphVector makeGlyphVector(String fontname, FontRenderContext frc, String text, boolean rtl, int script) {
  95         Font font = new Font(fontname, Font.PLAIN, 14);
  96         System.out.println("asking for " + fontname + " and got " + font.getFontName());
  97         int flags = rtl ? 1 : 0;
  98         return font.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), flags);
  99     }
 100 
 101     void test(String name, GlyphVector gv, int expectedFlags) {
 102         expectedFlags &= gv.FLAG_MASK;
 103         int computedFlags = computeFlags(gv) & gv.FLAG_MASK;
 104         int actualFlags = gv.getLayoutFlags() & gv.FLAG_MASK;
 105 


   1 /*
   2  * Copyright (c) 2004, 2016, 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 4328745 5090704 8166111
  27    @summary exercise getLayoutFlags, getGlyphCharIndex, getGlyphCharIndices
  28  */
  29 
  30 import java.awt.*;
  31 import java.awt.event.*;
  32 import java.awt.font.*;
  33 import java.awt.geom.*;
  34 
  35 public class TestLayoutFlags {
  36 
  37     static public void main(String[] args) {
  38         new TestLayoutFlags().runTest();
  39     }
  40 
  41     void runTest() {
  42 
  43         Font font = new Font("Lucida Sans", Font.PLAIN, 24);
  44 
  45         String latin1 = "This is a latin1 string"; // none
  46         String hebrew = "\u05d0\u05d1\u05d2\u05d3"; // rtl


  65           }
  66         }
  67 
  68         GlyphVector latinGV = makeGlyphVector("Lucida Sans", frc, latin1, false, 1 /* ScriptRun.LATIN */);
  69         GlyphVector hebrewGV = makeGlyphVector("Lucida Sans", frc, hebrew, true, 5 /* ScriptRun.HEBREW */);
  70         GlyphVector arabicGV = makeGlyphVector("Lucida Sans", frc, arabic, true, 6 /* ScriptRun.ARABIC */);
  71         GlyphVector hindiGV = makeGlyphVector("Lucida Sans", frc, hindi, false, 7 /* ScriptRun.DEVANAGARI */);
  72         //      GlyphVector tamilGV = makeGlyphVector("Devanagari MT for IBM", frc, tamil, false, 12 /* ScriptRun.TAMIL */);
  73 
  74         GlyphVector latinPos = font.createGlyphVector(frc, latin1);
  75         Point2D pt = latinPos.getGlyphPosition(0);
  76         pt.setLocation(pt.getX(), pt.getY() + 1.0);
  77         latinPos.setGlyphPosition(0, pt);
  78 
  79         GlyphVector latinTrans = font.createGlyphVector(frc, latin1);
  80         latinTrans.setGlyphTransform(0, AffineTransform.getRotateInstance(.15));
  81 
  82         test("latin", latinGV, GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  83         test("hebrew", hebrewGV, GlyphVector.FLAG_RUN_RTL |
  84              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  85         test("arabic", arabicGV, GlyphVector.FLAG_COMPLEX_GLYPHS |
  86              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  87         test("hindi", hindiGV, GlyphVector.FLAG_COMPLEX_GLYPHS |
  88              GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  89         //      test("tamil", tamilGV, GlyphVector.FLAG_COMPLEX_GLYPHS);
  90         test("pos", latinPos, GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS);
  91         test("trans", latinTrans, GlyphVector.FLAG_HAS_TRANSFORMS);
  92     }
  93 
  94     GlyphVector makeGlyphVector(String fontname, FontRenderContext frc, String text, boolean rtl, int script) {
  95         Font font = new Font(fontname, Font.PLAIN, 14);
  96         System.out.println("asking for " + fontname + " and got " + font.getFontName());
  97         int flags = rtl ? 1 : 0;
  98         return font.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), flags);
  99     }
 100 
 101     void test(String name, GlyphVector gv, int expectedFlags) {
 102         expectedFlags &= gv.FLAG_MASK;
 103         int computedFlags = computeFlags(gv) & gv.FLAG_MASK;
 104         int actualFlags = gv.getLayoutFlags() & gv.FLAG_MASK;
 105 


< prev index next >