Merged with head and Andreas

This commit is contained in:
Tim Bentley 2011-04-26 19:52:46 +01:00
commit 1d830ee1f0
2 changed files with 63 additions and 91 deletions

View File

@ -217,22 +217,22 @@ class Renderer(object):
log.debug(u'format slide') log.debug(u'format slide')
# clean up line endings # clean up line endings
lines = self._lines_split(text) lines = self._lines_split(text)
pages = self._paginate_slide(lines, line_break, self.force_page)
if len(pages) > 1:
# 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'\n[---]\n')
pages = [] pages = []
for slide in slides: for slide in slides:
lines = self._lines(slide) lines = self._lines(slide)
new_pages = self._paginate_slide(lines, line_break, new_pages = self._paginate_slide(lines, line_break,
self.force_page) self.force_page)
for page in new_pages: pages.extend([page for page in new_pages])
pages.append(page) # 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)
# Theme preview "service items".
else:
pages = self._paginate_slide(lines, line_break, self.force_page)
return pages return pages
def _calculate_default(self, screen): def _calculate_default(self, screen):
@ -316,13 +316,13 @@ class Renderer(object):
The words to be fitted on the slide split into lines. The words to be fitted on the slide split into lines.
``line_break`` ``line_break``
Add line endings after each line of text used for bibles. Add line endings after each line of text (used for bibles).
``force_page`` ``force_page``
Flag to tell message lines in page. Flag to tell message lines in page.
""" """
log.debug(u'format_slide - Start') log.debug(u'_paginate_slide - Start')
line_end = u'' line_end = u''
if line_break: if line_break:
line_end = u'<br>' line_end = u'<br>'
@ -342,16 +342,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
if html_text.endswith(u'<br>'): html_text = html_text.rstrip(u'<br>')
html_text = html_text[:len(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
if html_text.endswith(u'<br>'): html_text = html_text.rstrip(u'<br>')
html_text = html_text[:len(html_text)-4]
formatted.append(html_text) formatted.append(html_text)
log.debug(u'format_slide - End') log.debug(u'_paginate_slide - End')
return formatted return formatted
def _paginate_slide_words(self, text, line_break): def _paginate_slide_words(self, text, line_break):
@ -367,72 +365,48 @@ class Renderer(object):
Add line endings after each line of text used for bibles. Add line endings after each line of text used for bibles.
""" """
print "st", [text] # TODO: Make sure spaces are striped so that they will not confuse
log.debug(u'format_slide - Start') # rendering. for instance when the style is set to Verse per Line:
# In the beginning ...
# <space> <!-- here we could have added the second verse -->
# <new slide>
# Verse 2
log.debug(u'_paginate_slide_words - Start')
line_end = u'' line_end = u''
if line_break: if line_break:
line_end = u'<br>' line_end = u'<br>'
formatted = [] formatted = []
html_text = u'' previous_html = u''
styled_text = u'' previous_raw = u''
line_count = 0
force_current = False
lines = self._lines(text, u'[---]') lines = self._lines(text, u'[---]')
previous_line = u''
# Loop through the lines
for line in lines: for line in lines:
line_count += 1
styled_line = expand_tags(line) styled_line = expand_tags(line)
styled_line = line_end + styled_line html = self.page_shell + previous_html + styled_line + HTML_END
previous_line = line
previous_styled = styled_line
styled_text += styled_line
html = self.page_shell + styled_text + HTML_END
self.web.setHtml(html) self.web.setHtml(html)
# Text too long so go to next page # Text too long so go to next page
print self.web_frame.contentsSize().height() , self.page_height, [line]
if self.web_frame.contentsSize().height() > self.page_height: if self.web_frame.contentsSize().height() > self.page_height:
# we have more than 1 verse on the slide and it does not fit!
# Save the previous line as it fits on the page.
print "A", line_count
print "AA", [previous_line]
print "AAA", [styled_text]
if line_count > 1:
if html_text.endswith(u'<br>'):
html_text = html_text[:len(html_text)-4]
formatted.append(html_text + line_end)
line = previous_line
line_count = 1
html_text = u''
print "c", [html_text]
if line_count == 1:
line_count = 0
words = self._words_split(line) words = self._words_split(line)
styled_text = u''
styled_line = u''
for word in words: for word in words:
styled_word = expand_tags(word) styled_word = expand_tags(word)
styled_text += styled_word html = self.page_shell + previous_html + styled_word + \
html = self.page_shell + styled_text + HTML_END HTML_END
self.web.setHtml(html) self.web.setHtml(html)
# Text too long so go to next page # Text too long so go to next page
print self.web_frame.contentsSize().height() , self.page_height, [line]
if self.web_frame.contentsSize().height() > self.page_height: if self.web_frame.contentsSize().height() > self.page_height:
if html_text.endswith(u'<br>'): previous_raw = previous_raw.rstrip(u'<br>')
html_text = html_text[:len(html_text)-4] formatted.append(previous_raw)
formatted.append(html_text + line_break) previous_html = u''
html_text = u'' previous_raw = u''
styled_text = u'' previous_html += styled_word
html_text += word previous_raw += word
a=1 previous_html += line_end
previous_raw += line_end
else: else:
styled_text = styled_line previous_html += styled_line + line_end
html_text += line + line_end previous_raw += line + line_end
previous_line = line previous_raw = previous_raw.rstrip(u'<br>')
if html_text.endswith(u'<br>'): formatted.append(previous_raw)
html_text = html_text[:len(html_text)-4] log.debug(u'_paginate_slide_words - End')
formatted.append(html_text)
log.debug(u'format_slide - End')
return formatted return formatted
def _lines(self, words, split=u'n[---]n'): def _lines(self, words, split=u'n[---]n'):
@ -445,8 +419,8 @@ class Renderer(object):
text = [] text = []
for verse in verses_text: for verse in verses_text:
lines = verse.split(u'\n') lines = verse.split(u'\n')
for line in lines: text.extend([line for line in lines])
text.append(line)
return text return text
def _words_split(self, words): def _words_split(self, words):
@ -459,8 +433,7 @@ class Renderer(object):
text = [] text = []
for verse in verses_text: for verse in verses_text:
lines = verse.split(u' ') lines = verse.split(u' ')
for line in lines: text.extend([line + u' ' for line in lines])
text.append(line + u' ')
return text return text
def _lines_split(self, text): def _lines_split(self, text):
@ -473,6 +446,5 @@ class Renderer(object):
for line in lines: for line in lines:
line = line.replace(u' [---]', u'[---]') line = line.replace(u' [---]', u'[---]')
sub_lines = line.split(u'\n') sub_lines = line.split(u'\n')
for sub_line in sub_lines: real_lines.extend([sub_line for sub_line in sub_lines])
real_lines.append(sub_line)
return real_lines return real_lines

View File

@ -163,9 +163,7 @@ class ServiceItem(object):
log.debug(u'Render called') log.debug(u'Render called')
self._display_frames = [] self._display_frames = []
self.bg_image_bytes = None self.bg_image_bytes = None
line_break = True line_break = not self.is_capable(ItemCapabilities.NoLineBreaks)
if self.is_capable(ItemCapabilities.NoLineBreaks):
line_break = False
theme = self.theme if self.theme else None theme = self.theme if self.theme else None
self.main, self.footer = \ self.main, self.footer = \
self.renderer.set_override_theme(theme, use_override) self.renderer.set_override_theme(theme, use_override)
@ -176,11 +174,12 @@ class ServiceItem(object):
formatted = self.renderer \ formatted = self.renderer \
.format_slide(slide[u'raw_slide'], line_break, self) .format_slide(slide[u'raw_slide'], line_break, self)
for page in formatted: for page in formatted:
self._display_frames.append( self._display_frames.append({
{u'title': clean_tags(page), u'title': clean_tags(page),
u'text': clean_tags(page.rstrip()), u'text': clean_tags(page.rstrip()),
u'html': expand_tags(page.rstrip()), u'html': expand_tags(page.rstrip()),
u'verseTag': slide[u'verseTag'] }) u'verseTag': slide[u'verseTag']
})
elif self.service_item_type == ServiceItemType.Image or \ elif self.service_item_type == ServiceItemType.Image or \
self.service_item_type == ServiceItemType.Command: self.service_item_type == ServiceItemType.Command:
pass pass
@ -456,3 +455,4 @@ class ServiceItem(object):
return end return end
else: else:
return u'%s : %s' % (start, end) return u'%s : %s' % (start, end)