From 55e77678e6295bbaaca5106e8fd9222f960e3cc4 Mon Sep 17 00:00:00 2001 From: Mauritz Jeanson Date: Wed, 11 Jul 2007 07:09:12 +0000 Subject: [PATCH] Added code for generating id attributes on callouts in HTML and FO output. These patches enable cross-references to callouts placed by area coordinates. It works for graphic, unicode and text callouts. Part of fix for bug #1675513 (xref to area broken). --- .../src/com/nwalsh/saxon/FormatCallout.java | 49 +++++++++++++++++-- .../nwalsh/saxon/FormatGraphicCallout.java | 6 ++- .../nwalsh/saxon/FormatUnicodeCallout.java | 8 ++- .../src/com/nwalsh/xalan/FormatCallout.java | 44 +++++++++++++++-- .../nwalsh/xalan/FormatDingbatCallout.java | 2 +- .../nwalsh/xalan/FormatGraphicCallout.java | 5 +- .../nwalsh/xalan/FormatUnicodeCallout.java | 5 +- 7 files changed, 103 insertions(+), 16 deletions(-) diff --git a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatCallout.java b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatCallout.java index 256a3b513..2ffa507fb 100644 --- a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatCallout.java +++ b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatCallout.java @@ -62,21 +62,45 @@ public abstract class FormatCallout { return label; } - public void startSpan(Emitter rtf) + // Get ID (used for xrefs) + public String areaID(Element area) { + String id = null; + + if (area.hasAttribute("id")) { + id = area.getAttribute("id"); + } + + else { + if (area.hasAttribute("xml:id")) { + id = area.getAttribute("xml:id"); + } + + else { + id = ""; + } + } + //System.out.println(id); + return id; + } + + + public void startSpan(Emitter rtf, String id) throws TransformerException { - // no point in doing this for FO, right? + if (!foStylesheet && namePool != null) { int spanName = namePool.allocate("", "", "span"); AttributeCollection spanAttr = new AttributeCollection(namePool); int namespaces[] = new int[1]; spanAttr.addAttribute("", "", "class", "CDATA", "co"); + spanAttr.addAttribute("", "", "id", "CDATA", id); rtf.startElement(spanName, spanAttr, namespaces, 0); } + } public void endSpan(Emitter rtf) throws TransformerException { - // no point in doing this for FO, right? + if (!foStylesheet && namePool != null) { int spanName = namePool.allocate("", "", "span"); rtf.endElement(spanName); @@ -88,6 +112,7 @@ public abstract class FormatCallout { Element area = callout.getArea(); int num = callout.getCallout(); String userLabel = areaLabel(area); + String id = areaID(area); String label = "(" + num + ")"; if (userLabel != null) { @@ -97,14 +122,28 @@ public abstract class FormatCallout { char chars[] = label.toCharArray(); try { - startSpan(rtfEmitter); + startSpan(rtfEmitter, id); + + if (foStylesheet) { + int inlineName = namePool.allocate("fo", foURI, "inline"); + AttributeCollection inlineAttr = new AttributeCollection(namePool); + int namespaces[] = new int[1]; + inlineAttr.addAttribute("", "", "id", "CDATA", id); + rtfEmitter.startElement(inlineName, inlineAttr, namespaces, 0); + } rtfEmitter.characters(chars, 0, label.length()); endSpan(rtfEmitter); + + if (foStylesheet) { + int inlineName = namePool.allocate("fo", foURI, "inline"); + rtfEmitter.endElement(inlineName); + } + } catch (TransformerException e) { System.out.println("Transformer Exception in formatTextCallout"); } } - + public abstract void formatCallout(Emitter rtfEmitter, Callout callout); } diff --git a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatGraphicCallout.java b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatGraphicCallout.java index c2f16d95a..c72b9bf53 100644 --- a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatGraphicCallout.java +++ b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatGraphicCallout.java @@ -50,6 +50,7 @@ public class FormatGraphicCallout extends FormatCallout { int num = callout.getCallout(); String userLabel = areaLabel(area); String label = "(" + num + ")"; + String id = areaID(area); if (userLabel != null) { label = userLabel; @@ -66,16 +67,19 @@ public class FormatGraphicCallout extends FormatCallout { imgAttr = new AttributeCollection(namePool); imgAttr.addAttribute("", "", "src", "CDATA", "url(" + graphicsPath + num + graphicsExt + ")"); + imgAttr.addAttribute("", "", "id", "CDATA", id); + // HTML } else { imgName = namePool.allocate("", "", "img"); imgAttr = new AttributeCollection(namePool); imgAttr.addAttribute("", "", "src", "CDATA", graphicsPath + num + graphicsExt); imgAttr.addAttribute("", "", "alt", "CDATA", label); + } - startSpan(rtfEmitter); + startSpan(rtfEmitter, id); rtfEmitter.startElement(imgName, imgAttr, namespaces, 0); rtfEmitter.endElement(imgName); endSpan(rtfEmitter); diff --git a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatUnicodeCallout.java b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatUnicodeCallout.java index e51e1c074..426d618ba 100644 --- a/xsl-java/saxon65/src/com/nwalsh/saxon/FormatUnicodeCallout.java +++ b/xsl-java/saxon65/src/com/nwalsh/saxon/FormatUnicodeCallout.java @@ -54,7 +54,8 @@ public class FormatUnicodeCallout extends FormatCallout { int num = callout.getCallout(); String userLabel = areaLabel(area); String label = ""; - + String id = areaID(area); + if (userLabel != null) { label = userLabel; } @@ -70,13 +71,16 @@ public class FormatUnicodeCallout extends FormatCallout { inName = namePool.allocate("fo", foURI, "inline"); inAttr = new AttributeCollection(namePool); inAttr.addAttribute("", "", "font-family", "CDATA", unicodeFont); + inAttr.addAttribute("", "", "id", "ID", id); + } else { inName = namePool.allocate("", "", "font"); inAttr = new AttributeCollection(namePool); inAttr.addAttribute("", "", "face", "CDATA", unicodeFont); + inAttr.addAttribute("", "", "id", "ID", id); } - startSpan(rtfEmitter); + startSpan(rtfEmitter, id); rtfEmitter.startElement(inName, inAttr, namespaces, 0); } diff --git a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatCallout.java b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatCallout.java index ff3018b95..8ce78ec1e 100644 --- a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatCallout.java +++ b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatCallout.java @@ -55,19 +55,43 @@ public abstract class FormatCallout { return label; } - public void startSpan(DOMBuilder rtf) + +// Get area ID (used for xrefs to callouts) + public String areaID(Element area) { + String id = null; + + if (area.hasAttribute("id")) { + id = area.getAttribute("id"); + } + + else { + if (area.hasAttribute("xml:id")) { + id = area.getAttribute("xml:id"); + } + + else { + id = ""; + } + } + //System.out.println(id); + return id; + } + + + public void startSpan(DOMBuilder rtf, String id) throws SAXException { - // no point in doing this for FO, right? + if (!stylesheetFO) { AttributesImpl spanAttr = new AttributesImpl(); spanAttr.addAttribute("", "class", "class", "CDATA", "co"); + spanAttr.addAttribute("", "id", "id", "ID", id); rtf.startElement("", "span", "span", spanAttr); } } - + public void endSpan(DOMBuilder rtf) throws SAXException { - // no point in doing this for FO, right? + if (!stylesheetFO) { rtf.endElement("", "span", "span"); } @@ -84,11 +108,21 @@ public abstract class FormatCallout { label = userLabel; } + String id = areaID(area); char chars[] = label.toCharArray(); try { - startSpan(rtf); + startSpan(rtf, id); + if (stylesheetFO) { + AttributesImpl spanAttr = new AttributesImpl(); + spanAttr.addAttribute("", "id", "id", "ID", id); + rtf.startElement(foURI, "inline", "fo:inline", spanAttr); + } + rtf.characters(chars, 0, label.length()); + if (stylesheetFO) { + rtf.endElement(foURI, "inline", "fo:inline"); + } endSpan(rtf); } catch (SAXException e) { System.out.println("SAX Exception in text formatCallout"); diff --git a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatDingbatCallout.java b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatDingbatCallout.java index e78d3cc1d..f727d4b94 100644 --- a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatDingbatCallout.java +++ b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatDingbatCallout.java @@ -63,7 +63,7 @@ public class FormatDingbatCallout extends FormatCallout { "ZapfDingbats"); } - startSpan(rtf); + startSpan(rtf, ""); // empty dummy id rtf.startElement(ns, imgName, prefix+imgName, imgAttr); char chars[] = new char[1]; diff --git a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatGraphicCallout.java b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatGraphicCallout.java index 6686b36b9..bdbf35b01 100644 --- a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatGraphicCallout.java +++ b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatGraphicCallout.java @@ -45,6 +45,7 @@ public class FormatGraphicCallout extends FormatCallout { Element area = callout.getArea(); int num = callout.getCallout(); String label = areaLabel(area); + String id = areaID(area); try { if (label == null && num <= graphicsMax) { @@ -59,6 +60,7 @@ public class FormatGraphicCallout extends FormatCallout { imgName = "external-graphic"; imgAttr.addAttribute("", "src", "src", "CDATA", "url(" + graphicsPath + num + graphicsExt + ")"); + imgAttr.addAttribute("", "id", "id", "ID", id); } else { ns = ""; @@ -67,9 +69,10 @@ public class FormatGraphicCallout extends FormatCallout { imgAttr.addAttribute("", "src", "src", "CDATA", graphicsPath + num + graphicsExt); imgAttr.addAttribute("", "alt", "alt", "CDATA", label); + imgAttr.addAttribute("", "id", "id", "ID", id); } - startSpan(rtf); + startSpan(rtf, id); rtf.startElement(ns, imgName, prefix+imgName, imgAttr); rtf.endElement(ns, imgName, prefix+imgName); endSpan(rtf); diff --git a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatUnicodeCallout.java b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatUnicodeCallout.java index 2fdaf54ce..83529b7c9 100644 --- a/xsl-java/xalan27/src/com/nwalsh/xalan/FormatUnicodeCallout.java +++ b/xsl-java/xalan27/src/com/nwalsh/xalan/FormatUnicodeCallout.java @@ -45,6 +45,7 @@ public class FormatUnicodeCallout extends FormatCallout { Element area = callout.getArea(); int num = callout.getCallout(); String label = areaLabel(area); + String id = areaID(area); try { if (label == null && num <= unicodeMax) { @@ -59,16 +60,18 @@ public class FormatUnicodeCallout extends FormatCallout { prefix = "fo:"; inName = "inline"; inAttr.addAttribute("", "", "font-family", "CDATA", unicodeFont); + inAttr.addAttribute("", "", "id", "ID", id); } else { inName = "font"; inAttr.addAttribute("", "", "face", "CDATA", unicodeFont); + inAttr.addAttribute("", "", "id", "ID", id); } } char chars[] = new char[1]; chars[0] = (char) (unicodeStart + num - 1); - startSpan(rtf); + startSpan(rtf, id); if (!unicodeFont.equals("")) { rtf.startElement(ns, inName, prefix+inName, inAttr); } -- 2.40.0