- fixed wrong use of strip()

- fixed soft break not working, when used within a line.
- removed redundant code

bzr-revno: 1502
This commit is contained in:
Andreas Preikschat 2011-04-29 18:46:10 +02:00
commit 15d0087a1a

View File

@ -222,13 +222,13 @@ class Renderer(object):
# Songs and Custom # Songs and Custom
if item.is_capable(ItemCapabilities.AllowsVirtualSplit): if item.is_capable(ItemCapabilities.AllowsVirtualSplit):
# Do not forget the line breaks ! # Do not forget the line breaks !
slides = text.split(u'\n[---]\n') slides = text.split(u'[---]')
pages = [] pages = []
for slide in slides: for slide in slides:
lines = self._lines(slide) lines = slide.strip(u'\n').split(u'\n')
new_pages = self._paginate_slide(lines, line_break, new_pages = self._paginate_slide(lines, line_break,
self.force_page) self.force_page)
pages.extend([page for page in new_pages]) pages.extend(new_pages)
# Bibles # Bibles
elif item.is_capable(ItemCapabilities.AllowsWordSplit): elif item.is_capable(ItemCapabilities.AllowsWordSplit):
pages = self._paginate_slide_words(text, line_break) pages = self._paginate_slide_words(text, line_break)
@ -341,12 +341,14 @@ class Renderer(object):
if force_page and line_count > 0: if force_page and line_count > 0:
Receiver.send_message(u'theme_line_count', line_count) Receiver.send_message(u'theme_line_count', line_count)
line_count = -1 line_count = -1
html_text = html_text.rstrip(u'<br>') while html_text.endswith(u'<br>'):
html_text = html_text[:-4]
formatted.append(html_text) formatted.append(html_text)
html_text = u'' html_text = u''
styled_text = styled_line styled_text = styled_line
html_text += line + line_end html_text += line + line_end
html_text = html_text.rstrip(u'<br>') while html_text.endswith(u'<br>'):
html_text = html_text[:-4]
formatted.append(html_text) formatted.append(html_text)
log.debug(u'_paginate_slide - End') log.debug(u'_paginate_slide - End')
return formatted return formatted
@ -371,7 +373,7 @@ class Renderer(object):
formatted = [] formatted = []
previous_html = u'' previous_html = u''
previous_raw = u'' previous_raw = u''
lines = self._lines(text) lines = text.split(u'\n')
for line in lines: for line in lines:
styled_line = expand_tags(line) styled_line = expand_tags(line)
html = self.page_shell + previous_html + styled_line + HTML_END html = self.page_shell + previous_html + styled_line + HTML_END
@ -385,7 +387,8 @@ class Renderer(object):
self.web.setHtml(html) self.web.setHtml(html)
if self.web_frame.contentsSize().height() <= \ if self.web_frame.contentsSize().height() <= \
self.page_height: self.page_height:
previous_raw = previous_raw.rstrip(u'<br>') while previous_raw.endswith(u'<br>'):
previous_raw = previous_raw[:-4]
formatted.append(previous_raw) formatted.append(previous_raw)
previous_html = u'' previous_html = u''
previous_raw = u'' previous_raw = u''
@ -408,7 +411,8 @@ class Renderer(object):
# Text too long so go to next page # Text too long so go to next page
if self.web_frame.contentsSize().height() > \ if self.web_frame.contentsSize().height() > \
self.page_height: self.page_height:
previous_raw = previous_raw.rstrip(u'<br>') while previous_raw.endswith(u'<br>'):
previous_raw = previous_raw[:-4]
formatted.append(previous_raw) formatted.append(previous_raw)
previous_html = u'' previous_html = u''
previous_raw = u'' previous_raw = u''
@ -419,36 +423,20 @@ class Renderer(object):
else: else:
previous_html += styled_line + line_end previous_html += styled_line + line_end
previous_raw += line + line_end previous_raw += line + line_end
previous_raw = previous_raw.rstrip(u'<br>') while previous_raw.endswith(u'<br>'):
previous_raw = previous_raw[:-4]
formatted.append(previous_raw) formatted.append(previous_raw)
log.debug(u'_paginate_slide_words - End') log.debug(u'_paginate_slide_words - End')
return formatted return formatted
def _lines(self, text):
"""
Split the slide up by physical line
"""
# this parse we do not want to use this so remove it
verses_text = text.split(u'\n')
text = []
for verse in verses_text:
lines = verse.split(u'\n')
text.extend([line for line in lines])
return text
def _words_split(self, line): def _words_split(self, line):
""" """
Split the slide up by word so can wrap better Split the slide up by word so can wrap better
""" """
# this parse we are to be wordy # this parse we are to be wordy
line = line.replace(u'\n', u' ') line = line.replace(u'\n', u' ')
verses_text = line.split(u' ') words = line.split(u' ')
text = [] return [word + u' ' for word in words]
for verse in verses_text:
lines = verse.split(u' ')
text.extend([line + u' ' for line in lines])
return text
def _lines_split(self, text): def _lines_split(self, text):
""" """
@ -457,9 +445,4 @@ class Renderer(object):
# this parse we do not want to use this so remove it # this parse we do not want to use this so remove it
text = text.replace(u'\n[---]', u'') text = text.replace(u'\n[---]', u'')
lines = text.split(u'\n') lines = text.split(u'\n')
real_lines = [] return [line.replace(u'[---]', u'') for line in lines]
for line in lines:
line = line.replace(u'[---]', u'')
sub_lines = line.split(u'\n')
real_lines.extend([sub_line for sub_line in sub_lines])
return real_lines