sw/source/core/inc/txtfrm.hxx | 2 sw/source/core/text/txtfrm.cxx | 84 ++++++++++++++++++++++++++++++++++++++++ sw/source/core/text/xmldump.cxx | 75 ----------------------------------- 3 files changed, 87 insertions(+), 74 deletions(-)
New commits: commit 8925e5eda74128503c942bff240ccaae84e13e18 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jun 15 20:04:15 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jun 16 08:18:13 2023 +0200 sw layout xml dump: extract SwTextFrame::dumpAsXml() from SwFrame Ideally SwFrame should not really know anything about text frames. Change-Id: I2734e76ced3001de1fc1176d6315f8c69c02d8b6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153152 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index 40cc0ef0bfac..c39df900dfb7 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -802,6 +802,8 @@ public: static SwView* GetView(); virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override; + + void dumpAsXml(xmlTextWriterPtr writer = nullptr) const override; }; //use this to protect a SwTextFrame for a given scope from getting merged with diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx index a495e312a60b..821c22f528cd 100644 --- a/sw/source/core/text/txtfrm.cxx +++ b/sw/source/core/text/txtfrm.cxx @@ -793,6 +793,90 @@ SwTextFrame::SwTextFrame(SwTextNode * const pNode, SwFrame* pSib, m_pMergedPara = CheckParaRedlineMerge(*this, *pNode, eMode); } +void SwTextFrame::dumpAsXml(xmlTextWriterPtr writer) const +{ + (void)xmlTextWriterStartElement(writer, reinterpret_cast<const xmlChar*>("txt")); + dumpAsXmlAttributes(writer); + sw::MergedPara const*const pMerged(GetMergedPara()); + if (pMerged) + { + (void)xmlTextWriterStartElement( writer, BAD_CAST( "merged" ) ); + (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "paraPropsNodeIndex" ), "%" SAL_PRIdINT32, sal_Int32(pMerged->pParaPropsNode->GetIndex()) ); + for (auto const& e : pMerged->extents) + { + (void)xmlTextWriterStartElement( writer, BAD_CAST( "extent" ) ); + (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "txtNodeIndex" ), "%" SAL_PRIdINT32, sal_Int32(e.pNode->GetIndex()) ); + (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "start" ), "%" SAL_PRIdINT32, e.nStart ); + (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "end" ), "%" SAL_PRIdINT32, e.nEnd ); + (void)xmlTextWriterEndElement( writer ); + } + (void)xmlTextWriterEndElement( writer ); + } + + (void)xmlTextWriterStartElement(writer, BAD_CAST("infos")); + dumpInfosAsXml(writer); + (void)xmlTextWriterEndElement(writer); + + // Dump Anchored objects if any + const SwSortedObjs* pAnchored = GetDrawObjs(); + if ( pAnchored && pAnchored->size() > 0 ) + { + (void)xmlTextWriterStartElement( writer, BAD_CAST( "anchored" ) ); + + for (SwAnchoredObject* pObject : *pAnchored) + { + pObject->dumpAsXml( writer ); + } + + (void)xmlTextWriterEndElement( writer ); + } + + // Dump the children + OUString aText = GetText( ); + for ( int i = 0; i < 32; i++ ) + { + aText = aText.replace( i, '*' ); + } + auto nTextOffset = static_cast<sal_Int32>(GetOffset()); + sal_Int32 nTextLength = aText.getLength() - nTextOffset; + if (const SwTextFrame* pTextFrameFollow = GetFollow()) + { + nTextLength = static_cast<sal_Int32>(pTextFrameFollow->GetOffset() - GetOffset()); + } + OString aText8 + = OUStringToOString(aText.subView(nTextOffset, nTextLength), RTL_TEXTENCODING_UTF8); + (void)xmlTextWriterWriteString( writer, + reinterpret_cast<const xmlChar *>(aText8.getStr( )) ); + if (const SwParaPortion* pPara = GetPara()) + { + (void)xmlTextWriterStartElement(writer, BAD_CAST("SwParaPortion")); + TextFrameIndex nOffset(0); + const OUString& rText = GetText(); + (void)xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("ptr"), "%p", pPara); + const SwLineLayout* pLine = pPara; + if (IsFollow()) + { + nOffset += GetOffset(); + } + while (pLine) + { + (void)xmlTextWriterStartElement(writer, BAD_CAST("SwLineLayout")); + pLine->dumpAsXmlAttributes(writer, rText, nOffset); + const SwLinePortion* pPor = pLine->GetFirstPortion(); + while (pPor) + { + pPor->dumpAsXml(writer, rText, nOffset); + pPor = pPor->GetNextPortion(); + } + (void)xmlTextWriterEndElement(writer); + pLine = pLine->GetNext(); + } + (void)xmlTextWriterEndElement(writer); + } + + (void)xmlTextWriterEndElement(writer); +} + namespace sw { SwTextFrame * MakeTextFrame(SwTextNode & rNode, SwFrame *const pSibling, diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx index cadf89fb3531..2ed4113cddba 100644 --- a/sw/source/core/text/xmldump.cxx +++ b/sw/source/core/text/xmldump.cxx @@ -174,9 +174,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const switch ( GetType( ) ) { - case SwFrameType::Txt: - name = "txt"; - break; case SwFrameType::NoTxt: name = "notxt"; break; @@ -189,26 +186,6 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const dumpAsXmlAttributes( writer ); - if (IsTextFrame()) - { - const SwTextFrame *pTextFrame = static_cast<const SwTextFrame *>(this); - sw::MergedPara const*const pMerged(pTextFrame->GetMergedPara()); - if (pMerged) - { - (void)xmlTextWriterStartElement( writer, BAD_CAST( "merged" ) ); - (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "paraPropsNodeIndex" ), "%" SAL_PRIdINT32, sal_Int32(pMerged->pParaPropsNode->GetIndex()) ); - for (auto const& e : pMerged->extents) - { - (void)xmlTextWriterStartElement( writer, BAD_CAST( "extent" ) ); - (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "txtNodeIndex" ), "%" SAL_PRIdINT32, sal_Int32(e.pNode->GetIndex()) ); - (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "start" ), "%" SAL_PRIdINT32, e.nStart ); - (void)xmlTextWriterWriteFormatAttribute( writer, BAD_CAST( "end" ), "%" SAL_PRIdINT32, e.nEnd ); - (void)xmlTextWriterEndElement( writer ); - } - (void)xmlTextWriterEndElement( writer ); - } - } - (void)xmlTextWriterStartElement( writer, BAD_CAST( "infos" ) ); dumpInfosAsXml( writer ); (void)xmlTextWriterEndElement( writer ); @@ -227,57 +204,7 @@ void SwFrame::dumpAsXml( xmlTextWriterPtr writer ) const (void)xmlTextWriterEndElement( writer ); } - // Dump the children - if ( IsTextFrame( ) ) - { - const SwTextFrame *pTextFrame = static_cast<const SwTextFrame *>(this); - OUString aText = pTextFrame->GetText( ); - for ( int i = 0; i < 32; i++ ) - { - aText = aText.replace( i, '*' ); - } - auto nTextOffset = static_cast<sal_Int32>(pTextFrame->GetOffset()); - sal_Int32 nTextLength = aText.getLength() - nTextOffset; - if (const SwTextFrame* pTextFrameFollow = pTextFrame->GetFollow()) - { - nTextLength = static_cast<sal_Int32>(pTextFrameFollow->GetOffset() - pTextFrame->GetOffset()); - } - OString aText8 - = OUStringToOString(aText.subView(nTextOffset, nTextLength), RTL_TEXTENCODING_UTF8); - (void)xmlTextWriterWriteString( writer, - reinterpret_cast<const xmlChar *>(aText8.getStr( )) ); - if (const SwParaPortion* pPara = pTextFrame->GetPara()) - { - (void)xmlTextWriterStartElement(writer, BAD_CAST("SwParaPortion")); - TextFrameIndex nOffset(0); - const OUString& rText = pTextFrame->GetText(); - (void)xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("ptr"), "%p", pPara); - const SwLineLayout* pLine = pPara; - if (pTextFrame->IsFollow()) - { - nOffset += pTextFrame->GetOffset(); - } - while (pLine) - { - (void)xmlTextWriterStartElement(writer, BAD_CAST("SwLineLayout")); - pLine->dumpAsXmlAttributes(writer, rText, nOffset); - const SwLinePortion* pPor = pLine->GetFirstPortion(); - while (pPor) - { - pPor->dumpAsXml(writer, rText, nOffset); - pPor = pPor->GetNextPortion(); - } - (void)xmlTextWriterEndElement(writer); - pLine = pLine->GetNext(); - } - (void)xmlTextWriterEndElement(writer); - } - - } - else - { - dumpChildrenAsXml( writer ); - } + dumpChildrenAsXml( writer ); (void)xmlTextWriterEndElement( writer ); } }