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):
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(
'<item id="%s" href="%s" media-type="application/x-font-truetype" />' % (fname, fname)))
rmtree(tmpdir)
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 = {}
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)
+++ /dev/null
-/* =================================================== */
-/* = 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;
-}