diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2019-10-02 17:15:32 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2019-10-23 13:01:53 +0200 |
commit | f610f9b611fe9f206b872ed06f7e859d688385fc (patch) | |
tree | 7b8f57f23083b502fc687ef2780e7ef30def6bf9 | |
parent | 12385f9e79e15b215c1d398b4bfb212ef1b23fb3 (diff) |
writerfilter: import nested generic fields from RTF
* for m_bStartGenericField, push new insert position onto the stack in
DomainMapper_Impl::CloseFieldCommand(), not in
DomainMapper_Impl::appendTextPortion()
* how is the field result inserted into the field, instead of after it?
- it doesn't seem possible to move the insertion of the field mark to
PopFieldContext(), as there's no way to pass 3 positions to
attach(), and exposing a writable property for the position(s)
is a bad idea
- finishParagraph() calls AppendTextNode(), which happily ignores a
content index on the given XTextRange
- so temporarily insert a paragraph break, override the insert
position, and join the paragraphs in PopFieldContext()
Change-Id: Ie49084f6ea6451e7d7f9b613cedce326de9a54f1
Reviewed-on: https://gerrit.libreoffice.org/80075
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 35 |
2 files changed, 30 insertions, 7 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index e269a3bfba6e..3996c634ab8f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -537,7 +537,7 @@ DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx") DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx") { if (xmlDocPtr pXmlDoc = parseExport()) - assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:instrText", "ADDIN EN.CITE.DATA"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[7]/w:instrText", "ADDIN EN.CITE.DATA"); } DECLARE_OOXMLEXPORT_TEST(testEditTime, "fdo81341.docx") diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index b9c053700574..b2cb490f221a 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1779,7 +1779,10 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, const Proper m_bTextInserted = true; xTOCTextCursor->gotoRange(xTextRange->getEnd(), true); mxTOCTextCursor = xTOCTextCursor; - m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); + if (!m_bStartGenericField) + { + m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); + } } } else @@ -5029,12 +5032,27 @@ void DomainMapper_Impl::CloseFieldCommand() const uno::Reference<text::XTextContent> xTextContent(xFieldInterface, uno::UNO_QUERY_THROW); uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange()); - if (xTextContent.is()) + if (m_aTextAppendStack.top().xInsertPosition.is()) + { + xCrsr->gotoRange(m_aTextAppendStack.top().xInsertPosition, true); + } + else { - xTextAppend->insertTextContent(xCrsr,xTextContent, true); + xCrsr->gotoEnd(true); } - uno::Reference<uno::XInterface> xContent(xTextContent); - uno::Reference< text::XFormField> xFormField(xContent, uno::UNO_QUERY); + xTextAppend->insertTextContent(xCrsr, xTextContent, true); + // problem: the fieldmark must be inserted here, because + // attach() takes 2 positions, not 3! + // FAIL: AppendTextNode() ignores the content index! + // plan B: insert a spurious paragraph break now and join + // it in PopFieldContext()! + xCrsr->gotoRange(xTextContent->getAnchor()->getEnd(), false); + xCrsr->goLeft(1, false); // skip CH_TXT_ATR_FIELDEND + xTextAppend->insertControlCharacter(xCrsr, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCrsr->goLeft(1, false); // back to previous paragraph + m_aTextAppendStack.push(TextAppendContext(xTextAppend, xCrsr)); + + uno::Reference<text::XFormField> xFormField(xTextContent, uno::UNO_QUERY); xFormField->setFieldType(aCode); m_bStartGenericField = true; pContext->SetFormField( xFormField ); @@ -5396,9 +5414,14 @@ void DomainMapper_Impl::PopFieldContext() else if(m_bStartGenericField) { m_bStartGenericField = false; + xCrsr->gotoRange(m_aTextAppendStack.top().xInsertPosition, false); + xCrsr->goRight(1, true); + xCrsr->setString(OUString()); // undo SplitNode from CloseFieldCommand() + // note: paragraph properties will be overwritten + // by finishParagraph() anyway so ignore here + m_aTextAppendStack.pop(); if(m_bTextInserted) { - m_aTextAppendStack.pop(); m_bTextInserted = false; } } |