Crop watermark if doesn't fit on page.

This commit is contained in:
Roman Telezhynskyi 2021-09-28 16:10:55 +03:00
parent 2e9c94ffae
commit 72a2300bef

View File

@ -659,16 +659,19 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co
painter->save(); painter->save();
painter->setOpacity(watermarkData.opacity/100.); painter->setOpacity(watermarkData.opacity/100.);
if (watermark.width() < img.width() && watermark.height() < img.height())
{
QRect imagePosition(0, 0, watermark.width(), watermark.height()); QRect imagePosition(0, 0, watermark.width(), watermark.height());
imagePosition.translate(img.center().toPoint() - imagePosition.center()); imagePosition.translate(img.center().toPoint() - imagePosition.center());
if (watermark.width() < img.width() && watermark.height() < img.height())
{
painter->drawPixmap(imagePosition, watermark); painter->drawPixmap(imagePosition, watermark);
} }
else else
{ {
painter->drawPixmap(img.toRect(), watermark); QRect croppedRect = imagePosition.intersected(img.toRect());
QPixmap cropped = watermark.copy(croppedRect.translated(-imagePosition.x(), -imagePosition.y()));
painter->drawPixmap(croppedRect, cropped);
} }
painter->restore(); painter->restore();