diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-11-06 16:48:55 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-11-06 17:56:59 +0100 |
commit | bd520b177637d4b7d9d93733103cff17a3c91b0a (patch) | |
tree | 9111fcadfebcf18bfed89a3f6397300cf4089589 /vcl/source | |
parent | 032b6698c11f6b6e67fa3a12c2d34f1f7afe63f6 (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.
Change-Id: I55a4f63e0b986637ccdeba0b783f1db9a85c4d93
Reviewed-on: https://gerrit.libreoffice.org/82154
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index faabdd8769f9..a63a2152e6b7 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -8842,6 +8842,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 = { @@ -8855,9 +8883,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) |