[Libreoffice-commits] core.git: include/sfx2 include/svx sc/source sd/qa sd/source svx/source sw/source

Caolán McNamara caolanm at redhat.com
Wed Jun 29 09:49:33 UTC 2016


 include/sfx2/objsh.hxx                      |    6 +-
 include/svx/svdmodel.hxx                    |    4 +
 sc/source/ui/docshell/docsh.cxx             |    8 ++
 sd/qa/unit/data/odp/tdf99729-legacy.odp     |binary
 sd/qa/unit/data/odp/tdf99729-new.odp        |binary
 sd/qa/unit/import-tests.cxx                 |   80 ++++++++++++++++++++++++++++
 sd/source/ui/docshell/docshel4.cxx          |    7 ++
 svx/source/svdraw/svdmodel.cxx              |   33 ++++++++++-
 svx/source/svdraw/svdotextdecomposition.cxx |   18 ++++--
 sw/source/uibase/app/docshini.cxx           |   10 +++
 10 files changed, 155 insertions(+), 11 deletions(-)

New commits:
commit 488fd60c2dc2372f3dc33f5a5313e4f032adf968
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jun 29 10:12:28 2016 +0100

    Reinstate: tdf#99729: fix text alignment (no autofit & no full width)
    
    with extra disposes to shutdown the test thingies in the right order
    
    This reverts commit a4780b3c8b45261e59ed3cbb34c4463d58ad8079.
    
    Change-Id: I13282d6bc54a0dceb3ed91a04cd438a9011154fe
    Reviewed-on: https://gerrit.libreoffice.org/26756
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 6f0c244..6b694f9 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -217,8 +217,6 @@ private:
 
     bool                        CloseInternal();
 
-    SAL_DLLPRIVATE static bool IsOwnStorageFormat(const SfxMedium &);
-
     SAL_DLLPRIVATE void UpdateTime_Impl(const css::uno::Reference<
         css::document::XDocumentProperties> & i_xDocProps);
 
@@ -626,7 +624,9 @@ public:
     virtual void    SetProtectionPassword( const OUString &rPassword );
     virtual bool    GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash );
 
-    SAL_DLLPRIVATE std::shared_ptr<GDIMetaFile> CreatePreviewMetaFile_Impl( bool bFullContent ) const;
+    static bool IsOwnStorageFormat(const SfxMedium &);
+
+    SAL_DLLPRIVATE std::shared_ptr<GDIMetaFile> CreatePreviewMetaFile_Impl(bool bFullContent) const;
 
     SAL_DLLPRIVATE bool IsPackageStorageFormat_Impl(const SfxMedium &) const;
 
diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx
index ae3c68c..81ec9c5 100644
--- a/include/svx/svdmodel.hxx
+++ b/include/svx/svdmodel.hxx
@@ -544,6 +544,10 @@ public:
     void SetAddExtLeading( bool bEnabled );
     bool IsAddExtLeading() const { return mbAddExtLeading; }
 
+    // tdf#99729 compatibility flag
+    void SetAnchoredTextOverflowLegacy(bool bEnabled);
+    bool IsAnchoredTextOverflowLegacy() const;
+
     void ReformatAllTextObjects();
 
     SdrOutliner* createOutliner( OutlinerMode nOutlinerMode );
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 79cb8c8..d700e16 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -557,6 +557,14 @@ bool ScDocShell::Load( SfxMedium& rMedium )
     //  -> initialize the others from options (before loading)
     InitOptions(true);
 
+    // If this is an ODF file being loaded, then by default, use legacy processing
+    // for tdf#99729 (if required, it will be overriden in *::ReadUserDataSequence())
+    if (IsOwnStorageFormat(rMedium))
+    {
+        if (aDocument.GetDrawLayer())
+            aDocument.GetDrawLayer()->SetAnchoredTextOverflowLegacy(true);
+    }
+
     GetUndoManager()->Clear();
 
     bool bRet = SfxObjectShell::Load( rMedium );
