summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2023-01-23 16:38:03 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2023-01-24 13:39:23 +0000
commit90e1698dab3d286c10136719aa85fee2f56ad9fd (patch)
tree4e6e56ffacb7bbb45fd34aa67d6678d61a37e74c /xmloff
parent668f55b65849012b359d7d6b9386113facbadc57 (diff)
tdf#153090 xmloff: ODF import/export of source style on ToX
For Table of Figures/Objects/Tables. Make this similar to DOCX: only one source style is possible, so omit the intermediate text:index-source-styles element. Also a boolean attribute like text:use-index-source-styles appears as unnecessary complexity, so try to do without. Change-Id: I7cb599c7ec1261ddedc196a25c3eafe35f35fbe9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146013 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx2
-rw-r--r--xmloff/source/text/XMLIndexBibliographySourceContext.cxx5
-rw-r--r--xmloff/source/text/XMLIndexIllustrationSourceContext.cxx4
-rw-r--r--xmloff/source/text/XMLIndexObjectSourceContext.cxx5
-rw-r--r--xmloff/source/text/XMLIndexSourceBaseContext.cxx23
-rw-r--r--xmloff/source/text/XMLIndexSourceBaseContext.hxx16
-rw-r--r--xmloff/source/text/XMLIndexTOCSourceContext.cxx2
-rw-r--r--xmloff/source/text/XMLIndexTOCStylesContext.cxx28
-rw-r--r--xmloff/source/text/XMLIndexTableSourceContext.cxx3
-rw-r--r--xmloff/source/text/XMLIndexUserSourceContext.cxx5
-rw-r--r--xmloff/source/text/XMLSectionExport.cxx16
11 files changed, 81 insertions, 28 deletions
diff --git a/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx
index df1385d95b0e..d3210421f525 100644
--- a/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx
@@ -45,7 +45,7 @@ using namespace ::xmloff::token;
XMLIndexAlphabeticalSourceContext::XMLIndexAlphabeticalSourceContext(
SvXMLImport& rImport,
Reference<XPropertySet> & rPropSet)
-: XMLIndexSourceBaseContext(rImport, rPropSet, false)
+: XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::None)
, bMainEntryStyleNameOK(false)
, bSeparators(false)
, bCombineEntries(true)
diff --git a/xmloff/source/text/XMLIndexBibliographySourceContext.cxx b/xmloff/source/text/XMLIndexBibliographySourceContext.cxx
index 0ec5563895f6..226e5b10dc3a 100644
--- a/xmloff/source/text/XMLIndexBibliographySourceContext.cxx
+++ b/xmloff/source/text/XMLIndexBibliographySourceContext.cxx
@@ -38,9 +38,8 @@ using ::com::sun::star::xml::sax::XAttributeList;
XMLIndexBibliographySourceContext::XMLIndexBibliographySourceContext(
SvXMLImport& rImport,
- Reference<XPropertySet> & rPropSet) :
- XMLIndexSourceBaseContext(rImport,
- rPropSet, false)
+ Reference<XPropertySet> & rPropSet)
+ : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::None)
{
}
diff --git a/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
index 780d821bc883..74f2ed9332c6 100644
--- a/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
@@ -37,8 +37,8 @@ using ::xmloff::token::XML_TOKEN_INVALID;
XMLIndexIllustrationSourceContext::XMLIndexIllustrationSourceContext(
SvXMLImport& rImport,
- Reference<XPropertySet> & rPropSet) :
- XMLIndexTableSourceContext(rImport, rPropSet)
+ Reference<XPropertySet> & rPropSet)
+ : XMLIndexTableSourceContext(rImport, rPropSet)
{
}
diff --git a/xmloff/source/text/XMLIndexObjectSourceContext.cxx b/xmloff/source/text/XMLIndexObjectSourceContext.cxx
index d35f3f025149..847ec680b0cd 100644
--- a/xmloff/source/text/XMLIndexObjectSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexObjectSourceContext.cxx
@@ -43,9 +43,8 @@ using namespace ::xmloff::token;
XMLIndexObjectSourceContext::XMLIndexObjectSourceContext(
SvXMLImport& rImport,
- Reference<XPropertySet> & rPropSet) :
- XMLIndexSourceBaseContext(rImport,
- rPropSet, false),
+ Reference<XPropertySet> & rPropSet)
+ : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::Single),
bUseCalc(false),
bUseChart(false),
bUseDraw(false),
diff --git a/xmloff/source/text/XMLIndexSourceBaseContext.cxx b/xmloff/source/text/XMLIndexSourceBaseContext.cxx
index 77de7bf4cac9..242e95012781 100644
--- a/xmloff/source/text/XMLIndexSourceBaseContext.cxx
+++ b/xmloff/source/text/XMLIndexSourceBaseContext.cxx
@@ -42,9 +42,9 @@ using ::com::sun::star::xml::sax::XAttributeList;
XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
SvXMLImport& rImport,
Reference<XPropertySet> & rPropSet,
- bool bLevelFormats)
+ UseStyles const eUseStyles)
: SvXMLImportContext(rImport)
-, bUseLevelFormats(bLevelFormats)
+, m_UseStyles(eUseStyles)
, bChapterIndex(false)
, bRelativeTabs(true)
, rIndexPropertySet(rPropSet)
@@ -100,7 +100,7 @@ void XMLIndexSourceBaseContext::endFastElement(sal_Int32 )
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexSourceBaseContext::createFastChildContext(
sal_Int32 nElement,
- const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
{
SvXMLImportContextRef xContext;
@@ -109,12 +109,25 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexSourceBaseCont
xContext = new XMLIndexTitleTemplateContext(GetImport(),
rIndexPropertySet);
}
- else if ( bUseLevelFormats &&
- nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLES) )
+ else if (m_UseStyles == UseStyles::Level
+ && nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLES))
{
xContext = new XMLIndexTOCStylesContext(GetImport(),
rIndexPropertySet);
}
+ else if (m_UseStyles == UseStyles::Single
+ && (nElement == XML_ELEMENT(LO_EXT, XML_INDEX_SOURCE_STYLE)
+ || nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE)))
+ {
+ OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
+ if (!styleName.isEmpty())
+ {
+ OUString const convertedStyleName(GetImport().GetStyleDisplayName(
+ XmlStyleFamily::TEXT_PARAGRAPH, styleName));
+ rIndexPropertySet->setPropertyValue("CreateFromParagraphStyle", css::uno::Any(convertedStyleName));
+ }
+ }
+
// else: unknown namespace -> ignore
return xContext;
diff --git a/xmloff/source/text/XMLIndexSourceBaseContext.hxx b/xmloff/source/text/XMLIndexSourceBaseContext.hxx
index 17d287e9a882..b927954e5f83 100644
--- a/xmloff/source/text/XMLIndexSourceBaseContext.hxx
+++ b/xmloff/source/text/XMLIndexSourceBaseContext.hxx
@@ -35,7 +35,11 @@ namespace com::sun::star {
*/
class XMLIndexSourceBaseContext : public SvXMLImportContext
{
- bool bUseLevelFormats;
+protected:
+ enum class UseStyles { None, Level, Single };
+
+private:
+ UseStyles m_UseStyles;
bool bChapterIndex; /// chapter-wise or document index?
bool bRelativeTabs; /// tab stops relative to margin or indent?
@@ -50,7 +54,7 @@ public:
XMLIndexSourceBaseContext(
SvXMLImport& rImport,
css::uno::Reference<css::beans::XPropertySet> & rPropSet,
- bool bLevelFormats);
+ UseStyles eUseStyles);
virtual ~XMLIndexSourceBaseContext() override;
@@ -69,4 +73,12 @@ protected:
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};
+
+namespace xmloff {
+
+OUString GetIndexSourceStyleName(
+ css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList);
+
+} // namespace xmloff
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/XMLIndexTOCSourceContext.cxx b/xmloff/source/text/XMLIndexTOCSourceContext.cxx
index 45899e4543d2..bea5ff58ad4c 100644
--- a/xmloff/source/text/XMLIndexTOCSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexTOCSourceContext.cxx
@@ -40,7 +40,7 @@ using ::com::sun::star::xml::sax::XAttributeList;
XMLIndexTOCSourceContext::XMLIndexTOCSourceContext(
SvXMLImport& rImport,
Reference<XPropertySet> & rPropSet)
-: XMLIndexSourceBaseContext(rImport, rPropSet, true)
+: XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::Level)
// use all chapters by default
, nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount())
, bUseOutline(true)
diff --git a/xmloff/source/text/XMLIndexTOCStylesContext.cxx b/xmloff/source/text/XMLIndexTOCStylesContext.cxx
index 5331b687a9f9..c3e2c5b4ec31 100644
--- a/xmloff/source/text/XMLIndexTOCStylesContext.cxx
+++ b/xmloff/source/text/XMLIndexTOCStylesContext.cxx
@@ -18,6 +18,8 @@
*/
#include "XMLIndexTOCStylesContext.hxx"
+
+#include "XMLIndexSourceBaseContext.hxx"
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <xmloff/xmlictxt.hxx>
@@ -103,6 +105,23 @@ void XMLIndexTOCStylesContext::endFastElement(sal_Int32 )
xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
}
+namespace xmloff {
+
+OUString GetIndexSourceStyleName(
+ css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList)
+{
+ for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
+ {
+ if (rIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
+ {
+ return rIter.toString();
+ }
+ }
+ return OUString();
+}
+
+} // namespace xmloff
+
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
@@ -111,13 +130,10 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesConte
if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
{
// find text:style-name attribute and record in aStyleNames
- for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
+ OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
+ if (!styleName.isEmpty())
{
- if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
- {
- aStyleNames.push_back(aIter.toString());
- break;
- }
+ aStyleNames.emplace_back(styleName);
}
}
diff --git a/xmloff/source/text/XMLIndexTableSourceContext.cxx b/xmloff/source/text/XMLIndexTableSourceContext.cxx
index 480baf0cee16..3a7f8a5a779b 100644
--- a/xmloff/source/text/XMLIndexTableSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexTableSourceContext.cxx
@@ -45,8 +45,7 @@ using ::com::sun::star::xml::sax::XAttributeList;
XMLIndexTableSourceContext::XMLIndexTableSourceContext(
SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
- : XMLIndexSourceBaseContext(rImport,
- rPropSet, false)
+ : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::Single)
, nDisplayFormat(0)
, bSequenceOK(false)
, bDisplayFormatOK(false)
diff --git a/xmloff/source/text/XMLIndexUserSourceContext.cxx b/xmloff/source/text/XMLIndexUserSourceContext.cxx
index 392e8b72bc5f..ebaf6ee23e4e 100644
--- a/xmloff/source/text/XMLIndexUserSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexUserSourceContext.cxx
@@ -37,9 +37,8 @@ using namespace ::xmloff::token;
XMLIndexUserSourceContext::XMLIndexUserSourceContext(
SvXMLImport& rImport,
- Reference<XPropertySet> & rPropSet) :
- XMLIndexSourceBaseContext(rImport,
- rPropSet, true),
+ Reference<XPropertySet> & rPropSet)
+ : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::Level),
bUseObjects(false),
bUseGraphic(false),
bUseMarks(false),
diff --git a/xmloff/source/text/XMLSectionExport.cxx b/xmloff/source/text/XMLSectionExport.cxx
index d97e30c0c6fa..f76c4f2815f1 100644
--- a/xmloff/source/text/XMLSectionExport.cxx
+++ b/xmloff/source/text/XMLSectionExport.cxx
@@ -830,6 +830,22 @@ void XMLSectionExport::ExportBaseIndexSource(
aAny >>= xLevelParagraphStyles;
ExportLevelParagraphStyles(xLevelParagraphStyles);
}
+ else if (TEXT_SECTION_TYPE_ILLUSTRATION == eType
+ || TEXT_SECTION_TYPE_OBJECT == eType
+ || TEXT_SECTION_TYPE_TABLE == eType)
+ {
+ Any const any(rPropertySet->getPropertyValue("CreateFromParagraphStyle"));
+ if (any.hasValue() &&
+ (rExport.getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED))
+ {
+ OUString const styleName(any.get<OUString>());
+ GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
+ GetExport().EncodeStyleName(styleName));
+
+ SvXMLElementExport const e(GetExport(),
+ XML_NAMESPACE_LO_EXT, XML_INDEX_SOURCE_STYLE, true, false);
+ }
+ }
}