diff --git a/src/libprs500/ebooks/lrf/objects.py b/src/libprs500/ebooks/lrf/objects.py index 4f6babf3c5..f1bd3ee463 100644 --- a/src/libprs500/ebooks/lrf/objects.py +++ b/src/libprs500/ebooks/lrf/objects.py @@ -308,6 +308,7 @@ class Locate(EmptyPageElement): pos_map = {1:'bottomleft', 2:'bottomright',3:'topright',4:'topleft', 5:'base'} def __init__(self, pos): + print pos self.pos = self.pos_map[pos] def __unicode__(self): @@ -316,11 +317,11 @@ class Locate(EmptyPageElement): class BlockSpace(EmptyPageElement): def __init__(self, xspace, yspace): - self.xsace, self.yspace = xspace, yspace + self.xspace, self.yspace = xspace, yspace def __unicode__(self): return u'\n\n'%\ - (self.xspace, self.ysapce) + (self.xspace, self.yspace) class Page(LRFStream): tag_map = { @@ -343,7 +344,7 @@ class Page(LRFStream): 0xF54E: 'page_div', 0xF547: 'x_space', 0xF546: 'y_space', - 0xF548: 'pos', + 0xF548: 'do_pos', 0xF573: 'ruled_line', 0xF5D4: 'wait', 0xF5D6: 'sound_stop', @@ -370,7 +371,7 @@ class Page(LRFStream): self.yspace = tag.word self.in_blockspace = True - def pos(self, tag): + def do_pos(self, tag): self.pos = tag.wordself.pos_map[tag.word] self.in_blockspace = True @@ -647,7 +648,7 @@ class Text(LRFStream): def invalid(op): stream.seek(op) - self.simple_container('EmpLine') + self.simple_container(None, 'EmpLine') oldpos = stream.tell() try: @@ -731,7 +732,8 @@ class Text(LRFStream): else: self.containers.append(self.__class__.Span('Span', {name:val})) current_style[name] = val - + if self.containers: + self.empty_containers() self.stream = None def __unicode__(self): @@ -741,9 +743,10 @@ class Text(LRFStream): if isinstance(c, basestring): s += c elif c is None: - p = open_containers.pop() - nl = u'\n' if p.name == 'P' else u'' - s += nl + u''%(p.name,) + nl + if len(open_containers) > 0: #for malformed text streams like those produced by BookDesigner + p = open_containers.pop() + nl = u'\n' if p.name == 'P' else u'' + s += nl + u''%(p.name,) + nl else: s += unicode(c) if not c.self_closing: diff --git a/src/libprs500/gui2/lrf_renderer/document.py b/src/libprs500/gui2/lrf_renderer/document.py index 6e94a1a225..94e3ceb37c 100644 --- a/src/libprs500/gui2/lrf_renderer/document.py +++ b/src/libprs500/gui2/lrf_renderer/document.py @@ -76,10 +76,10 @@ class FontLoader(object): rfont.setBold(wt>=69) self.cache[font] = rfont qfont = rfont - if text_style.underline or text_style.overline: + if text_style.emplinetype != 'none': qfont = QFont(rfont) - qfont.setOverline(text_style.overline) - qfont.setUnderline(text_style.underline) + qfont.setOverline(text_style.emplineposition == 'before') + qfont.setUnderline(text_style.emplineposition == 'after') return qfont class ParSkip(object): @@ -208,7 +208,9 @@ class Line(QGraphicsRectItem): tcf.setFont(ts.font) tcf.setVerticalAlignment(ts.valign) tcf.setForeground(ts.textcolor) - tcf.setUnderlineStyle(self.line_map[ts.line_style]) + tcf.setUnderlineColor(ts.linecolor) + if ts.emplineposition == 'after': + tcf.setUnderlineStyle(self.line_map[ts.emplinetype]) return tcf def populate(self, phrase, ts, wordspace, in_link): @@ -362,13 +364,11 @@ class TextStyle(Style): def __init__(self, style, font_loader, ruby_tags): self.font_loader = font_loader self.fontstyle = QFont.StyleNormal - self.valign = QTextCharFormat.AlignBottom - self.underline = False - self.overline = False - self.line_style = 'none' - Style.__init__(self, style, font_loader.dpi) + self.valign = QTextCharFormat.AlignBottom for attr in ruby_tags: setattr(self, attr, ruby_tags[attr]) + Style.__init__(self, style, font_loader.dpi) + self.emplinetype = 'none' self.font = self.font_loader.font(self) @@ -490,12 +490,9 @@ class TextBlock(ContentObject): open_containers.append((('current_style', self.current_style.copy()),)) self.current_style.valign=QTextCharFormat.AlignSubScript elif i.name == 'EmpLine': - open_containers.append((('current_style', self.current_style.copy()),)) - if i.attrs['emplineposition'] == 'before': - self.current_style.overline = True - if i.attrs['emplineposition'] == 'after': - self.current_style.underline = True - self.current_style.update(line_type=i.attrs['emplinetype']) + if i.attrs: + open_containers.append((('current_style', self.current_style.copy()),)) + self.current_style.update(i.attrs) else: self.logger.warning('Unhandled TextTag %s'%(i.name,)) if not i.self_closing: @@ -715,9 +712,15 @@ class Screen(_Canvas): self.setPen(QPen(Qt.red, 1, Qt.SolidLine)) header = footer = None if page_style.headheight > 0: - header = chapter.oddheader if odd else chapter.evenheader + try: + header = chapter.oddheader if odd else chapter.evenheader + except AttributeError: + pass if page_style.footheight > 0: - footer = chapter.oddfooter if odd else chapter.evenfooter + try: + footer = chapter.oddfooter if odd else chapter.evenfooter + except AttributeError: + pass if header: header = Header(font_loader, header, page_style, logger, opts, ruby_tags, link_activated) self.layout_canvas(header, self.content_x, self.header_y)