mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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.
This commit is contained in:
parent
adc45635e9
commit
67b50d7994
Notes:
sideshowbarker
2024-07-17 08:45:34 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/67b50d7994 Pull-request: https://github.com/SerenityOS/serenity/pull/16202
4 changed files with 17 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue