Fix #1526 (Error on EPUB conversion from deDRMed Mobipocket file)

This commit is contained in:
Kovid Goyal 2009-01-02 09:34:36 -08:00
parent 4f8315a5bb
commit c9177f4658
2 changed files with 22 additions and 1 deletions

View File

@ -788,7 +788,10 @@ class Processor(Parser):
size = '3' size = '3'
if size and size.strip() and size.strip()[0] in ('+', '-'): if size and size.strip() and size.strip()[0] in ('+', '-'):
size = 3 + float(size) # Hack assumes basefont=3 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) face = font.attrib.pop('face', None)
if face is not None: if face is not None:
setting += 'font-face:%s;'%face setting += 'font-face:%s;'%face

View File

@ -234,6 +234,15 @@ class MobiReader(object):
def cleanup_soup(self, soup): def cleanup_soup(self, soup):
if self.verbose: if self.verbose:
print 'Replacing height, width and align attributes' 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(): for tag in soup.recursiveChildGenerator():
if not isinstance(tag, Tag): continue if not isinstance(tag, Tag): continue
styles = [] styles = []
@ -259,6 +268,15 @@ class MobiReader(object):
if styles: if styles:
tag['style'] = '; '.join(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): def create_opf(self, htmlfile, guide=None):
mi = self.book_header.exth.mi mi = self.book_header.exth.mi
opf = OPFCreator(os.path.dirname(htmlfile), mi) opf = OPFCreator(os.path.dirname(htmlfile), mi)