diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index bdbdca85c8..b308b092e9 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -133,7 +133,8 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True): from PyQt4.QtWebKit import QWebPage from PyQt4.Qt import QEventLoop, QPalette, Qt, QUrl, QSize from calibre.gui2 import is_ok_to_use_qt - if not is_ok_to_use_qt(): return None + if not is_ok_to_use_qt(): + return None path_to_html = os.path.abspath(path_to_html) with CurrentDir(os.path.dirname(path_to_html)): page = QWebPage() @@ -214,9 +215,9 @@ def calibre_cover(title, author_string, series_string=None, if cleanup: os.remove(font_path) -UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc)$') +UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc|rem)$') -def unit_convert(value, base, font, dpi): +def unit_convert(value, base, font, dpi, body_font_size=12): ' Return value in pts' if isinstance(value, (int, long, float)): return value @@ -250,6 +251,8 @@ def unit_convert(value, base, font, dpi): result = value * 2.8346456693 elif unit == 'cm': result = value * 28.346456693 + elif unit == 'rem': + result = value * body_font_size return result def generate_masthead(title, output_path=None, width=600, height=60): diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index f9618099a4..fbb8fb1f49 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -210,6 +210,7 @@ class Stylizer(object): if self.profile is None: # Just in case the default profile is removed in the future :) self.profile = opts.output_profile + self.body_font_size = self.profile.fbase self.logger = oeb.logger item = oeb.manifest.hrefs[path] basename = os.path.basename(path) @@ -630,7 +631,7 @@ class Style(object): base = self.width if not font and font != 0: font = self.fontSize - return unit_convert(value, base, font, self._profile.dpi) + return unit_convert(value, base, font, self._profile.dpi, body_font_size=self._stylizer.body_font_size) def pt_to_px(self, value): return (self._profile.dpi / 72.0) * value diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 1b678a3fe5..eadcdff4d0 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -310,6 +310,8 @@ class CSSFlattener(object): except: font_size = self.sbase if self.sbase is not None else \ self.context.source.fbase + if tag == 'body' and isinstance(font_size, (int, float)): + stylizer.body_font_size = font_size if 'align' in node.attrib: if tag != 'img': cssdict['text-align'] = node.attrib['align']