Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Aug 9, 2024
1 parent edfa3ea commit 61929e0
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 467 deletions.
8 changes: 4 additions & 4 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,7 @@ std::wstring TextBuffer::GetPlainText(const CopyRequest& req) const
// Return Value:
// - string containing the generated HTML. Empty if the copy request is invalid.
std::string TextBuffer::GenHTML(const CopyRequest& req,
const int fontHeightPoints,
const float fontHeightPoints,
const std::wstring_view fontFaceName,
const COLORREF backgroundColor,
const bool isIntenseBold,
Expand Down Expand Up @@ -1966,7 +1966,7 @@ std::string TextBuffer::GenHTML(const CopyRequest& req,
// even with different font, add monospace as fallback
fmt::format_to(std::back_inserter(htmlBuilder), FMT_COMPILE("font-family:'{}',monospace;"), til::u16u8(fontFaceName));

fmt::format_to(std::back_inserter(htmlBuilder), FMT_COMPILE("font-size:{}pt;"), fontHeightPoints);
fmt::format_to(std::back_inserter(htmlBuilder), FMT_COMPILE("font-size:{}pt;"), lroundf(fontHeightPoints));

// note: MS Word doesn't support padding (in this way at least)
// todo: customizable padding
Expand Down Expand Up @@ -2141,7 +2141,7 @@ std::string TextBuffer::GenHTML(const CopyRequest& req,
// Return Value:
// - string containing the generated RTF. Empty if the copy request is invalid.
std::string TextBuffer::GenRTF(const CopyRequest& req,
const int fontHeightPoints,
const float fontHeightPoints,
const std::wstring_view fontFaceName,
const COLORREF backgroundColor,
const bool isIntenseBold,
Expand Down Expand Up @@ -2217,7 +2217,7 @@ std::string TextBuffer::GenRTF(const CopyRequest& req,

// \fsN: specifies font size in half-points. E.g. \fs20 results in a font
// size of 10 pts. That's why, font size is multiplied by 2 here.
fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\fs{}"), 2 * fontHeightPoints);
fmt::format_to(std::back_inserter(contentBuilder), FMT_COMPILE("\\fs{}"), lroundf(2 * fontHeightPoints));

// Set the background color for the page. But the standard way (\cbN) to do
// this isn't supported in Word. However, the following control words sequence
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ class TextBuffer final
std::wstring GetPlainText(const CopyRequest& req) const;

std::string GenHTML(const CopyRequest& req,
const int fontHeightPoints,
const float fontHeightPoints,
const std::wstring_view fontFaceName,
const COLORREF backgroundColor,
const bool isIntenseBold,
std::function<std::tuple<COLORREF, COLORREF, COLORREF>(const TextAttribute&)> GetAttributeColors) const noexcept;

std::string GenRTF(const CopyRequest& req,
const int fontHeightPoints,
const float fontHeightPoints,
const std::wstring_view fontFaceName,
const COLORREF backgroundColor,
const bool isIntenseBold,
Expand Down
20 changes: 10 additions & 10 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

ControlCore::ControlCore(Control::IControlSettings settings,
Control::IControlAppearance unfocusedAppearance,
TerminalConnection::ITerminalConnection connection) :
_desiredFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, DEFAULT_FONT_SIZE, CP_UTF8 },
_actualFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false }
TerminalConnection::ITerminalConnection connection)
{
static const auto textMeasurementInit = [&]() {
TextMeasurementMode mode = TextMeasurementMode::Graphemes;
Expand Down Expand Up @@ -1019,18 +1017,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// - Returns true if you need to call _refreshSizeUnderLock().
bool ControlCore::_setFontSizeUnderLock(float fontSize)
{
// Make sure we have a non-zero font size
const auto before = _actualFont.GetSize();

const auto newSize = std::max(fontSize, 1.0f);
const auto fontFace = _settings->FontFace();
const auto fontWeight = _settings->FontWeight();
_desiredFont = { fontFace, 0, fontWeight.Weight, newSize, CP_UTF8 };
_actualFont = { fontFace, 0, fontWeight.Weight, _desiredFont.GetEngineSize(), CP_UTF8, false };

_desiredFont.SetEnableBuiltinGlyphs(_builtinGlyphs);
_desiredFont.SetEnableColorGlyphs(_colorGlyphs);
_desiredFont.SetCellSize(_cellWidth, _cellHeight);
_desiredFont = FontInfoDesired{
GetFaceName() = std::wstring{ std::wstring_view{ fontFace } },
.GetWeight() = fontWeight.Weight,
.fontSize = newSize,
.cellSize = { _cellWidth, _cellHeight },
};
_actualFontFaceName = fontFace;

const auto before = _actualFont.GetSize();
_updateFont();
const auto after = _actualFont.GetSize();
return before != after;
Expand Down
20 changes: 13 additions & 7 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto fontSize = settings.FontSize();
const auto fontWeight = settings.FontWeight();
const auto fontFace = settings.FontFace();
const auto cellWidth = CSSLengthPercentage::FromString(settings.CellWidth().c_str());
const auto cellHeight = CSSLengthPercentage::FromString(settings.CellHeight().c_str());
const auto scrollState = settings.ScrollState();
const auto padding = settings.Padding();

Expand All @@ -2715,8 +2717,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// The family is only used to determine if the font is truetype or
// not, but DX doesn't use that info at all.
// The Codepage is additionally not actually used by the DX engine at all.
FontInfoDesired desiredFont{ fontFace, 0, fontWeight.Weight, fontSize, CP_UTF8 };
FontInfo actualFont{ fontFace, 0, fontWeight.Weight, desiredFont.GetEngineSize(), CP_UTF8, false };
FontInfoDesired desiredFont{
fontFace,
0,
fontWeight.Weight,
0,
{ cellWidth, cellHeight },
fontSize,
};
FontInfo actualFont;

// Create a DX engine and initialize it with our font and DPI. We'll
// then use it to measure how much space the requested rows and columns
Expand All @@ -2729,22 +2738,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
LOG_IF_FAILED(engine->UpdateDpi(dpi));
LOG_IF_FAILED(engine->UpdateFont(desiredFont, actualFont));

const auto scale = dpi / static_cast<float>(USER_DEFAULT_SCREEN_DPI);
const auto actualFontSize = actualFont.GetSize();

// UWP XAML scrollbars aren't guaranteed to be the same size as the
// ComCtl scrollbars, but it's certainly close enough.
const auto scrollbarSize = GetSystemMetricsForDpi(SM_CXVSCROLL, dpi);

float width = cols * static_cast<float>(actualFontSize.width);
float width = cols * static_cast<float>(actualFont.GetSize().width);

// Reserve additional space if scrollbar is intended to be visible
if (scrollState != ScrollbarState::Hidden)
{
width += scrollbarSize;
}

float height = rows * static_cast<float>(actualFontSize.height);
float height = rows * static_cast<float>(actualFont.GetSize().height);
const auto thickness = ParseThicknessFromPadding(padding);
// GH#2061 - make sure to account for the size the padding _will be_ scaled to
width += scale * static_cast<float>(thickness.Left + thickness.Right);
Expand Down
4 changes: 1 addition & 3 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@ class Microsoft::Terminal::Core::Terminal final :
std::wstring _answerbackMessage;
std::wstring _workingDirectory;

// This default fake font value is only used to check if the font is a raster font.
// Otherwise, the font is changed to a real value with the renderer via TriggerFontChange.
FontInfo _fontInfo{ DEFAULT_FONT_FACE, TMPF_TRUETYPE, 10, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false };
FontInfo _fontInfo;
#pragma region Text Selection
// a selection is represented as a range between two COORDs (start and end)
// the pivot is the til::point that remains selected when you extend a selection in any direction
Expand Down
7 changes: 2 additions & 5 deletions src/cascadia/TerminalSettingsEditor/Appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
IncrementNumberRounder rounder;
rounder.Increment(1e-6);

for (const auto& box : { _fontSizeBox(), _lineHeightBox() })
{
// BODGY: Depends on WinUI internals.
box.NumberFormatter().as<DecimalFormatter>().NumberRounder(rounder);
}
// BODGY: Depends on WinUI internals.
_fontSizeBox().NumberFormatter().as<DecimalFormatter>().NumberRounder(rounder);
}

INITIALIZE_BINDABLE_ENUM_SETTING(CursorShape, CursorStyle, winrt::Microsoft::Terminal::Core::CursorStyle, L"Profile_CursorShape", L"Content");
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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(String, CellHeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.UI.Text.FontWeight, FontWeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, EnableBuiltinGlyphs);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, EnableColorGlyphs);
Expand Down
18 changes: 7 additions & 11 deletions src/cascadia/TerminalSettingsEditor/Appearances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,14 @@

<!-- Line Height -->
<local:SettingContainer x:Uid="Profile_LineHeight"
ClearSettingValue="{x:Bind Appearance.ClearLineHeight}"
HasSettingValue="{x:Bind Appearance.HasLineHeight, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.LineHeightOverrideSource, Mode=OneWay}"
ClearSettingValue="{x:Bind Appearance.ClearCellHeight}"
HasSettingValue="{x:Bind Appearance.HasCellHeight, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.CellHeightOverrideSource, Mode=OneWay}"
Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}">
<muxc:NumberBox x:Name="_lineHeightBox"
x:Uid="Profile_LineHeightBox"
LargeChange="0.1"
Maximum="10"
Minimum="0.1"
SmallChange="0.1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind Appearance.LineHeight, Mode=TwoWay}" />
<TextBox x:Uid="Profile_LineHeightBox"
IsSpellCheckEnabled="False"
Style="{StaticResource TextBoxSettingStyle}"
Text="{x:Bind Appearance.CellHeight, Mode=TwoWay}" />
</local:SettingContainer>

<!-- Font Weight -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@
<comment>Header for a control that sets the text line height.</comment>
</data>
<data name="Profile_LineHeight.HelpText" xml:space="preserve">
<value>Override the line height of the terminal. Measured as a multiple of the font size. The default value depends on your font and is usually around 1.2.</value>
<comment>A description for what the "line height" setting does. Presented near "Profile_LineHeight".</comment>
<value>Override the line height of the terminal. It supports inputs such as 1.5, 150%, 16px, 12pt, or 1ch. To match the font size behavior of the previous Windows Console Host, you can set this setting to something like 16px and then revert the font size setting to the default above.</value>
<comment>CSS stands for Cascading Style Sheets and is a web technology. "line-height", "px", "pt" and "ch" are part of CSS and should not be translated. {Locked="line-height","1.5","150%","16px","12pt","1ch"}</comment>
</data>
<data name="Profile_LineHeightBox.PlaceholderText" xml:space="preserve">
<value>1.2</value>
Expand Down
24 changes: 2 additions & 22 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,17 @@
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"colorScheme": "Campbell",
"antialiasingMode": "grayscale",
"closeOnExit": "automatic",
"cursorShape": "bar",
"fontFace": "Cascadia Mono",
"fontSize": 12,
"hidden": false,
"historySize": 9001,
"padding": "8, 8, 8, 8",
"snapOnInput": true,
"altGrAliasing": true,
"startingDirectory": "%USERPROFILE%",
"useAcrylic": false
"startingDirectory": "%USERPROFILE%"
},
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "%SystemRoot%\\System32\\cmd.exe",
"icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"colorScheme": "Campbell",
"antialiasingMode": "grayscale",
"closeOnExit": "automatic",
"cursorShape": "bar",
"fontFace": "Cascadia Mono",
"fontSize": 12,
"hidden": false,
"historySize": 9001,
"padding": "8, 8, 8, 8",
"snapOnInput": true,
"altGrAliasing": true,
"startingDirectory": "%USERPROFILE%",
"useAcrylic": false
"startingDirectory": "%USERPROFILE%"
}
],
"schemes":
Expand Down
4 changes: 2 additions & 2 deletions src/host/directio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,10 @@ CATCH_RETURN();

