← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/bug-805088 into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/bug-805088 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #805088 in OpenLP: "Display tags do not work on second slide when slide is split"
  https://bugs.launchpad.net/openlp/+bug/805088

For more details, see:
https://code.launchpad.net/~googol/openlp/bug-805088/+merge/75905

Hello,

Fixed bug 805088 "Display tags do not work on second slide when slide is split"

To test this, you can use a slide with this text:

{o}a
a
a
{g}a
a{/g}
a
a
{bl}a
a
a
a
a
a{/bl}
a
a
a
a
a
a
a
a
a{/o}
a
a
a
-- 
https://code.launchpad.net/~googol/openlp/bug-805088/+merge/75905
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/bug-805088 into lp:openlp.
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py	2011-08-31 07:49:57 +0000
+++ openlp/core/lib/renderer.py	2011-09-18 15:41:31 +0000
@@ -31,7 +31,7 @@
 
 from openlp.core.lib import ServiceItem, expand_tags, \
     build_lyrics_format_css, build_lyrics_outline_css, Receiver, \
-    ItemCapabilities
+    ItemCapabilities, FormattingTags
 from openlp.core.lib.theme import ThemeLevel
 from openlp.core.ui import MainDisplay, ScreenList
 
@@ -439,6 +439,42 @@
         log.debug(u'_paginate_slide_words - End')
         return formatted
 
+    def _get_start_tags(self, raw_text):
+        """
+        Tests the given text for not closed formatting tags and returns a tuple
+        consisting of two unicode strings::
+
+            (u'{st}{r}', u'<strong><span style="-webkit-text-fill-color:red">')
+
+        The returned strings can be prepended to the next slide. The first
+        unicode string are OpenLP's formatting tags and the second unicode
+        string the html formatting tags.
+
+        ``raw_text``
+            The text to test. The text must **not** contain html tags, only
+            OpenLP formatting tags are allowed.
+        """
+        raw_tags = []
+        html_tags = []
+        for tag in FormattingTags.get_html_tags():
+            if tag[u'start tag'] == u'{br}':
+                continue
+            if tag[u'start tag'] in raw_text and not \
+                tag[u'end tag'] in raw_text:
+                raw_tags.append(
+                    (tag[u'start tag'], raw_text.find(tag[u'start tag'])))
+                html_tags.append(
+                    (tag[u'start html'], raw_text.find(tag[u'start tag'])))
+        # Sort the lists, so that the tags which were opened first on the first
+        # slide (the text we are checking) will be opened first on the next
+        # slide as well.
+        raw_tags.sort(key=lambda tag: tag[1])
+        html_tags.sort(key=lambda tag: tag[1])
+        # Remove the indexes.
+        raw_tags = [tag[0] for tag in raw_tags]
+        html_tags = [tag[0] for tag in html_tags]
+        return u''.join(raw_tags), u''.join(html_tags)
+
     def _binary_chop(self, formatted, previous_html, previous_raw, html_list,
         raw_list, separator, line_end):
         """
@@ -490,8 +526,10 @@
             # We found the number of words which will fit.
             if smallest_index == index or highest_index == index:
                 index = smallest_index
-                formatted.append(previous_raw.rstrip(u'<br>') +
-                    separator.join(raw_list[:index + 1]))
+                text = previous_raw.rstrip(u'<br>') + \
+                    separator.join(raw_list[:index + 1])
+                formatted.append(text)
+                raw_tags, html_tags = self._get_start_tags(text)
                 previous_html = u''
                 previous_raw = u''
                 # Stop here as the theme line count was requested.
@@ -502,17 +540,19 @@
                 continue
             # Check if the remaining elements fit on the slide.
             if self._text_fits_on_slide(
-                    separator.join(html_list[index + 1:]).strip()):
-                previous_html = separator.join(
+                    html_tags + separator.join(html_list[index + 1:]).strip()):
+                previous_html = html_tags + separator.join(
                     html_list[index + 1:]).strip() + line_end
-                previous_raw = separator.join(
+                previous_raw = raw_tags + separator.join(
                     raw_list[index + 1:]).strip() + line_end
                 break
             else:
                 # The remaining elements do not fit, thus reset the indexes,
                 # create a new list and continue.
                 raw_list = raw_list[index + 1:]
+                raw_list[0] = raw_tags + raw_list[0]
                 html_list = html_list[index + 1:]
+                html_list[0] = html_tags + html_list[0]
                 smallest_index = 0
                 highest_index = len(html_list) - 1
                 index = int(highest_index / 2)


Follow ups