KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > gvt > renderer > ConcreteTextPainter


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.gvt.renderer;
19
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.font.TextLayout JavaDoc;
22 import java.awt.geom.Point2D JavaDoc;
23 import java.text.AttributedCharacterIterator JavaDoc;
24
25 import org.apache.batik.gvt.TextNode;
26
27 /**
28  * Renders the attributed character iterator of a <tt>TextNode</tt>.
29  *
30  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
31  * @version $Id: ConcreteTextPainter.java,v 1.7 2005/03/27 08:58:34 cam Exp $
32  */

33 public abstract class ConcreteTextPainter extends BasicTextPainter {
34
35     /**
36      * Paints the specified attributed character iterator using the
37      * specified Graphics2D and context and font context.
38      * @param aci the AttributedCharacterIterator containing the text
39      * @param location the location to paint the text
40      * @param anchor the text anchor position
41      * @param g2d the Graphics2D to use
42      */

43     public void paint(AttributedCharacterIterator JavaDoc aci, Point2D JavaDoc location,
44                       TextNode.Anchor anchor, Graphics2D JavaDoc g2d) {
45         // Compute aci size to be able to draw it
46
TextLayout JavaDoc layout = new TextLayout JavaDoc(aci, fontRenderContext);
47         float advance = layout.getAdvance();
48         float tx = 0;
49
50         switch(anchor.getType()){
51         case TextNode.Anchor.ANCHOR_MIDDLE:
52             tx = -advance/2;
53             break;
54         case TextNode.Anchor.ANCHOR_END:
55             tx = -advance;
56         }
57         layout.draw(g2d, (float)(location.getX() + tx), (float)(location.getY()));
58     }
59
60 }
61
Popular Tags