From e39ea45caa3712ae2ff077203ef8aef0e16fe41a Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Wed, 18 May 2022 18:10:09 +0200 Subject: tdf#105972: pdf form: export date fields as date type using AFDate_FormatEx which allows to set a custom format Change-Id: I38839965423794a0278b783c39c612c361a90eea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134543 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- toolkit/source/helper/formpdfexport.cxx | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'toolkit') diff --git a/toolkit/source/helper/formpdfexport.cxx b/toolkit/source/helper/formpdfexport.cxx index def4f38d8a61..1c001cd9e5c5 100644 --- a/toolkit/source/helper/formpdfexport.cxx +++ b/toolkit/source/helper/formpdfexport.cxx @@ -555,6 +555,54 @@ namespace toolkitform } } } break; + case FormComponentType::DATEFIELD: + { + pEditWidget->Format = vcl::PDFWriter::Date; + + static constexpr OUStringLiteral FM_PROP_DATEFORMAT = u"DateFormat"; + if ( xPSI->hasPropertyByName( FM_PROP_DATEFORMAT ) ) + { + sal_Int32 nDateFormat = 0; + if( ! (xModelProps->getPropertyValue( FM_PROP_DATEFORMAT ) >>= nDateFormat) ) + SAL_WARN("toolkit.helper", "describePDFControl: unable to get property " << FM_PROP_DATEFORMAT); + + switch ( nDateFormat ) + { + case 0: + case 1: + pEditWidget->DateFormat = "mm/dd/yy"; // Standard (short) + break; + case 2: + case 3: + pEditWidget->DateFormat = "mm/dd/yyyy"; // Standard (long) + break; + case 4: + pEditWidget->DateFormat = "dd/mm/yy"; // DD/MM/YY + break; + case 5: + pEditWidget->DateFormat = "mm/dd/yy"; // MM/DD/YY + break; + case 6: + pEditWidget->DateFormat = "yy/mm/dd"; // YY/MM/DD + break; + case 7: + pEditWidget->DateFormat = "dd/mm/yyyy"; // DD/MM/YYYY + break; + case 8: + pEditWidget->DateFormat = "mm/dd/yyyy"; // MM/DD/YYYY + break; + case 9: + pEditWidget->DateFormat = "yyyy/mm/dd"; // YYYY/MM/DD + break; + case 10: + pEditWidget->DateFormat = "yy-mm-dd"; // YY-MM-DD + break; + case 11: + pEditWidget->DateFormat = "yyyy-mm-dd"; // YYYY-MM-DD + break; + } + } + } break; } } -- cgit