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  * Copyright (C) 2021, Oliver Sander <oliver.sander@tu-dresden.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "poppler-link-extractor-private.h"
22 
23 #include <GfxState.h>
24 #include <Link.h>
25 #include <Object.h>
26 #include <Page.h>
27 #include <Annot.h>
28 
29 #include "poppler-qt6.h"
30 #include "poppler-page-private.h"
31 
32 namespace Poppler {
33 
LinkExtractorOutputDev(PageData * data)34 LinkExtractorOutputDev::LinkExtractorOutputDev(PageData *data) : m_data(data)
35 {
36     Q_ASSERT(m_data);
37     ::Page *popplerPage = m_data->page;
38     m_pageCropWidth = popplerPage->getCropWidth();
39     m_pageCropHeight = popplerPage->getCropHeight();
40     if (popplerPage->getRotate() == 90 || popplerPage->getRotate() == 270)
41         qSwap(m_pageCropWidth, m_pageCropHeight);
42     GfxState gfxState(72.0, 72.0, popplerPage->getCropBox(), popplerPage->getRotate(), true);
43     setDefaultCTM(gfxState.getCTM());
44 }
45 
~LinkExtractorOutputDev()46 LinkExtractorOutputDev::~LinkExtractorOutputDev() { }
47 
processLink(::AnnotLink * link)48 void LinkExtractorOutputDev::processLink(::AnnotLink *link)
49 {
50     if (!link->isOk())
51         return;
52 
53     double left, top, right, bottom;
54     int leftAux, topAux, rightAux, bottomAux;
55     link->getRect(&left, &top, &right, &bottom);
56     QRectF linkArea;
57 
58     cvtUserToDev(left, top, &leftAux, &topAux);
59     cvtUserToDev(right, bottom, &rightAux, &bottomAux);
60     linkArea.setLeft((double)leftAux / m_pageCropWidth);
61     linkArea.setTop((double)topAux / m_pageCropHeight);
62     linkArea.setRight((double)rightAux / m_pageCropWidth);
63     linkArea.setBottom((double)bottomAux / m_pageCropHeight);
64 
65     std::unique_ptr<Link> popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea);
66     if (popplerLink) {
67         m_links.push_back(std::move(popplerLink));
68     }
69     OutputDev::processLink(link);
70 }
71 
links()72 std::vector<std::unique_ptr<Link>> LinkExtractorOutputDev::links()
73 {
74     return std::move(m_links);
75 }
76 
77 }
78