Need some help about transformation

Yue Liu yue.liu at mail.com
Tue Jul 19 08:38:05 BST 2011


Hello,

In recent days I'm trying to fix the shape group shadow issues but I
think I have some misunderstandings and made things even worse. Hope I
can get some help.

My design:

get the shadow rectangle by shadowRect = shape->boundingRect();
this will include the insets of shadow offsets and shadow blur caused
shadow expansion.

I think after that I'll get a rectangle with shape's origin inside it.

create a buffer image with shadow rectangle's size in view zoomlevel.
QRectF zoomedClipRegion = converter.documentToView(shadowRect);
QImage sourceGraphic(zoomedClipRegion.size().toSize(),
QImage::Format_ARGB32_Premultiplied);

apply a transform to th qpainter which paints the shadow onto the image.
this part confuse me very much, currently i did:

//offset transformation on the buffer image in pixel, shape's own coordinate
QTransform tm;
tm.translate(d->offset.x(), d->offset.y());
QTransform tr = shape->absoluteTransformation(&converter);
QTransform offsetMatrix = tr * tm * tr.inverted();

//set the absolute transformation to shape so it can draw in it's own
coordinate system in pixel
KoShape::applyConversion(painter, converter);
// apply the offset transformation so it draws on the correct position
on buffer image
painter.setTransform(offsetMatrix * painter.transform());

//process the image and paste the image to the canvas
QPointF clippingOffset = zoomedClipRegion.topLeft();
painter.drawImage(clippingOffset, sourceGraphic);

But the result goes very starnge, the shadow rectangle changes a lot
when shape is moving, and the shadow position is incorrect. I must
have get something wrong. Anyone knows what's wrong with the
implementation?

in the attachment shape group part are commented since I haven't
figure out the single shape part.

Best Regards,
Yue Liu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KoShapeShadow.cpp
Type: text/x-c++src
Size: 11373 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20110719/2646fc95/attachment.cpp>


More information about the calligra-devel mailing list