summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-05-10 20:39:12 +0300
committerAndras Timar <andras.timar@collabora.com>2023-05-13 20:05:34 +0200
commit758b763d6b0367454029fc257978e5125a966f18 (patch)
treee88b64f6d8a2e4de9bc0d1c207e26c1c198301a6 /xmloff
parentbe3d21f77732486de264b879f1c502e249b7b48a (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')
-rw-r--r--xmloff/inc/xmlprop.hxx1
-rw-r--r--xmloff/source/core/xmltoken.cxx1
-rw-r--r--xmloff/source/text/txtimp.cxx9
-rw-r--r--xmloff/source/text/txtparae.cxx32
-rw-r--r--xmloff/source/text/txtparai.cxx22
-rw-r--r--xmloff/source/text/txtparai.hxx1
-rw-r--r--xmloff/source/text/txtprmap.cxx2
-rw-r--r--xmloff/source/token/tokens.txt1
8 files changed, 68 insertions, 1 deletions
diff --git a/xmloff/inc/xmlprop.hxx b/xmloff/inc/xmlprop.hxx
index b93bf926e569..e2968b688e2c 100644
--- a/xmloff/inc/xmlprop.hxx
+++ b/xmloff/inc/xmlprop.hxx
@@ -428,6 +428,7 @@ inline constexpr OUStringLiteral PROP_LineTransparence = u"LineTransparence";
inline constexpr OUStringLiteral PROP_LineWidth = u"LineWidth";
inline constexpr OUStringLiteral PROP_Lines = u"Lines";
inline constexpr OUStringLiteral PROP_LinkNumberFormatToSource = u"LinkNumberFormatToSource";
+inline constexpr OUStringLiteral PROP_ListAutoFormat = u"ListAutoFormat";
inline constexpr OUStringLiteral PROP_Logarithmic = u"Logarithmic";
inline constexpr OUStringLiteral PROP_MajorOrigin = u"MajorOrigin";
inline constexpr OUStringLiteral PROP_MarkPosition = u"MarkPosition";
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 75dc00177665..17a58c6984d1 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -1222,6 +1222,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 9c3f3ebb15b7..d8a622bdd888 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 c3b7403de1d7..21dd3cae294f 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 1657466dfe80..2b5c3c654ef3 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -1122,6 +1122,7 @@ lines-used
linked-cell
link-to-source-data
list
+marker-style-name
list-block
list-header
list-info