1 package com.nwalsh.saxon; 2 3 import org.xml.sax.SAXException ; 4 import org.w3c.dom.*; 5 6 import javax.xml.transform.TransformerException ; 7 8 import com.icl.saxon.om.NamePool; 9 import com.icl.saxon.output.Emitter; 10 import com.icl.saxon.tree.AttributeCollection; 11 12 import com.nwalsh.saxon.Callout; 13 14 34 35 public class FormatGraphicCallout extends FormatCallout { 36 String graphicsPath = ""; 37 String graphicsExt = ""; 38 int graphicsMax = 0; 39 40 public FormatGraphicCallout(NamePool nPool, String path, String ext, int max, boolean fo) { 41 super(nPool, fo); 42 graphicsPath = path; 43 graphicsExt = ext; 44 graphicsMax = max; 45 } 46 47 public void formatCallout(Emitter rtfEmitter, 48 Callout callout) { 49 Element area = callout.getArea(); 50 int num = callout.getCallout(); 51 String userLabel = areaLabel(area); 52 String label = "(" + num + ")"; 53 54 if (userLabel != null) { 55 label = userLabel; 56 } 57 58 try { 59 if (userLabel == null && num <= graphicsMax) { 60 int imgName = 0; 61 AttributeCollection imgAttr = null; 62 int namespaces[] = new int[1]; 63 64 if (foStylesheet) { 65 imgName = namePool.allocate("fo", foURI, "external-graphic"); 66 imgAttr = new AttributeCollection(namePool); 67 imgAttr.addAttribute("", "", "src", "CDATA", 68 graphicsPath + num + graphicsExt); 69 } else { 70 imgName = namePool.allocate("", "", "img"); 71 imgAttr = new AttributeCollection(namePool); 72 imgAttr.addAttribute("", "", "src", "CDATA", 73 graphicsPath + num + graphicsExt); 74 imgAttr.addAttribute("", "", "alt", "CDATA", label); 75 } 76 77 startSpan(rtfEmitter); 78 rtfEmitter.startElement(imgName, imgAttr, namespaces, 0); 79 rtfEmitter.endElement(imgName); 80 endSpan(rtfEmitter); 81 } else { 82 formatTextCallout(rtfEmitter, callout); 83 } 84 } catch (TransformerException e) { 85 System.out.println("Transformer Exception in graphic formatCallout"); 86 } 87 } 88 } 89 | Popular Tags |