Kaydet (Commit) 7aa93e2c authored tarafından Miklos Vajna's avatar Miklos Vajna Kaydeden (comit) Petr Mladek

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/2873Reviewed-by: 's avatarNoel Power <noel.power@suse.com>
Tested-by: 's avatarNoel Power <noel.power@suse.com>

(cherry picked from commit 473cd59a)

Change-Id: Ic4a5a1bc685917f2b26be4ab645203f706719c80
Reviewed-on: https://gerrit.libreoffice.org/2908Reviewed-by: 's avatarMichael Meeks <michael.meeks@suse.com>
Reviewed-by: 's avatarFridrich Strba <fridrich@documentfoundation.org>
Reviewed-by: 's avatarPetr Mladek <pmladek@suse.cz>
Tested-by: 's avatarPetr Mladek <pmladek@suse.cz>
üst 939daba0
...@@ -33,6 +33,7 @@ class Test : public SwModelTestBase ...@@ -33,6 +33,7 @@ class Test : public SwModelTestBase
public: public:
void testFdo38244(); void testFdo38244();
void testFirstHeaderFooter(); void testFirstHeaderFooter();
void testFdo60769();
CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT) #if !defined(MACOSX) && !defined(WNT)
...@@ -49,6 +50,7 @@ void Test::run() ...@@ -49,6 +50,7 @@ void Test::run()
MethodEntry<Test> aMethods[] = { MethodEntry<Test> aMethods[] = {
{"fdo38244.odt", &Test::testFdo38244}, {"fdo38244.odt", &Test::testFdo38244},
{"first-header-footer.odt", &Test::testFirstHeaderFooter}, {"first-header-footer.odt", &Test::testFirstHeaderFooter},
{"fdo60769.odt", &Test::testFdo60769},
}; };
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
{ {
...@@ -116,6 +118,32 @@ void Test::testFirstHeaderFooter() ...@@ -116,6 +118,32 @@ void Test::testFirstHeaderFooter()
CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()")); 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_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -754,6 +754,18 @@ lcl_ExportHints( ...@@ -754,6 +754,18 @@ lcl_ExportHints(
Reference<XTextField> xField = Reference<XTextField> xField =
SwXTextField::CreateSwXTextField(*pDoc, pAttr->GetFld()); SwXTextField::CreateSwXTextField(*pDoc, pAttr->GetFld());
pPortion->SetTextField(xField); 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; break;
case RES_TXTATR_FLYCNT : case RES_TXTATR_FLYCNT :
......
...@@ -2198,7 +2198,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( ...@@ -2198,7 +2198,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
static const OUString sMeta("InContentMetadata"); static const OUString sMeta("InContentMetadata");
static const OUString sFieldMarkName("__FieldMark_"); static const OUString sFieldMarkName("__FieldMark_");
bool bPrevCharIsSpace = bPrvChrIsSpc; bool bPrevCharIsSpace = bPrvChrIsSpc;
bool bAnnotationStarted = false;
/* This is used for exporting to strict OpenDocument 1.2, in which case traditional /* This is used for exporting to strict OpenDocument 1.2, in which case traditional
* bookmarks are used instead of fieldmarks. */ * bookmarks are used instead of fieldmarks. */
...@@ -2222,11 +2221,17 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( ...@@ -2222,11 +2221,17 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
} }
else if( sType.equals(sTextField)) 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 ); exportTextField( xTxtRange, bAutoStyles, bIsProgress );
bPrevCharIsSpace = false; bPrevCharIsSpace = false;
...@@ -2291,10 +2296,9 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( ...@@ -2291,10 +2296,9 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
else if (sType.equals(sTextFieldStart)) else if (sType.equals(sTextFieldStart))
{ {
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); 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 ); exportTextField( xTxtRange, bAutoStyles, bIsProgress );
bAnnotationStarted = true;
continue; continue;
} }
...@@ -2358,7 +2362,8 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( ...@@ -2358,7 +2362,8 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
} }
else if (sType.equals(sTextFieldEnd)) 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); Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
const OUString& rName = xBookmark->getName(); const OUString& rName = xBookmark->getName();
...@@ -2378,7 +2383,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration( ...@@ -2378,7 +2383,6 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
} }
else else
{ {
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if (xFormField.is()) if (xFormField.is())
{ {
OUString sName; OUString sName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment