Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions lib/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ void TerminalDisplay::fontChange(const QFont&)

_fontAscent = fm.ascent();

_staticTextCache.clear();

emit changedFontMetricSignal( _fontHeight, _fontWidth );
propagateSize();

Expand Down Expand Up @@ -361,6 +363,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
,mMotionAfterPasting(NoMoveScreenWindow)
,_leftBaseMargin(1)
,_topBaseMargin(1)
,_staticTextCache(4096)
{
// variables for draw text
_drawTextAdditionHeight = 0;
Expand Down Expand Up @@ -825,10 +828,11 @@ void TerminalDisplay::drawCharacters(QPainter& painter,
|| font.strikeOut() != useStrikeOut
|| font.overline() != useOverline) {
font.setBold(useBold);
font.setUnderline(useUnderline);
// FIXME: QStaticText have some problem with underline, strikeline and overline... see below
// font.setUnderline(useUnderline);
font.setItalic(useItalic);
font.setStrikeOut(useStrikeOut);
font.setOverline(useOverline);
// font.setStrikeOut(useStrikeOut);
// font.setOverline(useOverline);
painter.setFont(font);
}

Expand Down Expand Up @@ -856,11 +860,44 @@ void TerminalDisplay::drawCharacters(QPainter& painter,
if (_bidiEnabled) {
painter.drawText(rect.x(), rect.y() + _fontAscent + _lineSpacing, QString::fromStdWString(text));
} else {
{
QString draw_text_str = QString::fromStdWString(text);
uint32_t draw_text_flags = 0;
if (useBold) draw_text_flags |= (1 << 0);
// if (useUnderline) draw_text_flags |= (1 << 1);
if (useItalic) draw_text_flags |= (1 << 2);
// if (useStrikeOut) draw_text_flags |= (1 << 3);
// if (useOverline) draw_text_flags |= (1 << 4);

QPair<uint32_t, QString> static_text_key(draw_text_flags, draw_text_str);

QStaticText *staticText = _staticTextCache.object(static_text_key);
if (!staticText) {
staticText = new QStaticText(draw_text_str);
staticText->setTextFormat(Qt::PlainText);
staticText->prepare(QTransform(), font);
_staticTextCache.insert(static_text_key, staticText);
}

#if 0
QRect drawRect(rect.topLeft(), rect.size());
drawRect.setHeight(rect.height() + _drawTextAdditionHeight);
painter.drawText(drawRect, Qt::AlignBottom, LTR_OVERRIDE_CHAR + QString::fromStdWString(text));
}
#else
// painter.drawStaticText(rect.topLeft(), *staticText);
painter.drawStaticText(
QPointF(
rect.left(),
rect.top() - (staticText->size().height() - rect.height()) * 4 / 5), // align baseline for fallback font (80% of height)
*staticText);
#endif

// FIXME: see previous comments
if (useUnderline)
painter.drawLine(QLineF(rect.left(), rect.bottom() - 0.5, rect.right(), rect.bottom() - 0.5));
if (useStrikeOut)
painter.drawLine(QLineF(rect.left(), (rect.top() + rect.bottom()) / 2.0, rect.right(), (rect.top() + rect.bottom()) / 2.0));
if (useOverline)
painter.drawLine(QLineF(rect.left(), rect.top() + 0.5, rect.right(), rect.top() + 0.5));
}
}
}
Expand Down Expand Up @@ -1263,7 +1300,6 @@ void TerminalDisplay::updateImage()
if (!_hasBlinker && _blinkTimer->isActive()) { _blinkTimer->stop(); _blinking = false; }
delete[] dirtyMask;
delete[] disstrU;

}

void TerminalDisplay::showResizeNotification()
Expand Down
5 changes: 5 additions & 0 deletions lib/TerminalDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <QColor>
#include <QPointer>
#include <QWidget>
#include <QStaticText>
#include <QCache>
#include <QPair>

// Konsole
#include "Filter.h"
Expand Down Expand Up @@ -827,6 +830,8 @@ private slots:
int _leftBaseMargin;
int _topBaseMargin;

QCache<QPair<uint32_t, QString>, QStaticText> _staticTextCache;

public:
static void setTransparencyEnabled(bool enable)
{
Expand Down