From aaec2a50e002dacde6b4f922f552c963afd9da67 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 19 Oct 2022 19:37:56 +0200 Subject: [PATCH 1/5] Implement cell size customizations --- doc/cascadia/profiles.schema.json | 20 ++++ src/cascadia/TerminalControl/ControlCore.cpp | 4 + src/cascadia/TerminalControl/ControlCore.h | 2 + .../TerminalControl/IControlSettings.idl | 2 + .../TerminalSettingsEditor/Appearances.cpp | 104 +++++++++++++++++- .../TerminalSettingsEditor/Appearances.h | 25 ++--- .../TerminalSettingsEditor/Appearances.idl | 1 + .../TerminalSettingsEditor/Appearances.xaml | 18 +++ .../Resources/en-US/Resources.resw | 16 +++ .../CascadiaSettings.cpp | 4 +- .../TerminalSettingsModel/Profile.cpp | 20 +++- src/cascadia/TerminalSettingsModel/Profile.h | 2 + .../TerminalSettingsModel/Profile.idl | 2 + .../TerminalSettings.cpp | 2 + .../TerminalSettingsModel/TerminalSettings.h | 2 + src/cascadia/inc/ControlProperties.h | 2 + src/renderer/atlas/AtlasEngine.api.cpp | 27 +++-- src/renderer/atlas/AtlasEngine.cpp | 8 ++ src/renderer/atlas/AtlasEngine.h | 4 +- src/renderer/base/CSSLengthPercentage.cpp | 78 +++++++++++++ src/renderer/base/FontInfoDesired.cpp | 16 +++ src/renderer/base/lib/base.vcxproj | 2 + src/renderer/base/lib/base.vcxproj.filters | 8 +- src/renderer/dx/DxFontRenderData.cpp | 29 ++--- src/renderer/inc/CSSLengthPercentage.h | 33 ++++++ src/renderer/inc/FontInfoDesired.hpp | 7 ++ 26 files changed, 387 insertions(+), 51 deletions(-) create mode 100644 src/renderer/base/CSSLengthPercentage.cpp create mode 100644 src/renderer/inc/CSSLengthPercentage.h diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 6366468e689..5b015c36df4 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -296,6 +296,13 @@ }, "type": "object" }, + "CSSLengthPercentage": { + "pattern": "^[+-]?\\d+(?:\\.\\d+)?(?:%|ch|pt|px)?$", + "type": [ + "string", + "null" + ] + }, "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}\\}$", @@ -2086,6 +2093,19 @@ "null" ] }, + "cellSize": { + "type": "object", + "properties": { + "height": { + "$ref": "#/$defs/CSSLengthPercentage", + "description": "Override the height of the terminal's cells. The override works similar to CSS' line-height. Defaults to the sum of the natural glyph ascend, descend and line-gap of the primary font rounded to the nearest pixel. The default is usually quite close to setting this to 1.2." + }, + "width": { + "$ref": "#/$defs/CSSLengthPercentage", + "description": "Override the width of the terminal's cells. The override works similar to CSS' line-height. Defaults to the natural glyph advance width of the primary font rounded to the nearest pixel." + } + } + }, "backgroundImage": { "description": "Sets the file location of the image to draw over the window background.", "oneOf": [ diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index cc9a1d1cb38..907f2f7b310 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -713,6 +713,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation auto lock = _terminal->LockForWriting(); + _cellSizeAdjustmentX = CSSLengthPercentage::FromString(_settings->CellSizeX().c_str()); + _cellSizeAdjustmentY = CSSLengthPercentage::FromString(_settings->CellSizeY().c_str()); _runtimeOpacity = std::nullopt; _runtimeUseAcrylic = std::nullopt; @@ -871,6 +873,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation _actualFont = { fontFace, 0, fontWeight.Weight, _desiredFont.GetEngineSize(), CP_UTF8, false }; _actualFontFaceName = { fontFace }; + _desiredFont.SetCellSizes(_cellSizeAdjustmentX, _cellSizeAdjustmentY); + const auto before = _actualFont.GetSize(); _updateFont(); const auto after = _actualFont.GetSize(); diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index d2649b53a67..a02bff883ba 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -257,6 +257,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation FontInfoDesired _desiredFont; FontInfo _actualFont; winrt::hstring _actualFontFaceName; + CSSLengthPercentage _cellSizeAdjustmentX; + CSSLengthPercentage _cellSizeAdjustmentY; // storage location for the leading surrogate of a utf-16 surrogate pair std::optional _leadingSurrogate{ std::nullopt }; diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index d014b8ac9be..dd132dc78e0 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -42,6 +42,8 @@ namespace Microsoft.Terminal.Control String Padding { get; }; Windows.Foundation.Collections.IMap FontFeatures { get; }; Windows.Foundation.Collections.IMap FontAxes { get; }; + String CellSizeX { get; }; + String CellSizeY { get; }; Microsoft.Terminal.Control.IKeyBindings KeyBindings { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 49d3082350e..deabdaa26d4 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -49,6 +49,88 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + double AppearanceViewModel::LineHeight() const noexcept + { + const auto cellSizeY = _appearance.SourceProfile().CellSizeY(); + const auto str = cellSizeY.c_str(); + + auto& errnoRef = errno; // Nonzero cost, pay it once. + errnoRef = 0; + + wchar_t* end; + const auto value = std::wcstod(str, &end); + + return str == end || errnoRef == ERANGE ? NAN : value; + } + + void AppearanceViewModel::LineHeight(const double value) + { + wchar_t buffer[16]; + std::wstring_view view; + + if (value >= 0.1 && value <= 10.0) + { + auto length = gsl::narrow(swprintf_s(&buffer[0], std::size(buffer), L"%.6f", value)); + const auto separator = std::wstring_view{ &buffer[0], length }.find(L'.'); + + if (separator != std::wstring_view::npos) + { + for (; length > separator && buffer[length - 1] == L'0'; --length) + { + } + // winrt::hstring expects a null-terminated string + buffer[length] = L'\0'; + } + + view = { &buffer[0], length }; + } + + const auto profile = _appearance.SourceProfile(); + + if (profile.CellSizeY() != view) + { + if (view.empty()) + { + profile.ClearCellSizeY(); + } + else + { + profile.CellSizeY(view); + } + _NotifyChanges(L"HasLineHeight", L"LineHeight"); + } + } + + bool AppearanceViewModel::HasLineHeight() + { + return _appearance.SourceProfile().HasCellSizeY(); + } + + void AppearanceViewModel::ClearLineHeight() + { + LineHeight({}); + } + + Model::Profile AppearanceViewModel::LineHeightOverrideSource() + { + return _appearance.SourceProfile().CellSizeYOverrideSource(); + } + + void AppearanceViewModel::SetFontWeightFromDouble(double fontWeight) + { + FontWeight(Converters::DoubleToFontWeight(fontWeight)); + } + + void AppearanceViewModel::SetBackgroundImageOpacityFromPercentageValue(double percentageValue) + { + BackgroundImageOpacity(Converters::PercentageValueToPercentage(percentageValue)); + } + + void AppearanceViewModel::SetBackgroundImagePath(winrt::hstring path) + { + BackgroundImagePath(path); + } + bool AppearanceViewModel::UseDesktopBGImage() { return BackgroundImagePath() == L"desktopWallpaper"; @@ -83,6 +165,16 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation return BackgroundImagePath() != L""; } + IMapView AppearanceViewModel::Schemes() + { + return _Schemes; + } + + void AppearanceViewModel::Schemes(const IMapView& val) + { + _Schemes = val; + } + DependencyProperty Appearances::_AppearanceProperty{ nullptr }; Appearances::Appearances() : @@ -96,10 +188,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // > .NET rounds to 12 significant digits when displaying doubles, so we will [...] // ...obviously not do that, because this is an UI element for humans. This prevents // issues when displaying 32-bit floats, because WinUI is unaware about their existence. - SignificantDigitsNumberRounder rounder; - rounder.SignificantDigits(6); - // BODGY: Depends on WinUI internals. - _fontSizeBox().NumberFormatter().as().NumberRounder(rounder); + IncrementNumberRounder rounder; + rounder.Increment(1e-6); + + for (const auto& box : { _fontSizeBox(), _lineHeightBox() }) + { + // BODGY: Depends on WinUI internals. + box.NumberFormatter().as().NumberRounder(rounder); + } } INITIALIZE_BINDABLE_ENUM_SETTING(CursorShape, CursorStyle, winrt::Microsoft::Terminal::Core::CursorStyle, L"Profile_CursorShape", L"Content"); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index 1eec30f57af..215aae60c78 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -51,26 +51,22 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation public: AppearanceViewModel(const Model::AppearanceConfig& appearance); - void SetFontWeightFromDouble(double fontWeight) - { - FontWeight(winrt::Microsoft::Terminal::Settings::Editor::Converters::DoubleToFontWeight(fontWeight)); - } - void SetBackgroundImageOpacityFromPercentageValue(double percentageValue) - { - BackgroundImageOpacity(winrt::Microsoft::Terminal::Settings::Editor::Converters::PercentageValueToPercentage(percentageValue)); - } - void SetBackgroundImagePath(winrt::hstring path) - { - BackgroundImagePath(path); - } + double LineHeight() const noexcept; + void LineHeight(const double value); + bool HasLineHeight(); + void ClearLineHeight(); + Model::Profile LineHeightOverrideSource(); + void SetFontWeightFromDouble(double fontWeight); + void SetBackgroundImageOpacityFromPercentageValue(double percentageValue); + void SetBackgroundImagePath(winrt::hstring path); // background image bool UseDesktopBGImage(); void UseDesktopBGImage(const bool useDesktop); bool BackgroundImageSettingsVisible(); - Windows::Foundation::Collections::IMapView Schemes() { return _Schemes; } - void Schemes(const Windows::Foundation::Collections::IMapView& val) { _Schemes = val; } + Windows::Foundation::Collections::IMapView Schemes(); + void Schemes(const Windows::Foundation::Collections::IMapView& val); WINRT_PROPERTY(bool, IsDefault, false); WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr); @@ -99,6 +95,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Model::AppearanceConfig _appearance; winrt::hstring _lastBgImagePath; Windows::Foundation::Collections::IMapView _Schemes; + float _cachedLineHeight = 0; }; struct Appearances : AppearancesT diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 39068ee8254..5b525c11522 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -35,6 +35,7 @@ namespace Microsoft.Terminal.Settings.Editor OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, FontFace); 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(String, ColorSchemeName); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 2e348581216..215833f6e09 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -104,6 +104,24 @@ Value="{x:Bind Appearance.FontSize, Mode=TwoWay}" /> + + + + + Size of the font in points. A description for what the "font size" setting does. Presented near "Profile_FontSize". + + Line height + Header for a control that sets the text line height. + + + Line height + Header for a control that sets the text line height. + + + Sets the height of each line in the terminal as a multiple of the font size. The default depends on your font and is usually around 1.2. + A description for what the "line height" setting does. Presented near "Profile_LineHeight". + + + 1.2 + "1.2" is a decimal number. + Font weight Name for a control to select the weight (i.e. bold, thin, etc.) of the text in the app. diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 9712c6e51cf..0d8a115ce79 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -295,7 +295,9 @@ Model::Profile CascadiaSettings::DuplicateProfile(const Model::Profile& source) MTSM_PROFILE_SETTINGS(DUPLICATE_PROFILE_SETTINGS) #undef DUPLICATE_PROFILE_SETTINGS - // These two aren't in MTSM_PROFILE_SETTINGS because they're special + // These aren't in MTSM_PROFILE_SETTINGS because they're special + DUPLICATE_SETTING_MACRO(CellSizeX); + DUPLICATE_SETTING_MACRO(CellSizeY); DUPLICATE_SETTING_MACRO(TabColor); DUPLICATE_SETTING_MACRO(Padding); diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 9db6741703e..0e004aa42cb 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -27,6 +27,9 @@ static constexpr std::string_view SourceKey{ "source" }; static constexpr std::string_view HiddenKey{ "hidden" }; static constexpr std::string_view FontInfoKey{ "font" }; +static constexpr std::string_view CellSizeKey{ "cellSize" }; +static constexpr std::string_view CellSizeXKey{ "width" }; +static constexpr std::string_view CellSizeYKey{ "height" }; static constexpr std::string_view PaddingKey{ "padding" }; static constexpr std::string_view TabColorKey{ "tabColor" }; static constexpr std::string_view UnfocusedAppearanceKey{ "unfocusedAppearance" }; @@ -102,6 +105,8 @@ winrt::com_ptr Profile::CopySettings() const profile->_Name = _Name; profile->_Source = _Source; profile->_Hidden = _Hidden; + profile->_CellSizeX = _CellSizeX; + profile->_CellSizeY = _CellSizeY; profile->_TabColor = _TabColor; profile->_Padding = _Padding; @@ -171,10 +176,14 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, HiddenKey, _Hidden); JsonUtils::GetValueForKey(json, SourceKey, _Source); + if (const auto& cellSizeJSON = json[JsonKey(CellSizeKey)]) + { + JsonUtils::GetValueForKey(cellSizeJSON, CellSizeXKey, _CellSizeX); + JsonUtils::GetValueForKey(cellSizeJSON, CellSizeYKey, _CellSizeY); + } // Padding was never specified as an integer, but it was a common working mistake. // Allow it to be permissive. JsonUtils::GetValueForKey(json, PaddingKey, _Padding, JsonUtils::OptionalConverter>{}); - JsonUtils::GetValueForKey(json, TabColorKey, _TabColor); #define PROFILE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ @@ -313,9 +322,14 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, HiddenKey, writeBasicSettings ? Hidden() : _Hidden); JsonUtils::SetValueForKey(json, SourceKey, writeBasicSettings ? Source() : _Source); - // PermissiveStringConverter is unnecessary for serialization + if (_CellSizeX || _CellSizeY) + { + Json::Value cellSizeJSON{ Json::ValueType::objectValue }; + JsonUtils::SetValueForKey(cellSizeJSON, CellSizeXKey, _CellSizeX); + JsonUtils::SetValueForKey(cellSizeJSON, CellSizeYKey, _CellSizeY); + json[JsonKey(CellSizeKey)] = std::move(cellSizeJSON); + } JsonUtils::SetValueForKey(json, PaddingKey, _Padding); - JsonUtils::SetValueForKey(json, TabColorKey, _TabColor); #define PROFILE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/Profile.h b/src/cascadia/TerminalSettingsModel/Profile.h index dbc33fc9ef5..066caaf1d03 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.h +++ b/src/cascadia/TerminalSettingsModel/Profile.h @@ -116,6 +116,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, hstring, Source); INHERITABLE_SETTING(Model::Profile, bool, Hidden, false); INHERITABLE_SETTING(Model::Profile, guid, Guid, _GenerateGuidForProfile(Name(), Source())); + INHERITABLE_SETTING(Model::Profile, hstring, CellSizeX); + INHERITABLE_SETTING(Model::Profile, hstring, CellSizeY); INHERITABLE_SETTING(Model::Profile, hstring, Padding, DEFAULT_PADDING); #define PROFILE_SETTINGS_INITIALIZE(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index 608dfc5f914..a816c31c7b6 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -71,6 +71,8 @@ namespace Microsoft.Terminal.Settings.Model String EvaluatedStartingDirectory { get; }; FontConfig FontInfo { get; }; + INHERITABLE_PROFILE_SETTING(String, CellSizeX); + INHERITABLE_PROFILE_SETTING(String, CellSizeY); IAppearanceConfig DefaultAppearance { get; }; INHERITABLE_PROFILE_SETTING(IAppearanceConfig, UnfocusedAppearance); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 0ba57857303..3f0bb1b2083 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -253,6 +253,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _FontWeight = profile.FontInfo().FontWeight(); _FontFeatures = profile.FontInfo().FontFeatures(); _FontAxes = profile.FontInfo().FontAxes(); + _CellSizeX = profile.CellSizeX(); + _CellSizeY = profile.CellSizeY(); _Padding = profile.Padding(); _Commandline = profile.Commandline(); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index 0dd65cdfbb7..4fd186c5c8f 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -126,6 +126,8 @@ 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, hstring, CellSizeX); + INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellSizeY); INHERITABLE_SETTING(Model::TerminalSettings, Model::ColorScheme, AppliedColorScheme); INHERITABLE_SETTING(Model::TerminalSettings, hstring, BackgroundImage); diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index 5911fa26183..59e6ac7d25c 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -61,6 +61,8 @@ X(winrt::Windows::UI::Text::FontWeight, FontWeight) \ X(IFontFeatureMap, FontFeatures) \ X(IFontAxesMap, FontAxes) \ + X(hstring, CellSizeX) \ + X(hstring, CellSizeY) \ X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \ X(winrt::hstring, Commandline) \ X(winrt::hstring, StartingDirectory) \ diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index 1e1776559bc..c480ccf454b 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -622,20 +622,23 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo const auto designUnitsPerPx = fontSizeInPx / static_cast(metrics.designUnitsPerEm); const auto ascent = static_cast(metrics.ascent) * designUnitsPerPx; const auto descent = static_cast(metrics.descent) * designUnitsPerPx; + const auto lineGap = static_cast(metrics.lineGap) * designUnitsPerPx; const auto underlinePosition = static_cast(-metrics.underlinePosition) * designUnitsPerPx; const auto underlineThickness = static_cast(metrics.underlineThickness) * designUnitsPerPx; const auto strikethroughPosition = static_cast(-metrics.strikethroughPosition) * designUnitsPerPx; const auto strikethroughThickness = static_cast(metrics.strikethroughThickness) * designUnitsPerPx; - const auto advanceWidth = static_cast(glyphMetrics.advanceWidth) * designUnitsPerPx; + const auto advanceHeight = ascent + descent + lineGap; + + auto adjustedWidth = std::roundf(fontInfoDesired.GetCellSizeX().Resolve(advanceWidth, _api.dpi, fontSizeInPx, advanceWidth)); + auto adjustedHeight = std::roundf(fontInfoDesired.GetCellSizeY().Resolve(advanceHeight, _api.dpi, fontSizeInPx, advanceWidth)); + + // Protection against bad user values in GetCellSizeX/Y. + // AtlasEngine fails hard with 0 cell sizes. + adjustedWidth = std::max(1.0f, adjustedWidth); + adjustedHeight = std::max(1.0f, adjustedHeight); - // NOTE: Line-gaps shouldn't be taken into account for lineHeight calculations. - // Terminals don't really have "gaps" between lines and instead the expectation - // is that two full block characters above each other don't leave any gaps - // between the lines. "Terminus TTF" for instance sets a line-gap of 90 units - // even though its font bitmap only covers the ascend/descend height. - const auto baseline = std::roundf(ascent); - const auto lineHeight = std::roundf(baseline + descent); + const auto baseline = std::roundf(ascent + (lineGap + adjustedHeight - advanceHeight) / 2.0f); const auto underlinePos = std::roundf(baseline + underlinePosition); const auto underlineWidth = std::max(1.0f, std::roundf(underlineThickness)); const auto strikethroughPos = std::roundf(baseline + strikethroughPosition); @@ -662,10 +665,10 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo const auto doubleUnderlineGap = std::max(1.0f, std::roundf(1.2f / 72.0f * _api.dpi)); doubleUnderlinePosBottom = std::max(doubleUnderlinePosBottom, doubleUnderlinePosTop + doubleUnderlineGap + thinLineWidth); // Our cells can't overlap each other so we additionally clamp the bottom line to be inside the cell boundaries. - doubleUnderlinePosBottom = std::min(doubleUnderlinePosBottom, lineHeight - thinLineWidth); + doubleUnderlinePosBottom = std::min(doubleUnderlinePosBottom, adjustedHeight - thinLineWidth); - const auto cellWidth = gsl::narrow(std::lroundf(advanceWidth)); - const auto cellHeight = gsl::narrow(lineHeight); + const auto cellWidth = gsl::narrow(std::lroundf(adjustedWidth)); + const auto cellHeight = gsl::narrow(std::lroundf(adjustedHeight)); { til::size coordSize; @@ -703,7 +706,7 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo fontMetrics->fontName = std::move(fontName); fontMetrics->fontSizeInDIP = fontSizeInDIP; fontMetrics->baselineInDIP = baseline / static_cast(_api.dpi) * 96.0f; - fontMetrics->advanceScale = cellWidth / advanceWidth; + fontMetrics->advanceScale = cellWidth / adjustedWidth; fontMetrics->cellSize = { cellWidth, cellHeight }; fontMetrics->fontWeight = fontWeightU16; fontMetrics->underlinePos = underlinePosU16; diff --git a/src/renderer/atlas/AtlasEngine.cpp b/src/renderer/atlas/AtlasEngine.cpp index c99c9303b21..7ce4da06b63 100644 --- a/src/renderer/atlas/AtlasEngine.cpp +++ b/src/renderer/atlas/AtlasEngine.cpp @@ -1121,6 +1121,14 @@ void AtlasEngine::_recreateFontDependentResources() // fonts making them look fairly unslightly. With no option to easily disable this // feature in Windows Terminal, it's better left disabled by default. + const DWRITE_LINE_SPACING lineSpacing{ + .method = DWRITE_LINE_SPACING_METHOD_UNIFORM, + .height = _r.cellSizeDIP.y, + .baseline = _api.fontMetrics.baselineInDIP, + .fontLineGapUsage = DWRITE_FONT_LINE_GAP_USAGE_ENABLED, + }; + THROW_IF_FAILED(textFormat.query()->SetLineSpacing(&lineSpacing)); + if (!_api.fontAxisValues.empty()) { if (const auto textFormat3 = textFormat.try_query()) diff --git a/src/renderer/atlas/AtlasEngine.h b/src/renderer/atlas/AtlasEngine.h index 6a1533b4f6e..8b8b1c894f2 100644 --- a/src/renderer/atlas/AtlasEngine.h +++ b/src/renderer/atlas/AtlasEngine.h @@ -412,8 +412,8 @@ namespace Microsoft::Console::Render wil::com_ptr fontCollection; wil::com_ptr fontFamily; std::wstring fontName; - float baselineInDIP = 0.0f; - float fontSizeInDIP = 0.0f; + f32 baselineInDIP = 0.0f; + f32 fontSizeInDIP = 0.0f; f32 advanceScale = 0; u16x2 cellSize; u16 fontWeight = 0; diff --git a/src/renderer/base/CSSLengthPercentage.cpp b/src/renderer/base/CSSLengthPercentage.cpp new file mode 100644 index 00000000000..f9ac48f94c9 --- /dev/null +++ b/src/renderer/base/CSSLengthPercentage.cpp @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "precomp.h" + +#include "../inc/CSSLengthPercentage.h" + +CSSLengthPercentage CSSLengthPercentage::FromString(const wchar_t* str) +{ + auto& errnoRef = errno; // Nonzero cost, pay it once. + errnoRef = 0; + + wchar_t* end; + auto value = std::wcstof(str, &end); + + if (str == end || errnoRef == ERANGE) + { + return {}; + } + + auto referenceFrame = ReferenceFrame::FontSize; + + if (*end) + { + if (wcscmp(end, L"%") == 0) + { + value /= 100.0f; + } + else if (wcscmp(end, L"px") == 0) + { + referenceFrame = ReferenceFrame::Absolute; + value /= 96.0f; + } + else if (wcscmp(end, L"pt") == 0) + { + referenceFrame = ReferenceFrame::Absolute; + value /= 72.0f; + } + else if (wcscmp(end, L"ch") == 0) + { + referenceFrame = ReferenceFrame::AdvanceWidth; + } + else + { + return {}; + } + } + + CSSLengthPercentage obj; + obj._value = value; + obj._referenceFrame = referenceFrame; + return obj; +} + +CSSLengthPercentage::ReferenceFrame CSSLengthPercentage::GetReferenceFrame() const noexcept +{ + return _referenceFrame; +} + +float CSSLengthPercentage::Resolve(float factor) const noexcept +{ + return _value * factor; +} + +float CSSLengthPercentage::Resolve(float fallback, float dpi, float fontSize, float advanceWidth) const noexcept +{ + switch (_referenceFrame) + { + case ReferenceFrame::Absolute: + return _value * dpi; + case ReferenceFrame::FontSize: + return _value * fontSize; + case ReferenceFrame::AdvanceWidth: + return _value * advanceWidth; + default: + return fallback; + } +} diff --git a/src/renderer/base/FontInfoDesired.cpp b/src/renderer/base/FontInfoDesired.cpp index 8340aeab12b..a0284dd0fb0 100644 --- a/src/renderer/base/FontInfoDesired.cpp +++ b/src/renderer/base/FontInfoDesired.cpp @@ -23,6 +23,22 @@ FontInfoDesired::FontInfoDesired(const FontInfo& fiFont) noexcept : { } +void FontInfoDesired::SetCellSizes(const CSSLengthPercentage& adjustmentX, const CSSLengthPercentage& adjustmentY) noexcept +{ + _adjustmentX = adjustmentX; + _adjustmentY = adjustmentY; +} + +const CSSLengthPercentage& FontInfoDesired::GetCellSizeX() const noexcept +{ + return _adjustmentX; +} + +const CSSLengthPercentage& FontInfoDesired::GetCellSizeY() const noexcept +{ + return _adjustmentY; +} + float FontInfoDesired::GetFontSize() const noexcept { return _fontSize; diff --git a/src/renderer/base/lib/base.vcxproj b/src/renderer/base/lib/base.vcxproj index 697934e8551..3c177d955e2 100644 --- a/src/renderer/base/lib/base.vcxproj +++ b/src/renderer/base/lib/base.vcxproj @@ -11,6 +11,7 @@ + @@ -25,6 +26,7 @@ + diff --git a/src/renderer/base/lib/base.vcxproj.filters b/src/renderer/base/lib/base.vcxproj.filters index a678fb27cce..8887f1c610f 100644 --- a/src/renderer/base/lib/base.vcxproj.filters +++ b/src/renderer/base/lib/base.vcxproj.filters @@ -45,6 +45,9 @@ Source Files + + Source Files + @@ -89,8 +92,11 @@ Header Files + + Header Files\inc + - \ No newline at end of file + diff --git a/src/renderer/dx/DxFontRenderData.cpp b/src/renderer/dx/DxFontRenderData.cpp index 3f334dbedf3..b45799d51d2 100644 --- a/src/renderer/dx/DxFontRenderData.cpp +++ b/src/renderer/dx/DxFontRenderData.cpp @@ -706,6 +706,7 @@ std::vector DxFontRenderData::GetAxisVector(const DWRITE // - None void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, FontInfo& actual, const int dpi) { + const auto dpiF = static_cast(dpi); auto fontLocaleName = UserLocaleName(); // This is the first attempt to resolve font face after `UpdateFont`. // Note that the following line may cause property changes _inside_ `_defaultFontInfo` because the desired font may not exist. @@ -737,27 +738,20 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font // - 12 ppi font * (96 dpi / 96 dpi) * (96 dpi / 72 points per inch) = 16 pixels tall font for 100% display (96 dpi is 100%) // - 12 ppi font * (144 dpi / 96 dpi) * (96 dpi / 72 points per inch) = 24 pixels tall font for 150% display (144 dpi is 150%) // - 12 ppi font * (192 dpi / 96 dpi) * (96 dpi / 72 points per inch) = 32 pixels tall font for 200% display (192 dpi is 200%) - auto heightDesired = desired.GetEngineSize().Y * USER_DEFAULT_SCREEN_DPI / POINTS_PER_INCH; + const auto heightDesired = desired.GetEngineSize().Y / POINTS_PER_INCH * dpiF; // The advance is the number of pixels left-to-right (X dimension) for the given font. // We're finding a proportional factor here with the design units in "ems", not an actual pixel measurement. - - // Now we play trickery with the font size. Scale by the DPI to get the height we expect. - heightDesired *= (static_cast(dpi) / static_cast(USER_DEFAULT_SCREEN_DPI)); - const auto widthAdvance = static_cast(advanceInDesignUnits) / fontMetrics.designUnitsPerEm; // Use the real pixel height desired by the "em" factor for the width to get the number of pixels // we will need per character in width. This will almost certainly result in fractional X-dimension pixels. - const auto widthApprox = heightDesired * widthAdvance; - - // Since we can't deal with columns of the presentation grid being fractional pixels in width, round to the nearest whole pixel. - const auto widthExact = round(widthApprox); + const auto widthAdvanceInPx = heightDesired * widthAdvance; // Now reverse the "em" factor from above to turn the exact pixel width into a (probably) fractional // height in pixels of each character. It's easier for us to pad out height and align vertically // than it is horizontally. - const auto fontSize = widthExact / widthAdvance; + const auto fontSize = roundf(widthAdvanceInPx) / widthAdvance; _fontSize = fontSize; // Now figure out the basic properties of the character height which include ascent and descent @@ -809,8 +803,12 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font const auto fullPixelAscent = ceil(ascent + halfGap); const auto fullPixelDescent = ceil(descent + halfGap); - lineSpacing.height = fullPixelAscent + fullPixelDescent; - lineSpacing.baseline = fullPixelAscent; + const auto defaultHeight = fullPixelAscent + fullPixelDescent; + const auto lineHeight = desired.GetCellSizeY().Resolve(defaultHeight, dpiF, heightDesired, widthAdvanceInPx); + const auto baseline = fullPixelAscent + (lineHeight - defaultHeight) / 2.0f; + + lineSpacing.height = roundf(lineHeight); + lineSpacing.baseline = roundf(baseline); // According to MSDN (https://docs.microsoft.com/en-us/windows/win32/api/dwrite_3/ne-dwrite_3-dwrite_font_line_gap_usage) // Setting "ENABLED" means we've included the line gapping in the spacing numbers given. @@ -818,6 +816,9 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font _lineSpacing = lineSpacing; + const auto widthApprox = desired.GetCellSizeX().Resolve(widthAdvanceInPx, dpiF, heightDesired, widthAdvanceInPx); + const auto widthExact = roundf(widthApprox); + // The scaled size needs to represent the pixel box that each character will fit within for the purposes // of hit testing math and other such multiplication/division. til::size coordSize; @@ -861,8 +862,8 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font // Offsets are relative to the base line of the font, so we subtract // from the ascent to get an offset relative to the top of the cell. - lineMetrics.underlineOffset = fullPixelAscent - lineMetrics.underlineOffset; - lineMetrics.strikethroughOffset = fullPixelAscent - lineMetrics.strikethroughOffset; + lineMetrics.underlineOffset = lineSpacing.baseline - lineMetrics.underlineOffset; + lineMetrics.strikethroughOffset = lineSpacing.baseline - lineMetrics.strikethroughOffset; // For double underlines we need a second offset, just below the first, // but with a bit of a gap (about double the grid line width). diff --git a/src/renderer/inc/CSSLengthPercentage.h b/src/renderer/inc/CSSLengthPercentage.h new file mode 100644 index 00000000000..289904ceb93 --- /dev/null +++ b/src/renderer/inc/CSSLengthPercentage.h @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +struct CSSLengthPercentage +{ + enum class ReferenceFrame : uint8_t + { + // This indicates the object is empty/unset. + // No need to call Resolve(). + None, + // Call Resolve() with factor set to the target DPI (e.g. 96 for DIP). + // Returns an absolute length value scaled by that DPI. + Absolute, + // Call Resolve() with factor set to the font size + // in an arbitrary DPI. Returns a value relative to it. + FontSize, + // Call Resolve() with factor set to the "0" glyph advance width + // in an arbitrary DPI. Returns a value relative to it. + AdvanceWidth, + }; + + static CSSLengthPercentage FromString(const wchar_t* str); + + ReferenceFrame GetReferenceFrame() const noexcept; + float Resolve(float factor) const noexcept; + float Resolve(float fallback, float dpi, float fontSize, float advanceWidth) const noexcept; + +private: + float _value = 0; + ReferenceFrame _referenceFrame = ReferenceFrame::None; +}; diff --git a/src/renderer/inc/FontInfoDesired.hpp b/src/renderer/inc/FontInfoDesired.hpp index 5e77e466f9c..343e664b7aa 100644 --- a/src/renderer/inc/FontInfoDesired.hpp +++ b/src/renderer/inc/FontInfoDesired.hpp @@ -20,6 +20,7 @@ Author(s): #include "FontInfoBase.hpp" #include "FontInfo.hpp" +#include "CSSLengthPercentage.h" class FontInfoDesired : public FontInfoBase { @@ -33,6 +34,10 @@ class FontInfoDesired : public FontInfoBase bool operator==(const FontInfoDesired& other) = delete; + void SetCellSizes(const CSSLengthPercentage& adjustmentX, const CSSLengthPercentage& adjustmentY) noexcept; + + const CSSLengthPercentage& GetCellSizeX() const noexcept; + const CSSLengthPercentage& GetCellSizeY() const noexcept; float GetFontSize() const noexcept; til::size GetEngineSize() const noexcept; bool IsDefaultRasterFont() const noexcept; @@ -40,4 +45,6 @@ class FontInfoDesired : public FontInfoBase private: til::size _coordSizeDesired; float _fontSize; + CSSLengthPercentage _adjustmentX; + CSSLengthPercentage _adjustmentY; }; From ba8e1650a19d2a7338cd35116223e3b4df4acb62 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 20 Oct 2022 01:09:11 +0200 Subject: [PATCH 2/5] Fix unit tests --- src/cascadia/TerminalControl/ControlCore.cpp | 6 +++--- src/cascadia/TerminalControl/ControlCore.h | 4 ++-- src/cascadia/inc/ControlProperties.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 907f2f7b310..3c334f40ab3 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -713,8 +713,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation auto lock = _terminal->LockForWriting(); - _cellSizeAdjustmentX = CSSLengthPercentage::FromString(_settings->CellSizeX().c_str()); - _cellSizeAdjustmentY = CSSLengthPercentage::FromString(_settings->CellSizeY().c_str()); + _cellSizeX = CSSLengthPercentage::FromString(_settings->CellSizeX().c_str()); + _cellSizeY = CSSLengthPercentage::FromString(_settings->CellSizeY().c_str()); _runtimeOpacity = std::nullopt; _runtimeUseAcrylic = std::nullopt; @@ -873,7 +873,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation _actualFont = { fontFace, 0, fontWeight.Weight, _desiredFont.GetEngineSize(), CP_UTF8, false }; _actualFontFaceName = { fontFace }; - _desiredFont.SetCellSizes(_cellSizeAdjustmentX, _cellSizeAdjustmentY); + _desiredFont.SetCellSizes(_cellSizeX, _cellSizeY); const auto before = _actualFont.GetSize(); _updateFont(); diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index a02bff883ba..a2acb37f290 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -257,8 +257,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation FontInfoDesired _desiredFont; FontInfo _actualFont; winrt::hstring _actualFontFaceName; - CSSLengthPercentage _cellSizeAdjustmentX; - CSSLengthPercentage _cellSizeAdjustmentY; + CSSLengthPercentage _cellSizeX; + CSSLengthPercentage _cellSizeY; // storage location for the leading surrogate of a utf-16 surrogate pair std::optional _leadingSurrogate{ std::nullopt }; diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index 59e6ac7d25c..a561c29b2eb 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -61,8 +61,8 @@ X(winrt::Windows::UI::Text::FontWeight, FontWeight) \ X(IFontFeatureMap, FontFeatures) \ X(IFontAxesMap, FontAxes) \ - X(hstring, CellSizeX) \ - X(hstring, CellSizeY) \ + X(winrt::hstring, CellSizeX) \ + X(winrt::hstring, CellSizeY) \ X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \ X(winrt::hstring, Commandline) \ X(winrt::hstring, StartingDirectory) \ From f6e730ecfb4032112f81444164d1ab9bdfaa6f26 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 20 Oct 2022 23:43:22 +0200 Subject: [PATCH 3/5] Address parts of the feedback --- src/cascadia/TerminalSettingsEditor/Appearances.cpp | 2 +- src/cascadia/TerminalSettingsEditor/Appearances.xaml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index deabdaa26d4..3e32658b88b 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -108,7 +108,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void AppearanceViewModel::ClearLineHeight() { - LineHeight({}); + LineHeight(NAN); } Model::Profile AppearanceViewModel::LineHeightOverrideSource() diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 215833f6e09..414827cb822 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -95,7 +95,6 @@ Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}"> From 504f483586c97e9461a5b6908475234748abca89 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 6 Dec 2022 22:03:10 +0100 Subject: [PATCH 4/5] Address feedback --- doc/cascadia/profiles.schema.json | 35 +++++++--------- src/cascadia/TerminalControl/ControlCore.cpp | 6 +-- src/cascadia/TerminalControl/ControlCore.h | 4 +- .../TerminalControl/IControlSettings.idl | 4 +- .../TerminalSettingsEditor/Appearances.cpp | 42 +++++++------------ .../TerminalSettingsEditor/Appearances.h | 4 +- .../CascadiaSettings.cpp | 2 - .../TerminalSettingsModel/FontConfig.idl | 3 +- .../TerminalSettingsModel/MTSMSettings.h | 4 +- .../TerminalSettingsModel/Profile.cpp | 20 ++------- src/cascadia/TerminalSettingsModel/Profile.h | 2 - .../TerminalSettingsModel/Profile.idl | 2 - .../TerminalSettings.cpp | 15 +++---- .../TerminalSettingsModel/TerminalSettings.h | 4 +- src/cascadia/inc/ControlProperties.h | 4 +- src/renderer/atlas/AtlasEngine.api.cpp | 6 +-- src/renderer/base/FontInfoDesired.cpp | 14 +++---- src/renderer/dx/DxFontRenderData.cpp | 4 +- src/renderer/inc/FontInfoDesired.hpp | 10 ++--- 19 files changed, 77 insertions(+), 108 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index c86c69e9ba4..efea7b89adc 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -24,6 +24,13 @@ "pattern": "^(-?\\d+)?(,\\s?(-?\\d+)?)?$", "type": "string" }, + "CSSLengthPercentage": { + "pattern": "^[+-]?\\d+(?:\\.\\d+)?(?:%|ch|pt|px)?$", + "type": [ + "string", + "null" + ] + }, "DynamicProfileSource": { "enum": [ "Windows.Terminal.Wsl", @@ -292,17 +299,18 @@ } }, "additionalProperties": false + }, + "cellWidth": { + "$ref": "#/$defs/CSSLengthPercentage", + "description": "Override the width of the terminal's cells. The override works similar to CSS' letter-spacing. It defaults to the natural glyph advance width of the primary font rounded to the nearest pixel." + }, + "cellHeight": { + "$ref": "#/$defs/CSSLengthPercentage", + "description": "Override the height of the terminal's cells. The override works similar to CSS' line-height. Defaults to the sum of the natural glyph ascend, descend and line-gap of the primary font rounded to the nearest pixel. The default is usually quite close to setting this to 1.2." } }, "type": "object" }, - "CSSLengthPercentage": { - "pattern": "^[+-]?\\d+(?:\\.\\d+)?(?:%|ch|pt|px)?$", - "type": [ - "string", - "null" - ] - }, "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}\\}$", @@ -2093,19 +2101,6 @@ "null" ] }, - "cellSize": { - "type": "object", - "properties": { - "height": { - "$ref": "#/$defs/CSSLengthPercentage", - "description": "Override the height of the terminal's cells. The override works similar to CSS' line-height. Defaults to the sum of the natural glyph ascend, descend and line-gap of the primary font rounded to the nearest pixel. The default is usually quite close to setting this to 1.2." - }, - "width": { - "$ref": "#/$defs/CSSLengthPercentage", - "description": "Override the width of the terminal's cells. The override works similar to CSS' line-height. Defaults to the natural glyph advance width of the primary font rounded to the nearest pixel." - } - } - }, "backgroundImage": { "description": "Sets the file location of the image to draw over the window background.", "oneOf": [ diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 4e2b7d02877..8d2f749a039 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -714,8 +714,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation auto lock = _terminal->LockForWriting(); - _cellSizeX = CSSLengthPercentage::FromString(_settings->CellSizeX().c_str()); - _cellSizeY = CSSLengthPercentage::FromString(_settings->CellSizeY().c_str()); + _cellWidth = CSSLengthPercentage::FromString(_settings->CellWidth().c_str()); + _cellHeight = CSSLengthPercentage::FromString(_settings->CellHeight().c_str()); // GH#11285 - If the user is on Windows 10, and they wanted opacity, but // didn't explicitly request acrylic, then opt them in to acrylic. @@ -871,7 +871,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation _actualFont = { fontFace, 0, fontWeight.Weight, _desiredFont.GetEngineSize(), CP_UTF8, false }; _actualFontFaceName = { fontFace }; - _desiredFont.SetCellSizes(_cellSizeX, _cellSizeY); + _desiredFont.SetCellSize(_cellWidth, _cellHeight); const auto before = _actualFont.GetSize(); _updateFont(); diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 4ef249b4b2f..d71b23833dd 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -257,8 +257,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation FontInfoDesired _desiredFont; FontInfo _actualFont; winrt::hstring _actualFontFaceName; - CSSLengthPercentage _cellSizeX; - CSSLengthPercentage _cellSizeY; + CSSLengthPercentage _cellWidth; + CSSLengthPercentage _cellHeight; // storage location for the leading surrogate of a utf-16 surrogate pair std::optional _leadingSurrogate{ std::nullopt }; diff --git a/src/cascadia/TerminalControl/IControlSettings.idl b/src/cascadia/TerminalControl/IControlSettings.idl index dd132dc78e0..a47af4cc262 100644 --- a/src/cascadia/TerminalControl/IControlSettings.idl +++ b/src/cascadia/TerminalControl/IControlSettings.idl @@ -42,8 +42,8 @@ namespace Microsoft.Terminal.Control String Padding { get; }; Windows.Foundation.Collections.IMap FontFeatures { get; }; Windows.Foundation.Collections.IMap FontAxes { get; }; - String CellSizeX { get; }; - String CellSizeY { get; }; + String CellWidth { get; }; + String CellHeight { get; }; Microsoft.Terminal.Control.IKeyBindings KeyBindings { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 8a575bb48e6..9c4332ffd5e 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -51,8 +51,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation double AppearanceViewModel::LineHeight() const noexcept { - const auto cellSizeY = _appearance.SourceProfile().CellSizeY(); - const auto str = cellSizeY.c_str(); + const auto fontInfo = _appearance.SourceProfile().FontInfo(); + const auto cellHeight = fontInfo.CellHeight(); + const auto str = cellHeight.c_str(); auto& errnoRef = errno; // Nonzero cost, pay it once. errnoRef = 0; @@ -65,45 +66,33 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void AppearanceViewModel::LineHeight(const double value) { - wchar_t buffer[16]; - std::wstring_view view; + std::wstring str; if (value >= 0.1 && value <= 10.0) { - auto length = gsl::narrow(swprintf_s(&buffer[0], std::size(buffer), L"%.6f", value)); - const auto separator = std::wstring_view{ &buffer[0], length }.find(L'.'); - - if (separator != std::wstring_view::npos) - { - for (; length > separator && buffer[length - 1] == L'0'; --length) - { - } - // winrt::hstring expects a null-terminated string - buffer[length] = L'\0'; - } - - view = { &buffer[0], length }; + str = fmt::format(FMT_STRING(L"{:.6g}"), value); } - const auto profile = _appearance.SourceProfile(); + const auto fontInfo = _appearance.SourceProfile().FontInfo(); - if (profile.CellSizeY() != view) + if (fontInfo.CellHeight() != str) { - if (view.empty()) + if (str.empty()) { - profile.ClearCellSizeY(); + fontInfo.ClearCellHeight(); } else { - profile.CellSizeY(view); + fontInfo.CellHeight(str); } _NotifyChanges(L"HasLineHeight", L"LineHeight"); } } - bool AppearanceViewModel::HasLineHeight() + bool AppearanceViewModel::HasLineHeight() const { - return _appearance.SourceProfile().HasCellSizeY(); + const auto fontInfo = _appearance.SourceProfile().FontInfo(); + return fontInfo.HasCellHeight(); } void AppearanceViewModel::ClearLineHeight() @@ -111,9 +100,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation LineHeight(NAN); } - Model::Profile AppearanceViewModel::LineHeightOverrideSource() + Model::FontConfig AppearanceViewModel::LineHeightOverrideSource() const { - return _appearance.SourceProfile().CellSizeYOverrideSource(); + const auto fontInfo = _appearance.SourceProfile().FontInfo(); + return fontInfo.CellHeightOverrideSource(); } void AppearanceViewModel::SetFontWeightFromDouble(double fontWeight) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index d98ccc7699a..372cb2cf2c9 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -53,9 +53,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation double LineHeight() const noexcept; void LineHeight(const double value); - bool HasLineHeight(); + bool HasLineHeight() const; void ClearLineHeight(); - Model::Profile LineHeightOverrideSource(); + Model::FontConfig LineHeightOverrideSource() const; void SetFontWeightFromDouble(double fontWeight); void SetBackgroundImageOpacityFromPercentageValue(double percentageValue); void SetBackgroundImagePath(winrt::hstring path); diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 0d8a115ce79..5608081b955 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -296,8 +296,6 @@ Model::Profile CascadiaSettings::DuplicateProfile(const Model::Profile& source) #undef DUPLICATE_PROFILE_SETTINGS // These aren't in MTSM_PROFILE_SETTINGS because they're special - DUPLICATE_SETTING_MACRO(CellSizeX); - DUPLICATE_SETTING_MACRO(CellSizeY); DUPLICATE_SETTING_MACRO(TabColor); DUPLICATE_SETTING_MACRO(Padding); diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.idl b/src/cascadia/TerminalSettingsModel/FontConfig.idl index 174a6ff74b0..249bb94f8d1 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.idl +++ b/src/cascadia/TerminalSettingsModel/FontConfig.idl @@ -18,8 +18,9 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_FONT_SETTING(String, FontFace); INHERITABLE_FONT_SETTING(Single, FontSize); INHERITABLE_FONT_SETTING(Windows.UI.Text.FontWeight, FontWeight); - INHERITABLE_FONT_SETTING(Windows.Foundation.Collections.IMap, FontFeatures); INHERITABLE_FONT_SETTING(Windows.Foundation.Collections.IMap, FontAxes); + INHERITABLE_FONT_SETTING(String, CellWidth); + INHERITABLE_FONT_SETTING(String, CellHeight); } } diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index 3cae1919883..7c0605efef7 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -99,7 +99,9 @@ Author(s): X(float, FontSize, "size", DEFAULT_FONT_SIZE) \ X(winrt::Windows::UI::Text::FontWeight, FontWeight, "weight", DEFAULT_FONT_WEIGHT) \ X(IFontAxesMap, FontAxes, "axes") \ - X(IFontFeatureMap, FontFeatures, "features") + X(IFontFeatureMap, FontFeatures, "features") \ + X(winrt::hstring, CellWidth, "cellWidth") \ + X(winrt::hstring, CellHeight, "cellHeight") #define MTSM_APPEARANCE_SETTINGS(X) \ X(Core::CursorStyle, CursorShape, "cursorShape", Core::CursorStyle::Bar) \ diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 0e004aa42cb..9db6741703e 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -27,9 +27,6 @@ static constexpr std::string_view SourceKey{ "source" }; static constexpr std::string_view HiddenKey{ "hidden" }; static constexpr std::string_view FontInfoKey{ "font" }; -static constexpr std::string_view CellSizeKey{ "cellSize" }; -static constexpr std::string_view CellSizeXKey{ "width" }; -static constexpr std::string_view CellSizeYKey{ "height" }; static constexpr std::string_view PaddingKey{ "padding" }; static constexpr std::string_view TabColorKey{ "tabColor" }; static constexpr std::string_view UnfocusedAppearanceKey{ "unfocusedAppearance" }; @@ -105,8 +102,6 @@ winrt::com_ptr Profile::CopySettings() const profile->_Name = _Name; profile->_Source = _Source; profile->_Hidden = _Hidden; - profile->_CellSizeX = _CellSizeX; - profile->_CellSizeY = _CellSizeY; profile->_TabColor = _TabColor; profile->_Padding = _Padding; @@ -176,14 +171,10 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, HiddenKey, _Hidden); JsonUtils::GetValueForKey(json, SourceKey, _Source); - if (const auto& cellSizeJSON = json[JsonKey(CellSizeKey)]) - { - JsonUtils::GetValueForKey(cellSizeJSON, CellSizeXKey, _CellSizeX); - JsonUtils::GetValueForKey(cellSizeJSON, CellSizeYKey, _CellSizeY); - } // Padding was never specified as an integer, but it was a common working mistake. // Allow it to be permissive. JsonUtils::GetValueForKey(json, PaddingKey, _Padding, JsonUtils::OptionalConverter>{}); + JsonUtils::GetValueForKey(json, TabColorKey, _TabColor); #define PROFILE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ @@ -322,14 +313,9 @@ Json::Value Profile::ToJson() const JsonUtils::SetValueForKey(json, HiddenKey, writeBasicSettings ? Hidden() : _Hidden); JsonUtils::SetValueForKey(json, SourceKey, writeBasicSettings ? Source() : _Source); - if (_CellSizeX || _CellSizeY) - { - Json::Value cellSizeJSON{ Json::ValueType::objectValue }; - JsonUtils::SetValueForKey(cellSizeJSON, CellSizeXKey, _CellSizeX); - JsonUtils::SetValueForKey(cellSizeJSON, CellSizeYKey, _CellSizeY); - json[JsonKey(CellSizeKey)] = std::move(cellSizeJSON); - } + // PermissiveStringConverter is unnecessary for serialization JsonUtils::SetValueForKey(json, PaddingKey, _Padding); + JsonUtils::SetValueForKey(json, TabColorKey, _TabColor); #define PROFILE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/Profile.h b/src/cascadia/TerminalSettingsModel/Profile.h index 066caaf1d03..dbc33fc9ef5 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.h +++ b/src/cascadia/TerminalSettingsModel/Profile.h @@ -116,8 +116,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::Profile, hstring, Source); INHERITABLE_SETTING(Model::Profile, bool, Hidden, false); INHERITABLE_SETTING(Model::Profile, guid, Guid, _GenerateGuidForProfile(Name(), Source())); - INHERITABLE_SETTING(Model::Profile, hstring, CellSizeX); - INHERITABLE_SETTING(Model::Profile, hstring, CellSizeY); INHERITABLE_SETTING(Model::Profile, hstring, Padding, DEFAULT_PADDING); #define PROFILE_SETTINGS_INITIALIZE(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/Profile.idl b/src/cascadia/TerminalSettingsModel/Profile.idl index a816c31c7b6..608dfc5f914 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.idl +++ b/src/cascadia/TerminalSettingsModel/Profile.idl @@ -71,8 +71,6 @@ namespace Microsoft.Terminal.Settings.Model String EvaluatedStartingDirectory { get; }; FontConfig FontInfo { get; }; - INHERITABLE_PROFILE_SETTING(String, CellSizeX); - INHERITABLE_PROFILE_SETTING(String, CellSizeY); IAppearanceConfig DefaultAppearance { get; }; INHERITABLE_PROFILE_SETTING(IAppearanceConfig, UnfocusedAppearance); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 3f0bb1b2083..a448e4ef187 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -248,13 +248,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _ProfileSource = profile.Source(); _UseAcrylic = profile.UseAcrylic(); - _FontFace = profile.FontInfo().FontFace(); - _FontSize = profile.FontInfo().FontSize(); - _FontWeight = profile.FontInfo().FontWeight(); - _FontFeatures = profile.FontInfo().FontFeatures(); - _FontAxes = profile.FontInfo().FontAxes(); - _CellSizeX = profile.CellSizeX(); - _CellSizeY = profile.CellSizeY(); + const auto fontInfo = profile.FontInfo(); + _FontFace = fontInfo.FontFace(); + _FontSize = fontInfo.FontSize(); + _FontWeight = fontInfo.FontWeight(); + _FontFeatures = fontInfo.FontFeatures(); + _FontAxes = fontInfo.FontAxes(); + _CellWidth = fontInfo.CellWidth(); + _CellHeight = fontInfo.CellHeight(); _Padding = profile.Padding(); _Commandline = profile.Commandline(); diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index 4fd186c5c8f..304d3e87173 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -126,8 +126,8 @@ 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, hstring, CellSizeX); - INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellSizeY); + INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellWidth); + INHERITABLE_SETTING(Model::TerminalSettings, hstring, CellHeight); INHERITABLE_SETTING(Model::TerminalSettings, Model::ColorScheme, AppliedColorScheme); INHERITABLE_SETTING(Model::TerminalSettings, hstring, BackgroundImage); diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index a561c29b2eb..8b79a310d53 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -61,8 +61,8 @@ X(winrt::Windows::UI::Text::FontWeight, FontWeight) \ X(IFontFeatureMap, FontFeatures) \ X(IFontAxesMap, FontAxes) \ - X(winrt::hstring, CellSizeX) \ - X(winrt::hstring, CellSizeY) \ + X(winrt::hstring, CellWidth) \ + X(winrt::hstring, CellHeight) \ X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \ X(winrt::hstring, Commandline) \ X(winrt::hstring, StartingDirectory) \ diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index 24a89308b20..df9859a0cf3 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -635,10 +635,10 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo const auto advanceWidth = static_cast(glyphMetrics.advanceWidth) * designUnitsPerPx; const auto advanceHeight = ascent + descent + lineGap; - auto adjustedWidth = std::roundf(fontInfoDesired.GetCellSizeX().Resolve(advanceWidth, _api.dpi, fontSizeInPx, advanceWidth)); - auto adjustedHeight = std::roundf(fontInfoDesired.GetCellSizeY().Resolve(advanceHeight, _api.dpi, fontSizeInPx, advanceWidth)); + auto adjustedWidth = std::roundf(fontInfoDesired.GetCellWidth().Resolve(advanceWidth, _api.dpi, fontSizeInPx, advanceWidth)); + auto adjustedHeight = std::roundf(fontInfoDesired.GetCellHeight().Resolve(advanceHeight, _api.dpi, fontSizeInPx, advanceWidth)); - // Protection against bad user values in GetCellSizeX/Y. + // Protection against bad user values in GetCellWidth/Y. // AtlasEngine fails hard with 0 cell sizes. adjustedWidth = std::max(1.0f, adjustedWidth); adjustedHeight = std::max(1.0f, adjustedHeight); diff --git a/src/renderer/base/FontInfoDesired.cpp b/src/renderer/base/FontInfoDesired.cpp index 6ac038644ea..742883e7c14 100644 --- a/src/renderer/base/FontInfoDesired.cpp +++ b/src/renderer/base/FontInfoDesired.cpp @@ -23,20 +23,20 @@ FontInfoDesired::FontInfoDesired(const FontInfo& fiFont) noexcept : { } -void FontInfoDesired::SetCellSizes(const CSSLengthPercentage& adjustmentX, const CSSLengthPercentage& adjustmentY) noexcept +void FontInfoDesired::SetCellSize(const CSSLengthPercentage& cellWidth, const CSSLengthPercentage& cellHeight) noexcept { - _adjustmentX = adjustmentX; - _adjustmentY = adjustmentY; + _cellWidth = cellWidth; + _cellHeight = cellHeight; } -const CSSLengthPercentage& FontInfoDesired::GetCellSizeX() const noexcept +const CSSLengthPercentage& FontInfoDesired::GetCellWidth() const noexcept { - return _adjustmentX; + return _cellWidth; } -const CSSLengthPercentage& FontInfoDesired::GetCellSizeY() const noexcept +const CSSLengthPercentage& FontInfoDesired::GetCellHeight() const noexcept { - return _adjustmentY; + return _cellHeight; } float FontInfoDesired::GetFontSize() const noexcept diff --git a/src/renderer/dx/DxFontRenderData.cpp b/src/renderer/dx/DxFontRenderData.cpp index 5d27be5f277..559ebe6d85b 100644 --- a/src/renderer/dx/DxFontRenderData.cpp +++ b/src/renderer/dx/DxFontRenderData.cpp @@ -804,7 +804,7 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font const auto fullPixelAscent = ceil(ascent + halfGap); const auto fullPixelDescent = ceil(descent + halfGap); const auto defaultHeight = fullPixelAscent + fullPixelDescent; - const auto lineHeight = desired.GetCellSizeY().Resolve(defaultHeight, dpiF, heightDesired, widthAdvanceInPx); + const auto lineHeight = desired.GetCellHeight().Resolve(defaultHeight, dpiF, heightDesired, widthAdvanceInPx); const auto baseline = fullPixelAscent + (lineHeight - defaultHeight) / 2.0f; lineSpacing.height = roundf(lineHeight); @@ -816,7 +816,7 @@ void DxFontRenderData::_BuildFontRenderData(const FontInfoDesired& desired, Font _lineSpacing = lineSpacing; - const auto widthApprox = desired.GetCellSizeX().Resolve(widthAdvanceInPx, dpiF, heightDesired, widthAdvanceInPx); + const auto widthApprox = desired.GetCellWidth().Resolve(widthAdvanceInPx, dpiF, heightDesired, widthAdvanceInPx); const auto widthExact = roundf(widthApprox); // The scaled size needs to represent the pixel box that each character will fit within for the purposes diff --git a/src/renderer/inc/FontInfoDesired.hpp b/src/renderer/inc/FontInfoDesired.hpp index 343e664b7aa..84643283183 100644 --- a/src/renderer/inc/FontInfoDesired.hpp +++ b/src/renderer/inc/FontInfoDesired.hpp @@ -34,10 +34,10 @@ class FontInfoDesired : public FontInfoBase bool operator==(const FontInfoDesired& other) = delete; - void SetCellSizes(const CSSLengthPercentage& adjustmentX, const CSSLengthPercentage& adjustmentY) noexcept; + void SetCellSize(const CSSLengthPercentage& cellWidth, const CSSLengthPercentage& cellHeight) noexcept; - const CSSLengthPercentage& GetCellSizeX() const noexcept; - const CSSLengthPercentage& GetCellSizeY() const noexcept; + const CSSLengthPercentage& GetCellWidth() const noexcept; + const CSSLengthPercentage& GetCellHeight() const noexcept; float GetFontSize() const noexcept; til::size GetEngineSize() const noexcept; bool IsDefaultRasterFont() const noexcept; @@ -45,6 +45,6 @@ class FontInfoDesired : public FontInfoBase private: til::size _coordSizeDesired; float _fontSize; - CSSLengthPercentage _adjustmentX; - CSSLengthPercentage _adjustmentY; + CSSLengthPercentage _cellWidth; + CSSLengthPercentage _cellHeight; }; From 17f8e4705597c776e16ac53477a67006d85f3067 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 7 Dec 2022 00:33:28 +0100 Subject: [PATCH 5/5] Fix config saving --- src/cascadia/TerminalSettingsModel/FontConfig.cpp | 5 ----- src/cascadia/TerminalSettingsModel/FontConfig.h | 1 - src/cascadia/TerminalSettingsModel/Profile.cpp | 6 ++---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index 62ebc5aacec..fafdf0976bc 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -78,11 +78,6 @@ void FontConfig::LayerJson(const Json::Value& json) } } -bool FontConfig::HasAnyOptionSet() const -{ - 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 7b9b4663d21..8a789278eb7 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.h +++ b/src/cascadia/TerminalSettingsModel/FontConfig.h @@ -35,7 +35,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static winrt::com_ptr CopyFontInfo(const FontConfig* source, winrt::weak_ref sourceProfile); Json::Value ToJson() const; void LayerJson(const Json::Value& json); - bool HasAnyOptionSet() const; Model::Profile SourceProfile(); diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 9db6741703e..b660337e971 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -324,11 +324,9 @@ Json::Value Profile::ToJson() const MTSM_PROFILE_SETTINGS(PROFILE_SETTINGS_TO_JSON) #undef PROFILE_SETTINGS_TO_JSON - // Font settings - const auto fontInfoImpl = winrt::get_self(_FontInfo); - if (fontInfoImpl->HasAnyOptionSet()) + if (auto fontJSON = winrt::get_self(_FontInfo)->ToJson(); !fontJSON.empty()) { - json[JsonKey(FontInfoKey)] = winrt::get_self(_FontInfo)->ToJson(); + json[JsonKey(FontInfoKey)] = std::move(fontJSON); } if (_UnfocusedAppearance)