diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -587,20 +587,48 @@ } } + double yOffset, realLineHeight; QVector additionalFormats; if (range->length() > 0) { + auto boundingRect = range->layout()->boundingRect(); + realLineHeight = boundingRect.height(); + // Here is the trick for font that does not have consistent height. + yOffset = lineHeight() - boundingRect.height(); + if (yOffset < 0) { + yOffset = 0; + } + if (drawSelection) { + additionalFormats = decorationsForLine(range->textLine(), range->line(), true); + } + // We assume that decoration is always rect. + if (yOffset > 0 && realLineHeight > 0) { + QVector additionalFormatsClone = additionalFormats; + for (auto &format : additionalFormatsClone) { + format.format.setForeground(QColorConstants::Transparent); + } + paint.setPen(QColorConstants::Transparent); + auto diffHeight = yOffset; + double yStart = 0; + while (diffHeight > 0) { + QRectF clip; + if (diffHeight < realLineHeight) { + clip = boundingRect; + clip.setHeight(diffHeight); + } + range->layout()->draw(&paint, QPoint(-xStart, yStart), additionalFormatsClone, clip); + yStart += realLineHeight; + diffHeight -= realLineHeight; + } + } // 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, yOffset), additionalFormats); + } else { + yOffset = m_fontHeight - (m_fontMetrics.ascent() + m_fontMetrics.descent()); + realLineHeight = m_fontMetrics.ascent() + m_fontMetrics.descent(); } QBrush backgroundBrush; @@ -834,7 +862,7 @@ } if (cursor->column() <= range->length()) { - range->layout()->drawCursor(&paint, QPoint(-xStart, 0), cursor->column(), caretWidth); + range->layout()->drawCursor(&paint, QPoint(-xStart, yOffset), cursor->column(), caretWidth); } else { // Off the end of the line... must be block mode. Draw the caret ourselves. const KateTextLayout &lastLine = range->viewLine(range->viewLineCount() - 1); @@ -980,6 +1008,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()