summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorekuiitr <jhaekansh80@gmail.com>2018-05-21 01:07:19 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-11-09 08:42:33 +0100
commitc0da7d8509516ba6f1fc8781c042fd6f1bd92297 (patch)
treea18eb07514581b9f9daa75a70fc258a1f24df4c1
parent6ed498a71482109fea731bb84f288f978bea12dc (diff)
tdf#117761 Corrected Snake Algorithm
This is a combination of 5 commits. It brings libreoffice-6-1 up to date with master when it comes to SmartArt fixes which were not backported so far. 1st commit: Now it displays correct position of child layout nodes along a linear path in two dimensions, with the correct number of rows and columns and aspect ratio, this algorithm is for smartarts like Basic Block List - grouped blocks of information. It also specifies the behaviour of the direction that additional nodes are added to new rows or columns in the snake algorithm. Added Reverse Algorithm and SameDirection Algorithm in this patch, rather than commiting new Patch. (cherry picked from commit 8d43de9a88dc7c7fec0e7c794cef14953fb34b6e) Commit #2: (cherry picked from commit f1368d6a45456b5682d588371cfa2efa5571d798) Commit #3: Support autoTxRot parameter in Text algorithm Specifies how text is oriented relative to the shape, according to values: none, upright(default) and gravity. (cherry picked from commit cf7b97d1328ec2f2c8254abb9ce67d63d9c54c80) Commit #4: coverity#1436015 UNUSED_VALUE I got to know that, earlier the code I've submitted about line algorithm creates error. I've fixed that in this patch. Moreover, child width and height doesn't depend of nIncX and nIncY, so I've removed that code, it relates only to the position of the child. (cherry picked from commit 3f8fdfced059bdec7f28164eb3c0e99974c6780a) Commit #5: Support txAnchorVert parameter Specifies the y-axis anchoring of the text area in a shape according to: t(top), mid(middle, default), b(bottom). (cherry picked from commit 1f66bd9cbd961d1923c260b2d74249e363a0c217) Change-Id: I85ba53690fd716f0387cfdb21f8874e63bc44194 Reviewed-on: https://gerrit.libreoffice.org/63113 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-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();