writerfilter/source/dmapper/DomainMapper_Impl.cxx | 68 ++++++++--------- writerfilter/source/dmapper/DomainMapper_Impl.hxx | 84 +++++++++++----------- 2 files changed, 74 insertions(+), 78 deletions(-)
New commits: commit 244a2e5d62c212c5914412a25788a1618d02a76a Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Feb 6 13:19:48 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Apr 16 16:54:57 2025 +0200 writerfilter: move yet more members to SubstreamContext Conflicts: writerfilter/source/dmapper/DomainMapper_Impl.cxx writerfilter/source/dmapper/DomainMapper_Impl.hx Change-Id: I708375204226fbad502155f4d2efc81ecc206a31 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163052 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit 115569f6895f48b28e8e9e649ffbc72968a3bdeb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184260 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index a697e4c66999..9d964a51efff 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -343,8 +343,6 @@ DomainMapper_Impl::DomainMapper_Impl( m_bSetCitation( false ), m_bSetDateValue( false ), m_bIsFirstSection( true ), - m_bSdtEndDeferred(false), - m_bParaSdtEndDeferred(false), m_bStartTOC(false), m_bStartTOCHeaderFooter(false), m_bStartedTOC(false), @@ -360,15 +358,12 @@ DomainMapper_Impl::DomainMapper_Impl( m_bInNumberingImport(false), m_bInAnyTableImport( false ), m_bDiscardHeaderFooter( false ), - m_bHasFootnoteStyle(false), - m_bCheckFootnoteStyle(false), m_eSkipFootnoteState(SkipFootnoteSeparator::OFF), m_nFootnotes(-1), m_nEndnotes(-1), m_nFirstFootnoteIndex(-1), m_nFirstEndnoteIndex(-1), m_bLineNumberingSet( false ), - m_bIsInFootnoteProperties( false ), m_bIsParaMarkerChange( false ), m_bIsParaMarkerMove( false ), m_bRedlineImageInPreviousRun( false ), @@ -382,7 +377,6 @@ DomainMapper_Impl::DomainMapper_Impl( m_aSmartTagHandler(m_xComponentContext, m_xTextDocument), m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference<text::XTextRange>())), m_xAltChunkStartingRange(rMediaDesc.getUnpackedValueOrDefault("AltChunkStartingRange", uno::Reference<text::XTextRange>())), - m_bIsInTextBox(false), m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)), m_bIsAltChunk(rMediaDesc.getUnpackedValueOrDefault("AltChunkMode", false)), m_bReadOnly(rMediaDesc.getUnpackedValueOrDefault("ReadOnly", false)), @@ -687,7 +681,7 @@ void DomainMapper_Impl::RemoveDummyParaForTableInSection() void DomainMapper_Impl::AddDummyParaForTableInSection() { // Shapes, headers, and textboxes can't have sections. - if (IsInShape() || IsInHeaderFooter() || m_bIsInTextBox) + if (IsInShape() || IsInHeaderFooter() || m_StreamStateStack.top().bIsInTextBox) return; if (!m_aTextAppendStack.empty()) @@ -1448,7 +1442,7 @@ OUString DomainMapper_Impl::GetCurrentParaStyleName() // tdf#134784 except in the case of first paragraph of shapes to avoid bad fallback. // TODO fix this "highly inaccurate" m_sCurrentParaStyleName if ( !IsInShape() ) - sName = m_sCurrentParaStyleName; + sName = m_StreamStateStack.top().sCurrentParaStyleName; PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH); if ( pParaContext && pParaContext->isSet(PROP_PARA_STYLE_NAME) ) @@ -1687,22 +1681,22 @@ void DomainMapper_Impl::clearDeferredBreaks() void DomainMapper_Impl::setSdtEndDeferred(bool bSdtEndDeferred) { - m_bSdtEndDeferred = bSdtEndDeferred; + m_StreamStateStack.top().bSdtEndDeferred = bSdtEndDeferred; } bool DomainMapper_Impl::isSdtEndDeferred() const { - return m_bSdtEndDeferred; + return m_StreamStateStack.top().bSdtEndDeferred; } void DomainMapper_Impl::setParaSdtEndDeferred(bool bParaSdtEndDeferred) { - m_bParaSdtEndDeferred = bParaSdtEndDeferred; + m_StreamStateStack.top().bParaSdtEndDeferred = bParaSdtEndDeferred; } bool DomainMapper_Impl::isParaSdtEndDeferred() const { - return m_bParaSdtEndDeferred; + return m_StreamStateStack.top().bParaSdtEndDeferred; } static void lcl_MoveBorderPropertiesToFrame(std::vector<beans::PropertyValue>& rFrameProperties, @@ -3104,7 +3098,8 @@ void DomainMapper_Impl::applyToggleAttributes(const PropertyMapPtr& pPropertyMap nCharStyleRelief != css::awt::FontRelief::NONE || bCharStyleContoured || bCharStyleShadowed || nCharStyleStrikeThrough == awt::FontStrikeout::SINGLE || bCharStyleHidden) { - uno::Reference<beans::XPropertySet> xParaStylePropertySet = GetParagraphStyles()->getByName(m_sCurrentParaStyleName).get<uno::Reference<beans::XPropertySet>>(); + uno::Reference<beans::XPropertySet> const xParaStylePropertySet = + GetParagraphStyles()->getByName(m_StreamStateStack.top().sCurrentParaStyleName).get<uno::Reference<beans::XPropertySet>>(); float fParaStyleBold = css::awt::FontWeight::NORMAL; float fParaStyleBoldComplex = css::awt::FontWeight::NORMAL; css::awt::FontSlant eParaStylePosture = css::awt::FontSlant_NONE; @@ -4262,15 +4257,15 @@ void DomainMapper_Impl::StartCustomFootnote(const PropertyMapPtr pContext) return; assert(pContext->GetFootnote().is()); - m_bHasFootnoteStyle = true; - m_bCheckFootnoteStyle = !pContext->GetFootnoteStyle().isEmpty(); + m_StreamStateStack.top().bHasFootnoteStyle = true; + m_StreamStateStack.top().bCheckFootnoteStyle = !pContext->GetFootnoteStyle().isEmpty(); m_pFootnoteContext = pContext; } void DomainMapper_Impl::EndCustomFootnote() { - m_bHasFootnoteStyle = false; - m_bCheckFootnoteStyle = false; + m_StreamStateStack.top().bHasFootnoteStyle = false; + m_StreamStateStack.top().bCheckFootnoteStyle = false; } void DomainMapper_Impl::PushAnnotation() @@ -4730,14 +4725,14 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape m_aAnchoredStack.push(AnchoredContext(xTextContent)); uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY); - m_xEmbedded.set(m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW); + m_StreamStateStack.top().xEmbedded.set(m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xEmbeddedProperties(m_StreamStateStack.top().xEmbedded, uno::UNO_QUERY_THROW); xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_EMBEDDED_OBJECT), xShapePropertySet->getPropertyValue(getPropertyName(PROP_EMBEDDED_OBJECT))); xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), uno::Any(text::TextContentAnchorType_AS_CHARACTER)); // So that the original bitmap-only shape will be replaced by the embedded object. m_aAnchoredStack.top().bToRemove = true; m_aTextAppendStack.pop(); - appendTextContent(m_xEmbedded, uno::Sequence<beans::PropertyValue>()); + appendTextContent(m_StreamStateStack.top().xEmbedded, uno::Sequence<beans::PropertyValue>()); } else { @@ -4876,7 +4871,7 @@ void DomainMapper_Impl::UpdateEmbeddedShapeProps(const uno::Reference< drawing:: if (!xShape.is()) return; - uno::Reference<beans::XPropertySet> xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> const xEmbeddedProperties(m_StreamStateStack.top().xEmbedded, uno::UNO_QUERY_THROW); awt::Size aSize = xShape->getSize( ); xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_WIDTH), uno::Any(sal_Int32(aSize.Width))); xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_HEIGHT), uno::Any(sal_Int32(aSize.Height))); @@ -4886,7 +4881,7 @@ void DomainMapper_Impl::UpdateEmbeddedShapeProps(const uno::Reference< drawing:: xShapeProps->getPropertyValue(getPropertyName(PROP_DESCRIPTION))); xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_TITLE), xShapeProps->getPropertyValue(getPropertyName(PROP_TITLE))); - uno::Reference<container::XNamed> const xEmbedName(m_xEmbedded, uno::UNO_QUERY); + uno::Reference<container::XNamed> const xEmbedName(m_StreamStateStack.top().xEmbedded, uno::UNO_QUERY); uno::Reference<container::XNamed> const xShapeName(xShape, uno::UNO_QUERY); OUString const name(xShapeName->getName()); if (!name.isEmpty()) // setting empty name will throw @@ -5142,27 +5137,27 @@ void DomainMapper_Impl::HandleLineBreakClear(sal_Int32 nClear) { case NS_ooxml::LN_Value_ST_BrClear_left: // SwLineBreakClear::LEFT - m_oLineBreakClear = 1; + m_StreamStateStack.top().oLineBreakClear = 1; break; case NS_ooxml::LN_Value_ST_BrClear_right: // SwLineBreakClear::RIGHT - m_oLineBreakClear = 2; + m_StreamStateStack.top().oLineBreakClear = 2; break; case NS_ooxml::LN_Value_ST_BrClear_all: // SwLineBreakClear::ALL - m_oLineBreakClear = 3; + m_StreamStateStack.top().oLineBreakClear = 3; break; } } bool DomainMapper_Impl::HasLineBreakClear() const { - return m_oLineBreakClear.has_value(); + return m_StreamStateStack.top().oLineBreakClear.has_value(); } void DomainMapper_Impl::HandleLineBreak(const PropertyMapPtr& pPropertyMap) { - if (!m_oLineBreakClear.has_value()) + if (!m_StreamStateStack.top().oLineBreakClear.has_value()) { appendTextPortion(" ", pPropertyMap); return; @@ -5173,10 +5168,10 @@ void DomainMapper_Impl::HandleLineBreak(const PropertyMapPtr& pPropertyMap) uno::Reference<text::XTextContent> xLineBreak( GetTextFactory()->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, uno::UNO_QUERY); - xLineBreakProps->setPropertyValue("Clear", uno::Any(*m_oLineBreakClear)); + xLineBreakProps->setPropertyValue("Clear", uno::Any(*m_StreamStateStack.top().oLineBreakClear)); appendTextContent(xLineBreak, pPropertyMap->GetPropertyValues()); } - m_oLineBreakClear.reset(); + m_StreamStateStack.top().oLineBreakClear.reset(); } static sal_Int16 lcl_ParseNumberingType( std::u16string_view rCommand ) @@ -5789,7 +5784,7 @@ void DomainMapper_Impl::ChainTextFrames() void DomainMapper_Impl::PushTextBoxContent() { - if (m_bIsInTextBox) + if (m_StreamStateStack.top().bIsInTextBox) return; try @@ -5804,7 +5799,7 @@ void DomainMapper_Impl::PushTextBoxContent() m_xPendingTextBoxFrames.push(xTBoxFrame); m_aTextAppendStack.push(TextAppendContext(uno::Reference<text::XTextAppend>(xTBoxFrame, uno::UNO_QUERY_THROW), {})); - m_bIsInTextBox = true; + m_StreamStateStack.top().bIsInTextBox = true; appendTableManager(); appendTableHandler(); @@ -5818,7 +5813,7 @@ void DomainMapper_Impl::PushTextBoxContent() void DomainMapper_Impl::PopTextBoxContent() { - if (!m_bIsInTextBox || m_xPendingTextBoxFrames.empty()) + if (!m_StreamStateStack.top().bIsInTextBox || m_xPendingTextBoxFrames.empty()) return; if (uno::Reference<text::XTextFrame>(m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY).is()) @@ -5831,7 +5826,7 @@ void DomainMapper_Impl::PopTextBoxContent() RemoveLastParagraph(); m_aTextAppendStack.pop(); - m_bIsInTextBox = false; + m_StreamStateStack.top().bIsInTextBox = false; } } @@ -9275,7 +9270,8 @@ void DomainMapper_Impl::ImportGraphic(const writerfilter::Reference<Properties> // Update the shape properties if it is embedded object. - if(m_xEmbedded.is()){ + if (m_StreamStateStack.top().xEmbedded.is()) + { if (m_pGraphicImport->GetXShapeObject()) m_pGraphicImport->GetXShapeObject()->setPosition( m_pGraphicImport->GetGraphicObjectPosition()); @@ -9284,7 +9280,7 @@ void DomainMapper_Impl::ImportGraphic(const writerfilter::Reference<Properties> UpdateEmbeddedShapeProps(xShape); if (m_eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) { - uno::Reference<beans::XPropertySet> xEmbeddedProps(m_xEmbedded, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> const xEmbeddedProps(m_StreamStateStack.top().xEmbedded, uno::UNO_QUERY); xEmbeddedProps->setPropertyValue("AnchorType", uno::Any(text::TextContentAnchorType_AT_CHARACTER)); xEmbeddedProps->setPropertyValue("IsFollowingTextFlow", uno::Any(m_pGraphicImport->GetLayoutInCell())); uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); @@ -9370,7 +9366,7 @@ void DomainMapper_Impl::ImportGraphic(const writerfilter::Reference<Properties> // Clear the reference, so in case the embedded object is inside a // TextFrame, we won't try to resize it (to match the size of the // TextFrame) here. - m_xEmbedded.clear(); + m_StreamStateStack.top().xEmbedded.clear(); m_pGraphicImport.clear(); } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index ee2f446c96ab..1f4e7dc79863 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -163,6 +163,24 @@ enum StoredRedlines NONE }; +struct RubyInfo +{ + OUString sRubyText; + OUString sRubyStyle; + sal_uInt32 nSprmId; + sal_uInt32 nRubyAlign; + sal_uInt32 nHps; + sal_uInt32 nHpsBaseText; + + RubyInfo(): + nSprmId(0), + nRubyAlign(0), + nHps(0), + nHpsBaseText(0) + { + } +}; + enum class SubstreamType { Body, @@ -224,6 +242,18 @@ struct SubstreamContext sal_Int32 nTableCellDepth = 0; /// If the next tab should be ignored, used for footnotes. bool bCheckFirstFootnoteTab = false; + std::optional<sal_Int16> oLineBreakClear; + bool bIsInTextBox = false; + css::uno::Reference<css::text::XTextContent> xEmbedded; + /// If we want to set "sdt end" on the next character context. + bool bSdtEndDeferred = false; + /// If we want to set "paragraph sdt end" on the next paragraph context. + bool bParaSdtEndDeferred = false; + OUString sCurrentParaStyleName; ///< highly inaccurate. Overwritten by "overlapping" paragraphs like flys. + bool bHasFootnoteStyle = false; + bool bCheckFootnoteStyle = false; + bool bIsInFootnoteProperties = false; + RubyInfo aRubyInfo; bool bDummyParaAddedForTableInSection = false; // tdf#161631 }; @@ -420,24 +450,6 @@ struct AnnotationPosition css::uno::Reference<css::text::XTextRange> m_xEnd; }; -struct RubyInfo -{ - OUString sRubyText; - OUString sRubyStyle; - sal_uInt32 nSprmId; - sal_uInt32 nRubyAlign; - sal_uInt32 nHps; - sal_uInt32 nHpsBaseText; - - RubyInfo(): - nSprmId(0), - nRubyAlign(0), - nHps(0), - nHpsBaseText(0) - { - } -}; - struct LineNumberSettings { sal_Int32 nDistance; @@ -522,7 +534,6 @@ private: // cache next available number, expensive to repeatedly compute std::optional<int> m_xNextUnusedCharacterStyleNo; css::uno::Reference<css::text::XText> m_xBodyText; - css::uno::Reference<css::text::XTextContent> m_xEmbedded; std::stack<TextAppendContext> m_aTextAppendStack; std::stack<AnchoredContext> m_aAnchoredStack; @@ -539,10 +550,6 @@ private: bool m_bSetCitation; bool m_bSetDateValue; bool m_bIsFirstSection; - /// If we want to set "sdt end" on the next character context. - bool m_bSdtEndDeferred; - /// If we want to set "paragraph sdt end" on the next paragraph context. - bool m_bParaSdtEndDeferred; bool m_bStartTOC; bool m_bStartTOCHeaderFooter; /// If we got any text that is the pre-rendered result of the TOC field. @@ -596,7 +603,6 @@ private: PropertyMapPtr m_pLastCharacterContext; ::std::vector<DeletableTabStop> m_aCurrentTabStops; - OUString m_sCurrentParaStyleName; //highly inaccurate. Overwritten by "overlapping" paragraphs like comments, flys. OUString m_sDefaultParaStyleName; //caches the ConvertedStyleName of the default paragraph style bool m_bInDocDefaultsImport; bool m_bInStyleSheetImport; //in import of fonts, styles, lists or lfos @@ -604,8 +610,6 @@ private: bool m_bInAnyTableImport; //in import of fonts, styles, lists or lfos bool m_bDiscardHeaderFooter; PropertyMapPtr m_pFootnoteContext; - bool m_bHasFootnoteStyle; - bool m_bCheckFootnoteStyle; /// Skip paragraphs from the <w:separator/> footnote SkipFootnoteSeparator m_eSkipFootnoteState; /// preload footnotes and endnotes @@ -616,9 +620,7 @@ private: sal_Int32 m_nFirstEndnoteIndex; bool m_bLineNumberingSet; - bool m_bIsInFootnoteProperties; - RubyInfo m_aRubyInfo; //registered frame properties std::vector<css::beans::PropertyValue> m_aFrameProperties; css::uno::Reference<css::text::XTextRange> m_xFrameStartRange; @@ -680,14 +682,12 @@ public: std::deque<sal_Int32> m_aFootnoteIds; std::deque<sal_Int32> m_aEndnoteIds; - bool m_bIsInTextBox; private: bool m_bIsNewDoc; bool m_bIsAltChunk = false; /// Document is loaded for viewing, not editing. bool m_bReadOnly = false; bool m_bIsReadGlossaries; - std::optional<sal_Int16> m_oLineBreakClear; public: DomainMapper_Impl( @@ -750,13 +750,13 @@ public: void SetIsDecimalComma() { m_bIsDecimalComma = true; }; void SetIsLastParagraphInSection( bool bIsLast ); bool GetIsLastParagraphInSection() const { return m_StreamStateStack.top().bIsLastParaInSection; } - void SetRubySprmId( sal_uInt32 nSprmId) { m_aRubyInfo.nSprmId = nSprmId ; } + void SetRubySprmId(sal_uInt32 const nSprmId) { m_StreamStateStack.top().aRubyInfo.nSprmId = nSprmId; } void SetRubyText( OUString const &sText, OUString const &sStyle) { - m_aRubyInfo.sRubyText = sText; - m_aRubyInfo.sRubyStyle = sStyle; + m_StreamStateStack.top().aRubyInfo.sRubyText = sText; + m_StreamStateStack.top().aRubyInfo.sRubyStyle = sStyle; } - const RubyInfo & GetRubyInfo() const { return m_aRubyInfo;} - void SetRubyInfo(const RubyInfo & rInfo) { m_aRubyInfo = rInfo;} + const RubyInfo & GetRubyInfo() const { return m_StreamStateStack.top().aRubyInfo; } + void SetRubyInfo(const RubyInfo & rInfo) { m_StreamStateStack.top().aRubyInfo = rInfo; } void SetIsLastSectionGroup( bool bIsLast ); bool GetIsLastSectionGroup() const { return m_bIsLastSectionGroup;} @@ -884,7 +884,7 @@ public: void IncorporateTabStop( const DeletableTabStop &aTabStop ); css::uno::Sequence<css::style::TabStop> GetCurrentTabStopAndClear(); - void SetCurrentParaStyleName(const OUString& sStringValue) {m_sCurrentParaStyleName = sStringValue;} + void SetCurrentParaStyleName(const OUString& rString) { m_StreamStateStack.top().sCurrentParaStyleName = rString; } OUString GetCurrentParaStyleName(); OUString GetDefaultParaStyleName(); @@ -928,10 +928,10 @@ public: void StartCustomFootnote(const PropertyMapPtr pContext); void EndCustomFootnote(); - bool IsInCustomFootnote() const { return m_bHasFootnoteStyle; } - bool CheckFootnoteStyle() const { return m_bCheckFootnoteStyle; } - void SetHasFootnoteStyle(bool bVal) { m_bHasFootnoteStyle = bVal; } - void SetCheckFootnoteStyle(bool bVal) { m_bCheckFootnoteStyle = bVal; } + bool IsInCustomFootnote() const { return m_StreamStateStack.top().bHasFootnoteStyle; } + bool CheckFootnoteStyle() const { return m_StreamStateStack.top().bCheckFootnoteStyle; } + void SetHasFootnoteStyle(bool const bVal) { m_StreamStateStack.top().bHasFootnoteStyle = bVal; } + void SetCheckFootnoteStyle(bool const bVal) { m_StreamStateStack.top().bCheckFootnoteStyle = bVal; } const PropertyMapPtr& GetFootnoteContext() const { return m_pFootnoteContext; } @@ -1071,8 +1071,8 @@ public: const LineNumberSettings& GetLineNumberSettings() const { return m_aLineNumberSettings;} void SetLineNumberSettings(const LineNumberSettings& rSet) { m_aLineNumberSettings = rSet;} - void SetInFootnoteProperties(bool bSet) { m_bIsInFootnoteProperties = bSet;} - bool IsInFootnoteProperties() const { return m_bIsInFootnoteProperties;} + void SetInFootnoteProperties(bool const bSet) { m_StreamStateStack.top().bIsInFootnoteProperties = bSet; } + bool IsInFootnoteProperties() const { return m_StreamStateStack.top().bIsInFootnoteProperties; } bool IsInComments() const { return m_StreamStateStack.top().eSubstreamType == SubstreamType::Annotation; };