From: <abd...@us...> - 2009-05-07 01:03:19
|
Revision: 8424 http://docbook.svn.sourceforge.net/docbook/?rev=8424&view=rev Author: abdelazer Date: 2009-05-07 01:03:07 +0000 (Thu, 07 May 2009) Log Message: ----------- Slightly more nuanced handling of imageobject alternatives and better support in dbtoepub for XIncludes and ENTITYs to resolve Issue #2750442 Modified Paths: -------------- trunk/xsl/epub/bin/lib/docbook.rb trunk/xsl/epub/bin/spec/epub_regressions_spec.rb trunk/xsl/epub/bin/spec/files/orm.book.001.xml trunk/xsl/epub/docbook.xsl Added Paths: ----------- trunk/xsl/epub/bin/spec/files/onegraphic.entity.xml trunk/xsl/epub/bin/spec/files/onegraphic.xinclude.xml trunk/xsl/epub/bin/spec/files/xincludeents.xml Modified: trunk/xsl/epub/bin/lib/docbook.rb =================================================================== --- trunk/xsl/epub/bin/lib/docbook.rb 2009-05-05 21:17:59 UTC (rev 8423) +++ trunk/xsl/epub/bin/lib/docbook.rb 2009-05-07 01:03:07 UTC (rev 8424) @@ -61,6 +61,8 @@ 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 @@ 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 @@ 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 @@ end def bundle_epub(output_file, verbose) + quiet = verbose ? "" : "-q" mimetype_filename = write_mimetype() meta = File.basename(@meta_dir) @@ -109,6 +111,19 @@ 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 @@ # 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 @@ # 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") Modified: trunk/xsl/epub/bin/spec/epub_regressions_spec.rb =================================================================== --- trunk/xsl/epub/bin/spec/epub_regressions_spec.rb 2009-05-05 21:17:59 UTC (rev 8423) +++ trunk/xsl/epub/bin/spec/epub_regressions_spec.rb 2009-05-07 01:03:07 UTC (rev 8424) @@ -133,7 +133,18 @@ 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) end Added: trunk/xsl/epub/bin/spec/files/onegraphic.entity.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/onegraphic.entity.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/onegraphic.entity.xml 2009-05-07 01:03:07 UTC (rev 8424) @@ -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>nd...@nw...</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> + Property changes on: trunk/xsl/epub/bin/spec/files/onegraphic.entity.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: trunk/xsl/epub/bin/spec/files/onegraphic.xinclude.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/onegraphic.xinclude.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/onegraphic.xinclude.xml 2009-05-07 01:03:07 UTC (rev 8424) @@ -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> + Property changes on: trunk/xsl/epub/bin/spec/files/onegraphic.xinclude.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Modified: trunk/xsl/epub/bin/spec/files/orm.book.001.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/orm.book.001.xml 2009-05-05 21:17:59 UTC (rev 8423) +++ trunk/xsl/epub/bin/spec/files/orm.book.001.xml 2009-05-07 01:03:07 UTC (rev 8424) @@ -101,6 +101,9 @@ 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 @@ <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> Added: trunk/xsl/epub/bin/spec/files/xincludeents.xml =================================================================== --- trunk/xsl/epub/bin/spec/files/xincludeents.xml (rev 0) +++ trunk/xsl/epub/bin/spec/files/xincludeents.xml 2009-05-07 01:03:07 UTC (rev 8424) @@ -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 & Figures</title> + +&onegraphic; +<xi:include href="onegraphic.xinclude.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> + +</set> Property changes on: trunk/xsl/epub/bin/spec/files/xincludeents.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Modified: trunk/xsl/epub/docbook.xsl =================================================================== --- trunk/xsl/epub/docbook.xsl 2009-05-05 21:17:59 UTC (rev 8423) +++ trunk/xsl/epub/docbook.xsl 2009-05-07 01:03:07 UTC (rev 8424) @@ -843,8 +843,8 @@ <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> @@ -966,13 +966,33 @@ 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> @@ -1036,9 +1056,10 @@ </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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |