File Metadata

Author
cullmann
Created
May 9 2020, 2:29 PM

lineheight.patch

diff --git a/src/render/katelinelayout.cpp b/src/render/katelinelayout.cpp
index ca3367c0..aeabb560 100644
--- a/src/render/katelinelayout.cpp
+++ b/src/render/katelinelayout.cpp
@@ -206,6 +206,23 @@ int KateLineLayout::widthOfLastLine() const
return lastLine.width() + lastLine.xOffset();
}
+
+int KateLineLayout::height() const
+{
+ int height = 0;
+
+ for (int i = 0; i < m_layout->lineCount(); ++i) {
+ height += m_layout->lineAt(i).height();
+ }
+
+ return height;
+}
+
+int KateLineLayout::heightOfLine(int viewLine) const
+{
+ return m_layout->lineAt(viewLine).height();
+}
+
bool KateLineLayout::isOutsideDocument() const
{
return line() < 0 || line() >= m_renderer.doc()->lines();
diff --git a/src/render/katelinelayout.h b/src/render/katelinelayout.h
index a6a19d05..b473dc73 100644
--- a/src/render/katelinelayout.h
+++ b/src/render/katelinelayout.h
@@ -78,6 +78,9 @@ public:
int width() const;
int widthOfLastLine() const;
+ int height() const;
+ int heightOfLine(int viewLine) const;
+
int viewLineCount() const;
KateTextLayout viewLine(int viewLine) const;
int viewLineForColumn(int column) const;
diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp
index 99984cf8..27166922 100644
--- a/src/render/katerenderer.cpp
+++ b/src/render/katerenderer.cpp
@@ -230,7 +230,7 @@ void KateRenderer::paintTextLineBackground(QPainter &paint, KateLineLayoutPtr la
}
// Draw line background
- paint.fillRect(0, 0, xEnd - xStart, lineHeight() * layout->viewLineCount(), backgroundColor);
+ paint.fillRect(0, 0, xEnd - xStart, layout->height(), backgroundColor);
// paint the current line background if we're on the current line
if (currentViewLine != -1) {
@@ -552,18 +552,18 @@ void KateRenderer::paintTextLine(QPainter &paint, KateLineLayoutPtr range, int x
paintTextLineBackground(paint, range, currentViewLine, xStart, xEnd);
- // Draws the dashed underline at the start of a folded block of text.
- if (!(flags & SkipDrawFirstInvisibleLineUnderlined) && range->startsInvisibleBlock()) {
- QPen pen(config()->foldingColor());
- pen.setCosmetic(true);
- pen.setStyle(Qt::DashLine);
- pen.setDashOffset(xStart);
- pen.setWidth(2);
- paint.setPen(pen);
- paint.drawLine(0, (lineHeight() * range->viewLineCount()) - 2, xEnd - xStart, (lineHeight() * range->viewLineCount()) - 2);
- }
-
if (range->layout()) {
+ // Draws the dashed underline at the start of a folded block of text.
+ if (!(flags & SkipDrawFirstInvisibleLineUnderlined) && range->startsInvisibleBlock()) {
+ QPen pen(config()->foldingColor());
+ pen.setCosmetic(true);
+ pen.setStyle(Qt::DashLine);
+ pen.setDashOffset(xStart);
+ pen.setWidth(2);
+ paint.setPen(pen);
+ paint.drawLine(0, range->height() - 2, xEnd - xStart, range->height() - 2);
+ }
+
bool drawSelection = m_view && m_view->selection() && showSelections() && m_view->selectionRange().overlapsLine(range->line());
// Draw selection in block selection mode. We need 2 kinds of selections that QTextLayout::draw can't render:
// - past-end-of-line selection and
@@ -577,13 +577,13 @@ void KateRenderer::paintTextLine(QPainter &paint, KateLineLayoutPtr range, int x
if (selectionEndColumn > lastLine.startCol()) {
int selectionStartX = (selectionStartColumn > lastLine.startCol()) ? cursorToX(lastLine, selectionStartColumn, true) : 0;
int selectionEndX = cursorToX(lastLine, selectionEndColumn, true);
- paint.fillRect(QRect(selectionStartX - xStart, (int)lastLine.lineLayout().y(), selectionEndX - selectionStartX, lineHeight()), selectionBrush);
+ paint.fillRect(QRectF(selectionStartX - xStart, lastLine.lineLayout().y(), selectionEndX - selectionStartX, lastLine.lineLayout().height()), selectionBrush);
}
} else {
const int selectStickWidth = 2;
KateTextLayout selectionLine = range->viewLine(range->viewLineForColumn(selectionStartColumn));
int selectionX = cursorToX(selectionLine, selectionStartColumn, true);
- paint.fillRect(QRect(selectionX - xStart, (int)selectionLine.lineLayout().y(), selectStickWidth, lineHeight()), selectionBrush);
+ paint.fillRect(QRectF(selectionX - xStart, selectionLine.lineLayout().y(), selectStickWidth, selectionLine.lineLayout().height()), selectionBrush);
}
}
@@ -666,9 +666,9 @@ void KateRenderer::paintTextLine(QPainter &paint, KateLineLayoutPtr range, int x
if (draw) {
int fillStartX = line.endX() - line.startX() + line.xOffset() - xStart;
- int fillStartY = lineHeight() * i;
+ int fillStartY = line.lineLayout().y();
int width = xEnd - xStart - fillStartX;
- int height = lineHeight();
+ int height = line.lineLayout().height();
// reverse X for right-aligned lines
if (range->layout()->textOption().alignment() == Qt::AlignRight) {
@@ -676,8 +676,7 @@ void KateRenderer::paintTextLine(QPainter &paint, KateLineLayoutPtr range, int x
}
if (width > 0) {
- QRect area(fillStartX, fillStartY, width, height);
- paint.fillRect(area, drawBrush);
+ paint.fillRect(QRectF(fillStartX, fillStartY, width, height), drawBrush);
}
}
@@ -694,7 +693,7 @@ void KateRenderer::paintTextLine(QPainter &paint, KateLineLayoutPtr range, int x
// draw an open box to mark non-breaking spaces
const QString &text = range->textLine()->string();
- int y = lineHeight() * i + fm.ascent() - fm.strikeOutPos();
+ int y = line.lineLayout().y() + fm.ascent() - fm.strikeOutPos();
int nbSpaceIndex = text.indexOf(nbSpaceChar, line.lineLayout().xToCursor(xStart));
while (nbSpaceIndex != -1 && nbSpaceIndex < line.endCol()) {
@@ -1111,7 +1110,7 @@ void KateRenderer::layoutLine(KateLineLayoutPtr lineLayout, int maxwidth, bool c
lineLayout->setShiftX(shiftX);
}
- height += lineHeight();
+ height += line.height();
}
l->endLayout();