Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpdfdocument_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPDFDOCUMENT_P_H
5#define QPDFDOCUMENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qpdfdocument.h"
19#include "qtpdfexports.h"
20
21#include "third_party/pdfium/public/fpdfview.h"
22#include "third_party/pdfium/public/fpdf_dataavail.h"
23
24#include <QtCore/qbuffer.h>
25#include <QtCore/qmutex.h>
26#include <QtCore/qpointer.h>
27#include <QtNetwork/qnetworkreply.h>
28
29#include <mutex>
30
31QT_BEGIN_NAMESPACE
32
33class QPdfMutexLocker : public std::unique_lock<QRecursiveMutex>
34{
35public:
36 QPdfMutexLocker();
37};
38
39class QPdfPageModel;
40
41class Q_PDF_EXPORT QPdfDocumentPrivate: public FPDF_FILEACCESS, public FX_FILEAVAIL, public FX_DOWNLOADHINTS
42{
43public:
44 QPdfDocumentPrivate();
45 ~QPdfDocumentPrivate();
46
47 QPdfDocument *q;
48 QPdfPageModel *pageModel = nullptr;
49
50 FPDF_AVAIL avail;
51 FPDF_DOCUMENT doc;
52 bool loadComplete;
53
54 QPointer<QIODevice> device;
55 QScopedPointer<QIODevice> ownDevice;
56 QBuffer asyncBuffer;
57 QPointer<QIODevice> sequentialSourceDevice;
58 QByteArray password;
59
60 QPdfDocument::Status status;
61 QPdfDocument::Error lastError;
62 int pageCount;
63
64 void clear();
65
66 void load(QIODevice *device, bool ownDevice);
67 void loadAsync(QIODevice *device);
68
69 void _q_tryLoadingWithSizeFromContentHeader();
70 void initiateAsyncLoadWithTotalSizeKnown(quint64 totalSize);
71 void _q_copyFromSequentialSourceDevice();
72 void tryLoadDocument();
73 void checkComplete();
74 bool checkPageComplete(int page);
75 void setStatus(QPdfDocument::Status status);
76
77 static FPDF_BOOL fpdf_IsDataAvail(struct _FX_FILEAVAIL* pThis, size_t offset, size_t size);
78 static int fpdf_GetBlock(void* param, unsigned long position, unsigned char* pBuf, unsigned long size);
79 static void fpdf_AddSegment(struct _FX_DOWNLOADHINTS* pThis, size_t offset, size_t size);
80 void updateLastError();
81 QString getText(FPDF_TEXTPAGE textPage, int startIndex, int count) const;
82 QPointF getCharPosition(FPDF_PAGE pdfPage, FPDF_TEXTPAGE textPage, int charIndex) const;
83 QRectF getCharBox(FPDF_PAGE pdfPage, FPDF_TEXTPAGE textPage, int charIndex) const;
84 QPointF mapPageToView(FPDF_PAGE pdfPage, double x, double y) const;
85 QRectF mapPageToView(FPDF_PAGE pdfPage, double left, double top, double right, double bottom) const;
86 QPointF mapViewToPage(FPDF_PAGE pdfPage, QPointF position) const;
87
88 // FPDF takes the rotation parameter as an int.
89 // This enum is mapping the int values defined in fpdfview.h:956.
90 // (not using enum class to ensure int convertability)
91 enum QFPDFRotation {
92 Normal = 0,
93 ClockWise90 = 1,
94 ClockWise180 = 2,
95 CounterClockWise90 = 3
96 };
97
98 static constexpr QFPDFRotation toFPDFRotation(QPdfDocumentRenderOptions::Rotation rotation)
99 {
100 switch (rotation) {
101 case QPdfDocumentRenderOptions::Rotation::None:
102 return QFPDFRotation::Normal;
103 case QPdfDocumentRenderOptions::Rotation::Clockwise90:
104 return QFPDFRotation::ClockWise90;
105 case QPdfDocumentRenderOptions::Rotation::Clockwise180:
106 return QFPDFRotation::ClockWise180;
107 case QPdfDocumentRenderOptions::Rotation::Clockwise270:
108 return QFPDFRotation::CounterClockWise90;
109 }
110 Q_UNREACHABLE();
111 }
112
113 struct TextPosition {
114 QPointF position;
115 qreal height = 0;
116 int charIndex = -1;
117 };
118 TextPosition hitTest(int page, QPointF position);
119};
120
121QT_END_NAMESPACE
122
123#endif // QPDFDOCUMENT_P_H
The QPdfBookmarkModel class holds a tree of of links (anchors) within a PDF document,...
The QPdfDocument class loads a PDF document and renders pages from it.
Combined button and popup list for selecting options.
QHash< int, QByteArray > m_roleNames
QPointer< QPdfDocument > m_document
void appendChildNode(BookmarkNode *parentBookmarkNode, FPDF_BOOKMARK parentBookmark, int level, FPDF_DOCUMENT document)
QScopedPointer< BookmarkNode > m_rootNode