From f4a3027ade4e824063a77ca616ca32cb54203fab Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 15 Jun 2021 10:22:32 -0700 Subject: [PATCH 01/12] initial --- .../TerminalSettingsEditor/Profiles.h | 6 +- .../CascadiaSettings.cpp | 14 +++- .../TerminalSettingsModel/FontConfig.cpp | 64 +++++++++++++++++++ .../TerminalSettingsModel/FontConfig.h | 34 ++++++++++ .../TerminalSettingsModel/FontConfig.idl | 20 ++++++ ...crosoft.Terminal.Settings.ModelLib.vcxproj | 7 ++ ...Terminal.Settings.ModelLib.vcxproj.filters | 1 + .../TerminalSettingsModel/Profile.cpp | 49 ++++++++++---- src/cascadia/TerminalSettingsModel/Profile.h | 6 +- .../TerminalSettingsModel/Profile.idl | 6 +- .../TerminalSettings.cpp | 6 +- 11 files changed, 184 insertions(+), 29 deletions(-) create mode 100644 src/cascadia/TerminalSettingsModel/FontConfig.cpp create mode 100644 src/cascadia/TerminalSettingsModel/FontConfig.h create mode 100644 src/cascadia/TerminalSettingsModel/FontConfig.idl diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.h b/src/cascadia/TerminalSettingsEditor/Profiles.h index 90fe6535115..6faca8cbd76 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.h +++ b/src/cascadia/TerminalSettingsEditor/Profiles.h @@ -77,9 +77,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation OBSERVABLE_PROJECTED_SETTING(_profile, UseAcrylic); OBSERVABLE_PROJECTED_SETTING(_profile, AcrylicOpacity); OBSERVABLE_PROJECTED_SETTING(_profile, ScrollState); - OBSERVABLE_PROJECTED_SETTING(_profile, FontFace); - OBSERVABLE_PROJECTED_SETTING(_profile, FontSize); - OBSERVABLE_PROJECTED_SETTING(_profile, FontWeight); + OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontFace); + OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontSize); + OBSERVABLE_PROJECTED_SETTING(_profile.FontInfo(), FontWeight); OBSERVABLE_PROJECTED_SETTING(_profile, Padding); OBSERVABLE_PROJECTED_SETTING(_profile, Commandline); OBSERVABLE_PROJECTED_SETTING(_profile, StartingDirectory); diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 5e45159e7b0..7d355cc814a 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -303,6 +303,13 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate duplicated->##settingName(source.##settingName()); \ } +#define DUPLICATE_FONT_SETTING_MACRO(settingName) \ + if (source.FontInfo().Has##settingName() || \ + (source.FontInfo().##settingName##OverrideSource() != nullptr && source.FontInfo().##settingName##OverrideSource().SourceProfile().Origin() != OriginTag::ProfilesDefaults)) \ + { \ + duplicated->FontInfo().##settingName(source.FontInfo().##settingName()); \ + } + #define DUPLICATE_APPEARANCE_SETTING_MACRO(settingName) \ if (source.DefaultAppearance().Has##settingName() || \ (source.DefaultAppearance().##settingName##OverrideSource() != nullptr && source.DefaultAppearance().##settingName##OverrideSource().SourceProfile().Origin() != OriginTag::ProfilesDefaults)) \ @@ -319,9 +326,6 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate DUPLICATE_SETTING_MACRO(UseAcrylic); DUPLICATE_SETTING_MACRO(AcrylicOpacity); DUPLICATE_SETTING_MACRO(ScrollState); - DUPLICATE_SETTING_MACRO(FontFace); - DUPLICATE_SETTING_MACRO(FontSize); - DUPLICATE_SETTING_MACRO(FontWeight); DUPLICATE_SETTING_MACRO(Padding); DUPLICATE_SETTING_MACRO(Commandline); DUPLICATE_SETTING_MACRO(StartingDirectory); @@ -333,6 +337,10 @@ winrt::Microsoft::Terminal::Settings::Model::Profile CascadiaSettings::Duplicate DUPLICATE_SETTING_MACRO(AltGrAliasing); DUPLICATE_SETTING_MACRO(BellStyle); + DUPLICATE_FONT_SETTING_MACRO(FontFace); + DUPLICATE_FONT_SETTING_MACRO(FontSize); + DUPLICATE_FONT_SETTING_MACRO(FontWeight); + DUPLICATE_APPEARANCE_SETTING_MACRO(ColorSchemeName); DUPLICATE_APPEARANCE_SETTING_MACRO(Foreground); DUPLICATE_APPEARANCE_SETTING_MACRO(Background); diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp new file mode 100644 index 00000000000..5d0949992ae --- /dev/null +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "FontConfig.h" +#include "FontConfig.g.cpp" +#include "TerminalSettingsSerializationHelpers.h" +#include "JsonUtils.h" + +using namespace Microsoft::Terminal::Settings::Model; +using namespace winrt::Microsoft::Terminal::Settings::Model::implementation; + +static constexpr std::string_view FontFaceKey{ "fontFace" }; +static constexpr std::string_view FontSizeKey{ "fontSize" }; +static constexpr std::string_view FontWeightKey{ "fontWeight" }; + +winrt::Microsoft::Terminal::Settings::Model::implementation::FontConfig::FontConfig(const winrt::weak_ref sourceProfile) : + _sourceProfile(sourceProfile) +{ +} + +winrt::com_ptr FontConfig::CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile) +{ + auto fontInfo{ winrt::make_self(sourceProfile) }; + auto const sourceFontInfo = source.try_as(); + fontInfo->_FontFace = sourceFontInfo->_FontFace; + fontInfo->_FontSize = sourceFontInfo->_FontSize; + fontInfo->_FontWeight = sourceFontInfo->_FontWeight; + return fontInfo; +} + +Json::Value FontConfig::ToJson() const +{ + Json::Value json{ Json::ValueType::objectValue }; + + JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace); + JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize); + JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight); + + return json; +} + +// Method Description: +// - Layer values from the given json object on top of the existing properties +// of this object. For any keys we're expecting to be able to parse in the +// given object, we'll parse them and replace our settings with values from +// the new json object. Properties that _aren't_ in the json object will _not_ +// be replaced. +// - Optional values that are set to `null` in the json object +// will be set to nullopt. +// - This is similar to Profile::LayerJson but for FontConfig +// Arguments: +// - json: an object which should be a partial serialization of a FontConfig object. +void FontConfig::LayerJson(const Json::Value& json) +{ + JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); + JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); + JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); +} + +winrt::Microsoft::Terminal::Settings::Model::Profile FontConfig::SourceProfile() +{ + return _sourceProfile.get(); +} diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.h b/src/cascadia/TerminalSettingsModel/FontConfig.h new file mode 100644 index 00000000000..f2c5b2b6981 --- /dev/null +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -0,0 +1,34 @@ +/*++ +Copyright (c) Microsoft Corporation +Licensed under the MIT license. +--*/ + +#pragma once + +#include "pch.h" +#include "FontConfig.g.h" +#include "JsonUtils.h" +#include "../inc/cppwinrt_utils.h" +#include "IInheritable.h" +#include + +namespace winrt::Microsoft::Terminal::Settings::Model::implementation +{ + struct FontConfig : FontConfigT, IInheritable + { + public: + FontConfig(const winrt::weak_ref sourceProfile); + static winrt::com_ptr CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile); + Json::Value ToJson() const; + void LayerJson(const Json::Value& json); + + Model::Profile SourceProfile(); + + INHERITABLE_SETTING(Model::FontConfig, hstring, FontFace, DEFAULT_FONT_FACE); + INHERITABLE_SETTING(Model::FontConfig, int32_t, FontSize, DEFAULT_FONT_SIZE); + INHERITABLE_SETTING(Model::FontConfig, Windows::UI::Text::FontWeight, FontWeight, DEFAULT_FONT_WEIGHT); + + private: + winrt::weak_ref _sourceProfile; + }; +} diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.idl b/src/cascadia/TerminalSettingsModel/FontConfig.idl new file mode 100644 index 00000000000..7bca0ef119d --- /dev/null +++ b/src/cascadia/TerminalSettingsModel/FontConfig.idl @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "Profile.idl"; +#include "IInheritable.idl.h" + +#define INHERITABLE_FONT_SETTING(Type, Name) \ + _BASE_INHERITABLE_SETTING(Type, Name); \ + Microsoft.Terminal.Settings.Model.FontConfig Name##OverrideSource { get; } + +namespace Microsoft.Terminal.Settings.Model +{ + [default_interface] runtimeclass FontConfig { + Microsoft.Terminal.Settings.Model.Profile SourceProfile { get; }; + + INHERITABLE_FONT_SETTING(String, FontFace); + INHERITABLE_FONT_SETTING(Int32, FontSize); + INHERITABLE_FONT_SETTING(Windows.UI.Text.FontWeight, FontWeight); + } +} diff --git a/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj b/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj index c2b645bd02b..30de7b307e2 100644 --- a/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj +++ b/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj @@ -59,6 +59,9 @@ AppearanceConfig.idl + + FontConfig.idl + EnumMappings.idl @@ -123,6 +126,9 @@ AppearanceConfig.idl + + FontConfig.idl + TerminalSettings.idl @@ -154,6 +160,7 @@ + diff --git a/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters b/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters index d844a34c86d..96f2615ed2b 100644 --- a/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters +++ b/src/cascadia/TerminalSettingsModel/Microsoft.Terminal.Settings.ModelLib.vcxproj.filters @@ -82,6 +82,7 @@ + diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index c3cb73774f2..7ef45ba6936 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -10,6 +10,7 @@ #include "LegacyProfileGeneratorNamespaces.h" #include "TerminalSettingsSerializationHelpers.h" #include "AppearanceConfig.h" +#include "FontConfig.h" #include "Profile.g.cpp" @@ -34,9 +35,7 @@ static constexpr std::string_view AltGrAliasingKey{ "altGrAliasing" }; static constexpr std::string_view ConnectionTypeKey{ "connectionType" }; static constexpr std::string_view CommandlineKey{ "commandline" }; -static constexpr std::string_view FontFaceKey{ "fontFace" }; -static constexpr std::string_view FontSizeKey{ "fontSize" }; -static constexpr std::string_view FontWeightKey{ "fontWeight" }; +static constexpr std::string_view FontInfoKey{ "font" }; static constexpr std::string_view AcrylicTransparencyKey{ "acrylicOpacity" }; static constexpr std::string_view UseAcrylicKey{ "useAcrylic" }; static constexpr std::string_view ScrollbarStateKey{ "scrollbarState" }; @@ -76,9 +75,6 @@ winrt::com_ptr Profile::CopySettings(winrt::com_ptr source) profile->_UseAcrylic = source->_UseAcrylic; profile->_AcrylicOpacity = source->_AcrylicOpacity; profile->_ScrollState = source->_ScrollState; - profile->_FontFace = source->_FontFace; - profile->_FontSize = source->_FontSize; - profile->_FontWeight = source->_FontWeight; profile->_Padding = source->_Padding; profile->_Commandline = source->_Commandline; profile->_StartingDirectory = source->_StartingDirectory; @@ -92,8 +88,14 @@ winrt::com_ptr Profile::CopySettings(winrt::com_ptr source) profile->_ConnectionType = source->_ConnectionType; profile->_Origin = source->_Origin; - // Copy over the appearance + // Copy over the font info const auto weakRefToProfile = weak_ref(*profile); + winrt::com_ptr sourceFontInfoImpl; + sourceFontInfoImpl.copy_from(winrt::get_self(source->_FontInfo)); + auto copiedFontInfo = FontConfig::CopyFontInfo(sourceFontInfoImpl, weakRefToProfile); + profile->_FontInfo = *copiedFontInfo; + + // Copy over the appearance winrt::com_ptr sourceDefaultAppearanceImpl; sourceDefaultAppearanceImpl.copy_from(winrt::get_self(source->_DefaultAppearance)); auto copiedDefaultAppearance = AppearanceConfig::CopyAppearance(sourceDefaultAppearanceImpl, weakRefToProfile); @@ -315,6 +317,10 @@ void Profile::LayerJson(const Json::Value& json) auto defaultAppearanceImpl = winrt::get_self(_DefaultAppearance); defaultAppearanceImpl->LayerJson(json); + // Font Settings + auto fontInfoImpl = winrt::get_self(_FontInfo); + fontInfoImpl->LayerJson(json); + // Profile-specific Settings JsonUtils::GetValueForKey(json, NameKey, _Name); JsonUtils::GetValueForKey(json, GuidKey, _Guid); @@ -327,12 +333,9 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, AltGrAliasingKey, _AltGrAliasing); JsonUtils::GetValueForKey(json, TabTitleKey, _TabTitle); - // Control Settings - JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); + // Control Settings JsonUtils::GetValueForKey(json, ConnectionTypeKey, _ConnectionType); JsonUtils::GetValueForKey(json, CommandlineKey, _Commandline); - JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); - JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); JsonUtils::GetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity); JsonUtils::GetValueForKey(json, UseAcrylicKey, _UseAcrylic); JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle); @@ -392,6 +395,19 @@ void Profile::_FinalizeInheritance() } } } + if (auto fontInfoImpl = get_self(_FontInfo)) + { + // Clear any existing parents first, we don't want duplicates from any previous + // calls to this function + fontInfoImpl->ClearParents(); + for (auto& parent : _parents) + { + if (auto parentFontInfoImpl = parent->_FontInfo.try_as()) + { + fontInfoImpl->InsertParent(parentFontInfoImpl); + } + } + } } winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig Profile::DefaultAppearance() @@ -399,6 +415,11 @@ winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig Profile::DefaultA return _DefaultAppearance; } +winrt::Microsoft::Terminal::Settings::Model::FontConfig Profile::FontInfo() +{ + return _FontInfo; +} + // Method Description: // - Helper function for expanding any environment variables in a user-supplied starting directory and validating the resulting path // Arguments: @@ -510,11 +531,8 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, TabTitleKey, _TabTitle); // Control Settings - JsonUtils::SetValueForKey(json, FontWeightKey, _FontWeight); JsonUtils::SetValueForKey(json, ConnectionTypeKey, _ConnectionType); JsonUtils::SetValueForKey(json, CommandlineKey, _Commandline); - JsonUtils::SetValueForKey(json, FontFaceKey, _FontFace); - JsonUtils::SetValueForKey(json, FontSizeKey, _FontSize); JsonUtils::SetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity); JsonUtils::SetValueForKey(json, UseAcrylicKey, _UseAcrylic); JsonUtils::SetValueForKey(json, SuppressApplicationTitleKey, _SuppressApplicationTitle); @@ -530,6 +548,9 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, TabColorKey, _TabColor); JsonUtils::SetValueForKey(json, BellStyleKey, _BellStyle); + // Font settings + json[JsonKey(FontInfoKey)] = winrt::get_self(_FontInfo)->ToJson(); + if (_UnfocusedAppearance) { json[JsonKey(UnfocusedAppearanceKey)] = winrt::get_self(_UnfocusedAppearance.value())->ToJson(); diff --git a/src/cascadia/TerminalSettingsModel/Profile.h b/src/cascadia/TerminalSettingsModel/Profile.h index 82e837db254..d61c35308c4 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.h +++ b/src/cascadia/TerminalSettingsModel/Profile.h @@ -51,6 +51,7 @@ Author(s): #include "JsonUtils.h" #include #include "AppearanceConfig.h" +#include "FontConfig.h" // fwdecl unittest classes namespace SettingsModelLocalTests @@ -98,6 +99,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static guid GetGuidOrGenerateForJson(const Json::Value& json) noexcept; Model::IAppearanceConfig DefaultAppearance(); + Model::FontConfig FontInfo(); void _FinalizeInheritance() override; @@ -121,9 +123,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, double, AcrylicOpacity, 0.5); INHERITABLE_SETTING(Model::Profile, Microsoft::Terminal::Control::ScrollbarState, ScrollState, Microsoft::Terminal::Control::ScrollbarState::Visible); - INHERITABLE_SETTING(Model::Profile, hstring, FontFace, DEFAULT_FONT_FACE); - INHERITABLE_SETTING(Model::Profile, int32_t, FontSize, DEFAULT_FONT_SIZE); - INHERITABLE_SETTING(Model::Profile, Windows::UI::Text::FontWeight, FontWeight, DEFAULT_FONT_WEIGHT); INHERITABLE_SETTING(Model::Profile, hstring, Padding, DEFAULT_PADDING); INHERITABLE_SETTING(Model::Profile, hstring, Commandline, L"cmd.exe"); @@ -143,6 +142,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation private: Model::IAppearanceConfig _DefaultAppearance{ winrt::make(weak_ref(*this)) }; + Model::FontConfig _FontInfo{ winrt::make(weak_ref(*this)) }; static std::wstring EvaluateStartingDirectory(const std::wstring& directory); static guid _GenerateGuidForProfile(const hstring& name, const hstring& source) noexcept; diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index ceee66d5a44..3015c5119d2 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -2,6 +2,7 @@ // Licensed under the MIT license. import "IAppearanceConfig.idl"; +import "FontConfig.idl"; #include "IInheritable.idl.h" #define INHERITABLE_PROFILE_SETTING(Type, Name) \ @@ -62,15 +63,14 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_PROFILE_SETTING(Boolean, UseAcrylic); INHERITABLE_PROFILE_SETTING(Double, AcrylicOpacity); INHERITABLE_PROFILE_SETTING(Microsoft.Terminal.Control.ScrollbarState, ScrollState); - INHERITABLE_PROFILE_SETTING(String, FontFace); - INHERITABLE_PROFILE_SETTING(Int32, FontSize); - INHERITABLE_PROFILE_SETTING(Windows.UI.Text.FontWeight, FontWeight); INHERITABLE_PROFILE_SETTING(String, Padding); INHERITABLE_PROFILE_SETTING(String, Commandline); INHERITABLE_PROFILE_SETTING(String, StartingDirectory); String EvaluatedStartingDirectory { get; }; + FontConfig FontInfo { get; }; + IAppearanceConfig DefaultAppearance { get; }; INHERITABLE_PROFILE_SETTING(IAppearanceConfig, UnfocusedAppearance); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 19ddf5e1576..de0047be2f3 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -260,9 +260,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _UseAcrylic = profile.UseAcrylic(); _TintOpacity = profile.AcrylicOpacity(); - _FontFace = profile.FontFace(); - _FontSize = profile.FontSize(); - _FontWeight = profile.FontWeight(); + _FontFace = profile.FontInfo().FontFace(); + _FontSize = profile.FontInfo().FontSize(); + _FontWeight = profile.FontInfo().FontWeight(); _Padding = profile.Padding(); _Commandline = profile.Commandline(); From 50b595dd3efbf62f7313cc683004cbd4773c8c11 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 15 Jun 2021 13:56:24 -0700 Subject: [PATCH 02/12] complete --- .../TerminalSettingsModel/FontConfig.cpp | 21 ++++++++++++++++--- .../TerminalSettings.cpp | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index 5d0949992ae..418f4af1e8c 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -10,6 +10,7 @@ using namespace Microsoft::Terminal::Settings::Model; using namespace winrt::Microsoft::Terminal::Settings::Model::implementation; +static constexpr std::string_view FontInfoKey{ "font" }; static constexpr std::string_view FontFaceKey{ "fontFace" }; static constexpr std::string_view FontSizeKey{ "fontSize" }; static constexpr std::string_view FontWeightKey{ "fontWeight" }; @@ -53,9 +54,23 @@ Json::Value FontConfig::ToJson() const // - json: an object which should be a partial serialization of a FontConfig object. void FontConfig::LayerJson(const Json::Value& json) { - JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); - JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); - JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); + // Legacy users may not have a font object defined in their profile, + // so check for that before we decide how to parse this + if (json.isMember(JsonKey(FontInfoKey))) + { + // A font object is defined, use that + const auto fontInfoJson = json[JsonKey(FontInfoKey)]; + JsonUtils::GetValueForKey(fontInfoJson, FontFaceKey, _FontFace); + JsonUtils::GetValueForKey(fontInfoJson, FontSizeKey, _FontSize); + JsonUtils::GetValueForKey(fontInfoJson, FontWeightKey, _FontWeight); + } + else + { + // No font object is defined + JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); + JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); + JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); + } } winrt::Microsoft::Terminal::Settings::Model::Profile FontConfig::SourceProfile() diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index de0047be2f3..69a8bab8d16 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -82,7 +82,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation childImpl->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes()); child = *childImpl; } - + const auto face = settings->FontFace(); return winrt::make(*settings, child); } From d91275f2289ab386c2208f417bd164b12c8c76d7 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 15 Jun 2021 14:10:02 -0700 Subject: [PATCH 03/12] remove remnant --- src/cascadia/TerminalSettingsModel/TerminalSettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 69a8bab8d16..de0047be2f3 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -82,7 +82,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation childImpl->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes()); child = *childImpl; } - const auto face = settings->FontFace(); + return winrt::make(*settings, child); } From a9dd675e31cf6667e4709cada7db870309c30141 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 17 Jun 2021 11:17:44 -0700 Subject: [PATCH 04/12] change keys, update tests, add test for legacy keys --- .../SerializationTests.cpp | 52 ++++++++++++++++--- .../TerminalSettingsModel/FontConfig.cpp | 15 +++--- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp index 164ac0bb8e8..108329eb239 100644 --- a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp @@ -41,6 +41,7 @@ namespace SettingsModelLocalTests TEST_METHOD(ColorScheme); TEST_METHOD(Actions); TEST_METHOD(CascadiaSettings); + TEST_METHOD(LegacyFontSettings); TEST_CLASS_SETUP(ClassSetup) { @@ -138,9 +139,11 @@ namespace SettingsModelLocalTests "tabTitle": "Cool Tab", "suppressApplicationTitle": false, - "fontFace": "Cascadia Mono", - "fontSize": 12, - "fontWeight": "normal", + "font": { + "face": "Cascadia Mono", + "size": 12, + "weight": "normal" + }, "padding": "8, 8, 8, 8", "antialiasingMode": "grayscale", @@ -174,7 +177,8 @@ namespace SettingsModelLocalTests const std::string smallProfileString{ R"( { - "name": "Custom Profile" + "name": "Custom Profile", + "font": {} })" }; // Setting "tabColor" to null tests two things: @@ -187,6 +191,7 @@ namespace SettingsModelLocalTests "hidden": false, "tabColor": null, "foreground": null, + "font": {}, "source": "local" })" }; @@ -402,20 +407,24 @@ namespace SettingsModelLocalTests "profiles": { "defaults": { - "fontFace": "Zamora Code" + "font": { + "face": "Zamora Code" + } }, "list": [ { - "fontFace": "Cascadia Code", + "font": { "face": "Cascadia Code" }, "guid": "{61c54bbd-1111-5271-96e7-009a87ff44bf}", "name": "HowettShell" }, { "hidden": true, + "font": {}, "name": "BhojwaniShell" }, { "antialiasingMode": "aliased", + "font": {}, "name": "NiksaShell" } ] @@ -464,4 +473,35 @@ namespace SettingsModelLocalTests const auto result{ settings->ToJson() }; VERIFY_ARE_EQUAL(toString(settings->_userSettings), toString(result)); } + + void SerializationTests::LegacyFontSettings() + { + const std::string profileString{ R"( + { + "name": "Profile with legacy font settings", + + "fontFace": "Cascadia Mono", + "fontSize": 12, + "fontWeight": "normal" + })" }; + + const std::string expectedOutput{ R"( + { + "name": "Profile with legacy font settings", + + "font": { + "face": "Cascadia Mono", + "size": 12, + "weight": "normal" + } + })" }; + + const auto json{ VerifyParseSucceeded(profileString) }; + const auto settings{ implementation::Profile::FromJson(json) }; + const auto result{ settings->ToJson() }; + + const auto jsonOutput{ VerifyParseSucceeded(expectedOutput) }; + + VERIFY_ARE_EQUAL(toString(jsonOutput), toString(result)); + } } diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index 418f4af1e8c..60042ad7dbf 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -11,9 +11,12 @@ using namespace Microsoft::Terminal::Settings::Model; using namespace winrt::Microsoft::Terminal::Settings::Model::implementation; static constexpr std::string_view FontInfoKey{ "font" }; -static constexpr std::string_view FontFaceKey{ "fontFace" }; -static constexpr std::string_view FontSizeKey{ "fontSize" }; -static constexpr std::string_view FontWeightKey{ "fontWeight" }; +static constexpr std::string_view FontFaceKey{ "face" }; +static constexpr std::string_view FontSizeKey{ "size" }; +static constexpr std::string_view FontWeightKey{ "weight" }; +static constexpr std::string_view LegacyFontFaceKey{ "fontFace" }; +static constexpr std::string_view LegacyFontSizeKey{ "fontSize" }; +static constexpr std::string_view LegacyFontWeightKey{ "fontWeight" }; winrt::Microsoft::Terminal::Settings::Model::implementation::FontConfig::FontConfig(const winrt::weak_ref sourceProfile) : _sourceProfile(sourceProfile) @@ -67,9 +70,9 @@ void FontConfig::LayerJson(const Json::Value& json) else { // No font object is defined - JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); - JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); - JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); + JsonUtils::GetValueForKey(json, LegacyFontFaceKey, _FontFace); + JsonUtils::GetValueForKey(json, LegacyFontSizeKey, _FontSize); + JsonUtils::GetValueForKey(json, LegacyFontWeightKey, _FontWeight); } } From 861390c4ca8d2f243c8e24ebd6dd61e6ef6ee805 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 17 Jun 2021 11:19:46 -0700 Subject: [PATCH 05/12] abstract --- src/cascadia/TerminalSettingsModel/FontConfig.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.h b/src/cascadia/TerminalSettingsModel/FontConfig.h index f2c5b2b6981..ad1ae0e5a62 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.h +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -1,6 +1,17 @@ /*++ Copyright (c) Microsoft Corporation Licensed under the MIT license. + +Module Name: +- FontConfig + +Abstract: +- The implementation of the FontConfig winrt class. Provides settings related + to the font settings of the terminal, for the terminal control. + +Author(s): +- Pankaj Bhojwani - June 2021 + --*/ #pragma once From e72495df3de26ceb35005a1be95b14ddbcbad68a Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 18 Jun 2021 11:16:39 -0700 Subject: [PATCH 06/12] format --- src/cascadia/TerminalSettingsModel/Profile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 7ef45ba6936..95aae26c7db 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -333,7 +333,7 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, AltGrAliasingKey, _AltGrAliasing); JsonUtils::GetValueForKey(json, TabTitleKey, _TabTitle); - // Control Settings + // Control Settings JsonUtils::GetValueForKey(json, ConnectionTypeKey, _ConnectionType); JsonUtils::GetValueForKey(json, CommandlineKey, _Commandline); JsonUtils::GetValueForKey(json, AcrylicTransparencyKey, _AcrylicOpacity); From 57b22b1832df4c7a53abfd4ab2f4600356e94fd2 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 23 Jun 2021 13:41:40 -0700 Subject: [PATCH 07/12] no more empty font in json --- .../LocalTests_SettingsModel/SerializationTests.cpp | 6 +----- src/cascadia/TerminalSettingsModel/FontConfig.cpp | 5 +++++ src/cascadia/TerminalSettingsModel/FontConfig.h | 1 + src/cascadia/TerminalSettingsModel/Profile.cpp | 6 +++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp index 108329eb239..3577883f437 100644 --- a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp @@ -177,8 +177,7 @@ namespace SettingsModelLocalTests const std::string smallProfileString{ R"( { - "name": "Custom Profile", - "font": {} + "name": "Custom Profile" })" }; // Setting "tabColor" to null tests two things: @@ -191,7 +190,6 @@ namespace SettingsModelLocalTests "hidden": false, "tabColor": null, "foreground": null, - "font": {}, "source": "local" })" }; @@ -419,12 +417,10 @@ namespace SettingsModelLocalTests }, { "hidden": true, - "font": {}, "name": "BhojwaniShell" }, { "antialiasingMode": "aliased", - "font": {}, "name": "NiksaShell" } ] diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index 60042ad7dbf..94fe9ca6359 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -76,6 +76,11 @@ void FontConfig::LayerJson(const Json::Value& json) } } +bool FontConfig::HasAnyOptionSet() +{ + return HasFontFace() || HasFontSize() || HasFontWeight(); +} + winrt::Microsoft::Terminal::Settings::Model::Profile FontConfig::SourceProfile() { return _sourceProfile.get(); diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.h b/src/cascadia/TerminalSettingsModel/FontConfig.h index ad1ae0e5a62..a165b2f4bd1 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.h +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -32,6 +32,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static winrt::com_ptr CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile); Json::Value ToJson() const; void LayerJson(const Json::Value& json); + bool HasAnyOptionSet(); Model::Profile SourceProfile(); diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 95aae26c7db..9b25dad8d9c 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -549,7 +549,11 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, BellStyleKey, _BellStyle); // Font settings - json[JsonKey(FontInfoKey)] = winrt::get_self(_FontInfo)->ToJson(); + const auto fontInfoImpl = winrt::get_self(_FontInfo); + if (fontInfoImpl->HasAnyOptionSet()) + { + json[JsonKey(FontInfoKey)] = winrt::get_self(_FontInfo)->ToJson(); + } if (_UnfocusedAppearance) { From 6297d33a7cd3457df56c2d4d54fb5212ae8c5806 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 23 Jun 2021 16:21:35 -0700 Subject: [PATCH 08/12] const --- src/cascadia/TerminalSettingsModel/FontConfig.cpp | 2 +- src/cascadia/TerminalSettingsModel/FontConfig.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index 94fe9ca6359..ef8baa1c6d0 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -76,7 +76,7 @@ void FontConfig::LayerJson(const Json::Value& json) } } -bool FontConfig::HasAnyOptionSet() +bool FontConfig::HasAnyOptionSet() const { return HasFontFace() || HasFontSize() || HasFontWeight(); } diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.h b/src/cascadia/TerminalSettingsModel/FontConfig.h index a165b2f4bd1..48a5767168f 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.h +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -32,7 +32,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static winrt::com_ptr CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile); Json::Value ToJson() const; void LayerJson(const Json::Value& json); - bool HasAnyOptionSet(); + bool HasAnyOptionSet() const; Model::Profile SourceProfile(); From ca07380caa78870d4fca34210336a5c3e3e6c9de Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 24 Jun 2021 11:34:05 -0700 Subject: [PATCH 09/12] update schema --- doc/cascadia/profiles.schema.json | 86 +++++++++++++++++-------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 66e914fa9c3..f931583f579 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -165,6 +165,49 @@ }, "type": "object" }, + "FontConfig": { + "properties": { + "fontFace": { + "default": "Cascadia Mono", + "description": "Name of the font face used in the profile.", + "type": "string" + }, + "fontSize": { + "default": 12, + "description": "Size of the font in points.", + "minimum": 1, + "type": "integer" + }, + "fontWeight": { + "default": "normal", + "description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.", + "oneOf": [ + { + "enum": [ + "thin", + "extra-light", + "light", + "semi-light", + "normal", + "medium", + "semi-bold", + "bold", + "extra-bold", + "black", + "extra-black" + ], + "type": "string" + }, + { + "maximum": 990, + "minimum": 100, + "type": "integer" + } + ] + } + }, + "type": "object" + }, "ProfileGuid": { "default": "{}", "pattern": "^\\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\}$", @@ -1242,6 +1285,11 @@ "description": "Sets the appearance of the terminal when it is unfocused.", "type": ["object", "null"] }, + "font": { + "$ref": "#/definitions/FontConfig", + "description": "Sets the font options of the terminal.", + "type": ["object", "null"] + }, "backgroundImage": { "description": "Sets the file location of the image to draw over the window background.", "oneOf": [ @@ -1356,44 +1404,6 @@ "description": "Use to set a path to a pixel shader to use with the Terminal. Overrides `experimental.retroTerminalEffect`. This is an experimental feature, and its continued existence is not guaranteed.", "type": "string" }, - "fontFace": { - "default": "Cascadia Mono", - "description": "Name of the font face used in the profile.", - "type": "string" - }, - "fontSize": { - "default": 12, - "description": "Size of the font in points.", - "minimum": 1, - "type": "integer" - }, - "fontWeight": { - "default": "normal", - "description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.", - "oneOf": [ - { - "enum": [ - "thin", - "extra-light", - "light", - "semi-light", - "normal", - "medium", - "semi-bold", - "bold", - "extra-bold", - "black", - "extra-black" - ], - "type": "string" - }, - { - "maximum": 990, - "minimum": 100, - "type": "integer" - } - ] - }, "foreground": { "$ref": "#/definitions/Color", "default": "#cccccc", From 927a66b9146a1af2613a7af4e58ea11a37b49af9 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 24 Jun 2021 11:34:55 -0700 Subject: [PATCH 10/12] remove 'font' prefix --- doc/cascadia/profiles.schema.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index f931583f579..480d618e957 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -167,18 +167,18 @@ }, "FontConfig": { "properties": { - "fontFace": { + "face": { "default": "Cascadia Mono", "description": "Name of the font face used in the profile.", "type": "string" }, - "fontSize": { + "size": { "default": 12, "description": "Size of the font in points.", "minimum": 1, "type": "integer" }, - "fontWeight": { + "weight": { "default": "normal", "description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.", "oneOf": [ From b2c09159506701e6e87bb296c65fc9b033405560 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 24 Jun 2021 16:12:04 -0700 Subject: [PATCH 11/12] deprecated --- doc/cascadia/profiles.schema.json | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 480d618e957..b275eb4a4c6 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -1404,6 +1404,47 @@ "description": "Use to set a path to a pixel shader to use with the Terminal. Overrides `experimental.retroTerminalEffect`. This is an experimental feature, and its continued existence is not guaranteed.", "type": "string" }, + "fontFace": { + "default": "Cascadia Mono", + "description": "[deprecated] Define 'face' within the 'font' object instead.", + "type": "string", + "deprecated": true + }, + "fontSize": { + "default": 12, + "description": "[deprecated] Define 'size' within the 'font' object instead.", + "minimum": 1, + "type": "integer", + "deprecated": true + }, + "fontWeight": { + "default": "normal", + "description": "[deprecated] Define 'weight' within the 'font' object instead.", + "oneOf": [ + { + "enum": [ + "thin", + "extra-light", + "light", + "semi-light", + "normal", + "medium", + "semi-bold", + "bold", + "extra-bold", + "black", + "extra-black" + ], + "type": "string" + }, + { + "maximum": 990, + "minimum": 100, + "type": "integer" + } + ], + "deprecated": true + }, "foreground": { "$ref": "#/definitions/Color", "default": "#cccccc", From 73530c6173378ba4095c70440c514fa0d79854b0 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 30 Jun 2021 09:59:05 -0700 Subject: [PATCH 12/12] std::move --- src/cascadia/TerminalSettingsModel/FontConfig.cpp | 15 +++++++-------- src/cascadia/TerminalSettingsModel/FontConfig.h | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index ef8baa1c6d0..a7c22a58163 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -18,18 +18,17 @@ static constexpr std::string_view LegacyFontFaceKey{ "fontFace" }; static constexpr std::string_view LegacyFontSizeKey{ "fontSize" }; static constexpr std::string_view LegacyFontWeightKey{ "fontWeight" }; -winrt::Microsoft::Terminal::Settings::Model::implementation::FontConfig::FontConfig(const winrt::weak_ref sourceProfile) : - _sourceProfile(sourceProfile) +winrt::Microsoft::Terminal::Settings::Model::implementation::FontConfig::FontConfig(winrt::weak_ref sourceProfile) : + _sourceProfile(std::move(sourceProfile)) { } -winrt::com_ptr FontConfig::CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile) +winrt::com_ptr FontConfig::CopyFontInfo(const winrt::com_ptr source, winrt::weak_ref sourceProfile) { - auto fontInfo{ winrt::make_self(sourceProfile) }; - auto const sourceFontInfo = source.try_as(); - fontInfo->_FontFace = sourceFontInfo->_FontFace; - fontInfo->_FontSize = sourceFontInfo->_FontSize; - fontInfo->_FontWeight = sourceFontInfo->_FontWeight; + auto fontInfo{ winrt::make_self(std::move(sourceProfile)) }; + fontInfo->_FontFace = source->_FontFace; + fontInfo->_FontSize = source->_FontSize; + fontInfo->_FontWeight = source->_FontWeight; return fontInfo; } diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.h b/src/cascadia/TerminalSettingsModel/FontConfig.h index 48a5767168f..5ed2bef3d21 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.h +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -28,8 +28,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation struct FontConfig : FontConfigT, IInheritable { public: - FontConfig(const winrt::weak_ref sourceProfile); - static winrt::com_ptr CopyFontInfo(const winrt::com_ptr source, const winrt::weak_ref sourceProfile); + FontConfig(winrt::weak_ref sourceProfile); + static winrt::com_ptr CopyFontInfo(const winrt::com_ptr source, winrt::weak_ref sourceProfile); Json::Value ToJson() const; void LayerJson(const Json::Value& json); bool HasAnyOptionSet() const;