mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
PDFViewer: Let users change clipping paths visibility
Now that the Renderer accepts preferences, PDFViewer can offer ways for changing these preferences. The first step in this direction is to add a checkbox that allows toggling whether clipping paths are visible or not. A Config item has also been added to remember this setting.
This commit is contained in:
parent
e92ec26771
commit
bc7da24fe6
Notes:
sideshowbarker
2024-07-17 04:07:27 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/bc7da24fe6 Pull-request: https://github.com/SerenityOS/serenity/pull/16155
@ -45,6 +45,7 @@ PDFViewer::PDFViewer()
|
||||
start_timer(30'000);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
PDF::PDFErrorOr<void> PDFViewer::set_document(RefPtr<PDF::Document> document)
|
||||
@ -66,13 +67,14 @@ 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& rendered_page_map = m_rendered_page_list[index];
|
||||
auto existing_rendered_page = rendered_page_map.get(m_zoom_level);
|
||||
auto existing_rendered_page = rendered_page_map.get(key);
|
||||
if (existing_rendered_page.has_value() && existing_rendered_page.value().rotation == m_rotations)
|
||||
return existing_rendered_page.value().bitmap;
|
||||
|
||||
auto rendered_page = TRY(render_page(index));
|
||||
rendered_page_map.set(m_zoom_level, { rendered_page, m_rotations });
|
||||
rendered_page_map.set(key, { rendered_page, m_rotations });
|
||||
return rendered_page;
|
||||
}
|
||||
|
||||
@ -163,6 +165,13 @@ void PDFViewer::set_current_page(u32 current_page)
|
||||
update();
|
||||
}
|
||||
|
||||
void PDFViewer::set_show_clipping_paths(bool show_clipping_paths)
|
||||
{
|
||||
m_rendering_preferences.show_clipping_paths = show_clipping_paths;
|
||||
Config::write_bool("PDFViewer"sv, "Rendering"sv, "ShowClippingPaths"sv, show_clipping_paths);
|
||||
update();
|
||||
}
|
||||
|
||||
void PDFViewer::resize_event(GUI::ResizeEvent&)
|
||||
{
|
||||
for (auto& map : m_rendered_page_list)
|
||||
@ -301,7 +310,7 @@ PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> PDFViewer::render_page(u32 page_inde
|
||||
auto& page_size = m_page_dimension_cache.render_info[page_index].size;
|
||||
auto bitmap = TRY(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, page_size.to_type<int>()));
|
||||
|
||||
TRY(PDF::Renderer::render(*m_document, page, bitmap));
|
||||
TRY(PDF::Renderer::render(*m_document, page, bitmap, m_rendering_preferences));
|
||||
|
||||
if (page.rotate + m_rotations != 0) {
|
||||
int rotation_count = ((page.rotate + m_rotations) / 90) % 4;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <LibGUI/AbstractScrollableWidget.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibPDF/Document.h>
|
||||
#include <LibPDF/Renderer.h>
|
||||
|
||||
static constexpr size_t initial_zoom_level = 8;
|
||||
|
||||
@ -60,6 +61,8 @@ public:
|
||||
|
||||
PageViewMode page_view_mode() const { return m_page_view_mode; }
|
||||
void set_page_view_mode(PageViewMode);
|
||||
bool show_clipping_paths() const { return m_rendering_preferences.show_clipping_paths; }
|
||||
void set_show_clipping_paths(bool);
|
||||
|
||||
protected:
|
||||
PDFViewer();
|
||||
@ -90,6 +93,7 @@ private:
|
||||
u8 m_zoom_level { initial_zoom_level };
|
||||
PageDimensionCache m_page_dimension_cache;
|
||||
PageViewMode m_page_view_mode;
|
||||
PDF::RenderingPreferences m_rendering_preferences;
|
||||
|
||||
Gfx::IntPoint m_pan_starting_position;
|
||||
int m_rotations { 0 };
|
||||
|
@ -167,6 +167,12 @@ void PDFViewerWidget::initialize_toolbar(GUI::Toolbar& toolbar)
|
||||
toolbar.add_action(*m_reset_zoom_action);
|
||||
toolbar.add_action(*m_rotate_counterclockwise_action);
|
||||
toolbar.add_action(*m_rotate_clockwise_action);
|
||||
toolbar.add_separator();
|
||||
|
||||
m_show_clipping_paths = toolbar.add<GUI::CheckBox>();
|
||||
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); };
|
||||
}
|
||||
|
||||
void PDFViewerWidget::open_file(Core::File& file)
|
||||
@ -214,6 +220,7 @@ void PDFViewerWidget::open_file(Core::File& file)
|
||||
m_reset_zoom_action->set_enabled(true);
|
||||
m_rotate_counterclockwise_action->set_enabled(true);
|
||||
m_rotate_clockwise_action->set_enabled(true);
|
||||
m_show_clipping_paths->set_checked(m_viewer->show_clipping_paths(), GUI::AllowCallback::No);
|
||||
|
||||
if (document->outline()) {
|
||||
auto outline = document->outline();
|
||||
|
@ -6,12 +6,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AK/RefPtr.h"
|
||||
#include "NumericInput.h"
|
||||
#include "PDFViewer.h"
|
||||
#include "SidebarWidget.h"
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/ActionGroup.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
class PDFViewer;
|
||||
@ -45,6 +46,7 @@ private:
|
||||
GUI::ActionGroup m_page_view_action_group;
|
||||
RefPtr<GUI::Action> m_page_view_mode_single;
|
||||
RefPtr<GUI::Action> m_page_view_mode_multiple;
|
||||
RefPtr<GUI::CheckBox> m_show_clipping_paths;
|
||||
|
||||
bool m_sidebar_open { false };
|
||||
ByteBuffer m_buffer;
|
||||
|
Loading…
Reference in New Issue
Block a user