diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-05-29 12:15:28 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-05-29 14:43:44 +0200 |
commit | 3e266853608eb26fb15ac508ba78d74afb72f51c (patch) | |
tree | 4d00dc66fac8b984ea53cf105e3ddacee6c564c3 | |
parent | ad8aeb6e02444aa007ef38a59bbd84d67d60ffad (diff) |
SwTextBoxHelper::create(): initialize position
The situation is a bit more complicated here,
drawing::XCustomShapeEngine returns the text rectangle in absolute
coordinates, but that's on the drawpage. So count the relative
coordinates, and then just adjust the position we got from the original
shape.
Change-Id: Ibfbc183e5170037c8c281d61ce802a19a7acda17
-rw-r--r-- | sw/inc/textboxhelper.hxx | 4 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 28 |
2 files changed, 26 insertions, 6 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index 747e729762ef..cb0a643b8b84 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -40,8 +40,8 @@ public: static void syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const OUString& rPropertyName, const css::uno::Any& rValue); /// If we have an associated TextFrame, then return that. static SwFrmFmt* findTextBox(SwFrmFmt* pShape); - /// Return the textbox rectangle of a draw shape (absolute values, in twips). - static Rectangle getTextRectangle(SwFrmFmt* pShape); + /// Return the textbox rectangle of a draw shape (in twips). + static Rectangle getTextRectangle(SwFrmFmt* pShape, bool bAbsolute = true); /// Look up TextFrames in a document, which are in fact TextBoxes. static std::list<SwFrmFmt*> findTextBoxes(const SwDoc* pDoc); diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 1e92c67ce9de..ad4bf62a07fe 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -70,6 +70,14 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape) // Also initialize the properties, which are not constant, but inherited from the shape's ones. uno::Reference<drawing::XShape> xShape(pShape->FindRealSdrObject()->getUnoShape(), uno::UNO_QUERY); syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, "Size", uno::makeAny(xShape->getSize())); + + uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY); + syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, "HoriOrient", xShapePropertySet->getPropertyValue("HoriOrient")); + syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, "HoriOrientRelation", xShapePropertySet->getPropertyValue("HoriOrientRelation")); + syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, "VertOrient", xShapePropertySet->getPropertyValue("VertOrient")); + syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, "VertOrientRelation", xShapePropertySet->getPropertyValue("VertOrientRelation")); + syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, "HoriOrientPosition", xShapePropertySet->getPropertyValue("HoriOrientPosition")); + syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, "VertOrientPosition", xShapePropertySet->getPropertyValue("VertOrientPosition")); } } @@ -196,13 +204,25 @@ uno::Any SwTextBoxHelper::queryInterface(SwFrmFmt* pShape, const uno::Type& rTyp return aRet; } -Rectangle SwTextBoxHelper::getTextRectangle(SwFrmFmt* pShape) +Rectangle SwTextBoxHelper::getTextRectangle(SwFrmFmt* pShape, bool bAbsolute) { Rectangle aRet; aRet.SetEmpty(); SdrObjCustomShape* pCustomShape = dynamic_cast<SdrObjCustomShape*>(pShape->FindRealSdrObject()); if (pCustomShape) pCustomShape->GetTextBounds(aRet); + + if (!bAbsolute) + { + // Relative, so count the logic (reference) rectangle, see the EnhancedCustomShape2d ctor. + Point aPoint(pCustomShape->GetSnapRect().Center()); + Size aSize(pCustomShape->GetLogicRect().GetSize()); + aPoint.X() -= aSize.Width() / 2; + aPoint.Y() -= aSize.Height() / 2; + Rectangle aLogicRect(aPoint, aSize); + aRet.Move(-1 * aLogicRect.Left(), -1 * aLogicRect.Top()); + } + return aRet; } @@ -274,7 +294,7 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 // Position/size should be the text position/size, not the shape one as-is. if (bAdjustX || bAdjustY || bAdjustSize) { - Rectangle aRect = getTextRectangle(pShape); + Rectangle aRect = getTextRectangle(pShape, /*bAbsolute=*/false); if (!aRect.IsEmpty()) { if (bAdjustX || bAdjustY) @@ -283,9 +303,9 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 if (aValue >>= nValue) { if (bAdjustX) - nValue = TWIPS_TO_MM(aRect.getX()); + nValue += TWIPS_TO_MM(aRect.getX()); else if (bAdjustY) - nValue = TWIPS_TO_MM(aRect.getY()); + nValue += TWIPS_TO_MM(aRect.getY()); aValue <<= nValue; } } |