| 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 |
* Copyright (C) 2021, Oliver Sander <[email protected]> |
| 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 |
|
| 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 |
} |
| 43 |
GfxState gfxState(72.0, 72.0, popplerPage->getCropBox(), popplerPage->getRotate(), true); |
| 44 |
setDefaultCTM(gfxState.getCTM()); |
| 45 |
} |
| 46 |
|
| 47 |
LinkExtractorOutputDev::~LinkExtractorOutputDev() = default; |
| 48 |
|
| 49 |
void 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(&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 |
std::unique_ptr<Link> popplerLink = m_data->convertLinkActionToLink(link->getAction(), linkArea); |
| 68 |
if (popplerLink) { |
| 69 |
m_links.push_back(std::move(popplerLink)); |
| 70 |
} |
| 71 |
OutputDev::processLink(link); |
| 72 |
} |
| 73 |
|
| 74 |
std::vector<std::unique_ptr<Link>> LinkExtractorOutputDev::links() |
| 75 |
{ |
| 76 |
return std::move(m_links); |
| 77 |
} |
| 78 |
|
| 79 |
} |