1package com.nwalsh.saxon;
2
3import org.xml.sax.SAXException;
4import org.w3c.dom.*;
5
6import javax.xml.transform.TransformerException;
7
8import com.icl.saxon.om.NamePool;
9import com.icl.saxon.output.Emitter;
10import com.icl.saxon.tree.AttributeCollection;
11
12import 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.1 2001/07/16 21:23:57 nwalsh 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.1 2001/07/16 21:23:57 nwalsh Exp $
33 **/
34
35public 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