From 88704fbc68d302b276813f89370e3e88a5316223 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 30 Aug 2011 15:35:06 +0200 Subject: [PATCH 1/3] fix soft break --- openlp/core/lib/renderer.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 3fff5cbe0..f9166e7d2 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -235,27 +235,36 @@ class Renderer(object): 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])) + slides = text.split(u'\n[---]\n', 2) + # If there are (at least) two occurrences of [---] we use + # the use the first two slides (and neglect the last for + # now). + if len(slides) == 3: + html_text = expand_tags(u'\n'.join(slides[:2])) + # We check both slides to determine if the virtual break is + # needed. + else: + html_text = expand_tags(u'\n'.join(slides)) 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) + text = text.replace(u'\n[---]', u'', 1) else: # The first two virtual slides did not fit as a whole. - # Check if the first virtual slide will fit. + # Check if the second part fits. 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): + if not 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 + # The first virtual slide fits, which means # we have to render the first virtual slide. text_contains_break = u'[---]' in text if text_contains_break: - text_to_render, text = text.split(u'\n[---]\n', 1) + text_to_render, text = text.split( + u'\n[---]\n', 1) else: text_to_render = text text = u'' From 25ce484fb1ce7b57a84a117a267698c7aaaef776 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 30 Aug 2011 17:12:16 +0200 Subject: [PATCH 2/3] hopefully fixed it now completely --- openlp/core/lib/renderer.py | 55 ++++++++++++++----------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index f9166e7d2..6ae0fa426 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -233,54 +233,41 @@ 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. slides = text.split(u'\n[---]\n', 2) # If there are (at least) two occurrences of [---] we use - # the use the first two slides (and neglect the last for - # now). + # the first two slides (and neglect the last for now). if len(slides) == 3: html_text = expand_tags(u'\n'.join(slides[:2])) # We check both slides to determine if the virtual break is - # needed. + # needed (there is only one virtual break). else: html_text = expand_tags(u'\n'.join(slides)) 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 [---]. + # slide. Replace the first occurrence of [---]. text = text.replace(u'\n[---]', u'', 1) else: - # The first two virtual slides did not fit as a whole. - # Check if the second part fits. - html_text = expand_tags(text.split(u'\n[---]\n', 1)[1]) - html_text = html_text.replace(u'\n', u'
') - if not self._text_fits_on_slide(html_text): - # The first virtual slide fits, so remove it. - text = text.replace(u'\n[---]', u'', 1) + # The first virtual slide fits, which means + # we have to render the first virtual slide. + if u'[---]' in text: + text_to_render, text = text.split(u'\n[---]\n', 1) else: - # The first virtual slide fits, which means - # we have to render the first virtual slide. - text_contains_break = u'[---]' in text - if text_contains_break: - text_to_render, text = text.split( - u'\n[---]\n', 1) + text_to_render = text + text = u'' + lines = text_to_render.strip(u'\n').split(u'\n') + 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_to_render = text - text = u'' - lines = text_to_render.strip(u'\n').split(u'\n') - 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) + text = slides[-1] + u'\n'+ text + text = text.replace(u'
', u'\n') + else: + pages.extend(slides) if u'[---]' not in text: lines = text.strip(u'\n').split(u'\n') pages.extend(self._paginate_slide(lines, line_end)) From 71bdaf0708c45f984952f8628444a5f5e896e010 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 30 Aug 2011 17:15:39 +0200 Subject: [PATCH 3/3] comments --- openlp/core/lib/renderer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 6ae0fa426..185d74878 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -248,9 +248,10 @@ class Renderer(object): # slide. Replace the first occurrence of [---]. text = text.replace(u'\n[---]', u'', 1) else: - # The first virtual slide fits, which means - # we have to render the first virtual slide. - if u'[---]' in text: + # The first virtual slide fits, which means we have to + # render the first virtual slide. + text_contains_break = u'[---]' in text + if text_contains_break: text_to_render, text = text.split(u'\n[---]\n', 1) else: text_to_render = text @@ -258,8 +259,7 @@ class Renderer(object): lines = text_to_render.strip(u'\n').split(u'\n') slides = self._paginate_slide(lines, line_end) if len(slides) > 1 and text: - # Add all slides apart from the last one the - # list. + # 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