From c7ab79f9870e7813046347fb514cf252a612b7fb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 6 Sep 2011 13:56:52 +0200 Subject: [PATCH 1/7] fixed bug 805088 --- openlp/core/lib/renderer.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 8353ddc19..3c1bb9be8 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -31,7 +31,7 @@ from PyQt4 import QtGui, QtCore, QtWebKit 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 @@ -377,7 +377,8 @@ class Renderer(object): separator = u'
' html_lines = map(expand_tags, lines) # Text too long so go to next page. - if not self._text_fits_on_slide(separator.join(html_lines)): + text = separator.join(html_lines) + if not self._text_fits_on_slide(text): html_text, previous_raw = self._binary_chop(formatted, previous_html, previous_raw, html_lines, lines, separator, u'') else: @@ -439,6 +440,22 @@ class Renderer(object): log.debug(u'_paginate_slide_words - End') return formatted + def _get_start_tags(self, text): + missing_raw_tags = [] + missing_html_tags = [] + for tag in FormattingTags.get_html_tags(): + if tag[u'start html'] == u'
': + continue + if tag[u'start html'] in text: + missing_raw_tags.append((tag[u'start tag'], text.find(tag[u'start html']))) + missing_html_tags.append((tag[u'start html'], text.find(tag[u'start html']))) + elif tag[u'start tag'] in text: + missing_raw_tags.append((tag[u'start tag'], text.find(tag[u'start tag']))) + missing_html_tags.append((tag[u'start html'], text.find(tag[u'start tag']))) + missing_raw_tags.sort(key=lambda tag: tag[1]) + missing_html_tags.sort(key=lambda tag: tag[1]) + return u''.join(missing_raw_tags), u''.join(missing_html_tags) + def _binary_chop(self, formatted, previous_html, previous_raw, html_list, raw_list, separator, line_end): """ @@ -490,8 +507,10 @@ class Renderer(object): # 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'
') + - separator.join(raw_list[:index + 1])) + text = previous_raw.rstrip(u'
') + \ + 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 +521,19 @@ class Renderer(object): 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) From 4c869fa1f54619d6a8782d197b2d74504666a655 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 6 Sep 2011 13:57:31 +0200 Subject: [PATCH 2/7] fixed bug 805088 Fixes: https://launchpad.net/bugs/805088 From 3c3339f114643e1a06d8b2a2c1a93d09d454f014 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 18 Sep 2011 12:26:47 +0200 Subject: [PATCH 3/7] final fixes and clean ups --- openlp/core/lib/renderer.py | 46 ++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 3c1bb9be8..bf7319da0 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -440,21 +440,41 @@ class Renderer(object): log.debug(u'_paginate_slide_words - End') return formatted - def _get_start_tags(self, text): - missing_raw_tags = [] - missing_html_tags = [] + 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'') + + 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 html'] == u'
': + if tag[u'start tag'] == u'{br}': continue - if tag[u'start html'] in text: - missing_raw_tags.append((tag[u'start tag'], text.find(tag[u'start html']))) - missing_html_tags.append((tag[u'start html'], text.find(tag[u'start html']))) - elif tag[u'start tag'] in text: - missing_raw_tags.append((tag[u'start tag'], text.find(tag[u'start tag']))) - missing_html_tags.append((tag[u'start html'], text.find(tag[u'start tag']))) - missing_raw_tags.sort(key=lambda tag: tag[1]) - missing_html_tags.sort(key=lambda tag: tag[1]) - return u''.join(missing_raw_tags), u''.join(missing_html_tags) + 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): From ceec3d6f3a52b3c752d71ee74f3d35d16c478093 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 18 Sep 2011 12:32:27 +0200 Subject: [PATCH 4/7] reverted not necessary change --- openlp/core/lib/renderer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index bf7319da0..37443a76c 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -377,8 +377,7 @@ class Renderer(object): separator = u'
' html_lines = map(expand_tags, lines) # Text too long so go to next page. - text = separator.join(html_lines) - if not self._text_fits_on_slide(text): + if not self._text_fits_on_slide(separator.join(html_lines)): html_text, previous_raw = self._binary_chop(formatted, previous_html, previous_raw, html_lines, lines, separator, u'') else: From 724e2be04faecf2b8af5504bb54447ef046b6eb6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 19 Sep 2011 18:00:27 +0200 Subject: [PATCH 5/7] close tags --- openlp/core/lib/renderer.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 37443a76c..f08ca38fa 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -442,17 +442,20 @@ class Renderer(object): 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:: + consisting of three unicode strings:: - (u'{st}{r}', u'') + (u'{st}{r}Text text text{/st}{/r}', u'{st}{r}', u' + ') - 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. + The first unicode string is the text, with correct closing tags. The + second unicode string are OpenLP's opening formatting tags and the third + unicode string the html opening formatting tags. ``raw_text`` The text to test. The text must **not** contain html tags, only - OpenLP formatting tags are allowed. + OpenLP formatting tags are allowed:: + + {st}{r}Text text text """ raw_tags = [] html_tags = [] @@ -462,18 +465,23 @@ class Renderer(object): 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']))) + (raw_text.find(tag[u'start tag']), tag[u'start tag'], + tag[u'end tag'])) html_tags.append( - (tag[u'start html'], raw_text.find(tag[u'start tag']))) + (raw_text.find(tag[u'start tag']), tag[u'start html'])) # 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]) + raw_tags.sort(key=lambda tag: tag[0]) + html_tags.sort(key=lambda tag: tag[0]) + # Create a list with closing tags for the raw_text. + end_tags = [tag[2] for tag in raw_tags] + end_tags.reverse() # 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) + raw_tags = [tag[1] for tag in raw_tags] + html_tags = [tag[1] for tag in html_tags] + return raw_text + u''.join(end_tags), u''.join(raw_tags), \ + u''.join(html_tags) def _binary_chop(self, formatted, previous_html, previous_raw, html_list, raw_list, separator, line_end): @@ -528,8 +536,8 @@ class Renderer(object): index = smallest_index text = previous_raw.rstrip(u'
') + \ separator.join(raw_list[:index + 1]) + text, raw_tags, html_tags = self._get_start_tags(text) 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. From 240d612948e2aefc5a26a6eaf49b6dfa41fa9acb Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 19 Sep 2011 18:13:38 +0200 Subject: [PATCH 6/7] fixed doc --- openlp/core/lib/renderer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index f08ca38fa..68ca7f1a9 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -444,7 +444,7 @@ class Renderer(object): Tests the given text for not closed formatting tags and returns a tuple consisting of three unicode strings:: - (u'{st}{r}Text text text{/st}{/r}', u'{st}{r}', u' + (u'{st}{r}Text text text{/r}{/st}', u'{st}{r}', u' ') The first unicode string is the text, with correct closing tags. The From 920a65b4e1ee899595df7e953e99a5dcf53f0cb2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 20 Sep 2011 17:50:43 +0200 Subject: [PATCH 7/7] fix detection when tag exists more than once --- openlp/core/lib/renderer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 68ca7f1a9..abfd658ba 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -462,8 +462,8 @@ class Renderer(object): 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: + if raw_text.count(tag[u'start tag']) != \ + raw_text.count(tag[u'end tag']): raw_tags.append( (raw_text.find(tag[u'start tag']), tag[u'start tag'], tag[u'end tag']))