Skip to content

Commit

Permalink
Add support for turning off full-color Emoji (#16871)
Browse files Browse the repository at this point in the history
This pull request introduces support for disabling full-color emoji (and
technically other COLR-related font features!)

Full-color emoji don't respond to SGR colors, intensity, faint or blink.
Some users also just prefer the line art ones.

Related to #15979
Refs #1790
Closes #956
  • Loading branch information
DHowett authored Mar 15, 2024
1 parent 566b660 commit c3ab2fb
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto lock = _terminal->LockForWriting();

_builtinGlyphs = _settings->EnableBuiltinGlyphs();
_colorGlyphs = _settings->EnableColorGlyphs();
_cellWidth = CSSLengthPercentage::FromString(_settings->CellWidth().c_str());
_cellHeight = CSSLengthPercentage::FromString(_settings->CellHeight().c_str());
_runtimeOpacity = std::nullopt;
Expand Down Expand Up @@ -1042,6 +1043,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_actualFontFaceName = { fontFace };

_desiredFont.SetEnableBuiltinGlyphs(_builtinGlyphs);
_desiredFont.SetEnableColorGlyphs(_colorGlyphs);
_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 @@ -317,6 +317,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
FontInfo _actualFont;
winrt::hstring _actualFontFaceName;
bool _builtinGlyphs = true;
bool _colorGlyphs = 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 @@ -42,6 +42,7 @@ namespace Microsoft.Terminal.Control
Windows.Foundation.Collections.IMap<String, UInt32> FontFeatures { get; };
Windows.Foundation.Collections.IMap<String, Single> FontAxes { get; };
Boolean EnableBuiltinGlyphs { get; };
Boolean EnableColorGlyphs { 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 @@ -151,6 +151,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontAxes);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontFeatures);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), EnableBuiltinGlyphs);
OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), EnableColorGlyphs);

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 @@ -80,6 +80,7 @@ namespace Microsoft.Terminal.Settings.Editor
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(Boolean, EnableColorGlyphs);

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 @@ -423,6 +423,15 @@
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>

