summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-06-21 08:32:05 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2024-06-27 16:38:30 +0200
commit04013dbc77095eb140743e82c4f0e3fae83a02cb (patch)
treef28891b1de538a144804ae56354bbfd26463c52b /sw
parentb72c54b1441487e3a7190aec0b38da53bf6ad9d2 (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 Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169472
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 860b2197f761..930be1b031f4 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(OUString("Yes"), 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 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.