r23523 by jghali - #16070: Improve AdjustFrameToImageSize <Pontobart>

scribus-commit scribus-commit at lists.scribus.net
Sun Mar 22 14:36:01 UTC 2020


Author: jghali
Date: Sun Mar 22 14:36:00 2020
New Revision: 23523

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23523
Log:
#16070: Improve AdjustFrameToImageSize <Pontobart>

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23523&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sun Mar 22 14:36:00 2020
@@ -15919,18 +15919,41 @@
 		{
 			if (currItem->asImageFrame() && currItem->imageIsAvailable)
 			{
-				double w, h, x, y;
-				w = currItem->OrigW * currItem->imageXScale();
-				h = currItem->OrigH * currItem->imageYScale();
-				x = currItem->imageXOffset() * currItem->imageXScale();
-				y = currItem->imageYOffset() * currItem->imageYScale();
-				if ((x != 0.0) || (y != 0.0)) // if the image frame has an offset, its assumed that the user wants the image to stay where it is
-				{
-					sizeItem(w, h, currItem);
-					moveItem(x, y, currItem);
+				double w = currItem->OrigW * currItem->imageXScale();
+				double h = currItem->OrigH * currItem->imageYScale();
+				double x = currItem->imageXOffset() * currItem->imageXScale();
+				double y = currItem->imageYOffset() * currItem->imageYScale();
+
+				// m determines the position of the upper left corner of the image relative to
+				// the current position of the item. 
+				QTransform m = QTransform().rotate(currItem->rotation());
+				double newRotation = currItem->rotation();
+				if (currItem->imageFlippedH() && currItem->imageFlippedV()) {
+					newRotation += currItem->imageRotation();
+					// Inner rotation happens around the lower right corner. m already contains the item rotation.
+					// Next we have to translate to the rotation point. For flipped images the offsets are subtracted from
+					// the opposite edge. Then we have to adjust for the inner rotation. Finally, we can translate to
+					// to the upper left corner of the image. The transformations in the other cases happen analogously.
+					m.translate(currItem->width() - x, currItem->height() - y).rotate(currItem->imageRotation()).translate(-w, -h);
+				} else if (currItem->imageFlippedH() && !currItem->imageFlippedV()) {
+					newRotation -= currItem->imageRotation();
+					// Inner rotation happens around the upper right corner.
+					m.translate(currItem->width() - x, y).rotate(-currItem->imageRotation()).translate(-w, 0);
+				} else if (!currItem->imageFlippedH() && currItem->imageFlippedV()) {
+					newRotation -= currItem->imageRotation();
+					// Inner rotation happens around the lower left corner.
+					m.translate(x, currItem->height() - y).rotate(-currItem->imageRotation()).translate(0, -h);
+				} else { /* !FlippedH and !FlippedV */
+					newRotation += currItem->imageRotation();
+					// Inner rotation happens already around the upper left corner.
+					m.translate(x, y);
 				}
-				else
-					sizeItem(w, h, currItem, true);
+				currItem->setRotation(newRotation);
+				currItem->setImageRotation(0);
+
+				sizeItem(w, h, currItem);
+				QPointF imageUpperLeft = m.map(QPointF(0, 0));
+				moveItem(imageUpperLeft.x(), imageUpperLeft.y(), currItem);
 				currItem->setImageXYOffset(0.0, 0.0);
 			}
 		}




More information about the scribus-commit mailing list