1 18 package org.apache.batik.gvt.renderer; 19 20 import java.awt.Graphics2D ; 21 import java.awt.font.TextLayout ; 22 import java.awt.geom.Point2D ; 23 import java.text.AttributedCharacterIterator ; 24 25 import org.apache.batik.gvt.TextNode; 26 27 33 public abstract class ConcreteTextPainter extends BasicTextPainter { 34 35 43 public void paint(AttributedCharacterIterator aci, Point2D location, 44 TextNode.Anchor anchor, Graphics2D g2d) { 45 TextLayout layout = new TextLayout (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 |