| 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 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class FormatGraphicCallout extends FormatCallout { |
| 36 |
String graphicsPath = ""; |
| 37 |
String graphicsExt = ""; |
| 38 |
int graphicsMax = 0; |
| 39 |
String iconSize = ""; |
| 40 |
|
| 41 |
public FormatGraphicCallout(NamePool nPool, String path, String ext, int max, String size, boolean fo) { |
| 42 |
super(nPool, fo); |
| 43 |
graphicsPath = path; |
| 44 |
graphicsExt = ext; |
| 45 |
graphicsMax = max; |
| 46 |
iconSize = size; |
| 47 |
} |
| 48 |
|
| 49 |
public void formatCallout(Emitter rtfEmitter, |
| 50 |
Callout callout) { |
| 51 |
Element area = callout.getArea(); |
| 52 |
int num = callout.getCallout(); |
| 53 |
String userLabel = areaLabel(area); |
| 54 |
String label = "(" + num + ")"; |
| 55 |
String id = areaID(area); |
| 56 |
|
| 57 |
if (userLabel != null) { |
| 58 |
label = userLabel; |
| 59 |
} |
| 60 |
|
| 61 |
try { |
| 62 |
if (userLabel == null && num <= graphicsMax) { |
| 63 |
int imgName = 0; |
| 64 |
AttributeCollection imgAttr = null; |
| 65 |
int namespaces[] = new int[1]; |
| 66 |
|
| 67 |
if (foStylesheet) { |
| 68 |
imgName = namePool.allocate("fo", foURI, "external-graphic"); |
| 69 |
imgAttr = new AttributeCollection(namePool); |
| 70 |
imgAttr.addAttribute("", "", "src", "CDATA", "url(" + |
| 71 |
graphicsPath + num + graphicsExt + ")"); |
| 72 |
imgAttr.addAttribute("", "", "id", "CDATA", id); |
| 73 |
imgAttr.addAttribute("", "", "content-width", "CDATA", iconSize); |
| 74 |
imgAttr.addAttribute("", "", "width", "CDATA", iconSize); |
| 75 |
|
| 76 |
|
| 77 |
} else { |
| 78 |
imgName = namePool.allocate("", "", "img"); |
| 79 |
imgAttr = new AttributeCollection(namePool); |
| 80 |
imgAttr.addAttribute("", "", "src", "CDATA", |
| 81 |
graphicsPath + num + graphicsExt); |
| 82 |
imgAttr.addAttribute("", "", "alt", "CDATA", label); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
startSpan(rtfEmitter, id); |
| 87 |
rtfEmitter.startElement(imgName, imgAttr, namespaces, 0); |
| 88 |
rtfEmitter.endElement(imgName); |
| 89 |
endSpan(rtfEmitter); |
| 90 |
} else { |
| 91 |
formatTextCallout(rtfEmitter, callout); |
| 92 |
} |
| 93 |
} catch (TransformerException e) { |
| 94 |
System.out.println("Transformer Exception in graphic formatCallout"); |
| 95 |
} |
| 96 |
} |
| 97 |
} |