external/pdfium/UnpackedTarball_pdfium.mk | 2 + external/pdfium/annot.patch.1 | 45 ++++++++++++++++++++++++++++++ include/vcl/filter/PDFiumLibrary.hxx | 1 sw/qa/core/text/text.cxx | 27 ++++++++++++++++++ sw/source/core/text/itrform2.cxx | 6 ++++ vcl/source/pdf/PDFiumLibrary.cxx | 13 ++++++++ 6 files changed, 94 insertions(+)
New commits: commit 9550cd1fb7d88e5f66c2248d1f696a5623523dcb Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Sep 16 08:20:56 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Sep 19 08:44:46 2022 +0200 sw content controls: add PDF export of font properties Like font name or size. (cherry picked from commit 493b10997053882d06803156a98ae8924bf7660d) Change-Id: Ie7b0d38be0ef69faf364b7c801d0bd3fdd60777a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140075 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk index c1791ed8e823..272fa5cb606f 100644 --- a/external/pdfium/UnpackedTarball_pdfium.mk +++ b/external/pdfium/UnpackedTarball_pdfium.mk @@ -28,6 +28,8 @@ pdfium_patches += include.patch pdfium_patches += abseil-trivial.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..542cb9766ff7 --- /dev/null +++ b/external/pdfium/annot.patch.1 @@ -0,0 +1,45 @@ +diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp +index 349348583..54e139645 100644 +--- a/fpdfsdk/fpdf_annot.cpp ++++ b/fpdfsdk/fpdf_annot.cpp +@@ -1223,6 +1223,26 @@ FPDFAnnot_GetFormFieldType(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { + return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1; + } + ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFAnnot_GetFormFontSize(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, float* value) { ++ const CPDF_FormField* pFormField = GetFormField(hHandle, annot); ++ if (!pFormField) { ++ return false; ++ } ++ ++ if (!value) { ++ return false; ++ } ++ ++ ByteString DA; ++ if (const CPDF_Object* pObj = pFormField->GetFieldAttr(pFormField->GetDict(), "DA")) ++ DA = pObj->GetString(); ++ ++ CPDF_DefaultAppearance appearance(DA); ++ appearance.GetFont(value); ++ return true; ++} ++ + FPDF_EXPORT unsigned long FPDF_CALLCONV + FPDFAnnot_GetFormFieldValue(FPDF_FORMHANDLE hHandle, + FPDF_ANNOTATION annot, +diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h +index ccfbb0f1c..3c96b99a0 100644 +--- a/public/fpdf_annot.h ++++ b/public/fpdf_annot.h +@@ -699,6 +699,9 @@ FPDFAnnot_GetFormFieldName(FPDF_FORMHANDLE hHandle, + FPDF_EXPORT int FPDF_CALLCONV + FPDFAnnot_GetFormFieldType(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot); + ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFAnnot_GetFormFontSize(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, float* value); ++ + // Experimental API. + // Gets the value of |annot|, which is an interactive form annotation. + // |buffer| is only modified if |buflen| is longer than the length of contents. diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 8274ded92e1f..390c826cd57b 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -102,6 +102,7 @@ public: virtual std::vector<basegfx::B2DPoint> getAttachmentPoints(size_t nIndex) = 0; virtual std::vector<basegfx::B2DPoint> getLineGeometry() = 0; virtual PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) = 0; + virtual float getFormFontSize(PDFiumDocument* pDoc) = 0; }; class PDFiumTextPage; diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index d173b1b00a98..8813ebf8879a 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -18,6 +18,7 @@ #include <vcl/filter/PDFiumLibrary.hxx> #include <comphelper/propertyvalue.hxx> #include <unotools/mediadescriptor.hxx> +#include <editeng/fhgtitem.hxx> #include <docsh.hxx> #include <unotxdoc.hxx> @@ -622,6 +623,32 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDateContentControlPDF) pAnnotation->getFormFieldType(pPdfDocument.get())); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDFFont) +{ + // Given a document with a custom 24pt font size and a content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SfxItemSetFixed<RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE> aSet(pWrtShell->GetAttrPool()); + SvxFontHeightItem aItem(480, 100, RES_CHRATR_FONTSIZE); + aSet.Put(aItem); + pWrtShell->SetAttrSet(aSet); + pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT); + + // When exporting that document to PDF: + StoreToTempFile("writer_pdf_Export"); + + // Then make sure that the widget in the PDF result has that custom font size: + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); + 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: 24 + // - Actual : 8 + // i.e. i.e. the font size was some default, not the 24pt specified in the model. + CPPUNIT_ASSERT_EQUAL(24.0f, pAnnotation->getFormFontSize(pPdfDocument.get())); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index a90ccf6451c5..c50560eef5c5 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -972,6 +972,12 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co return false; } + const SwFont* pFont = rInf.GetFont(); + if (pFont) + { + pDescriptor->TextFont = pFont->GetActualFont(); + } + SwRect aLocation; rInf.CalcRect(*this, &aLocation); pDescriptor->Location = aLocation.SVRect(); diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 1180410521f7..da7a9141e322 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -249,6 +249,7 @@ public: std::vector<basegfx::B2DPoint> getAttachmentPoints(size_t nIndex) override; std::vector<basegfx::B2DPoint> getLineGeometry() override; PDFFormFieldType getFormFieldType(PDFiumDocument* pDoc) override; + float getFormFontSize(PDFiumDocument* pDoc) override; }; class PDFiumPageObjectImpl final : public PDFiumPageObject @@ -1134,6 +1135,18 @@ PDFFormFieldType PDFiumAnnotationImpl::getFormFieldType(PDFiumDocument* pDoc) FPDFAnnot_GetFormFieldType(pDocImpl->getFormHandlePointer(), mpAnnotation)); } +float PDFiumAnnotationImpl::getFormFontSize(PDFiumDocument* pDoc) +{ + auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); + float fRet{}; + if (!FPDFAnnot_GetFormFontSize(pDocImpl->getFormHandlePointer(), mpAnnotation, &fRet)) + { + return 0.0f; + } + + return fRet; +} + namespace { bool getBorderProperties(FPDF_ANNOTATION mpAnnotation, float& rHorizontalCornerRadius,