From 0d99f5be96048c5a40862c39970392234593b692 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 23 Aug 2011 21:57:29 +0200 Subject: [PATCH 1/6] hopefully fixed bug #796528 (to be cleaned up Fixes: https://launchpad.net/bugs/796528 --- openlp/core/lib/renderer.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index ac7e95c4c..711be4227 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -229,13 +229,33 @@ class Renderer(object): pages = self._paginate_slide(lines, line_end) if len(pages) > 1: # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit): - # Do not forget the line breaks! - slides = text.split(u'[---]') + if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ + u'[---]' in text: pages = [] - for slide in slides: - lines = slide.strip(u'\n').split(u'\n') - pages.extend(self._paginate_slide(lines, line_end)) + while True: + html_text = expand_tags(text.split(u'[---]', 1)[0]) + html_text = html_text.strip() + html_text = html_text.replace(u'\n', u'
') + if not self._text_fits_on_slide(html_text): + text = text.replace(u'\n[---]', u'', 1) + else: + if u'[---]' in text: + slides = text.split(u'[---]', 1) + text_to_render = slides[0] + text_to_render = text_to_render.strip() + text_to_render = text_to_render.replace(u'\n', u'
') + text = slides[1] + else: + text_to_render = text + text = u'' + lines = text_to_render.strip(u'\n').split(u'\n') + lines = map(expand_tags, lines) + pages.extend(self._paginate_slide(lines, line_end)) + if not text or u'[---]' not in text: + lines = text.strip(u'\n').split(u'\n') + lines = map(expand_tags, lines) + pages.extend(self._paginate_slide(lines, line_end)) + break new_pages = [] for page in pages: while page.endswith(u'
'): @@ -488,7 +508,7 @@ class Renderer(object): returned, otherwise ``False``. ``text`` - The text to check. It can contain HTML tags. + The text to check. It may contain HTML tags. """ self.web_frame.evaluateJavaScript(u'show_text("%s")' % text.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) From 6c3d15636301db0249aafa1eee81b2d152824f4d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 26 Aug 2011 17:22:57 +0200 Subject: [PATCH 2/6] fixed inversion :-D --- openlp/core/lib/renderer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 711be4227..df8235b33 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -236,7 +236,7 @@ class Renderer(object): html_text = expand_tags(text.split(u'[---]', 1)[0]) html_text = html_text.strip() html_text = html_text.replace(u'\n', u'
') - if not self._text_fits_on_slide(html_text): + if self._text_fits_on_slide(html_text): text = text.replace(u'\n[---]', u'', 1) else: if u'[---]' in text: @@ -361,7 +361,7 @@ class Renderer(object): separator = u'
' html_lines = map(expand_tags, lines) # Text too long so go to next page. - if self._text_fits_on_slide(separator.join(html_lines)): + 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: @@ -394,18 +394,18 @@ class Renderer(object): line = line.strip() html_line = expand_tags(line) # Text too long so go to next page. - if self._text_fits_on_slide(previous_html + html_line): + if not self._text_fits_on_slide(previous_html + html_line): # Check if there was a verse before the current one and append # it, when it fits on the page. if previous_html: - if not self._text_fits_on_slide(previous_html): + if self._text_fits_on_slide(previous_html): formatted.append(previous_raw) previous_html = u'' previous_raw = u'' # Now check if the current verse will fit, if it does # not we have to start to process the verse word by # word. - if not self._text_fits_on_slide(html_line): + if self._text_fits_on_slide(html_line): previous_html = html_line + line_end previous_raw = line + line_end continue @@ -462,7 +462,7 @@ class Renderer(object): highest_index = len(html_list) - 1 index = int(highest_index / 2) while True: - if self._text_fits_on_slide( + if not self._text_fits_on_slide( previous_html + separator.join(html_list[:index + 1]).strip()): # We know that it does not fit, so change/calculate the # new index and highest_index accordingly. @@ -485,8 +485,8 @@ class Renderer(object): else: continue # Check if the remaining elements fit on the slide. - if not self._text_fits_on_slide( - separator.join(html_list[index + 1:]).strip()): + if self._text_fits_on_slide( + separator.join(html_list[index + 1:]).strip()): previous_html = separator.join( html_list[index + 1:]).strip() + line_end previous_raw = separator.join( @@ -512,7 +512,7 @@ class Renderer(object): """ self.web_frame.evaluateJavaScript(u'show_text("%s")' % text.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) - return self.web_frame.contentsSize().height() > self.page_height + return self.web_frame.contentsSize().height() <= self.page_height def _words_split(self, line): """ From 2364ea72c2b4b8fc2da0c7badd317639959b432e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 17:53:27 +0200 Subject: [PATCH 3/6] hopefully completed the fix --- openlp/core/lib/renderer.py | 43 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index df8235b33..b5d507e29 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -227,35 +227,36 @@ class Renderer(object): # Clean up line endings. lines = self._lines_split(text) pages = self._paginate_slide(lines, line_end) - if len(pages) > 1: - # Songs and Custom - if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ - u'[---]' in text: - pages = [] - while True: - html_text = expand_tags(text.split(u'[---]', 1)[0]) - html_text = html_text.strip() + # Songs and Custom + if item.is_capable(ItemCapabilities.AllowsVirtualSplit) and \ + len(pages) > 1 and u'[---]' in text: + pages = [] + while True: + html_text = expand_tags( + u'\n'.join(text.split(u'\n[---]\n', 2)[:-1])) + html_text = html_text.replace(u'\n', u'
') + if self._text_fits_on_slide(html_text): + text = text.replace(u'\n[---]', u'', 2) + else: + html_text = expand_tags(text.split(u'\n[---]\n', 1)[1]) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): text = text.replace(u'\n[---]', u'', 1) else: if u'[---]' in text: - slides = text.split(u'[---]', 1) - text_to_render = slides[0] - text_to_render = text_to_render.strip() - text_to_render = text_to_render.replace(u'\n', u'
') - text = slides[1] + html_text, text = text.split(u'\n[---]\n', 1) + html_text = html_text.replace(u'\n', u'
') else: - text_to_render = text + html_text = text text = u'' - lines = text_to_render.strip(u'\n').split(u'\n') - lines = map(expand_tags, lines) + lines = expand_tags(html_text) + lines = lines.strip(u'\n').split(u'\n') pages.extend(self._paginate_slide(lines, line_end)) - if not text or u'[---]' not in text: - lines = text.strip(u'\n').split(u'\n') - lines = map(expand_tags, lines) - pages.extend(self._paginate_slide(lines, line_end)) - break + if u'[---]' not in text: + lines = expand_tags(text) + lines = lines.strip(u'\n').split(u'\n') + pages.extend(self._paginate_slide(lines, line_end)) + break new_pages = [] for page in pages: while page.endswith(u'
'): From 2acd1ae2adfdc7f93240d1668a82b8a60677a021 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 18:04:18 +0200 Subject: [PATCH 4/6] added comments --- openlp/core/lib/renderer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index b5d507e29..c4cbe8568 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -232,17 +232,26 @@ class Renderer(object): len(pages) > 1 and u'[---]' in text: pages = [] while True: + # Check if the first two potential virtual slides will fit + # (as a whole) on one slide. html_text = expand_tags( u'\n'.join(text.split(u'\n[---]\n', 2)[:-1])) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): + # The first two virtual slides fit (as a whole) on one + # slide. Replace the occurrences of [---]. text = text.replace(u'\n[---]', u'', 2) else: + # The first two virtual slides did not fit as a whole. + # Check if the first virtual slide will fit. html_text = expand_tags(text.split(u'\n[---]\n', 1)[1]) html_text = html_text.replace(u'\n', u'
') if self._text_fits_on_slide(html_text): + # The first virtual slide fits, so remove it. text = text.replace(u'\n[---]', u'', 1) else: + # The first virtual slide does not fit, which means + # we have to render the first virtual slide. if u'[---]' in text: html_text, text = text.split(u'\n[---]\n', 1) html_text = html_text.replace(u'\n', u'
') From bc1f2d2977f050ddcd392adb9c730f6d11e2e50b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 18:59:09 +0200 Subject: [PATCH 5/6] removed wrong line --- openlp/core/lib/renderer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c4cbe8568..94cff011d 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -254,7 +254,6 @@ class Renderer(object): # we have to render the first virtual slide. if u'[---]' in text: html_text, text = text.split(u'\n[---]\n', 1) - html_text = html_text.replace(u'\n', u'
') else: html_text = text text = u'' From fc71905735e4d6fa9712e4bdc762c3a132314eb7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 28 Aug 2011 19:46:52 +0200 Subject: [PATCH 6/6] append text to the last slide (if more than one) --- openlp/core/lib/renderer.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 94cff011d..eed31a689 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -252,14 +252,26 @@ class Renderer(object): else: # The first virtual slide does not fit, which means # we have to render the first virtual slide. - if u'[---]' in text: + text_contains_break = u'[---]' in text + if text_contains_break: html_text, text = text.split(u'\n[---]\n', 1) else: html_text = text text = u'' lines = expand_tags(html_text) lines = lines.strip(u'\n').split(u'\n') - pages.extend(self._paginate_slide(lines, line_end)) + slides = self._paginate_slide(lines, line_end) + if len(slides) > 1 and text: + # Add all slides apart from the last one the + # list. + pages.extend(slides[:-1]) + if text_contains_break: + text = slides[-1] + u'\n[---]\n' + text + else: + text = slides[-1] + u'\n'+ text + text = text.replace(u'
', u'\n') + else: + pages.extend(slides) if u'[---]' not in text: lines = expand_tags(text) lines = lines.strip(u'\n').split(u'\n')