1 /*
2 dspdfviewer - Dual Screen PDF Viewer for LaTeX-Beamer
3 Copyright (C) 2012 Danny Edel <mail@danny-edel.de>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20
21 #include "renderthread.h"
22 #include "renderutils.h"
23 #include "adjustedlink.h"
24 #include "debug.h"
25
RenderThread(const PDFDocumentReference & theDocument,const RenderingIdentifier & renderIdent)26 RenderThread::RenderThread(const PDFDocumentReference& theDocument, const RenderingIdentifier& renderIdent):
27 QObject(),
28 QRunnable(),
29 m_page( theDocument.page( renderIdent.pageNumber() ) ),
30 renderMe(renderIdent)
31 {
32 }
33
run()34 void RenderThread::run()
35 {
36 DEBUGOUT << "RenderThread for" << renderMe << "started";
37 QImage renderImage = RenderUtils::renderPagePart(m_page.page, renderMe.requestedPageSize(), renderMe.pagePart());
38 if ( renderImage.isNull() )
39 {
40 WARNINGOUT << "RenderThread for" << renderMe << "failed";
41 QSharedPointer<RenderingIdentifier> ri( new RenderingIdentifier(renderMe) );
42 emit renderingFailed(ri);
43 return;
44 }
45
46 QList< AdjustedLink > links;
47
48 for( Poppler::Link* link: m_page.page->links() )
49 {
50 QSharedPointer<Poppler::Link> ptrLink(link);
51 try{
52 AdjustedLink al(renderMe, ptrLink);
53 links.append(al);
54 } catch( AdjustedLink::OutsidePage &) {
55 // no-op
56 }
57 }
58 QSharedPointer<RenderedPage> renderResult(new RenderedPage( renderImage, links, renderMe ));
59 DEBUGOUT << "RenderThread for" << renderMe << "successful, image has size" << renderResult->getImage().size();
60 emit renderingFinished(renderResult);
61 }
62