[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - sw/inc sw/qa sw/source writerfilter/source

Patrick Jaap patrick.jaap at tu-dresden.de
Thu Jan 4 09:19:13 UTC 2018


 sw/inc/IDocumentSettingAccess.hxx                           |    2 +
 sw/qa/extras/ooxmlimport/data/tdf112443.docx                |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                    |   10 ++++++
 sw/source/core/doc/DocumentSettingManager.cxx               |    7 ++++
 sw/source/core/inc/DocumentSettingManager.hxx               |    1 
 sw/source/core/layout/flylay.cxx                            |    6 ++++
 sw/source/core/objectpositioning/anchoredobjectposition.cxx |   18 ++++++++++++
 sw/source/filter/xml/xmlimp.cxx                             |    7 ++++
 sw/source/uibase/uno/SwXDocumentSettings.cxx                |   17 +++++++++++
 writerfilter/source/filter/WriterFilter.cxx                 |    2 -
 10 files changed, 67 insertions(+), 3 deletions(-)

New commits:
commit 529924a29ce6f688337f91de9dcf1aa9869e91ad
Author: Patrick Jaap <patrick.jaap at tu-dresden.de>
Date:   Wed Nov 29 12:41:33 2017 +0100

    tdf#112443 disable off-page content positioning
    
    Disable the positioning for objects that are completely off-page.
    During import, LO writer forces content always back to the page
    and causes unwanted content on the page in constrast to MSO.
    
    To achive this the top/left position of the content is compared to the bottom/right border of the clipping region.
    
    A new compatibility flag OFF_PAGE_POSITIONING is introduced for
    legacy rendering of legacy documents.
    
    A unit test demonstrates the issue.
    
    It resolves tdf#112443.
    
    Change-Id: I263c129f9f09ed909ad777a34f8b9ffc84d871e4
    Reviewed-on: https://gerrit.libreoffice.org/43313
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 8d62b79f168180c6992eb483ec864d473050635f)
    Reviewed-on: https://gerrit.libreoffice.org/47260

diff --git a/sw/inc/IDocumentSettingAccess.hxx b/sw/inc/IDocumentSettingAccess.hxx
index 6e9942bce66c..41b2c4ff79c3 100644
--- a/sw/inc/IDocumentSettingAccess.hxx
+++ b/sw/inc/IDocumentSettingAccess.hxx
@@ -81,6 +81,8 @@ enum class DocumentSettingId
     SURROUND_TEXT_WRAP_SMALL,
     PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
     SUBTRACT_FLYS,
+    // tdf#112443 disable off-page content positioning
+    DISABLE_OFF_PAGE_POSITIONING,
     // COMPATIBILITY FLAGS END
     BROWSE_MODE,
     HTML_MODE,
diff --git a/sw/qa/extras/ooxmlimport/data/tdf112443.docx b/sw/qa/extras/ooxmlimport/data/tdf112443.docx
new file mode 100644
index 000000000000..385ce514c1c9
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf112443.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index cafef1d2ee53..4d65beeb90c4 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -118,7 +118,6 @@ public:
     }
 };
 
-
 DECLARE_OOXMLIMPORT_TEST(testImageHyperlink, "image-hyperlink.docx")
 {
     OUString URL = getProperty<OUString>(getShape(1), "HyperLinkURL");
@@ -1559,6 +1558,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx")
         sal_Int32(-1), getProperty<sal_Int32>(xText, "CharColor"));
 }
 
+
+DECLARE_OOXMLIMPORT_TEST(testTdf112443, "tdf112443.docx")
+{
+    // the position of the flying text frame should be off page
+    // 30624 below its anchor
+    OUString aTop = parseDump("//fly[1]/infos/bounds", "top");
+    CPPUNIT_ASSERT_EQUAL( OUString("30624"), aTop );
+
+}
 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx b/sw/source/core/doc/DocumentSettingManager.cxx
index 47c513e1486e..77de92017537 100644
--- a/sw/source/core/doc/DocumentSettingManager.cxx
+++ b/sw/source/core/doc/DocumentSettingManager.cxx
@@ -87,7 +87,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc)
     mbPropLineSpacingShrinksFirstLine(true),
     mbSubtractFlys(false),
     mApplyParagraphMarkFormatToNumbering(false),
