| 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 FormatUnicodeCallout extends FormatCallout { |
| 36 |
int unicodeMax = 0; |
| 37 |
int unicodeStart = 0; |
| 38 |
String unicodeFont = ""; |
| 39 |
|
| 40 |
public FormatUnicodeCallout(NamePool nPool, |
| 41 |
String font, |
| 42 |
int start, |
| 43 |
int max, |
| 44 |
boolean fo) { |
| 45 |
super(nPool, fo); |
| 46 |
unicodeFont = font; |
| 47 |
unicodeMax = max; |
| 48 |
unicodeStart = start; |
| 49 |
} |
| 50 |
|
| 51 |
public void formatCallout(Emitter rtfEmitter, |
| 52 |
Callout callout) { |
| 53 |
Element area = callout.getArea(); |
| 54 |
int num = callout.getCallout(); |
| 55 |
String userLabel = areaLabel(area); |
| 56 |
String label = ""; |
| 57 |
String id = areaID(area); |
| 58 |
|
| 59 |
if (userLabel != null) { |
| 60 |
label = userLabel; |
| 61 |
} |
| 62 |
|
| 63 |
try { |
| 64 |
if (userLabel == null && num <= unicodeMax) { |
| 65 |
int inName = 0; |
| 66 |
AttributeCollection inAttr = null; |
| 67 |
int namespaces[] = new int[1]; |
| 68 |
|
| 69 |
if (!unicodeFont.equals("")) { |
| 70 |
if (foStylesheet) { |
| 71 |
inName = namePool.allocate("fo", foURI, "inline"); |
| 72 |
inAttr = new AttributeCollection(namePool); |
| 73 |
inAttr.addAttribute("", "", "font-family", "CDATA", unicodeFont); |
| 74 |
inAttr.addAttribute("", "", "id", "ID", id); |
| 75 |
|
| 76 |
} else { |
| 77 |
inName = namePool.allocate("", "", "font"); |
| 78 |
inAttr = new AttributeCollection(namePool); |
| 79 |
inAttr.addAttribute("", "", "face", "CDATA", unicodeFont); |
| 80 |
inAttr.addAttribute("", "", "id", "ID", id); |
| 81 |
} |
| 82 |
|
| 83 |
startSpan(rtfEmitter, id); |
| 84 |
rtfEmitter.startElement(inName, inAttr, namespaces, 0); |
| 85 |
} |
| 86 |
|
| 87 |
char chars[] = new char[1]; |
| 88 |
chars[0] = (char) (unicodeStart + num - 1); |
| 89 |
rtfEmitter.characters(chars, 0, 1); |
| 90 |
|
| 91 |
if (!unicodeFont.equals("")) { |
| 92 |
rtfEmitter.endElement(inName); |
| 93 |
endSpan(rtfEmitter); |
| 94 |
} |
| 95 |
} else { |
| 96 |
formatTextCallout(rtfEmitter, callout); |
| 97 |
} |
| 98 |
} catch (TransformerException e) { |
| 99 |
System.out.println("Transformer Exception in graphic formatCallout"); |
| 100 |
} |
| 101 |
} |
| 102 |
} |