KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > Bug4945


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen;
19
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.Font JavaDoc;
22 import java.awt.geom.AffineTransform JavaDoc;
23
24 /**
25  * This test validates fix to Bug #4945 which checks that
26  * the generator handles Font transform.
27  *
28  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
29  * @version $Id: Bug4945.java,v 1.4 2004/08/18 07:16:44 vhardy Exp $
30  */

31 public class Bug4945 implements Painter {
32     public void paint(Graphics2D JavaDoc g){
33         Font JavaDoc origFont = g.getFont();
34
35         g.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,
36                            java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
37        
38         // 1) create scaled font
39
Font JavaDoc font = origFont.deriveFont(AffineTransform.getScaleInstance(1.5, 3));
40         g.setFont(font);
41         g.drawString("Scaled Font", 20, 40);
42
43         // 2) create translated font
44
font = origFont.deriveFont(AffineTransform.getTranslateInstance(50, 20));
45         g.setFont(font);
46         g.drawString("Translated Font", 20, 80);
47         g.drawLine(20, 80, 120, 80);
48
49         // 3) create sheared font
50
font = origFont.deriveFont(AffineTransform.getShearInstance(.5, .5));
51         g.setFont(font);
52         g.drawString("Sheared Font", 20, 120);
53
54         // 4) create rotated font
55
font = origFont.deriveFont(AffineTransform.getRotateInstance(Math.PI/4));
56         g.setFont(font);
57         g.drawString("Rotated Font", 220, 120);
58     }
59 }
60
61
Popular Tags