Commit graph

20 commits

Author SHA1 Message Date
Nico Weber 21917e7b1e LibPDF+PDFViewer+MacPDF: Don't draw hidden text by default
Text can be rendered in various ways in PDFs: Filled, stroked,
both filled and stroked, set as clipping path, hidden, or
some combinations thereof.

We don't implement any of this at the moment except "filled".

Hidden text is used in scanned documents: The image of the scan is
drawn in the background, and then OCRd text is "drawn" as hidden
on top of the scanned bitmap. That way, the (hidden) text can be
selected and copied, and it looks like you're selecting text from
the scanned bitmap. Find-in-page also works similarly. (We currently
have neither text selection nor find-in-page, but one day we will.)

Now that we have pretty good support for CCITT and are growing some
support for JBIG2, we now draw both the scanned background image
as well as the foreground text. They're not always perfectly aligned.

This change makes it so that we don't render text that's marked as
hidden. (We still do most of the coordinate math, which will probably
come in handy at some point when we implement text selection.)

This makes these scanned documents appear as they're supposed to
appear (at least in documents where we manage to decode the background
bitmap).

This also adds a debug option to force rendering of hidden text.
2024-03-16 13:10:48 -04:00
Kyle Lanmon a099d0e140 PDFViewer: Hide the rendering diagnostics window by default
You can enable it in the Debug menu and we will remember your choice.
2024-03-04 10:43:41 +01:00
Nico Weber d9267a388d PDFViewer: Add Debug menu entries for disabling clipping 2024-01-21 09:32:22 -05:00
Rodrigo Tobar e87fecf710 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.
2022-12-16 10:04:23 +01:00
Rodrigo Tobar 67b50d7994 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.
2022-12-10 10:49:03 +01:00
Rodrigo Tobar bc7da24fe6 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.
2022-11-25 23:03:24 +01:00
Matthew Olsson baac720e13 PDFViewer: Respect page navigation features in multi-page mode
This includes the text box and the page up/down arrows.
2022-04-04 14:59:37 +02:00
Matthew Olsson 3ecb41b7d9 PDFViewer: Support a continuous page view mode 2022-04-04 14:59:37 +02:00
Matthew Olsson 091c2cfdca PDFViewer: Add page mode option 2022-04-04 14:59:37 +02:00
Matthew Olsson b2f79a74d4 PDFViewer: Clear rendered page cache on application resize
When resizing the application, the pages are expected to grow or shrink
proportionally. This means that after a resize, we need to rerender
every page.
2022-04-04 14:59:37 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Matthew Olsson b240d23a87 LibPDF: Propagate errors in Renderer/PDFViewer 2022-03-07 10:53:57 +01:00
Lenny Maiorani 1dd70a6f49 Applications: Change static constexpr variables to constexpr
Function-local `static constexpr` variables can be `constexpr`. This
can reduce memory consumption, binary size, and offer additional
compiler optimizations.
2022-02-28 13:54:27 +01:00
Marcus Nilsson eb97617ff0 PDFViewer: Add actions to rotate the displayed PDF
This implements the rotate cw/ccw actions in PDFViewer.
Since the rendered pages are stored in a HashMap for caching,
the bitmap is wrapped in a struct with the current rotation.
This way the caching works as expected while zooming, and a new bitmap
is rendered when the page is rotated.
2022-01-06 21:25:02 +01:00
Marcus Nilsson 56bec4968c PDFViewer: Enable panning with middle mouse button
Enable the use of the middle mouse button for panning in PDFViewer.
2022-01-06 21:25:02 +01:00
Marcus Nilsson 3af71c406d PDFViewer: Add zoom in/out/reset menu actions
Make PDFViewer::zoom_in() & ::zoom_out() public and add menu and toolbar
actions. Also add an action for zoom reset.
2022-01-06 21:25:02 +01:00
FalseHonesty 4f0a75224c PDFViewer: Update the page number when scrolling between pages 2021-06-22 06:26:44 +04:30
Matthew Olsson cf3eb27108 PDFViewer: Add a toolbar
The toolbar has an option to toggle the sidebar, a number input to
set the current page, and two buttons to go up and down by one page
2021-05-25 00:24:09 +04:30
Matthew Olsson c3c2121b57 PDFViewer: Allow zooming in and out + scrolling
When holding ctrl and scrolling, the page will be zoomed in an out.
When zoomed in on a page, scrolling with move vertically up and down
the page (or horizontally if shift is being held).

In order to speed up zooming, zoomed bitmaps are cached per-page at
each distinct zoom level. This cache is cleared every 30 seconds to
prevent OOM problems.
2021-05-18 16:35:23 +02:00
Matthew Olsson f7ea1eb610 Applications: Add a very simple PDFViewer 2021-05-18 16:35:23 +02:00