toolkit/source/helper/formpdfexport.cxx     |    8 ++++++
 vcl/qa/cppunit/pdfexport/data/tdf148706.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   37 ++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

New commits:
commit 5b58b8a4c3d6473deb91ed8cb1a33f87ba4d5de9
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu May 12 16:37:19 2022 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Sun Jun 26 22:13:24 2022 +0200

    tdf#148706: map value prop in numericfield to text
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134240
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 3bd7111fe29ce19a007915af87f1f9269d27d9ff)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134183
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    
    Change-Id: Ifc37b0aa8dc657d7a7f05199c8132896d03eb437
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136364
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/toolkit/source/helper/formpdfexport.cxx 
b/toolkit/source/helper/formpdfexport.cxx
index 7394a442cef7..eb0a17f1bd58 100644
--- a/toolkit/source/helper/formpdfexport.cxx
+++ b/toolkit/source/helper/formpdfexport.cxx
@@ -315,10 +315,18 @@ namespace toolkitform
             Any aText;
             static const char FM_PROP_TEXT[] = "Text";
             static const char FM_PROP_LABEL[] = "Label";
+            static const char FM_PROP_VALUE[] = "Value";
             if ( xPSI->hasPropertyByName( FM_PROP_TEXT ) )
                 aText = xModelProps->getPropertyValue( FM_PROP_TEXT );
             else if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) )
                 aText = xModelProps->getPropertyValue( FM_PROP_LABEL );
+            else if ( xPSI->hasPropertyByName( FM_PROP_VALUE ) )
+            {
+                double aValue;
+                if (xModelProps->getPropertyValue( FM_PROP_VALUE ) >>= aValue)
+                    aText <<= OUString::number(aValue);
+            }
+
             if ( aText.hasValue() ) {
                 if( ! (aText >>= Descriptor->Text) ) {
                     SAL_WARN("toolkit.helper", "describePDFControl: unable to 
assign aText to Descriptor->Text");
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf148706.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf148706.odt
new file mode 100644
index 000000000000..974bb97433f0
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf148706.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 344a74f87521..645e4487a149 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -110,6 +110,7 @@ public:
     void testSofthyphenPos();
     void testTdf107013();
     void testTdf107018();
+    void testTdf148706();
     void testTdf107089();
     void testTdf99680();
     void testTdf99680_2();
@@ -155,6 +156,7 @@ public:
     CPPUNIT_TEST(testSofthyphenPos);
     CPPUNIT_TEST(testTdf107013);
     CPPUNIT_TEST(testTdf107018);
+    CPPUNIT_TEST(testTdf148706);
     CPPUNIT_TEST(testTdf107089);
     CPPUNIT_TEST(testTdf99680);
     CPPUNIT_TEST(testTdf99680_2);
@@ -749,6 +751,41 @@ void PdfExportTest::testTdf107018()
     CPPUNIT_ASSERT_EQUAL(OString("Pages"), pName->GetValue());
 }
 
+void PdfExportTest::testTdf148706()
+{
+    // Import the bugdoc and export as PDF.
+    aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+    saveAsPDF(u"tdf148706.odt");
+
+    // Parse the export result with pdfium.
+    std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parseExport();
+    CPPUNIT_ASSERT(pPdfDocument);
+
+    // The document has one page.
+    CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
+    std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = 
pPdfDocument->openPage(/*nIndex=*/0);
+    CPPUNIT_ASSERT(pPdfPage);
+
+    // The page has one annotation.
+    CPPUNIT_ASSERT_EQUAL(1, pPdfPage->getAnnotationCount());
+    std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnot = 
pPdfPage->getAnnotation(0);
+
+    CPPUNIT_ASSERT(pAnnot->hasKey("V"));
+    CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFObjectType::String, 
pAnnot->getValueType("V"));
+    OUString aV = pAnnot->getString("V");
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 1821.84
+    // - Actual  :
+    CPPUNIT_ASSERT_EQUAL(OUString("1821.84"), aV);
+
+    CPPUNIT_ASSERT(pAnnot->hasKey("DV"));
+    CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFObjectType::String, 
pAnnot->getValueType("DV"));
+    OUString aDV = pAnnot->getString("DV");
+
+    CPPUNIT_ASSERT_EQUAL(OUString("1821.84"), aDV);
+}
+
 void PdfExportTest::testTdf107089()
 {
     vcl::filter::PDFDocument aDocument;

Reply via email to