diff options
-rw-r--r-- | external/pdfium/UnpackedTarball_pdfium.mk | 2 | ||||
-rw-r--r-- | external/pdfium/annot.patch.1 | 65 | ||||
-rw-r--r-- | include/vcl/filter/PDFiumLibrary.hxx | 1 | ||||
-rw-r--r-- | sw/qa/core/text/itrform2.cxx | 34 | ||||
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 4 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 13 |
6 files changed, 119 insertions, 0 deletions
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk index 924bbe23a8b8..73f8c2f528f4 100644 --- a/external/pdfium/UnpackedTarball_pdfium.mk +++ b/external/pdfium/UnpackedTarball_pdfium.mk @@ -16,6 +16,8 @@ pdfium_patches += c++20-comparison.patch pdfium_patches += constexpr-template.patch +pdfium_patches += annot.patch.1 + $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium)) $(eval $(call gb_UnpackedTarball_set_tarball,pdfium,$(PDFIUM_TARBALL))) diff --git a/external/pdfium/annot.patch.1 b/external/pdfium/annot.patch.1 new file mode 100644 index 000000000000..330685962b4e --- /dev/null +++ b/external/pdfium/annot.patch.1 @@ -0,0 +1,65 @@ +diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp +index bc1f7f7eb..075baf1df 100644 +--- a/fpdfsdk/fpdf_annot.cpp ++++ b/fpdfsdk/fpdf_annot.cpp +@@ -1366,6 +1366,42 @@ FPDFAnnot_GetFontSize(FPDF_FORMHANDLE hHandle, + return true; + } + ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFAnnot_GetFontColor(FPDF_FORMHANDLE hHandle, ++ FPDF_ANNOTATION annot, ++ unsigned int* R, ++ unsigned int* G, ++ unsigned int* B) { ++ if (!R || !G || !B) ++ return false; ++ ++ CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); ++ if (!pForm) ++ return false; ++ ++ const CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); ++ if (!pAnnotDict) ++ return false; ++ ++ CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); ++ CPDF_FormControl* pFormControl = pPDFForm->GetControlByDict(pAnnotDict); ++ if (!pFormControl) ++ return false; ++ ++ CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); ++ if (!pWidget) ++ return false; ++ ++ std::optional<FX_COLORREF> text_color = pWidget->GetTextColor(); ++ if (!text_color) ++ return false; ++ ++ *R = FXSYS_GetRValue(*text_color); ++ *G = FXSYS_GetGValue(*text_color); ++ *B = FXSYS_GetBValue(*text_color); ++ return true; ++} ++ + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_IsChecked(FPDF_FORMHANDLE hHandle, + FPDF_ANNOTATION annot) { + const CPDFSDK_Widget* pWidget = +diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h +index 337da58f1..27de4b1a8 100644 +--- a/public/fpdf_annot.h ++++ b/public/fpdf_annot.h +@@ -845,6 +845,13 @@ FPDFAnnot_GetFontSize(FPDF_FORMHANDLE hHandle, + FPDF_ANNOTATION annot, + float* value); + ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFAnnot_GetFontColor(FPDF_FORMHANDLE hHandle, ++ FPDF_ANNOTATION annot, ++ unsigned int* R, ++ unsigned int* G, ++ unsigned int* B); ++ + // Experimental API. + // Determine if |annot| is a form widget that is checked. Intended for use with + // checkbox and radio button widgets. diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 3c087cf7b11c..557eaff349f7 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -105,6 +105,7 @@ public: virtual std::vector<basegfx::B2DPoint> getLineGeometry() = 0; virtual PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) = 0; virtual float getFontSize(PDFiumDocument* pDoc) = 0; + virtual Color getFontColor(PDFiumDocument* pDoc) = 0; virtual OUString getFormFieldAlternateName(PDFiumDocument* pDoc) = 0; virtual int getFormFieldFlags(PDFiumDocument* pDoc) = 0; virtual OUString getFormAdditionalActionJavaScript(PDFiumDocument* pDoc, 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. diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 553be738c8f5..4a8a40fb6764 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -264,6 +264,7 @@ public: std::vector<basegfx::B2DPoint> getLineGeometry() override; PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) override; float getFontSize(PDFiumDocument* pDoc) override; + Color getFontColor(PDFiumDocument* pDoc) override; OUString getFormFieldAlternateName(PDFiumDocument* pDoc) override; int getFormFieldFlags(PDFiumDocument* pDoc) override; OUString getFormAdditionalActionJavaScript(PDFiumDocument* pDoc, @@ -1216,6 +1217,18 @@ float PDFiumAnnotationImpl::getFontSize(PDFiumDocument* pDoc) return fRet; } +Color PDFiumAnnotationImpl::getFontColor(PDFiumDocument* pDoc) +{ + auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); + unsigned int nR, nG, nB; + if (!FPDFAnnot_GetFontColor(pDocImpl->getFormHandlePointer(), mpAnnotation, &nR, &nG, &nB)) + { + return Color(); + } + + return Color(nR, nG, nB); +} + OUString PDFiumAnnotationImpl::getFormFieldAlternateName(PDFiumDocument* pDoc) { auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); |