01: package com.nwalsh.saxon;
02:
03: import org.xml.sax.SAXException;
04: import org.w3c.dom.*;
05:
06: import javax.xml.transform.TransformerException;
07:
08: import com.icl.saxon.om.NamePool;
09: import com.icl.saxon.output.Emitter;
10: import com.icl.saxon.tree.AttributeCollection;
11:
12: import com.nwalsh.saxon.Callout;
13:
14: /**
15: * <p>Utility class for the Verbatim extension (ignore this).</p>
16: *
17: * <p>$Id: FormatGraphicCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $</p>
18: *
19: * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
20: *
21: * <p><b>Change Log:</b></p>
22: * <dl>
23: * <dt>1.0</dt>
24: * <dd><p>Initial release.</p></dd>
25: * </dl>
26: *
27: * @author Norman Walsh
28: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
29: *
30: * @see Verbatim
31: *
32: * @version $Id: FormatGraphicCallout.java,v 1.4 2005-08-30 08:14:58 draganr Exp $
33: **/
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,
41: String ext, int max, boolean fo) {
42: super (nPool, fo);
43: graphicsPath = path;
44: graphicsExt = ext;
45: graphicsMax = max;
46: }
47:
48: public void formatCallout(Emitter rtfEmitter, 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,
66: "external-graphic");
67: imgAttr = new AttributeCollection(namePool);
68: imgAttr.addAttribute("", "", "src", "CDATA",
69: graphicsPath + num + graphicsExt);
70: } else {
71: imgName = namePool.allocate("", "", "img");
72: imgAttr = new AttributeCollection(namePool);
73: imgAttr.addAttribute("", "", "src", "CDATA",
74: graphicsPath + num + graphicsExt);
75: imgAttr.addAttribute("", "", "alt", "CDATA", label);
76: }
77:
78: startSpan(rtfEmitter);
79: rtfEmitter
80: .startElement(imgName, imgAttr, namespaces, 0);
81: rtfEmitter.endElement(imgName);
82: endSpan(rtfEmitter);
83: } else {
84: formatTextCallout(rtfEmitter, callout);
85: }
86: } catch (TransformerException e) {
87: System.out
88: .println("Transformer Exception in graphic formatCallout");
89: }
90: }
91: }
|