Skip to content

Simplify pagepainter

This simplifies the code in PagePainter on an algorithmic level, but keeps the existing algorithms for annotation drawing. See the commit message for details.

I have tested this with 100% and 231.25% hiDPI, with PDF and JPG, with all annotation tools from the annotation toolbar, with rotated view, with trimmed view, and with different color modes. I think I have reimplemented the existing behavior quite accurate, and a user will not notice any changes. I intend to make some additional MRs which build on this simplification.

For reviewing part/pagepainter.cpp, I recommend side-by-side diff view. ;)


  • How to do performance tests?
  • Additional MRs (not blocking for this MR)
    • Respect color mode for the Magnifier mouse mode,
    • and several other cases were it is ignored.
    • Use a primitive pixmap cache for color mode modified tiles (huge performance improvement expected).
    • Move viewport highlighting code to PageView, because it does not have much to do with Okular::Page data.
    • Adapt some annotation drawing code. Many of them do not need to create new QImages only for painting a single line.
    • Use some QFlags.

Suggested squash commit message

Simplify PagePainter (on algorithmic level, and except annotation drawing)

This commit rewrites PagePainter::paintCroppedPageOnPainter() with these improvements:
 * Paint directly on the painter instead of on a buffer QImage in some cases.
   This unifies two parallel implementations of painting to only one implementation.
 * Use a painter in PageViewItem coordinate system, not in paint region coordinate system.
   This saves a lot of coordinate system conversions.
   Some storage structures can even be passed directly to QPainter.
 * Use range-for loops.
 * Do not create heap allocated temporary objects.
 * Do not create non-trivial temporary objects.
 * Parameters to paintPageOnPainter() do not contradict anymore.
 * Use several static methods.
   This saves a lot of temporary variables over hundreds of code lines,
   which should make future modifications easier.

The code for drawing annotations is copied without algorithmic changes.

The behavior of PagePainter is not changed.
The performance is about the same as before.
Edited by Laura David Hurka

Merge request reports