Skip to content

Commit

Permalink
Fix font axes/features settings UI (#17164)
Browse files Browse the repository at this point in the history
Due to #16821 everything about #16104 broke. This PR rights the wrongs
by rewriting all the `Font`-based code to not use `Font` at all.
Instead we split the font spec once into font families, do a lot of
complex logic to split font axes/features into used and unused ones
and construct all the UI elements. So. much. boilerplate. code.

Closes #16943

## Validation Steps Performed
There are more edge cases than I can list here... Some ideas:
* Edit the settings.json with invalid axis/feature keys ✅
* ...out of range values ✅
* Settings UI reloads when the settings.json changes ✅
* Adding axes/features works ✅
* Removing axes/features works ✅
* Resetting axes/features works ✅
* Axes/features apply in the renderer when saving ✅
  • Loading branch information
lhecker authored May 1, 2024
1 parent 77087e6 commit d380394
Show file tree
Hide file tree
Showing 22 changed files with 798 additions and 956 deletions.
4 changes: 2 additions & 2 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
"description": "Sets the DWrite font features for the given font. For example, { \"ss01\": 1, \"liga\":0 } will enable ss01 and disable ligatures.",
"type": "object",
"patternProperties": {
"^(([A-Za-z0-9]){4})$": {
"^[\\x20-\\x7E]{4}$": {
"type": "integer"
}
},
Expand All @@ -359,7 +359,7 @@
"description": "Sets the DWrite font axes for the given font. For example, { \"wght\": 200 } will set the font weight to 200.",
"type": "object",
"patternProperties": {
"^([A-Za-z]{4})$": {
"^[\\x20-\\x7E]{4}$": {
"type": "number"
}
},
Expand Down
31 changes: 14 additions & 17 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,26 +959,23 @@ namespace winrt::Microsoft::Terminal::Control::implementation

if (_renderEngine)
{
std::unordered_map<std::wstring_view, uint32_t> featureMap;
if (const auto fontFeatures = _settings->FontFeatures())
{
featureMap.reserve(fontFeatures.Size());

for (const auto& [tag, param] : fontFeatures)
static constexpr auto cloneMap = [](const IFontFeatureMap& map) {
std::unordered_map<std::wstring_view, float> clone;
if (map)
{
featureMap.emplace(tag, param);
clone.reserve(map.Size());
for (const auto& [tag, param] : map)
{
clone.emplace(tag, param);
}
}
}
std::unordered_map<std::wstring_view, float> axesMap;
if (const auto fontAxes = _settings->FontAxes())
{
axesMap.reserve(fontAxes.Size());
return clone;
};

for (const auto& [axis, value] : fontAxes)
{
axesMap.emplace(axis, value);
}
}
const auto fontFeatures = _settings->FontFeatures();
const auto fontAxes = _settings->FontAxes();
const auto featureMap = cloneMap(fontFeatures);
const auto axesMap = cloneMap(fontAxes);

// TODO: MSFT:20895307 If the font doesn't exist, this doesn't
// actually fail. We need a way to gracefully fallback.
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Licensed under the MIT license.
#include <conattrs.hpp>
#include "ControlAppearance.h"

using IFontFeatureMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, uint32_t>;
using IFontFeatureMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, float>;
using IFontAxesMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, float>;

namespace winrt::Microsoft::Terminal::Control::implementation
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Microsoft.Terminal.Control
Single FontSize { get; };
Windows.UI.Text.FontWeight FontWeight { get; };
String Padding { get; };
Windows.Foundation.Collections.IMap<String, UInt32> FontFeatures { get; };
Windows.Foundation.Collections.IMap<String, Single> FontFeatures { get; };
Windows.Foundation.Collections.IMap<String, Single> FontAxes { get; };
Boolean EnableBuiltinGlyphs { get; };
Boolean EnableColorGlyphs { get; };
Expand Down
Loading

0 comments on commit d380394

Please sign in to comment.