diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 3143ad2..8b63ae1 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -435,13 +435,20 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, // tag that's implicitly defined when is used. // Apply the view box translation if specified. - p->translate(target.x() - source.x(), - target.y() - source.y()); +// p->translate(target.x() - source.x(), +// target.y() - source.y()); // Scale the view box into the view port (target) by preserve the aspect ratio. QSizeF viewBoxSize = source.size(); viewBoxSize.scale(target.width(), target.height(), Qt::KeepAspectRatio); + QTransform transform; + transform.scale(viewBoxSize.width() / source.width(), + viewBoxSize.height() / source.height()); + QRectF c2 = transform.mapRect(source); + p->translate(target.x() - c2.x(), + target.y() - c2.y()); + // Center the view box in the view port p->translate((target.width() - viewBoxSize.width()) / 2, (target.height() - viewBoxSize.height()) / 2);