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
32namespace Poppler {
33
34LinkExtractorOutputDev::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(value1&: m_pageCropWidth, value2&: m_pageCropHeight);
42 }
43 GfxState gfxState(72.0, 72.0, popplerPage->getCropBox(), popplerPage->getRotate(), true);
44 setDefaultCTM(gfxState.getCTM());
45}
46
47LinkExtractorOutputDev::~LinkExtractorOutputDev() { }
48
49void LinkExtractorOutputDev::processLink(::AnnotLink *link)
50{
51 if (!link->isOk()) {
52 return;
53 }
54
55 double left, top, right, bottom;
56 int leftAux, topAux, rightAux, bottomAux;
57 link->getRect(x1: &left, y1: &top, x2: &right, y2: &bottom);
58 QRectF linkArea;
59
60 cvtUserToDev(ux: left, uy: top, dx: &leftAux, dy: &topAux);
61 cvtUserToDev(ux: right, uy: bottom, dx: &rightAux, dy: &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 std::unique_ptr<Link> popplerLink = m_data->convertLinkActionToLink(a: link->getAction(), linkArea);
68 if (popplerLink) {
69 m_links.push_back(x: std::move(popplerLink));
70 }
71 OutputDev::processLink(link);
72}
73
74std::vector<std::unique_ptr<Link>> LinkExtractorOutputDev::links()
75{
76 return std::move(m_links);
77}
78
79}
80

source code of poppler/qt6/src/poppler-link-extractor.cc