lib/asciidoctor-epub3/packager.rb in asciidoctor-epub3-1.5.0.alpha.5 vs lib/asciidoctor-epub3/packager.rb in asciidoctor-epub3-1.5.0.alpha.6

- old
+ new

@@ -47,22 +47,39 @@ ::File.join DATA_DIR, 'styles' end # TODO improve design/UX of custom theme functionality, including custom fonts resources do - file 'styles/epub3.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3.css'), format) - file 'styles/epub3-css3-only.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3-css3-only.css'), format) + if format == :kf8 + # NOTE add layer of indirection so Kindle Direct Publishing (KDP) doesn't strip font-related CSS rules + file 'styles/epub3.css' => '@import url("epub3-proxied.css");'.to_ios + file 'styles/epub3-css3-only.css' => '@import url("epub3-css3-only-proxied.css");'.to_ios + file 'styles/epub3-proxied.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3.css'), format) + file 'styles/epub3-css3-only-proxied.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3-css3-only.css'), format) + else + file 'styles/epub3.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3.css'), format) + file 'styles/epub3-css3-only.css' => (builder.postprocess_css_file ::File.join(workdir, 'epub3-css3-only.css'), format) + end end resources do - #file 'styles/epub3.css' => (builder.postprocess_css_file 'styles/epub3.css', format) - #file 'styles/epub3-css3-only.css' => (builder.postprocess_css_file 'styles/epub3-css3-only.css', format) font_files, font_css = builder.select_fonts ::File.join(DATA_DIR, 'styles/epub3-fonts.css'), (doc.attr 'scripts', 'latin') file 'styles/epub3-fonts.css' => font_css - with_media_type 'application/x-font-ttf' do - font_files.each do |font_file| - file font_file => ::File.join(DATA_DIR, font_file) + unless font_files.empty? + # NOTE metadata property in oepbs package manifest doesn't work; must use proprietary iBooks file instead + #(@book.metadata.add_metadata 'meta', 'true')['property'] = 'ibooks:specified-fonts' unless format == :kf8 + builder.optional_file 'META-INF/com.apple.ibooks.display-options.xml' => '<?xml version="1.0" encoding="UTF-8"?> +<display_options> +<platform name="*"> +<option name="specified-fonts">true</option> +</platform> +</display_options>'.to_ios unless format == :kf8 + + with_media_type 'application/x-font-ttf' do + font_files.each do |font_file| + file font_file => ::File.join(DATA_DIR, font_file) + end end end end end @@ -444,10 +461,11 @@ end puts %(Extracted #{fmt.upcase} to #{extract_dir}) if $VERBOSE end if fmt == :kf8 + # QUESTION shouldn't we validate this epub file too? distill_epub_to_mobi epub_file, target elsif options[:validate] validate_epub epub_file end end @@ -458,10 +476,10 @@ unless ::File.executable? kindlegen_cmd require 'kindlegen' unless defined? ::Kindlegen kindlegen_cmd = ::Kindlegen.command end mobi_file = ::File.basename(target.sub EpubExtensionRx, '.mobi') - ::Open3.popen2e(::Shellwords.join [kindlegen_cmd, '-o', mobi_file, epub_file]) {|input, output, wait_thr| + ::Open3.popen2e(::Shellwords.join [kindlegen_cmd, '-dont_append_source', '-o', mobi_file, epub_file]) {|input, output, wait_thr| output.each {|line| puts line } unless $VERBOSE.nil? } puts %(Wrote MOBI to #{::File.join ::File.dirname(epub_file), mobi_file}) if $VERBOSE end