2010-03-21 23:58:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-12-01 13:15:31 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
2009-07-14 13:51:27 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-07-24 22:10:47 +00:00
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
|
|
|
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
|
|
|
# Carsten Tinggaard, Frode Woldsund #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2010-06-29 15:25:24 +00:00
|
|
|
"""
|
|
|
|
The :mod:`renderer` module enables OpenLP to take the input from plugins and
|
|
|
|
format it for the output display.
|
|
|
|
"""
|
2009-03-29 14:38:23 +00:00
|
|
|
import logging
|
2009-05-11 05:09:43 +00:00
|
|
|
|
2010-09-04 13:06:06 +00:00
|
|
|
from PyQt4 import QtGui, QtCore, QtWebKit
|
2010-07-05 11:39:48 +00:00
|
|
|
|
2010-09-04 13:06:06 +00:00
|
|
|
from openlp.core.lib import resize_image, expand_tags, \
|
2010-09-16 21:19:51 +00:00
|
|
|
build_lyrics_format_css, build_lyrics_outline_css, image_to_byte
|
|
|
|
|
2008-10-07 19:12:32 +00:00
|
|
|
|
2010-02-27 15:31:23 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2009-07-10 13:16:15 +00:00
|
|
|
class Renderer(object):
|
2009-06-05 18:53:50 +00:00
|
|
|
"""
|
2009-06-08 04:30:12 +00:00
|
|
|
Genarates a pixmap image of a array of text. The Text is formatted to
|
2009-09-19 23:05:30 +00:00
|
|
|
make sure it fits on the screen and if not extra frames are generated.
|
2008-10-07 19:12:32 +00:00
|
|
|
"""
|
2009-06-05 18:53:50 +00:00
|
|
|
log.info(u'Renderer Loaded')
|
|
|
|
|
2009-05-16 10:24:03 +00:00
|
|
|
def __init__(self):
|
2009-07-10 13:16:15 +00:00
|
|
|
"""
|
|
|
|
Initialise the renderer.
|
|
|
|
"""
|
2009-05-16 10:24:03 +00:00
|
|
|
self._rect = None
|
|
|
|
self.theme_name = None
|
|
|
|
self._theme = None
|
2009-03-29 14:38:23 +00:00
|
|
|
|
2008-10-07 19:12:32 +00:00
|
|
|
def set_theme(self, theme):
|
2009-05-16 10:24:03 +00:00
|
|
|
"""
|
2009-07-10 13:16:15 +00:00
|
|
|
Set the theme to be used.
|
|
|
|
|
|
|
|
``theme``
|
|
|
|
The theme to be used.
|
2009-05-16 10:24:03 +00:00
|
|
|
"""
|
|
|
|
log.debug(u'set theme')
|
|
|
|
self._theme = theme
|
|
|
|
self.theme_name = theme.theme_name
|
2008-10-23 19:49:13 +00:00
|
|
|
|
2010-07-14 17:36:48 +00:00
|
|
|
def set_text_rectangle(self, rect_main, rect_footer):
|
|
|
|
"""
|
|
|
|
Sets the rectangle within which text should be rendered.
|
|
|
|
|
|
|
|
``rect_main``
|
|
|
|
The main text block.
|
|
|
|
|
|
|
|
``rect_footer``
|
|
|
|
The footer text block.
|
|
|
|
"""
|
|
|
|
log.debug(u'set_text_rectangle %s , %s' % (rect_main, rect_footer))
|
|
|
|
self._rect = rect_main
|
|
|
|
self._rect_footer = rect_footer
|
2010-09-16 21:19:51 +00:00
|
|
|
self.page_width = self._rect.width()
|
|
|
|
self.page_height = self._rect.height()
|
|
|
|
if self._theme.display_shadow:
|
|
|
|
self.page_width -= int(self._theme.display_shadow_size)
|
|
|
|
self.page_height -= int(self._theme.display_shadow_size)
|
2010-09-17 20:32:00 +00:00
|
|
|
self.web = QtWebKit.QWebView()
|
|
|
|
self.web.setVisible(False)
|
2010-09-16 21:19:51 +00:00
|
|
|
self.web.resize(self.page_width, self.page_height)
|
|
|
|
self.web_frame = self.web.page().mainFrame()
|
|
|
|
# Adjust width and height to account for shadow. outline done in css
|
|
|
|
self.page_shell = u'<html><head><style>' \
|
|
|
|
u'*{margin: 0; padding: 0; border: 0;} '\
|
|
|
|
u'#main {position:absolute; top:0px; %s %s}</style><body>' \
|
|
|
|
u'<div id="main">' % \
|
2010-09-20 18:36:56 +00:00
|
|
|
(build_lyrics_format_css(self._theme, self.page_width,
|
2010-09-16 21:19:51 +00:00
|
|
|
self.page_height), build_lyrics_outline_css(self._theme))
|
2010-07-14 17:36:48 +00:00
|
|
|
|
2010-08-03 19:23:05 +00:00
|
|
|
def format_slide(self, words, line_break):
|
2009-05-16 10:24:03 +00:00
|
|
|
"""
|
2009-07-10 13:16:15 +00:00
|
|
|
Figure out how much text can appear on a slide, using the current
|
|
|
|
theme settings.
|
|
|
|
|
|
|
|
``words``
|
|
|
|
The words to be fitted on the slide.
|
2009-05-16 10:24:03 +00:00
|
|
|
"""
|
2009-06-10 15:54:46 +00:00
|
|
|
log.debug(u'format_slide - Start')
|
2010-08-03 19:23:05 +00:00
|
|
|
line_end = u''
|
|
|
|
if line_break:
|
|
|
|
line_end = u'<br>'
|
2009-06-08 04:30:12 +00:00
|
|
|
words = words.replace(u'\r\n', u'\n')
|
2009-08-31 06:53:55 +00:00
|
|
|
verses_text = words.split(u'\n')
|
2009-06-01 17:50:37 +00:00
|
|
|
text = []
|
2009-05-16 10:24:03 +00:00
|
|
|
for verse in verses_text:
|
|
|
|
lines = verse.split(u'\n')
|
2009-06-01 17:50:37 +00:00
|
|
|
for line in lines:
|
2010-09-04 16:14:56 +00:00
|
|
|
text.append(line)
|
2010-07-11 05:40:56 +00:00
|
|
|
formatted = []
|
2010-09-03 22:03:54 +00:00
|
|
|
html_text = u''
|
2010-09-04 13:06:06 +00:00
|
|
|
styled_text = u''
|
2010-07-11 05:40:56 +00:00
|
|
|
for line in text:
|
2010-09-28 17:41:14 +00:00
|
|
|
styled_line = expand_tags(line)
|
|
|
|
if styled_text:
|
|
|
|
styled_text += line_end + styled_line
|
2010-09-15 18:03:54 +00:00
|
|
|
html = self.page_shell + styled_text + u'</div></body></html>'
|
|
|
|
self.web.setHtml(html)
|
2010-09-03 22:03:54 +00:00
|
|
|
# Text too long so go to next page
|
2010-09-16 21:19:51 +00:00
|
|
|
if self.web_frame.contentsSize().height() > self.page_height:
|
2010-09-03 22:03:54 +00:00
|
|
|
formatted.append(html_text)
|
2010-09-04 13:06:06 +00:00
|
|
|
html_text = u''
|
|
|
|
styled_text = styled_line
|
2010-09-03 22:03:54 +00:00
|
|
|
html_text += line + line_end
|
2010-09-28 17:41:14 +00:00
|
|
|
if line_break:
|
|
|
|
html_text = html_text[:len(html_text)-4]
|
2010-09-03 22:03:54 +00:00
|
|
|
formatted.append(html_text)
|
2009-06-10 15:54:46 +00:00
|
|
|
log.debug(u'format_slide - End')
|
2010-07-11 07:45:49 +00:00
|
|
|
return formatted
|