tdf#62032 ODT export: handle style:list-level="..." for para styles
ODT import was already working. The spec also says to only take this into account when applying the style, so it seems only the UI remains for the bug to be closed, the rest is done. Change-Id: I27da4dc171b4ced75f143bbcecb3f8c748a26b02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121607 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
parent
cac7c02f52
commit
f38406ba79
4 changed files with 71 additions and 2 deletions
|
@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,xmloff_text))
|
|||
|
||||
$(eval $(call gb_CppunitTest_use_externals,xmloff_text,\
|
||||
boost_headers \
|
||||
libxml2 \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_add_exception_objects,xmloff_text, \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
|
||||
<office:styles>
|
||||
<style:style style:name="mystyle" style:family="paragraph" style:list-style-name="WWNum1" style:list-level="2"/>
|
||||
<style:style style:name="mystyle" style:family="paragraph" style:list-style-name="mylist" style:list-level="2"/>
|
||||
<text:list-style style:name="mylist">
|
||||
</text:list-style>
|
||||
</office:styles>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <test/bootstrapfixture.hxx>
|
||||
#include <unotest/macros_test.hxx>
|
||||
#include <test/xmltesttools.hxx>
|
||||
|
||||
#include <com/sun/star/beans/XPropertySet.hpp>
|
||||
#include <com/sun/star/frame/Desktop.hpp>
|
||||
|
@ -16,18 +17,22 @@
|
|||
#include <com/sun/star/text/XTextDocument.hpp>
|
||||
#include <com/sun/star/text/BibliographyDataType.hpp>
|
||||
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
|
||||
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
|
||||
|
||||
#include <comphelper/propertysequence.hxx>
|
||||
#include <comphelper/propertyvalue.hxx>
|
||||
#include <comphelper/sequenceashashmap.hxx>
|
||||
#include <unotools/tempfile.hxx>
|
||||
#include <unotools/ucbstreamhelper.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
|
||||
constexpr OUStringLiteral DATA_DIRECTORY = u"/xmloff/qa/unit/data/";
|
||||
|
||||
/// Covers xmloff/source/text/ fixes.
|
||||
class XmloffStyleTest : public test::BootstrapFixture, public unotest::MacrosTest
|
||||
class XmloffStyleTest : public test::BootstrapFixture,
|
||||
public unotest::MacrosTest,
|
||||
public XmlTestTools
|
||||
{
|
||||
private:
|
||||
uno::Reference<lang::XComponent> mxComponent;
|
||||
|
@ -35,9 +40,15 @@ private:
|
|||
public:
|
||||
void setUp() override;
|
||||
void tearDown() override;
|
||||
void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override;
|
||||
uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
|
||||
};
|
||||
|
||||
void XmloffStyleTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
|
||||
{
|
||||
XmlTestTools::registerODFNamespaces(pXmlXpathCtx);
|
||||
}
|
||||
|
||||
void XmloffStyleTest::setUp()
|
||||
{
|
||||
test::BootstrapFixture::setUp();
|
||||
|
@ -181,6 +192,32 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testParaStyleListLevel)
|
|||
sal_Int16 nNumberingLevel{};
|
||||
CPPUNIT_ASSERT(xStyle->getPropertyValue("NumberingLevel") >>= nNumberingLevel);
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), nNumberingLevel);
|
||||
|
||||
// Test the export as well:
|
||||
|
||||
// Given a doc model that has a para style with NumberingLevel=2:
|
||||
uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
|
||||
|
||||
// When exporting that to ODT:
|
||||
uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({
|
||||
{ "FilterName", uno::makeAny(OUString("writer8")) },
|
||||
});
|
||||
utl::TempFile aTempFile;
|
||||
aTempFile.EnableKillingFile();
|
||||
xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
|
||||
|
||||
// Then make sure we save the style's numbering level:
|
||||
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
|
||||
= packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL());
|
||||
uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("styles.xml"),
|
||||
uno::UNO_QUERY);
|
||||
std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
|
||||
xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
|
||||
// Without the accompanying fix in place, this failed with:
|
||||
// - XPath '/office:document-styles/office:styles/style:style[@style:name='mystyle']' no attribute 'list-level' exist
|
||||
// i.e. a custom NumberingLevel was lost on save.
|
||||
assertXPath(pXmlDoc, "/office:document-styles/office:styles/style:style[@style:name='mystyle']",
|
||||
"list-level", "2");
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <memory>
|
||||
#include <set>
|
||||
#include <prstylecond.hxx>
|
||||
#include <sal/log.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
using namespace ::com::sun::star::uno;
|
||||
|
@ -122,6 +123,34 @@ void XMLStyleExport::exportStyleContent( const Reference< XStyle >& rStyle )
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Writes <style:style style:list-level="..."> for Writer paragraph styles.
|
||||
void ExportStyleListlevel(const uno::Reference<beans::XPropertySetInfo>& xPropSetInfo,
|
||||
const uno::Reference<beans::XPropertyState>& xPropState,
|
||||
const uno::Reference<beans::XPropertySet>& xPropSet, SvXMLExport& rExport)
|
||||
{
|
||||
if (!xPropSetInfo->hasPropertyByName("NumberingLevel"))
|
||||
{
|
||||
SAL_WARN("xmloff", "ExportStyleListlevel: no NumberingLevel for a Writer paragraph style");
|
||||
return;
|
||||
}
|
||||
|
||||
if (xPropState->getPropertyState("NumberingLevel") != beans::PropertyState_DIRECT_VALUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sal_Int16 nNumberingLevel{};
|
||||
if (!(xPropSet->getPropertyValue("NumberingLevel") >>= nNumberingLevel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_LIST_LEVEL, OUString::number(nNumberingLevel));
|
||||
}
|
||||
}
|
||||
|
||||
bool XMLStyleExport::exportStyle(
|
||||
const Reference< XStyle >& rStyle,
|
||||
const OUString& rXMLFamily,
|
||||
|
@ -302,6 +331,8 @@ bool XMLStyleExport::exportStyle(
|
|||
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
|
||||
XML_LIST_STYLE_NAME,
|
||||
GetExport().EncodeStyleName( sListName ) );
|
||||
|
||||
ExportStyleListlevel(xPropSetInfo, xPropState, xPropSet, GetExport());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue