sw/CppunitTest_sw_core_accessibilitycheck.mk | 1 sw/CppunitTest_sw_uibase_dochdl.mk | 1 sw/CppunitTest_sw_uibase_frmdlg.mk | 1 sw/CppunitTest_sw_uibase_shells.mk | 1 sw/CppunitTest_sw_uibase_uno.mk | 1 sw/qa/core/text/text.cxx | 65 ++++++++++++--------------- sw/qa/inc/swmodeltestbase.hxx | 11 ++++ sw/qa/unit/swmodeltestbase.cxx | 13 +++++ sw/source/core/text/itrform2.cxx | 11 ++++ 9 files changed, 69 insertions(+), 36 deletions(-)
New commits: commit 951ae770688ae988e5a889d97f6ec75ab21a1f8e Author: Miklos Vajna <[email protected]> AuthorDate: Thu Sep 15 08:36:27 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Sep 16 08:23:29 2022 +0200 sw content controls, date: add PDF export Map it to /FT/Tx, and set the additional actions so it appears like a date picker. Also extract a SwModelTestBase::LoadPdfFromTempFile() to avoid copy&paste. (cherry picked from commit f7408cf0e472be91bdb7a4d2a4b8da3eb9a049a9) Conflicts: sw/CppunitTest_sw_core_view.mk sw/CppunitTest_sw_uibase_docvw.mk sw/qa/inc/swmodeltestbase.hxx Change-Id: I062481cc557d8222953987355c7b08cb92efda51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140019 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sw/CppunitTest_sw_core_accessibilitycheck.mk b/sw/CppunitTest_sw_core_accessibilitycheck.mk index 0d102842a6e1..1780c7c4bfc9 100644 --- a/sw/CppunitTest_sw_core_accessibilitycheck.mk +++ b/sw/CppunitTest_sw_core_accessibilitycheck.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_accessibilitycheck, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_core_accessibilitycheck,\ diff --git a/sw/CppunitTest_sw_uibase_dochdl.mk b/sw/CppunitTest_sw_uibase_dochdl.mk index 36494c0e7a8c..f605226206bb 100644 --- a/sw/CppunitTest_sw_uibase_dochdl.mk +++ b/sw/CppunitTest_sw_uibase_dochdl.mk @@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_dochdl, \ unotest \ utl \ vcl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_uibase_dochdl,\ diff --git a/sw/CppunitTest_sw_uibase_frmdlg.mk b/sw/CppunitTest_sw_uibase_frmdlg.mk index 5225def8fc2f..aea77b87d33d 100644 --- a/sw/CppunitTest_sw_uibase_frmdlg.mk +++ b/sw/CppunitTest_sw_uibase_frmdlg.mk @@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_frmdlg, \ unotest \ utl \ vcl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_uibase_frmdlg,\ diff --git a/sw/CppunitTest_sw_uibase_shells.mk b/sw/CppunitTest_sw_uibase_shells.mk index 44901cc56d85..a3d880458663 100644 --- a/sw/CppunitTest_sw_uibase_shells.mk +++ b/sw/CppunitTest_sw_uibase_shells.mk @@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_shells, \ unotest \ utl \ vcl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_uibase_shells,\ diff --git a/sw/CppunitTest_sw_uibase_uno.mk b/sw/CppunitTest_sw_uibase_uno.mk index 36c54d04db33..d6e43918e4a4 100644 --- a/sw/CppunitTest_sw_uibase_uno.mk +++ b/sw/CppunitTest_sw_uibase_uno.mk @@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_uno, \ unotest \ utl \ vcl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sw_uibase_uno,\ diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 9e0d3cc81579..d173b1b00a98 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -119,12 +119,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport) StoreToTempFile("writer_pdf_Export"); // Then make sure the field links the source. - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); // Without the accompanying fix in place, this test would have failed, the field was not // clickable (while it was clickable on the UI). @@ -543,16 +538,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) StoreToTempFile("writer_pdf_Export"); // Then make sure that a fillable form widget is emitted: - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - { - return; - } - std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -572,16 +558,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF) StoreToTempFile("writer_pdf_Export"); // Then make sure that a checkbox form widget is emitted: - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - { - return; - } - std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -606,16 +583,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF) StoreToTempFile("writer_pdf_Export"); // Then make sure that a dropdown form widget is emitted: - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - { - return; - } - std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -629,6 +597,31 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF) pAnnotation->getFormFieldType(pPdfDocument.get())); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDateContentControlPDF) +{ + // Given a file with a date content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DATE); + + // When exporting to PDF: + StoreToTempFile("writer_pdf_Export"); + + // Then make sure that a date form widget is emitted: + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the date content control was just exported as normal text. + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); + std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Widget, pAnnotation->getSubType()); + // Also check the form widget type (our date is a mode of text in PDF terms): + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::TextField, + pAnnotation->getFormFieldType(pPdfDocument.get())); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx index 75bee223fbd2..f3ae9688c64a 100644 --- a/sw/qa/inc/swmodeltestbase.hxx +++ b/sw/qa/inc/swmodeltestbase.hxx @@ -102,6 +102,14 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ void TestName::verify() +namespace vcl +{ +namespace pdf +{ +class PDFiumDocument; +} +} + /// Base class for filter tests loading or roundtripping a document, then asserting the document model. class SWQAHELPER_DLLPUBLIC SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools { @@ -121,6 +129,7 @@ protected: sal_uInt32 mnStartTime; utl::TempFile maTempFile; + SvMemoryStream maMemory; ///< Underlying memory for parsed PDF files. bool mbExported; ///< Does maTempFile already contain something useful? protected: @@ -403,6 +412,8 @@ protected: std::u16string_view rDataDirectory = std::u16string_view(), const char* pName = nullptr); void StoreToTempFile(const OUString& rFilterName); + + std::unique_ptr<vcl::pdf::PDFiumDocument> LoadPdfFromTempFile(); }; /** diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index cc8edcb2a213..4926d4bcd639 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -26,6 +26,7 @@ #include <unotools/mediadescriptor.hxx> #include <unotools/streamwrap.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <vcl/filter/PDFiumLibrary.hxx> #include <IDocumentLayoutAccess.hxx> #include <docsh.hxx> @@ -774,4 +775,16 @@ void SwModelTestBase::StoreToTempFile(const OUString& rFilterName) xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); } +std::unique_ptr<vcl::pdf::PDFiumDocument> SwModelTestBase::LoadPdfFromTempFile() +{ + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + maMemory.WriteStream(aFile); + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return nullptr; + } + return pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize(), OString()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 6db3fe4a39c8..a90ccf6451c5 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -952,6 +952,17 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co } break; } + case SwContentControlType::DATE: + { + pDescriptor = std::make_unique<vcl::PDFWriter::EditWidget>(); + auto pEditWidget = static_cast<vcl::PDFWriter::EditWidget*>(pDescriptor.get()); + pEditWidget->Format = vcl::PDFWriter::Date; + // GetDateFormat() uses a syntax that works with SvNumberFormatter::PutEntry(), PDF's + // AFDate_FormatEx() uses a similar syntax, but uses lowercase characters in case of + // "Y", "M" and "D" at least. + pEditWidget->DateFormat = pContentControl->GetDateFormat().toAsciiLowerCase(); + break; + } default: break; }
