summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2013-03-20 10:39:08 +0100
committerPetr Mladek <pmladek@suse.cz>2013-03-22 16:34:06 +0000
commit7aa93e2c7c17e11f612bd4313e7c819aa49a9f26 (patch)
tree8d0480ea39784935123078adad6a9beab718cca3
parent939daba04c25a9a3b7be2f3df39692453cf9a304 (diff)
fdo#60769 implement odf export of multi-paragraph comment ranges
(cherry picked from commits 287c254d5ebf9b58ca63a8c271e523adf0d34b82 and 1fba17854b2be4fdbe436f44da3ae57a1f75a27c) Conflicts: sw/qa/extras/odfexport/odfexport.cxx Reviewed-on: https://gerrit.libreoffice.org/2873 Reviewed-by: Noel Power <noel.power@suse.com> Tested-by: Noel Power <noel.power@suse.com> (cherry picked from commit 473cd59a71706ada01f8be68c7dfd008ca9bb716) Change-Id: Ic4a5a1bc685917f2b26be4ab645203f706719c80 Reviewed-on: https://gerrit.libreoffice.org/2908 Reviewed-by: Michael Meeks <michael.meeks@suse.com> Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Reviewed-by: Petr Mladek <pmladek@suse.cz> Tested-by: Petr Mladek <pmladek@suse.cz>
-rw-r--r--sw/qa/extras/odfexport/data/fdo60769.odtbin0 -> 9482 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx28
-rw-r--r--sw/source/core/unocore/unoportenum.cxx12
-rw-r--r--xmloff/source/text/txtparae.cxx20
4 files changed, 52 insertions, 8 deletions
diff --git a/sw/qa/extras/odfexport/data/fdo60769.odt b/sw/qa/extras/odfexport/data/fdo60769.odt
new file mode 100644
index 000000000000..b3c39376b82c
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/fdo60769.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 7d93b3b89efa..1252fe97b3c8 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -33,6 +33,7 @@ class Test : public SwModelTestBase
public:
void testFdo38244();
void testFirstHeaderFooter();
+ void testFdo60769();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -49,6 +50,7 @@ void Test::run()
MethodEntry<Test> aMethods[] = {
{"fdo38244.odt", &Test::testFdo38244},
{"first-header-footer.odt", &Test::testFirstHeaderFooter},
+ {"fdo60769.odt", &Test::testFdo60769},
};
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
{
@@ -116,6 +118,32 @@ void Test::testFirstHeaderFooter()
CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
}
+void Test::testFdo60769()
+{
+ // Test multi-paragraph comment range feature.
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
+ while (xRunEnum->hasMoreElements())
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
+ OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
+ // First paragraph: no field end, no anchor
+ CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldStart");
+ }
+
+ xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+ while (xRunEnum->hasMoreElements())
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
+ OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
+ // Second paragraph: no field start
+ CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldEnd" || aType == "TextFieldEnd");
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index d05b8f5b0d6a..2829d3f6b058 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -754,6 +754,18 @@ lcl_ExportHints(
Reference<XTextField> xField =
SwXTextField::CreateSwXTextField(*pDoc, pAttr->GetFld());
pPortion->SetTextField(xField);
+
+ // If this is a postit field and it has a fieldmark
+ // associated, set the fieldmark as a bookmark.
+ const SwField* pField = pAttr->GetFld().GetFld();
+ if (pField->Which() == RES_POSTITFLD)
+ {
+ const SwPostItField* pPostItField = dynamic_cast<const SwPostItField*>(pField);
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+ IDocumentMarkAccess::const_iterator_t it = pMarkAccess->findMark(pPostItField->GetName());
+ if (it != pMarkAccess->getMarksEnd())
+ pPortion->SetBookmark(SwXFieldmark::CreateXFieldmark(*pDoc, *it->get()));
+ }
}
break;
case RES_TXTATR_FLYCNT :
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 96cb8428c5f0..36f7f0c3cdf9 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -2198,7 +2198,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
static const OUString sMeta("InContentMetadata");
static const OUString sFieldMarkName("__FieldMark_");
bool bPrevCharIsSpace = bPrvChrIsSpc;
- bool bAnnotationStarted = false;
/* This is used for exporting to strict OpenDocument 1.2, in which case traditional
* bookmarks are used instead of fieldmarks. */
@@ -2222,11 +2221,17 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
else if( sType.equals(sTextField))
{
- if (bAnnotationStarted)
+ Reference< ::com::sun::star::text::XFormField > xFormField;
+ try
{
- bAnnotationStarted = false;
+ xFormField.set(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
}
- else
+ catch( const uno::Exception& )
+ {
+ SAL_WARN("xmloff", "unexpected bookmark exception");
+ }
+
+ if (!xFormField.is() || xFormField->getFieldType() != ODF_COMMENTRANGE)
{
exportTextField( xTxtRange, bAutoStyles, bIsProgress );
bPrevCharIsSpace = false;
@@ -2291,10 +2296,9 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
else if (sType.equals(sTextFieldStart))
{
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- if (xFormField->getFieldType() == ODF_COMMENTRANGE)
+ if (xFormField.is() && xFormField->getFieldType() == ODF_COMMENTRANGE)
{
exportTextField( xTxtRange, bAutoStyles, bIsProgress );
- bAnnotationStarted = true;
continue;
}
@@ -2358,7 +2362,8 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
else if (sType.equals(sTextFieldEnd))
{
- if (bAnnotationStarted)
+ Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
+ if (xFormField.is() && xFormField->getFieldType() == ODF_COMMENTRANGE)
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
const OUString& rName = xBookmark->getName();
@@ -2378,7 +2383,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
else
{
- Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if (xFormField.is())
{
OUString sName;