-    mbLastBrowseMode( false )
+    mbLastBrowseMode( false ),
+    mbDisableOffPagePositioning ( false )
 
     // COMPATIBILITY FLAGS END
 {
@@ -202,6 +203,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ DocumentSettingId id) const
         case DocumentSettingId::EMBED_FONTS: return mEmbedFonts;
         case DocumentSettingId::EMBED_SYSTEM_FONTS: return mEmbedSystemFonts;
         case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: return mApplyParagraphMarkFormatToNumbering;
+        case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING: return mbDisableOffPagePositioning;
         default:
             OSL_FAIL("Invalid setting id");
     }
@@ -416,6 +418,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ DocumentSettingId id, /*[in]*/ boo
         case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING:
             mApplyParagraphMarkFormatToNumbering = value;
             break;
+        case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING:
+            mbDisableOffPagePositioning = value;
+            break;
         default:
             OSL_FAIL("Invalid setting id");
     }
diff --git a/sw/source/core/inc/DocumentSettingManager.hxx b/sw/source/core/inc/DocumentSettingManager.hxx
index 81dca8d42780..5f762d099ca8 100644
--- a/sw/source/core/inc/DocumentSettingManager.hxx
+++ b/sw/source/core/inc/DocumentSettingManager.hxx
@@ -154,6 +154,7 @@ class DocumentSettingManager :
     bool mApplyParagraphMarkFormatToNumbering;
 
     bool mbLastBrowseMode                           : 1;
