diff options
Diffstat (limited to 'capi')
-rw-r--r-- | capi/qt-wrapper/ResvgQt.cpp | 18 | ||||
-rw-r--r-- | capi/qt-wrapper/ResvgQt.h | 7 |
2 files changed, 23 insertions, 2 deletions
diff --git a/capi/qt-wrapper/ResvgQt.cpp b/capi/qt-wrapper/ResvgQt.cpp index e9a1a62..b66dac2 100644 --- a/capi/qt-wrapper/ResvgQt.cpp +++ b/capi/qt-wrapper/ResvgQt.cpp @@ -104,7 +104,7 @@ ResvgRenderer::~ResvgRenderer() {} bool ResvgRenderer::load(const QString &filePath) { // Check for Qt resource path. - if (filePath.startsWith(":/")) { + if (filePath.startsWith(QLatin1String(":/"))) { QFile file(filePath); if (file.open(QFile::ReadOnly)) { return load(file.readAll()); @@ -201,6 +201,20 @@ QRectF ResvgRenderer::viewBoxF() const return QRectF(); } +QRectF ResvgRenderer::boundsOnElement(const QString &id) const +{ + if (d->tree) { + const auto utf8Str = id.toUtf8(); + const auto rawId = utf8Str.constData(); + resvg_rect bbox; + if (resvg_qt_get_node_bbox(d->tree, &d->opt, rawId, &bbox)) { + return QRectF(bbox.x, bbox.y, bbox.height, bbox.width); + } + } + + return QRectF(); +} + bool ResvgRenderer::elementExists(const QString &id) const { if (d->tree) { @@ -262,7 +276,7 @@ void ResvgRenderer::render(QPainter *p, const QString &elementId, const QRectF & resvg_rect bbox; if (!resvg_qt_get_node_bbox(d->tree, &d->opt, rawId, &bbox)) { - qWarning() << QString("Element '%1' has no bounding box.").arg(elementId); + qWarning() << QString(QStringLiteral("Element '%1' has no bounding box.")).arg(elementId); return; } diff --git a/capi/qt-wrapper/ResvgQt.h b/capi/qt-wrapper/ResvgQt.h index e31b2ba..b73aad0 100644 --- a/capi/qt-wrapper/ResvgQt.h +++ b/capi/qt-wrapper/ResvgQt.h @@ -99,6 +99,13 @@ public: QRectF viewBoxF() const; /** + * @brief Returns bounding rectangle of the item with the given \b id. + * The transformation matrix of parent elements is not affecting + * the bounds of the element. + */ + QRectF boundsOnElement(const QString &id) const; + + /** * @brief Returns \b true if element with such an ID exists. */ bool elementExists(const QString &id) const; |