Repository navigation
Group font options in the json into a single object #10433
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f4a3027
initial
PankajBhojwani 50b595d
complete
PankajBhojwani d91275f
remove remnant
PankajBhojwani c1540dc
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani ae7b350
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani a9dd675
change keys, update tests, add test for legacy keys
PankajBhojwani 861390c
abstract
PankajBhojwani e72495d
format
PankajBhojwani 57b22b1
no more empty font in json
PankajBhojwani 6297d33
const
PankajBhojwani ca07380
update schema
PankajBhojwani 927a66b
remove 'font' prefix
PankajBhojwani b2c0915
deprecated
PankajBhojwani 73530c6
std::move
PankajBhojwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // 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 FontInfoKey{ "font" }; | ||
| 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(winrt::weak_ref<Profile> sourceProfile) : | ||
| _sourceProfile(std::move(sourceProfile)) | ||
| { | ||
| } | ||
|
|
||
| winrt::com_ptr<FontConfig> FontConfig::CopyFontInfo(const winrt::com_ptr<FontConfig> source, winrt::weak_ref<Profile> sourceProfile) | ||
| { | ||
| auto fontInfo{ winrt::make_self<FontConfig>(std::move(sourceProfile)) }; | ||
| fontInfo->_FontFace = source->_FontFace; | ||
| fontInfo->_FontSize = source->_FontSize; | ||
| fontInfo->_FontWeight = source->_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) | ||
| { | ||
| // 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, LegacyFontFaceKey, _FontFace); | ||
| JsonUtils::GetValueForKey(json, LegacyFontSizeKey, _FontSize); | ||
| JsonUtils::GetValueForKey(json, LegacyFontWeightKey, _FontWeight); | ||
| } | ||
| } | ||
|
|
||
| bool FontConfig::HasAnyOptionSet() const | ||
| { | ||
| return HasFontFace() || HasFontSize() || HasFontWeight(); | ||
| } | ||
|
|
||
| winrt::Microsoft::Terminal::Settings::Model::Profile FontConfig::SourceProfile() | ||
| { | ||
| return _sourceProfile.get(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /*++ | ||
| 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 | ||
|
|
||
| #include "pch.h" | ||
| #include "FontConfig.g.h" | ||
| #include "JsonUtils.h" | ||
| #include "../inc/cppwinrt_utils.h" | ||
| #include "IInheritable.h" | ||
| #include <DefaultSettings.h> | ||
|
|
||
| namespace winrt::Microsoft::Terminal::Settings::Model::implementation | ||
| { | ||
| struct FontConfig : FontConfigT<FontConfig>, IInheritable<FontConfig> | ||
| { | ||
| public: | ||
| FontConfig(winrt::weak_ref<Profile> sourceProfile); | ||
| static winrt::com_ptr<FontConfig> CopyFontInfo(const winrt::com_ptr<FontConfig> source, winrt::weak_ref<Profile> sourceProfile); | ||
| Json::Value ToJson() const; | ||
| void LayerJson(const Json::Value& json); | ||
| bool HasAnyOptionSet() const; | ||
|
|
||
| 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<Profile> _sourceProfile; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.