summaryrefslogtreecommitdiff
path: root/svx/source/svdraw
diff options
context:
space:
mode:
Diffstat (limited to 'svx/source/svdraw')
-rw-r--r--svx/source/svdraw/svdedtv1.cxx153
-rw-r--r--svx/source/svdraw/svdlegacy.cxx40
-rw-r--r--svx/source/svdraw/svdmrkv.cxx60
-rw-r--r--svx/source/svdraw/svdograf.cxx2
-rw-r--r--svx/source/svdraw/svdopath.cxx34
5 files changed, 181 insertions, 108 deletions
diff --git a/svx/source/svdraw/svdedtv1.cxx b/svx/source/svdraw/svdedtv1.cxx
index d6dfc708c1e1..f565d99e398f 100644
--- a/svx/source/svdraw/svdedtv1.cxx
+++ b/svx/source/svdraw/svdedtv1.cxx
@@ -268,36 +268,22 @@ void SdrEditView::ResizeMarkedObj(const basegfx::B2DPoint& rRefPoint, const base
double SdrEditView::GetMarkedObjRotate() const
{
- if(!areSdrObjectsSelected())
- {
- return 0.0;
- }
-
- SdrObject* pSingle = getSelectedIfSingle();
-
- if(pSingle)
- {
- return pSingle->getSdrObjectRotate();
- }
-
- const SdrObjectVector aSelection(getSelectedSdrObjectVectorFromSdrMarkView());
+ SdrObject* pCandidate = getSelectedIfSingle();
- if(aSelection.size())
+ if(!pCandidate)
{
- SdrObject* pObject = aSelection[0];
+ // for multiselection use the rotation angle of the 1st object
+ const SdrObjectVector aSelection(getSelectedSdrObjectVectorFromSdrMarkView());
- if(pObject)
+ if(aSelection.size())
{
- return pObject->getSdrObjectRotate();
- }
- else
- {
- OSL_ENSURE(false, "OOps, areSdrObjectsSelected() == true, but no first object (!)");
+ pCandidate = aSelection[0];
}
}
- else
+
+ if(pCandidate)
{
- OSL_ENSURE(false, "OOps, areSdrObjectsSelected() == true, but no objects (!)");
+ return pCandidate->getSdrObjectRotate();
}
return 0.0;
@@ -496,36 +482,30 @@ void SdrEditView::MirrorMarkedObjVertical(bool bCopy)
double SdrEditView::GetMarkedObjShearX() const
{
- double fRetval(0.0);
+ SdrObject* pCandidate = getSelectedIfSingle();
- if(areSdrObjectsSelected())
+ if(!pCandidate)
{
+ // for multiselection use the shear value of the 1st object
const SdrObjectVector aSelection(getSelectedSdrObjectVectorFromSdrMarkView());
- for(sal_uInt32 a(0); a < aSelection.size(); a++)
+ if(aSelection.size())
{
- SdrObject* pObject = aSelection[a];
-
- if(a)
- {
- const double fNew(pObject->getSdrObjectShearX());
-
- if(!basegfx::fTools::equal(fNew, fRetval))
- {
- return 0.0;
- }
- }
- else
- {
- fRetval = pObject->getSdrObjectShearX();
- }
+ pCandidate = aSelection[0];
}
+ }
- const double fMaxShearRange(F_PI2 * (89.0/90.0));
- fRetval = basegfx::clamp(fRetval, -fMaxShearRange, fMaxShearRange);
+ if(pCandidate)
+ {
+ OSL_ENSURE(
+ basegfx::fTools::less(atan(pCandidate->getSdrObjectShearX()), F_PI2 * (89.0/90.0)) &&
+ basegfx::fTools::more(atan(pCandidate->getSdrObjectShearX()), -F_PI2 * (89.0/90.0)),
+ "Shear angle is out of bounds (inside the one degree extrema corresponding to a +/- 90 degree range)");
+
+ return pCandidate->getSdrObjectShearX();
}
- return fRetval;
+ return 0.0;
}
void SdrEditView::ShearMarkedObj(const basegfx::B2DPoint& rRefPoint, double fAngle, bool bVShear, bool bCopy)
@@ -962,7 +942,7 @@ void SdrEditView::SetNotPersistAttrToMarked(const SfxItemSet& rAttr, bool /*bRep
if (rAttr.GetItemState(SDRATTR_ROTATEALL,true,&pPoolItem)==SFX_ITEM_SET)
{
const sal_Int32 nAngle(((const SdrAngleItem*)pPoolItem)->GetValue());
- const double fNewAngle((((36000 - nAngle) % 36000) * F_PI) / 18000.0);
+ const double fNewAngle(sdr::legacy::convertRotateAngleLegacyToNew(nAngle));
RotateMarkedObj(rAllSnapRange.getCenter(), fNewAngle);
}
@@ -970,7 +950,7 @@ void SdrEditView::SetNotPersistAttrToMarked(const SfxItemSet& rAttr, bool /*bRep
if (rAttr.GetItemState(SDRATTR_HORZSHEARALL,true,&pPoolItem)==SFX_ITEM_SET)
{
const sal_Int32 nAngle(((const SdrAngleItem*)pPoolItem)->GetValue());
- const double fAngle(tan(((36000 - nAngle) * F_PI) / 18000.0));
+ const double fAngle(sdr::legacy::convertShearAngleXLegacyToNew(nAngle));
ShearMarkedObj(rAllSnapRange.getCenter(), fAngle, false);
}
@@ -978,7 +958,7 @@ void SdrEditView::SetNotPersistAttrToMarked(const SfxItemSet& rAttr, bool /*bRep
if (rAttr.GetItemState(SDRATTR_VERTSHEARALL,true,&pPoolItem)==SFX_ITEM_SET)
{
const sal_Int32 nAngle(((const SdrAngleItem*)pPoolItem)->GetValue());
- const double fAngle(tan(((36000 - nAngle) * F_PI) / 18000.0));
+ const double fAngle(sdr::legacy::convertShearAngleXLegacyToNew(nAngle));
ShearMarkedObj(rAllSnapRange.getCenter(), fAngle, true);
}
@@ -1706,8 +1686,12 @@ SfxItemSet SdrEditView::GetGeoAttrFromMarked() const
fRotateRefY = aRotateAxe.getY();
}
+ // get rotation of selection. fAllRotation is in radians [0.0 .. F_2PI[
const double fAllRotation(GetMarkedObjRotate());
- const sal_Int32 nOldAllRot((basegfx::fround(((F_2PI - fAllRotation) * 18000.0) / F_PI)) % 36000);
+
+ // convert to old notation used in the UI; it's orientation is mirrored and its
+ // degrees * 100 in integer
+ const sal_Int32 nOldAllRot(sdr::legacy::convertRotateAngleNewToLegacy(fAllRotation));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_ANGLE,nOldAllRot));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_ROT_X,basegfx::fround(fRotateRefX)));
@@ -1724,15 +1708,15 @@ SfxItemSet SdrEditView::GetGeoAttrFromMarked() const
fShearRefY = aRotateAxe.getY();
}
- double fAllShearX(GetMarkedObjShearX());
- const double fMaxShearRange(F_PI2 * (89.0/90.0));
-
- fAllShearX = basegfx::snapToRange(fAllShearX, -F_PI, F_PI);
- fAllShearX = basegfx::clamp(fAllShearX, -fMaxShearRange, fMaxShearRange);
+ // get shear of selection. GetMarkedObjShearX is the tan of the shear angle in radians
+ // tan(]-F_PI2 .. F_PI2[), so apply atan to get the shear angle
+ const double fAllShearAngleX(atan(GetMarkedObjShearX()));
- const sal_Int32 nOldAllShearX(basegfx::fround(((-fAllShearX) * 18000.0) / F_PI));
+ // convert to old notation used in the UI; it's orientation is mirrored and its
+ // degrees * 100 in integer
+ const sal_Int32 nOldAllShearAngleX(sdr::legacy::convertShearAngleXNewToLegacy(fAllShearAngleX));
- aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR,nOldAllShearX));
+ aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR,nOldAllShearAngleX));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_X,basegfx::fround(fShearRefX)));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_Y,basegfx::fround(fShearRefY)));
@@ -1936,13 +1920,16 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr)
}
// rotation change?
- const double fOldRotateAngle(GetMarkedObjRotate());
+ const double fOldRotateAngle(GetMarkedObjRotate()); // radians [0.0 .. F_2PI[
double fNewRotateAngle(fOldRotateAngle);
if (SFX_ITEM_SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_ANGLE,true,&pPoolItem))
{
const sal_Int32 nAllRot(((const SfxInt32Item*)pPoolItem)->GetValue());
- fNewRotateAngle = (((36000 - nAllRot) % 36000) * F_PI) / 18000.0;
+
+ // convert from old UI units (angle in degree * 100, wrong oriented)
+ // to correctly orinented radians, same coordinate system as fOldRotateAngle
+ fNewRotateAngle = sdr::legacy::convertRotateAngleLegacyToNew(nAllRot);
}
const bool bRotate(!basegfx::fTools::equal(fOldRotateAngle, fNewRotateAngle));
@@ -1960,24 +1947,36 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr)
}
// shear change?
- double fShearAngle(0.0);
+ double fShearChange(0.0);
basegfx::B2DPoint aShearOffset(0.0, 0.0);
- bool bShearVert(false);
- bool bShear(false);
+ bool bDoShearY(false);
+ bool bDoShearDelta(false);
if(SFX_ITEM_SET == rAttr.GetItemState(SID_ATTR_TRANSFORM_SHEAR,true,&pPoolItem))
{
+ // get UI shear angle ]-9000 .. 9000[
const sal_Int32 nAllShear(((const SfxInt32Item*)pPoolItem)->GetValue());
+
+ // convert to correctly oriented shear angle in radians ]-F_PI2 .. F_PI2[
+ // limit to partial values (corresponding to +-89 degree)
+ // convert from shear angle to shear value used in the transformation to
+ // get to the same coordinate system as fOldShearValue below will use
const double fMaxShearRange(F_PI2 * (89.0/90.0));
- double fNewShearAngle(((-nAllShear) * F_PI) / 18000.0);
+ const double fNewShearValue(
+ tan(
+ basegfx::clamp(
+ sdr::legacy::convertShearAngleXLegacyToNew(nAllShear),
+ -fMaxShearRange,
+ fMaxShearRange)));
- fNewShearAngle = basegfx::snapToRange(fNewShearAngle, -F_PI, F_PI);
- fNewShearAngle = basegfx::clamp(fNewShearAngle, -fMaxShearRange, fMaxShearRange);
+ // check if we have a ShearY
+ bDoShearY = ((const SfxBoolItem&)rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_VERTICAL)).GetValue();
- bShearVert = ((const SfxBoolItem&)rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_VERTICAL)).GetValue();
- double fOldShearAngle(GetMarkedObjShearX());
+ // get current shear value. It is the tan of the shear angle in radians
+ // tan(]-F_PI .. F_PI[)
+ double fOldShearValue(GetMarkedObjShearX());
- if(bShearVert)
+ if(bDoShearY)
{
// Currently only ShearX is directly used at the SdrObject since the homogen
// matrix only has six degrees of freedom and it has to be decided which one
@@ -1985,16 +1984,18 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr)
// the same as a 90 degree rotation, a ShearY(-x) and a -90 degree back-rotation.
// Exactly this will be used below. It also shows that the ShearY is -ShearX, thus
// the compare value can be detected
- fOldShearAngle = -fOldShearAngle;
+ fOldShearValue = -fOldShearValue;
}
- if(!basegfx::fTools::equal(fNewShearAngle, fOldShearAngle))
+ if(!basegfx::fTools::equal(fNewShearValue, fOldShearValue))
{
- fShearAngle = fNewShearAngle - fOldShearAngle;
- bShear = true;
+ // create shear diff and convert to shear angle, this is what ShearMarkedObj
+ // expects
+ fShearChange = atan(fNewShearValue - fOldShearValue);
+ bDoShearDelta = true;
}
- if(bShear)
+ if(bDoShearDelta)
{
aShearOffset.setX(((const SfxInt32Item&)rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_X)).GetValue());
aShearOffset.setY(((const SfxInt32Item&)rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_Y)).GetValue());
@@ -2062,20 +2063,20 @@ void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr)
}
// change shear
- if(bShear && mbShearAllowed)
+ if(bDoShearDelta && mbShearAllowed)
{
basegfx::B2DPoint aRef(aShearOffset + aPageOrigin);
- if(bShearVert)
+ if(bDoShearY)
{
- // see explanation at setting bShearVert
+ // see explanation at setting bDoShearY above
RotateMarkedObj(aRef, F_PI2);
- ShearMarkedObj(aRef, -fShearAngle, true);
+ ShearMarkedObj(aRef, -fShearChange, true);
RotateMarkedObj(aRef, -F_PI2);
}
else
{
- ShearMarkedObj(aRef, fShearAngle, false);
+ ShearMarkedObj(aRef, fShearChange, false);
}
}
diff --git a/svx/source/svdraw/svdlegacy.cxx b/svx/source/svdraw/svdlegacy.cxx
index e5f0a2872fbe..e7c3b43778ce 100644
--- a/svx/source/svdraw/svdlegacy.cxx
+++ b/svx/source/svdraw/svdlegacy.cxx
@@ -285,14 +285,21 @@ namespace sdr
return Point(basegfx::fround(rAnchor.getX()), basegfx::fround(rAnchor.getY()));
}
+ long convertRotateAngleNewToLegacy(double fNew)
+ {
+ return basegfx::fround(basegfx::snapToZeroRange(-fNew / F_PI18000, 36000.0));
+ }
+
+ double convertRotateAngleLegacyToNew(long nOld)
+ {
+ return basegfx::snapToZeroRange(static_cast< double >(nOld) * -F_PI18000, F_2PI);
+ }
+
long GetRotateAngle(const SdrObject& rObject)
{
if(rObject.isRotated())
{
- const double fRotate(rObject.getSdrObjectRotate());
- const double fSnapped(basegfx::snapToZeroRange(-fRotate / F_PI18000, 36000.0));
-
- return basegfx::fround(fSnapped);
+ return convertRotateAngleNewToLegacy(rObject.getSdrObjectRotate());
}
else
{
@@ -300,24 +307,21 @@ namespace sdr
}
}
+ long convertShearAngleXNewToLegacy(double fNew)
+ {
+ return basegfx::fround(basegfx::snapToRange(-fNew / F_PI18000, -18000.0, 18000.0));
+ }
+
+ double convertShearAngleXLegacyToNew(long nOld)
+ {
+ return basegfx::snapToRange(static_cast< double >(nOld) * -F_PI18000, -F_PI, F_PI);
+ }
+
long GetShearAngleX(const SdrObject& rObject)
{
if(rObject.isSheared())
{
- const double fShearX(rObject.getSdrObjectShearX());
- long nRetval(basegfx::fround(-atan(fShearX) / F_PI18000));
-
- while(nRetval < -18000)
- {
- nRetval += 36000;
- }
-
- while(nRetval >= 18000)
- {
- nRetval -= 36000;
- }
-
- return nRetval;
+ return convertShearAngleXNewToLegacy(rObject.getSdrObjectShearX());
}
else
{
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index b26efb8f0fba..c4b01d604e57 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -530,9 +530,40 @@ void SdrMarkView::BrkMarkGluePoints()
bool SdrMarkView::HasMarkableObj() const
{
- const sal_uInt32 nCount(GetMarkableObjCount());
+ SdrPageView* pPV = GetSdrPageView();
+
+ if(pPV)
+ {
+ SdrObjList* pOL = pPV->GetCurrentObjectList();
+
+ if(pOL)
+ {
+ SdrObjectVector aObjects(pOL->getSdrObjectVector());
+
+ for(sal_uInt32 a(0); a < aObjects.size(); a++)
+ {
+ SdrObject* pCandidate = aObjects[a];
- return (0 != nCount);
+ if(pCandidate)
+ {
+ if(IsObjMarkable(*pCandidate))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ OSL_ENSURE(false, "SdrObjectVector with empty entries (!)");
+ }
+ }
+ }
+ else
+ {
+ OSL_ENSURE(false, "Unexpected missing SdrObjList (!)");
+ }
+ }
+
+ return false;
}
sal_uInt32 SdrMarkView::GetMarkableObjCount() const
@@ -543,17 +574,32 @@ sal_uInt32 SdrMarkView::GetMarkableObjCount() const
if(pPV)
{
SdrObjList* pOL = pPV->GetCurrentObjectList();
- sal_uInt32 nObjAnz = pOL->GetObjCount();
- for(sal_uInt32 nObjNum(0); nObjNum < nObjAnz && !nCount; nObjNum++)
+ if(pOL)
{
- SdrObject* pObj=pOL->GetObj(nObjNum);
+ SdrObjectVector aObjects(pOL->getSdrObjectVector());
- if(IsObjMarkable(*pObj))
+ for(sal_uInt32 a(0); a < aObjects.size(); a++)
{
- nCount++;
+ SdrObject* pCandidate = aObjects[a];
+
+ if(pCandidate)
+ {
+ if(IsObjMarkable(*pCandidate))
+ {
+ nCount++;
+ }
+ }
+ else
+ {
+ OSL_ENSURE(false, "SdrObjectVector with empty entries (!)");
+ }
}
}
+ else
+ {
+ OSL_ENSURE(false, "Unexpected missing SdrObjList (!)");
+ }
}
return nCount;
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index f7619f1a37b4..62c9988fc832 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -792,7 +792,7 @@ void SdrGrafObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
rInfo.mbShearAllowed = true;
rInfo.mbEdgeRadiusAllowed=false;
- rInfo.mbCanConvToPath = false;
+ rInfo.mbCanConvToPath = !IsEPS();
rInfo.mbCanConvToPathLineToArea = false;
rInfo.mbCanConvToPolyLineToArea = false;
rInfo.mbCanConvToPoly = !IsEPS();
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index 0ec10ead82c3..845c43572442 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -1637,7 +1637,7 @@ void SdrPathObj::impSetPathPolyPolygonWithTransformationAdaption(const basegfx::
// the SdrPathObj has two basic states, line and other. Line is for two points
// and no bezier, it uses a specialized geometry (unified line from 0.0, to 1.0)
// and a specialized transformation which shows the rotation of the line what is
- // wanted.
+ // wanted. Shear is not preserved due to lines having no shear.
// When a third point is added that mode is left and the regular one entered, in
// this conversion when using the code below keeping the rotation of the former
// line object. This is not wrong and works as intended, but is irritating for the
@@ -1750,6 +1750,9 @@ void SdrPathObj::impSetPathPolyPolygonWithTransformationAdaption(const basegfx::
else
{
// use translate and scale straightforward from new geometry
+ // when either no mirror, scale and shear or object was a line
+ // before and reset is wanted (see explanation for
+ // bResetCoordinateSystemAfterWasLine above)
maSdrObjectTransformation.setB2DHomMatrix(
basegfx::tools::createScaleTranslateB2DHomMatrix(
aRangeNewGeometry.getRange(),
@@ -2726,11 +2729,26 @@ void SdrPathObj::setSdrObjectTransformation(const basegfx::B2DHomMatrix& rTransf
if(isLine())
{
// apply new transformation to (0,0) and (1,0) to create the polygon data
+ // and set as new geometry
+ const basegfx::B2DPoint aPointA(rTransformation * basegfx::B2DPoint(0.0, 0.0));
+ const basegfx::B2DPoint aPointB(rTransformation * basegfx::B2DPoint(1.0, 0.0));
basegfx::B2DPolygon aLine;
- aLine.append(rTransformation * basegfx::B2DPoint(0.0, 0.0));
- aLine.append(rTransformation * basegfx::B2DPoint(1.0, 0.0));
+ aLine.append(aPointA);
+ aLine.append(aPointB);
maPathPolyPolygon = basegfx::B2DPolyPolygon(aLine);
+
+ // the geometry is a non-curved line, create unit transformation so that (0,0) is
+ // 1st point and (1,0) is 2nd point and call the parent method with the new
+ // transformation. This is needed to trigger all the refresh stuff
+ const basegfx::B2DVector aDelta(aPointB - aPointA);
+
+ // call parent with new, adapted transformation
+ SdrTextObj::setSdrObjectTransformation(
+ basegfx::tools::createScaleRotateTranslateB2DHomMatrix(
+ basegfx::B2DTuple(aDelta.getLength(), 1.0),
+ atan2(aDelta.getY(), aDelta.getX()),
+ aPointA));
}
else
{
@@ -2740,14 +2758,18 @@ void SdrPathObj::setSdrObjectTransformation(const basegfx::B2DHomMatrix& rTransf
// take out old and apply new transformation
basegfx::B2DHomMatrix aCombined(maSdrObjectTransformation.getB2DHomMatrix());
+ // apply minimal scaling before inverting to secure inversion and
+ // to handle cases where polygons have no width and/or height, but are not a line
+ aCombined = basegfx::tools::guaranteeMinimalScaling(aCombined);
+
aCombined.invert();
aCombined = rTransformation * aCombined;
maPathPolyPolygon.transform(aCombined);
}
- }
- // call parent
- SdrTextObj::setSdrObjectTransformation(rTransformation);
+ // call parent
+ SdrTextObj::setSdrObjectTransformation(rTransformation);
+ }
}
}