1 | /* poppler-annotation-helper.h: qt interface to poppler |
---|---|

2 | * Copyright (C) 2006, 2008, 2017-2019, 2021, Albert Astals Cid <aacid@kde.org> |

3 | * Copyright (C) 2008, Pino Toscano <pino@kde.org> |

4 | * Copyright (C) 2012, Fabio D'Urso <fabiodurso@hotmail.it> |

5 | * Copyright (C) 2018, Dileep Sankhla <sankhla.dileep96@gmail.com> |

6 | * Copyright (C) 2018, Carlos Garcia Campos <carlosgc@gnome.org> |

7 | * Copyright (C) 2018, 2019, Oliver Sander <oliver.sander@tu-dresden.de> |

8 | * Adapting code from |

9 | * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> |

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 | |

33 | #include <Object.h> |

34 | |

35 | class QColor; |

36 | |

37 | class AnnotColor; |

38 | |

39 | namespace Poppler { |

40 | |

41 | class XPDFReader |

42 | { |

43 | public: |

44 | // transform from user coords to normalized ones using the matrix M |

45 | static inline void transform(double *M, double x, double y, QPointF &res); |

46 | static inline void invTransform(const double *M, const QPointF p, double &x, double &y); |

47 | }; |

48 | |

49 | void XPDFReader::transform(double *M, double x, double y, QPointF &res) |

50 | { |

51 | res.setX(M[0] * x + M[2] * y + M[4]); |

52 | res.setY(M[1] * x + M[3] * y + M[5]); |

53 | } |

54 | |

55 | void XPDFReader::invTransform(const double *M, const QPointF p, double &x, double &y) |

56 | { |

57 | const double det = M[0] * M[3] - M[1] * M[2]; |

58 | if (det == 0) { |

59 | qWarning(msg: "Tried to invert singular matrix, something won't work"); |

60 | x = 0; |

61 | y = 0; |

62 | return; |

63 | } |

64 | |

65 | const double invM[4] = { M[3] / det, -M[1] / det, -M[2] / det, M[0] / det }; |

66 | const double xt = p.x() - M[4]; |

67 | const double yt = p.y() - M[5]; |

68 | |

69 | x = invM[0] * xt + invM[2] * yt; |

70 | y = invM[1] * xt + invM[3] * yt; |

71 | } |

72 | |

73 | QColor convertAnnotColor(const AnnotColor *color); |

74 | std::unique_ptr<AnnotColor> convertQColor(const QColor &color); |

75 | |

76 | } |

77 | |

78 | #endif |

79 |