From 04013dbc77095eb140743e82c4f0e3fae83a02cb Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 21 Jun 2024 08:32:05 +0200 Subject: tdf#161708 sw content controls: handle font color when exporting to PDF form Export the bugdoc to PDF, the orange "date" lost its font color. This went wrong in commit 82d90529dc2b3cb8359dec78852cbd910a66d275 (sw content controls, rich text: add initial PDF export, 2022-09-12), we export the content control as a PDF form widget by default since then. Various properties like checkbox status and dropdown items were handled already, but not text color. Fix the problem by mapping the SwFont color to the widget descriptor color, this fixes the color of the already filled in content of the widget. Note that given this is a property of the form widget, the color is correctly applied also to strings filled in via PDF readers, interacting with the form. Change-Id: Id3e8611e415c0d571afe1cd14561c97b8a910ce9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169317 Tested-by: Jenkins Reviewed-by: Miklos Vajna (cherry picked from commit 0f165b7f2f03d806eb14ba7529223d31e30674a8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169295 Signed-off-by: Xisco Fauli Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169472 --- sw/qa/core/text/itrform2.cxx | 34 ++++++++++++++++++++++++++++++++++ sw/source/core/text/itrform2.cxx | 4 ++++ 2 files changed, 38 insertions(+) (limited to 'sw') diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx index 860b2197f761..930be1b031f4 100644 --- a/sw/qa/core/text/itrform2.cxx +++ b/sw/qa/core/text/itrform2.cxx @@ -11,6 +11,8 @@ #include +#include + #include #include #include @@ -224,6 +226,38 @@ CPPUNIT_TEST_FIXTURE(Test, testCheckedCheckboxContentControlPDF) // would match /V, leading to not showing the checked state. CPPUNIT_ASSERT_EQUAL(OUString("Yes"), aActual); } + +CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFFontColor) +{ + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + return; + + // Given a document with a custom orange font color and a content control: + createSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + SfxItemSetFixed aSet(pWrtShell->GetAttrPool()); + Color nOrange(0xff6b00); + SvxColorItem aItem(nOrange, RES_CHRATR_COLOR); + aSet.Put(aItem); + pWrtShell->SetAttrSet(aSet); + pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT); + + // When exporting that document to PDF: + save(u"writer_pdf_Export"_ustr); + + // Then make sure that the widget in the PDF result has that custom font color: + std::unique_ptr pPdfDocument = parsePDFExport(); + std::unique_ptr pPage = pPdfDocument->openPage(0); + pPage->onAfterLoadPage(pPdfDocument.get()); + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); + std::unique_ptr pAnnotation = pPage->getAnnotation(0); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: rgba[ff6b00ff] + // - Actual : rgba[000000ff] + // i.e. the custom color was lost, the font color was black, not orange. + CPPUNIT_ASSERT_EQUAL(nOrange, pAnnotation->getFontColor(pPdfDocument.get())); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index dad32bf4fcac..c3c1c770c031 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1083,6 +1083,10 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co if (pFont) { pDescriptor->TextFont = pFont->GetActualFont(); + + // Need to transport the color explicitly, so it's applied to both already filled in and + // future content. + pDescriptor->TextColor = pFont->GetColor(); } // Description for accessibility purposes. -- cgit v1.2.3