]> granicus.if.org Git - docbook-dsssl/commitdiff
Added code for generating id attributes on callouts in HTML and FO output.
authorMauritz Jeanson <mj@johanneberg.com>
Wed, 11 Jul 2007 07:09:12 +0000 (07:09 +0000)
committerMauritz Jeanson <mj@johanneberg.com>
Wed, 11 Jul 2007 07:09:12 +0000 (07:09 +0000)
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).

xsl-java/saxon65/src/com/nwalsh/saxon/FormatCallout.java
xsl-java/saxon65/src/com/nwalsh/saxon/FormatGraphicCallout.java
xsl-java/saxon65/src/com/nwalsh/saxon/FormatUnicodeCallout.java
xsl-java/xalan27/src/com/nwalsh/xalan/FormatCallout.java
xsl-java/xalan27/src/com/nwalsh/xalan/FormatDingbatCallout.java
xsl-java/xalan27/src/com/nwalsh/xalan/FormatGraphicCallout.java
xsl-java/xalan27/src/com/nwalsh/xalan/FormatUnicodeCallout.java

index 256a3b513aeffa798c6a876982356afa7f2b2070..2ffa507fb51b7060e6a3af6c9b1a353fdfee05c0 100644 (file)
@@ -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);
 }
index c2f16d95a68a076cbb544ed411ef1d36c28f5bf5..c72b9bf53b377d502cded164bc13fd8d91b68352 100644 (file)
@@ -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);
index e51e1c074c7f139640748ec42490dd25ae667803..426d618baa6151197f993a7383d00781eb0dbcca 100644 (file)
@@ -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);
        }
 
index ff3018b95287c7e7168969f68e7cf4159ce7f6ac..8ce78ec1ec6a9e56be1adeb95ee5765c903602e2 100644 (file)
@@ -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");
index e78d3cc1da9e290f513d399b1b41fad179790e11..f727d4b94cc42232cfe9f3b387b3614050a087b8 100644 (file)
@@ -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];
index 6686b36b9018fcf93cb2a12bfbd0c9cc007550da..bdbf35b01f0a4676eacc75f15bd36fe681ad0aaa 100644 (file)
@@ -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);
index 2fdaf54ce8a01870910b272df48772d630193399..83529b7c9868161cf4d766f741f984f9b3e699e0 100644 (file)
@@ -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);
        }