From c9177f46582499d8f2e08a28539f6d9af755cb63 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Jan 2009 09:34:36 -0800 Subject: [PATCH] Fix #1526 (Error on EPUB conversion from deDRMed Mobipocket file) --- src/calibre/ebooks/html.py | 5 ++++- src/calibre/ebooks/mobi/reader.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 0fc9c10e25..011c0f6a8d 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -788,7 +788,10 @@ class Processor(Parser): size = '3' if size and size.strip() and size.strip()[0] in ('+', '-'): size = 3 + float(size) # Hack assumes basefont=3 - setting = 'font-size: %d%%;'%int((float(size)/3) * 100) + try: + setting = 'font-size: %d%%;'%int((float(size)/3) * 100) + except ValueError: + setting = '' face = font.attrib.pop('face', None) if face is not None: setting += 'font-face:%s;'%face diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index 5e553dcdd5..779bdf8067 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -234,6 +234,15 @@ class MobiReader(object): def cleanup_soup(self, soup): if self.verbose: print 'Replacing height, width and align attributes' + size_map = { + 'xx-small' : '0.5', + 'x-small' : '1', + 'small' : '2', + 'medium' : '3', + 'large' : '4', + 'x-large' : '5', + 'xx-large' : '6', + } for tag in soup.recursiveChildGenerator(): if not isinstance(tag, Tag): continue styles = [] @@ -258,6 +267,15 @@ class MobiReader(object): pass if styles: tag['style'] = '; '.join(styles) + + if tag.name.lower() == 'font': + sz = tag.get('size', '') + try: + float(sz) + except ValueError: + sz = sz.lower() + if sz in size_map.keys(): + tag['size'] = size_map[sz] def create_opf(self, htmlfile, guide=None): mi = self.book_header.exth.mi