r22362 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Thu Feb 1 13:05:12 UTC 2018


Author: jghali
Date: Thu Feb  1 13:05:12 2018
New Revision: 22362

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22362
Log:
#14840: Exporting embedded pdf file sometime produces incorrect result

Modified:
    trunk/Scribus/scribus/pdflib_core.cpp

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22362&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Thu Feb  1 13:05:12 2018
@@ -9796,12 +9796,20 @@
 			importedObjects[page->GetObject()->Reference()] = xObj;
 			writer.startObj(xObj);
 			PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1");
-			PoDoFo::PdfRect pageRect   = page->GetArtBox(); // Because scimagedataloader_pdf use ArtBox
+			PoDoFo::PdfRect pageRect = page->GetArtBox(); // Because scimagedataloader_pdf use ArtBox
 			int rotation = page->GetRotation();
+			double imgWidth  = (rotation == 90 || rotation == 270) ? pageRect.GetHeight() : pageRect.GetWidth();
+			double imgHeight = (rotation == 90 || rotation == 270) ? pageRect.GetWidth() : pageRect.GetHeight();
 			QTransform pageM;
 			pageM.translate(pageRect.GetLeft(), pageRect.GetBottom());
-			pageM.scale(pageRect.GetWidth(), pageRect.GetHeight());
 			pageM.rotate(rotation);
+			if (rotation == 90)
+				pageM.translate(0.0, -imgHeight);
+			else if (rotation == 180)
+				pageM.translate(-imgWidth, -imgHeight);
+			else if (rotation == 270)
+				pageM.translate(-imgWidth, 0.0);
+			pageM.scale(imgWidth, imgHeight);
 			pageM = pageM.inverted();
 			PutDoc("\n/BBox [" + Pdf::toPdf(pageRect.GetLeft()));
 			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom()));
@@ -9811,19 +9819,10 @@
 			PutDoc("\n/Matrix [" + Pdf::toPdf(pageM.m11()) + " "
 								 + Pdf::toPdf(pageM.m12()) + " "
 								 + Pdf::toPdf(pageM.m21()) + " "
-								 + Pdf::toPdf(pageM.m22()) + " ");
-			if (rotation == 0)
-				PutDoc("0 0");
-			else if (rotation == 90)
-				PutDoc("0 1");
-			else if (rotation == 180)
-				PutDoc("1 1");
-			else if (rotation == 270)
-				PutDoc("1 0");
-			else
-				PutDoc("0 0");
+								 + Pdf::toPdf(pageM.m22()) + " "
+								 + Pdf::toPdf(pageM.dx())  + " "
+								 + Pdf::toPdf(pageM.dy())  + " ");
 			PutDoc("]");
-//			PutDoc("\n/Matrix [" + Pdf::toPdf(1.0/pagesize.GetWidth()) + " 0 0 " + Pdf::toPdf(1.0/pagesize.GetHeight()) + " 0 0]");
 			PutDoc("\n/Resources " + Pdf::toPdf(xResources) + " 0 R");
 			nextObj = page->GetObject()->GetIndirectKey("Group");
 			if (nextObj)
@@ -9902,14 +9901,14 @@
 			imgInfo.ResNum = ResCount;
 			ResCount++;
 			// Avoid a divide-by-zero if width/height are less than 1 point:
-			imgInfo.Width  = qMax(1, (int) pageRect.GetWidth());
-			imgInfo.Height = qMax(1, (int) pageRect.GetHeight());
-			imgInfo.xa  = sx * pageRect.GetWidth()/imgInfo.Width;
-			imgInfo.ya  = sy * pageRect.GetHeight()/imgInfo.Height;
+			imgInfo.Width  = qMax(1, (int) imgWidth);
+			imgInfo.Height = qMax(1, (int) imgHeight);
+			imgInfo.xa  = sx * imgWidth / imgInfo.Width;
+			imgInfo.ya  = sy * imgHeight / imgInfo.Height;
 			// Width/Height are integers and may not exactly equal pageRect.GetWidth()/
 			// pageRect.GetHeight(). Adjust scale factor to compensate for the difference.
