From: Robert BÅ‚aut Date: Sun, 19 Jan 2014 11:41:00 +0000 (+0100) Subject: [Mobi] Mobi output improvements X-Git-Tag: 1.7~104^2~21 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/f2d38866c775f83eb7d941345a1f4ac8a9133290?ds=sidebyside [Mobi] Mobi output improvements 1. Produce dual Mobi file by default (Mobi7 + KF8). Much nicer and richer experience on Kindle devices. 2. Embed fonts in Mobi. 3. Remove obsolete Mobi stylesheet (mobi.py uses epub css by default) 4. Add flag with-full-fonts to epub.py as it is required for mobi.py to produce working subset of fonts by calibre. 5. Ignore margins option by default to ensure that result mobi file will use Kindle devices own margins. --- diff --git a/librarian/epub.py b/librarian/epub.py index c92de3c..9e30134 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -336,7 +336,7 @@ def transform(wldoc, verbose=False, sample=n: generate sample e-book (with at least n paragraphs) cover: a cover.Cover factory or True for default - flags: less-advertising, without-fonts, working-copy + flags: less-advertising, without-fonts, working-copy, with-full-fonts """ def transform_file(wldoc, chunk_counter=1, first=True, sample=None): @@ -540,14 +540,17 @@ def transform(wldoc, verbose=False, os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'font-optimizer')) for fname in 'DejaVuSerif.ttf', 'DejaVuSerif-Bold.ttf', 'DejaVuSerif-Italic.ttf', 'DejaVuSerif-BoldItalic.ttf': - optimizer_call = ['perl', 'subset.pl', '--chars', ''.join(chars).encode('utf-8'), - get_resource('fonts/' + fname), os.path.join(tmpdir, fname)] - if verbose: - print "Running font-optimizer" - subprocess.check_call(optimizer_call) + if not flags or not 'with-full-fonts' in flags: + optimizer_call = ['perl', 'subset.pl', '--chars', ''.join(chars).encode('utf-8'), + get_resource('fonts/' + fname), os.path.join(tmpdir, fname)] + if verbose: + print "Running font-optimizer" + subprocess.check_call(optimizer_call) + else: + subprocess.check_call(optimizer_call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + zip.write(os.path.join(tmpdir, fname), os.path.join('OPS', fname)) else: - subprocess.check_call(optimizer_call, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - zip.write(os.path.join(tmpdir, fname), os.path.join('OPS', fname)) + zip.write(get_resource('fonts/' + fname), os.path.join('OPS', fname)) manifest.append(etree.fromstring( '' % (fname, fname))) rmtree(tmpdir) diff --git a/librarian/mobi.py b/librarian/mobi.py index 74018b3..3c4c949 100644 --- a/librarian/mobi.py +++ b/librarian/mobi.py @@ -42,9 +42,9 @@ def transform(wldoc, verbose=False, if not flags: flags = [] - flags = list(flags) + ['without-fonts'] + flags = list(flags) + ['with-full-fonts'] epub = document.as_epub(verbose=verbose, sample=sample, html_toc=True, - flags=flags, style=get_resource('mobi/style.css')) + flags=flags, style=get_resource('epub/style.css')) if verbose: kwargs = {} @@ -55,6 +55,6 @@ def transform(wldoc, verbose=False, output_file = NamedTemporaryFile(prefix='librarian', suffix='.mobi', delete=False) output_file.close() subprocess.check_call(['ebook-convert', epub.get_filename(), output_file.name, - '--no-inline-toc', '--cover=%s' % cover_file.name], **kwargs) + '--no-inline-toc', '--mobi-file-type=both', '--subset-embedded-fonts', '--mobi-ignore-margins', '--cover=%s' % cover_file.name], **kwargs) os.unlink(cover_file.name) return OutputFile.from_filename(output_file.name) diff --git a/librarian/mobi/style.css b/librarian/mobi/style.css deleted file mode 100644 index 55af220..0000000 --- a/librarian/mobi/style.css +++ /dev/null @@ -1,280 +0,0 @@ -/* =================================================== */ -/* = Common elements: headings, paragraphs and lines = */ -/* =================================================== */ - -.h2 -{ - font-size: 2em; - margin: 0; - margin-top: 1.5em; - font-weight: bold; - line-height: 1.5em; -} - -.h3 -{ - text-align:left; - font-size: 1.5em; - margin-top: 1.5em; - font-weight: normal; - line-height: 1.5em; -} - -.h4 -{ - font-size: 1em; - margin: 0; - margin-top: 1em; - line-height: 1.5em; -} - -.paragraph -{ - margin: 0; -} - -.paragraph + .paragraph -{ - text-indent: 1.2em; -} - - -/* ======================== */ -/* = Footnotes and themes = */ -/* ======================== */ - -.annotation -{ - margin-bottom: 0.3em; - text-align: left; -} - -.block -{ - font-size: 0.875em; - padding: 1em; -} - - -/* ============= */ -/* = Numbering = */ -/* ============= */ - -.anchor sup -{ - vertical-align: text-top; - font-size: 0.7em; -} - -/* =================== */ -/* = Custom elements = */ -/* =================== */ - -.title-page -{ - margin-top: 1.5em; -} - -.title -{ - font-size: 3em; - text-align: center; - line-height: 1.5em; - font-weight: bold; -} - -.author -{ - margin: 0; - text-align: center; - font-weight: bold; - - font-size: 1.5em; - line-height: 1.5em; - margin-bottom: 0.25em; -} - -.intitle -{ - margin: 0; - text-align: center; - font-weight: bold; - - font-size: 1.5em; - line-height: 1.5em; - margin-bottom: 0.25em; -} - -.insubtitle -{ - margin: 0; - text-align: center; - font-weight: bold; - - font-size: 1em; - line-height: 1.5em; - margin-bottom: 0.25em; -} - -.collection -{ - margin: 0; - text-align: center; - font-weight: bold; - - font-size: 1.125em; - line-height: 1.5em; - margin-bottom: -0.25em; -} - -.subtitle -{ - margin: 0; - text-align: center; - font-weight: bold; - - font-size: 1.5em; - line-height: 1.5em; - margin-top: -0.25em; -} - -div.didaskalia -{ - font-style: italic; - margin-top: 0.5em; - margin-left: 1.5em; -} - -.kwestia -{ - margin-top: 0.5em; -} - -.stanza -{ - margin-bottom: 1em; -} - -.stanza-spacer -{ - display: none; -} - -.motto -{ - text-align: justify; - font-style: italic; - margin-top: 1.5em; -} - -.motto_podpis, .motto_podpis .paragraph -{ - font-size: 0.875em; - text-align: right; -} - -.fragment -{ - border-bottom: 0.1em solid #999; - padding-bottom: 1.5em; -} - -.note, .note .paragraph -{ - text-align: right; - font-style: italic; -} - -.dedication, .dedication .paragaph -{ - text-align: right; - font-style: italic; -} - -hr.spacer -{ - height: 3em; - visibility: hidden; -} - -hr.spacer-line -{ - margin: 0; - margin-top: 1.5em; - margin-bottom: 1.5em; - border: none; - border-bottom: 0.1em solid #000; -} - -.spacer-asterisk -{ - padding: 0; - margin: 0; - margin-top: 1.5em; - margin-bottom: 1.5em; - text-align: center; -} - -div.person-list ol -{ - list-style: none; - padding: 0; - padding-left: 1.5em; -} - -.place-and-time -{ - font-style: italic; -} - -em.math -{ - font-style: italic; -} -em.foreign-word -{ - font-style: italic; -} -em.book-title -{ - font-style: italic; -} -em.didaskalia -{ - font-style: italic; -} - -em.author-emphasis -{ - letter-spacing: 0.1em; -} - -.person-list em.person -{ - font-style: normal; - text-transform: uppercase; -} - -.info -{ - text-align: center; - margin-bottom: 1em; -} -.info div -{ - text-align: center; -} - -.info img -{ - margin: 0; - margin-left: 2em; - margin-right: 2em; -} - -p.minor { - font-size: 0.75em; -} -p.footer { - margin-top: 2em; -}