peerdavid / remapy

An open source explorer for your remarkable tablet to show, upload or delete files via the remarkable cloud.
Apache License 2.0
174 stars 19 forks source link

Page size adjustment #57

Closed NiklasKappel closed 2 years ago

NiklasKappel commented 2 years ago

Fixes issue #34 Fixes issue #35

Disclaimer: When running python -m tests.annotation_test with my changes, the test output seems to contain misaligned annotations. However, I can not reproduce these misalignments with any PDF files I annotate on my reMarkable. Please let me know if either the tests are outdated or if you can create misaligned annotations with my changes.

Changes: I reorganized the code in render._render_rm_file into the following process:

  1. We loop over the reMarkable file and collect all layer/stroke/segment data into lists/dictionaries.
  2. We inspect the data to determine a canvas width/height and offset. The canvas width/height is the width/height of the smallest rectangle that contains both the original PDF page and all annotations. The canvas offset is used to translate the canvas, so that annotations at negative coordinates are correctly drawn onto the canvas.
  3. We then deal with snapped highlights, draw regular highlight strokes and then all other strokes in this order.
  4. The function returns the canvas offset to render.pdf, which uses the offset to properly align the original PDF page and merges that under the larger annotation page.

Result: PDF annotations that are written arbitrarily far away from the original content of the document, even when using the reMarkable's "adjust view" function are now rendered correctly. Individual pages of the rendered PDF are increased in size if necessary to fit all annotations

test.pdf .

peerdavid commented 2 years ago

Thanks a lot for the improvements :)