tdf#132475 writerfilter: connect PRINTDATE with DocInfo.PrintDateTime

NOTE: This patch depends on a follow-up patch to handle the case
where no date formating instructions are provided.

NOTE: The time part might be considered a regression by some since
Word displays as local time while LO seems to display GMT time.

Although the date was being imported as a generic field,
it wasn't associated with the last printed date.

PRINTDATE is about the only field that MS Word automatically
updates without the user having to press F9 on it,
so that shows we should NOT mark it as fixed on import.
On the other hand, it doesn't update very often, so if a
user hand-modifies the result, then (without marking it as fixed)
LO will display differently from MS Word.

Hey, its a last-printed-date field I say. Who cares what
it looks like on someone else's computer. It only matters
if it is accurate and visible on yours.

This caused a unit test failure with
make CppunitTest_sw_ooxmlfieldexport CPPUNIT_TESt_NAME=testGenericTextField
because contents.match(" PRINTDATE ")
NOTE: we are losing \* MERGEFORMAT on all of supported fields on export,
but that might be OK because we don't do MERGEFORMAT anyway.

Change-Id: I7cb79ce7470cd55090a61be63848ce328d48be06
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132446
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf132475_printField.docx b/sw/qa/extras/ooxmlexport/data/tdf132475_printField.docx
new file mode 100644
index 0000000..032a58d
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf132475_printField.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index dcfede6..8dbdd63 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -100,6 +100,24 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148380_modifiedField, "tdf148380_modifiedField.d
                                 OUString("Charles Brown"), xField->getPresentation(false));
}

DECLARE_OOXMLEXPORT_TEST(testTdf132475_printField, "tdf132475_printField.docx")
{
    // The last printed date field: formatted two diferent ways
    getParagraph(2, "Thursday, March 17, 2022");
    getParagraph(3, "17-Mar-22");
    // Time zone affects the displayed time in MS Word. LO shows GMT time. Word only updated by F9
    getParagraph(5, "12:49");
    getParagraph(6, "12:49:00 PM");

    // Verify that these are fields, and not just plain text
    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
    auto xFieldsAccess(xTextFieldsSupplier->getTextFields());
    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
    uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(OUString("Thursday, March 17, 2022"), xField->getPresentation(false));
    CPPUNIT_ASSERT_EQUAL(OUString("DocInformation:Last printed"), xField->getPresentation(true));
}

CPPUNIT_TEST_FIXTURE(Test, testTdf135906)
{
    loadAndReload("tdf135906.docx");
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index e3628f7..b3f45fd 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -342,7 +342,7 @@ CPPUNIT_TEST_FIXTURE(Test, testGenericTextField)
    xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
    OUString contents = OUString::createFromAscii(reinterpret_cast<char*>((pXmlNode->children[0]).content));
    CPPUNIT_ASSERT(contents.match("PRINTDATE   \\* MERGEFORMAT"));
    CPPUNIT_ASSERT(contents.match(" PRINTDATE "));
    xmlXPathFreeObject(pXmlObj);
}

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 2aff26a..6206a93 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -5165,6 +5165,7 @@ static const FieldConversionMap_t & lcl_GetFieldConversion()
        {"NEXTIF",          {"DatabaseNextSet",         FIELD_NEXTIF        }},
        {"PAGE",            {"PageNumber",              FIELD_PAGE          }},
        {"PAGEREF",         {"GetReference",            FIELD_PAGEREF       }},
        {"PRINTDATE",       {"DocInfo.PrintDateTime",   FIELD_PRINTDATE     }},
        {"REF",             {"GetReference",            FIELD_REF           }},
        {"REVNUM",          {"DocInfo.Revision",        FIELD_REVNUM        }},
        {"SAVEDATE",        {"DocInfo.Change",          FIELD_SAVEDATE      }},
@@ -6367,6 +6368,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                }
                break;
                case FIELD_CREATEDATE  :
                case FIELD_PRINTDATE:
                {
                    xFieldProperties->setPropertyValue(
                        getPropertyName( PROP_IS_DATE ), uno::makeAny( true ));
diff --git a/writerfilter/source/dmapper/FieldTypes.hxx b/writerfilter/source/dmapper/FieldTypes.hxx
index f28d0f0..a907a7a 100644
--- a/writerfilter/source/dmapper/FieldTypes.hxx
+++ b/writerfilter/source/dmapper/FieldTypes.hxx
@@ -161,6 +161,7 @@ enum FieldId
     */
    ,FIELD_PAGE
    ,FIELD_PAGEREF
    ,FIELD_PRINTDATE
    /* REF targetbkm \f \* MERGEFORMAT ->
        imports a ShowVariable (bookmarkname)?
        \h hyperlink to paragraph