<!-- Color Glyphs -->
<local:SettingContainer x:Uid="Profile_EnableColorGlyphs"
ClearSettingValue="{x:Bind Appearance.ClearEnableColorGlyphs}"
HasSettingValue="{x:Bind Appearance.HasEnableColorGlyphs, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.EnableColorGlyphsOverrideSource, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind Appearance.EnableColorGlyphs, 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 @@ -914,6 +914,14 @@
<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_EnableColorGlyphs.Header" xml:space="preserve">
<value>Full-color Emoji</value>
<comment>The main label of a toggle. When enabled, certain characters (emoji in this case) are displayed with multiple colors.</comment>
</data>
<data name="Profile_EnableColorGlyphs.HelpText" xml:space="preserve">
<value>When enabled, Emoji are displayed in full color.</value>
<comment>A longer description of the "Profile_EnableColorGlyphs" toggle.</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 @@ -21,6 +21,7 @@ namespace Microsoft.Terminal.Settings.Model
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(Boolean, EnableColorGlyphs);
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 @@ -114,6 +114,7 @@ Author(s):
X(IFontAxesMap, FontAxes, "axes") \
X(IFontFeatureMap, FontFeatures, "features") \
X(bool, EnableBuiltinGlyphs, "builtinGlyphs", true) \
X(bool, EnableColorGlyphs, "colorGlyphs", 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 @@ -291,6 +291,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_FontFeatures = fontInfo.FontFeatures();
_FontAxes = fontInfo.FontAxes();
_EnableBuiltinGlyphs = fontInfo.EnableBuiltinGlyphs();
_EnableColorGlyphs = fontInfo.EnableColorGlyphs();
_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 @@ -130,6 +130,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::TerminalSettings, IFontAxesMap, FontAxes);
INHERITABLE_SETTING(Model::TerminalSettings, IFontFeatureMap, FontFeatures);
INHERITABLE_SETTING(Model::TerminalSettings, bool, EnableBuiltinGlyphs, true);
INHERITABLE_SETTING(Model::TerminalSettings, bool, EnableColorGlyphs, 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 @@ -65,6 +65,7 @@
X(IFontFeatureMap, FontFeatures) \
X(IFontAxesMap, FontAxes) \
X(bool, EnableBuiltinGlyphs, true) \
X(bool, EnableColorGlyphs, true) \
X(winrt::hstring, CellWidth) \
X(winrt::hstring, CellHeight) \
X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \
Expand Down
1 change: 1 addition & 0 deletions src/renderer/atlas/AtlasEngine.api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,5 +794,6 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo
fontMetrics->overline = { 0, underlineWidthU16 };

fontMetrics->builtinGlyphs = fontInfoDesired.GetEnableBuiltinGlyphs();
fontMetrics->colorGlyphs = fontInfoDesired.GetEnableColorGlyphs();
}
}
8 changes: 7 additions & 1 deletion src/renderer/atlas/BackendD2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,14 @@ void BackendD2D::_drawText(RenderingPayload& p)
if (glyphRun.fontFace)
{
D2D1_RECT_F bounds = GlyphRunEmptyBounds;
wil::com_ptr<IDWriteColorGlyphRunEnumerator1> enumerator;

if (const auto enumerator = TranslateColorGlyphRun(p.dwriteFactory4.get(), baselineOrigin, &glyphRun))
if (p.s->font->colorGlyphs)
{
enumerator = TranslateColorGlyphRun(p.dwriteFactory4.get(), baselineOrigin, &glyphRun);
}

if (enumerator)
{
while (ColorGlyphRunMoveNext(enumerator.get()))
{
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/atlas/BackendD3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,12 @@ BackendD3D::AtlasGlyphEntry* BackendD3D::_drawGlyph(const RenderingPayload& p, c
});

{
const auto enumerator = TranslateColorGlyphRun(p.dwriteFactory4.get(), {}, &glyphRun);
wil::com_ptr<IDWriteColorGlyphRunEnumerator1> enumerator;

if (p.s->font->colorGlyphs)
{
enumerator = TranslateColorGlyphRun(p.dwriteFactory4.get(), {}, &glyphRun);
}

if (!enumerator)
{
Expand Down
1 change: 1 addition & 0 deletions src/renderer/atlas/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ namespace Microsoft::Console::Render::Atlas
u16 dpi = 96;
AntialiasingMode antialiasingMode = DefaultAntialiasingMode;
bool builtinGlyphs = false;
bool colorGlyphs = true;

std::vector<uint16_t> softFontPattern;
til::size softFontCellSize;
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/base/FontInfoDesired.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ void FontInfoDesired::SetEnableBuiltinGlyphs(bool builtinGlyphs) noexcept
_builtinGlyphs = builtinGlyphs;
}

void FontInfoDesired::SetEnableColorGlyphs(bool colorGlyphs) noexcept
{
_colorGlyphs = colorGlyphs;
}

const CSSLengthPercentage& FontInfoDesired::GetCellWidth() const noexcept
{
return _cellWidth;
Expand All @@ -49,6 +54,11 @@ bool FontInfoDesired::GetEnableBuiltinGlyphs() const noexcept
return _builtinGlyphs;
}

bool FontInfoDesired::GetEnableColorGlyphs() const noexcept
{
return _colorGlyphs;
}

float FontInfoDesired::GetFontSize() const noexcept
{
return _fontSize;
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/inc/FontInfoDesired.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class FontInfoDesired : public FontInfoBase

void SetCellSize(const CSSLengthPercentage& cellWidth, const CSSLengthPercentage& cellHeight) noexcept;
void SetEnableBuiltinGlyphs(bool builtinGlyphs) noexcept;
void SetEnableColorGlyphs(bool colorGlyphs) noexcept;

const CSSLengthPercentage& GetCellWidth() const noexcept;
const CSSLengthPercentage& GetCellHeight() const noexcept;
bool GetEnableBuiltinGlyphs() const noexcept;
bool GetEnableColorGlyphs() const noexcept;
float GetFontSize() const noexcept;
til::size GetEngineSize() const noexcept;
bool IsDefaultRasterFont() const noexcept;
Expand All @@ -50,4 +52,5 @@ class FontInfoDesired : public FontInfoBase
CSSLengthPercentage _cellWidth;
CSSLengthPercentage _cellHeight;
bool _builtinGlyphs = false;
bool _colorGlyphs = true;
};

0 comments on commit c3ab2fb

Please sign in to comment.