[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Nov 28 05:18:18 PST 2014


 sw/inc/textboxhelper.hxx                                    |    2 +
 sw/qa/extras/ooxmlexport/data/textbox-right-edge.docx       |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                    |   13 ++++++++++++
 sw/source/core/doc/textboxhelper.cxx                        |    9 ++++++++
 sw/source/core/objectpositioning/anchoredobjectposition.cxx |    8 ++++++-
 5 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 9101ccfa400e38f420fbda0a1c064550534eb26d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 28 12:34:40 2014 +0100

    SwAnchoredObjectPosition::_GetHoriAlignmentValues: fix position of textboxes
    
    The problem was that the right edge of the textbox was outside the parent
    draw shape, which is unexpected for rectangle shapes.
    
    Change-Id: I5154a61b07d3d8d894491e76923b3b017aa3ce8e

diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 55c0ac8..89802c3 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -77,6 +77,8 @@ public:
      * returned.
      */
     static std::set<const SwFrmFmt*> findTextBoxes(const SwNode& rNode);
+    /// Is pObject a textbox of a drawinglayer shape?
+    static bool isTextBox(const SdrObject* pObject);
     /// Build a textbox -> shape format map.
     static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const SwDoc* pDoc);
     /// Count number of shapes in the document, excluding TextBoxes.
diff --git a/sw/qa/extras/ooxmlexport/data/textbox-right-edge.docx b/sw/qa/extras/ooxmlexport/data/textbox-right-edge.docx
new file mode 100644
index 0000000..990d1e4
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/textbox-right-edge.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index c4a7934..2c4f608 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -606,6 +606,19 @@ DECLARE_OOXMLEXPORT_TEST(testNumOverrideStart, "num-override-start.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int16(3), comphelper::SequenceAsHashMap(xRules->getByIndex(1))["StartWith"].get<sal_Int16>());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTextboxRightEdge, "textbox-right-edge.docx")
+{
+    // I'm fairly sure this is not specific to DOCX, but the doc model created
+    // by the ODF import doesn't trigger this bug, so let's test this here
+    // instead of uiwriter.
+    int nShapeLeft = parseDump("//SwAnchoredDrawObject/bounds", "left").toInt32();
+    int nShapeWidth = parseDump("//SwAnchoredDrawObject/bounds", "width").toInt32();
+    int nTextboxLeft = parseDump("//fly/infos/bounds", "left").toInt32();
+    int nTextboxWidth = parseDump("//fly/infos/bounds", "width").toInt32();
+    // This is a rectangle, make sure the right edge of the textbox is still
+    // inside the draw shape.
+    CPPUNIT_ASSERT(nShapeLeft + nShapeWidth >= nTextboxLeft + nTextboxWidth);
+}
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 0c8ede9..c59bcbd 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -181,6 +181,15 @@ bool lcl_isTextBox(SdrObject* pSdrObject, std::set<const SwFrmFmt*>& rTextBoxes)
     return pObject && rTextBoxes.find(pObject->GetFmt()) != rTextBoxes.end();
 }
 
+bool SwTextBoxHelper::isTextBox(const SdrObject* pObject)
+{
+    const SwVirtFlyDrawObj* pVirtFlyDrawObj = PTR_CAST(SwVirtFlyDrawObj, pObject);
+    if (!pVirtFlyDrawObj)
+        return false;
+    std::set<const SwFrmFmt*> aTextBoxes = findTextBoxes(pVirtFlyDrawObj->GetFmt()->GetDoc());
+    return aTextBoxes.find(pVirtFlyDrawObj->GetFmt()) != aTextBoxes.end();
+}
+
 sal_Int32 SwTextBoxHelper::getCount(SdrPage* pPage, std::set<const SwFrmFmt*>& rTextBoxes)
 {
     sal_Int32 nRet = 0;
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 7cf57d2..94bf450 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -34,6 +34,7 @@
 #include <editeng/ulspitem.hxx>
 #include <ndtxt.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <textboxhelper.hxx>
 
 using namespace ::com::sun::star;
 using namespace objectpositioning;
@@ -662,8 +663,13 @@ void SwAnchoredObjectPosition::_GetHoriAlignmentValues( const SwFrm&  _rHoriOrie
         default:
         {
             nWidth = (_rHoriOrientFrm.Frm().*fnRect->fnGetWidth)();
+
+            // When positioning TextBoxes, always ignore flys anchored at the
+            // text frame, as we do want to have the textbox overlap with its
+            // draw shape.
+            bool bIgnoreFlysAnchoredAtFrame = !_bObjWrapThrough || SwTextBoxHelper::isTextBox(&GetObject());
             nOffset = _rHoriOrientFrm.IsTxtFrm() ?
-                   static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( !_bObjWrapThrough ) :
+                   static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( bIgnoreFlysAnchoredAtFrame ) :
                    0;
             break;
         }


More information about the Libreoffice-commits mailing list