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++
Fix handling multiple bitmaps per character result cluster.
Wolthera van Hövell tot Westerflieraba35da770dc
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex c071feabd1..0837eb59fa 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -70,8 +70,8 @@ struct Outline {};struct Bitmap {- QImage image;- QRectF drawRect;+ QVector<QImage> images;+ QVector<QRectF> drawRects;};struct ColorLayers {diff --git a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp b/libs/flake/text/KoSvgTextShape_p_glyphs.cppindex 787796d74b..77946b029a 100644--- a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp+++ b/libs/flake/text/KoSvgTextShape_p_glyphs.cpp@@ -425,8 +425,8 @@ std::pair<QTransform, qreal> KoSvgTextShape::Private::loadGlyphOnly(const QTransbitmapGlyph = &charResult.glyph.emplace<Glyph::Bitmap>();}- // TODO: Handle glyph clusters better...- bitmapGlyph->image = convertFromFreeTypeBitmap(currentGlyph.ftface->glyph);+ QImage image = convertFromFreeTypeBitmap(currentGlyph.ftface->glyph);+ bitmapGlyph->images.append(image);// Check whether we need to synthesize italic by shearing the glyph:if (charResult.fontStyle != QFont::StyleNormal@@ -443,7 +443,7 @@ std::pair<QTransform, qreal> KoSvgTextShape::Private::loadGlyphOnly(const QTrans} else {shearTf.shear(0, SLANT_BITMAP);glyphObliqueTf.shear(0, -SLANT_BITMAP);- shearAt = QPoint(bitmapGlyph->image.width() / 2, 0);+ shearAt = QPoint(image.width() / 2, 0);}// We need to shear around the baseline, hence the translation.bitmapTf = (QTransform::fromTranslate(-shearAt.x(), -shearAt.y()) * shearTf@@ -451,10 +451,10 @@ std::pair<QTransform, qreal> KoSvgTextShape::Private::loadGlyphOnly(const QTrans}if (!bitmapTf.isIdentity()) {- const QSize srcSize = bitmapGlyph->image.size();- bitmapGlyph->image = std::move(bitmapGlyph->image).transformed(+ const QSize srcSize = image.size();+ bitmapGlyph->images.replace(bitmapGlyph->images.size()-1, std::move(image).transformed(bitmapTf,- this->textRendering == OptimizeSpeed ? Qt::FastTransformation : Qt::SmoothTransformation);+ this->textRendering == OptimizeSpeed ? Qt::FastTransformation : Qt::SmoothTransformation));// This does the same as `QImage::trueMatrix` to get the image// offset after transforming.@@ -485,7 +485,6 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,// Whenever the freetype docs talk about a 26.6 floating point unit, they// mean a 1/64 value.const qreal ftFontUnit = 64.0;- const qreal ftFontUnitFactor = 1 / ftFontUnit;const int cluster = static_cast<int>(currentGlyph.cluster);@@ -601,15 +600,17 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,Glyph::Bitmap *const bitmapGlyph = std::get_if<Glyph::Bitmap>(&charResult.glyph);if (bitmapGlyph) {- const int width = bitmapGlyph->image.width();- const int height = bitmapGlyph->image.height();+ const int width = bitmapGlyph->images.last().width();+ const int height = bitmapGlyph->images.last().height();const int left = currentGlyph.ftface->glyph->bitmap_left;const int top = currentGlyph.ftface->glyph->bitmap_top - height;QRect bboxPixel(left, top, width, height);if (!isHorizontal) {bboxPixel.moveLeft(-(bboxPixel.width() / 2));}- bitmapGlyph->drawRect = ftTF.mapRect(QRectF(bboxPixel.topLeft() * ftFontUnit, bboxPixel.size() * ftFontUnit));+ QRectF drawRect = ftTF.mapRect(QRectF(bboxPixel.topLeft() * ftFontUnit, bboxPixel.size() * ftFontUnit));+ drawRect.translate(charResult.advance - ftTF.map(advance));+ bitmapGlyph->drawRects.append(drawRect);}QRectF bbox;@@ -633,7 +634,7 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,charResult.scaledDescent = isHorizontal? scaledBBox.bottom(): scaledBBox.left();if (bitmapGlyph) {- charResult.inkBoundingBox |= bitmapGlyph->drawRect;+ charResult.inkBoundingBox |= bitmapGlyph->drawRects.last();} else if (const auto *outlineGlyph = std::get_if<Glyph::Outline>(&charResult.glyph)) {charResult.inkBoundingBox |= outlineGlyph->path.boundingRect();} else if (const auto *colorGlyph = std::get_if<Glyph::ColorLayers>(&charResult.glyph)) {diff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex 4c92f38147..67978b557b 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -167,20 +167,24 @@ void KoSvgTextShape::Private::paintPaths(QPainter &painter,} 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)) {- if (bitmapGlyph->image.format() == QImage::Format_Grayscale8 || bitmapGlyph->image.format() == QImage::Format_Mono) {- fillPainter.maskPainter()->save();- fillPainter.maskPainter()->translate(result.at(i).finalPosition.x(), result.at(i).finalPosition.y());- fillPainter.maskPainter()->rotate(qRadiansToDegrees(result.at(i).rotate));- fillPainter.maskPainter()->setCompositionMode(QPainter::CompositionMode_Plus);- fillPainter.maskPainter()->drawImage(bitmapGlyph->drawRect, bitmapGlyph->image);- fillPainter.maskPainter()->restore();- } else {- painter.save();- painter.translate(result.at(i).finalPosition.x(), result.at(i).finalPosition.y());- painter.rotate(qRadiansToDegrees(result.at(i).rotate));- painter.setRenderHint(QPainter::SmoothPixmapTransform, true);- painter.drawImage(bitmapGlyph->drawRect, bitmapGlyph->image);- painter.restore();+ for (int b = 0; b < bitmapGlyph->images.size(); b++) {+ QImage img = bitmapGlyph->images.at(b);+ QRectF rect = bitmapGlyph->drawRects.value(b, QRectF(0, 0, img.width(), img.height()));+ if (img.format() == QImage::Format_Grayscale8 || img.format() == QImage::Format_Mono) {+ fillPainter.maskPainter()->save();+ fillPainter.maskPainter()->translate(result.at(i).finalPosition.x(), result.at(i).finalPosition.y());+ fillPainter.maskPainter()->rotate(qRadiansToDegrees(result.at(i).rotate));+ fillPainter.maskPainter()->setCompositionMode(QPainter::CompositionMode_Plus);+ fillPainter.maskPainter()->drawImage(rect, img);+ fillPainter.maskPainter()->restore();+ } else {+ painter.save();+ painter.translate(result.at(i).finalPosition.x(), result.at(i).finalPosition.y());+ painter.rotate(qRadiansToDegrees(result.at(i).rotate));+ painter.setRenderHint(QPainter::SmoothPixmapTransform, true);+ painter.drawImage(rect, img);+ painter.restore();+ }}}}@@ -410,34 +414,37 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Charactechunk.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.format() == QImage::Format_Grayscale8 || bitmapGlyph->image.format() == QImage::Format_Mono) {- KoShape *rect = rectangleFactory->createDefaultShape();- shape->setSize(drawRect.size());- rect->setSize(drawRect.size());- rect->setStroke(nullptr);- KoClipMask *mask = new KoClipMask();- mask->setShapes({shape});- rect->setClipMask(mask);- rect->setZIndex(shapes.size());- rect->setBackground(transformBackgroundToBounds(background,- rootShape->outlineRect(),- tf.mapRect(drawRect)));- rect->setTransformation(imageTf*tf);-- shapes.append(rect);- } else {- shape->setSize(drawRect.size());- shape->setTransformation(imageTf*tf);- shape->setZIndex(shapes.size());- shapes.append(shape);+ for (int b = 0; b < bitmapGlyph->images.size(); b++) {+ QImage img = bitmapGlyph->images.at(b);+ QRectF drawRect = bitmapGlyph->drawRects.at(b);+ KoProperties params;+ QTransform imageTf = QTransform::fromTranslate(drawRect.x(), drawRect.y());+ QTransform viewBox = QTransform::fromScale(drawRect.width()/img.width(),+ drawRect.height()/img.height());+ params.setProperty(imageProp, img);+ params.setProperty(imageViewTransformProp, viewBox);+ KoShape *shape = imageFactory->createShape(¶ms);+ if (img.format() == QImage::Format_Grayscale8 || img.format() == QImage::Format_Mono) {+ KoShape *rect = rectangleFactory->createDefaultShape();+ shape->setSize(drawRect.size());+ rect->setSize(drawRect.size());+ rect->setStroke(nullptr);+ KoClipMask *mask = new KoClipMask();+ mask->setShapes({shape});+ rect->setClipMask(mask);+ rect->setZIndex(shapes.size());+ rect->setBackground(transformBackgroundToBounds(background,+ rootShape->outlineRect(),+ tf.mapRect(drawRect)));+ rect->setTransformation(imageTf*tf);++ shapes.append(rect);+ } else {+ shape->setSize(drawRect.size());+ shape->setTransformation(imageTf*tf);+ shape->setZIndex(shapes.size());+ shapes.append(shape);+ }}}}@@ -508,7 +515,9 @@ void KoSvgTextShape::Private::paintDebug(QPainter &painter,pen.setWidth(2);painter.setPen(pen);if (const auto *bitmapGlyph = std::get_if<Glyph::Bitmap>(&result.at(i).glyph)) {- painter.drawPolygon(tf.map(bitmapGlyph->drawRect));+ Q_FOREACH(const QRectF drawRect, bitmapGlyph->drawRects) {+ painter.drawPolygon(tf.map(drawRect));+ }} else if (const auto *colorGlyph = std::get_if<Glyph::ColorLayers>(&result.at(i).glyph)) {QRectF boundingRect;Q_FOREACH (const QPainterPath &p, colorGlyph->paths) {