-			imgInfo.sxa = sx * pageRect.GetWidth()/imgInfo.Width;
-			imgInfo.sya = sy * pageRect.GetHeight()/imgInfo.Height;
+			imgInfo.sxa = sx * imgWidth / imgInfo.Width;
+			imgInfo.sya = sy * imgHeight / imgInfo.Height;
 
 			return true;
 		}
@@ -9926,10 +9925,18 @@
 			PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1");
 			PoDoFo::PdfRect pageRect = page->GetArtBox(); // Because scimagedataloader_pdf use ArtBox
 			int rotation = page->GetRotation();
-			QMatrix pageM;
+			double imgWidth  = (rotation == 90 || rotation == 270) ? pageRect.GetHeight() : pageRect.GetWidth();
+			double imgHeight = (rotation == 90 || rotation == 270) ? pageRect.GetWidth() : pageRect.GetHeight();
+			QTransform pageM;
 			pageM.translate(pageRect.GetLeft(), pageRect.GetBottom());
-			pageM.scale(pageRect.GetWidth(), pageRect.GetHeight());
 			pageM.rotate(rotation);
+			if (rotation == 90)
+				pageM.translate(0.0, -imgHeight);
+			else if (rotation == 180)
+				pageM.translate(-imgWidth, -imgHeight);
+			else if (rotation == 270)
+				pageM.translate(-imgWidth, 0.0);
+			pageM.scale(imgWidth, imgHeight);
 			pageM = pageM.inverted();
 			PutDoc("\n/BBox [" + Pdf::toPdf(pageRect.GetLeft()));
 			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom()));
@@ -9939,17 +9946,9 @@
 			PutDoc("\n/Matrix [" + Pdf::toPdf(pageM.m11()) + " "
 								 + Pdf::toPdf(pageM.m12()) + " "
 								 + Pdf::toPdf(pageM.m21()) + " "
-								 + Pdf::toPdf(pageM.m22()) + " ");
-			if (rotation == 0)
-				PutDoc("0 0");
-			else if (rotation == 90)
-				PutDoc("0 1");
-			else if (rotation == 180)
-				PutDoc("1 1");
-			else if (rotation == 270)
-				PutDoc("1 0");
-			else
-				PutDoc("0 0");
+								 + Pdf::toPdf(pageM.m22()) + " "
+								 + Pdf::toPdf(pageM.dx())  + " "
+								 + Pdf::toPdf(pageM.dy())  + " ");
 			PutDoc("]");
 			PutDoc("\n/Resources " + Pdf::toPdf(xResources) + " 0 R");
 			nextObj = page->GetObject()->GetIndirectKey("Group");
@@ -10045,14 +10044,14 @@
 			imgInfo.ResNum = ResCount;
 			ResCount++;
 			// Avoid a divide-by-zero if width/height are less than 1 point:
-			imgInfo.Width  = qMax(1, (int) pageRect.GetWidth());
-			imgInfo.Height = qMax(1, (int) pageRect.GetHeight());
-			imgInfo.xa  = sx * pageRect.GetWidth() / imgInfo.Width;
-			imgInfo.ya  = sy * pageRect.GetHeight() / imgInfo.Height;
+			imgInfo.Width  = qMax(1, (int) imgWidth);
+			imgInfo.Height = qMax(1, (int) imgHeight);
+			imgInfo.xa  = sx * imgWidth / imgInfo.Width;
+			imgInfo.ya  = sy * imgHeight / imgInfo.Height;
 			// Width/Height are integers and may not exactly equal pageRect.GetWidth()/
 			// pageRect.GetHeight(). Adjust scale factor to compensate for the difference.
-			imgInfo.sxa = sx * pageRect.GetWidth() / imgInfo.Width;
-			imgInfo.sya = sy * pageRect.GetHeight() / imgInfo.Height;
+			imgInfo.sxa = sx * imgWidth / imgInfo.Width;
+			imgInfo.sya = sy * imgHeight / imgInfo.Height;
 
 			return true;
 		}




More information about the scribus-commit mailing list