fixed virtue breaks, fixed word break

This commit is contained in:
Andreas Preikschat 2011-04-26 19:03:19 +02:00
parent 9c6a400634
commit 68fdc7dee9
3 changed files with 71 additions and 99 deletions

View File

@ -159,14 +159,14 @@ class Plugin(QtCore.QObject):
self.status = PluginStatus.Inactive
# Set up logging
self.log = logging.getLogger(self.name)
self.previewController = pluginHelpers[u'preview']
self.liveController = pluginHelpers[u'live']
self.renderer = pluginHelpers[u'renderer']
self.serviceManager = pluginHelpers[u'service']
self.settingsForm = pluginHelpers[u'settings form']
self.mediadock = pluginHelpers[u'toolbox']
self.pluginManager = pluginHelpers[u'pluginmanager']
self.formparent = pluginHelpers[u'formparent']
self.previewController = plugin_helpers[u'preview']
self.liveController = plugin_helpers[u'live']
self.renderer = plugin_helpers[u'renderer']
self.serviceManager = plugin_helpers[u'service']
self.settingsForm = plugin_helpers[u'settings form']
self.mediadock = plugin_helpers[u'toolbox']
self.pluginManager = plugin_helpers[u'pluginmanager']
self.formparent = plugin_helpers[u'formparent']
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'%s_add_service_item' % self.name),
self.processAddServiceEvent)

View File

@ -214,26 +214,26 @@ class Renderer(object):
``line_break``
Add line endings after each line of text used for bibles.
"""
print [text]
log.debug(u'format slide')
# clean up line endings
lines = self._lines_split(text)
pages = self._paginate_slide(lines, line_break, self.force_page)
if len(pages) > 1:
# Songs and Custom
if item.is_capable(ItemCapabilities.AllowsVirtualSplit):
# do not forget the line breaks !
slides = text.split(u'\n[---]\n')
pages = []
for slide in slides:
lines = self._lines(slide)
new_pages = self._paginate_slide(lines, line_break,
self.force_page)
for page in new_pages:
pages.append(page)
# # Bibles
elif item.is_capable(ItemCapabilities.AllowsWordSplit):
pages = self._paginate_slide_words(text, line_break)
# Songs and Custom
if item.is_capable(ItemCapabilities.AllowsVirtualSplit):
# Do not forget the line breaks !
slides = text.split(u'\n[---]\n')
pages = []
for slide in slides:
lines = self._lines(slide)
new_pages = self._paginate_slide(lines, line_break,
self.force_page)
pages.extend([page for page in new_pages])
# Bibles
elif item.is_capable(ItemCapabilities.AllowsWordSplit):
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
def _calculate_default(self, screen):
@ -316,13 +316,13 @@ class Renderer(object):
The words to be fitted on the slide split into lines.
``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``
Flag to tell message lines in page.
"""
log.debug(u'format_slide - Start')
log.debug(u'_paginate_slide - Start')
line_end = u''
if line_break:
line_end = u'<br>'
@ -342,16 +342,14 @@ class Renderer(object):
if force_page and line_count > 0:
Receiver.send_message(u'theme_line_count', line_count)
line_count = -1
if html_text.endswith(u'<br>'):
html_text = html_text[:len(html_text)-4]
html_text = html_text.rstrip(u'<br>')
formatted.append(html_text)
html_text = u''
styled_text = styled_line
html_text += line + line_end
if html_text.endswith(u'<br>'):
html_text = html_text[:len(html_text)-4]
html_text = html_text.rstrip(u'<br>')
formatted.append(html_text)
log.debug(u'format_slide - End')
log.debug(u'_paginate_slide - End')
return formatted
def _paginate_slide_words(self, text, line_break):
@ -367,71 +365,48 @@ class Renderer(object):
Add line endings after each line of text used for bibles.
"""
print [text]
log.debug(u'format_slide - Start')
# TODO: Make sure spaces are striped so that they will not confuse
# 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''
if line_break:
line_end = u'<br>'
formatted = []
html_text = u''
styled_text = u''
line_count = 0
force_current = False
previous_html = u''
previous_raw = u''
lines = self._lines(text, u'[---]')
previous_line = u''
# Loop through the lines
for line in lines:
line_count += 1
styled_line = expand_tags(line)
styled_line = line_end + styled_line
previous_line = line
previous_styled = styled_line
styled_text += styled_line
html = self.page_shell + styled_text + HTML_END
html = self.page_shell + previous_html + styled_line + HTML_END
self.web.setHtml(html)
# 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:
# we have more than 1 verse on the slide
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)
styled_text = u''
styled_line = u''
for word in words:
styled_word = expand_tags(word)
styled_text += styled_word
html = self.page_shell + styled_text + HTML_END
self.web.setHtml(html)
# 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 html_text.endswith(u'<br>'):
html_text = html_text[:len(html_text)-4]
formatted.append(html_text + line_break)
html_text = u''
styled_text = u''
html_text += word
a=1
words = self._words_split(line)
for word in words:
styled_word = expand_tags(word)
html = self.page_shell + previous_html + styled_word + \
HTML_END
self.web.setHtml(html)
# Text too long so go to next page
if self.web_frame.contentsSize().height() > self.page_height:
previous_raw = previous_raw.rstrip(u'<br>')
formatted.append(previous_raw)
previous_html = u''
previous_raw = u''
previous_html += styled_word
previous_raw += word
previous_html += line_end
previous_raw += line_end
else:
styled_text = styled_line
html_text += line + line_end
previous_line = line
if html_text.endswith(u'<br>'):
html_text = html_text[:len(html_text)-4]
formatted.append(html_text)
log.debug(u'format_slide - End')
previous_html += styled_line + line_end
previous_raw += line + line_end
previous_raw = previous_raw.rstrip(u'<br>')
formatted.append(previous_raw)
log.debug(u'_paginate_slide_words - End')
return formatted
def _lines(self, words, split=u'n[---]n'):
@ -444,8 +419,7 @@ class Renderer(object):
text = []
for verse in verses_text:
lines = verse.split(u'\n')
for line in lines:
text.append(line)
text.extend([line for line in lines])
return text
def _words_split(self, words):
@ -458,8 +432,7 @@ class Renderer(object):
text = []
for verse in verses_text:
lines = verse.split(u' ')
for line in lines:
text.append(line + u' ')
text.extend([line + u' ' for line in lines])
return text
def _lines_split(self, text):
@ -472,6 +445,5 @@ class Renderer(object):
for line in lines:
line = line.replace(u' [---]', u'[---]')
sub_lines = line.split(u'\n')
for sub_line in sub_lines:
real_lines.append(sub_line)
real_lines.extend([sub_line for sub_line in sub_lines])
return real_lines

View File

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