// Create new screen buffer.
auto WindowSize = siExisting.GetViewport().Dimensions();
const auto& existingFont = siExisting.GetCurrentFont();
SCREEN_INFORMATION* ScreenInfo = nullptr;
auto Status = SCREEN_INFORMATION::CreateInstance(WindowSize,
existingFont,
siExisting.GetDesiredFont(),
siExisting.GetCurrentFont(),
WindowSize,
siExisting.GetAttributes(),
siExisting.GetAttributes(),
Expand Down
23 changes: 10 additions & 13 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
if (index == 0)
{
// As of the November 2015 renderer system, we only have a single font at index 0.
size = context.GetActiveBuffer().GetCurrentFont().GetUnscaledSize();
size = context.GetActiveBuffer().GetWhackyConhostFontSize();
return S_OK;
}
else
Expand Down Expand Up @@ -270,7 +270,7 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
}
else
{
WindowSize = activeScreenInfo.GetCurrentFont().GetUnscaledSize();
WindowSize = activeScreenInfo.GetWhackyConhostFontSize();
}
consoleFontInfoEx.dwFontSize = til::unwrap_coord_size(WindowSize);

Expand Down Expand Up @@ -304,19 +304,16 @@ void ApiRoutines::GetNumberOfConsoleMouseButtonsImpl(ULONG& buttons) noexcept
LockConsole();
auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

