Bug 161599 - Remove excessive whitespace when vewing
Summary: Remove excessive whitespace when vewing
Status: RESOLVED FIXED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-04 12:35 UTC by kde2eran
Modified: 2008-05-19 09:06 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch for trimming whitespace borders (77.73 KB, patch)
2008-05-04 12:37 UTC, kde2eran
Details
Proposed patch for trimming whitespace borders (77.75 KB, patch)
2008-05-08 17:26 UTC, kde2eran
Details
Proposed patch for trimming whitespace borders (71.41 KB, patch)
2008-05-18 19:10 UTC, kde2eran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kde2eran 2008-05-04 12:35:01 UTC
Version:           SVN (using KDE 3.5.9)
Installed from:    RedHat RPMs

Many PDF files have wide margins that, while suitable for printing on paper, are very wasteful of screen resources. This problem is especially grave with some academic publications that use enormous margins in their standard stylesheets.

Implications include:
* In Fit to Page zoom, wide vertical margins cause the real content of the page to be unnecessarily small (and at other zoom levels page flipping is messy)
* In Continous mode, wide vertical margins necessitate a lot of scrolling between pages, and you can see less content simultaneously at page borders
* In Two Pages mode, wide horizontal margins cause the real content to be unnecessarily small (often making this important mode useless)

It would be great if Okular had an option to automatically detect margins and to subtract them from the image, prior to calculation of zoom level and rendering. To cover the overwhelming majority of cases, it would suffice to just have a simple heuristic which identifies the maximal white strip at each of the 4 edges of the paper.

Related bugs:
- Bug 115557 for the same feature in KPDF.
- Bug 136695 for stripping whitespace when printing, as opposed to viewing.
Comment 1 kde2eran 2008-05-04 12:37:37 UTC
Created attachment 24624 [details]
Proposed patch for trimming whitespace borders

Here's a rough patch that implements a "Trim Borders" mode for Okular, where
most of the white borders are stripped from every page.

This patch does the following:

- Add a "bounding box" property to Okular::Page
- Teach most of the generators to compute the page's bounding box when the page
is first rendered, by scanning the rendered image (pixel-by-pixel) for white
borders.
- Add a "crop" property to PageViewItem
- Add support for rendering cropped pages to PageView, PagePainter and
PageViewAnnotator.
- Add a "Trim Borders" mode to PageView, with a menu item under View and a
config item.
- When "Trim Borders" is enabled, set PageViewItem's crop according to the
page's bounding box.
- A few local comments/cleanups to help the next guy looking at this code.

Open issues:
- All the things pointed out in the new "TODO" comments.
- Add "native" bounding box computation (instead of pixel scanning) to
generators, where possible.
- Since we only scan pixels after pixmaps are generated, the layout of far-away
parts of the document will not reflect the cropped geometry. This causes the
layout to jump around annoyingly as more pages become visible and are cropped.
- Maybe there be a mode where all pages are cropped identically, so that
displayed text sizes are uniform.
- Needs testing and performance profiling.
Comment 2 kde2eran 2008-05-08 17:26:54 UTC
Created attachment 24673 [details]
Proposed patch for trimming whitespace borders

Revised patch for trimming whitespace borders: same as the previous patch,
except for improved calculation of crop area.

(Can someone fix the typo in the bug's name?)
Comment 3 kde2eran 2008-05-18 19:10:01 UTC
Created attachment 24825 [details]
Proposed patch for trimming whitespace borders

Revised version addressing Pino's comments. Same functionality, better
implementation.
Comment 4 Pino Toscano 2008-05-19 02:37:43 UTC
SVN commit 809496 by pino:

Make it possible to draw just sections (crops within bounding boxes) of pages.
Separated normal & cropped geometries in page items;
made the page painter able to draw based on a crop section;
add a config + menu option for turning the white borders removal.

Based on a patch by the Mr. anonymous kde2eran@tromer.org, thanks.

BUG: 161599


 M  +3 -0      conf/okular.kcfg  
 M  +2 -1      part.rc  
 M  +33 -17    ui/pagepainter.cpp  
 M  +11 -0     ui/pagepainter.h  
 M  +163 -75   ui/pageview.cpp  
 M  +1 -0      ui/pageview.h  
 M  +13 -14    ui/pageviewannotator.cpp  
 M  +57 -20    ui/pageviewutils.cpp  
 M  +28 -6     ui/pageviewutils.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=809496
Comment 5 Pino Toscano 2008-05-19 09:05:59 UTC
SVN commit 809593 by pino:

Make the poppler(pdf), spectre(ps), dvi and chm backend calculate and set bounding box of pages.

CCBUG: 161599


 M  +3 -0      chm/generator_chm.cpp  
 M  +3 -0      dvi/generator_dvi.cpp  
 M  +11 -2     poppler/generator_pdf.cpp  
 M  +4 -0      spectre/generator_ghostview.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=809593