Clean up the renderer some more.

Play with profiler
This commit is contained in:
Tim Bentley 2009-08-09 19:38:44 +01:00
parent 38f8005d5d
commit dc05294be6
2 changed files with 55 additions and 51 deletions

View File

@ -79,4 +79,6 @@ if __name__ == u'__main__':
Instantiate and run the application. Instantiate and run the application.
""" """
app = OpenLP(sys.argv) app = OpenLP(sys.argv)
#import cProfile
#cProfile.run("app.run()", "profile.out")
app.run() app.run()

View File

@ -144,6 +144,7 @@ class Renderer(object):
The footer of the slide. The footer of the slide.
""" """
log.debug(u'format_slide - Start') log.debug(u'format_slide - Start')
# print words
verses = [] verses = []
words = words.replace(u'\r\n', u'\n') words = words.replace(u'\r\n', u'\n')
verses_text = words.split(u'\n\n') verses_text = words.split(u'\n\n')
@ -152,8 +153,8 @@ 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)
#print text
split_text = self.pre_render_text(text) split_text = self.pre_render_text(text)
# print split_text
log.debug(u'format_slide - End') log.debug(u'format_slide - End')
return split_text return split_text
@ -162,11 +163,10 @@ class Renderer(object):
#take the width work out approx how many characters and add 50% #take the width work out approx how many characters and add 50%
line_width = self._rect.width() - self._right_margin line_width = self._rect.width() - self._right_margin
#number of lines on a page - adjust for rounding up. #number of lines on a page - adjust for rounding up.
#print self._rect.height() , metrics.height(), int(self._rect.height() / metrics.height()) # print "Metrics ", line_width
page_length = int(self._rect.height() / metrics.height() - 2 ) - 1 page_length = int(self._rect.height() / metrics.height() - 2 ) - 1
ave_line_width = line_width / metrics.averageCharWidth() ave_line_width = line_width / metrics.averageCharWidth()
# print "A", ave_line_width ave_line_width = int(ave_line_width + (ave_line_width * 1))
ave_line_width = int(ave_line_width + (ave_line_width * 0.5))
# print "B", ave_line_width # print "B", ave_line_width
split_pages = [] split_pages = []
page = [] page = []
@ -174,39 +174,36 @@ class Renderer(object):
count = 0 count = 0
for line in text: for line in text:
# print "C", line , len(line) # print "C", line , len(line)
if len(line) > ave_line_width: while len(line) > 0:
while len(line) > 0: # print "C1", line , len(line)
if len(line) > ave_line_width:
pos = line.find(u' ', ave_line_width) pos = line.find(u' ', ave_line_width)
# print "D2", len(line), ave_line_width, pos, line[:pos]
split_text = line[:pos] split_text = line[:pos]
# print "E", metrics.width(split_text, -1), line_width else:
while metrics.width(split_text, -1) > line_width: pos = len(line)
#Find the next space to the left split_text = line
pos = line[:pos].rfind(u' ') # print "E", metrics.width(split_text, -1), line_width
# print "F", ave_line_width, pos, line[:pos] while metrics.width(split_text, -1) > line_width:
#no more spaces found #Find the next space to the left
if pos == 0: pos = line[:pos].rfind(u' ')
split_text = line # print "F", pos, line[:pos]
while metrics.width(split_text, -1) > line_width: #no more spaces found
split_text = split_text[:-1] if pos == 0:
pos = len(split_text) split_text = line
else: while metrics.width(split_text, -1) > line_width:
split_text = line[:pos] split_text = split_text[:-1]
pos = len(split_text)
else:
split_text = line[:pos]
# print "F1", split_text, line, pos # print "F1", split_text, line, pos
split_lines.append(split_text) split_lines.append(split_text)
line = line[pos:] line = line[pos:]
#Text fits in a line now #Text fits in a line now
if len(line) <= ave_line_width: # if len(line) <= line_width:
split_lines.append(line) # split_lines.append(line)
line = u'' # line = u''
# count += 1 # print "G", split_lines
# if count == 15: # print "H", line
# a = c
# print "G", split_lines
# print "H", line
else:
split_lines.append(line)
line = u''
#print "I", split_lines, page_length #print "I", split_lines, page_length
for line in split_lines: for line in split_lines:
page.append(line) page.append(line)
@ -397,26 +394,32 @@ class Renderer(object):
# We draw the text to see how big it is and then iterate to make it fit # We draw the text to see how big it is and then iterate to make it fit
# when we line wrap we do in in the "lyrics" style, so the second line is # when we line wrap we do in in the "lyrics" style, so the second line is
# right aligned with a "hanging indent" # right aligned with a "hanging indent"
words = line.split(u' ') #print "----------------------------"
thisline = u' '.join(words) #print line
lastword = len(words) # words = line.split(u' ')
lines = [] # thisline = u' '.join(words)
# lastword = len(words)
# lines = []
maxx = self._rect.width(); maxx = self._rect.width();
maxy = self._rect.height(); maxy = self._rect.height();
while (len(words) > 0): # while (len(words) > 0):
w , h = self._get_extent_and_render(thisline, footer) # w , h = self._get_extent_and_render(thisline, footer)
rhs = w + x # print "m", w, h, x, maxx
if rhs < maxx - self._right_margin: # rhs = w + x
lines.append(thisline) # if rhs < maxx - self._right_margin:
words = words[lastword:] # lines.append(thisline)
thisline = ' '.join(words) # words = words[lastword:]
lastword = len(words) # thisline = ' '.join(words)
else: # lastword = len(words)
lastword -= 1 # else:
thisline = ' '.join(words[:lastword]) # lastword -= 1
# thisline = ' '.join(words[:lastword])
lines = []
lines.append(line)
startx = x startx = x
starty = y starty = y
rightextent = None rightextent = None
#print "inputs", startx, starty, maxx, maxy
# dont allow alignment messing with footers # dont allow alignment messing with footers
if footer: if footer:
align = 0 align = 0
@ -424,6 +427,7 @@ class Renderer(object):
else: else:
align = int(self._theme .display_horizontalAlign) align = int(self._theme .display_horizontalAlign)
shadow_offset = self._shadow_offset shadow_offset = self._shadow_offset
#print lines
for linenum in range(len(lines)): for linenum in range(len(lines)):
line = lines[linenum] line = lines[linenum]
#find out how wide line is #find out how wide line is
@ -534,8 +538,6 @@ class Renderer(object):
# setup defaults # setup defaults
painter = QtGui.QPainter() painter = QtGui.QPainter()
painter.begin(self._frame) painter.begin(self._frame)
# 'twould be more efficient to set this once when theme changes
# or p changes
if footer : if footer :
font = self.footerFont font = self.footerFont
else: else: