Skip to content

Commit

Permalink
Set Proper Background Color in HTML Copy (#2762)
Browse files Browse the repository at this point in the history
* Set actual background color in HTML copy

* const

Co-Authored-By: Mike Griese <[email protected]>

* format
  • Loading branch information
mcpiroman authored and carlos-zamora committed Sep 16, 2019
1 parent 3d35e39 commit ed87689
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,12 +1056,13 @@ const TextBuffer::TextAndColor TextBuffer::GetTextForClipboard(const bool lineSe
// - Generates a CF_HTML compliant structure based on the passed in text and color data
// Arguments:
// - rows - the text and color data we will format & encapsulate
// - backgroundColor - default background color for characters, also used in padding
// - fontHeightPoints - the unscaled font height
// - fontFaceName - the name of the font used
// - htmlTitle - value used in title tag of html header. Used to name the application
// Return Value:
// - string containing the generated HTML
std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPoints, const PCWCHAR fontFaceName, const std::string& htmlTitle)
std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPoints, const PCWCHAR fontFaceName, const COLORREF backgroundColor, const std::string& htmlTitle)
{
try
{
Expand All @@ -1086,11 +1087,8 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo
htmlBuilder << "display:inline-block;";
htmlBuilder << "white-space:pre;";

// fixme: this is only walkaround for filling background after last char of row.
// It is based on first char of first row, not the actual char at correct position.
htmlBuilder << "background-color:";
const COLORREF globalBgColor = rows.BkAttr.at(0).at(0);
htmlBuilder << Utils::ColorToHexString(globalBgColor);
htmlBuilder << Utils::ColorToHexString(backgroundColor);
htmlBuilder << ";";

htmlBuilder << "font-family:";
Expand Down
1 change: 1 addition & 0 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TextBuffer final
static std::string GenHTML(const TextAndColor& rows,
const int fontHeightPoints,
const PCWCHAR fontFaceName,
const COLORREF backgroundColor,
const std::string& htmlTitle);

private:
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
}

// convert text to HTML format
const auto htmlData = TextBuffer::GenHTML(bufferData, _actualFont.GetUnscaledSize().Y, _actualFont.GetFaceName(), "Windows Terminal");
const auto htmlData = TextBuffer::GenHTML(bufferData,
_actualFont.GetUnscaledSize().Y,
_actualFont.GetFaceName(),
_settings.DefaultBackground(),
"Windows Terminal");

if (!_terminal->IsCopyOnSelectActive())
{
Expand Down
3 changes: 2 additions & 1 deletion src/interactivity/win32/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ void Clipboard::CopyTextToSystemClipboard(const TextBuffer::TextAndColor& rows,
{
const auto& fontData = ServiceLocator::LocateGlobals().getConsoleInformation().GetActiveOutputBuffer().GetCurrentFont();
int const iFontHeightPoints = fontData.GetUnscaledSize().Y * 72 / ServiceLocator::LocateGlobals().dpi;
std::string HTMLToPlaceOnClip = TextBuffer::GenHTML(rows, iFontHeightPoints, fontData.GetFaceName(), "Windows Console Host");
const COLORREF bgColor = ServiceLocator::LocateGlobals().getConsoleInformation().GetDefaultBackground();
std::string HTMLToPlaceOnClip = TextBuffer::GenHTML(rows, iFontHeightPoints, fontData.GetFaceName(), bgColor, "Windows Console Host");
const size_t cbNeededHTML = HTMLToPlaceOnClip.size();
if (cbNeededHTML)
{
Expand Down

0 comments on commit ed87689

Please sign in to comment.