Debian Codegraph @

qt5/src/poppler-link-extractor.cc

raw
1 /* poppler-link-extractor_p.h: qt interface to poppler
2 * Copyright (C) 2007, 2008, 2011, Pino Toscano <[email protected]>
3 * Copyright (C) 2008, Albert Astals Cid <[email protected]>
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
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 }
42 GfxState gfxState(72.0, 72.0, popplerPage->getCropBox(), popplerPage->getRotate(), true);
43 setDefaultCTM(gfxState.getCTM());
44 }
45
46 LinkExtractorOutputDev::~LinkExtractorOutputDev()
47 {
48 qDeleteAll(m_links);
49 }
50
51 void LinkExtractorOutputDev::processLink(::AnnotLink *link)
52 {
53 if (!link->isOk()) {
54 return;
55 }
56
57 double left, top, right, bottom;
58 int leftAux, topAux, rightAux, bottomAux;
59 link->getRect(&left, &top, &right, &bottom);
60 QRectF linkArea;
61
62 cvtUserToDev(left, top, &leftAux, &topAux);
63 cvtUserToDev(right, bottom, &rightAux, &bottomAux);
64 linkArea.setLeft((double)leftAux / m_pageCropWidth);
65 linkArea.setTop((double)topAux / m_pageCropHeight);
66 linkArea.setRight((double)rightAux / m_pageCropWidth);
67 linkArea.setBottom((double)bottomAux / m_pageCropHeight);
68
69 Link *popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea);
70 if (popplerLink) {
71 m_links.append(popplerLink);
72 }
73 OutputDev::processLink(link);
74 }
75
76 QList<Link *> LinkExtractorOutputDev::links()
77 {
78 QList<Link *> ret = m_links;
79 m_links.clear();
80 return ret;
81 }
82
83 }