1 17 18 19 20 package org.apache.fop.svg; 21 22 import org.apache.batik.gvt.TextNode; 23 import org.apache.batik.bridge.SVGTextElementBridge; 24 import org.apache.batik.bridge.BridgeContext; 25 import org.apache.batik.bridge.TextUtilities; 26 import org.apache.batik.gvt.GraphicsNode; 27 28 import org.apache.fop.fonts.FontInfo; 29 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 33 40 public class PDFTextElementBridge extends SVGTextElementBridge { 41 private PDFTextPainter pdfTextPainter; 42 43 47 public PDFTextElementBridge(FontInfo fi) { 48 pdfTextPainter = new PDFTextPainter(fi); 49 } 50 51 58 public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { 59 GraphicsNode node = super.createGraphicsNode(ctx, e); 60 if (node != null && isSimple(ctx, e, node)) { 61 ((TextNode)node).setTextPainter(getTextPainter()); 62 } 63 return node; 64 } 65 66 private PDFTextPainter getTextPainter() { 67 return pdfTextPainter; 68 } 69 70 84 private boolean isSimple(BridgeContext ctx, Element element, GraphicsNode node) { 85 float fs = TextUtilities.convertFontSize(element).floatValue(); 87 if (fs > 36) { 89 return false; 90 } 91 92 Element nodeElement; 93 for (Node n = element.getFirstChild(); 94 n != null; 95 n = n.getNextSibling()) { 96 97 switch (n.getNodeType()) { 98 case Node.ELEMENT_NODE: 99 100 nodeElement = (Element )n; 101 102 if (n.getLocalName().equals(SVG_TSPAN_TAG) 103 || n.getLocalName().equals(SVG_ALT_GLYPH_TAG)) { 104 return false; 105 } else if (n.getLocalName().equals(SVG_TEXT_PATH_TAG)) { 106 return false; 107 } else if (n.getLocalName().equals(SVG_TREF_TAG)) { 108 return false; 109 } 110 break; 111 case Node.TEXT_NODE: 112 case Node.CDATA_SECTION_NODE: 113 } 114 } 115 116 119 120 return true; 121 } 122 } 123 124 | Popular Tags |