diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-10 20:39:12 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-12 08:50:02 +0200 |
commit | c2cfeed369a2b0f6d91d1093d3876357277411c9 (patch) | |
tree | 2f56b19c7b38d3aeb4dd38eeeecea388723273c9 /xmloff/source | |
parent | b69db38a38b09e158e8d46d8b717db85860ca874 (diff) |
tdf#155238: Reimplement how ListAutoFormat is stored to ODF
This reimplements commits 6249858a8972aef077e0249bd93cfe8f01bce4d6
(sw: ODT import/export of DOCX's paragraph marker formatting,
2022-12-19) and 209dce614c43f63f63f5b42a746665c0ec1cbfe3 (sw: fix
ODT import of paragraph marker formatting, 2022-12-20).
Instead of using an empty trailing span for the ListAutoFormat data,
introduce a new loext:marker-style-name attribute for text:p element,
referencing a text autostyle.
The problems with the previous implementation were that (1) it was
impossible (or very difficult) to disambiguate several empty trailing
spans, in case it was needed; and (2) this was incompatible change,
with other ODF implementations treating the trailing span normally.
I couldn't manage to incorporate the attribute to paragraph autostyle,
because of problems referencing different autostyles one from another,
so put it directly to the paragraph attributes.
Change-Id: I33473147f1f774c24cbbc57bf0c4f3a1d83ce5bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151645
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151681
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 1 | ||||
-rw-r--r-- | xmloff/source/text/txtimp.cxx | 9 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 32 | ||||
-rw-r--r-- | xmloff/source/text/txtparai.cxx | 22 | ||||
-rw-r--r-- | xmloff/source/text/txtparai.hxx | 1 | ||||
-rw-r--r-- | xmloff/source/text/txtprmap.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
7 files changed, 67 insertions, 1 deletions
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 1dc56ced1114..93d23f0a044b 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1221,6 +1221,7 @@ namespace xmloff::token { TOKEN( "linked-cell", XML_LINKED_CELL ), TOKEN( "link-to-source-data", XML_LINK_TO_SOURCE_DATA ), TOKEN( "list", XML_LIST ), + TOKEN( "marker-style-name", XML_MARKER_STYLE_NAME ), TOKEN( "list-block", XML_LIST_BLOCK ), TOKEN( "list-header", XML_LIST_HEADER ), TOKEN( "list-info", XML_LIST_INFO ), diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx index 87fd2b91283a..e0df349b63e4 100644 --- a/xmloff/source/text/txtimp.cxx +++ b/xmloff/source/text/txtimp.cxx @@ -2031,6 +2031,15 @@ XMLPropStyleContext* XMLTextImportHelper::FindPageMaster( return pStyle; } +XMLPropStyleContext* XMLTextImportHelper::FindAutoCharStyle(const OUString& rName) const +{ + if (!m_xImpl->m_xAutoStyles) + return nullptr; + auto pStyle + = m_xImpl->m_xAutoStyles->FindStyleChildContext(XmlStyleFamily::TEXT_TEXT, rName, true); + return dynamic_cast<XMLPropStyleContext*>(const_cast<SvXMLStyleContext*>(pStyle)); +} + XMLPropStyleContext * XMLTextImportHelper::FindDrawingPage(OUString const& rName) const { if (!m_xImpl->m_xAutoStyles.is()) diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 482a1fa71897..ee074c0b412d 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextSectionsSupplier.hpp> @@ -2187,6 +2188,37 @@ void XMLTextParagraphExport::exportParagraph( } } } + + if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) + { + try + { + // ParaMarkerAutoStyleSpan is a hidden property, just to pass the autostyle here + // See SwXParagraph::Impl::GetPropertyValues_Impl + css::uno::Any aVal = xPropSet->getPropertyValue("ParaMarkerAutoStyleSpan"); + if (css::uno::Reference<css::beans::XPropertySet> xFakeSpan{ aVal, css::uno::UNO_QUERY }) + { + if (bAutoStyles) + { + Add(XmlStyleFamily::TEXT_TEXT, xFakeSpan); + } + else + { + bool bIsUICharStyle, bHasAutoStyle; + OUString sStyle = FindTextStyle(xFakeSpan, bIsUICharStyle, bHasAutoStyle); + if (!sStyle.isEmpty()) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_MARKER_STYLE_NAME, + sStyle); + } + } + } + } + catch (const css::beans::UnknownPropertyException&) + { + // No problem + } + } } Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY ); diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index 5fffc202612a..1a0801646943 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -41,6 +41,7 @@ #include <sax/tools/converter.hxx> +#include <xmloff/prstylei.hxx> #include <xmloff/xmlictxt.hxx> #include <xmloff/xmlimp.hxx> #include <xmloff/xmltoken.hxx> @@ -1675,6 +1676,10 @@ XMLParaContext::XMLParaContext( nStartValue = sal::static_int_cast< sal_Int16 >(aIter.toInt32()); } break; + case XML_ELEMENT(LO_EXT, XML_MARKER_STYLE_NAME): + if (auto pStyle = rImport.GetTextImport()->FindAutoCharStyle(aIter.toString())) + m_aMarkerStyleName = pStyle->GetAutoName(); + break; default: XMLOFF_WARN_UNKNOWN("xmloff", aIter); } @@ -1720,6 +1725,21 @@ void XMLParaContext::endFastElement(sal_Int32 ) // insert a paragraph break xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH ); + if (!m_aMarkerStyleName.isEmpty()) + { + if (css::uno::Reference<css::beans::XPropertySet> xPropSet{ xStart, css::uno::UNO_QUERY }) + { + try + { + xPropSet->setPropertyValue("ListAutoFormat", css::uno::Any(m_aMarkerStyleName)); + } + catch (const css::beans::UnknownPropertyException&) + { + // no problem + } + } + } + // create a cursor that select the whole last paragraph Reference < XTextCursor > xAttrCursor; try { @@ -1832,7 +1852,7 @@ void XMLParaContext::endFastElement(sal_Int32 ) { bool bSetNoFormatAttr = false; uno::Reference<beans::XPropertySet> xCursorProps(xAttrCursor, uno::UNO_QUERY); - if (m_xHints->GetHints().size() > 1) + if (m_xHints->GetHints().size() > 1 || !m_aMarkerStyleName.isEmpty()) { // We have multiple hints, then make try to ask the cursor to not upgrade our character // attributes to paragraph-level formatting, which would lead to incorrect rendering. diff --git a/xmloff/source/text/txtparai.hxx b/xmloff/source/text/txtparai.hxx index 66c64181c4ba..4cf406027a2b 100644 --- a/xmloff/source/text/txtparai.hxx +++ b/xmloff/source/text/txtparai.hxx @@ -42,6 +42,7 @@ class XMLParaContext : public SvXMLImportContext OUString m_sProperty; OUString m_sContent; OUString m_sDatatype; + OUString m_aMarkerStyleName; bool m_bHaveAbout; sal_Int8 nOutlineLevel; std::unique_ptr<XMLHints_Impl> m_xHints; diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index 820506c8ea8a..b961a2c60944 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -463,6 +463,8 @@ XMLPropertyMapEntry const aXMLParaPropMap[] = MP_ED( PROP_FontIndependentLineSpacing, STYLE, FONT_INDEPENDENT_LINE_SPACING, XML_TYPE_BOOL, 0 ), + MAP_EXT( PROP_ListAutoFormat, XML_NAMESPACE_LO_EXT, XML_MARKER_STYLE_NAME, XML_TYPE_STYLENAME|XML_TYPE_PROP_PARAGRAPH, 0 ), + M_END() }; diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 5fef52535c63..27fc8621e638 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -1121,6 +1121,7 @@ lines-used linked-cell link-to-source-data list +marker-style-name list-block list-header list-info |