diff --git a/sd/qa/unit/data/odp/tdf99729-legacy.odp b/sd/qa/unit/data/odp/tdf99729-legacy.odp
new file mode 100644
index 0000000..899b55c
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf99729-legacy.odp differ
diff --git a/sd/qa/unit/data/odp/tdf99729-new.odp b/sd/qa/unit/data/odp/tdf99729-new.odp
new file mode 100644
index 0000000..1c5a9cd
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf99729-new.odp differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 6e321f4..b32ba90 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -68,6 +68,9 @@
 #include <comphelper/processfactory.hxx>
 #include <vcl/pngread.hxx>
 #include <vcl/bitmapaccess.hxx>
+#include <sfx2/frame.hxx>
+#include <com/sun/star/frame/XModel2.hpp>
+#include <com/sun/star/frame/XController2.hpp>
 
 using namespace ::com::sun::star;
 
@@ -117,6 +120,7 @@ public:
     void testTdf93097();
     void testTdf62255();
     void testTdf93124();
+    void testTdf99729();
     void testTdf89927();
     void testTdf93868();
     void testTdf95932();
@@ -167,6 +171,7 @@ public:
     CPPUNIT_TEST(testTdf93097);
     CPPUNIT_TEST(testTdf62255);
     CPPUNIT_TEST(testTdf93124);
+    CPPUNIT_TEST(testTdf99729);
     CPPUNIT_TEST(testTdf89927);
     CPPUNIT_TEST(testTdf93868);
     CPPUNIT_TEST(testTdf95932);
@@ -1319,6 +1324,81 @@ void SdImportTest::testTdf93124()
     xDocShRef->DoClose();
 }
 
