1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

PDFViewer: Support a continuous page view mode

This commit is contained in:
Matthew Olsson 2022-03-29 21:27:17 -07:00 committed by Andreas Kling
parent 091c2cfdca
commit 3ecb41b7d9
5 changed files with 196 additions and 49 deletions

View file

@ -14,6 +14,26 @@
static constexpr size_t initial_zoom_level = 8;
struct PageDimensionCache {
// Fixed for a given document
struct PageInfo {
Gfx::FloatSize size;
int rotation;
};
// Based on PageInfo, also depends on some dynamic factors like
// zoom level and app size
struct RenderInfo {
Gfx::FloatSize size;
float total_height_before_this_page;
};
Vector<PageInfo> page_info;
Vector<RenderInfo> render_info;
float max_width;
float total_height;
};
class PDFViewer : public GUI::AbstractScrollableWidget {
C_OBJECT(PDFViewer)
@ -29,7 +49,7 @@ public:
ALWAYS_INLINE void set_current_page(u32 current_page) { m_current_page_index = current_page; }
ALWAYS_INLINE RefPtr<PDF::Document> const& document() const { return m_document; }
void set_document(RefPtr<PDF::Document>);
PDF::PDFErrorOr<void> set_document(RefPtr<PDF::Document>);
Function<void(u32 new_page)> on_page_change;
@ -59,13 +79,16 @@ private:
};
PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> get_rendered_page(u32 index);
PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render_page(const PDF::Page&);
PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render_page(u32 page_index);
PDF::PDFErrorOr<void> cache_page_dimensions(bool recalculate_fixed_info = false);
void change_page(u32 new_page);
RefPtr<PDF::Document> m_document;
u32 m_current_page_index { 0 };
Vector<HashMap<u32, RenderedPage>> m_rendered_page_list;
u8 m_zoom_level { initial_zoom_level };
PageDimensionCache m_page_dimension_cache;
PageViewMode m_page_view_mode;
Gfx::IntPoint m_pan_starting_position;