css tidies, attempt to get paging correct, replacing qtextdoc with qwebview

This commit is contained in:
Jonathan Corwin 2010-09-04 14:06:06 +01:00
parent 1fca6ec81d
commit 1899fc3415
3 changed files with 74 additions and 40 deletions

View File

@ -324,7 +324,8 @@ from settingstab import SettingsTab
from serviceitem import ServiceItem from serviceitem import ServiceItem
from serviceitem import ServiceItemType from serviceitem import ServiceItemType
from serviceitem import ItemCapabilities from serviceitem import ItemCapabilities
from htmlbuilder import build_html, build_lyrics_format_css from htmlbuilder import build_html, build_lyrics_format_css, \
build_lyrics_outline_css
from toolbar import OpenLPToolbar from toolbar import OpenLPToolbar
from dockwidget import OpenLPDockWidget from dockwidget import OpenLPDockWidget
from theme import ThemeLevel, ThemeXML from theme import ThemeLevel, ThemeXML

View File

@ -329,9 +329,10 @@ def build_lyrics_css(item, webkitvers):
if theme: if theme:
lyricstable = u'left: %spx; top: %spx;' % \ lyricstable = u'left: %spx; top: %spx;' % \
(item.main.x(), item.main.y()) (item.main.x(), item.main.y())
lyrics = build_lyrics_format_css(theme) lyrics = build_lyrics_format_css(theme, item.main.width(),
lyrics += u'width: %spx; height: %spx; ' % \ item.main.height())
(item.main.width(), item.main.height()) #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, # For performance reasons we want to show as few DIV's as possible,
# especially when animating/transitions. # especially when animating/transitions.
# However some bugs in older versions of qtwebkit mean we need to # However some bugs in older versions of qtwebkit mean we need to
@ -347,29 +348,37 @@ def build_lyrics_css(item, webkitvers):
# Before 534.4 the text-shadow didn't get displayed when # Before 534.4 the text-shadow didn't get displayed when
# webkit-text-stroke was used. So use an offset text layer underneath. # webkit-text-stroke was used. So use an offset text layer underneath.
# https://bugs.webkit.org/show_bug.cgi?id=19728 # https://bugs.webkit.org/show_bug.cgi?id=19728
if theme.display_outline: if webkitvers >= 533.3:
outline = u' -webkit-text-stroke: %sem %s; ' \ lyricsmain += build_lyrics_outline_css(theme)
'-webkit-text-fill-color: %s; ' % \ else:
(float(theme.display_outline_size) / 16, outline = build_lyrics_outline_css(theme)
theme.display_outline_color, theme.font_main_color) if theme.display_shadow:
if webkitvers >= 533.3: if theme.display_outline and webkitvers < 534.3:
lyricsmain += outline shadow = u'padding-left: %spx; padding-top: %spx ' % \
if theme.display_shadow and webkitvers < 534.3: (theme.display_shadow_size, theme.display_shadow_size)
shadow = u'-webkit-text-stroke: %sem %s; ' \ shadow += build_lyrics_outline_css(theme, True)
u'-webkit-text-fill-color: %s; ' \ else:
u' padding-left: %spx; padding-top: %spx' % \ lyricsmain += u' text-shadow: %s %spx %spx;' % \
(float(theme.display_outline_size) / 16, (theme.display_shadow_color, theme.display_shadow_size,
theme.display_shadow_color, theme.display_shadow_color, theme.display_shadow_size)
theme.display_shadow_size, theme.display_shadow_size)
if theme.display_shadow and \
(not theme.display_outline or webkitvers >= 534.3):
lyricsmain += u' text-shadow: %s %spx %spx;' % \
(theme.display_shadow_color, theme.display_shadow_size,
theme.display_shadow_size)
lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow) lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow)
return lyrics_css return lyrics_css
def build_lyrics_format_css(theme): def build_lyrics_outline_css(theme, is_shadow=False):
if theme.display_outline:
size = float(theme.display_outline_size) / 16
if is_shadow:
fill_color = theme.display_shadow_color
outline_color = theme.display_shadow_color
else:
fill_color = theme.font_main_color
outline_color = theme.display_outline_color
return u' -webkit-text-stroke: %sem %s; ' \
u'-webkit-text-fill-color: %s; ' % (size, outline_color, fill_color)
else:
return u''
def build_lyrics_format_css(theme, width, height):
""" """
Build the css which controls the theme format Build the css which controls the theme format
Also used by renderer for splitting verses Also used by renderer for splitting verses
@ -393,18 +402,20 @@ def build_lyrics_format_css(theme):
valign = u'middle' valign = u'middle'
else: else:
valign = u'top' valign = u'top'
lyrics = u'word-wrap: break-word; ' \ lyrics = u'white-space:pre-wrap; word-wrap: break-word; ' \
'text-align: %s; vertical-align: %s; font-family: %s; ' \ 'text-align: %s; vertical-align: %s; font-family: %s; ' \
'font-size: %spt; color: %s; line-height: %d%%;' % \ 'font-size: %spt; color: %s; line-height: %d%%; ' \
'margin:0; padding:0; width: %spx; height: %spx; ' % \
(align, valign, theme.font_main_name, theme.font_main_proportion, (align, valign, theme.font_main_name, theme.font_main_proportion,
theme.font_main_color, 100 + int(theme.font_main_line_adjustment)) theme.font_main_color, 100 + int(theme.font_main_line_adjustment),
width, height)
if theme.display_outline: if theme.display_outline:
if webkit_version() < 534.3: if webkit_version() < 534.3:
lyrics += u' letter-spacing: 1px;' lyrics += u' letter-spacing: 1px;'
if theme.font_main_italics: if theme.font_main_italics:
lyrics += ' font-style:italic; ' lyrics += u' font-style:italic; '
if theme.font_main_weight == u'Bold': if theme.font_main_weight == u'Bold':
lyrics += ' font-weight:bold; ' lyrics += u' font-weight:bold; '
return lyrics return lyrics
def build_lyrics_html(item, webkitvers): def build_lyrics_html(item, webkitvers):

