1 /*
2  * Copyright (c) 2008, 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 TranslatedOutlineTest
26  * @bug 6703377
27  * @summary This test verifies that outline is translated in a correct direction
28  * @run main TranslatedOutlineTest
29  */
30 
31 import java.awt.Color;
32 import java.awt.Graphics2D;
33 import java.awt.RenderingHints;
34 import java.awt.font.FontRenderContext;
35 import java.awt.font.GlyphVector;
36 import java.awt.image.BufferedImage;
37 
38 public class TranslatedOutlineTest {
main(String a[])39    public static void main(String a[]) {
40         /* prepare blank image */
41         BufferedImage bi = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
42         Graphics2D g2 = (Graphics2D) bi.getGraphics();
43         g2.setColor(Color.WHITE);
44         g2.fillRect(0, 0, 50, 50);
45 
46         /* draw outline somethere in the middle of the image */
47         FontRenderContext frc = new FontRenderContext(null, false, false);
48         g2.setColor(Color.RED);
49         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
50         GlyphVector gv = g2.getFont().createGlyphVector(frc, "test");
51         g2.fill(gv.getOutline(20, 20));
52 
53         /* Check if anything was drawn.
54          * If y direction is not correct then image is still blank and
55          * test will fail.
56          */
57         int bgcolor = Color.WHITE.getRGB();
58         for (int i=0; i<bi.getWidth(); i++) {
59             for(int j=0; j<bi.getHeight(); j++) {
60                if (bi.getRGB(i, j) != bgcolor) {
61                    System.out.println("Test passed.");
62                    return;
63                }
64             }
65         }
66         throw new RuntimeException("Outline was not detected");
67     }
68 }
69