Bug 105796 - Render a single annotation with Qt5 frontend
Summary: Render a single annotation with Qt5 frontend
Status: RESOLVED MOVED
Alias: None
Product: poppler
Classification: Unclassified
Component: qt frontend (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-29 06:20 UTC by Tobias Deiminger
Modified: 2018-08-21 11:16 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Move Qt5 output device code out of poppler-page.cc (19.35 KB, patch)
2018-03-29 06:28 UTC, Tobias Deiminger
Details | Splinter Review
Factor out render setup (26.05 KB, patch)
2018-03-29 06:36 UTC, Tobias Deiminger
Details | Splinter Review
New API: Add Annotation::renderToImage to Qt5 frontend (10.22 KB, patch)
2018-03-29 06:45 UTC, Tobias Deiminger
Details | Splinter Review
Move Qt5 output device code out of poppler-page.cc (rev 2) (12.79 KB, patch)
2018-05-01 15:58 UTC, Tobias Deiminger
Details | Splinter Review
Factor out render setup (rev 2) (23.80 KB, patch)
2018-05-01 16:01 UTC, Tobias Deiminger
Details | Splinter Review
New API: Add Annotation::renderToImage to Qt5 frontend (rev 2) (10.40 KB, patch)
2018-05-01 16:13 UTC, Tobias Deiminger
Details | Splinter Review

Description Tobias Deiminger 2018-03-29 06:20:08 UTC
This is the Qt double of bug 83642. It adds Annotation::renderToImage() and similar methods.

The patch series has following use cases in mind:
-show realistic preview of icons in readers
-WYSIWYG editing of free text annotations, e.g. typewriter
-paint annotations while dragging them around (render page is expensive)
-extract single annotations from PDF with a command line tool
-enable composition of annotations in readers; quite tricky, due to blend mode, z-order and the ilk

Example usage:
...
  /* Generate image where annotation #0 is painted at offset (0,0) on transparent background. */
  Poppler::Annotation* annot = pdfPage->annotations()[0];
  QImage img = annot->renderToImage(myDpiX, myDpiY);
...

I'd recommend to fix bug 105692 along with these patches, to get the size right in all circumstances.
Comment 1 Tobias Deiminger 2018-03-29 06:28:43 UTC
Created attachment 138408 [details] [review]
Move Qt5 output device code out of poppler-page.cc

Qt5SplashOutputDev, OutputDevCallbackHelper and QImageDumpingArthurOutputDev had been defined only locally in poppler-page.cc. Factor them out to be reusable by other source files. They're in one file along with ArthurOutputDev now.

Based on master c7a3176.
Comment 2 Tobias Deiminger 2018-03-29 06:36:02 UTC
Created attachment 138409 [details] [review]
Factor out render setup

Encapsulates special handling of Arthur vs. Splash in new classes in Qt5OutputDevices.cc. Shifting this stuff away makes the code reusable from outside poppler-page.cc, and it leaves the logic regarding Page::renderToImage clearer.

Based on attachment 138408 [details] [review]
Comment 3 Tobias Deiminger 2018-03-29 06:45:34 UTC
Created attachment 138410 [details] [review]
New API: Add Annotation::renderToImage to Qt5 frontend

The first new public functionality in this series. Annotation::renderToImage renders the closed state of the "normal" appearance. It's drawn onto transparent background, at offset (0,0) and size determined by Annot Rect + DPI settings. Resulting QImage is in Format_ARGB32_Premultiplied format.

Based on attachment 138409 [details] [review].
Comment 4 Albert Astals Cid 2018-04-02 10:39:26 UTC
(In reply to Tobias Deiminger from comment #1)
> Created attachment 138408 [details] [review] [review]
> Move Qt5 output device code out of poppler-page.cc
> 
> Qt5SplashOutputDev, OutputDevCallbackHelper and QImageDumpingArthurOutputDev
> had been defined only locally in poppler-page.cc. Factor them out to be
> reusable by other source files. They're in one file along with
> ArthurOutputDev now.
> 
> Based on master c7a3176.

ArthurOutputDev is quite complex as it is now, I don't think it's a good idea to add more stuff to that file.

If you want to make those classes available for other files, i'd say poppler-private.h is more a nice place to have them if you don't want to add a new file altogether.
Comment 5 Tobias Deiminger 2018-05-01 15:58:41 UTC
Created attachment 139250 [details] [review]
Move Qt5 output device code out of poppler-page.cc (rev 2)

> ArthurOutputDev is quite complex as it is now, I don't think it's a good idea to > add more stuff to that file.

Leave ArthurOutputDev as it was. Move Qt5SplashOutputDev, OutputDevCallbackHelper and QImageDumpingArthurOutputDev to poppler-private.{cc,h} instead.

Rebased on master 60b4fe6.
Comment 6 Tobias Deiminger 2018-05-01 16:01:43 UTC
Created attachment 139251 [details] [review]
Factor out render setup (rev 2)

Rebased on patch1_move_qt5outputdev_r2.patch.
Comment 7 Tobias Deiminger 2018-05-01 16:13:29 UTC
Created attachment 139252 [details] [review]
New API: Add Annotation::renderToImage to Qt5 frontend (rev 2)

Add copyXRef option to PDFDoc::displayAnnot for thread safety.

It took me while to figure out what the copyXRef argument in Page::displaySlice is about. Commit 8eb489c355d734a72e140ce7e32470d048362499 and bug #50992 explain it. Now I do something similar for PDFDoc::displayAnnot. Arthur gets copyXRef=gFalse (i.e. no thread safety), because QT restricts painting to the main thread anyway.

Sidenotes:
* Maybe we should add a few comments or documentation, to explain copyXRef in Page::displaySlice?
* In Page::displaySlice the Page object and relevant members are temporarily pointed to a XRef copy, and Gfx is constructed with that copy. When Annot::draw is called, the Annot object is supposed to use the passed gfx->getXRef instead of member Annot::xref. Only gfx->getXRef points to the copy. When working on Annot, imho it's not obvious that only gfx->getXRef is thread safe and therefore that's not newbie-safe:)

Rebased on patch2_reusable_render_setup_r2.patch.

(Sorry, I messed up the "obsoletes" checkboxes, now patch3-rev2 obsoletes patch2-rev1, and patch2-rev2 obsoletes patch3-rev1. Should have been the other way round.)
Comment 8 GitLab Migration User 2018-08-21 11:11:36 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/poppler/poppler/issues/563.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.