auto& activeScreenInfo = context.GetActiveBuffer();

WCHAR FaceName[ARRAYSIZE(consoleFontInfoEx.FaceName)];
RETURN_IF_FAILED(StringCchCopyW(FaceName, ARRAYSIZE(FaceName), consoleFontInfoEx.FaceName));

FontInfo fi(FaceName,
gsl::narrow_cast<unsigned char>(consoleFontInfoEx.FontFamily),
consoleFontInfoEx.FontWeight,
til::wrap_coord_size(consoleFontInfoEx.dwFontSize),
gci.OutputCP);
FontInfoDesired fi{
consoleFontInfoEx.FaceName,
gsl::narrow_cast<unsigned char>(consoleFontInfoEx.FontFamily),
consoleFontInfoEx.FontWeight,
gci.OutputCP,
til::wrap_coord_size(consoleFontInfoEx.dwFontSize),
};

// TODO: MSFT: 9574827 - should this have a failure case?
activeScreenInfo.UpdateFont(&fi);
context.GetActiveBuffer().UpdateFont(fi);

return S_OK;
}
Expand Down
13 changes: 8 additions & 5 deletions src/host/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ using namespace Microsoft::Console::Interactivity;
{
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();

FontInfo fiFont(gci.GetFaceName(),
gsl::narrow_cast<unsigned char>(gci.GetFontFamily()),
gci.GetFontWeight(),
gci.GetFontSize(),
gci.GetCodePage());
FontInfoDesired fiFont{
gci.GetFaceName(),
gsl::narrow_cast<unsigned char>(gci.GetFontFamily()),
gci.GetFontWeight(),
gci.GetCodePage(),
gci.GetFontSize(),
};

// For East Asian version, we want to get the code page from the registry or shell32, so we can specify console
// codepage by console.cpl or shell32. The default codepage is OEMCP.
Expand All @@ -40,6 +42,7 @@ using namespace Microsoft::Console::Interactivity;

auto Status = SCREEN_INFORMATION::CreateInstance(gci.GetWindowSize(),
fiFont,
FontInfo{},
gci.GetScreenBufferSize(),
TextAttribute{},
TextAttribute{ gci.GetPopupFillAttribute() },
Expand Down
Loading

1 comment on commit 61929e0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (2)

otm
would've

Previously acknowledged words that are now absent Consoleroot gitmodules NTSYSCALLAPI Tpp vsconfig WDK wmemory 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/lhecker/14165-conhost-font-size branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/10326358167/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2229) from .github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt
.github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (2)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (1)

See the 📜action log or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 6

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.