Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom box drawing and powerline glyphs #16729

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

const auto lock = _terminal->LockForWriting();

_builtinGlyphs = _settings->EnableBuiltinGlyphs();
_cellWidth = CSSLengthPercentage::FromString(_settings->CellWidth().c_str());
_cellHeight = CSSLengthPercentage::FromString(_settings->CellHeight().c_str());
_runtimeOpacity = std::nullopt;
Expand Down Expand Up @@ -1047,6 +1048,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_actualFont = { fontFace, 0, fontWeight.Weight, _desiredFont.GetEngineSize(), CP_UTF8, false };
_actualFontFaceName = { fontFace };

_desiredFont.SetEnableBuiltinGlyphs(_builtinGlyphs);
_desiredFont.SetCellSize(_cellWidth, _cellHeight);

const auto before = _actualFont.GetSize();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
FontInfoDesired _desiredFont;
FontInfo _actualFont;
winrt::hstring _actualFontFaceName;
bool _builtinGlyphs = true;
CSSLengthPercentage _cellWidth;
CSSLengthPercentage _cellHeight;

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Microsoft.Terminal.Control
String Padding { get; };
Windows.Foundation.Collections.IMap<String, UInt32> FontFeatures { get; };
Windows.Foundation.Collections.IMap<String, Single> FontAxes { get; };
Boolean EnableBuiltinGlyphs { get; };
String CellWidth { get; };
String CellHeight { get; };

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontFace);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontSize);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontWeight);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), EnableBuiltinGlyphs);

OBSERVABLE_PROJECTED_SETTING(_appearance, RetroTerminalEffect);
OBSERVABLE_PROJECTED_SETTING(_appearance, CursorShape);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Single, FontSize);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Double, LineHeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.UI.Text.FontWeight, FontWeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, EnableBuiltinGlyphs);

OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, DarkColorSchemeName);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, LightColorSchemeName);
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@
</StackPanel>
</local:SettingContainer>

<!-- Builtin Glyphs -->
<local:SettingContainer x:Uid="Profile_EnableBuiltinGlyphs"
ClearSettingValue="{x:Bind Appearance.ClearEnableBuiltinGlyphs}"
HasSettingValue="{x:Bind Appearance.HasEnableBuiltinGlyphs, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.EnableBuiltinGlyphsOverrideSource, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind Appearance.EnableBuiltinGlyphs, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>

<!-- Retro Terminal Effect -->
<local:SettingContainer x:Uid="Profile_RetroTerminalEffect"
ClearSettingValue="{x:Bind Appearance.ClearRetroTerminalEffect}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,14 @@
<value>1.2</value>
<comment>"1.2" is a decimal number.</comment>
</data>
<data name="Profile_EnableBuiltinGlyphs.Header" xml:space="preserve">
<value>Builtin Glyphs</value>
<comment>The main label of a toggle. When enabled, certain characters (glyphs) are replaced with better looking ones.</comment>
</data>
<data name="Profile_EnableBuiltinGlyphs.HelpText" xml:space="preserve">
<value>When enabled, the terminal draws custom glyphs for block element and box drawing characters instead of using the font. This feature only works when GPU Acceleration is available.</value>
<comment>A longer description of the "Profile_EnableBuiltinGlyphs" toggle. "glyphs", "block element" and "box drawing characters" are technical terms from the Unicode specification.</comment>
</data>
<data name="Profile_FontWeightComboBox.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Font weight</value>
<comment>Name for a control to select the weight (i.e. bold, thin, etc.) of the text in the app.</comment>
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/FontConfig.idl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_FONT_SETTING(Windows.UI.Text.FontWeight, FontWeight);
INHERITABLE_FONT_SETTING(Windows.Foundation.Collections.IMap<String COMMA UInt32>, FontFeatures);
INHERITABLE_FONT_SETTING(Windows.Foundation.Collections.IMap<String COMMA Single>, FontAxes);
INHERITABLE_FONT_SETTING(Boolean, EnableBuiltinGlyphs);
INHERITABLE_FONT_SETTING(String, CellWidth);
INHERITABLE_FONT_SETTING(String, CellHeight);
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Author(s):
X(winrt::Windows::UI::Text::FontWeight, FontWeight, "weight", DEFAULT_FONT_WEIGHT) \
X(IFontAxesMap, FontAxes, "axes") \
X(IFontFeatureMap, FontFeatures, "features") \
X(bool, EnableBuiltinGlyphs, "builtinGlyphs", true) \
X(winrt::hstring, CellWidth, "cellWidth") \
X(winrt::hstring, CellHeight, "cellHeight")

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_FontWeight = fontInfo.FontWeight();
_FontFeatures = fontInfo.FontFeatures();
_FontAxes = fontInfo.FontAxes();
_EnableBuiltinGlyphs = fontInfo.EnableBuiltinGlyphs();
_CellWidth = fontInfo.CellWidth();
_CellHeight = fontInfo.CellHeight();
_Padding = profile.Padding();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, winrt::Windows::UI::Text::FontWeight, FontWeight);
INHERITABLE_SETTING(Model::TerminalSettings, IFontAxesMap, FontAxes);
INHERITABLE_SETTING(Model::TerminalSettings, IFontFeatureMap, FontFeatures);
INHERITABLE_SETTING(Model::TerminalSettings, bool, EnableBuiltinGlyphs, true);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellWidth);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellHeight);

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/inc/ControlProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
X(winrt::Windows::UI::Text::FontWeight, FontWeight) \
X(IFontFeatureMap, FontFeatures) \
X(IFontAxesMap, FontAxes) \
X(bool, EnableBuiltinGlyphs, true) \
X(winrt::hstring, CellWidth) \
X(winrt::hstring, CellHeight) \
X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \
Expand Down
4 changes: 4 additions & 0 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SCREEN_INFORMATION::SCREEN_INFORMATION(
{
OutputMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}
_desiredFont.SetEnableBuiltinGlyphs(gci.GetEnableBuiltinGlyphs());
}

