Skip to content

armgit / krita

Public Imported from GitHub
0

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 unclosed paths when intersecting two rectangular selections

Dmitry Kazakov9a8064bb1103
diff --git a/libs/image/kis_pixel_selection.cpp b/libs/image/kis_pixel_selection.cpp
index fc9a74694e..cd18faee53 100644
--- a/libs/image/kis_pixel_selection.cpp
+++ b/libs/image/kis_pixel_selection.cpp
@@ -28,6 +28,7 @@
#include "kis_outline_generator.h"
#include <kis_iterator_ng.h>
#include "kis_lod_transform.h"
+#include "krita_utils.h"
#include "kundo2command.h"
@@ -271,8 +272,7 @@ void KisPixelSelection::intersectSelection(KisPixelSelectionSP selection)
m_d->outlineCacheValid &= selection->outlineCacheValid();
if (m_d->outlineCacheValid) {
- m_d->outlineCache &= selection->outlineCache();
- m_d->outlineCache.closeSubpath();
+ m_d->outlineCache = KritaUtils::tryCloseTornSubpathsAfterIntersection(m_d->outlineCache & selection->outlineCache());
}
m_d->invalidateThumbnailImage();
diff --git a/libs/image/krita_utils.cpp b/libs/image/krita_utils.cpp
index 290ba360fd..560b245b30 100644
--- a/libs/image/krita_utils.cpp
+++ b/libs/image/krita_utils.cpp
@@ -530,6 +530,23 @@ namespace KritaUtils
return QTransform::fromScale(image->xRes(), image->yRes());
}
+ QPainterPath tryCloseTornSubpathsAfterIntersection(QPainterPath path)
+ {
+ path.setFillRule(Qt::WindingFill);
+ QList<QPolygonF> polys = path.toSubpathPolygons();
+
+ path = QPainterPath();
+ path.setFillRule(Qt::WindingFill);
+ Q_FOREACH (QPolygonF poly, polys) {
+ ENTER_FUNCTION() << ppVar(poly.isClosed());
+ if (!poly.isClosed()) {
+ poly.append(poly.first());
+ }
+ path.addPolygon(poly);
+ }
+ return path;
+ }
+
void thresholdOpacity(KisPaintDeviceSP device, const QRect &rect, ThresholdMode mode)
{
const KoColorSpace *cs = device->colorSpace();
diff --git a/libs/image/krita_utils.h b/libs/image/krita_utils.h
index 1f4466ddc8..d3c8d46636 100644
--- a/libs/image/krita_utils.h
+++ b/libs/image/krita_utils.h
@@ -113,6 +113,20 @@ namespace KritaUtils
*/
QTransform KRITAIMAGE_EXPORT pathShapeBooleanSpaceWorkaround(KisImageSP image);
+ /**
+ * Sometimes, when intersecting two paths, QPainterPath
+ * does not close some of the subpaths. It causes glitches
+ * when rendering them on screen. So we should just close
+ * them explicitly.
+ *
+ * Note: after intersecting the paths all bezier curves are
+ * already converted to polylines, so it should be safe
+ * to go through the polygons.
+ *
+ * See: https://bugs.kde.org/show_bug.cgi?id=408369
+ */
+ QPainterPath KRITAIMAGE_EXPORT tryCloseTornSubpathsAfterIntersection(QPainterPath path);
+
enum ThresholdMode {
ThresholdNone = 0,
ThresholdFloor,
diff --git a/libs/ui/tool/kis_selection_tool_helper.cpp b/libs/ui/tool/kis_selection_tool_helper.cpp
index 71aa171103..5a7c34fd4e 100644
--- a/libs/ui/tool/kis_selection_tool_helper.cpp
+++ b/libs/ui/tool/kis_selection_tool_helper.cpp
@@ -262,8 +262,8 @@ void KisSelectionToolHelper::addSelectionShapes(QList< KoShape* > shapes, Select
case SELECTION_INTERSECT:
path = path1 & path2;
+ path = KritaUtils::tryCloseTornSubpathsAfterIntersection(path);
break;
-
case SELECTION_ADD:
path = path1 | path2;
break;