r14639 by fschmid - DRW Importer: rotated Groups are now correct.
scribus-commit
scribus-commit at lists.scribus.net
Thu Feb 4 13:20:25 CET 2010
Revision: 14639
Author: fschmid
Date: 2010-02-04T12:11:43.181903Z
Commit message: DRW Importer: rotated Groups are now correct.
Changeset:
M /trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp
M /trunk/Scribus/scribus/plugins/import/drw/importdrw.h
Diffs:
Index: scribus/plugins/import/drw/importdrw.cpp
===================================================================
--- scribus/plugins/import/drw/importdrw.cpp (revision 14638)
+++ scribus/plugins/import/drw/importdrw.cpp (revision 14639)
@@ -1043,7 +1043,7 @@
}
if (!gesPa.isEmpty())
{
- QRectF bb = gesPa.boundingRect();
+ QRectF bb = gesPa.controlPointRect();
if (popped.rotationAngle != 0)
{
QTransform mt;
@@ -1054,12 +1054,12 @@
ma.rotate(-popped.rotationAngle / 10.0);
gesPa = ma.map(gesPa);
}
- bb = gesPa.boundingRect();
+ bb = gesPa.controlPointRect();
QTransform mt;
mt.translate(-bb.x(), -bb.y());
gesPa = mt.map(gesPa);
- if ((popped.scaleX != 0) || (popped.scaleY != 0))
- {
+ // if ((popped.scaleX != 0) || (popped.scaleY != 0))
+ // {
if ((bb.width() != 0) && (bb.height() != 0) && (popped.width != 0) && (popped.height != 0))
{
if (bb.width() != popped.width)
@@ -1070,7 +1070,7 @@
ms.scale(scx, scy);
gesPa = ms.map(gesPa);
}
- }
+ // }
FPointArray res;
res.fromQPainterPath(gesPa);
PageItem *ite = tmpSel->takeItem(0);
@@ -1124,22 +1124,30 @@
uint selectedItemCount = tmpSel->count();
if (selectedItemCount > 0)
{
- /* if (popped.rotationAngle != 0)
+ if (popped.rotationAngle != 0)
{
PageItem* currItem;
QTransform ma;
- ma.translate(posPivot.x(), posPivot.y());
- ma.rotate(-popped.rotationAngle);
+ ma.translate(popped.posPivot.x(), popped.posPivot.y());
+ ma.rotate(-popped.rotationAngle / 10.0);
FPoint n;
for (int a = 0; a < tmpSel->count(); ++a)
{
currItem = tmpSel->itemAt(a);
- n = FPoint(currItem->xPos() - posPivot.x(), currItem->yPos() - posPivot.y());
+ n = FPoint(currItem->xPos(), currItem->yPos());
currItem->setXYPos(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
- currItem->rotateBy(-popped.rotationAngle);
+ currItem->rotateBy(-popped.rotationAngle / 10.0);
}
}
- tmpSel->setGroupRect(); */
+ tmpSel->setGroupRect();
+ QRectF gr = tmpSel->getGroupRect();
+ double dx = popped.groupItem->xPos() - gr.x();
+ double dy = popped.groupItem->yPos() - gr.y();
+ for (int a = 0; a < tmpSel->count(); ++a)
+ {
+ tmpSel->itemAt(a)->moveBy(dx, dy);
+ }
+ tmpSel->setGroupRect();
if ((popped.scaleX != 0) || (popped.scaleY != 0))
{
if ((tmpSel->width() != 0) && (tmpSel->height() != 0) && (popped.width != 0) && (popped.height != 0))
@@ -1230,11 +1238,6 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
posStart = getCoordinate(ds);
posEnd = getCoordinate(ds);
if (posStart == posEnd)
@@ -1243,16 +1246,14 @@
boundingBoxYO = getValue(ds);
boundingBoxWO = getValue(ds);
boundingBoxHO = getValue(ds);
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
bBoxO = QRectF(QPointF(boundingBoxXO, boundingBoxYO), QPointF(boundingBoxWO, boundingBoxHO)).normalized();
sLin = QLineF(bBoxO.center(), posStart);
eLin = QLineF(bBoxO.center(), posEnd);
rotS = sLin.angle();
rotE = eLin.angle();
+ if (rotS > rotE)
+ rotS = rotS - 360;
rotE = rotE - rotS;
path = QPainterPath();
path.arcMoveTo(bBoxO, rotS);
@@ -1260,7 +1261,7 @@
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
currentItem->PoLine.fromQPainterPath(path);
- bBoxO = path.boundingRect();
+ bBoxO = path.controlPointRect();
currentItem->PoLine.translate(-bBoxO.x(), -bBoxO.y());
handleLineStyle(currentItem, flags, lineColor);
finishItem(currentItem);
@@ -1271,22 +1272,10 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 1;
z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1304,11 +1293,7 @@
gList.scaleX = scaleX;
gList.scaleY = scaleY;
gList.rotationAngle = rotationAngle;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
gList.posPivot = posPivot;
gList.itemGroupName = "";
gList.GElements.clear();
@@ -1332,11 +1317,6 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
boundingBoxXO = getValue(ds);
boundingBoxYO = getValue(ds);
boundingBoxWO = getValue(ds);
@@ -1344,14 +1324,7 @@
bBoxO = QRectF(QPointF(boundingBoxXO, boundingBoxYO), QPointF(boundingBoxWO, boundingBoxHO));
cornerRadius = getValue(ds);
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
finishItem(currentItem);
@@ -1379,11 +1352,7 @@
if (posStart == posEnd)
break;
ds >> patternIndex;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
lineWidth = patternIndex * scaleFactor;
path = QPainterPath();
path.moveTo(posStart);
@@ -1402,22 +1371,10 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 3;
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1438,11 +1395,6 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
boundingBoxXO = getValue(ds);
boundingBoxYO = getValue(ds);
boundingBoxWO = getValue(ds);
@@ -1450,14 +1402,7 @@
cornerRadius = getValue(ds);
bBoxO = QRectF(QPointF(boundingBoxXO, boundingBoxYO), QPointF(boundingBoxWO, boundingBoxHO));
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
handleLineStyle(currentItem, flags, lineColor);
@@ -1475,11 +1420,6 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
boundingBoxXO = getValue(ds);
boundingBoxYO = getValue(ds);
boundingBoxWO = getValue(ds);
@@ -1487,14 +1427,7 @@
bBoxO = QRectF(QPointF(boundingBoxXO, boundingBoxYO), QPointF(boundingBoxWO, boundingBoxHO));
cornerRadius = getValue(ds);
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
handleLineStyle(currentItem, flags, lineColor);
@@ -1508,11 +1441,6 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
posStart = getCoordinate(ds);
posEnd = getCoordinate(ds);
if (posStart == posEnd)
@@ -1521,16 +1449,14 @@
boundingBoxYO = getValue(ds);
boundingBoxWO = getValue(ds);
boundingBoxHO = getValue(ds);
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
bBoxO = QRectF(QPointF(boundingBoxXO, boundingBoxYO), QPointF(boundingBoxWO, boundingBoxHO)).normalized();
sLin = QLineF(bBoxO.center(), posStart);
eLin = QLineF(bBoxO.center(), posEnd);
rotS = sLin.angle();
rotE = eLin.angle();
+ // if (rotS > rotE)
+ // rotS = rotS - 360;
rotE = rotE - rotS;
path = QPainterPath();
path.arcMoveTo(bBoxO, rotS);
@@ -1538,7 +1464,7 @@
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
currentItem->PoLine.fromQPainterPath(path);
- bBoxO = path.boundingRect();
+ bBoxO = path.controlPointRect();
currentItem->PoLine.translate(-bBoxO.x(), -bBoxO.y());
handleLineStyle(currentItem, flags, lineColor);
finishItem(currentItem);
@@ -1549,21 +1475,12 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
posStart = getCoordinate(ds);
posMid = getCoordinate(ds);
posEnd = getCoordinate(ds);
if (posStart == posEnd)
break;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
path = QPainterPath();
path.moveTo(posStart);
path.cubicTo(posMid, posMid, posEnd);
@@ -1571,7 +1488,7 @@
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
currentItem->PoLine.fromQPainterPath(path);
- bBoxO = path.boundingRect();
+ bBoxO = path.controlPointRect();
currentItem->PoLine.translate(-bBoxO.x(), -bBoxO.y());
finishItem(currentItem);
if (currentItem != NULL)
@@ -1586,22 +1503,10 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 4;
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1617,15 +1522,7 @@
ds >> nItems;
ds >> dummy;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
gElements.xoffset = bX + bBox.x() + groupX;
gElements.yoffset = bY + bBox.y() + groupY;
gElements.width = bBox.width();
@@ -1662,21 +1559,12 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
posStart = getCoordinate(ds);
posMid = getCoordinate(ds);
posEnd = getCoordinate(ds);
if (posStart == posEnd)
break;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
path = QPainterPath();
path.moveTo(posStart);
path.cubicTo(posMid, posMid, posEnd);
@@ -1684,7 +1572,7 @@
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
currentItem = m_Doc->Items->at(z);
currentItem->PoLine.fromQPainterPath(path);
- bBoxO = path.boundingRect();
+ bBoxO = path.controlPointRect();
currentItem->PoLine.translate(-bBoxO.x(), -bBoxO.y());
handleLineStyle(currentItem, flags, lineColor);
finishItem(currentItem);
@@ -1695,22 +1583,10 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 4;
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1733,11 +1609,7 @@
ds >> rTrans;
ds >> gTrans;
ds >> bTrans;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
if ((bitsPerPixel == 24) || (bitsPerPixel == 8))
{
z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Rectangle, posX, posY, bBox.width(), bBox.height(), lineWidth, CommonStrings::None, CommonStrings::None, true);
@@ -1759,14 +1631,7 @@
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 2;
z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1779,22 +1644,10 @@
fillColor = getColor(ds);
if (patternIndex != 0)
fillC = fillColor;
- if (groupStack.count() > 1)
- {
- if (groupStack.top().patternIndex != 0)
- fillC = groupStack.top().fillColor;
- }
ds >> dummy;
ds >> nPoints;
ds >> appFlags;
- ds >> dummy;
- ds >> dummy;
- ds >> dummy;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
nrOfPoints = nPoints;
createObjCode = 2;
z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, posX, posY, bBox.width(), bBox.height(), lineWidth, fillC, lineColor, true);
@@ -1805,11 +1658,7 @@
case 25:
cmdText += "Rich Text";
fontColor = lineColor;
- ds.device()->seek(0x38);
- backColor = getColor(ds);
- lineWidth = getValue(ds);
- ds >> dummy;
- posPivot = getCoordinate(ds);
+ getCommonData(ds);
createObjCode = 6;
z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, posX, posY, bBox.width(), bBox.height(), 0, CommonStrings::None, CommonStrings::None, true);
currentItem = m_Doc->Items->at(z);
@@ -1836,7 +1685,6 @@
cmdText += "Unknown";
break;
}
- printMSG = false;
if (printMSG)
{
if (currentItem != NULL)
@@ -2152,6 +2000,17 @@
return tmpName;
}
+
+void DrwPlug::getCommonData(QDataStream &ds)
+{
+ quint16 dummy;
+ ds.device()->seek(0x38);
+ backColor = getColor(ds);
+ lineWidth = getValue(ds);
+ ds >> dummy;
+ posPivot = getCoordinate(ds);
+}
+
QString DrwPlug::getColor(QDataStream &ds)
{
quint8 r, g, b, a;
@@ -2184,22 +2043,25 @@
FPoint tp2(getMinClipF(&ite->PoLine));
ite->PoLine.translate(-tp2.x(), -tp2.y());
}
- if ((scaleX != 0) || (scaleY != 0))
+ if (scale)
{
- QPainterPath pa = ite->PoLine.toQPainterPath(true);
- QRectF bb = pa.boundingRect();
- double scx = 1.0;
- double scy = 1.0;
- if ((bb.width() != 0.0) && (ite->width() != 0.0))
- scx = ite->width() / bb.width();
- else
- scx = 1.0;
- if ((bb.height() != 0.0) && (ite->height() != 0.0))
- scy = ite->height() / bb.height();
- else
- scy = 1.0;
- ite->PoLine.scale(scx, scy);
- ite->setLineWidth(ite->lineWidth() / qMin(scx, scy));
+ if ((scaleX != 0) || (scaleY != 0))
+ {
+ QPainterPath pa = ite->PoLine.toQPainterPath(true);
+ QRectF bb = pa.controlPointRect();
+ double scx = 1.0;
+ double scy = 1.0;
+ if ((bb.width() != 0.0) && (ite->width() != 0.0))
+ scx = ite->width() / bb.width();
+ else
+ scx = 1.0;
+ if ((bb.height() != 0.0) && (ite->height() != 0.0))
+ scy = ite->height() / bb.height();
+ else
+ scy = 1.0;
+ ite->PoLine.scale(scx, scy);
+ ite->setLineWidth(ite->lineWidth() / qMin(scx, scy));
+ }
}
ite->OldB2 = ite->width();
ite->OldH2 = ite->height();
Index: scribus/plugins/import/drw/importdrw.h
===================================================================
--- scribus/plugins/import/drw/importdrw.h (revision 14638)
+++ scribus/plugins/import/drw/importdrw.h (revision 14639)
@@ -70,6 +70,7 @@
void handleGradient(PageItem* currentItem, quint8 patternIndex, QString fillColor, QString backColor, QRectF bBox);
void handlePreviewBitmap(QDataStream &ds);
QString handleColor(ScColor &color, QString proposedName);
+ void getCommonData(QDataStream &ds);
QString getColor(QDataStream &ds);
void finishItem(PageItem* ite, bool scale = true);
double getValue(QDataStream &ds);
More information about the scribus-commit
mailing list