1 /* poppler-link-extractor_p.h: qt interface to poppler
2  * Copyright (C) 2007, 2008, 2011, Pino Toscano <pino@kde.org>
3  * Copyright (C) 2008, Albert Astals Cid <aacid@kde.org>
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, or (at your option)
8  * 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
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "poppler-link-extractor-private.h"
21 
22 #include <GfxState.h>
23 #include <Link.h>
24 #include <Object.h>
25 #include <Page.h>
26 #include <Annot.h>
27 
28 #include "poppler-qt5.h"
29 #include "poppler-page-private.h"
30 
31 namespace Poppler {
32 
LinkExtractorOutputDev(PageData * data)33 LinkExtractorOutputDev::LinkExtractorOutputDev(PageData *data) : m_data(data)
34 {
35     Q_ASSERT(m_data);
36     ::Page *popplerPage = m_data->page;
37     m_pageCropWidth = popplerPage->getCropWidth();
38     m_pageCropHeight = popplerPage->getCropHeight();
39     if (popplerPage->getRotate() == 90 || popplerPage->getRotate() == 270)
40         qSwap(m_pageCropWidth, m_pageCropHeight);
41     GfxState gfxState(72.0, 72.0, popplerPage->getCropBox(), popplerPage->getRotate(), true);
42     setDefaultCTM(gfxState.getCTM());
43 }
44 
~LinkExtractorOutputDev()45 LinkExtractorOutputDev::~LinkExtractorOutputDev()
46 {
47     qDeleteAll(m_links);
48 }
49 
processLink(::AnnotLink * link)50 void LinkExtractorOutputDev::processLink(::AnnotLink *link)
51 {
52     if (!link->isOk())
53         return;
54 
55     double left, top, right, bottom;
56     int leftAux, topAux, rightAux, bottomAux;
57     link->getRect(&left, &top, &right, &bottom);
58     QRectF linkArea;
59 
60     cvtUserToDev(left, top, &leftAux, &topAux);
61     cvtUserToDev(right, bottom, &rightAux, &bottomAux);
62     linkArea.setLeft((double)leftAux / m_pageCropWidth);
63     linkArea.setTop((double)topAux / m_pageCropHeight);
64     linkArea.setRight((double)rightAux / m_pageCropWidth);
65     linkArea.setBottom((double)bottomAux / m_pageCropHeight);
66 
67     Link *popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea);
68     if (popplerLink) {
69         m_links.append(popplerLink);
70     }
71     OutputDev::processLink(link);
72 }
73 
links()74 QList<Link *> LinkExtractorOutputDev::links()
75 {
76     QList<Link *> ret = m_links;
77     m_links.clear();
78     return ret;
79 }
80 
81 }
82