diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -984,9 +984,21 @@ void KateRenderer::updateFontHeight() { - // ensure minimal height of one pixel to not fall in the div by 0 trap somewhere - // use font line spacing, this includes the leading - m_fontHeight = qMax(1, qCeil(config()->fontMetrics().lineSpacing())); + /** + * ensure minimal height of one pixel to not fall in the div by 0 trap somewhere + * + * use a line spacing that matches the code in qt to layout/paint text + * + * see bug 403868 + * https://github.com/qt/qtbase/blob/5.12/src/gui/text/qtextlayout.cpp (line 2270 at the moment) where the text height is set as: + * + * qreal height = maxY + fontHeight - minY; + * + * with fontHeight: + * + * qreal fontHeight = font.ascent() + font.descent(); + */ + m_fontHeight = qMax(1, qCeil(config()->fontMetrics().ascent() + config()->fontMetrics().descent())); } void KateRenderer::updateMarkerSize() diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp --- a/src/view/kateviewinternal.cpp +++ b/src/view/kateviewinternal.cpp @@ -2713,7 +2713,7 @@ m_scrollY = 0; m_scrollTimer.start(50); - + e->accept(); } else { e->ignore(); @@ -2989,73 +2989,64 @@ renderer()->setShowSpaces(doc()->config()->showSpaces()); renderer()->updateMarkerSize(); - int sy = startz * h; + /** + * paint line by line + * this includes parts that span areas without real lines + * translate to first line to paint + */ paint.translate(unionRect.x(), startz * h); - for (uint z = startz; z <= endz; z++) { - paint.save(); - + /** + * paint regions without lines mapped to + */ if ((z >= lineRangesSize) || (cache()->viewLine(z).line() == -1)) { if (!(z >= lineRangesSize)) { cache()->viewLine(z).setDirty(false); } - - // set clipping region if we paint the line above us, too - paint.setClipRect(QRect(0, 0, unionRect.width(), h)); paint.fillRect(0, 0, unionRect.width(), h, renderer()->config()->backgroundColor()); + } - // second: paint previous line elements, that span into our line like _ in last line, bug 335079 - if (z > 0 && (z-1 < lineRangesSize) && (cache()->viewLine(z-1).line() != -1)) { - KateTextLayout &previousLine = cache()->viewLine(z-1); - paint.save(); - paint.translate(QPoint(0, h * - (previousLine.viewLine() + 1))); - renderer()->paintTextLine(paint, previousLine.kateLineLayout(), xStart, xEnd, &pos); - paint.restore(); - } - } else { - //qCDebug(LOG_KTE)<<"KateViewInternal::paintEvent(QPaintEvent *e):cache()->viewLine"<viewLine(z); - - /* If viewLine() returns non-zero, then a document line was split - in several visual lines, and we're trying to paint visual line - that is not the first. In that case, this line was already - painted previously, since KateRenderer::paintTextLine paints - all visual lines. - Except if we're at the start of the region that needs to - be painted -- when no previous calls to paintTextLine were made. + /** + * paint text lines + */ + else { + /** + * If viewLine() returns non-zero, then a document line was split + * in several visual lines, and we're trying to paint visual line + * that is not the first. In that case, this line was already + * painted previously, since KateRenderer::paintTextLine paints + * all visual lines. + * + * Except if we're at the start of the region that needs to + * be painted -- when no previous calls to paintTextLine were made. */ + KateTextLayout &thisLine = cache()->viewLine(z); if (!thisLine.viewLine() || z == startz) { - //qDebug() << "paint text: line: " << thisLine.line() << " viewLine " << thisLine.viewLine() << " x: " << unionRect.x() << " y: " << unionRect.y() << " width: " << xEnd-xStart << " height: " << h << endl; - - // first: paint our line - // set clipping region if we paint the line above us, too + /** + * paint our line + * set clipping region to only paint the relevant parts + */ + paint.save(); paint.translate(QPoint(0, h * - thisLine.viewLine())); paint.setClipRect(QRect(0, 0, unionRect.width(), h * thisLine.kateLineLayout()->viewLineCount())); renderer()->paintTextLine(paint, thisLine.kateLineLayout(), xStart, xEnd, &pos); - paint.translate(0, h * thisLine.viewLine()); - - // second: paint previous line elements, that span into our line like _, bug 335079 - if (z > 0) { - KateTextLayout &previousLine = cache()->viewLine(z-1); - paint.save(); - paint.translate(QPoint(0, h * - (previousLine.viewLine() + 1))); - renderer()->paintTextLine(paint, previousLine.kateLineLayout(), xStart, xEnd, &pos); - paint.restore(); - } + paint.restore(); /** * line painted, reset and state + mark line as non-dirty */ thisLine.setDirty(false); } } - paint.restore(); + /** + * translate to next line + */ paint.translate(0, h); - sy += h; } paint.restore(); + if (m_textAnimation) { m_textAnimation->draw(paint); }