Set Proper Background Color in HTML Copy (#2762)

* Set actual background color in HTML copy

* const

Co-Authored-By: Mike Griese <migrie@microsoft.com>

* format
This commit is contained in:
mcpiroman 2019-09-16 19:32:04 +02:00 committed by Carlos Zamora
parent 3d35e396b2
commit ed87689c04
4 changed files with 11 additions and 7 deletions

View file

@ -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
{
@ -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:";

View file

@ -148,6 +148,7 @@ public:
static std::string GenHTML(const TextAndColor& rows,
const int fontHeightPoints,
const PCWCHAR fontFaceName,
const COLORREF backgroundColor,
const std::string& htmlTitle);
private:

View file

@ -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())
{

View file

@ -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)
{