summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-11-06 16:48:55 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-11-08 14:14:32 +0100
commitcc7b53d569be3d280b414c94ca7ce2e801eb40a0 (patch)
tree445eec69346edcf0a431293ffb23427bea922fef
parentb6b7e7b54be0b7d48a12ddd7914f807fc7021c43 (diff)
vcl PDF export: fix re-exporting PDF images with page-level rotation
PDF images are effectively 1 page PDF documents. The page object may have a /Rotate key, which was simply ignored before. We turn page objects into form XObjects on PDF export, such rotation can be expressed with a /Matrix key. Add support for the 90 degrees rotation case, this can be generalized later if wanted. (cherry picked from commit bd520b177637d4b7d9d93733103cff17a3c91b0a) Conflicts: vcl/qa/cppunit/pdfexport/data/pdf-image-resource-inline-xobject-ref.pdf vcl/qa/cppunit/pdfexport/pdfexport.cxx Change-Id: I55a4f63e0b986637ccdeba0b783f1db9a85c4d93
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx32
1 files changed, 30 insertions, 2 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 43e97145ad77..7a341f8d10b2 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -11176,6 +11176,34 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
aLine.append(" 0 obj\n");
aLine.append("<< /Type /XObject");
aLine.append(" /Subtype /Form");
+
+ long nWidth = aSize.Width();
+ long nHeight = aSize.Height();
+ if (auto pRotate = dynamic_cast<filter::PDFNumberElement*>(pPage->Lookup("Rotate")))
+ {
+ // The original page was rotated, then construct a transformation matrix which does the
+ // same with our form object.
+ if (rtl::math::approxEqual(pRotate->GetValue(), 90))
+ {
+ std::swap(nWidth, nHeight);
+ basegfx::B2DHomMatrix aMat;
+ aMat.rotate(basegfx::deg2rad(pRotate->GetValue()));
+ // Rotate around the origo (bottom left corner) counter-clockwise, then translate
+ // horizontally to effectively keep the bottom left corner unchanged.
+ aLine.append(" /Matrix [ ");
+ aLine.append(aMat.get(0, 0));
+ aLine.append(" ");
+ aLine.append(aMat.get(0, 1));
+ aLine.append(" ");
+ aLine.append(aMat.get(1, 0));
+ aLine.append(" ");
+ aLine.append(aMat.get(1, 1));
+ aLine.append(" 0 ");
+ aLine.append(nWidth);
+ aLine.append(" ] ");
+ }
+ }
+
aLine.append(" /Resources <<");
static const std::initializer_list<OString> aKeys =
{
@@ -11189,9 +11217,9 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
aLine.append(copyExternalResources(*pPage, rKey, aCopiedResources));
aLine.append(">>");
aLine.append(" /BBox [ 0 0 ");
- aLine.append(aSize.Width());
+ aLine.append(nWidth);
aLine.append(" ");
- aLine.append(aSize.Height());
+ aLine.append(nHeight);
aLine.append(" ]");
if (!g_bDebugDisableCompression)