View File

@ -29,9 +29,10 @@ format it for the output display.
""" """
import logging import logging
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore, QtWebKit
from openlp.core.lib import resize_image, expand_tags, build_lyrics_format_css from openlp.core.lib import resize_image, expand_tags, \
build_lyrics_format_css, build_lyrics_outline_css
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -143,20 +144,41 @@ class Renderer(object):
lines = verse.split(u'\n') lines = verse.split(u'\n')
for line in lines: for line in lines:
text.append(line) text.append(line)
doc = QtGui.QTextDocument()
doc.setPageSize(QtCore.QSizeF(self._rect.width(), self._rect.height())) web = QtWebKit.QWebView()
layout = doc.documentLayout() web.resize(self._rect.width(), self._rect.height())
web.setVisible(False)
frame = web.page().mainFrame()
# Adjust width and height to account for shadow. outline done in css
width = self._rect.width() + int(self._theme.display_shadow_size)
height = self._rect.height() + int(self._theme.display_shadow_size)
css = u'<html><head><style>#main {%s %s}</style><body>' \
u'<div id="main">' % \
(build_lyrics_format_css(self._theme, width, height),
build_lyrics_outline_css(self._theme))
# doc = QtGui.QTextDocument()
# doc.setPageSize(QtCore.QSizeF(self._rect.width(), self._rect.height()))
# doc.setDocumentMargin(0)
# css = u'* {%s}' % build_lyrics_format_css(self._theme)
# doc.setDefaultStyleSheet(css)
#layout = doc.documentLayout()
formatted = [] formatted = []
shell = u'<div style="%s">' % build_lyrics_format_css(self._theme)
html_text = u'' html_text = u''
styled_text = shell styled_text = u''
divheight = 'document.getElementById("main").scrollHeight'
for line in text: for line in text:
styled_text += expand_tags(line) + line_end styled_line = expand_tags(line) + line_end
doc.setHtml(styled_text + u'</div>') styled_text += styled_line
html = css + styled_text + u'</div></body></html>'
web.setHtml(html)
# doc.setHtml(styled_text)
# Text too long so go to next page # Text too long so go to next page
if layout.pageCount() != 1: # if doc.pageCount() != 1:
text_height = int(frame.evaluateJavaScript(divheight).toString())
if text_height > height:
formatted.append(html_text) formatted.append(html_text)
styled_text = shell html_text = u''
styled_text = styled_line
html_text += line + line_end html_text += line + line_end
formatted.append(html_text) formatted.append(html_text)
log.debug(u'format_slide - End') log.debug(u'format_slide - End')