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.
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.
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]
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].
(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.
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.
Created attachment 139251 [details] [review] Factor out render setup (rev 2) Rebased on patch1_move_qt5outputdev_r2.patch.
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.)
-- 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.