mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-30 06:52:52 +00:00
LibPDF: Switch to best-effort PDF rendering
The current rendering routine aborts as soon as an error is found during rendering, which potentially severely limits the contents we show on screen. Moreover, whenever an error happens the PDFViewer widget shows an error dialog, and doesn't display the bitmap that has been painted so far. This commit improves the situation in both fronts, implementing rendering now with a best-effort approach. Firstly, execution of operations isn't halted after an operand results in an error, but instead execution of all operations is always attempted, and all collected errors are returned in bulk. Secondly, PDFViewer now always displays the resulting bitmap, regardless of error being produced or not. To communicate errors, an on_render_errors callback has been added so clients can subscribe to these events and handle them as appropriate.
This commit is contained in:
parent
96fb4b20f1
commit
e87fecf710
Notes:
sideshowbarker
2024-07-17 04:41:05 +09:00
Author: https://github.com/rtobar
Commit: e87fecf710
Pull-request: https://github.com/SerenityOS/serenity/pull/16496
4 changed files with 25 additions and 13 deletions
|
@ -319,7 +319,12 @@ 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, m_rendering_preferences));
|
||||
auto maybe_errors = PDF::Renderer::render(*m_document, page, bitmap, m_rendering_preferences);
|
||||
if (maybe_errors.is_error()) {
|
||||
auto errors = maybe_errors.release_error();
|
||||
on_render_errors(page_index, errors);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
if (page.rotate + m_rotations != 0) {
|
||||
int rotation_count = ((page.rotate + m_rotations) / 90) % 4;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue