summaryrefslogtreecommitdiff
path: root/capi
diff options
context:
space:
mode:
authorRazrFalcon <razrfalcon@gmail.com>2018-05-15 14:42:25 +0300
committerRazrFalcon <razrfalcon@gmail.com>2018-05-15 14:42:25 +0300
commit5ff892a1c31f607b7207503081a640ab8ed2bbac (patch)
tree2409f5c32ac543a597be7c23e11244ab840c4d37 /capi
parent7c87dda49831d0b93a6d4c337f1b175df0761d77 (diff)
Added `boundsOnElement` to ResvgQt API.
Diffstat (limited to 'capi')
-rw-r--r--capi/qt-wrapper/ResvgQt.cpp18
-rw-r--r--capi/qt-wrapper/ResvgQt.h7
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;