summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-07-10 08:57:19 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-07-10 10:44:37 +0200
commit597806350152b746b192a66b4789ca7c8c5377a9 (patch)
treebf74e4fad0a460796a5e4b310e22c2070bb3c036
parentffd41d7ae80079ba53792495720b926599ef37bf (diff)
tdf#161970 sw content controls: fix PDF export for the ExportNotesInMargin case
Have both a content control and a comment in a document, export to PDF while "Comments in margin" is enabled, now the default text of the content control has an incorrect position / size. The transform for normal writer comment was added in commit eb1c0480050a1328287c4a85468afbec50b0e29d (Resolves: fdo#36815 enable printing WYSIWYG sidewindow comments, 2014-04-16), and e.g. the hyperlink rectangles are transformed correctly, but the content control PDF export code added in commit 82d90529dc2b3cb8359dec78852cbd910a66d275 (sw content controls, rich text: add initial PDF export, 2022-09-12) missed this. Fix the problem by extracting the actual transform to a new SwEnhancedPDFExportHelper::MapSwRectToPDFRect() and then using it in both SwEnhancedPDFExportHelper::SwRectToPDFRect() (e.g. hyperlinks) and SwContentControlPortion::DescribePDFControl(). Note that the font size of the PDF widget also needs scaling down, also fix here. Change-Id: I9cccbd569070336e1720ba2a82e91793083722f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170266 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/inc/EnhancedPDFExportHelper.hxx4
-rw-r--r--sw/qa/core/text/itrform2.cxx45
-rw-r--r--sw/source/core/text/EnhancedPDFExportHelper.cxx13
-rw-r--r--sw/source/core/text/itrform2.cxx22
4 files changed, 82 insertions, 2 deletions
diff --git a/sw/inc/EnhancedPDFExportHelper.hxx b/sw/inc/EnhancedPDFExportHelper.hxx
index dd20f54cbef8..450c9c2fe71a 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -247,6 +247,10 @@ class SwEnhancedPDFExportHelper
//scale and position rRectangle if we're scaling due to notes in margins.
tools::Rectangle SwRectToPDFRect(const SwPageFrame* pCurrPage,
const tools::Rectangle& rRectangle) const;
+
+ static tools::Rectangle MapSwRectToPDFRect(const SwPageFrame* pCurrPage,
+ const tools::Rectangle& rRectangle);
+ static double GetSwRectToPDFRectScale();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx
index 5612863a0ddf..00ea3debe556 100644
--- a/sw/qa/core/text/itrform2.cxx
+++ b/sw/qa/core/text/itrform2.cxx
@@ -15,6 +15,8 @@
#include <comphelper/propertyvalue.hxx>
#include <editeng/colritem.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <rootfrm.hxx>
@@ -25,6 +27,8 @@
#include <wrtsh.hxx>
#include <formatcontentcontrol.hxx>
#include <textcontentcontrol.hxx>
+#include <view.hxx>
+#include <cmdid.h>
namespace
{
@@ -314,6 +318,47 @@ CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFDropDownText)
// i.e. only the 3 colors were exported, the default "test" text was not.
CPPUNIT_ASSERT_EQUAL(4, pAnnotation->getOptionCount(pPdfDocument.get()));
}
+
+CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFComments)
+{
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ if (!pPDFium)
+ return;
+
+ // Given a document with both a content control and a comment:
+ createSwDoc();
+ SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+ pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ SwDocShell* pDocShell = getSwDocShell();
+ SwView* pView = pDocShell->GetView();
+ pView->GetViewFrame().GetDispatcher()->Execute(FN_POSTIT, SfxCallMode::SYNCHRON);
+
+ // When exporting to PDF, exporting notes in master (and not as widgets):
+ uno::Sequence<beans::PropertyValue> aFilterData = {
+ comphelper::makePropertyValue(u"ExportNotes"_ustr, false),
+ comphelper::makePropertyValue(u"ExportNotesInMargin"_ustr, true),
+ };
+ saveWithParams({
+ comphelper::makePropertyValue(u"FilterName"_ustr, u"writer_pdf_Export"_ustr),
+ comphelper::makePropertyValue(u"FilterData"_ustr, aFilterData),
+ });
+
+ // Then make sure the only widget for the content control has a correct position:
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0);
+ pPage->onAfterLoadPage(pPdfDocument.get());
+ CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
+ std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0);
+ basegfx::B2DPoint aAnnotTopLeft = pAnnotation->getRectangle().getMinimum();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: (41.749, 639.401)
+ // - Actual : (59.249,716.951)
+ // i.e. the content control rectangle was shifted towards the top right of the page, compared to
+ // where it's expected.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(41.749, aAnnotTopLeft.getX(), 0.001);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(639.401, aAnnotTopLeft.getY(), 0.001);
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 9816adacea7d..46581f3c1c49 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -2102,11 +2102,22 @@ tools::Rectangle SwEnhancedPDFExportHelper::SwRectToPDFRect(const SwPageFrame* p
{
return rRectangle;
}
+ return MapSwRectToPDFRect(pCurrPage, rRectangle);
+}
+
+double SwEnhancedPDFExportHelper::GetSwRectToPDFRectScale()
+{
+ return 0.75;
+}
+
+tools::Rectangle SwEnhancedPDFExportHelper::MapSwRectToPDFRect(const SwPageFrame* pCurrPage,
+ const tools::Rectangle& rRectangle)
+{
//the page has been scaled by 75% and vertically centered, so adjust these
//rectangles equivalently
tools::Rectangle aRect(rRectangle);
Size aRectSize(aRect.GetSize());
- double fScale = 0.75;
+ double fScale = GetSwRectToPDFRectScale();
aRectSize.setWidth( aRectSize.Width() * fScale );
aRectSize.setHeight( aRectSize.Height() * fScale );
tools::Long nOrigHeight = pCurrPage->getFrameArea().Height();
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index bfb7c6ed7a2c..2f0811364665 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -62,6 +62,7 @@
#include <docsh.hxx>
#include <unocrsrhelper.hxx>
#include <textcontentcontrol.hxx>
+#include <EnhancedPDFExportHelper.hxx>
#include <com/sun/star/rdf/Statement.hpp>
#include <com/sun/star/rdf/URI.hpp>
#include <com/sun/star/rdf/URIs.hpp>
@@ -1088,10 +1089,19 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co
return false;
}
+ bool bShrinkPageForPostIts = pPDFExtOutDevData->GetIsExportNotesInMargin()
+ && sw_GetPostIts(rDoc.getIDocumentFieldsAccess(), nullptr);
const SwFont* pFont = rInf.GetFont();
if (pFont)
{
pDescriptor->TextFont = pFont->GetActualFont();
+ if (bShrinkPageForPostIts)
+ {
+ // Page area is scaled down so we have space for comments. Scale down the font height
+ // for the content of the widgets, too.
+ double fScale = SwEnhancedPDFExportHelper::GetSwRectToPDFRectScale();
+ pDescriptor->TextFont.SetFontHeight(pDescriptor->TextFont.GetFontHeight() * fScale);
+ }
// Need to transport the color explicitly, so it's applied to both already filled in and
// future content.
@@ -1135,7 +1145,17 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co
aLocation.AddLeft(-20);
aLocation.AddRight(20);
- pDescriptor->Location = aLocation.SVRect();
+ tools::Rectangle aRect = aLocation.SVRect();
+ if (bShrinkPageForPostIts)
+ {
+ // Map the rectangle of the form widget, similar to how it's done for e.g. hyperlinks.
+ const SwPageFrame* pPageFrame = pTextFrame->FindPageFrame();
+ if (pPageFrame)
+ {
+ aRect = SwEnhancedPDFExportHelper::MapSwRectToPDFRect(pPageFrame, aRect);
+ }
+ }
+ pDescriptor->Location = aRect;
pPDFExtOutDevData->WrapBeginStructureElement(vcl::PDFWriter::Form);
pPDFExtOutDevData->CreateControl(*pDescriptor);