]> granicus.if.org Git - docbook-dsssl/commitdiff
Slightly more nuanced handling of imageobject alternatives and better support in...
authorKeith Fahlgren <abdelazer@users.sourceforge.net>
Thu, 7 May 2009 01:03:07 +0000 (01:03 +0000)
committerKeith Fahlgren <abdelazer@users.sourceforge.net>
Thu, 7 May 2009 01:03:07 +0000 (01:03 +0000)
xsl/epub/bin/lib/docbook.rb
xsl/epub/bin/spec/epub_regressions_spec.rb
xsl/epub/bin/spec/files/onegraphic.entity.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/onegraphic.xinclude.xml [new file with mode: 0644]
xsl/epub/bin/spec/files/orm.book.001.xml
xsl/epub/bin/spec/files/xincludeents.xml [new file with mode: 0644]
xsl/epub/docbook.xsl

index d4d06aca6ca40665869be89ff1eae59959d5e40d..a5006f6db2091d2fc374a71c0ccda8640f8aaad1 100755 (executable)
@@ -61,6 +61,8 @@ module DocBook
 
     private
     def render_to_epub(output_file, verbose)  
+      @collapsed_docbook_file = collapse_docbook()
+
       chunk_quietly =   "--stringparam chunk.quietly " + (verbose ? '0' : '1')
       callout_path =    "--stringparam callout.graphics.path #{CALLOUT_PATH}/"
       callout_limit =   "--stringparam callout.graphics.number.limit #{CALLOUT_LIMIT}"
@@ -72,8 +74,7 @@ module DocBook
       end  
       meta =            "--stringparam epub.metainf.dir #{@meta_dir}/" 
       oebps =           "--stringparam epub.oebps.dir #{@oebps_dir}/" 
