From 2dabc47ee6231a84121ce07ae7d1bd8422f40668 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Jun 2009 18:47:10 -0700 Subject: [PATCH] Handle lengths in units of ex and en --- src/calibre/ebooks/oeb/stylizer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index 8cac967890..daf5d21d2a 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -279,7 +279,7 @@ class Stylizer(object): class Style(object): - UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|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)$') def __init__(self, element, stylizer): self._element = element @@ -362,6 +362,11 @@ class Style(object): elif unit == 'em': font = font or self.fontSize result = value * font + elif unit in ('ex', 'en'): + # This is a hack for ex since we have no way to know + # the x-height of the font + font = font or self.fontSize + result = value * font * 0.5 elif unit == 'pc': result = value * 12.0 elif unit == 'mm':