diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -589,18 +589,51 @@ QVector additionalFormats; if (range->length() > 0) { + if (drawSelection) { + additionalFormats = decorationsForLine(range->textLine(), range->line(), true); + } + + // Check if there's any format need to be fill into the gap. + auto formats = range->layout()->formats(); + if (!formats.isEmpty() || !additionalFormats.isEmpty()) { + QVector additionalFormatsCopy = formats; + additionalFormatsCopy += additionalFormats; + additionalFormatsCopy.append(QTextLayout::FormatRange()); + // Add this dummy selection to further drawing. + additionalFormatsCopy.back().start = 0; + additionalFormatsCopy.back().length = INT_MAX; + additionalFormatsCopy.back().format.setForeground(Qt::transparent); + additionalFormatsCopy.back().format.setBackground(Qt::transparent); + for (int i = 0 ; i < formats.size() + additionalFormats.size(); i++) { + additionalFormatsCopy[i].format.clearForeground(); + } + for (int i = 0; i < range->layout()->lineCount(); i++) { + auto line = range->layout()->lineAt(i); + int y = qRound(range->layout()->lineAt(i).y()); + // Right now, y should always be multiply of lineHeight. + if (auto yOffset = y % lineHeight()) { + auto rect = line.rect(); + if (rect.height() > 0) { + rect.moveTop(line.y() - yOffset); + rect.setHeight(yOffset); + auto diffHeight = yOffset; + auto yStart = -yOffset; + // We use a loop here just in case yOffset is very large, which should be rare. + while (diffHeight > 0) { + range->layout()->draw(&paint, QPoint(-xStart, yStart), additionalFormatsCopy, rect); + yStart += rect.height(); + diffHeight -= rect.height(); + } + } + } + } + } // We may have changed the pen, be absolutely sure it gets set back to // normal foreground color before drawing text for text that does not // set the pen color paint.setPen(attribute(KTextEditor::dsNormal)->foreground().color()); // Draw the text :) - if (drawSelection) { - additionalFormats = decorationsForLine(range->textLine(), range->line(), true); - range->layout()->draw(&paint, QPoint(-xStart, 0), additionalFormats); - - } else { - range->layout()->draw(&paint, QPoint(-xStart, 0)); - } + range->layout()->draw(&paint, QPoint(-xStart, 0), additionalFormats); } QBrush backgroundBrush; @@ -980,6 +1013,10 @@ * qreal fontHeight = font.ascent() + font.descent(); */ m_fontHeight = qMax(1, qCeil(m_fontMetrics.ascent() + m_fontMetrics.descent())); + // Try to use representitve character from English, Chinese, Japanese + // and Korean to calculate the line height. + // The characters being tested are "AHIygあ你말". + m_fontHeight = qMax(m_fontHeight, qCeil(m_fontMetrics.boundingRect(QString::fromUtf8("AHIyg\xe3\x81\x82\xe4\xbd\xa0\xeb\xa7\x90")).height())); } void KateRenderer::updateMarkerSize() @@ -1088,8 +1125,11 @@ // we include the leading, this must match the ::updateFontHeight code! line.setLeadingIncluded(true); - - line.setPosition(QPoint(line.lineNumber() ? shiftX : firstLineOffset, height)); + qreal lineOffset = 0; + if (line.height() < lineHeight()) { + lineOffset = lineHeight() - line.height(); + } + line.setPosition(QPoint(line.lineNumber() ? shiftX : firstLineOffset, height + lineOffset)); if (needShiftX && line.width() > 0) { needShiftX = false;