From b48997e9bf3df931087db2ed867d3711e52029d5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Apr 2014 10:46:55 +0530 Subject: [PATCH] Conversion: When inserting metadata as a jacket page, alter the font 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. --- resources/jacket/stylesheet.css | 11 +++-------- src/calibre/ebooks/oeb/transforms/jacket.py | 22 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/resources/jacket/stylesheet.css b/resources/jacket/stylesheet.css index 879b2830e7..1bc6d5b125 100644 --- a/resources/jacket/stylesheet.css +++ b/resources/jacket/stylesheet.css @@ -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; } @@ -47,7 +47,6 @@ table.cbj_header td.cbj_title { ** Series */ table.cbj_header td.cbj_series { - font-size: medium; text-align: center; } @@ -55,7 +54,6 @@ table.cbj_header td.cbj_series { ** Author */ table.cbj_header td.cbj_author { - font-size: medium; text-align: center; } @@ -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; } diff --git a/src/calibre/ebooks/oeb/transforms/jacket.py b/src/calibre/ebooks/oeb/transforms/jacket.py index bf506bfe29..f9c5944a94 100644 --- a/src/calibre/ebooks/oeb/transforms/jacket.py +++ b/src/calibre/ebooks/oeb/transforms/jacket.py @@ -91,7 +91,7 @@ class Jacket(object): 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) @@ -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: @@ -268,6 +268,24 @@ def render_jacket(mi, output_profile, 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 # }}}