diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index 5b0dec32e4..50154a71a4 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to suit your distribution. """ -__version__ = "0.3.24" +__version__ = "0.3.25" __docformat__ = "epytext" __author__ = "Kovid Goyal " diff --git a/src/libprs500/lrf/html/convert_from.py b/src/libprs500/lrf/html/convert_from.py index 135122b2f2..b4c2c129f4 100644 --- a/src/libprs500/lrf/html/convert_from.py +++ b/src/libprs500/lrf/html/convert_from.py @@ -155,10 +155,10 @@ class Span(_Span): if ans: t['fontsize'] = ans elif key == 'font-weight': - ans = font_weight(val) + ans = font_weight(val) if ans: t['fontweight'] = ans - if ans > 140: + if int(ans) > 1400: t['wordspace'] = '50' elif key.startswith("margin"): if key == "margin": @@ -816,11 +816,11 @@ class HTMLConverter(object): self.css[key].update(ncss[key]) else: self.css[key] = ncss[key] - ncss = None + ncss = {} if tagname == 'style': for c in tag.contents: if isinstance(c, NavigableString): - ncss = self.parse_css(str(c)) + ncss.update(self.parse_css(str(c))) elif tag.has_key('type') and tag['type'] == "text/css" \ and tag.has_key('href'): url = tag['href'] @@ -834,7 +834,7 @@ class HTMLConverter(object): except IOError: pass if ncss: - update_css(ncss) + update_css(ncss) elif tagname == 'pre': self.end_current_para() self.current_block.append_to(self.current_page) diff --git a/src/libprs500/lrf/meta.py b/src/libprs500/lrf/meta.py index a013ad51f5..077fa2ff7d 100644 --- a/src/libprs500/lrf/meta.py +++ b/src/libprs500/lrf/meta.py @@ -87,6 +87,46 @@ class fixed_stringfield(object): return "A string of length " + str(self._length) + \ " starting at byte " + str(self._start) +class xml_attr_field(object): + def __init__(self, tag_name, attr, parent='BookInfo'): + self.tag_name = tag_name + self.parent = parent + self.attr= attr + + def __get__(self, obj, typ=None): + """ Return the data in this field or '' if the field is empty """ + document = dom.parseString(obj.info) + elems = document.getElementsByTagName(self.tag_name) + if len(elems): + elem = None + for candidate in elems: + if candidate.parentNode.nodeName == self.parent: + elem = candidate + if elem and elem.hasAttribute(self.attr): + return elem.getAttribute(self.attr) + + def __set__(self, obj, val): + if val == None: + val = "" + document = dom.parseString(obj.info) + elems = document.getElementsByTagName(self.tag_name) + if len(elems): + elem = None + for candidate in elems: + if candidate.parentNode.nodeName == self.parent: + elem = candidate + if elem: + elem.setAttribute(self.attr, val) + info = document.toxml(encoding='utf-16') + obj.info = info + + + def __repr__(self): + return "XML Attr Field: " + self.tag_name + " in " + self.parent + + def __str__(self): + return self.tag_name+'.'+self.attr + class xml_field(object): """ Descriptor that gets and sets XML based meta information from an LRF file. @@ -236,7 +276,9 @@ class LRFMetaFile(object): fmt=DWORD, start=0x54) title = xml_field("Title", parent="BookInfo") + title_reading = xml_attr_field("Title", 'reading', parent="BookInfo") author = xml_field("Author", parent="BookInfo") + author_reading = xml_attr_field("Author", 'reading', parent="BookInfo") # 16 characters. First two chars should be FB for personal use ebooks. book_id = xml_field("BookID", parent="BookInfo") publisher = xml_field("Publisher", parent="BookInfo") @@ -510,8 +552,12 @@ def main(): """, version=VERSION) parser.add_option("-t", "--title", action="store", type="string", \ dest="title", help="Set the book title") + parser.add_option('--title-sort', action='store', type='string', default=None, + dest='title_reading', help='Set sort key for the title') parser.add_option("-a", "--author", action="store", type="string", \ dest="author", help="Set the author") + parser.add_option('--author-sort', action='store', type='string', default=None, + dest='author_reading', help='Set sort key for the author') parser.add_option("-c", "--category", action="store", type="string", \ dest="category", help="The category this book belongs"+\ " to. E.g.: History") @@ -533,6 +579,10 @@ def main(): lrf = LRFMetaFile(open(args[0], "r+b")) if options.title: lrf.title = options.title + if options.title_reading != None: + lrf.title_reading = options.title_reading + if options.author_reading != None: + lrf.author_reading = options.author_reading if options.author: lrf.author = options.author if options.category: @@ -557,6 +607,7 @@ def main(): f.close() fields = LRFMetaFile.__dict__.items() + fields.sort() for f in fields: if "XML" in str(f): print str(f[1]) + ":", lrf.__getattribute__(f[0]).encode('utf-8')