From: Keith Fahlgren Date: Sat, 10 Oct 2009 00:40:43 +0000 (+0000) Subject: This resolves bug #2873142, Please add support for multiple embedded fonts X-Git-Tag: release/1.79.1~6^2~953 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=241787ec1e4f76ea87debe02e60e072055166809;p=docbook-dsssl This resolves bug #2873142, Please add support for multiple embedded fonts If you navigate to a checkout of DocBook-XSL and go to: xsl/epub/bin/spec/files You can now run the following command: ../../dbtoepub -f DejaVuSerif.otf -f DejaVuSerif-Italic.otf -c test.css -s test_cust.xsl orm.book.001.xml In dbtoepub, the following option can be used more than once: -f, --font [OTF FILE] Embed OTF FILE in .epub. The underlying stylesheet now accepts a comma-separated list of font file names rather than just one as the RENAMED epub.embedded.fonts ('s' added). The runnable EPUB spec now includes: - should be valid .epub after including more than one embedded font --- diff --git a/xsl/epub/bin/lib/docbook.rb b/xsl/epub/bin/lib/docbook.rb index 2664999bb..2bb90a97b 100755 --- a/xsl/epub/bin/lib/docbook.rb +++ b/xsl/epub/bin/lib/docbook.rb @@ -26,7 +26,6 @@ module DocBook @oebps_dir = File.join(@output_dir, OEBPS_DIR) @css_file = css_file ? File.expand_path(css_file) : css_file @embedded_fonts = embedded_fonts - raise NotImplementedError if @embedded_fonts.length > 1 @to_delete = [] if customization_layer @@ -70,7 +69,8 @@ module DocBook html_stylesheet = "--stringparam html.stylesheet #{File.basename(@css_file)}" if @css_file base = "--stringparam base.dir #{OEBPS_DIR}/" unless @embedded_fonts.empty? - font = "--stringparam epub.embedded.font \"#{File.basename(@embedded_fonts.first)}\"" + embedded_fonts = @embedded_fonts.map {|f| File.basename(f)}.join(',') + font = "--stringparam epub.embedded.fonts \"#{embedded_fonts}\"" end meta = "--stringparam epub.metainf.dir #{META_DIR}/" oebps = "--stringparam epub.oebps.dir #{OEBPS_DIR}/" diff --git a/xsl/epub/bin/spec/epub_spec.rb b/xsl/epub/bin/spec/epub_spec.rb index 6ab69c952..a77494a23 100755 --- a/xsl/epub/bin/spec/epub_spec.rb +++ b/xsl/epub/bin/spec/epub_spec.rb @@ -39,8 +39,11 @@ describe DocBook::Epub do @css_file = File.join(@filedir, @css_file_base) customization_layer = nil @embedded_font_file_base = "DejaVuSerif.otf" - embedded_fonts = [File.join(@filedir, @embedded_font_file_base)] - @css_epub = DocBook::Epub.new(File.join(@testdocsdir, "book.002.xml"), @tmpdir, @css_file, customization_layer, embedded_fonts) + @embedded_font_file2_base = "DejaVuSerif-Italic.otf" + @embedded_fonts = [File.join(@filedir, @embedded_font_file_base), + File.join(@filedir, @embedded_font_file2_base), + ] + @css_epub = DocBook::Epub.new(File.join(@testdocsdir, "book.002.xml"), @tmpdir, @css_file, customization_layer, @embedded_fonts) @css_epubfile = File.join(@tmpdir, "css.epub") @css_epub.render_to_file(@css_epubfile, $DEBUG) @@ -233,8 +236,11 @@ describe DocBook::Epub do success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}") raise "Could not unzip #{@css_epubfile}" unless success opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf")) - opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<(opf:item|item) [^>]*#{@embedded_font_file_base}/} - opf_links.should_not be_empty + + @embedded_fonts.each {|font| + opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<(opf:item|item) [^>]*#{File.basename(font)}/} + opf_links.should_not be_empty + } rescue => e raise e ensure @@ -248,8 +254,10 @@ describe DocBook::Epub do success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}") raise "Could not unzip #{@css_epubfile}" unless success - font_files = Dir.glob(File.join(tmpdir, "**", @embedded_font_file_base)) - font_files.should_not be_empty + @embedded_fonts.each {|font| + font_files = Dir.glob(File.join(tmpdir, "**", File.basename(font))) + font_files.should_not be_empty + } rescue => e raise e ensure @@ -257,6 +265,10 @@ describe DocBook::Epub do end end + it "should be valid .epub after including more than one embedded font" do + @css_epubfile.should be_valid_epub + end + it "should include one and only one

in each HTML file in rendered ePub files for s" do begin tmpdir = File.join(Dir::tmpdir(), "epubtoctest"); Dir.mkdir(tmpdir) rescue Errno::EEXIST diff --git a/xsl/epub/bin/spec/files/DejaVuSerif-Italic.otf b/xsl/epub/bin/spec/files/DejaVuSerif-Italic.otf new file mode 100644 index 000000000..af3359172 Binary files /dev/null and b/xsl/epub/bin/spec/files/DejaVuSerif-Italic.otf differ diff --git a/xsl/epub/bin/spec/files/test.css b/xsl/epub/bin/spec/files/test.css index cd70946dc..195945972 100644 --- a/xsl/epub/bin/spec/files/test.css +++ b/xsl/epub/bin/spec/files/test.css @@ -4,8 +4,17 @@ font-weight: normal; src:url(DejaVuSerif.otf); } +@font-face { + font-family: "DejaVu Serif Italic"; + font-style: italic; + font-weight: normal; + src:url(DejaVuSerif-Italic.otf); +} h2 { font-family: "DejaVu Serif"; text-align: center; color: #dda0dd; } +em { + font-family: "DejaVu Serif Italic"; +} diff --git a/xsl/epub/docbook.xsl b/xsl/epub/docbook.xsl index 1ca985fe6..48c601e95 100644 --- a/xsl/epub/docbook.xsl +++ b/xsl/epub/docbook.xsl @@ -8,11 +8,12 @@ xmlns:ng="http://docbook.org/docbook-ng" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory" + xmlns:str="http://exslt.org/strings" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xtext="xalan://com.nwalsh.xalan.Text" extension-element-prefixes="stext xtext" - exclude-result-prefixes="exsl db dc h ncx ng opf stext xtext" + exclude-result-prefixes="exsl db dc h ncx ng opf stext str xtext" version="1.0"> @@ -48,7 +49,7 @@ htmltoc - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + font/opentype + + + + WARNING: OpenType fonts should be supplied! ( + + ) + + + + +