include/vcl/filter/PDFiumLibrary.hxx | 4 ++ include/vcl/pdf/PDFAnnotAActionType.hxx | 25 +++++++++++++++++ sw/qa/core/text/text.cxx | 3 ++ vcl/source/pdf/PDFiumLibrary.cxx | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+)
New commits: commit cd8e8685454c92c38f17ddcf8b4f49b9068635ec Author: Miklos Vajna <[email protected]> AuthorDate: Tue Nov 15 20:08:27 2022 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Nov 16 08:07:31 2022 +0100 sw content controls, date: improve PDF export test Assert not only that the widget is a text one, but also that it has the correct date format. Change-Id: If2bb8dcdfca0a8b76b5ed179ff558d351137bc06 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142747 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index f0a642847cc6..7b319a727259 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -34,6 +34,7 @@ #include <vcl/pdf/PDFFindFlags.hxx> #include <vcl/pdf/PDFErrorType.hxx> #include <vcl/pdf/PDFFormFieldType.hxx> +#include <vcl/pdf/PDFAnnotAActionType.hxx> class SvMemoryStream; @@ -105,6 +106,9 @@ public: virtual float getFontSize(PDFiumDocument* pDoc) = 0; virtual OUString getFormFieldAlternateName(PDFiumDocument* pDoc) = 0; virtual int getFormFieldFlags(PDFiumDocument* pDoc) = 0; + virtual OUString getFormAdditionalActionJavaScript(PDFiumDocument* pDoc, + PDFAnnotAActionType eEvent) + = 0; }; class PDFiumTextPage; diff --git a/include/vcl/pdf/PDFAnnotAActionType.hxx b/include/vcl/pdf/PDFAnnotAActionType.hxx new file mode 100644 index 000000000000..099dcda813c5 --- /dev/null +++ b/include/vcl/pdf/PDFAnnotAActionType.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +namespace vcl::pdf +{ +enum class PDFAnnotAActionType +{ + KeyStroke = 12, + Format = 13, + Validate = 14, + Calculate = 15, +}; + +} // namespace vcl::pdf + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 382f9a8738a4..9125cf256a4b 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -750,6 +750,9 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDateContentControlPDF) // Also check the form widget type (our date is a mode of text in PDF terms): CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFFormFieldType::TextField, pAnnotation->getFormFieldType(pPdfDocument.get())); + OUString aAction = pAnnotation->getFormAdditionalActionJavaScript( + pPdfDocument.get(), vcl::pdf::PDFAnnotAActionType::KeyStroke); + CPPUNIT_ASSERT_EQUAL(OUString("AFDate_KeystrokeEx(\"mm/dd/yy\");"), aAction); } CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDFFont) diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 3e247b7772eb..ad2f3332bea9 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -155,6 +155,18 @@ static_assert(static_cast<int>(vcl::pdf::PDFFormFieldType::TextField) == FPDF_FO static_assert(static_cast<int>(vcl::pdf::PDFFormFieldType::Signature) == FPDF_FORMFIELD_SIGNATURE, "PDFFormFieldType::Signature value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFAnnotAActionType::KeyStroke) + == FPDF_ANNOT_AACTION_KEY_STROKE, + "PDFAnnotAActionType::KeyStroke) value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFAnnotAActionType::Format) == FPDF_ANNOT_AACTION_FORMAT, + "PDFAnnotAActionType::Format) value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFAnnotAActionType::Validate) + == FPDF_ANNOT_AACTION_VALIDATE, + "PDFAnnotAActionType::Validate) value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFAnnotAActionType::Calculate) + == FPDF_ANNOT_AACTION_CALCULATE, + "PDFAnnotAActionType::Calculate) value mismatch"); + namespace { /// Callback class to be used with FPDF_SaveWithVersion(). @@ -253,6 +265,8 @@ public: float getFontSize(PDFiumDocument* pDoc) override; OUString getFormFieldAlternateName(PDFiumDocument* pDoc) override; int getFormFieldFlags(PDFiumDocument* pDoc) override; + OUString getFormAdditionalActionJavaScript(PDFiumDocument* pDoc, + PDFAnnotAActionType eEvent) override; }; class PDFiumPageObjectImpl final : public PDFiumPageObject @@ -1194,6 +1208,37 @@ OUString PDFiumAnnotationImpl::getFormFieldAlternateName(PDFiumDocument* pDoc) return aString; } +OUString PDFiumAnnotationImpl::getFormAdditionalActionJavaScript(PDFiumDocument* pDoc, + PDFAnnotAActionType eEvent) +{ + auto pDocImpl = static_cast<PDFiumDocumentImpl*>(pDoc); + OUString aString; + unsigned long nSize = FPDFAnnot_GetFormAdditionalActionJavaScript( + pDocImpl->getFormHandlePointer(), mpAnnotation, static_cast<int>(eEvent), nullptr, 0); + assert(nSize % 2 == 0); + nSize /= 2; + if (nSize > 1) + { + std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nSize]); + unsigned long nStringSize = FPDFAnnot_GetFormAdditionalActionJavaScript( + pDocImpl->getFormHandlePointer(), mpAnnotation, static_cast<int>(eEvent), + reinterpret_cast<FPDF_WCHAR*>(pText.get()), nSize * 2); + assert(nStringSize % 2 == 0); + nStringSize /= 2; + if (nStringSize > 0) + { +#if defined OSL_BIGENDIAN + for (unsigned long i = 0; i != nStringSize; ++i) + { + pText[i] = OSL_SWAPWORD(pText[i]); + } +#endif + aString = OUString(pText.get()); + } + } + return aString; +} + namespace { bool getBorderProperties(FPDF_ANNOTATION mpAnnotation, float& rHorizontalCornerRadius,