+    bool mbDisableOffPagePositioning; // tdf#112443
 
 public:
 
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 42e488a6b1b3..8a3af6c27006 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -495,6 +495,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
             {
                 const long nOld = getFrameArea().Top();
 
+                // tdf#112443 disable positioning if content is completely off page
+                bool bDisableOffPagePositioning = GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
+                if ( !bDisableOffPagePositioning || nOld <= nClipBot)
                 {
                     SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
                     aFrm.Pos().Y() = std::max( aClip.Top(), nClipBot - aFrm.Height() );
@@ -512,6 +515,9 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
         {
             const long nOld = getFrameArea().Left();
 
+            // tdf#112443 disable positioning if content is completely off page
+            bool bDisableOffPagePositioning = GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
+            if ( !bDisableOffPagePositioning || nOld <= nClipRig )
             {
                 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
                 aFrm.Pos().X() = std::max( aClip.Left(), nClipRig - aFrm.Width() );
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 0e7ec2e72ce0..94afc9ddc38d 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -455,6 +455,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
         }
         else
         {
+            /// tdf#112443 if position is completely off-page
+            // return the proposed position and do not adjust it.
+            bool bDisablePositioning = mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
+
+            if ( bDisablePositioning && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.Right() )
+            {
+                return nProposedRelPosY;
+            }
+
             if ( bCheckBottom &&
                  nTopOfAnch + nAdjustedRelPosY + aObjSize.Width() >
                     aPgAlignArea.Right() )
@@ -471,6 +480,15 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
     }
     else
     {
+        // tdf#112443 if position is completely off-page
+        // return the proposed position and do not adjust it.
+        bool bDisablePositioning =  mpFrameFormat->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
+
+        if ( bDisablePositioning && nTopOfAnch + nAdjustedRelPosY > aPgAlignArea.Bottom() )
+        {
+            return nProposedRelPosY;
+        }
+
         // #i31805# - consider value of <bCheckBottom>
         if ( bCheckBottom &&
              nTopOfAnch + nAdjustedRelPosY + aObjSize.Height() >
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index ccc00398576a..cb2e6a64eae8 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -1105,6 +1105,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
     aExcludeWhenNotLoadingUserSettings.insert("TabOverMargin");
     aExcludeWhenNotLoadingUserSettings.insert("PropLineSpacingShrinksFirstLine");
     aExcludeWhenNotLoadingUserSettings.insert("SubtractFlysAnchoredAtFlys");
+    aExcludeWhenNotLoadingUserSettings.insert("DisableOffPagePositioning");
 
     sal_Int32 nCount = aConfigProps.getLength();
     const PropertyValue* pValues = aConfigProps.getConstArray();
@@ -1138,6 +1139,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
     bool bTabOverMargin = false;
     bool bPropLineSpacingShrinksFirstLine = false;
     bool bSubtractFlysAnchoredAtFlys = false;
+    bool bDisableOffPagePositioning = false;
 
     const PropertyValue* currentDatabaseDataSource = nullptr;
     const PropertyValue* currentDatabaseCommand = nullptr;
@@ -1230,6 +1232,8 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
                     bPropLineSpacingShrinksFirstLine = true;
                 else if (pValues->Name == "SubtractFlysAnchoredAtFlys")
                     bSubtractFlysAnchoredAtFlys = true;
+                else if (pValues->Name == "DisableOffPagePositioning")
+                    bDisableOffPagePositioning = true;
             }
             catch( Exception& )
             {
@@ -1390,6 +1394,9 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
     if (!bSubtractFlysAnchoredAtFlys)
         xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true));
 
+    if ( !bDisableOffPagePositioning )
+        xProps->setPropertyValue("DisableOffPagePositioning", makeAny(true));
+
     SwDoc *pDoc = getDoc();
     SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false );
     if( pPrinter )
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index ed0b315a02b7..ee86063fea52 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -134,6 +134,7 @@ enum SwDocumentSettingsPropertyHandles
     HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING,
     HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE,
     HANDLE_SUBTRACT_FLYS,
+    HANDLE_DISABLE_OFF_PAGE_POSITIONING,
 };
 
 static MasterPropertySetInfo * lcl_createSettingsInfo()
@@ -210,6 +211,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo()
         { OUString("ApplyParagraphMarkFormatToNumbering"), HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, cppu::UnoType<bool>::get(), 0},
         { OUString("PropLineSpacingShrinksFirstLine"),       HANDLE_PROP_LINE_SPACING_SHRINKS_FIRST_LINE,         cppu::UnoType<bool>::get(),           0},
         { OUString("SubtractFlysAnchoredAtFlys"),       HANDLE_SUBTRACT_FLYS,         cppu::UnoType<bool>::get(),           0},
+        { OUString("DisableOffPagePositioning"),       HANDLE_DISABLE_OFF_PAGE_POSITIONING,         cppu::UnoType<bool>::get(),           0},
 /*
  * As OS said, we don't have a view when we need to set this, so I have to
  * find another solution before adding them to this property set - MTG
@@ -855,6 +857,16 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
             }
         }
         break;
+        case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
+        {
+            bool bTmp;
+            if (rValue >>= bTmp)
+            {
+                mpDoc->getIDocumentSettingAccess().set(
+                    DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING, bTmp);
+            }
+        }
+        break;
         default:
             throw UnknownPropertyException();
     }
@@ -1269,6 +1281,11 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf
             rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::SUBTRACT_FLYS);
         }
         break;
+        case HANDLE_DISABLE_OFF_PAGE_POSITIONING:
+        {
+            rValue <<= mpDoc->getIDocumentSettingAccess().get(DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING);
+        }
+        break;
         default:
             throw UnknownPropertyException();
     }
diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx
index 01d0f66a652f..499ffa9df0dd 100644
--- a/writerfilter/source/filter/WriterFilter.cxx
+++ b/writerfilter/source/filter/WriterFilter.cxx
@@ -266,7 +266,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& rDesc
     return false;
 }
 
-
 void WriterFilter::cancel()
 {
 }
@@ -303,6 +302,7 @@ void WriterFilter::setTargetDocument(const uno::Reference< lang::XComponent >& x
     xSettings->setPropertyValue("TreatSingleColumnBreakAsPageBreak", uno::makeAny(true));
     xSettings->setPropertyValue("PropLineSpacingShrinksFirstLine", uno::makeAny(true));
     xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::makeAny(true));
+    xSettings->setPropertyValue("DisableOffPagePositioning", uno::makeAny(true));
 }
 
 void WriterFilter::setSourceDocument(const uno::Reference< lang::XComponent >& xDoc)


More information about the Libreoffice-commits mailing list