[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sw/qa writerfilter/source
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Mon Aug 5 16:08:12 UTC 2019
sw/qa/extras/ooxmlexport/data/date_field_at_end_of_paragraph.docx |binary
sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 42 ++++++++++
writerfilter/source/dmapper/DomainMapper.cxx | 28 +++---
writerfilter/source/dmapper/DomainMapper.hxx | 2
writerfilter/source/dmapper/SdtHelper.cxx | 7 +
writerfilter/source/dmapper/SdtHelper.hxx | 2
6 files changed, 64 insertions(+), 17 deletions(-)
New commits:
commit 5052b61b9d3585e9dc3f4a3b1bb8c4b0b843839a
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Mon Aug 5 03:37:34 2019 +0200
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Aug 5 18:07:34 2019 +0200
tdf126701: MSForms: Fix import of date field at the end of the paragraph.
We need to create date field before the paragraph is finished
(line break is inserted). A date field can not span between
paragraphs.
Extend other related unit tests too. In other use cases, the field
content changes to an invalid data.
Reviewed-on: https://gerrit.libreoffice.org/76971
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
(cherry picked from commit b36ef83ea59eeaca239e58b95aa0b1acdcb99efc)
Change-Id: Id274649e0aaaf6e3c31e042afd126cefc368c858
Reviewed-on: https://gerrit.libreoffice.org/76980
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Andras Timar <andras.timar at collabora.com>
diff --git a/sw/qa/extras/ooxmlexport/data/date_field_at_end_of_paragraph.docx b/sw/qa/extras/ooxmlexport/data/date_field_at_end_of_paragraph.docx
new file mode 100644
index 000000000000..6514b2a53089
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/date_field_at_end_of_paragraph.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 1b30405018f0..4857385692e1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -8,6 +8,9 @@
*/
#include <swmodeltestbase.hxx>
+#include <xmloff/odffields.hxx>
+#include <IDocumentMarkAccess.hxx>
+#include <IMark.hxx>
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
@@ -558,6 +561,18 @@ DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
// Single <w:sdt> was exported as 2 <w:sdt> elements.
assertXPath(pXmlDoc, "//w:sdt", 1);
}
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+ ::sw::mark::IDateFieldmark* pFieldmark
+ = dynamic_cast<::sw::mark::IDateFieldmark*>(pMarkAccess->getAllMarksBegin()->get());
+ CPPUNIT_ASSERT(pFieldmark);
+ CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+ CPPUNIT_ASSERT_EQUAL(OUString("4/26/2012"), pFieldmark->GetContent());
}
DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx")
@@ -708,6 +723,33 @@ DECLARE_OOXMLEXPORT_TEST( testTdf66401, "tdf66401.docx")
DECLARE_OOXMLEXPORT_TEST( testDateFieldInShape, "date_field_in_shape.docx" )
{
// This was crashed on export.
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+ ::sw::mark::IDateFieldmark* pFieldmark
+ = dynamic_cast<::sw::mark::IDateFieldmark*>(pMarkAccess->getAllMarksBegin()->get());
+ CPPUNIT_ASSERT(pFieldmark);
+ CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+ CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), pFieldmark->GetContent());
+}
+
+DECLARE_OOXMLEXPORT_TEST( testDateFieldAtEndOfParagraph, "date_field_at_end_of_paragraph.docx" )
+{
+ // Additional line end was added by import and it was crashed on export
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+ ::sw::mark::IDateFieldmark* pFieldmark
+ = dynamic_cast<::sw::mark::IDateFieldmark*>(pMarkAccess->getAllMarksBegin()->get());
+ CPPUNIT_ASSERT(pFieldmark);
+ CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+ CPPUNIT_ASSERT_EQUAL(OUString("Click here to enter a date."), pFieldmark->GetContent());
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 253662695a1f..673037ee884e 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3214,7 +3214,7 @@ void DomainMapper::lcl_text(const sal_uInt8 * data_, size_t len)
pContext->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE));
m_pImpl->clearDeferredBreak(COLUMN_BREAK);
}
- m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH));
+ finishParagraph();
return;
}
case cFieldStart:
@@ -3394,15 +3394,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
m_pImpl->m_pSdtHelper->getLocale().truncate();
return;
}
- bool bIsInTable = (m_pImpl->hasTableManager() && m_pImpl->getTableManager().isInTable()) ||
- (m_pImpl->m_nTableDepth > 0);
- if(bIsInTable || m_pImpl->IsInShape())
- {
- // Inside an object we need to import date field earlier
- m_pImpl->m_pSdtHelper->createDateContentControl(bIsInTable);
- }
}
-
if (!m_pImpl->hasTableManager())
return;
@@ -3429,10 +3421,11 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
if ( m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun() )
{
m_pImpl->m_bIsSplitPara = true;
- m_pImpl->finishParagraph( m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) );
+ finishParagraph();
lcl_startParagraphGroup();
}
+
pContext->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE));
m_pImpl->clearDeferredBreaks();
}
@@ -3442,7 +3435,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
if ( m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun() )
{
mbIsSplitPara = true;
- m_pImpl->finishParagraph( m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) );
+ finishParagraph();
lcl_startParagraphGroup();
}
@@ -3472,7 +3465,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
xContext->Erase(PROP_NUMBERING_LEVEL);
}
m_pImpl->SetParaSectpr(false);
- m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH));
+ finishParagraph();
if (bRemove)
m_pImpl->RemoveLastParagraph();
}
@@ -3491,7 +3484,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
if (m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun())
{
m_pImpl->m_bIsSplitPara = true;
- m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH));
+ finishParagraph();
lcl_startParagraphGroup();
}
m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE));
@@ -3501,7 +3494,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
if (m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun())
{
mbIsSplitPara = true;
- m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH));
+ finishParagraph();
lcl_startParagraphGroup();
}
m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE));
@@ -3944,6 +3937,13 @@ void DomainMapper::HandleRedline( Sprm& rSprm )
m_pImpl->SetCurrentRedlineIsRead();
}
+void DomainMapper::finishParagraph()
+{
+ if (m_pImpl->m_pSdtHelper->validateDateFormat())
+ m_pImpl->m_pSdtHelper->createDateContentControl();
+ m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH));
+}
+
} //namespace dmapper
} //namespace writerfilter
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx
index b2b89f1776c1..2767d59f4754 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -156,6 +156,8 @@ private:
// Table
virtual void lcl_entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref) override;
+ void finishParagraph();
+
static void handleUnderlineType(const Id nId, const ::std::shared_ptr<PropertyMap>& rContext);
void handleParaJustification(const sal_Int32 nIntValue, const ::std::shared_ptr<PropertyMap>& rContext, const bool bExchangeLeftRight);
static bool getColorFromId(const Id, sal_Int32 &nColor);
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 22c3ceafe464..eec3438fa2a4 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -91,7 +91,7 @@ bool SdtHelper::validateDateFormat() const
return !m_sDateFormat.toString().isEmpty() && !m_sLocale.toString().isEmpty();
}
-void SdtHelper::createDateContentControl(bool bInsideTable)
+void SdtHelper::createDateContentControl()
{
if(!m_xDateFieldStartRange.is())
return;
@@ -110,7 +110,10 @@ void SdtHelper::createDateContentControl(bool bInsideTable)
try
{
xCrsr->gotoRange(m_xDateFieldStartRange, false);
- if(bInsideTable)
+ bool bIsInTable
+ = (m_rDM_Impl.hasTableManager() && m_rDM_Impl.getTableManager().isInTable())
+ || (m_rDM_Impl.m_nTableDepth > 0);
+ if (bIsInTable)
xCrsr->goRight(1, false);
xCrsr->gotoEnd(true);
}
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 0e229ce0fcdf..737021daae66 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -127,7 +127,7 @@ public:
void createDropDownControl();
/// Create date control from w:sdt's w:date.
- void createDateContentControl(bool bInsideTable = false);
+ void createDateContentControl();
void appendToInteropGrabBag(const css::beans::PropertyValue& rValue);
css::uno::Sequence<css::beans::PropertyValue> getInteropGrabBagAndClear();
More information about the Libreoffice-commits
mailing list