| 1 |
/* poppler-annotation-helper.h: qt interface to poppler |
| 2 |
* Copyright (C) 2006, 2008, 2017-2019, 2021, 2025, Albert Astals Cid <[email protected]> |
| 3 |
* Copyright (C) 2008, Pino Toscano <[email protected]> |
| 4 |
* Copyright (C) 2012, Fabio D'Urso <[email protected]> |
| 5 |
* Copyright (C) 2018, Dileep Sankhla <[email protected]> |
| 6 |
* Copyright (C) 2018, Carlos Garcia Campos <[email protected]> |
| 7 |
* Copyright (C) 2018, 2019, Oliver Sander <[email protected]> |
| 8 |
* Adapting code from |
| 9 |
* Copyright (C) 2004 by Enrico Ros <[email protected]> |
| 10 |
* |
| 11 |
* This program is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation; either version 2, or (at your option) |
| 14 |
* any later version. |
| 15 |
* |
| 16 |
* This program is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with this program; if not, write to the Free Software |
| 23 |
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef _POPPLER_ANNOTATION_HELPER_H_ |
| 27 |
#define _POPPLER_ANNOTATION_HELPER_H_ |
| 28 |
|
| 29 |
#include <memory> |
| 30 |
|
| 31 |
#include <QtCore/QDebug> |
| 32 |
#include <QtCore/QPointF> |
| 33 |
|
| 34 |
#include <Object.h> |
| 35 |
|
| 36 |
class QColor; |
| 37 |
|
| 38 |
class AnnotColor; |
| 39 |
|
| 40 |
namespace Poppler { |
| 41 |
|
| 42 |
class XPDFReader |
| 43 |
{ |
| 44 |
public: |
| 45 |
// transform from user coords to normalized ones using the matrix M |
| 46 |
static inline void transform(double *M, double x, double y, QPointF &res); |
| 47 |
static inline void invTransform(const double *M, const QPointF p, double &x, double &y); |
| 48 |
}; |
| 49 |
|
| 50 |
void XPDFReader::transform(double *M, double x, double y, QPointF &res) |
| 51 |
{ |
| 52 |
res.setX(M[0] * x + M[2] * y + M[4]); |
| 53 |
res.setY(M[1] * x + M[3] * y + M[5]); |
| 54 |
} |
| 55 |
|
| 56 |
void XPDFReader::invTransform(const double *M, const QPointF p, double &x, double &y) |
| 57 |
{ |
| 58 |
const double det = M[0] * M[3] - M[1] * M[2]; |
| 59 |
if (det == 0) { |
| 60 |
qWarning("Tried to invert singular matrix, something won't work"); |
| 61 |
x = 0; |
| 62 |
y = 0; |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
const double invM[4] = { M[3] / det, -M[1] / det, -M[2] / det, M[0] / det }; |
| 67 |
const double xt = p.x() - M[4]; |
| 68 |
const double yt = p.y() - M[5]; |
| 69 |
|
| 70 |
x = invM[0] * xt + invM[2] * yt; |
| 71 |
y = invM[1] * xt + invM[3] * yt; |
| 72 |
} |
| 73 |
|
| 74 |
QColor convertAnnotColor(const AnnotColor *color); |
| 75 |
std::unique_ptr<AnnotColor> convertQColor(const QColor &color); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
#endif |