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 1 commit
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();

_customGlyphs = _settings->CustomGlyphs();
_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.SetCustomGlyphs(_customGlyphs);
_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 _customGlyphs = 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 CustomGlyphs { 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(), CustomGlyphs);

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, CustomGlyphs);

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>

<!-- Retro Terminal Effect -->
lhecker marked this conversation as resolved.
Show resolved Hide resolved
<local:SettingContainer x:Uid="Profile_CustomGlyphs"
ClearSettingValue="{x:Bind Appearance.ClearCustomGlyphs}"
HasSettingValue="{x:Bind Appearance.HasCustomGlyphs, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.CustomGlyphsOverrideSource, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind Appearance.CustomGlyphs, 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_CustomGlyphs.Header" xml:space="preserve">
<value>Custom 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_CustomGlyphs.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_CustomGlyphs" 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, CustomGlyphs);
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, CustomGlyphs, "customGlyphs", true) \
Copy link
Member

Choose a reason for hiding this comment

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

We may want to call this compatibility.integratedDrawingGlyphs or something - IMO and of course open to discussion!

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively we could call them "integrated pseudographics" or "builtin semigraphics". apparently those (pseudo/semigraphics) are names for these glyphs

Copy link
Contributor

Choose a reason for hiding this comment

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

Feature label: Built-in Glyphs
Help text: "Use built-in glyphs for BoxDrawing, BlockElement and Powerline characters"

I think this fits well with the future plan where we would draw them even when the font itself may not come with any of those glyphs (Eg. unpatched fonts)

Copy link
Member

Choose a reason for hiding this comment

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

I'm mostly worried about the JSON name - where there is no help text and "glyphs" is awfully broad (there are a looooottt of glyphs in a font!)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm opposed to renaming this setting for 2 reasons:

  • wezterm calls it custom_block_glyphs
  • VS Code calls it terminal.integrated.customGlyphs

So while I agree that we should call it "integrated glyphs" I think consistency with other applications is more important to make it easier for users to find related settings in related applications.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW that's for "vscode's integrated terminal", not for "integrated custom glyphs"

That's fair, however.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In case you're still considering other names, I think both Alacritty and Contour use something like builtin_box_drawing for this option (as a sub setting of the font configuration).

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();
_CustomGlyphs = fontInfo.CustomGlyphs();
_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, CustomGlyphs, 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, CustomGlyphs, true) \
X(winrt::hstring, CellWidth) \
X(winrt::hstring, CellHeight) \
X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \
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
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->customGlyphs = fontInfoDesired.GetCustomGlyphs();
}
}
Loading
Loading