[Libreoffice-commits] core.git: oox/source sd/qa
Rosemary Sebastian
rosemaryseb8 at gmail.com
Wed Jan 27 14:42:32 PST 2016
oox/source/drawingml/textfield.cxx | 19 ++++++-
sd/qa/unit/data/odp/numfmt.odp |binary
sd/qa/unit/data/pptx/numfmt.pptx |binary
sd/qa/unit/export-tests.cxx | 90 +++++++++++++++++++++++++++++++++++++
4 files changed, 107 insertions(+), 2 deletions(-)
New commits:
commit 2b0669eec0d86e973a7d8def8744c522bbf8af8b
Author: Rosemary Sebastian <rosemaryseb8 at gmail.com>
Date: Mon Jan 25 12:40:35 2016 +0530
Format the datetime fields properly on import
Make sure that, after export, the datetime fields in impress are
imported with the correct number format.
Change-Id: I5565fef69b3a62e7dd59ea0d39cde151fb0af976
Reviewed-on: https://gerrit.libreoffice.org/21610
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
diff --git a/oox/source/drawingml/textfield.cxx b/oox/source/drawingml/textfield.cxx
index 135ef31..7c5fba0 100644
--- a/oox/source/drawingml/textfield.cxx
+++ b/oox/source/drawingml/textfield.cxx
@@ -60,7 +60,6 @@ void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
{
Reference< XInterface > xIface;
Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
-
if( sType.startsWith("datetime"))
{
OString s = OUStringToOString( sType, RTL_TEXTENCODING_UTF8);
@@ -69,6 +68,7 @@ void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
{
bool bIsDate = true;
int idx = p.toInt32();
+ sal_uInt16 nNumFmt;
// OSL_TRACE( "OOX: p = %s, %d", p.pData->buffer, idx );
xIface = xFactory->createInstance( "com.sun.star.text.TextField.DateTime" );
aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
@@ -79,10 +79,14 @@ void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
{
case 1: // Date dd/mm/yyyy
// this is the default format...
+ nNumFmt = 5;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
case 2: // Date Day, Month dd, yyyy
break;
case 3: // Date dd Month yyyy
+ nNumFmt = 3;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
case 4: // Date Month dd, yyyy
break;
@@ -100,17 +104,28 @@ void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
break;
case 10: // Time H:MM
bIsDate = false;
+ nNumFmt = 3;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
case 11: // Time H:MM:SS
bIsDate = false;
// this is the default format
+ nNumFmt = 2;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
case 12: // Time H:MM PM
bIsDate = false;
+ nNumFmt = 6;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
case 13: // Time H:MM:SS PM
bIsDate = false;
+ nNumFmt = 7;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
break;
+ default:
+ nNumFmt = 2;
+ xProps->setPropertyValue("NumberFormat", makeAny(nNumFmt));
}
xProps->setPropertyValue( "IsDate", makeAny( bIsDate ) );
xProps->setPropertyValue( "IsFixed", makeAny( false ) );
@@ -190,4 +205,4 @@ sal_Int32 TextField::insertAt(
} }
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sd/qa/unit/data/odp/numfmt.odp b/sd/qa/unit/data/odp/numfmt.odp
new file mode 100644
index 0000000..6fd32ce
Binary files /dev/null and b/sd/qa/unit/data/odp/numfmt.odp differ
diff --git a/sd/qa/unit/data/pptx/numfmt.pptx b/sd/qa/unit/data/pptx/numfmt.pptx
new file mode 100755
index 0000000..aca6927
Binary files /dev/null and b/sd/qa/unit/data/pptx/numfmt.pptx differ
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 211cff2..17ecbd2 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -137,6 +137,8 @@ public:
void testParaMarginAndindentation();
void testTransparentBackground();
void testExportTransitionsPPTX();
+ void testDatetimeFieldNumberFormat();
+ void testDatetimeFieldNumberFormatPPTX();
void testFdo90607();
void testTdf91378();
@@ -188,6 +190,8 @@ public:
CPPUNIT_TEST(testExportTransitionsPPTX);
CPPUNIT_TEST(testTdf92527);
+ CPPUNIT_TEST(testDatetimeFieldNumberFormat);
+ CPPUNIT_TEST(testDatetimeFieldNumberFormatPPTX);
CPPUNIT_TEST_SUITE_END();
@@ -1499,6 +1503,92 @@ void SdExportTest::testTdf92527()
xDocShRef->DoClose();
}
+namespace {
+
+void matchNumberFormat( int nPage, uno::Reference< text::XTextRange > xRun)
+{
+ uno::Reference< beans::XPropertySet > xPropSet( xRun, uno::UNO_QUERY_THROW );
+
+ uno::Reference<text::XTextField> xField;
+ xPropSet->getPropertyValue("TextField") >>= xField;
+ CPPUNIT_ASSERT_MESSAGE("Where is the text field?", xField.is() );
+
+ xPropSet.set(xField, uno::UNO_QUERY);
+ sal_Int32 nNumFmt;
+ xPropSet->getPropertyValue("NumberFormat") >>= nNumFmt;
+ switch( nPage )
+ {
+ case 0: // 13/02/96
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Date fields don't match", sal_Int32(2), nNumFmt);
+ break;
+ case 1: // 13/02/1996
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Date fields don't match", sal_Int32(5), nNumFmt);
+ break;
+ case 2: // 13 February 1996
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Date fields don't match", sal_Int32(3), nNumFmt);
+ break;
+ case 3: // 13:49:38
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Time fields don't match", sal_Int32(2), nNumFmt);
+ break;
+ case 4: // 13:49
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Time fields don't match", sal_Int32(3), nNumFmt);
+ break;
+ case 5: // 01:49 PM
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Time fields don't match", sal_Int32(6), nNumFmt);
+ break;
+ case 6: // 01:49:38 PM
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Number formats of Time fields don't match", sal_Int32(7), nNumFmt);
+ }
+}
+
+}
+
+void SdExportTest::testDatetimeFieldNumberFormat()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/numfmt.odp"), ODP);
+
+ xDocShRef = saveAndReload( xDocShRef, PPTX );
+
+ for(sal_uInt16 i = 0; i <= 6; ++i)
+ {
+ // get TextShape 1 from page i
+ uno::Reference< beans::XPropertySet > xShape( getShapeFromPage( 0, i, xDocShRef ) );
+
+ // Get first paragraph
+ uno::Reference<text::XTextRange> xParagraph( getParagraphFromShape( 0, xShape ) );
+
+ // first chunk of text
+ uno::Reference<text::XTextRange> xRun( getRunFromParagraph( 0, xParagraph ) );
+
+ matchNumberFormat( i, xRun );
+ }
+
+ xDocShRef->DoClose();
+}
+
+void SdExportTest::testDatetimeFieldNumberFormatPPTX()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/numfmt.pptx"), PPTX);
+
+ xDocShRef = saveAndReload( xDocShRef, PPTX );
+
+ for(sal_uInt16 i = 0; i <= 6; ++i)
+ {
+ // get TextShape 1 from page i
+ uno::Reference< beans::XPropertySet > xShape( getShapeFromPage( 0, i, xDocShRef ) );
+
+ // Get first paragraph
+ uno::Reference<text::XTextRange> xParagraph( getParagraphFromShape( 0, xShape ) );
+
+ // first chunk of text
+ uno::Reference<text::XTextRange> xRun( getRunFromParagraph( 0, xParagraph ) );
+
+ matchNumberFormat( i, xRun );
+ }
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list