tdf#153178 writerfilter: do not create text frame spuriously

There are different RTF keywords that end up in RTFFrame, and some of
them cause Word to create a frame, while others don't.

Getting this right requires implementing support for all the missing
wrapping keywords, as most of them create a frame in Word but
\wrapdefault does not.

Change-Id: I1e55d15180564f3d66a5ee7d98274ae18f032872
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159228
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit 4e2f2489c4c7436f8b3a21a530bc625cbef4e365)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159231
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/qa/extras/rtfexport/data/tdf153178.rtf b/sw/qa/extras/rtfexport/data/tdf153178.rtf
new file mode 100644
index 0000000..e1d74f4
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf153178.rtf
@@ -0,0 +1,7 @@
{\rtf1
\tqr\tlul\tx2025\dxfrtext142\dfrmtxtx142\dfrmtxty142\wrapdefault\faauto\adjustright\rin0\lin57\itap0 \rtlch\fcs1 \afs26\alang1025 \ltrch\fcs0 \fs26\lang1031\langfe3079\cgrid\langnp1031\langfenp3079
KKKKKKKK
\par
\pard
\par
}
diff --git a/sw/qa/extras/rtfexport/rtfexport7.cxx b/sw/qa/extras/rtfexport/rtfexport7.cxx
index ad9249b..4d1550a 100644
--- a/sw/qa/extras/rtfexport/rtfexport7.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport7.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/XBookmarksSupplier.hpp>

@@ -659,6 +660,15 @@ DECLARE_RTFEXPORT_TEST(testWatermark, "watermark.rtf")
    CPPUNIT_ASSERT_EQUAL(float(66), nFontSize);
}

DECLARE_RTFEXPORT_TEST(testTdf153178, "tdf153178.rtf")
{
    // the problem was that a frame was created
    uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
    uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(),
                                                         uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
}

DECLARE_RTFEXPORT_TEST(testTdf109790, "tdf109790.rtf")
{
    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), uno::UNO_QUERY);
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx
index de7b91e..699698a 100644
--- a/writerfilter/source/rtftok/rtfdispatchflag.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx
@@ -1242,6 +1242,26 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_notBeside);
            break;
        case RTFKeyword::OVERLAY:
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_none);
            break;
        case RTFKeyword::WRAPAROUND:
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_around);
            break;
        case RTFKeyword::WRAPTHROUGH:
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_through);
            break;
        case RTFKeyword::WRAPTIGHT:
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_tight);
            break;
        case RTFKeyword::WRAPDEFAULT:
            m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap,
                                               NS_ooxml::LN_Value_doc_ST_Wrap_auto);
            break;
        case RTFKeyword::MNOR:
            m_bMathNor = true;
            break;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 568ad4a8..11e251b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -3995,9 +3995,9 @@ RTFSprms RTFFrame::getSprms()

bool RTFFrame::hasProperties() const
{
    return m_nX != 0 || m_nY != 0 || m_nW != 0 || m_nH != 0 || m_nHoriPadding != 0
           || m_nVertPadding != 0 || m_nHoriAlign != 0 || m_nHoriAnchor != 0 || m_nVertAlign != 0
           || m_nVertAnchor != 0;
    // tdf#153178 \dxfrtext \dfrmtxtx \dfrmtxty \wrapdefault do *not* create frame
    return m_nX != 0 || m_nY != 0 || m_nW != 0 || m_nH != 0
           || (m_oWrap && *m_oWrap != NS_ooxml::LN_Value_doc_ST_Wrap_auto);
}

} // namespace writerfilter