summaryrefslogtreecommitdiffstats
path: root/oox
diff options
context:
space:
mode:
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx148
1 files changed, 124 insertions, 24 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 3c8993bd687d..e0fd7d246c60 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -356,10 +356,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
double fSpace = 0.3;
awt::Size aChildSize = rShape->getSize();
- if (nIncX)
- aChildSize.Width /= (nCount + (nCount-1)*fSpace);
- if (nIncY)
- aChildSize.Height /= (nCount + (nCount-1)*fSpace);
+
+ aChildSize.Width /= (nCount + (nCount-1)*fSpace);
+ aChildSize.Height /= (nCount + (nCount-1)*fSpace);
awt::Point aCurrPos(0, 0);
if (nIncX == -1)
@@ -402,18 +401,19 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
// TODO: get values from constraints
sal_Int32 nCount = rShape->getChildren().size();
double fSpace = 0.3;
- double fAspectRatio = 0.6;
+ double fAspectRatio = 0.54; // diagram should not spill outside, earlier it was 0.6
sal_Int32 nCol = 1;
sal_Int32 nRow = 1;
- for ( ; nCol<nCount; nCol++)
+ for ( ; nRow<nCount; nRow++)
{
- nRow = (nCount+nCol-1) / nCol;
+ nCol = (nCount+nRow-1) / nRow;
const double fShapeHeight = rShape->getSize().Height;
const double fShapeWidth = rShape->getSize().Width;
- if ((fShapeHeight / nRow) / (fShapeWidth / nCol) >= fAspectRatio)
+ if ((fShapeHeight / nCol) / (fShapeWidth / nRow) >= fAspectRatio)
break;
}
+
SAL_INFO("oox.drawingml", "Snake layout grid: " << nCol << "x" << nRow);
sal_Int32 nWidth = rShape->getSize().Width / (nCol + (nCol-1)*fSpace);
@@ -426,20 +426,89 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
sal_Int32 nStartX = aCurrPos.X;
- sal_Int32 nColIdx = 0;
+ sal_Int32 nColIdx = 0,index = 0;
- for (auto & aCurrShape : rShape->getChildren())
+ sal_Int32 num = rShape->getChildren().size();
+
+ const sal_Int32 aContDir = maMap.count(XML_contDir) ? maMap.find(XML_contDir)->second : XML_sameDir;
+
+ switch(aContDir)
{
- aCurrShape->setPosition(aCurrPos);
- aCurrShape->setSize(aChildSize);
- aCurrShape->setChildSize(aChildSize);
- aCurrPos.X += nIncX * (aChildSize.Width + fSpace*aChildSize.Width);
- if (++nColIdx == nCol)
+ case XML_sameDir:
+ for (auto & aCurrShape : rShape->getChildren())
+ {
+ aCurrShape->setPosition(aCurrPos);
+ aCurrShape->setSize(aChildSize);
+ aCurrShape->setChildSize(aChildSize);
+
+ index++; // counts index of child, helpful for positioning.
+
+ if(index%nCol==0 || ((index/nCol)+1)!=nRow)
+ aCurrPos.X += nIncX * (aChildSize.Width + fSpace*aChildSize.Width);
+
+ if(++nColIdx == nCol) // condition for next row
+ {
+ // if last row, then position children according to number of shapes.
+ if((index+1)%nCol!=0 && (index+1)>=3 && ((index+1)/nCol+1)==nRow && num!=nRow*nCol)
+ // position first child of last row
+ aCurrPos.X = nStartX + (nIncX * (aChildSize.Width + fSpace*aChildSize.Width))/2;
+ else
+ // if not last row, positions first child of that row
+ aCurrPos.X = nStartX;
+ aCurrPos.Y += nIncY * (aChildSize.Height + fSpace*aChildSize.Height);
+ nColIdx = 0;
+ }
+
+ // positions children in the last row.
+ if(index%nCol!=0 && index>=3 && ((index/nCol)+1)==nRow)
+ aCurrPos.X += (nIncX * (aChildSize.Width + fSpace*aChildSize.Width));
+ }
+ break;
+ case XML_revDir:
+ for (auto & aCurrShape : rShape->getChildren())
{
- aCurrPos.X = nStartX;
- aCurrPos.Y += nIncY * (aChildSize.Height + fSpace*aChildSize.Height);
- nColIdx = 0;
+ aCurrShape->setPosition(aCurrPos);
+ aCurrShape->setSize(aChildSize);
+ aCurrShape->setChildSize(aChildSize);
+
+ index++; // counts index of child, helpful for positioning.
+
+ /*
+ index%col -> tests node is at last column
+ ((index/nCol)+1)!=nRow) -> tests node is at last row or not
+ ((index/nCol)+1)%2!=0 -> tests node is at row which is multiple of 2, important for revDir
+ num!=nRow*nCol -> tests how last row nodes should be spread.
+ */
+
+ if((index%nCol==0 || ((index/nCol)+1)!=nRow) && ((index/nCol)+1)%2!=0)
+ aCurrPos.X += (aChildSize.Width + fSpace*aChildSize.Width);
+ else if( index%nCol!=0 && ((index/nCol)+1)!=nRow) // child other than placed at last column
+ aCurrPos.X -= (aChildSize.Width + fSpace*aChildSize.Width);
+
+ if(++nColIdx == nCol) // condition for next row
+ {
+ // if last row, then position children according to number of shapes.
+ if((index+1)%nCol!=0 && (index+1)>=4 && ((index+1)/nCol+1)==nRow && num!=nRow*nCol && ((index/nCol)+1)%2==0)
+ // position first child of last row
+ aCurrPos.X -= aChildSize.Width*3/2;
+ else if((index+1)%nCol!=0 && (index+1)>=4 && ((index+1)/nCol+1)==nRow && num!=nRow*nCol && ((index/nCol)+1)%2!=0)
+ aCurrPos.X = nStartX + (nIncX * (aChildSize.Width + fSpace*aChildSize.Width))/2;
+ else if(((index/nCol)+1)%2!=0)
+ aCurrPos.X = nStartX;
+
+ aCurrPos.Y += nIncY * (aChildSize.Height + fSpace*aChildSize.Height);
+ nColIdx = 0;
+ }
+
+ // positions children in the last row.
+ if(index%nCol!=0 && index>=3 && ((index/nCol)+1)==nRow && ((index/nCol)+1)%2==0)
+ //if row%2=0 then start from left else
+ aCurrPos.X -= (nIncX * (aChildSize.Width + fSpace*aChildSize.Width));
+ else if(index%nCol!=0 && index>=3 && ((index/nCol)+1)==nRow && ((index/nCol)+1)%2!=0)
+ // start from right
+ aCurrPos.X += (nIncX * (aChildSize.Width + fSpace*aChildSize.Width));
}
+ break;
}
break;
}
@@ -456,7 +525,6 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
{
// adjust text alignment
// TODO: adjust text size to fit shape
-
TextBodyPtr pTextBody = rShape->getTextBody();
if (!pTextBody ||
pTextBody->getParagraphs().empty() ||
@@ -465,12 +533,44 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
break;
}
- if (rShape->getRotation())
- pTextBody->getTextProperties().moRotation = -rShape->getRotation();
+ const sal_Int32 nautoTxRot = maMap.count(XML_autoTxRot) ? maMap.find(XML_autoTxRot)->second : XML_upr;
+
+ switch(nautoTxRot)
+ {
+ case XML_upr:
+ {
+ if (rShape->getRotation())
+ pTextBody->getTextProperties().moRotation = -F_PI180*90*rShape->getRotation();
+ }
+ break;
+ case XML_grav:
+ {
+ if (rShape->getRotation()==90*F_PI180 || rShape->getRotation()==180*F_PI180)
+ pTextBody->getTextProperties().moRotation = 180*F_PI180;
+ }
+ break;
+ case XML_none:
+ break;
+ }
+
+ const sal_Int32 atxAnchorVert = maMap.count(XML_txAnchorVert) ? maMap.find(XML_txAnchorVert)->second : XML_mid;
+
+ switch(atxAnchorVert)
+ {
+ case XML_t:
+ pTextBody->getTextProperties().meVA = css::drawing::TextVerticalAdjust_TOP;
+ break;
+ case XML_b:
+ pTextBody->getTextProperties().meVA = css::drawing::TextVerticalAdjust_BOTTOM;
+ break;
+ case XML_mid:
+ // text centered vertically by default
+ default:
+ pTextBody->getTextProperties().meVA = css::drawing::TextVerticalAdjust_CENTER;
+ break;
+ }
- // text centered vertically by default
- pTextBody->getTextProperties().meVA = css::drawing::TextVerticalAdjust_CENTER;
- pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextVerticalAdjust, css::drawing::TextVerticalAdjust_CENTER);
+ pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextVerticalAdjust, pTextBody->getTextProperties().meVA);
// normalize list level
sal_Int32 nBaseLevel = pTextBody->getParagraphs().front()->getProperties().getLevel();