diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 721b6ae23..da1778d65 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -324,7 +324,7 @@ from settingstab import SettingsTab from serviceitem import ServiceItem from serviceitem import ServiceItemType from serviceitem import ItemCapabilities -from htmlbuilder import build_html +from htmlbuilder import build_html, build_lyrics_format_css from toolbar import OpenLPToolbar from dockwidget import OpenLPDockWidget from theme import ThemeLevel, ThemeXML diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index d03b7f7cc..f65bfb1e3 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -263,13 +263,10 @@ def build_html(item, screen, alert, islive): `islive` Item is going live, rather than preview/theme building """ - try: - webkitvers = float(QtWebKit.qWebKitVersion()) - except AttributeError: - webkitvers = 0 width = screen[u'size'].width() height = screen[u'size'].height() theme = item.themedata + webkitvers = webkit_version() if item.bg_frame: image = u'data:image/png;base64,%s' % image_to_byte(item.bg_frame) else: @@ -284,9 +281,16 @@ def build_html(item, screen, alert, islive): build_lyrics_html(item, webkitvers)) return html +def webkit_version(): + try: + webkitvers = float(QtWebKit.qWebKitVersion()) + except AttributeError: + webkitvers = 0 + return webkitvers + def build_lyrics_css(item, webkitvers): """ - Build the video display css + Build the lyrics display css `item` Service Item containing theme and location information @@ -304,7 +308,6 @@ def build_lyrics_css(item, webkitvers): } .lyricscell { display:table-cell; - word-wrap: break-word; %s } .lyricsmain { @@ -326,24 +329,9 @@ def build_lyrics_css(item, webkitvers): if theme: lyricstable = u'left: %spx; top: %spx;' % \ (item.main.x(), item.main.y()) - if theme.display_horizontalAlign == 2: - align = u'center' - elif theme.display_horizontalAlign == 1: - align = u'right' - else: - align = u'left' - if theme.display_verticalAlign == 2: - valign = u'bottom' - elif theme.display_verticalAlign == 1: - valign = u'middle' - else: - valign = u'top' - lyrics = u'width: %spx; height: %spx; text-align: %s; ' \ - 'vertical-align: %s; font-family: %s; font-size: %spt; ' \ - 'color: %s; line-height: %d%%;' % \ - (item.main.width(), item.main.height(), align, valign, - theme.font_main_name, theme.font_main_proportion, - theme.font_main_color, 100 + int(theme.font_main_line_adjustment)) + lyrics = build_lyrics_format_css(theme) + lyrics += u'width: %spx; height: %spx; ' % \ + (item.main.width(), item.main.height()) # For performance reasons we want to show as few DIV's as possible, # especially when animating/transitions. # However some bugs in older versions of qtwebkit mean we need to @@ -360,8 +348,6 @@ def build_lyrics_css(item, webkitvers): # webkit-text-stroke was used. So use an offset text layer underneath. # https://bugs.webkit.org/show_bug.cgi?id=19728 if theme.display_outline: - if webkitvers < 534.3: - lyrics += u' letter-spacing: 1px;' outline = u' -webkit-text-stroke: %sem %s; ' \ '-webkit-text-fill-color: %s; ' % \ (float(theme.display_outline_size) / 16, @@ -383,6 +369,44 @@ def build_lyrics_css(item, webkitvers): lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow) return lyrics_css +def build_lyrics_format_css(theme): + """ + Build the css which controls the theme format + Also used by renderer for splitting verses + + `item` + Service Item containing theme and location information + + `webkitvers` + The version of qtwebkit we're using + + """ + if theme.display_horizontalAlign == 2: + align = u'center' + elif theme.display_horizontalAlign == 1: + align = u'right' + else: + align = u'left' + if theme.display_verticalAlign == 2: + valign = u'bottom' + elif theme.display_verticalAlign == 1: + valign = u'middle' + else: + valign = u'top' + lyrics = u'word-wrap: break-word; ' \ + 'text-align: %s; vertical-align: %s; font-family: %s; ' \ + 'font-size: %spt; color: %s; line-height: %d%%;' % \ + (align, valign, theme.font_main_name, theme.font_main_proportion, + theme.font_main_color, 100 + int(theme.font_main_line_adjustment)) + if theme.display_outline: + if webkit_version() < 534.3: + lyrics += u' letter-spacing: 1px;' + if theme.font_main_italics: + lyrics += ' font-style:italic; ' + if theme.font_main_weight == u'Bold': + lyrics += ' font-weight:bold; ' + return lyrics + def build_lyrics_html(item, webkitvers): """ Build the HTML required to show the lyrics diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 41e547800..dae7c820a 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -31,7 +31,7 @@ import logging from PyQt4 import QtGui, QtCore -from openlp.core.lib import resize_image, expand_tags +from openlp.core.lib import resize_image, expand_tags, build_lyrics_format_css log = logging.getLogger(__name__) @@ -145,39 +145,20 @@ class Renderer(object): text.append(line) doc = QtGui.QTextDocument() doc.setPageSize(QtCore.QSizeF(self._rect.width(), self._rect.height())) - df = doc.defaultFont() - df.setPointSize(self._theme.font_main_proportion) - df.setFamily(self._theme.font_main_name) - main_weight = 50 - if self._theme.font_main_weight == u'Bold': - main_weight = 75 - df.setWeight(main_weight) - doc.setDefaultFont(df) layout = doc.documentLayout() formatted = [] - if self._theme.font_main_weight == u'Bold' and \ - self._theme.font_main_italics: - shell = u'{p}{st}{it}%s{/it}{/st}{/p}' - elif self._theme.font_main_weight == u'Bold' and \ - not self._theme.font_main_italics: - shell = u'{p}{st}%s{/st}{/p}' - elif self._theme.font_main_italics: - shell = u'{p}{it}%s{/it}{/p}' - else: - shell = u'{p}%s{/p}' - temp_text = u'' - old_html_text = u'' + shell = u'
' % build_lyrics_format_css(self._theme) + html_text = u'' + styled_text = shell for line in text: - # mark line ends - temp_text = temp_text + line + line_end - html_text = shell % expand_tags(temp_text) - doc.setHtml(html_text) - # Text too long so gone to next mage + styled_text += expand_tags(line) + line_end + doc.setHtml(styled_text + u'
') + # Text too long so go to next page if layout.pageCount() != 1: - formatted.append(shell % old_html_text) - temp_text = line + line_end - old_html_text = temp_text - formatted.append(shell % old_html_text) + formatted.append(html_text) + styled_text = shell + html_text += line + line_end + formatted.append(html_text) log.debug(u'format_slide - End') return formatted diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 134df0c42..0e8625ce7 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -160,9 +160,9 @@ class ServiceItem(object): self.themedata = self.render_manager.renderer._theme for slide in self._raw_frames: before = time.time() - formated = self.render_manager \ + formatted = self.render_manager \ .format_slide(slide[u'raw_slide'], line_break) - for page in formated: + for page in formatted: self._display_frames.append( {u'title': clean_tags(page), u'text': clean_tags(page.rstrip()),