diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-17 13:51:31 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-17 15:24:57 +0200 |
commit | d7d43cf460d66354a40ffa3b34c0f9efcd42d0be (patch) | |
tree | 82ddf81c36fd7801f06e87d0ff208891ca6dea42 /vcl/source/gdi/pdfwriter_impl.cxx | |
parent | 6aec5d5a3a26bd973e46b6c593373e2f03f51a37 (diff) |
vcl PDF export: fix re-exporting PDF images with arbitrary page-level rotation
Building on top of commit bd520b177637d4b7d9d93733103cff17a3c91b0a (vcl
PDF export: fix re-exporting PDF images with page-level rotation,
2019-11-06), this was already working for 90 degrees, now generalize
this to work with 180 degrees as well.
Change-Id: I5a5d51662399814d5554d7c2cb86a6c9a2974012
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115705
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/source/gdi/pdfwriter_impl.cxx')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 564e35dee051..3fa3a10d31a0 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -8514,29 +8514,40 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit) tools::Long nWidth = aSize.Width(); tools::Long nHeight = aSize.Height(); + basegfx::B2DRange aBBox(0, 0, aSize.Width(), 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(" ] "); - } + sal_Int32 nRotAngle = static_cast<sal_Int32>(pRotate->GetValue()) % 360; + // /Rotate is clockwise, matrix rotate is counter-clockwise. + sal_Int32 nAngle = -1 * nRotAngle; + + // The bounding box just rotates. + basegfx::B2DHomMatrix aBBoxMat; + aBBoxMat.rotate(basegfx::deg2rad(pRotate->GetValue())); + aBBox.transform(aBBoxMat); + + // Now transform the object: rotate around the center and make sure that the rotation + // doesn't affect the aspect ratio. + basegfx::B2DHomMatrix aMat; + aMat.translate(-0.5 * aBBox.getWidth(), -0.5 * aBBox.getHeight()); + aMat.rotate(basegfx::deg2rad(nAngle)); + aMat.translate(0.5 * nWidth, 0.5 * nHeight); + + aLine.append(" /Matrix [ "); + aLine.append(aMat.a()); + aLine.append(" "); + aLine.append(aMat.b()); + aLine.append(" "); + aLine.append(aMat.c()); + aLine.append(" "); + aLine.append(aMat.d()); + aLine.append(" "); + aLine.append(aMat.e()); + aLine.append(" "); + aLine.append(aMat.f()); + aLine.append(" ] "); } PDFObjectCopier aCopier(*this); @@ -8544,9 +8555,9 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit) aCopier.copyPageResources(pPage, aLine, rResources); aLine.append(" /BBox [ 0 0 "); - aLine.append(nWidth); + aLine.append(aBBox.getWidth()); aLine.append(" "); - aLine.append(nHeight); + aLine.append(aBBox.getHeight()); aLine.append(" ]"); if (!g_bDebugDisableCompression) |