Cleanups - remove more old code

This commit is contained in:
Tim Bentley 2010-07-20 06:01:40 +01:00
parent c5e8a4cdab
commit 77fbd8ce3d
2 changed files with 104 additions and 118 deletions

View File

@ -167,13 +167,11 @@ def build_lyrics(item, width, height):
def build_footer(item, width, height): def build_footer(item, width, height):
lyrics = """ lyrics = """
#footer {position: absolute; %s z-index:3; %s; %s; %s %s } #footer {position: absolute; %s z-index:3; %s; %s }
""" """
theme = item.themedata theme = item.themedata
lyrics_html = u'' lyrics_html = u''
position = u'' position = u''
shadow = u''
outline = u''
font = u'' font = u''
text = u'' text = u''
if theme: if theme:
@ -193,16 +191,7 @@ def build_footer(item, width, height):
else: else:
valign = u'vertical-align=bottom;' valign = u'vertical-align=bottom;'
text = u'color:%s; %s %s' % (theme.font_footer_color, align, valign) text = u'color:%s; %s %s' % (theme.font_footer_color, align, valign)
if theme.display_shadow: lyrics_html = lyrics % (position, font, text)
shadow = u'text-shadow: %spx %spx %spx %s' %\
(theme.display_shadow_size, theme.display_shadow_size,
theme.display_shadow_size, theme.display_shadow_color)
if theme.display_outline:
# 1px is the blur radius
outline = u'text-outline: %spx 1px %s' %\
(theme.display_outline_size, theme.display_outline_color)
outline = u'text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white'
lyrics_html = lyrics % (position, shadow, outline, font, text)
print lyrics_html print lyrics_html
return lyrics_html return lyrics_html

View File

