summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-10-24 23:20:30 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-10-25 15:54:59 +0200
commit9299afbbd6bd264ba90e5e0ac21a700e88f56c0f (patch)
tree919e60346cb91ffaefccc0e3d4850695e2179352 /sw/qa
parentec54e7330ad3bbada1bfabd58a3fe66cef69a0ce (diff)
Export text placeholder fields as PDF form fields
Inspired by commit 82d90529dc2b3cb8359dec78852cbd910a66d275 (sw content controls, rich text: add initial PDF export, 2022-09-12). Change-Id: I16cc45b6f2e070ab9dc83ba15e3c66ca0caa5e53 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158407 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/core/text/data/placeholder.fodt9
-rw-r--r--sw/qa/core/text/text.cxx28
2 files changed, 37 insertions, 0 deletions
diff --git a/sw/qa/core/text/data/placeholder.fodt b/sw/qa/core/text/data/placeholder.fodt
new file mode 100644
index 000000000000..01cb60437618
--- /dev/null
+++ b/sw/qa/core/text/data/placeholder.fodt
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p><text:placeholder text:placeholder-type="text" text:description="reference text">&lt;placeholder text&gt;</text:placeholder></text:p>
+ </office:text>
+ </office:body>
+</office:document> \ No newline at end of file
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 8a48b75a03e4..496c14006539 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -1174,6 +1174,34 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF)
CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
}
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testPlaceholderFieldPDF)
+{
+ std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+ if (!pPDFium)
+ return;
+
+ // Given a file with a text-type placeholder field:
+ createSwDoc("placeholder.fodt");
+
+ // When exporting to PDF (default setting is "create a PDF form"):
+ save("writer_pdf_Export");
+
+ // Then make sure that a fillable form widget is emitted:
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
+ 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 placeholder field 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 verify that the widget description is correct:
+ CPPUNIT_ASSERT_EQUAL(OUString("reference text"),
+ pAnnotation->getFormFieldAlternateName(pPdfDocument.get()));
+}
+
CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testNumberPortionFormat)
{
// Given a document with a single paragraph, direct formatting asks 24pt font size for the