forked from openlp/openlp
Rendering cleanup
This commit is contained in:
parent
3ba6733f14
commit
b4a08096d6
@ -78,26 +78,19 @@ class Renderer:
|
|||||||
|
|
||||||
def scale_bg_image(self):
|
def scale_bg_image(self):
|
||||||
assert self._frame
|
assert self._frame
|
||||||
image = QtGui.QImage(self._bg_image_filename)
|
preview = QtGui.QPixmap(self._bg_image_filename)
|
||||||
# rescale and offset
|
width = self._frame.width()
|
||||||
imw = image.width()
|
height = self._frame.height()
|
||||||
imh = image.height()
|
preview = preview.scaled(width, height, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
|
||||||
dcw = self._frame.width()+1
|
realwidth = preview.width()
|
||||||
dch = self._frame.height()
|
realheight = preview.height()
|
||||||
imratio = imw/float(imh)
|
# and move it to the centre of the preview space
|
||||||
dcratio = dcw/float(dch)
|
self.bg_image = QtGui.QPixmap(width, height)
|
||||||
log.debug(u'Image scaling params %s %s %s %s %s %s', imw, imh, imratio, dcw, dch, dcratio)
|
self.bg_image.fill(QtCore.Qt.transparent)
|
||||||
if imratio > dcratio:
|
painter = QtGui.QPainter(self.bg_image)
|
||||||
scale = dcw/float(imw)
|
self.background_offsetx = (width - realwidth) / 2
|
||||||
elif imratio < dcratio:
|
self.background_offsety = (height - realheight) / 2
|
||||||
scale = dch/float(imh)
|
painter.drawPixmap(self.background_offsetx, self.background_offsety , preview)
|
||||||
else:
|
|
||||||
scale = dcw/float(imw) # either will do
|
|
||||||
neww = int(round(imw*scale))
|
|
||||||
newh = int(round(imh*scale))
|
|
||||||
self.background_offsetx=(dcw-neww)/2
|
|
||||||
self.background_offsety=(dch-newh)/2
|
|
||||||
self.bg_image=QtGui.QPixmap.fromImage(image.scaled(QtCore.QSize(neww, newh), Qt.Qt.KeepAspectRatio))
|
|
||||||
|
|
||||||
def set_frame_dest(self, frame_width, frame_height, preview=False):
|
def set_frame_dest(self, frame_width, frame_height, preview=False):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user