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}"
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,
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
end
def bundle_epub(output_file, verbose)
+
quiet = verbose ? "" : "-q"
mimetype_filename = write_mimetype()
meta = File.basename(@meta_dir)
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?
# 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
# 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")
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)
--- /dev/null
+<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>
+
--- /dev/null
+<?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>
+
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>
<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>
--- /dev/null
+<!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>
<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>