Jelajahi Sumber

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.
Shane Murphy 1 tahun lalu
induk
melakukan
d2fbc15f5d
1 mengubah file dengan 4 tambahan dan 4 penghapusan
  1. 4 4
      Userland/Applications/Terminal/main.cpp

+ 4 - 4
Userland/Applications/Terminal/main.cpp

@@ -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);