File: generic.hpp

package info (click to toggle)
diffpdf 2.1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,020 kB
  • sloc: cpp: 3,374; makefile: 16
file content (103 lines) | stat: -rw-r--r-- 3,281 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef GENERIC_HPP
#define GENERIC_HPP
/*
    Copyright © 2008-13 Qtrac Ltd. All rights reserved.
    This program or module is free software: you can redistribute it
    and/or modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation, either version 2 of
    the License, or (at your option) any later version. This program is
    distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    for more details.
*/

#include <poppler-qt5.h>
#include <QMetaType>
#include <QPair>
#include <QPixmap>
#include <QSet>

class QColor;
class QMimeData;
class QRectF;

#if QT_VERSION >= 0x040600
typedef QSharedPointer<Poppler::Document> PdfDocument;
typedef QSharedPointer<Poppler::Page> PdfPage;
typedef QSharedPointer<Poppler::TextBox> PdfTextBox;
#else
typedef std::tr1::shared_ptr<Poppler::Document> PdfDocument;
typedef std::tr1::shared_ptr<Poppler::Page> PdfPage;
typedef std::tr1::shared_ptr<Poppler::TextBox> PdfTextBox;
#endif
typedef QList<PdfTextBox> TextBoxList;

enum InitialComparisonMode{CompareAppearance=0, CompareCharacters=1,
                           CompareWords=2};

enum Debug{DebugOff, DebugShowTexts, DebugShowTextsAndYX};

const int POINTS_PER_INCH = 72;

typedef QSet<int> Ranges;
typedef QPair<Ranges, Ranges> RangesPair;

struct PagePair
{
    PagePair(int l=-1, int r=-1, bool v=false)
        : left(l), right(r), hasVisualDifference(v) {}

    bool isNull() { return left == -1 || right == -1; }

    const int left;
    const int right;
    const bool hasVisualDifference;
};
Q_DECLARE_METATYPE(PagePair)


inline const QChar canonicalizedCharacter(const QChar &in)
{
    QChar out = in;
    const ushort c = in.unicode();
    switch (c) {
        case 0x93:   out = QChar(0x201C); break; // “
        case 0x94:   out = QChar(0x201D); break; // ”
        case 0xAD:   // fallthrough (soft-hyphen)
        case 0x2D:   // fallthrough (hyphen-minus)
        case 0x2010: // fallthrough (hyphen)
        case 0x2011: // fallthrough (non-breaking hyphen)
        case 0x2043: out = '-'; break; // (hyphen-bullet)
    }
    return out;
}


void scaleRect(int dpi, QRectF *rect);
int pointValueForPixelOffset(const double dpi, int px);
int pixelOffsetForPointValue(const double dpi, int pt);
QRectF rectForMargins(const int width, const int height, const int top,
        const int bottom, const int left, const int right);
Ranges unorderedRange(int end, int start=0);

QPixmap colorSwatch(const QColor &color);
QPixmap brushSwatch(const Qt::BrushStyle style, const QColor &color);
QPixmap penStyleSwatch(const Qt::PenStyle style, const QColor &color);

const TextBoxList getTextBoxes(PdfPage page, const QRectF &rect=QRect());

const QString strippedFilename(const QString &filename);
const QStringList droppedFilenames(const QMimeData *mimeData);
const QRect resizeRect(const QRect &pageRect, const QSize &pixmapSize);

/* // Not needed
const int roundedToNearest(const int x, const int multiple)
{
    Q_ASSERT(multiple)
    const int remainder = x % multiple;
    return (remainder == 0) ? x : x + multiple - remainder;
}
*/

#endif // GENERIC_HPP