Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Extend image shape and allow bitmap text to use image shape for text outlines.
Wolthera van Hövell tot Westerflier246c0eb45559
diff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex 16d8807e39..ff9e81c798 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -14,6 +14,10 @@#include <KoColorBackground.h>#include <KoPathShape.h>#include <KoShapeStroke.h>+#include <KoShapeRegistry.h>+#include <KoShapeFactoryBase.h>+#include <KoProperties.h>+#include <KoClipMask.h>#include <QPainter>#include <QtMath>@@ -265,6 +269,13 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characte{QList<KoShape *> shapes;++ KoShapeFactoryBase *imageFactory = KoShapeRegistry::instance()->value("ImageShape");+ const QString imageProp = "image";+ const QString imageViewTransformProp = "viewboxTransform";+ KoShapeFactoryBase *rectangleFactory = KoShapeRegistry::instance()->value("RectangleShape");++KoShapeStrokeModelSP stroke = rootShape->stroke();QSharedPointer<KoShapeBackground> background = rootShape->background();QVector<KoShape::PaintOrder> paintOrder = rootShape->paintOrder();@@ -333,6 +344,31 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characte}} else if (const auto *outlineGlyph = std::get_if<Glyph::Outline>(&result.at(i).glyph)) {chunk.addPath(tf.map(outlineGlyph->path));+ } else if (const auto *bitmapGlyph = std::get_if<Glyph::Bitmap>(&result.at(i).glyph)) {++ KoProperties params;+ QRectF drawRect = bitmapGlyph->drawRect;+ QTransform imageTf = QTransform::fromTranslate(drawRect.x(), drawRect.y());+ QTransform viewBox = QTransform::fromScale(drawRect.width()/bitmapGlyph->image.width(),+ drawRect.height()/bitmapGlyph->image.height());+ params.setProperty(imageProp, bitmapGlyph->image);+ params.setProperty(imageViewTransformProp, viewBox);+ KoShape *shape = imageFactory->createShape(¶ms);+ if (bitmapGlyph->image.isGrayscale() || bitmapGlyph->image.format() == QImage::Format_Mono) {+ KoShape *rect = rectangleFactory->createDefaultShape();+ rect->setSize(drawRect.size());+ rect->setBackground(background);+ rect->setStroke(nullptr);+ KoClipMask *mask = new KoClipMask();+ mask->setShapes({shape});+ rect->setClipMask(mask);+ rect->setTransformation(imageTf*tf);+ shapes.append(rect);+ } else {+ shape->setSize(drawRect.size());+ shape->setTransformation(imageTf*tf);+ shapes.append(shape);+ }}}}diff --git a/plugins/flake/imageshape/ImageShape.cpp b/plugins/flake/imageshape/ImageShape.cppindex e5774632e1..8798b83fd5 100644--- a/plugins/flake/imageshape/ImageShape.cpp+++ b/plugins/flake/imageshape/ImageShape.cpp@@ -157,3 +157,29 @@ bool ImageShape::loadSvg(const QDomElement &element, SvgLoadingContext &context)return true;}++void ImageShape::setImage(const QImage &img)+{+ if (m_d->image != img) {+ m_d->image = img;+ shapeChanged(KoShape::ContentChanged);+ }+}++QImage ImageShape::image() const+{+ return m_d->image;+}++void ImageShape::setViewBoxTransform(const QTransform &tf)+{+ if (m_d->viewBoxTransform != tf) {+ m_d->viewBoxTransform = tf;+ shapeChanged(KoShape::GenericMatrixChange);+ }+}++QTransform ImageShape::viewBoxTransform() const+{+ return m_d->viewBoxTransform;+}diff --git a/plugins/flake/imageshape/ImageShape.h b/plugins/flake/imageshape/ImageShape.hindex 49ffa41b8f..5a0e1f32f1 100644--- a/plugins/flake/imageshape/ImageShape.h+++ b/plugins/flake/imageshape/ImageShape.h@@ -30,6 +30,12 @@ public:bool saveSvg(SvgSavingContext &context) override;bool loadSvg(const QDomElement &element, SvgLoadingContext &context) override;+ void setImage(const QImage &img);+ QImage image() const;++ void setViewBoxTransform(const QTransform &tf);+ QTransform viewBoxTransform() const;+private:ImageShape(const ImageShape &rhs);diff --git a/plugins/flake/imageshape/ImageShapeFactory.cpp b/plugins/flake/imageshape/ImageShapeFactory.cppindex 97f488be43..5e62b29e81 100644--- a/plugins/flake/imageshape/ImageShapeFactory.cpp+++ b/plugins/flake/imageshape/ImageShapeFactory.cpp@@ -16,6 +16,7 @@#include <KoXmlNS.h>#include <KoShapeLoadingContext.h>#include <KoIcon.h>+#include <KoProperties.h>// KDE#include <klocalizedstring.h>@@ -41,6 +42,23 @@ KoShape *ImageShapeFactory::createDefaultShape(KoDocumentResourceManager */*docureturn shape;}++KoShape *ImageShapeFactory::createShape(const KoProperties *params, KoDocumentResourceManager */*documentResources*/) const+{+ ImageShape *shape = new ImageShape();+ shape->setShapeId(ImageShapeId);++ QVariant var = params->value("image");+ if (var.type() == QVariant::Image) {+ shape->setImage(var.value<QImage>());+ }+ var = params->value("viewboxTransform");+ if (var.type() == QVariant::Transform) {+ shape->setViewBoxTransform(var.value<QTransform>());+ }+ return shape;+}+bool ImageShapeFactory::supports(const QDomElement &e, KoShapeLoadingContext &context) const{Q_UNUSED(context);diff --git a/plugins/flake/imageshape/ImageShapeFactory.h b/plugins/flake/imageshape/ImageShapeFactory.hindex 3ae36bf5de..e68bd88b9e 100644--- a/plugins/flake/imageshape/ImageShapeFactory.h+++ b/plugins/flake/imageshape/ImageShapeFactory.h@@ -22,6 +22,16 @@ public:~ImageShapeFactory() override {}KoShape *createDefaultShape(KoDocumentResourceManager *documentResources = 0) const override;+ /**+ * @brief createShape+ * @param params+ * The parameters. Will look at keys...+ * - "image" and retrieve as a QImage to set on the shape.+ * - "viewboxTransform" and retrieve as a QTransform to set on the shape.+ * @param documentResources -- unused.+ * @return ImageShape+ */+ KoShape *createShape(const KoProperties *params, KoDocumentResourceManager *documentResources = 0) const;bool supports(const QDomElement &e, KoShapeLoadingContext &context) const override;QList<KoShapeConfigWidgetBase *> createShapeOptionPanels() override;};