r22052 by jghali - #14840: fix case of PDF being wrongly offset on export when using PDF embedding option

scribus-commit scribus-commit at lists.scribus.net
Mon Jun 5 09:17:57 UTC 2017


Author: jghali
Date: Mon Jun  5 09:17:57 2017
New Revision: 22052

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22052
Log:
#14840: fix case of PDF being wrongly offset on export when using PDF embedding option

Modified:
    trunk/Scribus/scribus/pdflib_core.cpp

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22052&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Mon Jun  5 09:17:57 2017
@@ -9717,15 +9717,17 @@
 			importedObjects[page->GetObject()->Reference()] = xObj;
 			writer.startObj(xObj);
 			PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1");
-			PoDoFo::PdfRect pagesize = page->GetPageSize();
+			PoDoFo::PdfRect pageRect   = page->GetArtBox(); // Because scimagedataloader_pdf use ArtBox
 			int rotation = page->GetRotation();
 			QTransform pageM;
-			pageM.scale(1.0/pagesize.GetWidth(), 1.0/pagesize.GetHeight());
-			pageM.rotate(-rotation);
-			PutDoc("\n/BBox [" + Pdf::toPdf(pagesize.GetLeft()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetBottom()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetLeft() + pagesize.GetWidth()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetBottom() + pagesize.GetHeight()));
+			pageM.translate(pageRect.GetLeft(), pageRect.GetBottom());
+			pageM.scale(pageRect.GetWidth(), pageRect.GetHeight());
+			pageM.rotate(rotation);
+			pageM = pageM.inverted();
+			PutDoc("\n/BBox [" + Pdf::toPdf(pageRect.GetLeft()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetLeft() + pageRect.GetWidth()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom() + pageRect.GetHeight()));
 			PutDoc("]");
 			PutDoc("\n/Matrix [" + Pdf::toPdf(pageM.m11()) + " "
 								 + Pdf::toPdf(pageM.m12()) + " "
@@ -9738,7 +9740,7 @@
 			else if (rotation == 180)
 				PutDoc("1 1");
 			else if (rotation == 270)
-				PutDoc(Pdf::toPdf(pagesize.GetHeight() / pagesize.GetWidth()) + " " + Pdf::toPdf(1.0 - 1.0 / (pagesize.GetHeight() / pagesize.GetWidth())));
+				PutDoc("1 0");
 			else
 				PutDoc("0 0");
 			PutDoc("]");
@@ -9821,14 +9823,14 @@
 			imgInfo.ResNum = ResCount;
 			ResCount++;
 			// Avoid a divide-by-zero if width/height are less than 1 point:
-			imgInfo.Width  = qMax(1, (int) pagesize.GetWidth());
-			imgInfo.Height = qMax(1, (int) pagesize.GetHeight());
-			imgInfo.xa  = sx * pagesize.GetWidth()/imgInfo.Width;
-			imgInfo.ya  = sy * pagesize.GetHeight()/imgInfo.Height;
-			// Width/Height are integers and may not exactly equal pagesize.GetWidth()/
-			// pagesize.GetHeight(). Adjust scale factor to compensate for the difference.
-			imgInfo.sxa = sx * pagesize.GetWidth()/imgInfo.Width;
-			imgInfo.sya = sy * pagesize.GetHeight()/imgInfo.Height;
+			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;
+			// 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;
 
 			return true;
 		}
@@ -9843,15 +9845,17 @@
 			importedObjects[page->GetObject()->Reference()] = xObj;
 			writer.startObj(xObj);
 			PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1");
-			PoDoFo::PdfRect pagesize = page->GetPageSize();
+			PoDoFo::PdfRect pageRect = page->GetArtBox(); // Because scimagedataloader_pdf use ArtBox
 			int rotation = page->GetRotation();
 			QMatrix pageM;
-			pageM.scale(1.0/pagesize.GetWidth(), 1.0/pagesize.GetHeight());
-			pageM.rotate(-rotation);
-			PutDoc("\n/BBox [" + Pdf::toPdf(pagesize.GetLeft()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetBottom()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetLeft() + pagesize.GetWidth()));
-			PutDoc(" " + Pdf::toPdf(pagesize.GetBottom() + pagesize.GetHeight()));
+			pageM.translate(pageRect.GetLeft(), pageRect.GetBottom());
+			pageM.scale(pageRect.GetWidth(), pageRect.GetHeight());
+			pageM.rotate(rotation);
+			pageM = pageM.inverted();
+			PutDoc("\n/BBox [" + Pdf::toPdf(pageRect.GetLeft()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetLeft() + pageRect.GetWidth()));
+			PutDoc(" " + Pdf::toPdf(pageRect.GetBottom() + pageRect.GetHeight()));
 			PutDoc("]");
 			PutDoc("\n/Matrix [" + Pdf::toPdf(pageM.m11()) + " "
 								 + Pdf::toPdf(pageM.m12()) + " "
@@ -9864,7 +9868,7 @@
 			else if (rotation == 180)
 				PutDoc("1 1");
 			else if (rotation == 270)
-				PutDoc(Pdf::toPdf(pagesize.GetHeight() / pagesize.GetWidth()) + " " + Pdf::toPdf(1.0 - 1.0 / (pagesize.GetHeight() / pagesize.GetWidth())));
+				PutDoc("1 0");
 			else
 				PutDoc("0 0");
 			PutDoc("]");
@@ -9962,14 +9966,14 @@
 			imgInfo.ResNum = ResCount;
 			ResCount++;
 			// Avoid a divide-by-zero if width/height are less than 1 point:
-			imgInfo.Width  = qMax(1, (int) pagesize.GetWidth());
-			imgInfo.Height = qMax(1, (int) pagesize.GetHeight());
-			imgInfo.xa  = sx * pagesize.GetWidth()/imgInfo.Width;
-			imgInfo.ya  = sy * pagesize.GetHeight()/imgInfo.Height;
-			// Width/Height are integers and may not exactly equal pagesize.GetWidth()/
-			// pagesize.GetHeight(). Adjust scale factor to compensate for the difference.
-			imgInfo.sxa = sx * pagesize.GetWidth()/imgInfo.Width;
-			imgInfo.sya = sy * pagesize.GetHeight()/imgInfo.Height;
+			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;
+			// 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;
 
 			return true;
 		}




More information about the scribus-commit mailing list