[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/CppunitTest_sw_txtexport.mk sw/Module_sw.mk sw/qa sw/source
Jan Holesovsky
kendy at collabora.com
Thu May 11 09:07:07 UTC 2017
sw/CppunitTest_sw_txtexport.mk | 55 +++++++++++++++++++++++
sw/Module_sw.mk | 1
sw/qa/extras/txtexport/data/bullets.odt |binary
sw/qa/extras/txtexport/txtexport.cxx | 76 ++++++++++++++++++++++++++++++++
sw/source/filter/ascii/ascatr.cxx | 29 ++++++++++--
5 files changed, 156 insertions(+), 5 deletions(-)
New commits:
commit ce11f2452951d448b91b74d1e59e163a8b322eb6
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri May 5 15:02:20 2017 +0200
sw txt export: Greatly improve the export of bullets & numbering.
Includes unit testing infrastructure for .txt export too + the actual unit
test.
Change-Id: I19a32955bbc9b97449b4240917fe2505bc3dd54c
diff --git a/sw/CppunitTest_sw_txtexport.mk b/sw/CppunitTest_sw_txtexport.mk
new file mode 100644
index 000000000000..983d3d429b50
--- /dev/null
+++ b/sw/CppunitTest_sw_txtexport.mk
@@ -0,0 +1,55 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_txtexport))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_txtexport, \
+ sw/qa/extras/txtexport/txtexport \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_txtexport, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ i18nlangtag \
+ sal \
+ sw \
+ test \
+ tl \
+ unotest \
+ utl \
+ vcl \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_txtexport,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_txtexport,\
+ -I$(SRCDIR)/sw/inc \
+ -I$(SRCDIR)/sw/source/core/inc \
+ -I$(SRCDIR)/sw/source/uibase/inc \
+ -I$(SRCDIR)/sw/qa/extras/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,sw_txtexport))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_txtexport))
+$(eval $(call gb_CppunitTest_use_vcl,sw_txtexport))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_txtexport,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_txtexport))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 3dc57492d332..f31aa7ccaa78 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -72,6 +72,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_rtfimport \
CppunitTest_sw_odfexport \
CppunitTest_sw_odfimport \
+ CppunitTest_sw_txtexport \
CppunitTest_sw_uiwriter \
CppunitTest_sw_mailmerge \
CppunitTest_sw_globalfilter \
diff --git a/sw/qa/extras/txtexport/data/bullets.odt b/sw/qa/extras/txtexport/data/bullets.odt
new file mode 100644
index 000000000000..43e0c2123ffc
Binary files /dev/null and b/sw/qa/extras/txtexport/data/bullets.odt differ
diff --git a/sw/qa/extras/txtexport/txtexport.cxx b/sw/qa/extras/txtexport/txtexport.cxx
new file mode 100644
index 000000000000..b9cd02bdf0b5
--- /dev/null
+++ b/sw/qa/extras/txtexport/txtexport.cxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <swmodule.hxx>
+#include <swdll.hxx>
+#include <usrpref.hxx>
+
+class TxtExportTest : public SwModelTestBase
+{
+public:
+ TxtExportTest() :
+ SwModelTestBase("/sw/qa/extras/txtexport/data/", "Text")
+ {}
+
+protected:
+ OString readExportedFile()
+ {
+ SvMemoryStream aMemoryStream;
+ SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+ aStream.ReadStream(aMemoryStream);
+ const char* pData = static_cast<const char*>(aMemoryStream.GetData());
+
+ int offset = 0;
+ if (aMemoryStream.GetSize() > 2 && pData[0] == '\xEF' && pData[1] == '\xBB' && pData[2] == '\xBF')
+ offset = 3;
+
+ return OString(pData + offset, aMemoryStream.GetSize() - offset);
+ }
+};
+
+#define DECLARE_TXTEXPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, nullptr, TxtExportTest)
+
+DECLARE_TXTEXPORT_TEST(testBullets, "bullets.odt")
+{
+ OString aData = readExportedFile();
+
+ OUString aString = OStringToOUString(
+ "1 Heading 1" SAL_NEWLINE_STRING
+ "1.A Heading 2" SAL_NEWLINE_STRING
+ "Paragraph" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 First bullet" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Second bullet" SAL_NEWLINE_STRING
+ " \xe2\x97\xa6 Sub-second bullet" SAL_NEWLINE_STRING
+ " Third bullet, but deleted" SAL_NEWLINE_STRING
+ " \xe2\x80\xa2 Fourth bullet" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING
+ "Numbering" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING
+ " 1. First" SAL_NEWLINE_STRING
+ " 2. Second" SAL_NEWLINE_STRING
+ " 1. Second-first" SAL_NEWLINE_STRING
+ " Third, but deleted" SAL_NEWLINE_STRING
+ " 3. Actual third" SAL_NEWLINE_STRING
+ "" SAL_NEWLINE_STRING
+ "Paragraph after numbering" SAL_NEWLINE_STRING
+ "Next paragraph" SAL_NEWLINE_STRING
+ "Final paragraph" SAL_NEWLINE_STRING, RTL_TEXTENCODING_UTF8);
+
+ // To get the stuff back in the system's encoding
+ OString aExpected(OUStringToOString(aString, osl_getThreadTextEncoding()));
+
+ CPPUNIT_ASSERT_EQUAL(aExpected, aData);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ascii/ascatr.cxx b/sw/source/filter/ascii/ascatr.cxx
index 01c1caf673f7..1a3f416ea91f 100644
--- a/sw/source/filter/ascii/ascatr.cxx
+++ b/sw/source/filter/ascii/ascatr.cxx
@@ -180,14 +180,33 @@ static Writer& OutASC_SwTextNode( Writer& rWrt, SwContentNode& rNode )
SwASC_AttrIter aAttrIter( static_cast<SwASCWriter&>(rWrt), rNd, nStrPos );
- if( !nStrPos && rWrt.bExportPargraphNumbering )
+ const SwNumRule* pNumRule = rNd.GetNumRule();
+ if (pNumRule && !nStrPos && rWrt.bExportPargraphNumbering)
{
- OUString numString( rNd.GetNumString() );
- if (!numString.isEmpty())
+ bool bIsOutlineNumRule = pNumRule == rNd.GetDoc()->GetOutlineNumRule();
+
+ // indent each numbering level by 4 spaces
+ OUString level;
+ if (!bIsOutlineNumRule)
{
- numString += " ";
- rWrt.Strm().WriteUnicodeOrByteText(numString);
+ for (int i = 0; i <= rNd.GetActualListLevel(); ++i)
+ level += " ";
}
+
+ // set up bullets or numbering
+ OUString numString(rNd.GetNumString());
+ if (numString.isEmpty() && !bIsOutlineNumRule)
+ {
+ if (rNd.HasBullet() && !rNd.HasVisibleNumberingOrBullet())
+ numString = " ";
+ else if (rNd.HasBullet())
+ numString = OUString(numfunc::GetBulletChar(rNd.GetActualListLevel()));
+ else if (!rNd.HasBullet() && !rNd.HasVisibleNumberingOrBullet())
+ numString = " ";
+ }
+
+ if (!level.isEmpty() || !numString.isEmpty())
+ rWrt.Strm().WriteUnicodeOrByteText(level + numString + " ");
}
OUString aStr( rNd.GetText() );
More information about the Libreoffice-commits
mailing list