@ -131,8 +131,8 @@ class Renderer(object):
frame_height) frame_height)
self.frame = QtGui.QImage(frame_width, frame_height, self.frame = QtGui.QImage(frame_width, frame_height,
QtGui.QImage.Format_ARGB32_Premultiplied) QtGui.QImage.Format_ARGB32_Premultiplied)
self.frame_opaque = QtGui.QImage(frame_width, frame_height, # self.frame_opaque = QtGui.QImage(frame_width, frame_height,
QtGui.QImage.Format_ARGB32_Premultiplied) # QtGui.QImage.Format_ARGB32_Premultiplied)
if self._bg_image_filename and not self.bg_image: if self._bg_image_filename and not self.bg_image:
self.bg_image = resize_image(self._bg_image_filename, self.bg_image = resize_image(self._bg_image_filename,
self.frame.width(), self.frame.height()) self.frame.width(), self.frame.height())
@ -158,8 +158,6 @@ 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)
split_text = self.pre_render_text(text)
doc = QtGui.QTextDocument() doc = QtGui.QTextDocument()
doc.setPageSize(QtCore.QSizeF(self._rect.width(), self._rect.height())) doc.setPageSize(QtCore.QSizeF(self._rect.width(), self._rect.height()))
df = doc.defaultFont() df = doc.defaultFont()
@ -188,109 +186,108 @@ class Renderer(object):
old_html_text = temp_text old_html_text = temp_text
formatted.append(shell % old_html_text) formatted.append(shell % old_html_text)
log.debug(u'format_slide - End') log.debug(u'format_slide - End')
#return split_text
return formatted return formatted
def pre_render_text(self, text): # def pre_render_text(self, text):
metrics = QtGui.QFontMetrics(self.main_font) # metrics = QtGui.QFontMetrics(self.main_font)
#work out line width # #work out line width
line_width = self._rect.width() # line_width = self._rect.width()
#number of lines on a page - adjust for rounding up. # #number of lines on a page - adjust for rounding up.
line_height = metrics.height() # line_height = metrics.height()
if self._theme.display_shadow: # if self._theme.display_shadow:
line_height += int(self._theme.display_shadow_size) # line_height += int(self._theme.display_shadow_size)
if self._theme.display_outline: # if self._theme.display_outline:
# pixels top/bottom # # pixels top/bottom
line_height += 2 * int(self._theme.display_outline_size) # line_height += 2 * int(self._theme.display_outline_size)
page_length = int(self._rect.height() / line_height ) # page_length = int(self._rect.height() / line_height )
#Average number of characters in line # #Average number of characters in line
ave_line_width = line_width / metrics.averageCharWidth() # ave_line_width = line_width / metrics.averageCharWidth()
#Maximum size of a character # #Maximum size of a character
max_char_width = metrics.maxWidth() # max_char_width = metrics.maxWidth()
#Max characters pre line based on min size of a character # #Max characters pre line based on min size of a character
char_per_line = line_width / metrics.width(u'i') # char_per_line = line_width / metrics.width(u'i')
log.debug(u'Page Length area height %s , metrics %s , lines %s' % # log.debug(u'Page Length area height %s , metrics %s , lines %s' %
(int(self._rect.height()), metrics.height(), page_length )) # (int(self._rect.height()), metrics.height(), page_length ))
split_pages = [] # split_pages = []
page = [] # page = []
split_lines = [] # split_lines = []
count = 0 # count = 0
for line in text: # for line in text:
#Must be a blank line so keep it. # #Must be a blank line so keep it.
if len(line) == 0: # if len(line) == 0:
line = u' ' # line = u' '
while line: # while line:
pos = char_per_line # pos = char_per_line
split_text = line[:pos] # split_text = line[:pos]
#line needs splitting # #line needs splitting
if metrics.width(split_text, -1) > line_width: # if metrics.width(split_text, -1) > line_width:
#We have no spaces # #We have no spaces
if split_text.find(u' ') == -1: # if split_text.find(u' ') == -1:
#Move back 1 char at a time till it fits # #Move back 1 char at a time till it fits
while metrics.width(split_text, -1) > line_width: # while metrics.width(split_text, -1) > line_width:
split_text = split_text[:-1] # split_text = split_text[:-1]
pos = len(split_text) # pos = len(split_text)
else: # else:
#We have spaces so split at previous one # #We have spaces so split at previous one
while metrics.width(split_text, -1) > line_width: # while metrics.width(split_text, -1) > line_width:
pos = split_text.rfind(u' ') # pos = split_text.rfind(u' ')
#no more spaces and we are still too long # #no more spaces and we are still too long
if pos == -1: # if pos == -1:
while \ # while \
metrics.width(split_text, -1) > line_width: # metrics.width(split_text, -1) > line_width:
split_text = split_text[:-1] # split_text = split_text[:-1]
pos = len(split_text) # pos = len(split_text)
else: # else:
split_text = line[:pos] # split_text = line[:pos]
split_lines.append(split_text) # split_lines.append(split_text)
line = line[pos:].lstrip() # line = line[pos:].lstrip()
#if we have more text add up to 10 spaces on the front. # #if we have more text add up to 10 spaces on the front.
if line and self._theme.font_main_indentation > 0: # if line and self._theme.font_main_indentation > 0:
line = u'%s%s' % \ # line = u'%s%s' % \
(u' '[:int(self._theme.font_main_indentation)], # (u' '[:int(self._theme.font_main_indentation)],
line) # line)
#Text fits in a line now # #Text fits in a line now
for count, line in enumerate(split_lines): # for count, line in enumerate(split_lines):
page.append(line) # page.append(line)
#last but one line and only 2 lines to go or end of page # #last but one line and only 2 lines to go or end of page
if (len(page) == page_length - 1 and # if (len(page) == page_length - 1 and
len(split_lines) - 3 == count) or \ # len(split_lines) - 3 == count) or \
len(page) == page_length: # len(page) == page_length:
split_pages.append(page) # split_pages.append(page)
page = [] # page = []
if page and page != u' ': # if page and page != u' ':
split_pages.append(page) # split_pages.append(page)
return split_pages # return split_pages
#
def generate_frame_from_lines(self, lines, footer_lines=None): # def generate_frame_from_lines(self, lines, footer_lines=None):
""" # """
Render a set of lines according to the theme, and return the block # Render a set of lines according to the theme, and return the block
dimensions. # dimensions.
#
``lines`` # ``lines``
The lines to be rendered. # The lines to be rendered.
#
``footer_lines`` # ``footer_lines``
Defaults to *None*. The footer to render. # Defaults to *None*. The footer to render.
""" # """
log.debug(u'generate_frame_from_lines - Start') # log.debug(u'generate_frame_from_lines - Start')
bbox = self._render_lines_unaligned(lines, False) # bbox = self._render_lines_unaligned(lines, False)
if footer_lines: # if footer_lines:
bbox1 = self._render_lines_unaligned(footer_lines, True) # bbox1 = self._render_lines_unaligned(footer_lines, True)
# reset the frame. first time do not worry about what you paint on. # # reset the frame. first time do not worry about what you paint on.
self.frame = QtGui.QImage(self.bg_frame) # self.frame = QtGui.QImage(self.bg_frame)
if self._theme.display_slideTransition: # if self._theme.display_slideTransition:
self.frame_opaque = QtGui.QImage(self.bg_frame) # self.frame_opaque = QtGui.QImage(self.bg_frame)
x, y = self._correct_alignment(self._rect, bbox) # x, y = self._correct_alignment(self._rect, bbox)
bbox = self._render_lines_unaligned(lines, False, (x, y), True) # bbox = self._render_lines_unaligned(lines, False, (x, y), True)
if footer_lines: # if footer_lines:
bbox = self._render_lines_unaligned(footer_lines, True, # bbox = self._render_lines_unaligned(footer_lines, True,
(self._rect_footer.left(), self._rect_footer.top()), True) # (self._rect_footer.left(), self._rect_footer.top()), True)
log.debug(u'generate_frame_from_lines - Finish') # log.debug(u'generate_frame_from_lines - Finish')
if self._theme.display_slideTransition: # if self._theme.display_slideTransition:
return {u'main':self.frame, u'trans':self.frame_opaque} # return {u'main':self.frame, u'trans':self.frame_opaque}
else: # else:
return {u'main':self.frame, u'trans':None} # return {u'main':self.frame, u'trans':None}
def _generate_background_frame(self): def _generate_background_frame(self):
""" """