19#include <QRegularExpression>
29 ratioParser(rhs.ratioParser ? new
SvgUtil::PreserveAspectRatioParser(*rhs.ratioParser) : 0),
30 viewBoxTransform(rhs.viewBoxTransform)
35 QScopedPointer<SvgUtil::PreserveAspectRatioParser>
ratioParser;
64 const QRectF myrect(QPointF(),
size());
66 painter.setRenderHint(QPainter::SmoothPixmapTransform);
67 painter.setClipRect(QRectF(QPointF(),
size()), Qt::IntersectClip);
68 painter.setTransform(
m_d->viewBoxTransform,
true);
69 painter.drawImage(QPoint(),
m_d->image);
79 const QString uid = context.
createUID(
"image");
87 QString aspectString =
m_d->ratioParser?
m_d->ratioParser->toString(): QString();
88 if (!aspectString.isEmpty()) {
89 context.
shapeWriter().addAttribute(
"preserveAspectRatio", aspectString);
93 buffer.open(QIODevice::WriteOnly);
94 if (
m_d->image.save(&buffer,
"PNG")) {
96 context.
shapeWriter().addAttribute(
"xlink:href",
"data:"+ mimeType +
";base64," + buffer.data().toBase64());
115 if (w == 0.0 || h == 0.0) {
119 QString fileName = element.attribute(
"xlink:href");
123 if (fileName.startsWith(
"data:")) {
125 QRegularExpression re(
"data:(.+?);base64,(.+)");
126 QRegularExpressionMatch match = re.match(fileName);
128 data = match.captured(2).toLatin1();
129 data = QByteArray::fromBase64(data);
134 if (!data.isEmpty()) {
135 QBuffer buffer(&data);
136 m_d->image.load(&buffer,
"");
139 const QString aspectString = element.attribute(
"preserveAspectRatio",
"xMidYMid meet");
142 if (!
m_d->image.isNull()) {
144 m_d->viewBoxTransform =
145 QTransform::fromScale(w /
m_d->image.width(), h /
m_d->image.height());
148 QRectF(QPointF(),
size()),
149 QRect(QPoint(),
m_d->image.size()),
150 &
m_d->viewBoxTransform);
153 if (
m_d->ratioParser->defer) {
162 if (
m_d->image != img) {
175 if (
m_d->viewBoxTransform != tf) {
176 m_d->viewBoxTransform = tf;
183 return m_d->viewBoxTransform;
static QString mimeTypeForSuffix(const QString &suffix)
Find the mimetype for a given extension. The extension may have the form "*.xxx" or "xxx".
virtual QSizeF size() const
Get the size of the shape in pt.
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
@ ContentChanged
the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
@ GenericMatrixChange
used after the matrix was changed without knowing which property explicitly changed
QTransform transformation() const
Returns the shapes local transformation matrix.
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
virtual void setSize(const QSizeF &size)
Resize the shape.
Contains data used for loading svg.
QByteArray fetchExternalFile(const QString &url)
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
Context for saving svg files.
QString createUID(const QString &base)
Create a unique id from the specified base text.
QScopedPointer< KoXmlWriter > shapeWriter
static void saveMetadata(const KoShape *shape, SvgSavingContext &context)
static qreal parseUnitX(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in x-direction
static void parseAspectRatio(const PreserveAspectRatioParser &p, const QRectF &elementBounds, const QRectF &viewRect, QTransform *_viewTransform)
static void writeTransformAttributeLazy(const QString &name, const QTransform &transform, KoXmlWriter &shapeWriter)
Writes a transform as an attribute name iff the transform is not empty.
static qreal parseUnitY(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in y-direction
QString toString(const QString &value)
QTransform viewBoxTransform
void setImage(const QImage &img)
void setViewBoxTransform(const QTransform &tf)
void setSize(const QSizeF &size) override
Resize the shape.
bool loadSvg(const QDomElement &element, SvgLoadingContext &context) override
Loads data from specified svg element.
bool saveSvg(SvgSavingContext &context) override
Saves data utilizing specified svg saving context.
void paint(QPainter &painter) const override
Paint the shape fill The class extending this one is responsible for painting itself....
Private(const Private &rhs)
KoShape * cloneShape() const override
creates a deep copy of the shape or shape's subtree
QScopedPointer< SvgUtil::PreserveAspectRatioParser > ratioParser
QSharedDataPointer< Private > m_d