Skip to content

Commit

Permalink
Conversion: When inserting metadata as a jacket page, alter the font …
Browse files Browse the repository at this point in the history
…sizes in the jacket so that the sizes match the sizes used in the rest of the book. Also pretty print the generated jacket HTML.
  • Loading branch information
kovidgoyal committed Apr 9, 2014
1 parent fe0ea43 commit b48997e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 3 additions & 8 deletions resources/jacket/stylesheet.css
Expand Up @@ -38,7 +38,7 @@
** Title
*/
table.cbj_header td.cbj_title {
font-size: x-large;
font-size: 1.5em;
font-style: italic;
text-align: center;
}
Expand All @@ -47,15 +47,13 @@ table.cbj_header td.cbj_title {
** Series
*/
table.cbj_header td.cbj_series {
font-size: medium;
text-align: center;
}

/*
** Author
*/
table.cbj_header td.cbj_author {
font-size: medium;
text-align: center;
}

Expand Down Expand Up @@ -141,14 +139,11 @@ hr {

.cbj_footer {
font-family: sans-serif;
font-size: small;
font-size: 0.8em;
margin-top: 8px;
text-align: center;
}
.cbj_smallcaps {
font-size: 90%;
}

.cbj_comments {
font-family: sans-serif;
font-family: sans-serif;
}
22 changes: 20 additions & 2 deletions src/calibre/ebooks/oeb/transforms/jacket.py
Expand Up @@ -91,7 +91,7 @@ def insert_metadata(self, mi):

root = render_jacket(mi, self.opts.output_profile,
alt_title=title, alt_tags=tags,
alt_comments=comments)
alt_comments=comments, rescale_fonts=True)
id, href = self.oeb.manifest.generate('calibre_jacket', 'jacket.xhtml')

jacket = self.oeb.manifest.add(id, href, guess_type(href)[0], data=root)
Expand Down Expand Up @@ -144,7 +144,7 @@ def get_rating(rating, rchar, e_rchar):

def render_jacket(mi, output_profile,
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
alt_publisher=('')):
alt_publisher=(''), rescale_fonts=False):
css = P('jacket/stylesheet.css', data=True).decode('utf-8')

try:
Expand Down Expand Up @@ -268,6 +268,24 @@ def generate_html(comments):
except:
root = etree.fromstring(generate_html(''),
parser=RECOVER_PARSER)
if rescale_fonts:
# We ensure that the conversion pipeline will set the font sizes for
# text in the jacket to the same size as the font sizes for the rest of
# the text in the book. That means that as long as the jacket uses
# relative font sizes (em or %), the post conversion font size will be
# the same as for text in the main book. So text with size x em will
# be rescaled to the same value in both the jacket and the main content.
#
# We cannot use calibre_rescale_100 on the body tag as that will just
# give the body tag a font size of 1em, which is useless.
for body in root.xpath('//*[local-name()="body"]'):
fw = body.makeelement(XHTML('div'))
fw.set('class', 'calibre_rescale_100')
for child in body:
fw.append(child)
body.append(fw)
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree
pretty_html_tree(None, root)
return root

# }}}
Expand Down

0 comments on commit b48997e

Please sign in to comment.