Kaydet (Commit) 3a9854a9 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 5e062501
......@@ -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
......
......@@ -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: */
......@@ -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;
......@@ -3016,11 +3017,40 @@ void RtfAttributeOutput::FormatULSpace(const SvxULSpaceItem& rULSpace)
m_rExport.Strm(). WriteCharPtr(m_aSectionBreaks.makeStringAndClear().getStr());
}
else
{
// 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((sal_Int32) rULSpace.GetUpper());
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((sal_Int32) rULSpace.GetLower());
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)
{
}
......
......@@ -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);
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment