schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 62 ++++++++++++ sw/qa/extras/odfexport/data/Custom-Style-TOC.docx |binary sw/qa/extras/odfexport/odfexport2.cxx | 16 +++ xmloff/source/text/XMLIndexAlphabeticalSourceContext.cxx | 2 xmloff/source/text/XMLIndexBibliographySourceContext.cxx | 5 xmloff/source/text/XMLIndexIllustrationSourceContext.cxx | 4 xmloff/source/text/XMLIndexObjectSourceContext.cxx | 5 xmloff/source/text/XMLIndexSourceBaseContext.cxx | 23 +++- xmloff/source/text/XMLIndexSourceBaseContext.hxx | 16 ++- xmloff/source/text/XMLIndexTOCSourceContext.cxx | 2 xmloff/source/text/XMLIndexTOCStylesContext.cxx | 28 ++++- xmloff/source/text/XMLIndexTableSourceContext.cxx | 3 xmloff/source/text/XMLIndexUserSourceContext.cxx | 5 xmloff/source/text/XMLSectionExport.cxx | 16 +++ 14 files changed, 159 insertions(+), 28 deletions(-)
New commits: commit 90e1698dab3d286c10136719aa85fee2f56ad9fd Author: Michael Stahl <[email protected]> AuthorDate: Mon Jan 23 16:38:03 2023 +0100 Commit: Michael Stahl <[email protected]> CommitDate: Tue Jan 24 13:39:23 2023 +0000 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 <[email protected]> diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 682d93dfe6e9..4606e1cc282c 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -1912,6 +1912,68 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:interleave> </rng:define> + <!-- TODO no proposal --> + <rng:define name="text-illustration-index-source"> + <rng:element name="text:illustration-index-source"> + <rng:ref name="text-illustration-index-source-attrs"/> + <rng:optional> + <rng:ref name="text-index-title-template"/> + </rng:optional> + <rng:optional> + <rng:ref name="text-illustration-index-entry-template"/> + </rng:optional> + <rng:optional> + <!-- <rng:ref name="text-index-source-style"/> --> + <rng:element name="loext:index-source-style"> + <rng:attribute name="text:style-name"> + <rng:ref name="styleNameRef"/> + </rng:attribute> + <rng:empty/> + </rng:element> + </rng:optional> + </rng:element> + </rng:define> + <rng:define name="text-object-index-source"> + <rng:element name="text:object-index-source"> + <rng:ref name="text-object-index-source-attrs"/> + <rng:optional> + <rng:ref name="text-index-title-template"/> + </rng:optional> + <rng:optional> + <rng:ref name="text-object-index-entry-template"/> + </rng:optional> + <rng:optional> + <!-- <rng:ref name="text-index-source-style"/> --> + <rng:element name="loext:index-source-style"> + <rng:attribute name="text:style-name"> + <rng:ref name="styleNameRef"/> + </rng:attribute> + <rng:empty/> + </rng:element> + </rng:optional> + </rng:element> + </rng:define> + <rng:define name="text-table-index-source"> + <rng:element name="text:table-index-source"> + <rng:ref name="text-illustration-index-source-attrs"/> + <rng:optional> + <rng:ref name="text-index-title-template"/> + </rng:optional> + <rng:optional> + <rng:ref name="text-table-index-entry-template"/> + </rng:optional> + <rng:optional> + <!-- <rng:ref name="text-index-source-style"/> --> + <rng:element name="loext:index-source-style"> + <rng:attribute name="text:style-name"> + <rng:ref name="styleNameRef"/> + </rng:attribute> + <rng:empty/> + </rng:element> + </rng:optional> + </rng:element> + </rng:define> + </rng:include> <!-- TODO no proposal --> diff --git a/sw/qa/extras/odfexport/data/Custom-Style-TOC.docx b/sw/qa/extras/odfexport/data/Custom-Style-TOC.docx new file mode 100644 index 000000000000..2b4c57054f5a Binary files /dev/null and b/sw/qa/extras/odfexport/data/Custom-Style-TOC.docx differ diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index f065b28d5308..35e22a59f331 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -18,6 +18,8 @@ #include <com/sun/star/text/ColumnSeparatorStyle.hpp> #include <com/sun/star/text/XBookmarksSupplier.hpp> #include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> +#include <com/sun/star/text/XDocumentIndexesSupplier.hpp> #include <com/sun/star/text/XTextColumns.hpp> #include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <com/sun/star/text/XTextTable.hpp> @@ -597,6 +599,20 @@ DECLARE_ODFEXPORT_TEST(testTdf131025_noZerosInTable, "tdf131025_noZerosInTable.o CPPUNIT_ASSERT_EQUAL(OUString("5 gp"), xCell->getString()); } +DECLARE_ODFEXPORT_TEST(testTdf153090, "Custom-Style-TOC.docx") +{ + uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes()); + uno::Reference<text::XDocumentIndex> xTOC(xIndexes->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("_CustomImageCaption"), getProperty<OUString>(xTOC, "CreateFromParagraphStyle")); + + xTOC->update(); + OUString const tocContent(xTOC->getAnchor()->getString()); + CPPUNIT_ASSERT(tocContent.indexOf("1. Abb. Ein Haus") != -1); + CPPUNIT_ASSERT(tocContent.indexOf("2. Abb.Ein Schiff!") != -1); + CPPUNIT_ASSERT(tocContent.indexOf(u"1. ábra Small house with Hungarian description category") != -1); +} + DECLARE_ODFEXPORT_TEST(testTdf143793_noBodyWrapping, "tdf143793_noBodyWrapping.odt") { CPPUNIT_ASSERT_EQUAL(2, getShapes()); 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); + } + } }
