1 #ifndef GENERIC_HPP
2 #define GENERIC_HPP
3 /*
4 Copyright © 2008-13 Qtrac Ltd. All rights reserved.
5 This program or module is free software: you can redistribute it
6 and/or modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation, either version 2 of
8 the License, or (at your option) any later version. This program is
9 distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 */
14
15 #include <poppler-qt5.h>
16 #include <QMetaType>
17 #include <QPair>
18 #include <QPixmap>
19 #include <QSet>
20
21 class QColor;
22 class QMimeData;
23 class QRectF;
24
25 #if QT_VERSION >= 0x040600
26 typedef QSharedPointer<Poppler::Document> PdfDocument;
27 typedef QSharedPointer<Poppler::Page> PdfPage;
28 typedef QSharedPointer<Poppler::TextBox> PdfTextBox;
29 #else
30 typedef std::tr1::shared_ptr<Poppler::Document> PdfDocument;
31 typedef std::tr1::shared_ptr<Poppler::Page> PdfPage;
32 typedef std::tr1::shared_ptr<Poppler::TextBox> PdfTextBox;
33 #endif
34 typedef QList<PdfTextBox> TextBoxList;
35
36 enum InitialComparisonMode{CompareAppearance=0, CompareCharacters=1,
37 CompareWords=2};
38
39 enum Debug{DebugOff, DebugShowTexts, DebugShowTextsAndYX};
40
41 const int POINTS_PER_INCH = 72;
42
43 typedef QSet<int> Ranges;
44 typedef QPair<Ranges, Ranges> RangesPair;
45
46 struct PagePair
47 {
PagePairPagePair48 PagePair(int l=-1, int r=-1, bool v=false)
49 : left(l), right(r), hasVisualDifference(v) {}
50
isNullPagePair51 bool isNull() { return left == -1 || right == -1; }
52
53 const int left;
54 const int right;
55 const bool hasVisualDifference;
56 };
Q_DECLARE_METATYPE(PagePair) const57 Q_DECLARE_METATYPE(PagePair)
58
59
60 inline const QChar canonicalizedCharacter(const QChar &in)
61 {
62 QChar out = in;
63 const ushort c = in.unicode();
64 switch (c) {
65 case 0x93: out = QChar(0x201C); break; // “
66 case 0x94: out = QChar(0x201D); break; // ”
67 case 0xAD: // fallthrough (soft-hyphen)
68 case 0x2D: // fallthrough (hyphen-minus)
69 case 0x2010: // fallthrough (hyphen)
70 case 0x2011: // fallthrough (non-breaking hyphen)
71 case 0x2043: out = '-'; break; // (hyphen-bullet)
72 }
73 return out;
74 }
75
76
77 void scaleRect(int dpi, QRectF *rect);
78 int pointValueForPixelOffset(const double dpi, int px);
79 int pixelOffsetForPointValue(const double dpi, int pt);
80 QRectF rectForMargins(const int width, const int height, const int top,
81 const int bottom, const int left, const int right);
82 Ranges unorderedRange(int end, int start=0);
83
84 QPixmap colorSwatch(const QColor &color);
85 QPixmap brushSwatch(const Qt::BrushStyle style, const QColor &color);
86 QPixmap penStyleSwatch(const Qt::PenStyle style, const QColor &color);
87
88 const TextBoxList getTextBoxes(PdfPage page, const QRectF &rect=QRect());
89
90 const QString strippedFilename(const QString &filename);
91 const QStringList droppedFilenames(const QMimeData *mimeData);
92 const QRect resizeRect(const QRect &pageRect, const QSize &pixmapSize);
93
94 /* // Not needed
95 const int roundedToNearest(const int x, const int multiple)
96 {
97 Q_ASSERT(multiple)
98 const int remainder = x % multiple;
99 return (remainder == 0) ? x : x + multiple - remainder;
100 }
101 */
102
103 #endif // GENERIC_HPP
104