21#include <QRegularExpression>
31 ratioParser(rhs.ratioParser ? new
SvgUtil::PreserveAspectRatioParser(*rhs.ratioParser) : 0),
32 viewBoxTransform(rhs.viewBoxTransform)
37 QScopedPointer<SvgUtil::PreserveAspectRatioParser>
ratioParser;
66 const QRectF myrect(QPointF(),
size());
68 painter.setRenderHint(QPainter::SmoothPixmapTransform);
69 painter.setClipRect(QRectF(QPointF(),
size()), Qt::IntersectClip);
70 painter.setTransform(
m_d->viewBoxTransform,
true);
71 painter.drawImage(QPoint(),
m_d->image);
81 const QString uid = context.
createUID(
"image");
89 QString aspectString =
m_d->ratioParser?
m_d->ratioParser->toString(): QString();
90 if (!aspectString.isEmpty()) {
91 context.
shapeWriter().addAttribute(
"preserveAspectRatio", aspectString);
95 buffer.open(QIODevice::WriteOnly);
96 if (
m_d->image.save(&buffer,
"PNG")) {
98 context.
shapeWriter().addAttribute(
"xlink:href",
"data:"+ mimeType +
";base64," + buffer.data().toBase64());
117 if (w == 0.0 || h == 0.0) {
121 QString fileName = element.attribute(
"xlink:href");
125 if (fileName.startsWith(
"data:")) {
127 QRegularExpression re(
"data:(.+?);base64,(.+)");
128 QRegularExpressionMatch match = re.match(fileName);
130 data = match.captured(2).toLatin1();
131 data = QByteArray::fromBase64(data);
136 if (!data.isEmpty()) {
137 QBuffer buffer(&data);
138 m_d->image.load(&buffer,
"");
141 const QString aspectString = element.attribute(
"preserveAspectRatio",
"xMidYMid meet");
144 if (!
m_d->image.isNull()) {
146 m_d->viewBoxTransform =
147 QTransform::fromScale(w /
m_d->image.width(), h /
m_d->image.height());
150 QRectF(QPointF(),
size()),
151 QRect(QPoint(),
m_d->image.size()),
152 &
m_d->viewBoxTransform);
155 if (
m_d->ratioParser->defer) {
164 if (
m_d->image != img) {
177 if (
m_d->viewBoxTransform != tf) {
178 m_d->viewBoxTransform = tf;
185 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.
@ 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.
void shapeChanged(ChangeType type, KoShape *shape=0) override
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