View Issue Details

IDProjectCategoryView StatusLast Update
0016070ScribusGraphics / Image Framespublic2020-04-05 19:37
ReporterPontobart Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.6.svn 
Target VersionFixed in Version1.5.6.svn 
Summary0016070: Improve AdjustFrameToImageSize
DescriptionAdjustFrameToImageSize currently fails for ImageFrames that are rotated or that have inner rotations of the images. I expect that AdjustFrameToImageSize does not move the image at all.
The attached patch should fix this.
Steps To ReproduceTake an image frame where the frame does not match the image. Rotate it. Try to adjust the frame to the image.
TagsNo tags attached.
PatchYes

Activities

Pontobart

2020-03-21 16:02

reporter  

adjust_image_to_frame.diff (2,977 bytes)
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(Revision 23522)
+++ scribus/scribusdoc.cpp	(Arbeitskopie)
@@ -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);
 			}
 		}

jghali

2020-03-22 14:36

administrator   ~0047449

Thanks, applied!

Issue History

Date Modified Username Field Change
2020-03-21 16:02 Pontobart New Issue
2020-03-21 16:02 Pontobart File Added: adjust_image_to_frame.diff
2020-03-22 14:36 jghali Assigned To => jghali
2020-03-22 14:36 jghali Status new => resolved
2020-03-22 14:36 jghali Resolution open => fixed
2020-03-22 14:36 jghali Fixed in Version => 1.5.6.svn
2020-03-22 14:36 jghali Note Added: 0047449
2020-04-05 19:37 cbradney Status resolved => closed