Kaynağa Gözat

PDFViewer: Let users change image rendering

A new checkbox in the toolbar now allows users toggle image rendering. A
corresponding Config option makes this setting non-volatile. To void
clashing with the previous "show_clipping_paths" option when caching a
Page, we now use the RenderingPreferences.hash() and the pair_int_hash
funcitons to compute a unique key into the page cache map for a given
RenderingPreferences and zoom level.
Rodrigo Tobar 2 yıl önce
ebeveyn
işleme
67b50d7994

+ 10 - 1
Userland/Applications/PDFViewer/PDFViewer.cpp

@@ -8,6 +8,7 @@
 #include "PDFViewer.h"
 #include <AK/Array.h>
 #include <AK/BinarySearch.h>
+#include <AK/HashFunctions.h>
 #include <LibConfig/Client.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/MessageBox.h>
@@ -46,6 +47,7 @@ PDFViewer::PDFViewer()
 
     m_page_view_mode = static_cast<PageViewMode>(Config::read_i32("PDFViewer"sv, "Display"sv, "PageMode"sv, 0));
     m_rendering_preferences.show_clipping_paths = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ShowClippingPaths"sv, false);
+    m_rendering_preferences.show_images = Config::read_bool("PDFViewer"sv, "Rendering"sv, "ShowImages"sv, true);
 }
 
 PDF::PDFErrorOr<void> PDFViewer::set_document(RefPtr<PDF::Document> document)
@@ -67,7 +69,7 @@ PDF::PDFErrorOr<void> PDFViewer::set_document(RefPtr<PDF::Document> document)
 
 PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> PDFViewer::get_rendered_page(u32 index)
 {
-    auto key = m_zoom_level * (static_cast<int>(m_rendering_preferences.show_clipping_paths) + 1);
+    auto key = pair_int_hash(m_rendering_preferences.hash(), m_zoom_level);
     auto& rendered_page_map = m_rendered_page_list[index];
     auto existing_rendered_page = rendered_page_map.get(key);
     if (existing_rendered_page.has_value() && existing_rendered_page.value().rotation == m_rotations)
@@ -172,6 +174,13 @@ void PDFViewer::set_show_clipping_paths(bool show_clipping_paths)
     update();
 }
 
+void PDFViewer::set_show_images(bool show_images)
+{
+    m_rendering_preferences.show_images = show_images;
+    Config::write_bool("PDFViewer"sv, "Rendering"sv, "ShowImages"sv, show_images);
+    update();
+}
+
 void PDFViewer::resize_event(GUI::ResizeEvent&)
 {
     for (auto& map : m_rendered_page_list)

+ 2 - 0
Userland/Applications/PDFViewer/PDFViewer.h

@@ -63,6 +63,8 @@ public:
     void set_page_view_mode(PageViewMode);
     bool show_clipping_paths() const { return m_rendering_preferences.show_clipping_paths; }
     void set_show_clipping_paths(bool);
+    bool show_images() const { return m_rendering_preferences.show_images; }
+    void set_show_images(bool);
 
 protected:
     PDFViewer();

+ 4 - 0
Userland/Applications/PDFViewer/PDFViewerWidget.cpp

@@ -180,6 +180,10 @@ void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar)
     m_show_clipping_paths->set_text("Show clipping paths");
     m_show_clipping_paths->set_checked(m_viewer->show_clipping_paths(), GUI::AllowCallback::No);
     m_show_clipping_paths->on_checked = [&](auto checked) { m_viewer->set_show_clipping_paths(checked); };
+    m_show_images = toolbar.add<GUI::CheckBox>();
+    m_show_images->set_text("Show images");
+    m_show_images->set_checked(m_viewer->show_images(), GUI::AllowCallback::No);
+    m_show_images->on_checked = [&](auto checked) { m_viewer->set_show_images(checked); };
 }
 
 void PDFViewerWidget::open_file(Core::File& file)

+ 1 - 0
Userland/Applications/PDFViewer/PDFViewerWidget.h

@@ -47,6 +47,7 @@ private:
     RefPtr<GUI::Action> m_page_view_mode_single;
     RefPtr<GUI::Action> m_page_view_mode_multiple;
     RefPtr<GUI::CheckBox> m_show_clipping_paths;
+    RefPtr<GUI::CheckBox> m_show_images;
 
     bool m_sidebar_open { false };
     ByteBuffer m_buffer;