diff --git a/src/SessionController.cpp b/SessionController.cpp --- a/src/SessionController.cpp +++ b/SessionController.cpp @@ -1864,7 +1864,8 @@ if (((dialog->selectedNameFilter()).contains(QLatin1String("html"), Qt::CaseInsensitive)) || ((dialog->selectedFiles()).at(0).endsWith(QLatin1String("html"), Qt::CaseInsensitive))) { - jobInfo.decoder = new HTMLDecoder(); + Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); + jobInfo.decoder = new HTMLDecoder(profile); } else { jobInfo.decoder = new PlainTextDecoder(); } diff --git a/src/TerminalCharacterDecoder.h b/TerminalCharacterDecoder.h --- a/src/TerminalCharacterDecoder.h +++ b/TerminalCharacterDecoder.h @@ -27,6 +27,7 @@ // Konsole #include "Character.h" +#include "Profile.h" #include "konsoleprivate_export.h" class QTextStream; @@ -129,13 +130,7 @@ /** * Constructs an HTML decoder using a default black-on-white color scheme. */ - HTMLDecoder(); - - /** - * Sets the color table which the decoder uses to produce the HTML color codes in its - * output - */ - void setColorTable(const ColorEntry *table); + HTMLDecoder(const Profile::Ptr &profile = Profile::Ptr()); void decodeLine(const Character * const characters, int count, LineProperty properties) Q_DECL_OVERRIDE; @@ -148,7 +143,8 @@ void closeSpan(QString &text); QTextStream *_output; - const ColorEntry *_colorTable; + Profile::Ptr _profile; + ColorEntry _colorTable[TABLE_COLORS]; bool _innerSpanOpen; RenditionFlags _lastRendition; CharacterColor _lastForeColor; diff --git a/src/TerminalCharacterDecoder.cpp b/TerminalCharacterDecoder.cpp --- a/src/TerminalCharacterDecoder.cpp +++ b/TerminalCharacterDecoder.cpp @@ -28,6 +28,8 @@ // Konsole #include "ExtendedCharTable.h" #include "ColorScheme.h" +#include "ColorSchemeManager.h" +#include "Profile.h" using namespace Konsole; PlainTextDecoder::PlainTextDecoder() @@ -162,37 +164,75 @@ *_output << plainText; } -HTMLDecoder::HTMLDecoder() : +HTMLDecoder::HTMLDecoder(const QExplicitlySharedDataPointer &profile) : _output(nullptr) - , _colorTable(ColorScheme::defaultTable) + , _profile(profile) , _innerSpanOpen(false) , _lastRendition(DEFAULT_RENDITION) , _lastForeColor(CharacterColor()) , _lastBackColor(CharacterColor()) { + const ColorScheme *colorScheme = nullptr; + + if (profile) { + colorScheme = ColorSchemeManager::instance()->findColorScheme(profile->colorScheme()); + + if (!colorScheme) { + colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); + } + + } + + if (colorScheme) { + colorScheme->getColorTable(_colorTable); + } else { + for (int i = 0; i < TABLE_COLORS; i++) { + _colorTable[i] = ColorScheme::defaultTable[i]; + } + } } void HTMLDecoder::begin(QTextStream* output) { _output = output; - QString text; - //open monospace span - openSpan(text, QStringLiteral("font-family:monospace")); + if (_profile) { + QString style; - *output << text; + QFont font = _profile->font(); + style.append(QStringLiteral("font-family:'%1',monospace;").arg(font.family())); + + // Prefer point size if set + if (font.pointSizeF() > 0) { + style.append(QStringLiteral("font-size:%1pt;").arg(font.pointSizeF())); + } else { + style.append(QStringLiteral("font-size:%1px;").arg(font.pixelSize())); + } + + + style.append(QStringLiteral("color:%1;").arg(_colorTable[DEFAULT_FORE_COLOR].name())); + style.append(QStringLiteral("background-color:%1;").arg(_colorTable[DEFAULT_BACK_COLOR].name())); + + *output << QStringLiteral("").arg(style); + } else { + QString text; + openSpan(text, QStringLiteral("font-family:monospace")); + *output << text; + } } void HTMLDecoder::end() { Q_ASSERT(_output); - QString text; - - closeSpan(text); - - *_output << text; + if (_profile) { + *_output << QStringLiteral(""); + } else { + QString text; + closeSpan(text); + *_output << text; + } _output = nullptr; } @@ -300,8 +340,3 @@ { text.append(QLatin1String("")); } - -void HTMLDecoder::setColorTable(const ColorEntry* table) -{ - _colorTable = table; -} diff --git a/src/SessionController.cpp b/src/SessionController.cpp --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -1864,7 +1864,8 @@ if (((dialog->selectedNameFilter()).contains(QLatin1String("html"), Qt::CaseInsensitive)) || ((dialog->selectedFiles()).at(0).endsWith(QLatin1String("html"), Qt::CaseInsensitive))) { - jobInfo.decoder = new HTMLDecoder(); + Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); + jobInfo.decoder = new HTMLDecoder(profile); } else { jobInfo.decoder = new PlainTextDecoder(); } diff --git a/src/TerminalCharacterDecoder.h b/src/TerminalCharacterDecoder.h --- a/src/TerminalCharacterDecoder.h +++ b/src/TerminalCharacterDecoder.h @@ -27,6 +27,7 @@ // Konsole #include "Character.h" +#include "Profile.h" #include "konsoleprivate_export.h" class QTextStream; @@ -129,13 +130,7 @@ /** * Constructs an HTML decoder using a default black-on-white color scheme. */ - HTMLDecoder(); - - /** - * Sets the color table which the decoder uses to produce the HTML color codes in its - * output - */ - void setColorTable(const ColorEntry *table); + HTMLDecoder(const Profile::Ptr &profile = Profile::Ptr()); void decodeLine(const Character * const characters, int count, LineProperty properties) Q_DECL_OVERRIDE; @@ -148,7 +143,8 @@ void closeSpan(QString &text); QTextStream *_output; - const ColorEntry *_colorTable; + Profile::Ptr _profile; + ColorEntry _colorTable[TABLE_COLORS]; bool _innerSpanOpen; RenditionFlags _lastRendition; CharacterColor _lastForeColor; diff --git a/src/TerminalCharacterDecoder.cpp b/src/TerminalCharacterDecoder.cpp --- a/src/TerminalCharacterDecoder.cpp +++ b/src/TerminalCharacterDecoder.cpp @@ -28,6 +28,8 @@ // Konsole #include "ExtendedCharTable.h" #include "ColorScheme.h" +#include "ColorSchemeManager.h" +#include "Profile.h" using namespace Konsole; PlainTextDecoder::PlainTextDecoder() @@ -162,37 +164,75 @@ *_output << plainText; } -HTMLDecoder::HTMLDecoder() : +HTMLDecoder::HTMLDecoder(const QExplicitlySharedDataPointer &profile) : _output(nullptr) - , _colorTable(ColorScheme::defaultTable) + , _profile(profile) , _innerSpanOpen(false) , _lastRendition(DEFAULT_RENDITION) , _lastForeColor(CharacterColor()) , _lastBackColor(CharacterColor()) { + const ColorScheme *colorScheme = nullptr; + + if (profile) { + colorScheme = ColorSchemeManager::instance()->findColorScheme(profile->colorScheme()); + + if (!colorScheme) { + colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); + } + + } + + if (colorScheme) { + colorScheme->getColorTable(_colorTable); + } else { + for (int i = 0; i < TABLE_COLORS; i++) { + _colorTable[i] = ColorScheme::defaultTable[i]; + } + } } void HTMLDecoder::begin(QTextStream* output) { _output = output; - QString text; - //open monospace span - openSpan(text, QStringLiteral("font-family:monospace")); + if (_profile) { + QString style; - *output << text; + QFont font = _profile->font(); + style.append(QStringLiteral("font-family:'%1',monospace;").arg(font.family())); + + // Prefer point size if set + if (font.pointSizeF() > 0) { + style.append(QStringLiteral("font-size:%1pt;").arg(font.pointSizeF())); + } else { + style.append(QStringLiteral("font-size:%1px;").arg(font.pixelSize())); + } + + + style.append(QStringLiteral("color:%1;").arg(_colorTable[DEFAULT_FORE_COLOR].name())); + style.append(QStringLiteral("background-color:%1;").arg(_colorTable[DEFAULT_BACK_COLOR].name())); + + *output << QStringLiteral("").arg(style); + } else { + QString text; + openSpan(text, QStringLiteral("font-family:monospace")); + *output << text; + } } void HTMLDecoder::end() { Q_ASSERT(_output); - QString text; - - closeSpan(text); - - *_output << text; + if (_profile) { + *_output << QStringLiteral(""); + } else { + QString text; + closeSpan(text); + *_output << text; + } _output = nullptr; } @@ -300,8 +340,3 @@ { text.append(QLatin1String("")); } - -void HTMLDecoder::setColorTable(const ColorEntry* table) -{ - _colorTable = table; -}