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 a number of caret and selection related issues.
Wolthera van Hövell tot Westerflier4172c3b47212
diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cppindex 5239c73775..8d3d2acb93 100644--- a/libs/flake/text/KoFontRegistry.cpp+++ b/libs/flake/text/KoFontRegistry.cpp@@ -842,10 +842,12 @@ KoSvgText::FontMetrics KoFontRegistry::generateFontMetrics(FT_FaceSP face, boolmetricTags.append(HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN);metricTags.append(HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET);metrics.caretRise = 1;+ metrics.caretRun = 0;} else {metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_RISE);metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_RUN);metricTags.append(HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET);+ metrics.caretRise = 0;metrics.caretRun = 1;}diff --git a/libs/flake/text/KoSvgText.cpp b/libs/flake/text/KoSvgText.cppindex 343877b7cc..6c2a0f8eba 100644--- a/libs/flake/text/KoSvgText.cpp+++ b/libs/flake/text/KoSvgText.cpp@@ -1564,10 +1564,10 @@ void FontMetrics::setMetricsValueByTag(const QLatin1String &tag, int32_t value)caretOffset = value;} else if (tag == "vcrs") {caretRise = value;- } else if (tag == "vcrs") {- caretRise = value;- } else if (tag == "vcrs") {- caretRise = value;+ } else if (tag == "vcrn") {+ caretRun = value;+ } else if (tag == "vcof") {+ caretOffset = value;}}diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex d3f9070001..7081aa76a7 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -578,13 +578,8 @@ QPainterPath KoSvgTextShape::underlines(int pos, int anchor, KoSvgText::TextDecoif (start == end || start < 0 || end >= d->cursorPos.size()) {return QPainterPath();}-QPainterPathStroker stroker;- qreal width = minimum;- if (thick) {- width *= 2;- }- stroker.setWidth(width);+KoSvgText::WritingMode mode = KoSvgText::WritingMode(this->textProperties().propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());stroker.setCapStyle(Qt::FlatCap);if (style == KoSvgText::Solid) {@@ -600,10 +595,12 @@ QPainterPath KoSvgTextShape::underlines(int pos, int anchor, KoSvgText::TextDecoQPainterPath underPath;QPainterPath overPath;QPainterPath middlePath;- QPointF inset = mode == KoSvgText::HorizontalTB? QPointF(width*0.5, 0): QPointF(0, width*0.5);+ qint32 strokeWidth = 0;+ QPointF inset = mode == KoSvgText::HorizontalTB? QPointF(minimum*0.5, 0): QPointF(0, minimum*0.5);for (int i = start+1; i <= end; i++) {CursorPos pos = d->cursorPos.at(i);CharacterResult res = d->result.at(pos.cluster);+ strokeWidth += res.metrics.underlineThickness;const QTransform tf = res.finalTransform();QPointF first = res.cursorInfo.caret.p1();QPointF last = first;@@ -642,6 +639,11 @@ QPainterPath KoSvgTextShape::underlines(int pos, int anchor, KoSvgText::TextDeco}}+ const qreal freetypePixelsToPt = (1.0 / 64.0) * (72. / qMin(d->xRes, d->yRes));+ const qreal width = qMax(qreal(strokeWidth/(end-(start+1)))*freetypePixelsToPt, minimum);++ stroker.setWidth(thick? width*2: width);+QPainterPath final;if (decor.testFlag(KoSvgText::DecorationUnderline)){final.addPath(stroker.createStroke(underPath));diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex e2a35b5b07..d00f9296d1 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -178,6 +178,7 @@ struct CharacterResult {}cursorInfo.caret.translate(-newOrigin);inkBoundingBox.translate(-newOrigin);+if (isHorizontal) {scaledDescent -= newOrigin.y();scaledAscent -= newOrigin.y();@@ -226,6 +227,9 @@ struct CharacterResult {}advance = scale.map(advance);cursorInfo.caret = scale.map(cursorInfo.caret);+ for (int i = 0; i < cursorInfo.offsets.size(); i++) {+ cursorInfo.offsets[i] = scale.map(cursorInfo.offsets.at(i));+ }inkBoundingBox = scale.mapRect(inkBoundingBox);if (isHorizontal) {diff --git a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp b/libs/flake/text/KoSvgTextShape_p_glyphs.cppindex e0a5e8691d..78c6ea6b35 100644--- a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp+++ b/libs/flake/text/KoSvgTextShape_p_glyphs.cpp@@ -530,7 +530,7 @@ bool KoSvgTextShape::Private::loadGlyph(const QTransform &ftTF,} else {qreal slope = 0;if (charResult.metrics.caretRun != 0 && charResult.metrics.caretRise !=0) {- slope = double(charResult.metrics.caretRun)/double(charResult.metrics.caretRise);+ slope = double(charResult.metrics.caretRise)/double(charResult.metrics.caretRun);if (offset == 0) {offset = descender * slope;}diff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex 539572629c..4df05128ff 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -575,8 +575,14 @@ void KoSvgTextShape::Private::paintDebug(QPainter &painter,painter.setPen(pen);painter.drawPolygon(tf.map(result.at(i).lineHeightBox()));- pen.setWidth(2);pen.setStyle(Qt::SolidLine);+ pen.setWidth(2);++ penColor.setAlpha(192);+ pen.setColor(penColor);+ painter.setPen(pen);+ painter.drawLine(tf.map(result.at(i).cursorInfo.caret));+const QPointF center = tf.mapRect(result.at(i).layoutBox()).center();QString text = "#";