summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-05-09 09:10:24 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-05-09 13:51:29 +0200
commit3a9854a92923df8013ca832c48aa9f284bcb1adc (patch)
tree92ed195d12e40ba8b4ece1216eb878a0263853dd
parent5e062501eb6c3abe5219777fd9267702689785c7 (diff)
tdf#107620 RTF export: handle DocumentSettingId::PARA_SPACE_MAX compat setting
As it turns out it has a dedicated RTF control word. With this, the bugdoc is again kept as a one-page document during DOCX -> RTF conversion. If we are at it, also write the automatic before/after paragraph spacing markup. Change-Id: I78de644f0631e59ef507dfaa07c5a812d4ef10cd
-rw-r--r--include/svtools/rtfkeywd.hxx3
-rw-r--r--sw/qa/extras/rtfexport/data/tdf107620.docxbin0 -> 12654 bytes
-rw-r--r--sw/qa/extras/rtfexport/rtfexport.cxx11
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx60
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx9
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx5
6 files changed, 83 insertions, 5 deletions
diff --git a/include/svtools/rtfkeywd.hxx b/include/svtools/rtfkeywd.hxx
index 55d97f51bd16..ec6053f14434 100644
--- a/include/svtools/rtfkeywd.hxx
+++ b/include/svtools/rtfkeywd.hxx
@@ -1208,6 +1208,9 @@
#define LO_STRING_SVTOOLS_RTF_BRDRSH "\\brdrsh"
#define LO_STRING_SVTOOLS_RTF_GENERATOR "\\generator"
#define LO_STRING_SVTOOLS_RTF_VIEWBKSP "\\viewbksp"
+#define LO_STRING_SVTOOLS_RTF_SBAUTO "\\sbauto"
+#define LO_STRING_SVTOOLS_RTF_SAAUTO "\\saauto"
+#define LO_STRING_SVTOOLS_RTF_HTMAUTSP "\\htmautsp"
#endif // INCLUDED_SVTOOLS_RTFKEYWD_HXX
diff --git a/sw/qa/extras/rtfexport/data/tdf107620.docx b/sw/qa/extras/rtfexport/data/tdf107620.docx
new file mode 100644
index 000000000000..285bd92ae670
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf107620.docx
Binary files differ
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 0eccf65dd748..87e86c198612 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -1193,6 +1193,17 @@ DECLARE_RTFEXPORT_TEST(testHyperlinkTarget, "hyperlink-target.rtf")
CPPUNIT_ASSERT_EQUAL(OUString("_blank"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkTarget"));
}
+DECLARE_RTFEXPORT_TEST(testTdf107620, "tdf107620.docx")
+{
+ // This failed, RTF export didn't write the \htmautsp compat flag, the
+ // original bugdoc resulting in 2 pages instead of 1.
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xSettings(xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
+ bool bAddParaTableSpacing = true;
+ xSettings->getPropertyValue("AddParaTableSpacing") >>= bAddParaTableSpacing;
+ CPPUNIT_ASSERT(!bAddParaTableSpacing);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 4cce69b69bfd..6352aeb63bbb 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -80,6 +80,7 @@
#include <oox/mathml/export.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <o3tl/make_unique.hxx>
+#include <svl/grabbagitem.hxx>
using namespace ::com::sun::star;
using namespace sw::util;
@@ -3017,10 +3018,39 @@ void RtfAttributeOutput::FormatULSpace(const SvxULSpaceItem& rULSpace)
}
else
{
- m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SB);
- m_aStyles.append((sal_Int32) rULSpace.GetUpper());
- m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SA);
- m_aStyles.append((sal_Int32) rULSpace.GetLower());
+ // Spacing before.
+ if (m_bParaBeforeAutoSpacing && m_nParaBeforeSpacing == rULSpace.GetUpper())
+ m_aStyles.append(LO_STRING_SVTOOLS_RTF_SBAUTO "1");
+ else if (m_bParaBeforeAutoSpacing && m_nParaBeforeSpacing == -1)
+ {
+ m_aStyles.append(LO_STRING_SVTOOLS_RTF_SBAUTO "0");
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SB);
+ m_aStyles.append(static_cast<sal_Int32>(rULSpace.GetUpper()));
+ }
+ else
+ {
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SB);
+ m_aStyles.append(static_cast<sal_Int32>(rULSpace.GetUpper()));
+ }
+ m_bParaBeforeAutoSpacing = false;
+
+ // Spacing after.
+ if (m_bParaAfterAutoSpacing && m_nParaAfterSpacing == rULSpace.GetLower())
+ m_aStyles.append(LO_STRING_SVTOOLS_RTF_SAAUTO "1");
+ else if (m_bParaAfterAutoSpacing && m_nParaAfterSpacing == -1)
+ {
+ m_aStyles.append(LO_STRING_SVTOOLS_RTF_SAAUTO "0");
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SA);
+ m_aStyles.append(static_cast<sal_Int32>(rULSpace.GetLower()));
+ }
+ else
+ {
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SA);
+ m_aStyles.append(static_cast<sal_Int32>(rULSpace.GetLower()));
+ }
+ m_bParaAfterAutoSpacing = false;
+
+ // Contextual spacing.
if (rULSpace.GetContext())
m_aStyles.append(OOO_STRING_SVTOOLS_RTF_CONTEXTUALSPACE);
}
@@ -3381,8 +3411,24 @@ void RtfAttributeOutput::FormatFrameDirection(const SvxFrameDirectionItem& rDire
}
}
-void RtfAttributeOutput::ParaGrabBag(const SfxGrabBagItem& /*rItem*/)
+void RtfAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem)
{
+ const std::map<OUString, css::uno::Any>& rMap = rItem.GetGrabBag();
+ for (const auto& rValue : rMap)
+ {
+ if (rValue.first == "ParaTopMarginBeforeAutoSpacing")
+ {
+ m_bParaBeforeAutoSpacing = true;
+ rValue.second >>= m_nParaBeforeSpacing;
+ m_nParaBeforeSpacing = convertMm100ToTwip(m_nParaBeforeSpacing);
+ }
+ else if (rValue.first == "ParaBottomMarginAfterAutoSpacing")
+ {
+ m_bParaAfterAutoSpacing = true;
+ rValue.second >>= m_nParaAfterSpacing;
+ m_nParaAfterSpacing = convertMm100ToTwip(m_nParaAfterSpacing);
+ }
+ }
}
void RtfAttributeOutput::CharGrabBag(const SfxGrabBagItem& /*rItem*/)
@@ -3497,6 +3543,10 @@ RtfAttributeOutput::RtfAttributeOutput(RtfExport& rExport)
m_bSingleEmptyRun(false),
m_bInRun(false),
m_pFlyFrameSize(nullptr),
+ m_bParaBeforeAutoSpacing(false),
+ m_nParaBeforeSpacing(0),
+ m_bParaAfterAutoSpacing(false),
+ m_nParaAfterSpacing(0),
m_pPrevPageDesc(nullptr)
{
}
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index 2a5fca3c8309..23e8466681da 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -595,6 +595,15 @@ private:
/// If we're in the process of exporting a hyperlink, then its URL.
OUString m_sURL;
+ /// If original file had \sbauto.
+ bool m_bParaBeforeAutoSpacing;
+ /// If m_bParaBeforeAutoSpacing is set, value of \sb.
+ sal_Int32 m_nParaBeforeSpacing;
+ /// If original file had \saauto.
+ bool m_bParaAfterAutoSpacing;
+ /// If m_bParaBeforeAutoSpacing is set, value of \sa.
+ sal_Int32 m_nParaAfterSpacing;
+
public:
explicit RtfAttributeOutput(RtfExport& rExport);
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index aa481c62bfbb..8b2de89d8bc7 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -48,6 +48,7 @@
#include <editeng/hyphenzoneitem.hxx>
#include <fmtmeta.hxx>
#include <o3tl/make_unique.hxx>
+#include <IDocumentSettingAccess.hxx>
using namespace ::com::sun::star;
@@ -862,6 +863,10 @@ void RtfExport::ExportDocument_Impl()
Strm().WriteCharPtr(pOut);
}
+ if (!m_pDoc->getIDocumentSettingAccess().get(DocumentSettingId::PARA_SPACE_MAX))
+ // RTF default is true, so write compat flag if this should be false.
+ Strm().WriteCharPtr(LO_STRING_SVTOOLS_RTF_HTMAUTSP);
+
Strm().WriteCharPtr(SAL_NEWLINE_STRING);
WriteFootnoteSettings();