diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2024-02-05 20:49:31 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2024-02-06 13:03:36 +0100 |
commit | 4b2e61cb8b5429e08f43c5a70eaa1dd27c40ddab (patch) | |
tree | b95ab2f9093452cdc82ca7e6c0f5706f7521a20c | |
parent | 23abe10fb2d058dc25acd31ea089123c3cbe515c (diff) |
writerfilter: move more members to SubstreamContext
m_bIgnoreNextTab can be removed altogether, it is only set to true in
one place and immediately checked and reset in the next 2 statements.
Don't move m_bHasFtnSep, somehow breaks lots of tests.
Change-Id: I24bcb3ced839d2c87a367e8a1bcd7664361f9975
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163042
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 18 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 86 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 27 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 4 |
4 files changed, 61 insertions, 74 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index c5c487f37cf5..0764a03b908d 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -3309,10 +3309,10 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) m_pImpl->m_StreamStateStack.top().nTableDepth--; break; case NS_ooxml::LN_tcStart: - m_pImpl->m_nTableCellDepth++; + m_pImpl->m_StreamStateStack.top().nTableCellDepth++; break; case NS_ooxml::LN_tcEnd: - m_pImpl->m_nTableCellDepth--; + m_pImpl->m_StreamStateStack.top().nTableCellDepth--; break; case NS_ooxml::LN_glow_glow: case NS_ooxml::LN_shadow_shadow: @@ -4306,20 +4306,16 @@ void DomainMapper::lcl_utext(const sal_Unicode *const data_, size_t len) } else if (len == 1 && sText[0] == '\t' ) { - if ( m_pImpl->m_bCheckFirstFootnoteTab && m_pImpl->IsInFootOrEndnote() ) + if (m_pImpl->m_StreamStateStack.top().bCheckFirstFootnoteTab && m_pImpl->IsInFootOrEndnote()) { // Allow MSO to emulate LO footnote text starting at left margin - only meaningful with hanging indent - m_pImpl->m_bCheckFirstFootnoteTab = false; + m_pImpl->m_StreamStateStack.top().bCheckFirstFootnoteTab = false; sal_Int32 nFirstLineIndent = 0; m_pImpl->GetAnyProperty(PROP_PARA_FIRST_LINE_INDENT, m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)) >>= nFirstLineIndent; if ( nFirstLineIndent < 0 ) - m_pImpl->m_bIgnoreNextTab = true; - } - - if ( m_pImpl->m_bIgnoreNextTab ) - { - m_pImpl->m_bIgnoreNextTab = false; - return; + { + return; + } } } if (!m_pImpl->hasTableManager()) diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index af14dffa8cc5..1d429c82463f 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -384,14 +384,9 @@ DomainMapper_Impl::DomainMapper_Impl( m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)), m_bIsAltChunk(rMediaDesc.getUnpackedValueOrDefault("AltChunkMode", false)), m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)), - m_nTableCellDepth(0), - m_bHasFtn(false), m_bHasFtnSep(false), - m_bCheckFirstFootnoteTab(false), - m_bIgnoreNextTab(false), m_bIsSplitPara(false), m_bIsActualParagraphFramed( false ), - m_bParaAutoBefore(false), m_bSaxError(false) { m_StreamStateStack.emplace(); // add state for document body @@ -956,7 +951,7 @@ bool DomainMapper_Impl::GetIsFirstParagraphInSection( bool bAfterRedline ) const void DomainMapper_Impl::SetIsFirstParagraphInShape(bool bIsFirst) { - m_bIsFirstParaInShape = bIsFirst; + m_StreamStateStack.top().bIsFirstParaInShape = bIsFirst; } void DomainMapper_Impl::SetIsDummyParaAddedForTableInSection( bool bIsAdded ) @@ -2346,7 +2341,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con (GetIsFirstParagraphInSection() && GetSectionContext() && GetSectionContext()->IsFirstSection()) || (m_StreamStateStack.top().bFirstParagraphInCell && 0 < m_StreamStateStack.top().nTableDepth - && m_StreamStateStack.top().nTableDepth == m_nTableCellDepth)) + && m_StreamStateStack.top().nTableDepth == m_StreamStateStack.top().nTableCellDepth)) { // export requires grabbag to match top_margin, so keep them in sync if (nBeforeAutospacing && bIsAutoSet) @@ -2621,7 +2616,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con assert( isNumberingViaRule == (itNumberingRules != aProperties.end()) ); isNumberingViaRule = (itNumberingRules != aProperties.end()); - if (m_xPreviousParagraph.is() && (isNumberingViaRule || isNumberingViaStyle)) + if (m_StreamStateStack.top().xPreviousParagraph.is() + && (isNumberingViaRule || isNumberingViaStyle)) { // This textnode has numbering. Look up the numbering style name of the current and previous paragraph. OUString aCurrentNumberingName; @@ -2634,7 +2630,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con aCurrentNumberingName = xCurrentNumberingRules->getName(); try { - uno::Reference<container::XNamed> xPreviousNumberingRules(m_xPreviousParagraph->getPropertyValue("NumberingRules"), uno::UNO_QUERY_THROW); + uno::Reference<container::XNamed> xPreviousNumberingRules( + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("NumberingRules"), + uno::UNO_QUERY_THROW); aPreviousNumberingName = xPreviousNumberingRules->getName(); } catch (const uno::Exception&) @@ -2642,13 +2640,13 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con TOOLS_WARN_EXCEPTION("writerfilter", "DomainMapper_Impl::finishParagraph NumberingRules"); } } - else if (m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("NumberingStyleName") + else if (m_StreamStateStack.top().xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("NumberingStyleName") // don't update before tables && (m_StreamStateStack.top().nTableDepth == 0 || !m_StreamStateStack.top().bFirstParagraphInCell)) { aCurrentNumberingName = GetListStyleName(nListId); - m_xPreviousParagraph->getPropertyValue("NumberingStyleName") >>= aPreviousNumberingName; + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("NumberingStyleName") >>= aPreviousNumberingName; } // tdf#133363: remove extra auto space even for mixed list styles @@ -2657,21 +2655,23 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con || !isNumberingViaRule)) { uno::Sequence<beans::PropertyValue> aPrevPropertiesSeq; - m_xPreviousParagraph->getPropertyValue("ParaInteropGrabBag") >>= aPrevPropertiesSeq; + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("ParaInteropGrabBag") >>= aPrevPropertiesSeq; const auto & rPrevProperties = aPrevPropertiesSeq; - bool bParaAutoBefore = m_bParaAutoBefore || std::any_of(rPrevProperties.begin(), rPrevProperties.end(), [](const beans::PropertyValue& rValue) + bool bParaAutoBefore = m_StreamStateStack.top().bParaAutoBefore + || std::any_of(rPrevProperties.begin(), rPrevProperties.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "ParaTopMarginBeforeAutoSpacing"; }); // if style based spacing was set to auto in the previous paragraph, style of the actual paragraph must be the same - if (bParaAutoBefore && !m_bParaAutoBefore && m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ParaStyleName")) + if (bParaAutoBefore && !m_StreamStateStack.top().bParaAutoBefore + && m_StreamStateStack.top().xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ParaStyleName")) { auto itParaStyle = std::find_if(aProperties.begin(), aProperties.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "ParaStyleName"; }); bParaAutoBefore = itParaStyle != aProperties.end() && - m_xPreviousParagraph->getPropertyValue("ParaStyleName") == itParaStyle->Value; + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("ParaStyleName") == itParaStyle->Value; } // There was a previous textnode and it had the same numbering. if (bParaAutoBefore) @@ -2694,7 +2694,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con if (bPrevParaAutoAfter) { // Previous after spacing is set to auto, set previous after space to 0. - m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::Any(static_cast<sal_Int32>(0))); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::Any(static_cast<sal_Int32>(0))); } } } @@ -2718,9 +2718,9 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con } xTextRange = xTextAppend->finishParagraph( comphelper::containerToSequence(aProperties) ); - m_xPreviousParagraph.set(xTextRange, uno::UNO_QUERY); + m_StreamStateStack.top().xPreviousParagraph.set(xTextRange, uno::UNO_QUERY); - if (m_xPreviousParagraph.is() && // null for SvxUnoTextBase + if (m_StreamStateStack.top().xPreviousParagraph.is() && // null for SvxUnoTextBase (isNumberingViaStyle || isNumberingViaRule)) { assert(pParaContext); @@ -2730,16 +2730,16 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con pList->GetAbstractDefinition(); if (pAbsList && // SvxUnoTextRange doesn't have ListId - m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ListId")) + m_StreamStateStack.top().xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ListId")) { OUString paraId; - m_xPreviousParagraph->getPropertyValue("ListId") >>= paraId; + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("ListId") >>= paraId; if (!paraId.isEmpty()) // must be on some list? { OUString const listId = pAbsList->MapListId(paraId); if (listId != paraId) { - m_xPreviousParagraph->setPropertyValue("ListId", uno::Any(listId)); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue("ListId", uno::Any(listId)); } } } @@ -2760,8 +2760,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con // TODO: Not tested variant with different levels override in different lists. // Probably m_aListOverrideApplied as a set of overridden listids is not sufficient // and we need to register level overrides separately. - m_xPreviousParagraph->setPropertyValue("ParaIsNumberingRestart", uno::Any(true)); - m_xPreviousParagraph->setPropertyValue("NumberingStartValue", uno::Any(nOverrideLevel)); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue("ParaIsNumberingRestart", uno::Any(true)); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue("NumberingStartValue", uno::Any(nOverrideLevel)); m_aListOverrideApplied.insert(nListId); } } @@ -2994,8 +2994,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con } } - if (m_bIsFirstParaInShape) - m_bIsFirstParaInShape = false; + if (m_StreamStateStack.top().bIsFirstParaInShape) + m_StreamStateStack.top().bIsFirstParaInShape = false; if (pParaContext) { @@ -3009,13 +3009,13 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con // don't overwrite m_bFirstParagraphInCell in table separator nodes // and in text boxes anchored to the first paragraph of table cells if (0 < m_StreamStateStack.top().nTableDepth - && m_StreamStateStack.top().nTableDepth == m_nTableCellDepth + && m_StreamStateStack.top().nTableDepth == m_StreamStateStack.top().nTableCellDepth && !IsInShape() && !IsInComments()) { m_StreamStateStack.top().bFirstParagraphInCell = false; } - m_bParaAutoBefore = false; + m_StreamStateStack.top().bParaAutoBefore = false; m_StreamStateStack.top().bParaWithInlineObject = false; #ifdef DBG_UTIL @@ -3949,7 +3949,7 @@ void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote ) { SAL_WARN_IF(m_StreamStateStack.top().eSubstreamType != SubstreamType::Body, "writerfilter.dmapper", "PushFootOrEndnote() is called from another foot or endnote"); m_StreamStateStack.top().eSubstreamType = bIsFootnote ? SubstreamType::Footnote : SubstreamType::Endnote; - m_bCheckFirstFootnoteTab = true; + m_StreamStateStack.top().bCheckFirstFootnoteTab = true; try { // Redlines outside the footnote should not affect footnote content @@ -4464,9 +4464,6 @@ void DomainMapper_Impl::PopFootOrEndnote() if (!IsRTFImport() && !bCopied) RemoveLastParagraph(); - // In case the foot or endnote did not contain a tab. - m_bIgnoreNextTab = false; - if (!m_aTextAppendStack.empty()) m_aTextAppendStack.pop(); @@ -4953,16 +4950,16 @@ bool DomainMapper_Impl::IsDiscardHeaderFooter() const void DomainMapper_Impl::ClearPreviousParagraph() { // in table cells, set bottom auto margin of last paragraph to 0, except in paragraphs with numbering - if ((m_StreamStateStack.top().nTableDepth == (m_nTableCellDepth + 1)) - && m_xPreviousParagraph.is() + if ((m_StreamStateStack.top().nTableDepth == (m_StreamStateStack.top().nTableCellDepth + 1)) + && m_StreamStateStack.top().xPreviousParagraph.is() && hasTableManager() && getTableManager().isCellLastParaAfterAutospacing()) { - uno::Reference<container::XNamed> xPreviousNumberingRules(m_xPreviousParagraph->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + uno::Reference<container::XNamed> xPreviousNumberingRules(m_StreamStateStack.top().xPreviousParagraph->getPropertyValue("NumberingRules"), uno::UNO_QUERY); if ( !xPreviousNumberingRules.is() || xPreviousNumberingRules->getName().isEmpty() ) - m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::Any(static_cast<sal_Int32>(0))); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::Any(static_cast<sal_Int32>(0))); } - m_xPreviousParagraph.clear(); + m_StreamStateStack.top().xPreviousParagraph.clear(); // next table paragraph will be first paragraph in a cell m_StreamStateStack.top().bFirstParagraphInCell = true; @@ -9728,10 +9725,6 @@ void DomainMapper_Impl::substream(Id rName, } #endif - // Save "has footnote" state, which is specific to a section in the body - // text, so state from substreams is not relevant. - bool bHasFtn = m_bHasFtn; - //finalize any waiting frames before starting alternate streams CheckUnregisteredFrameConversion(); ExecuteFrameConversion(); @@ -9742,6 +9735,8 @@ void DomainMapper_Impl::substream(Id rName, appendTableHandler(); getTableManager().startLevel(); + // Save "has footnote" state, which is specific to a section in the body + // text, so state from substreams is not relevant. m_StreamStateStack.emplace(); //import of page header/footer @@ -9819,18 +9814,17 @@ void DomainMapper_Impl::substream(Id rName, break; } - assert(!m_StreamStateStack.empty()); m_StreamStateStack.pop(); + assert(!m_StreamStateStack.empty()); getTableManager().endLevel(); popTableManager(); - m_bHasFtn = bHasFtn; switch(rName) { case NS_ooxml::LN_footnote: case NS_ooxml::LN_endnote: - m_bHasFtn = true; + m_StreamStateStack.top().bHasFtn = true; break; } @@ -9849,7 +9843,7 @@ void DomainMapper_Impl::commentProps(const OUString& sId, const CommentPropertie bool DomainMapper_Impl::handlePreviousParagraphBorderInBetween() const { - if (!m_xPreviousParagraph.is()) + if (!m_StreamStateStack.top().xPreviousParagraph.is()) return false; // Connected borders ("ParaIsConnectBorder") are always on by default @@ -9857,7 +9851,7 @@ bool DomainMapper_Impl::handlePreviousParagraphBorderInBetween() const // between is used. So this is not the best, but easiest way to check // is previous paragraph has border in between. bool bConnectBorders = true; - m_xPreviousParagraph->getPropertyValue(getPropertyName(PROP_PARA_CONNECT_BORDERS)) >>= bConnectBorders; + m_StreamStateStack.top().xPreviousParagraph->getPropertyValue(getPropertyName(PROP_PARA_CONNECT_BORDERS)) >>= bConnectBorders; if (bConnectBorders) return false; @@ -9866,7 +9860,7 @@ bool DomainMapper_Impl::handlePreviousParagraphBorderInBetween() const // method is called). So current paragraph will get border above, but // also need to ensure, that no unexpected bottom border are remaining in previous // paragraph: since ParaIsConnectBorder=false it will be displayed in unexpected way. - m_xPreviousParagraph->setPropertyValue(getPropertyName(PROP_BOTTOM_BORDER), uno::Any(table::BorderLine2())); + m_StreamStateStack.top().xPreviousParagraph->setPropertyValue(getPropertyName(PROP_BOTTOM_BORDER), uno::Any(table::BorderLine2())); return true; } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 0464d5d9fba1..bd1d55253298 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -214,6 +214,16 @@ struct SubstreamContext bool bParaWithInlineObject = false; /// This is a continuation of already finished paragraph - e.g., first in an index section bool bRemoveThisParagraph = false; + bool bIsFirstParaInShape = false; + /// If the current section has footnotes. + bool bHasFtn = false; + css::uno::Reference<css::beans::XPropertySet> xPreviousParagraph; + /// Current paragraph has automatic before spacing. + bool bParaAutoBefore = false; + /// Raw table cell depth. + sal_Int32 nTableCellDepth = 0; + /// If the next tab should be ignored, used for footnotes. + bool bCheckFirstFootnoteTab = false; }; /// Information about a paragraph to be finished after a field end. @@ -626,7 +636,6 @@ private: // text ZWSPs to keep the change tracking of the image in Writer.) bool m_bRedlineImageInPreviousRun; - bool m_bIsFirstParaInShape = false; bool m_bDummyParaAddedForTableInSection; bool m_bTextFrameInserted; bool m_bIsLastSectionGroup; @@ -748,7 +757,7 @@ public: void SetIsFirstParagraphInSectionAfterRedline( bool bIsFirstAfterRedline ); bool GetIsFirstParagraphInSection( bool bAfterRedline = false ) const; void SetIsFirstParagraphInShape(bool bIsFirst); - bool GetIsFirstParagraphInShape() const { return m_bIsFirstParaInShape; } + bool GetIsFirstParagraphInShape() const { return m_StreamStateStack.top().bIsFirstParaInShape; } void SetIsDummyParaAddedForTableInSection( bool bIsAdded ); bool GetIsDummyParaAddedForTableInSection() const { return m_bDummyParaAddedForTableInSection;} @@ -1140,18 +1149,9 @@ public: /// Document background color, applied to every page style. std::optional<sal_Int32> m_oBackgroundColor; - /// Raw table cell depth. - sal_Int32 m_nTableCellDepth; - - /// If the current section has footnotes. - bool m_bHasFtn; /// If the current section has a footnote separator. bool m_bHasFtnSep; - /// If the next tab should be ignored, used for footnotes. - bool m_bCheckFirstFootnoteTab; - bool m_bIgnoreNextTab; - /// Paragraphs with anchored objects in the current section. std::vector<AnchoredObjectsInfo> m_aAnchoredObjectAnchors; @@ -1196,7 +1196,7 @@ public: bool IsForceGenericFields() const { return m_bForceGenericFields; } - void SetParaAutoBefore(bool bParaAutoBefore) { m_bParaAutoBefore = bParaAutoBefore; } + void SetParaAutoBefore(bool const bParaAutoBefore) { m_StreamStateStack.top().bParaAutoBefore = bParaAutoBefore; } /// Forget about the previous paragraph, as it's not inside the same /// start/end node. @@ -1237,9 +1237,6 @@ private: // Start a new index section; if needed, finish current paragraph css::uno::Reference<css::beans::XPropertySet> StartIndexSectionChecked(const OUString& sServiceName); std::vector<css::uno::Reference< css::drawing::XShape > > m_vTextFramesForChaining ; - css::uno::Reference<css::beans::XPropertySet> m_xPreviousParagraph; - /// Current paragraph has automatic before spacing. - bool m_bParaAutoBefore; /// SAXException was seen so document will be abandoned bool m_bSaxError; diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 114de3b6198e..96bec18a14fa 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1142,7 +1142,7 @@ void SectionPropertyMap::HandleMarginsHeaderFooter(DomainMapper_Impl& rDM_Impl) // Check for missing footnote separator only in case there is at least // one footnote. - if (rDM_Impl.m_bHasFtn && !rDM_Impl.m_bHasFtnSep) + if (rDM_Impl.m_StreamStateStack.top().bHasFtn && !rDM_Impl.m_bHasFtnSep) { // Set footnote line width to zero, document has no footnote separator. Insert(PROP_FOOTNOTE_LINE_RELATIVE_WIDTH, uno::Any(sal_Int32(0))); @@ -1880,7 +1880,7 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) if ( !rDM_Impl.IsInFootOrEndnote() && !rDM_Impl.IsInComments() ) { - rDM_Impl.m_bHasFtn = false; + rDM_Impl.m_StreamStateStack.top().bHasFtn = false; rDM_Impl.m_bHasFtnSep = false; } } |