// Routine Description:
Expand Down Expand Up @@ -539,7 +540,10 @@ void SCREEN_INFORMATION::RefreshFontWithRenderer()

void SCREEN_INFORMATION::UpdateFont(const FontInfo* const pfiNewFont)
{
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();

FontInfoDesired fiDesiredFont(*pfiNewFont);
fiDesiredFont.SetEnableBuiltinGlyphs(gci.GetEnableBuiltinGlyphs());

GetDesiredFont() = fiDesiredFont;

Expand Down
5 changes: 5 additions & 0 deletions src/host/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,8 @@ bool Settings::GetCopyColor() const noexcept
{
return _fCopyColor;
}

bool Settings::GetEnableBuiltinGlyphs() const noexcept
{
return _fEnableBuiltinGlyphs;
}
2 changes: 2 additions & 0 deletions src/host/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Settings

UseDx GetUseDx() const noexcept;
bool GetCopyColor() const noexcept;
bool GetEnableBuiltinGlyphs() const noexcept;

private:
RenderSettings _renderSettings;
Expand Down Expand Up @@ -221,6 +222,7 @@ class Settings
DWORD _dwVirtTermLevel;
UseDx _fUseDx;
bool _fCopyColor;
bool _fEnableBuiltinGlyphs = true;

// this is used for the special STARTF_USESIZE mode.
bool _fUseWindowSizePixels;
Expand Down
36 changes: 19 additions & 17 deletions src/inc/til/flat_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#pragma once

#pragma warning(push)
#pragma warning(disable : 26446) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4).
#pragma warning(disable : 26409) // Avoid calling new and delete explicitly, use std::make_unique<T> instead (r.11).
#pragma warning(disable : 26432) // If you define or delete any default operation in the type '...', define or delete them all (c.21).
#pragma warning(disable : 26446) // Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4).

namespace til
{
Expand Down Expand Up @@ -36,7 +37,7 @@ namespace til
// * small and cheap T
// * >= 50% successful lookups
// * <= 50% load factor (LoadFactor >= 2, which is the minimum anyways)
template<typename T, size_t LoadFactor = 2, size_t GrowthExponent = 1>
template<typename T, typename Traits, size_t LoadFactor = 2, size_t GrowthExponent = 1>
struct linear_flat_set
{
static_assert(LoadFactor >= 2);
Expand Down Expand Up @@ -98,27 +99,28 @@ namespace til
return nullptr;
}

const auto hash = ::std::hash<T>{}(key) >> _shift;
const auto hash = Traits::hash(key) >> _shift;

for (auto i = hash;; ++i)
{
auto& slot = _map[i & _mask];
if (!slot)
if (!Traits::occupied(slot))
{
return nullptr;
}
if (slot == key) [[likely]]
if (Traits::equals(slot, key)) [[likely]]
{
return &slot;
}
}
}

// NOTE: It also does not initialize the returned slot.
// You must do that yourself in way that ensures that Traits::occupied(slot) now returns true.
// Use lookup() to check if the item already exists.
template<typename U>
std::pair<T&, bool> insert(U&& key)
std::pair<T*, bool> insert(U&& key)
{
// Putting this into the lookup path is a little pessimistic, but it
// allows us to default-construct this hashmap with a size of 0.
if (_load >= _capacity) [[unlikely]]
{
_bumpSize();
Expand All @@ -129,20 +131,20 @@ namespace til
// many times in literature that such a scheme performs the best on average.
// As such, we perform the divide here to get the topmost bits down.
// See flat_set_hash_integer.
const auto hash = ::std::hash<T>{}(key) >> _shift;
const auto hash = Traits::hash(key) >> _shift;

for (auto i = hash;; ++i)
{
auto& slot = _map[i & _mask];
if (!slot)
if (!Traits::occupied(slot))
{
slot = std::forward<U>(key);
_load += LoadFactor;
return { slot, true };
Traits::assign(slot, key);
return { &slot, true };
}
if (slot == key) [[likely]]
if (Traits::equals(slot, key)) [[likely]]
{
return { slot, false };
return { &slot, false };
}
}
}
Expand All @@ -166,17 +168,17 @@ namespace til
// This mirrors the insert() function, but without the lookup part.
for (auto& oldSlot : container())
{
if (!oldSlot)
if (!Traits::occupied(oldSlot))
{
continue;
}

const auto hash = ::std::hash<T>{}(oldSlot) >> newShift;
const auto hash = Traits::hash(oldSlot) >> newShift;

for (auto i = hash;; ++i)
{
auto& slot = newMap[i & newMask];
if (!slot)
if (!Traits::occupied(slot))
{
slot = std::move_if_noexcept(oldSlot);
break;
Expand Down
13 changes: 10 additions & 3 deletions src/inc/til/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,28 @@ namespace til
inline constexpr wchar_t UNICODE_REPLACEMENT = 0xFFFD;
}

static constexpr bool is_surrogate(const wchar_t wch) noexcept
constexpr bool is_surrogate(const auto wch) noexcept
{
return (wch & 0xF800) == 0xD800;
}

static constexpr bool is_leading_surrogate(const wchar_t wch) noexcept
constexpr bool is_leading_surrogate(const auto wch) noexcept
{
return (wch & 0xFC00) == 0xD800;
}

static constexpr bool is_trailing_surrogate(const wchar_t wch) noexcept
constexpr bool is_trailing_surrogate(const auto wch) noexcept
{
return (wch & 0xFC00) == 0xDC00;
}

constexpr char32_t combine_surrogates(const auto lead, const auto trail)
{
// Ah, I love these bracketed C-style casts. I use them in C all the time. Yep.
#pragma warning(suppress : 26493) // Don't use C-style casts (type.4).
return (char32_t{ lead } << 10) - 0x35FDC00 + char32_t{ trail };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

horrifying

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i love it as long as it works

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not too bad actually if you search for 0x35FDC00 on the interwebz. You'll find tons of results of this exact pattern. :)

}

// Verifies the beginning of the given UTF16 string and returns the first UTF16 sequence
// or U+FFFD otherwise. It's not really useful and at the time of writing only a
// single caller uses this. It's best to delete this if you read this comment.
Expand Down
5 changes: 4 additions & 1 deletion src/propslib/RegistrySerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ const RegistrySerialization::_RegPropertyMap RegistrySerialization::s_PropertyMa
{ _RegPropertyType::Boolean, CONSOLE_REGISTRY_INTERCEPTCOPYPASTE, SET_FIELD_AND_SIZE(_fInterceptCopyPaste) },
{ _RegPropertyType::Boolean, CONSOLE_REGISTRY_TERMINALSCROLLING, SET_FIELD_AND_SIZE(_TerminalScrolling) },
{ _RegPropertyType::Dword, CONSOLE_REGISTRY_USEDX, SET_FIELD_AND_SIZE(_fUseDx) },
{ _RegPropertyType::Boolean, CONSOLE_REGISTRY_COPYCOLOR, SET_FIELD_AND_SIZE(_fCopyColor) }
{ _RegPropertyType::Boolean, CONSOLE_REGISTRY_COPYCOLOR, SET_FIELD_AND_SIZE(_fCopyColor) },
#if TIL_FEATURE_CONHOSTATLASENGINE_ENABLED
{ _RegPropertyType::Boolean, L"EnableBuiltinGlyphs", SET_FIELD_AND_SIZE(_fEnableBuiltinGlyphs) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

#endif

// Special cases that are handled manually in Registry::LoadFromRegistry:
// - CONSOLE_REGISTRY_WINDOWPOS
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/atlas/AtlasEngine.api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ CATCH_RETURN()
/* fontStyle */ DWRITE_FONT_STYLE_NORMAL,
/* fontStretch */ DWRITE_FONT_STRETCH_NORMAL,
/* fontSize */ _api.s->font->fontSize,
/* localeName */ L"",
/* textFormat */ textFormat.put()));
/* localeName */ _p.userLocaleName.c_str(),
/* textFormat */ textFormat.addressof()));

wil::com_ptr<IDWriteTextLayout> textLayout;
RETURN_IF_FAILED(_p.dwriteFactory->CreateTextLayout(glyph.data(), gsl::narrow_cast<uint32_t>(glyph.size()), textFormat.get(), FLT_MAX, FLT_MAX, textLayout.addressof()));
Expand Down Expand Up @@ -774,5 +774,7 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo
fontMetrics->doubleUnderline[0] = { doubleUnderlinePosTopU16, thinLineWidthU16 };
fontMetrics->doubleUnderline[1] = { doubleUnderlinePosBottomU16, thinLineWidthU16 };
fontMetrics->overline = { 0, underlineWidthU16 };

fontMetrics->builtinGlyphs = fontInfoDesired.GetEnableBuiltinGlyphs();
}
}
Loading
Loading