terminal/src/inc/conattrs.hpp
James Holderness 158a1708a6
Render the SGR "underlined" attribute in the style of the font (#7148)
This PR updates the rendering of the _underlined_ graphic rendition
attribute, using the style specified in the active font, instead of just
reusing the grid line at the bottom of the character cell.

* Support for drawing the correct underline effect in the grid line
  renderer was added in #7107.

There was already an `ExtendedAttributes` flag defined for the
underlined state, but I needed to update the `SetUnderlined` and
`IsUnderlined` methods in the `TextAttribute`  class to use that flag
now in place of the legacy `LVB_UNDERSCORE` attribute. This enables
underlines set via a VT sequence to be tracked separately from
`LVB_UNDERSCORE` grid lines set via the console API.

I then needed to update the `Renderer::s_GetGridlines` method to
activate the `GridLines::Underline` style when the `Underlined`
attribute was set. The `GridLines::Bottom` style is still triggered by
the `LVB_UNDERSCORE` attribute to produce the bottom grid line effect.

Validation
----------

Because this is a change from the existing behaviour, certain unit tests
that were expecting the `LVB_UNDERSCORE` to be toggled by `SGR 4` and
`SGR 24` have now had to be updated to check the `Underlined` flag
instead.

There were also some UI Automation tests that were checking for `SGR 4`
mapping to `LVB_UNDERSCORE` attribute, which I've now substituted with a
test of the `SGR 53` overline attribute mapping to
`LVB_GRID_HORIZONTAL`. These tests only work with legacy attributes, so
they can't access the extended underline state, and I thought a
replacement test that covered similar ground would be better than
dropping the tests altogether.

As far as the visual rendering is concerned, I've manually confirmed
that the VT underline sequences now draw the underline in the correct
position and style, while grid lines output via the console API are
still displayed in their original form.

Closes #2915
2020-08-03 12:49:25 +00:00

55 lines
2.1 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
--*/
#pragma once
#define FG_ATTRS (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
#define BG_ATTRS (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
#define META_ATTRS (COMMON_LVB_LEADING_BYTE | COMMON_LVB_TRAILING_BYTE | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_REVERSE_VIDEO | COMMON_LVB_UNDERSCORE)
enum class ExtendedAttributes : BYTE
{
Normal = 0x00,
Bold = 0x01,
Italics = 0x02,
Blinking = 0x04,
Invisible = 0x08,
CrossedOut = 0x10,
// TODO:GH#2916 add support for these to the parser as well.
Underlined = 0x20,
DoublyUnderlined = 0x40, // Included for completeness, but not currently supported.
Faint = 0x80,
};
DEFINE_ENUM_FLAG_OPERATORS(ExtendedAttributes);
WORD XtermToWindowsIndex(const size_t index) noexcept;
WORD Xterm256ToWindowsIndex(const size_t index) noexcept;
WORD XtermToLegacy(const size_t xtermForeground, const size_t xtermBackground);
const WORD WINDOWS_RED_ATTR = FOREGROUND_RED;
const WORD WINDOWS_GREEN_ATTR = FOREGROUND_GREEN;
const WORD WINDOWS_BLUE_ATTR = FOREGROUND_BLUE;
const WORD WINDOWS_BRIGHT_ATTR = FOREGROUND_INTENSITY;
const WORD XTERM_RED_ATTR = 0x01;
const WORD XTERM_GREEN_ATTR = 0x02;
const WORD XTERM_BLUE_ATTR = 0x04;
const WORD XTERM_BRIGHT_ATTR = 0x08;
enum class CursorType : unsigned int
{
Legacy = 0x0, // uses the cursor's height value to range from underscore-like to full box
VerticalBar = 0x1, // A single vertical line, '|'
Underscore = 0x2, // a single horizontal underscore, smaller that the min height legacy cursor.
EmptyBox = 0x3, // Just the outline of a full box
FullBox = 0x4 // a full box, similar to legacy with height=100%
};
// Valid COLORREFs are of the pattern 0x00bbggrr. -1 works as an invalid color,
// as the highest byte of a valid color is always 0.
constexpr COLORREF INVALID_COLOR = 0xffffffff;
constexpr WORD COLOR_TABLE_SIZE = 16;
constexpr WORD XTERM_COLOR_TABLE_SIZE = 256;