summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-06-21 08:32:05 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-06-21 13:38:25 +0200
commit38e3a4da66e0c3eaa5fd2e593131aa92a05548c3 (patch)
tree160b42cb55ba9fa8a03aa20e6938908ddfa0433e /sw
parent4ab9fea75f552dcaa52e1c25d2bc841e965e0b4e (diff)
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 <vmiklos@collabora.com> (cherry picked from commit 0f165b7f2f03d806eb14ba7529223d31e30674a8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169295
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/text/itrform2.cxx34
-rw-r--r--sw/source/core/text/itrform2.cxx4
2 files changed, 38 insertions, 0 deletions
diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx
index f4186a63e7e1..8753a797e9f8 100644
--- a/sw/qa/core/text/itrform2.cxx
+++ b/sw/qa/core/text/itrform2.cxx
@@ -11,6 +11,8 @@
#include <memory>
+#include <editeng/colritem.hxx>
+
#include <IDocumentLayoutAccess.hxx>
#include <rootfrm.hxx>
#include <sortedobjs.hxx>
@@ -224,6 +226,38 @@ CPPUNIT_TEST_FIXTURE(Test, testCheckedCheckboxContentControlPDF)
// would match /V, leading to not showing the checked state.
CPPUNIT_ASSERT_EQUAL(u"Yes"_ustr, aActual);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testContentControlPDFFontColor)
+{
+ std::shared_ptr<vcl::pdf::PDFium> 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<RES_CHRATR_COLOR, RES_CHRATR_COLOR> 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<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);
+ // 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 430e8d9aa778..621294528767 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1081,6 +1081,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.