Terminal: Fix zoom when font size is missing

If Terminal was configured with a typeface that does not have a font
for any given size, the zoom in and out button in the menu bar would
not work because font lookup was exact.

Use Font::AllowInexactMatch::Larger when zooming in and
Font::AllowInexactMatch::Smaller when zooming out to allow finding the
closest font size in the requested direction.
This commit is contained in:
Shane Murphy 2023-10-18 22:08:22 -07:00 committed by Andreas Kling
parent 0e05614710
commit d2fbc15f5d
Notes: sideshowbarker 2024-07-19 16:49:48 +09:00

View File

@ -400,10 +400,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}));
view_menu->add_action(terminal->clear_including_history_action());
auto adjust_font_size = [&](float adjustment) {
auto adjust_font_size = [&](float adjustment, Gfx::Font::AllowInexactSizeMatch preference) {
auto& font = terminal->font();
auto new_size = max(5, font.presentation_size() + adjustment);
if (auto new_font = Gfx::FontDatabase::the().get(font.family(), new_size, font.weight(), font.width(), font.slope())) {
if (auto new_font = Gfx::FontDatabase::the().get(font.family(), new_size, font.weight(), font.width(), font.slope(), preference)) {
terminal->set_font_and_resize_to_fit(*new_font);
terminal->apply_size_increments_to_window(*window);
window->resize(terminal->size());
@ -412,10 +412,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
view_menu->add_separator();
view_menu->add_action(GUI::CommonActions::make_zoom_in_action([&](auto&) {
adjust_font_size(1);
adjust_font_size(1, Gfx::Font::AllowInexactSizeMatch::Larger);
}));
view_menu->add_action(GUI::CommonActions::make_zoom_out_action([&](auto&) {
adjust_font_size(-1);
adjust_font_size(-1, Gfx::Font::AllowInexactSizeMatch::Smaller);
}));
auto help_menu = window->add_menu("&Help"_string);