include/xmloff/txtimp.hxx | 2 - include/xmloff/xmlimp.hxx | 1 xmloff/source/core/xmlimp.cxx | 9 +++++ xmloff/source/text/txtimp.cxx | 65 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 70 insertions(+), 7 deletions(-)
New commits: commit 4db3cdb9536594ee2b2700e63d4f0f98983814aa Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Tue Sep 26 15:03:58 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Sat Oct 7 20:47:43 2023 +0200 tdf#156146 xmloff: ODF import: add backward compatibility hack As a follow-up to ade0a153f453500f15343380ac937252992733e0 "tdf#114287 xmloff: ODF import: fix text:list override of list style", add some ugly compatibility hack to preserve the visual layout of documents produced by LO versions before 7.6. Override the left/first-line margin of the applied numbering rules with what is in the paragraph or paragraph style, and try to do this only in the specific situation where the list style is the same. Change-Id: I1f4520c9bf9d2257d2e3864e4ddb2d28451bbd2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157284 Tested-by: Jenkins Tested-by: Gabor Kelemen <kelem...@ubuntu.com> Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> (cherry picked from commit 7cf5faec6fdbc27dd77d2d36fb2ff205322cba0d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157325 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/include/xmloff/txtimp.hxx b/include/xmloff/txtimp.hxx index 218db6fa7acd..24caf36e53d7 100644 --- a/include/xmloff/txtimp.hxx +++ b/include/xmloff/txtimp.hxx @@ -170,7 +170,7 @@ public: // Add parameter <bOutlineLevelAttrFound> (#i73509#) // Add parameter <bSetListAttrs> in order to suppress the handling of the list attributes (#i80724#) OUString SetStyleAndAttrs( - SvXMLImport const & rImport, + SvXMLImport & rImport, const css::uno::Reference< css::text::XTextCursor >& rCursor, const OUString& rStyleName, bool bPara, diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx index 664e26056cef..f833e2b9aedb 100644 --- a/include/xmloff/xmlimp.hxx +++ b/include/xmloff/xmlimp.hxx @@ -554,6 +554,7 @@ public: static const sal_uInt16 LO_6x = 60 | LO_flag; static const sal_uInt16 LO_63x = 63 | LO_flag; static const sal_uInt16 LO_7x = 70 | LO_flag; + static const sal_uInt16 LO_76 = 76 | LO_flag; static const sal_uInt16 LO_New = 100 | LO_flag; static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16; diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 1a177c5a11e5..98d4dc3f4971 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -219,7 +219,14 @@ public: } else if ('7' == loVersion[0]) { - mnGeneratorVersion = SvXMLImport::LO_7x; + if (loVersion.getLength() > 2 && loVersion[2] == '6') + { + mnGeneratorVersion = SvXMLImport::LO_76; // 7.6 + } + else + { + mnGeneratorVersion = SvXMLImport::LO_7x; + } } else { diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx index b31c2b6ab99b..1e17f9921df0 100644 --- a/xmloff/source/text/txtimp.cxx +++ b/xmloff/source/text/txtimp.cxx @@ -1003,8 +1003,40 @@ static bool lcl_HasListStyle( const OUString& sStyleName, return bRet; } + +namespace { + +auto IsPropertySet(uno::Reference<container::XNameContainer> const& rxParaStyles, + uno::Reference<beans::XPropertySet> const& rxPropSet, + OUString const& rProperty) +{ + uno::Reference<beans::XPropertyState> const xPropState(rxPropSet, uno::UNO_QUERY); + // note: this is true only if it is set in automatic style + if (xPropState->getPropertyState(rProperty) == beans::PropertyState_DIRECT_VALUE) + { + return true; + } + // check if it is set by any parent common style + OUString style; + rxPropSet->getPropertyValue("ParaStyleName") >>= style; + while (!style.isEmpty() && rxParaStyles.is() && rxParaStyles->hasByName(style)) + { + uno::Reference<style::XStyle> const xStyle(rxParaStyles->getByName(style), uno::UNO_QUERY); + assert(xStyle.is()); + uno::Reference<beans::XPropertyState> const xStyleProps(xStyle, uno::UNO_QUERY); + if (xStyleProps->getPropertyState(rProperty) == beans::PropertyState_DIRECT_VALUE) + { + return true; + } + style = xStyle->getParentStyle(); + } + return false; +}; + +} // namespace + OUString XMLTextImportHelper::SetStyleAndAttrs( - SvXMLImport const & rImport, + SvXMLImport & rImport, const Reference < XTextCursor >& rCursor, const OUString& rStyleName, bool bPara, @@ -1086,13 +1118,16 @@ OUString XMLTextImportHelper::SetStyleAndAttrs( bool bNumberingIsNumber(true); // Assure that list style of automatic paragraph style is applied at paragraph. (#i101349#) bool bApplyNumRules(pStyle && pStyle->IsListStyleSet()); + bool bApplyNumRulesFix(false); if (pListBlock) { // the xNumRules is always created, even without a list-style-name - if (pListBlock->HasListStyleName() - || (pListItem != nullptr && pListItem->HasNumRulesOverride())) + if (!bApplyNumRules + && (pListBlock->HasListStyleName() + || (pListItem != nullptr && pListItem->HasNumRulesOverride()))) { bApplyNumRules = true; // tdf#114287 + bApplyNumRulesFix = rImport.isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_76); } if (!pListItem) { @@ -1125,7 +1160,7 @@ OUString XMLTextImportHelper::SetStyleAndAttrs( if (pListBlock || pNumberedParagraph) { - if ( !bApplyNumRules ) + if (!bApplyNumRules || bApplyNumRulesFix) { bool bSameNumRules = xNewNumRules == xNumRules; if( !bSameNumRules && xNewNumRules.is() && xNumRules.is() ) @@ -1149,7 +1184,14 @@ OUString XMLTextImportHelper::SetStyleAndAttrs( } } } - bApplyNumRules = !bSameNumRules; + if (!bApplyNumRules) + { + bApplyNumRules = !bSameNumRules; + } + if (!bSameNumRules) + { + bApplyNumRulesFix = false; + } } if ( bApplyNumRules ) @@ -1163,6 +1205,19 @@ OUString XMLTextImportHelper::SetStyleAndAttrs( { xPropSet->setPropertyValue( s_NumberingRules, Any(xNewNumRules) ); + if (bApplyNumRulesFix) + { // tdf#156146 override list margins for bug compatibility + if (IsPropertySet(m_xImpl->m_xParaStyles, xPropSet, "ParaLeftMargin")) + { + uno::Any const left(xPropSet->getPropertyValue("ParaLeftMargin")); + xPropSet->setPropertyValue("ParaLeftMargin", left); + } + if (IsPropertySet(m_xImpl->m_xParaStyles, xPropSet, "ParaFirstLineIndent")) + { + uno::Any const first(xPropSet->getPropertyValue("ParaFirstLineIndent")); + xPropSet->setPropertyValue("ParaFirstLineIndent", first); + } + } } catch(const Exception&) {