+void SdImportTest::testTdf99729()
+{
+    const char* filenames[] = { "/sd/qa/unit/data/odp/tdf99729-new.odp", "/sd/qa/unit/data/odp/tdf99729-legacy.odp" };
+    int nonwhitecounts[] = { 0, 0 };
+    for (unsigned int i = 0; i < sizeof(filenames)/sizeof(filenames[0]); ++i)
+    {
+        // 1st check for new behaviour - having AnchoredTextOverflowLegacy compatibility flag set to false in settings.xml
+        sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(filenames[i]), ODP);
+
+        const css::uno::Reference< css::frame::XFrame > xFrame = SfxFrame::CreateBlankFrame();
+        CPPUNIT_ASSERT(xFrame.is());
+        const css::uno::Reference< css::frame::XModel2 > xModel(xDocShRef->GetModel(), css::uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xModel.is());
+        const css::uno::Reference< css::frame::XController2 > xController(xModel->createViewController(
+            "Default",
+            css::uno::Sequence< css::beans::PropertyValue >(),
+            xFrame
+            ), css::uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xController.is());
+        xController->attachModel(xModel.get());
+        xModel->connectController(xController.get());
+        xFrame->setComponent(xController->getComponentWindow(), xController.get());
+        xController->attachFrame(xFrame);
+        xModel->setCurrentController(xController.get());
+
+        uno::Reference < uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
+        CPPUNIT_ASSERT(xContext.is());
+        uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create(xContext);
+        CPPUNIT_ASSERT(xGraphicExporter.is());
+
+        uno::Sequence< beans::PropertyValue > aFilterData(2);
+        aFilterData[0].Name = "PixelWidth";
+        aFilterData[0].Value <<= (sal_Int32)(320);
+        aFilterData[1].Name = "PixelHeight";
+        aFilterData[1].Value <<= (sal_Int32)(240);
+
+        utl::TempFile aTempFile;
+        aTempFile.EnableKillingFile();
+
+        uno::Sequence< beans::PropertyValue > aDescriptor(3);
+        aDescriptor[0].Name = "URL";
+        aDescriptor[0].Value <<= aTempFile.GetURL();
+        aDescriptor[1].Name = "FilterName";
+        aDescriptor[1].Value <<= OUString("PNG");
+        aDescriptor[2].Name = "FilterData";
+        aDescriptor[2].Value <<= aFilterData;
+
+        uno::Reference< lang::XComponent > xPage(getPage(0, xDocShRef), uno::UNO_QUERY);
+        xGraphicExporter->setSourceDocument(xPage);
+        xGraphicExporter->filter(aDescriptor);
+
+        SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
+        vcl::PNGReader aPNGReader(aFileStream);
+        BitmapEx aBMPEx = aPNGReader.Read();
+        Bitmap aBMP = aBMPEx.GetBitmap();
+        BitmapReadAccess* pRead = aBMP.AcquireReadAccess();
+        for (long nX = 154; nX < (154 + 12); ++nX)
+        {
+            for (long nY = 16; nY < (16 + 96); ++nY)
+            {
+                const Color aColor = pRead->GetColor(nY, nX);
+                if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff) || (aColor.GetBlue() != 0xff))
+                    ++nonwhitecounts[i];
+            }
+        }
+        xController->dispose();
+        xFrame->dispose();
+    }
+    // The numbers 1-9 should be above the Text Box in rectangle 154,16 - 170,112.
+    // If text alignment is wrong, the rectangle will be white.
+    CPPUNIT_ASSERT_MESSAGE("Tdf99729: vertical alignment of text is incorrect!", nonwhitecounts[0]>200); // it was 245 at my testing
+    // The numbers 1-9 should be below the Text Box -> rectangle 154,16 - 170,112 should be white.
+    CPPUNIT_ASSERT_MESSAGE("Tdf99729: legacy vertical alignment of text is incorrect!", nonwhitecounts[1] == 0);
+}
+
 void SdImportTest::testTdf89927()
 {
     sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf89927.pptx"), PPTX);
diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx
index 844548f..5fa1204 100644
--- a/sd/source/ui/docshell/docshel4.cxx
+++ b/sd/source/ui/docshell/docshel4.cxx
@@ -264,6 +264,13 @@ bool DrawDocShell::Load( SfxMedium& rMedium )
 {
     mbNewDocument = false;
 
+    // If this is an ODF file being loaded, then by default, use legacy processing
+    // for tdf#99729 (if required, it will be overriden in *::ReadUserDataSequence())
+    if (IsOwnStorageFormat(rMedium))
+    {
+        mpDoc->SetAnchoredTextOverflowLegacy(true);
+    }
+
     bool       bRet = false;
     bool       bStartPresentation = false;
     ErrCode nError = ERRCODE_NONE;
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index 5c66289..8d97029 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -103,6 +103,8 @@ struct SdrModelImpl
 {
     SfxUndoManager* mpUndoManager;
     SdrUndoFactory* mpUndoFactory;
+
+    bool mbAnchoredTextOverflowLegacy; // tdf#99729 compatibility flag
 };
 
 
@@ -112,6 +114,7 @@ void SdrModel::ImpCtor(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* _pEmbe
     mpImpl.reset(new SdrModelImpl);
     mpImpl->mpUndoManager=nullptr;
     mpImpl->mpUndoFactory=nullptr;
+    mpImpl->mbAnchoredTextOverflowLegacy = false;
     mbInDestruction = false;
     aObjUnit=SdrEngineDefaults::GetMapFraction();
     eObjUnit=SdrEngineDefaults::GetMapUnit();
@@ -1886,6 +1889,16 @@ void SdrModel::SetAddExtLeading( bool bEnabled )
     }
 }
 
+void SdrModel::SetAnchoredTextOverflowLegacy(bool bEnabled)
+{
+    mpImpl->mbAnchoredTextOverflowLegacy = bEnabled;
+}
+
+bool SdrModel::IsAnchoredTextOverflowLegacy() const
+{
+    return mpImpl->mbAnchoredTextOverflowLegacy;
+}
+
 void SdrModel::ReformatAllTextObjects()
 {
     ImpReformatAllTextObjects();
@@ -1925,16 +1938,28 @@ SvxNumType SdrModel::GetPageNumType() const
     return SVX_ARABIC;
 }
 
-void SdrModel::ReadUserDataSequenceValue(const css::beans::PropertyValue* /*pValue*/)
+void SdrModel::ReadUserDataSequenceValue(const css::beans::PropertyValue* pValue)
+{
+    bool bBool = false;
+    if (pValue->Name == "AnchoredTextOverflowLegacy")
+    {
+        if (pValue->Value >>= bBool)
+        {
+            mpImpl->mbAnchoredTextOverflowLegacy = bBool;
+        }
+    }
+}
+
+template <typename T>
+inline void addPair(std::vector< std::pair< OUString, Any > >& aUserData, const OUString& name, const T val)
 {
-    (void) this; // TODO: Read common model-level values
+    aUserData.push_back(std::pair< OUString, Any >(name, css::uno::makeAny(val)));
 }
 
 void SdrModel::WriteUserDataSequence(css::uno::Sequence < css::beans::PropertyValue >& rValues, bool /*bBrowse*/)
 {
     std::vector< std::pair< OUString, Any > > aUserData;
-    (void) this;
-    // TODO: Write common model-level properties (e.g. to settings.xml)
+    addPair(aUserData, "AnchoredTextOverflowLegacy", IsAnchoredTextOverflowLegacy());
 
     const sal_Int32 nOldLength = rValues.getLength();
     rValues.realloc(nOldLength + aUserData.size());
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index 27f289d..63bfcdd 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -972,14 +972,24 @@ void SdrTextObj::impDecomposeBlockTextPrimitive(
             // 'measurement' of the real size of block text would not work
             Size aMaxAutoPaperSize(aAnchorTextSize);
 
-            if(bHorizontalIsBlock)
+            // Usual processing - always grow in one of directions
+            bool bAllowGrowVertical = !bVerticalWriting;
+            bool bAllowGrowHorizontal = bVerticalWriting;
+            // Compatibility mode for tdf#99729
+            if (this->pModel->IsAnchoredTextOverflowLegacy())
             {
-                // allow to grow vertical for horizontal blocks
+                bAllowGrowVertical = bHorizontalIsBlock;
+                bAllowGrowHorizontal = bVerticalIsBlock;
+            }
+
+            if (bAllowGrowVertical)
+            {
+                // allow to grow vertical for horizontal texts
                 aMaxAutoPaperSize.setHeight(1000000);
             }
-            else if(bVerticalIsBlock)
+            else if (bAllowGrowHorizontal)
             {
-                // allow to grow horizontal for vertical blocks
+                // allow to grow horizontal for vertical texts
                 aMaxAutoPaperSize.setWidth(1000000);
             }
 
diff --git a/sw/source/uibase/app/docshini.cxx b/sw/source/uibase/app/docshini.cxx
index 92b2394..7d8bf17 100644
--- a/sw/source/uibase/app/docshini.cxx
+++ b/sw/source/uibase/app/docshini.cxx
@@ -88,6 +88,7 @@
 #include <swerror.h>
 #include <globals.hrc>
 #include <unochart.hxx>
+#include <drawdoc.hxx>
 
 #include <svx/CommonStyleManager.hxx>
 
@@ -490,6 +491,15 @@ void SwDocShell::ReactivateModel()
 bool  SwDocShell::Load( SfxMedium& rMedium )
 {
     bool bRet = false;
+
+    // If this is an ODF file being loaded, then by default, use legacy processing
+    // for tdf#99729 (if required, it will be overriden in *::ReadUserDataSequence())
+    if (IsOwnStorageFormat(rMedium))
+    {
+        if (m_pDoc && m_pDoc->getIDocumentDrawModelAccess().GetDrawModel())
+            m_pDoc->getIDocumentDrawModelAccess().GetDrawModel()->SetAnchoredTextOverflowLegacy(true);
+    }
+
     if( SfxObjectShell::Load( rMedium ))
     {
         SAL_INFO( "sw.ui", "after SfxInPlaceObject::Load" );


More information about the Libreoffice-commits mailing list