-      options = ["--xinclude", 
-                 chunk_quietly, 
+      options = [chunk_quietly, 
                  callout_path, 
                  callout_limit, 
                  callout_ext, 
@@ -84,7 +85,7 @@ module DocBook
                  html_stylesheet,
                 ].join(" ")
       # Double-quote stylesheet & file to help Windows cmd.exe
-      db2epub_cmd = "#{XSLT_PROCESSOR} #{options} \"#{@stylesheet}\" \"#{@docbook_file}\""
+      db2epub_cmd = "#{XSLT_PROCESSOR} #{options} \"#{@stylesheet}\" \"#{@collapsed_docbook_file}\""
       STDERR.puts db2epub_cmd if $DEBUG
       success = system(db2epub_cmd)
       raise "Could not render as .epub to #{output_file} (#{db2epub_cmd})" unless success
@@ -93,6 +94,7 @@ module DocBook
     end  
 
     def bundle_epub(output_file, verbose)  
+
       quiet = verbose ? "" : "-q"
       mimetype_filename = write_mimetype()
       meta   = File.basename(@meta_dir)
@@ -109,6 +111,19 @@ module DocBook
       raise "Could not bundle into .epub file to #{output_file}" unless success
     end
 
+    # Input must be collapsed because REXML couldn't find figures in files that
+    # were XIncluded or added by ENTITY
+    #   http://sourceforge.net/tracker/?func=detail&aid=2750442&group_id=21935&atid=373747
+    def collapse_docbook
+      collapsed_file = File.join(File.dirname(@docbook_file),
+                                              '.collapsed.' + File.basename(@docbook_file))
+      collapse_command = "xmllint --noent --xinclude -o '#{collapsed_file}' '#{@docbook_file}'"
+      success = system(collapse_command)
+      raise "Could not collapse XIncludes and/or entites in #{@docbook_file}" unless success
+      @to_delete << collapsed_file
+      return collapsed_file
+    end  
+
     def copy_callouts
       new_callout_images = []
       if has_callouts?
@@ -180,7 +195,7 @@ module DocBook
 
     # Returns an Array of all of the (image) @filerefs in a document
     def get_image_refs
-      parser = REXML::Parsers::PullParser.new(File.new(@docbook_file))
+      parser = REXML::Parsers::PullParser.new(File.new(@collapsed_docbook_file))
       image_refs = []
       while parser.has_next?
         el = parser.pull
@@ -193,7 +208,7 @@ module DocBook
 
     # Returns true if the document has code callouts
     def has_callouts?
-      parser = REXML::Parsers::PullParser.new(File.new(@docbook_file))
+      parser = REXML::Parsers::PullParser.new(File.new(@collapsed_docbook_file))
       while parser.has_next?
         el = parser.pull
         if el.start_element? and (el[0] == "calloutlist" or el[0] == "co")
index aa98497c3c5fbc2b21301b298745fd190ad13135..113650e5edc5f68bec9609fd8ea53071825ff961 100755 (executable)
@@ -133,6 +133,17 @@ describe DocBook::Epub do
     opf_lns.to_s.should =~ /language[^>]*>de</
   end
 
+  it "should include images from &entity; and XInclude'd documents" do
+    opf_lns = opf_lines('xincludeents.xml', @filedir)
+    opf_lns.to_s.should =~ /stamp.png/
+    opf_lns.to_s.should =~ /duck-small.png/
+    opf_lns.to_s.should_not =~ /duck-small.gif/ # Choose one, not both
+    xincludeents_epub = DocBook::Epub.new(File.join(@filedir, "xincludeents.xml"), @tmpdir)
+    xincludeents_epubfile  = File.join(@tmpdir, "xincludeentsepub.epub")
+    xincludeents_epub.render_to_file(xincludeents_epubfile, $DEBUG)
+    xincludeents_epubfile.should be_valid_epub  
+  end
+
 
   after(:all) do
     FileUtils.rm_r(@tmpdir, :force => true)
diff --git a/xsl/epub/bin/spec/files/onegraphic.entity.xml b/xsl/epub/bin/spec/files/onegraphic.entity.xml
new file mode 100644 (file)
index 0000000..8b83101
--- /dev/null
@@ -0,0 +1,30 @@
+<book>
+<bookinfo>
+<title>Unit Test: stamp.001</title>
+<releaseinfo role="CVS">$Id: stamp.001.xml 4056 2004-11-23 13:28:50Z nwalsh $</releaseinfo>
+<author><firstname>Norman</firstname><surname>Walsh</surname>
+        <affiliation><address><email>ndw@nwalsh.com</email></address></affiliation>
+</author>
+</bookinfo>
+<chapter>
+  <title>Chapter One</title>
+<sect1>
+  <title>The stamp image</title>
+
+<para>The stamp image has a natural size of 200x128 pixels.</para>
+
+<para>The stamp image.</para>
+
+<mediaobject>
+  <imageobject>
+    <?dbhtml background-color="blue"?>
+    <imagedata
+      fileref="graphics/stamp.png"/>
+  </imageobject>
+  <textobject><phrase>The DocBook Stamp</phrase></textobject>
+</mediaobject>
+</sect1>
+
+</chapter>
+</book>
+
diff --git a/xsl/epub/bin/spec/files/onegraphic.xinclude.xml b/xsl/epub/bin/spec/files/onegraphic.xinclude.xml
new file mode 100644 (file)
index 0000000..72d712c
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+          "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book>
+<title>Small Duck</title>
+<chapter>
+  <title>Chapter One</title>
+<sect1>
+<title>Fowl</title>
+
+<para>The small duck.</para>
+
+<mediaobject>
+  <imageobject role="webhires">
+    <imagedata format="PNG" fileref="graphics/duck-small.png"/>
+  </imageobject>
+  <imageobject role="weblowres">
+    <imagedata format="GIF" fileref="graphics/duck-small.gif"/>
+  </imageobject>
+  <imageobject role="print">
+    <imagedata format="PDF" fileref="graphics/duck-small.pdf"/>
+  </imageobject>
+</mediaobject>
+
+</sect1>
+
+</chapter>
+</book>
+
index 484051b5ac75f8be02e8f2d826c67d5e6eba70ec..75e9f230e90d83ac3c560f6bd3f36dee8bbd7011 100644 (file)
@@ -101,6 +101,9 @@ Mxxx xx xxx xxxxxxxxxxxx xxxx xx xxxxxxxxxxxxx xxx xxxxxxx xx xxxxxxxxxxx
         xx xxx xxxxxxx xxxxxxxxx xxxx xxx xxx xx xxx xxxxxxxxxxx xxxxxxxxx xxxxxx.</para>
     </legalnotice>
     <mediaobject role="cover" id="coverd1e4">
+      <imageobject role="front-large" remap="lrg">
+        <imagedata width="600px" format="JPG" fileref="covers/cvr_lrg.jpg"/>
+      </imageobject>
       <imageobject role="front" remap="s">
         <imagedata format="GIF" fileref="covers/cvr_s.gif"/>
       </imageobject>
@@ -110,9 +113,6 @@ Mxxx xx xxx xxxxxxxxxxxx xxxx xx xxxxxxxxxxxxx xxx xxxxxxx xx xxxxxxxxxxx
       <imageobject role="thumbnail" remap="cs">
         <imagedata format="GIF" fileref="covers/cvr_cs.gif"/>
       </imageobject>
-      <imageobject role="front-large" remap="lrg">
-        <imagedata width="600px" format="JPG" fileref="covers/cvr_lrg.jpg"/>
-      </imageobject>
     </mediaobject>
     <date>2008-04-15</date>
   </bookinfo>
diff --git a/xsl/epub/bin/spec/files/xincludeents.xml b/xsl/epub/bin/spec/files/xincludeents.xml
new file mode 100644 (file)
index 0000000..188bc07
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+  <!ENTITY onegraphic SYSTEM "onegraphic.entity.xml">
+]>
+<set>
+ <title>XIncludes and Entities &amp; Figures</title>
+
+&onegraphic;
+<xi:include href="onegraphic.xinclude.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
+</set>
index 98e262cdbd9aeaadcfee2fff05ba86bea439f8f8..a2076cf7d69fc413b0d8f0d17f7c595a479acee9 100644 (file)
               <xsl:attribute name="media-type">font/opentype</xsl:attribute>
             </xsl:when>
             <xsl:otherwise>
