mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 14:02:51 +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: 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue