tdf#99631 DOCX import: set 1:1 scale in embedded XLSX

based on the OLE object size, instead of applying
different scales for the bad (non-imported) VisibleArea
settings.

Change-Id: I3f246b779afd145fe260af83173c1944df21fb1a
Reviewed-on: https://gerrit.libreoffice.org/65244
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/odfexport/data/tdf99631.docx b/sw/qa/extras/odfexport/data/tdf99631.docx
new file mode 100644
index 0000000..7fcb612
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/tdf99631.docx
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 6bc9b8f..c8468eb 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -2123,6 +2123,15 @@
    CPPUNIT_ASSERT(xReplacementGraphic.is());
}

DECLARE_ODFEXPORT_TEST(tdf99631, "tdf99631.docx")
{
    // File asserting while saving in LO.
    xmlDocPtr pXmlDoc = parseExport("Object 1/settings.xml");
    if (!pXmlDoc)
        return;
    assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", "4515");
    assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaHeight']", "903");
}
#endif

CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 57fb431..23319ad 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -49,6 +49,7 @@
#include <sfx2/printer.hxx>
#include <unotools/charclass.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/classids.hxx>
#include <svx/svxdlg.hxx>
#include <svx/extrusionbar.hxx>
#include <svx/fontworkbar.hxx>
@@ -631,11 +632,20 @@

    try
    {
        SvGlobalName aCLSID( xObj->getClassID() );
        // tdf#99631 VisibleArea settings of embedded XLSX haven't been imported in DOCX, yet:
        // set the 1:1 scale based on the OLE object size instead of bad scaling in non-modified documents
        bool bUpdateDOCXSheet = !GetDoc()->GetDocShell()->IsModified() &&
               // embedded spreadsheet
               aCLSID == SvGlobalName( SO3_SC_CLASSID_60 ) &&
               // in docx
               GetView().GetViewFrame()->GetFrame().GetCurrentDocument()->GetModel()->getURL().endsWithIgnoreAsciiCase(".docx");

        nMisc = xObj->getStatus( nAspect );

        // This can surely only be a non-active object, if desired they
        // get the new size set as VisArea (StarChart).
        if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
        if ((embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc) || bUpdateDOCXSheet)
        {
            // TODO/MBA: testing
            SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
@@ -672,6 +682,7 @@
                // nothing has been changed.
                // If the replacement graphic changes by this action, the document
                // will be already modified via other mechanisms.
                if (embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc)
                {
                    bool bResetEnableSetModified(false);
                    if ( GetDoc()->GetDocShell()->IsEnableSetModified() )