-              <xsl:message terminate="yes">
-                <xsl:text>ERROR: Only OpenType fonts are supported in .epub! (</xsl:text>
+              <xsl:message>
+                <xsl:text>WARNING: OpenType fonts should be supplied! (</xsl:text>
                 <xsl:value-of select="$epub.embedded.font"/>
                 <xsl:text>)</xsl:text>
               </xsl:message>
                        mediaobjectco|
                        inlinemediaobject" 
                 mode="opf.manifest">
-    <xsl:apply-templates select="imageobject/imagedata"
-                         mode="opf.manifest"/>              
+    <xsl:choose>
+      <xsl:when test="imageobject/imagedata[@format = 'GIF' or 
+                                            @format = 'GIF87a' or 
+                                            @format = 'GIF89a' or 
+                                            @format = 'JPEG' or 
+                                            @format = 'JPG' or 
+                                            @format = 'PNG' or 
+                                            @format = 'SVG']">
+        <xsl:apply-templates select="imageobject[imagedata[@format = 'GIF' or 
+                                                           @format = 'GIF87a' or 
+                                                           @format = 'GIF89a' or 
+                                                           @format = 'JPEG' or 
+                                                           @format = 'JPG' or 
+                                                           @format = 'PNG' or 
+                                                           @format = 'SVG']][1]/imagedata"
+                             mode="opf.manifest"/>              
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:apply-templates select="imageobject/imagedata[1]"
+                             mode="opf.manifest"/>              
+      </xsl:otherwise>
+    </xsl:choose>  
   </xsl:template>
 
   <xsl:template match="mediaobjectco"
                 mode="opf.manifest">
-    <xsl:message>Warning: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
+    <xsl:message>WARNING: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
     <xsl:apply-templates select="imageobjectco/imageobject/imagedata" 
                          mode="opf.manifest"/>              
   </xsl:template>
   </xsl:template>
 
   <!-- TODO: Remove hardcoding -->
-  <xsl:template match="graphic[@format][@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
-                       inlinegraphic[@format][@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
-                       imagedata[@format][@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']"
+  <!-- Note: Selection of the first interesting imagedata is done in the select -->
+  <xsl:template match="graphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
+                       inlinegraphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
+                       imagedata[@format]"
                 mode="opf.manifest">
     <xsl:variable name="filename">
       <xsl:choose>