diff options
Diffstat (limited to 'capi/qt-wrapper/ResvgQt.h')
-rw-r--r-- | capi/qt-wrapper/ResvgQt.h | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/capi/qt-wrapper/ResvgQt.h b/capi/qt-wrapper/ResvgQt.h new file mode 100644 index 0000000..2572c88 --- /dev/null +++ b/capi/qt-wrapper/ResvgQt.h @@ -0,0 +1,154 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/** + * @file ResvgQt.h + * + * Qt wrapper for resvg C-API + */ + +#ifndef RESVGQT_H +#define RESVGQT_H + +#include <QString> +#include <QScopedPointer> +#include <QRectF> +#include <QTransform> + +class QPainter; + +class ResvgRendererPrivate; + +/** + * @brief QSvgRenderer-like wrapper for resvg C-API + */ +class ResvgRenderer { +public: + /** + * @brief Constructs a new renderer. + */ + ResvgRenderer(); + + /** + * @brief Constructs a new renderer and loads the contents of the SVG(Z) file. + * + * @param filePath File path. + */ + ResvgRenderer(const QString &filePath); + + /** + * @brief Constructs a new renderer and loads the SVG data. + * + * @param data SVG data. Must be already unzipped. + */ + ResvgRenderer(const QByteArray &data); + + /** + * @brief Destructs the renderer. + */ + ~ResvgRenderer(); + + /** + * @brief Loads the contents of the SVG(Z) file. + */ + bool load(const QString &filePath); + + /** + * @brief Loads the SVG data. + * + * @param data SVG data. Must be already unzipped. + */ + bool load(const QByteArray &data); + + /** + * @brief Returns \b true if the file or data were loaded successful. + */ + bool isValid() const; + + /** + * @brief Returns an underling error when #isValid is \b false. + */ + QString errorString() const; + + /** + * @brief Checks that underling tree has any nodes. + * + * #ResvgRenderer and #ResvgRenderer constructors + * will set an error only if a file does not exist or it has a non-UTF-8 encoding. + * All other errors will result in an empty tree with a 100x100px size. + * + * @return Returns \b true if tree has any nodes. + */ + bool isEmpty() const; + + /** + * @brief Returns an SVG size. + */ + QSize defaultSize() const; + + /** + * @brief Returns an SVG size. + */ + QSizeF defaultSizeF() const; + + /** + * @brief Returns an SVG viewbox. + */ + QRect viewBox() const; + + /** + * @brief Returns an SVG viewbox. + */ + QRectF viewBoxF() const; + + /** + * @brief Returns \b true if element with such an ID exists. + */ + bool elementExists(const QString &id) const; + + /** + * @brief Returns element's transform. + */ + QTransform transformForElement(const QString &id) const; + + /** + * @brief Renders the SVG data to canvas. + */ + void render(QPainter *p); + + /** + * @brief Renders the SVG data to canvas with the specified \b bounds. + * + * If the bounding rectangle is not specified + * the SVG file is mapped to the whole paint device. + */ + void render(QPainter *p, const QRectF &bounds); + + /** + * @brief Renders the given element with \b elementId on the specified \b bounds. + * + * If the bounding rectangle is not specified + * the SVG element is mapped to the whole paint device. + */ + void render(QPainter *p, const QString &elementId, + const QRectF &bounds = QRectF()); + + /** + * @brief Initializes the library log. + * + * Use it if you want to see any warnings. + * + * Must be called only once. + * + * All warnings will be printed to the \b stderr. + */ + static void initLog(); + +private: + QScopedPointer<ResvgRendererPrivate> d; +}; + +#endif // RESVGQT_H |