1 18 package org.apache.batik.gvt.renderer; 19 20 import java.awt.font.FontRenderContext ; 21 import java.awt.geom.AffineTransform ; 22 import java.awt.geom.Rectangle2D ; 23 24 import org.apache.batik.gvt.TextNode; 25 import org.apache.batik.gvt.TextPainter; 26 import org.apache.batik.gvt.text.ConcreteTextLayoutFactory; 27 import org.apache.batik.gvt.text.Mark; 28 import org.apache.batik.gvt.text.TextHit; 29 import org.apache.batik.gvt.text.TextLayoutFactory; 30 31 41 public abstract class BasicTextPainter implements TextPainter { 42 43 private static TextLayoutFactory textLayoutFactory = 44 new ConcreteTextLayoutFactory(); 45 46 49 protected FontRenderContext fontRenderContext = 50 new FontRenderContext (new AffineTransform (), true, true); 51 52 protected FontRenderContext aaOffFontRenderContext = 53 new FontRenderContext (new AffineTransform (), false, true); 54 55 protected TextLayoutFactory getTextLayoutFactory() { 56 return textLayoutFactory; 57 } 58 59 65 public Mark selectAt(double x, double y, TextNode node) { 66 return hitTest(x, y, node); 67 } 68 69 75 public Mark selectTo(double x, double y, Mark beginMark) { 76 if (beginMark == null) { 77 return null; 78 } else { 79 return hitTest(x, y, beginMark.getTextNode()); 80 } 81 } 82 83 84 89 public Rectangle2D getGeometryBounds(TextNode node) { 90 return getOutline(node).getBounds2D(); 91 } 92 93 96 protected abstract Mark hitTest(double x, double y, TextNode node); 97 98 102 105 protected static class BasicMark implements Mark { 106 107 private TextNode node; 108 private TextHit hit; 109 110 113 protected BasicMark(TextNode node, 114 TextHit hit) { 115 this.hit = hit; 116 this.node = node; 117 } 118 119 public TextHit getHit() { 120 return hit; 121 } 122 123 public TextNode getTextNode() { 124 return node; 125 } 126 127 132 public int getCharIndex() { 133 return hit.getCharIndex(); 134 } 135 } 136 } 137 138 139 | Popular Tags |