summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-19 10:01:36 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-19 11:31:05 +0200
commitde90c192cb8f1f03a4028493d8bfe9a127a76b2a (patch)
tree3bc07cac0f62f8d58a3301d1e1cb073926e03b05 /sw/source/filter/ww8
parentb20a64ce05ebf3720dd2d10ccd384020803c2ff2 (diff)
sw content controls, plain text: enable DOCX filter with data binding
- writerfilter/ had explicit code to not map plain text SDT to Writer content controls if it has data bindings specified, lift this limitation and set the value of content control from data binding, like Word does and Writer did it for input fields since b5c616d10bff3213840d4893d13b4493de71fa56 (tdf#104823: support for sdt plain text fields, 2021-11-24) - call DocxExport::AddSdtData() on the export side to do the opposite on export - give up on the idea to export content controls to DOCX by finding the text attribute in SwWW8AttrIter::OutAttrWithRange(): this needs buffering in both directions (need to start the SDT before the start of the run, need to end it after the end of the run), and solving this using marks and merges at a fast-serializer level looks like hacks on top of hacks. To be more specific, CppunitTest_sw_ooxmlexport7's testSdtAndShapeOverlapping seems to be very hard to fix with this design - instead, give not only the start position but also the length of the run to DocxAttributeOutput::EndRun(), which has random access to the doc model and can look up if there is a content control start or end that needs writing at the current position of the XML output, without any buffering, which also means less code - adapt CppunitTest_sw_ooxmlfieldexport's testSdtBeforeField, which didn't like the empty run at the start of content controls, which seems to be harmless otherwise - fix CppunitTest_sw_ooxmlfieldexport CPPUNIT_TEST_NAME=testSdtDateDuplicate by disabling the "set content control value from data binding" logic for date pickers because that logic in writerfilter/ sets the value as-is and it has to consider the requested date format before this can be enabled As a side effect, this gives PDF export for plain text SDTs, even if they have data binding set. CppunitTest_sw_ooxmlfieldexport's testTdf104823 is now updated to ensure that we import such SDTs as Writer content controls. Change-Id: I749a845b5a25454c51066b8ded892682f523b6b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140134 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/filter/ww8')
-rw-r--r--sw/source/filter/ww8/attributeoutputbase.hxx8
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx86
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx11
-rw-r--r--sw/source/filter/ww8/docxexport.cxx2
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx3
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx3
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx29
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx4
-rw-r--r--sw/source/filter/ww8/ww8attributeoutput.hxx2
9 files changed, 61 insertions, 87 deletions
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index a7740970347d..d8a8be3e8f7f 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -173,7 +173,7 @@ public:
virtual void StartRun( const SwRedlineData* pRedlineData, sal_Int32 nPos, bool bSingleEmptyRun = false ) = 0;
/// End of the text run.
- virtual void EndRun( const SwTextNode* pNode, sal_Int32 nPos, bool bLastRun = false ) = 0;
+ virtual void EndRun( const SwTextNode* pNode, sal_Int32 nPos, sal_Int32 nLen, bool bLastRun = false ) = 0;
/// Called before we start outputting the attributes.
virtual void StartRunProperties() = 0;
@@ -370,12 +370,6 @@ public:
const OUString &rNumberingString,
const SvxBrushItem* pBrush) = 0; // #i120928 export graphic of bullet
- /// Output content control start.
- virtual void StartContentControl(const SwFormatContentControl& /*rFormatContentControl*/) {}
-
- /// Output content control end.
- virtual void EndContentControl( const SwTextNode& /*rNode*/, sal_Int32 /*nPos*/ ) {}
-
protected:
static void GetNumberPara( OUString& rStr, const SwField& rField );
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 49ac7c64a9cf..f8fc5429fb97 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -136,6 +136,7 @@
#include <frmatr.hxx>
#include <txtatr.hxx>
#include <frameformats.hxx>
+#include <textcontentcontrol.hxx>
#include <o3tl/string_view.hxx>
#include <o3tl/unit_conversion.hxx>
@@ -363,23 +364,6 @@ void DocxAttributeOutput::WriteFloatingTable(ww8::Frame const* pParentFrame)
m_rExport.SetFloatingTableFrame(nullptr);
}
-void DocxAttributeOutput::StartContentControl(const SwFormatContentControl& rFormatContentControl)
-{
- m_pContentControl = rFormatContentControl.GetContentControl();
-}
-
-void DocxAttributeOutput::EndContentControl(const SwTextNode& rNode, sal_Int32 nPos)
-{
- if (rNode.GetTextAttrForCharAt(nPos, RES_TXTATR_CONTENTCONTROL))
- {
- ++m_nCloseContentControlInPreviousRun;
- }
- else
- {
- ++m_nCloseContentControlInThisRun;
- }
-}
-
static void checkAndWriteFloatingTables(DocxAttributeOutput& rDocxAttributeOutput)
{
const auto& rExport = rDocxAttributeOutput.GetExport();
@@ -1584,7 +1568,7 @@ void DocxAttributeOutput::StartRun( const SwRedlineData* pRedlineData, sal_Int32
m_pSerializer->mark(Tag_StartRun_3); // let's call it "postponed text"
}
-void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /*bLastRun*/)
+void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_Int32 nLen, bool /*bLastRun*/)
{
int nFieldsInPrevHyperlink = m_nFieldsInHyperlink;
// Reset m_nFieldsInHyperlink if a new hyperlink is about to start
@@ -1641,12 +1625,6 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
m_bEndCharSdt = false;
}
- for (; m_nCloseContentControlInPreviousRun > 0; --m_nCloseContentControlInPreviousRun)
- {
- // Not the last run of this paragraph.
- WriteContentControlEnd();
- }
-
if ( m_closeHyperlinkInPreviousRun )
{
if ( m_startedHyperlink )
@@ -1744,8 +1722,6 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
m_nHyperLinkCount++;
}
- WriteContentControlStart();
-
// if there is some redlining in the document, output it
StartRedline( m_pRedlineData );
@@ -1791,6 +1767,17 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
DoWriteBookmarkStartIfExist(nPos);
+ if (nLen != -1)
+ {
+ SwTextAttr* pAttr = pNode->GetTextAttrAt(nPos, RES_TXTATR_CONTENTCONTROL, SwTextNode::DEFAULT);
+ if (pAttr && pAttr->GetStart() == nPos)
+ {
+ auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr);
+ m_pContentControl = pTextContentControl->GetContentControl().GetContentControl();
+ WriteContentControlStart();
+ }
+ }
+
m_pSerializer->startElementNS(XML_w, XML_r);
if(GetExport().m_bTabInTOC && m_pHyperlinkAttrList.is())
{
@@ -1809,6 +1796,16 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
// append the actual run end
m_pSerializer->endElementNS( XML_w, XML_r );
+ if (nLen != -1)
+ {
+ sal_Int32 nEnd = nPos + nLen;
+ SwTextAttr* pAttr = pNode->GetTextAttrAt(nPos, RES_TXTATR_CONTENTCONTROL, SwTextNode::DEFAULT);
+ if (pAttr && *pAttr->GetEnd() == nEnd)
+ {
+ WriteContentControlEnd();
+ }
+ }
+
// if there is some redlining in the document, output it
// (except in the case of fields with multiple runs)
EndRedline( m_pRedlineData );
@@ -1856,12 +1853,6 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
m_pRedlineData = nullptr;
}
- for (; m_nCloseContentControlInThisRun > 0; --m_nCloseContentControlInThisRun)
- {
- // Last run of this paragraph.
- WriteContentControlEnd();
- }
-
if ( m_closeHyperlinkInThisRun )
{
if ( m_startedHyperlink )
@@ -2445,6 +2436,26 @@ void DocxAttributeOutput::WriteContentControlStart()
m_pSerializer->endElementNS(XML_w, XML_sdtPr);
m_pSerializer->startElementNS(XML_w, XML_sdtContent);
+
+ const OUString& rPrefixMapping = m_pContentControl->GetDataBindingPrefixMappings();
+ const OUString& rXpath = m_pContentControl->GetDataBindingXpath();
+ if (!rXpath.isEmpty())
+ {
+ // This content control has a data binding, update the data source.
+ SwTextContentControl* pTextAttr = m_pContentControl->GetTextAttr();
+ SwTextNode* pTextNode = m_pContentControl->GetTextNode();
+ SwPosition aPoint(*pTextNode, pTextAttr->GetStart());
+ SwPosition aMark(*pTextNode, *pTextAttr->GetEnd());
+ SwPaM aPam(aMark, aPoint);
+ OUString aSnippet = aPam.GetText();
+ static sal_Unicode const aForbidden[] = {
+ CH_TXTATR_BREAKWORD,
+ 0
+ };
+ aSnippet = comphelper::string::removeAny(aSnippet, aForbidden);
+ m_rExport.AddSdtData(rPrefixMapping, rXpath, aSnippet);
+ }
+
m_pContentControl = nullptr;
}
@@ -3387,11 +3398,6 @@ void DocxAttributeOutput::RunText( const OUString& rText, rtl_TextEncoding /*eCh
{
m_closeHyperlinkInPreviousRun = true;
}
- if (m_nCloseContentControlInThisRun > 0)
- {
- ++m_nCloseContentControlInPreviousRun;
- --m_nCloseContentControlInThisRun;
- }
m_bRunTextIsOn = true;
// one text can be split into more <w:t>blah</w:t>'s by line breaks etc.
const sal_Unicode *pBegin = rText.getStr();
@@ -3463,7 +3469,7 @@ void DocxAttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 nPos, co
{
WW8Ruby aWW8Ruby( rNode, rRuby, GetExport() );
SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::StartRuby( const SwTextNode& rNode, const SwFormatRuby& rRuby )" );
- EndRun( &rNode, nPos ); // end run before starting ruby to avoid nested runs, and overlap
+ EndRun( &rNode, nPos, -1 ); // end run before starting ruby to avoid nested runs, and overlap
assert(!m_closeHyperlinkInThisRun); // check that no hyperlink overlaps ruby
assert(!m_closeHyperlinkInPreviousRun);
m_pSerializer->startElementNS(XML_w, XML_r);
@@ -3507,7 +3513,7 @@ void DocxAttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 nPos, co
EndRunProperties( nullptr );
RunText( rRuby.GetText( ) );
- EndRun( &rNode, nPos );
+ EndRun( &rNode, nPos, -1 );
m_pSerializer->endElementNS( XML_w, XML_rt );
m_pSerializer->startElementNS(XML_w, XML_rubyBase);
@@ -3517,7 +3523,7 @@ void DocxAttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 nPos, co
void DocxAttributeOutput::EndRuby(const SwTextNode& rNode, sal_Int32 nPos)
{
SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::EndRuby()" );
- EndRun( &rNode, nPos );
+ EndRun( &rNode, nPos, -1 );
m_pSerializer->endElementNS( XML_w, XML_rubyBase );
m_pSerializer->endElementNS( XML_w, XML_ruby );
m_pSerializer->endElementNS( XML_w, XML_r );
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index b1b5d22ff456..9de8f6fed332 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -185,7 +185,7 @@ public:
virtual void StartRun( const SwRedlineData* pRedlineData, sal_Int32 nPos, bool bSingleEmptyRun = false ) override;
/// End of the text run.
- virtual void EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool bLastRun = false) override;
+ virtual void EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_Int32 nLen, bool bLastRun = false) override;
/// Called before we start outputting the attributes.
virtual void StartRunProperties() override;
@@ -404,12 +404,6 @@ public:
void WriteFloatingTable(ww8::Frame const* pParentFrame);
- /// See AttributeOutputBase::StartContentControl().
- void StartContentControl(const SwFormatContentControl& rFormatContentControl) override;
-
- /// See AttributeOutputBase::EndContentControl().
- void EndContentControl( const SwTextNode& rNode, sal_Int32 nPos ) override;
-
private:
/// Initialize the structures where we are going to collect some of the paragraph properties.
///
@@ -914,9 +908,6 @@ private:
o3tl::sorted_vector<const SwFrameFormat*> m_aFloatingTablesOfParagraph;
sal_Int32 m_nTextFrameLevel;
- sal_Int32 m_nCloseContentControlInThisRun = 0;
- sal_Int32 m_nCloseContentControlInPreviousRun = 0;
-
// close of hyperlink needed
bool m_closeHyperlinkInThisRun;
bool m_closeHyperlinkInPreviousRun;
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 52090fc74891..a8ec459c79a5 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1969,7 +1969,7 @@ sal_Int32 DocxExport::WriteOutliner(const OutlinerParaObject& rParaObj, sal_uInt
eChrSet = eNextChrSet;
aAttrIter.NextPos();
- AttrOutput().EndRun( nullptr, 0 );
+ AttrOutput().EndRun( nullptr, 0, -1 );
} while( nCurrentPos < nEnd );
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index a7f7086f0657..4c3c2c5a74af 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -419,7 +419,8 @@ void RtfAttributeOutput::StartRun(const SwRedlineData* pRedlineData, sal_Int32 /
OSL_ENSURE(m_aRunText.getLength() == 0, "m_aRunText is not empty");
}
-void RtfAttributeOutput::EndRun(const SwTextNode* /*pNode*/, sal_Int32 /*nPos*/, bool /*bLastRun*/)
+void RtfAttributeOutput::EndRun(const SwTextNode* /*pNode*/, sal_Int32 /*nPos*/, sal_Int32 /*nLen*/,
+ bool /*bLastRun*/)
{
m_aRun->append(SAL_NEWLINE_STRING);
m_aRun.appendAndClear(m_aRunText);
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index 17de105ed4f6..a20719df6777 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -75,7 +75,8 @@ public:
bool bSingleEmptyRun = false) override;
/// End of the text run.
- void EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool bLastRun = false) override;
+ void EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_Int32 nLen,
+ bool bLastRun = false) override;
/// Called before we start outputting the attributes.
void StartRunProperties() override;
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 692086fa709d..a9ff9a6b9b56 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -1402,14 +1402,6 @@ int SwWW8AttrIter::OutAttrWithRange(const SwTextNode& rNode, sal_Int32 nPos)
--nRet;
}
break;
- case RES_TXTATR_CONTENTCONTROL:
- pEnd = pHt->End();
- if (nPos == *pEnd && nPos != pHt->GetStart())
- {
- m_rExport.AttrOutput().EndContentControl(rNode, nPos);
- --nRet;
- }
- break;
}
if (nPos < pHt->GetAnyEnd())
break; // sorted by end
@@ -1464,17 +1456,6 @@ int SwWW8AttrIter::OutAttrWithRange(const SwTextNode& rNode, sal_Int32 nPos)
--nRet;
}
break;
- case RES_TXTATR_CONTENTCONTROL:
- if (nPos == pHt->GetStart())
- {
- auto pFormatContentControl
- = static_cast<const SwFormatContentControl*>(pItem);
- m_rExport.AttrOutput().StartContentControl(*pFormatContentControl);
- ++nRet;
- }
- // We know that the content control is never empty as it has a dummy character
- // at least.
- break;
}
if (nPos < pHt->GetStart())
break; // sorted by start
@@ -2427,7 +2408,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
{
if( AttrOutput().FootnoteEndnoteRefTag() )
{
- AttrOutput().EndRun( &rNode, nCurrentPos, nNextAttr == nEnd );
+ AttrOutput().EndRun( &rNode, nCurrentPos, -1, nNextAttr == nEnd );
AttrOutput().StartRun( pRedlineData, nCurrentPos, bSingleEmptyRun );
}
}
@@ -2481,7 +2462,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
&& nStateOfFlyFrame == FLY_PROCESSED)
{
// write flys in a separate run before field character
- AttrOutput().EndRun(&rNode, nCurrentPos, nNextAttr == nEnd);
+ AttrOutput().EndRun(&rNode, nCurrentPos, -1, nNextAttr == nEnd);
AttrOutput().StartRun(pRedlineData, nCurrentPos, bSingleEmptyRun);
}
@@ -2778,7 +2759,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
{
if (FLY_PROCESSED == nStateOfFlyFrame || FLY_NONE == nStateOfFlyFrame)
{
- AttrOutput().EndRun(&rNode, nCurrentPos, /*bLastRun=*/false);
+ AttrOutput().EndRun(&rNode, nCurrentPos, -1, /*bLastRun=*/false);
if (!aSavedSnippet.isEmpty())
bStartedPostponedRunProperties = false;
@@ -2796,10 +2777,10 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
AttrOutput().WritePostitFieldReference();
}
AttrOutput().RunText( aSavedSnippet, eChrSet );
- AttrOutput().EndRun(&rNode, nCurrentPos, nNextAttr == nEnd);
+ AttrOutput().EndRun(&rNode, nCurrentPos, nLen, nNextAttr == nEnd);
}
else
- AttrOutput().EndRun(&rNode, nCurrentPos, nNextAttr == nEnd);
+ AttrOutput().EndRun(&rNode, nCurrentPos, nLen, nNextAttr == nEnd);
nCurrentPos = nNextAttr;
UpdatePosition( &aAttrIter, nCurrentPos );
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 5afd5b0c8de2..3fce91b9b436 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -1099,7 +1099,7 @@ void WW8AttributeOutput::OnTOXEnding()
mbOnTOXEnding = true;
}
-void WW8AttributeOutput::EndRun( const SwTextNode* /*pNode*/, sal_Int32 nPos, bool bLastRun )
+void WW8AttributeOutput::EndRun( const SwTextNode* /*pNode*/, sal_Int32 nPos, sal_Int32 /*nLen*/, bool bLastRun )
{
/// Insert bookmarks ended after this run
auto aRange = m_aBookmarksOfParagraphEnd.equal_range(nPos);
@@ -2573,7 +2573,7 @@ void AttributeOutputBase::StartTOX( const SwSection& rSect )
FieldFlags::CmdEnd );
if (GetExport().GetExportFormat() == MSWordExportBase::ExportFormat::RTF)
{
- EndRun(nullptr, -42, true);
+ EndRun(nullptr, -42, -1, true);
}
}
}
diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx
index 9ea43ef885b5..32ad12cdadb3 100644
--- a/sw/source/filter/ww8/ww8attributeoutput.hxx
+++ b/sw/source/filter/ww8/ww8attributeoutput.hxx
@@ -58,7 +58,7 @@ public:
/// End of the text run.
///
/// No-op for binary filters.
- virtual void EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool bLastRun = false) override;
+ virtual void EndRun(const SwTextNode* pNode, sal_Int32 nPos, sal_Int32 nLen, bool bLastRun = false) override;
/// Before we start outputting the attributes.
virtual void StartRunProperties() override;