LibreOffice Module vcl (master)  1
PDFiumLibrary.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #pragma once
12 
13 #include <memory>
14 
15 #include <com/sun/star/util/DateTime.hpp>
16 
17 #include <vcl/dllapi.h>
22 #include <rtl/ustring.hxx>
23 #include <tools/color.hxx>
24 #include <tools/gen.hxx>
25 #include <vcl/checksum.hxx>
26 #include <vcl/Scanline.hxx>
33 #include <vcl/pdf/PDFFillMode.hxx>
34 #include <vcl/pdf/PDFFindFlags.hxx>
35 #include <vcl/pdf/PDFErrorType.hxx>
36 
37 class SvMemoryStream;
38 
39 namespace vcl::pdf
40 {
41 inline constexpr OStringLiteral constDictionaryKeyTitle = "T";
42 inline constexpr OStringLiteral constDictionaryKeyContents = "Contents";
43 inline constexpr OStringLiteral constDictionaryKeyPopup = "Popup";
44 inline constexpr OStringLiteral constDictionaryKeyModificationDate = "M";
45 inline constexpr OStringLiteral constDictionaryKeyInteriorColor = "IC";
46 
47 class PDFiumBitmap;
48 class PDFiumDocument;
49 class PDFiumPageObject;
50 
52 {
53 public:
54  virtual ~PDFium() = default;
55 
56  virtual const OUString& getLastError() const = 0;
57 
58  virtual std::unique_ptr<PDFiumDocument> openDocument(const void* pData, int nSize) = 0;
59  virtual PDFErrorType getLastErrorCode() = 0;
60  virtual std::unique_ptr<PDFiumBitmap> createBitmap(int nWidth, int nHeight, int nAlpha) = 0;
61 };
62 
63 class PDFiumPage;
64 
66 {
67 public:
68  virtual ~PDFiumBitmap() = default;
69  virtual void fillRect(int left, int top, int width, int height, sal_uInt32 nColor) = 0;
70  virtual void renderPageBitmap(PDFiumDocument* pDoc, PDFiumPage* pPage, int nStartX, int nStartY,
71  int nSizeX, int nSizeY)
72  = 0;
73  virtual ConstScanline getBuffer() = 0;
74  virtual int getStride() = 0;
75  virtual int getWidth() = 0;
76  virtual int getHeight() = 0;
77  virtual PDFBitmapType getFormat() = 0;
78 };
79 
81 {
82 public:
83  virtual ~PDFiumAnnotation() = default;
84  virtual PDFAnnotationSubType getSubType() = 0;
85  virtual basegfx::B2DRectangle getRectangle() = 0;
86  virtual bool hasKey(OString const& rKey) = 0;
87  virtual PDFObjectType getValueType(OString const& rKey) = 0;
88  virtual OUString getString(OString const& rKey) = 0;
89  virtual std::unique_ptr<PDFiumAnnotation> getLinked(OString const& rKey) = 0;
90  virtual int getObjectCount() = 0;
91  virtual std::unique_ptr<PDFiumPageObject> getObject(int nIndex) = 0;
92  virtual std::vector<std::vector<basegfx::B2DPoint>> getInkStrokes() = 0;
93  virtual std::vector<basegfx::B2DPoint> getVertices() = 0;
94  virtual Color getColor() = 0;
95  virtual Color getInteriorColor() = 0;
96  virtual float getBorderWidth() = 0;
97  virtual basegfx::B2DSize getBorderCornerRadius() = 0;
98  virtual size_t getAttachmentPointsCount() = 0;
99  virtual std::vector<basegfx::B2DPoint> getAttachmentPoints(size_t nIndex) = 0;
100  virtual std::vector<basegfx::B2DPoint> getLineGeometry() = 0;
101 };
102 
103 class PDFiumTextPage;
104 
106 {
107 public:
108  virtual ~PDFiumPathSegment() = default;
109  virtual basegfx::B2DPoint getPoint() const = 0;
110  virtual bool isClosed() const = 0;
111  virtual PDFSegmentType getType() const = 0;
112 };
113 
115 {
116 public:
117  virtual ~PDFiumPageObject() = default;
118 
119  virtual PDFPageObjectType getType() = 0;
120  virtual OUString getText(std::unique_ptr<PDFiumTextPage> const& pTextPage) = 0;
121 
122  virtual int getFormObjectCount() = 0;
123  virtual std::unique_ptr<PDFiumPageObject> getFormObject(int nIndex) = 0;
124 
125  virtual basegfx::B2DHomMatrix getMatrix() = 0;
126  virtual basegfx::B2DRectangle getBounds() = 0;
127  virtual double getFontSize() = 0;
128  virtual OUString getFontName() = 0;
129  virtual PDFTextRenderMode getTextRenderMode() = 0;
130  virtual Color getFillColor() = 0;
131  virtual Color getStrokeColor() = 0;
132  virtual double getStrokeWidth() = 0;
133  // Path
134  virtual int getPathSegmentCount() = 0;
135  virtual std::unique_ptr<PDFiumPathSegment> getPathSegment(int index) = 0;
136  virtual Size getImageSize(PDFiumPage& rPage) = 0;
137  virtual std::unique_ptr<PDFiumBitmap> getImageBitmap() = 0;
138  virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
139 };
140 
142 {
143 public:
144  virtual ~PDFiumSearchHandle() = default;
145 
146  virtual bool findNext() = 0;
147  virtual bool findPrev() = 0;
148  virtual int getSearchResultIndex() = 0;
149  virtual int getSearchCount() = 0;
150 };
151 
153 {
154 public:
155  virtual ~PDFiumTextPage() = default;
156 
157  virtual int countChars() = 0;
158  virtual unsigned int getUnicode(int index) = 0;
159  virtual std::unique_ptr<PDFiumSearchHandle>
160  findStart(const OUString& rFindWhat, PDFFindFlags nFlags, sal_Int32 nStartIndex) = 0;
161 
163  virtual basegfx::B2DRectangle getCharBox(int nIndex, double fPageHeight) = 0;
164 };
165 
167 {
168 public:
169  virtual ~PDFiumPage() = default;
170 
171  virtual int getObjectCount() = 0;
172  virtual std::unique_ptr<PDFiumPageObject> getObject(int nIndex) = 0;
173 
174  virtual int getAnnotationCount() = 0;
175  virtual int getAnnotationIndex(std::unique_ptr<PDFiumAnnotation> const& rAnnotation) = 0;
176 
177  virtual std::unique_ptr<PDFiumAnnotation> getAnnotation(int nIndex) = 0;
178 
179  virtual std::unique_ptr<PDFiumTextPage> getTextPage() = 0;
180 
182  virtual BitmapChecksum getChecksum(int nMDPPerm) = 0;
183 
184  virtual double getWidth() = 0;
185  virtual double getHeight() = 0;
186 
187  virtual bool hasTransparency() = 0;
188 
189  virtual bool hasLinks() = 0;
190 };
191 
194 {
195 public:
196  virtual ~PDFiumSignature() = default;
197 
198  virtual std::vector<int> getByteRange() = 0;
199  virtual int getDocMDPPermission() = 0;
200  virtual std::vector<unsigned char> getContents() = 0;
201  virtual OString getSubFilter() = 0;
202  virtual OUString getReason() = 0;
203  virtual css::util::DateTime getTime() = 0;
204 };
205 
207 {
208 public:
209  virtual ~PDFiumDocument() = default;
210 
211  // Page size in points
212  virtual basegfx::B2DSize getPageSize(int nIndex) = 0;
213  virtual int getPageCount() = 0;
214  virtual int getSignatureCount() = 0;
215  virtual int getFileVersion() = 0;
216  virtual bool saveWithVersion(SvMemoryStream& rStream, int nFileVersion) = 0;
217 
218  virtual std::unique_ptr<PDFiumPage> openPage(int nIndex) = 0;
219  virtual std::unique_ptr<PDFiumSignature> getSignature(int nIndex) = 0;
220  virtual std::vector<unsigned int> getTrailerEnds() = 0;
221 };
222 
224 {
225  static std::shared_ptr<PDFium>& get();
226 };
227 
228 // Tools
229 
230 VCL_DLLPUBLIC OUString convertPdfDateToISO8601(OUString const& rInput);
231 
232 } // namespace vcl::pdf
233 
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
sal_Int32 nIndex
sal_uInt64 left
bool getType(BSTR name, Type &type)
std::unique_ptr< ContentProperties > pData
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
static BitmapColor getColor(const BitmapReadAccess *pReadAcc, tools::Long nZ)
constexpr OStringLiteral constDictionaryKeyContents
Represents one digital signature, as exposed by PDFium.
OUString convertPdfDateToISO8601(OUString const &rInput)
Definition: PDFiumTools.cxx:15
void fillRect(const ::cppcanvas::CanvasSharedPtr &rCanvas, const ::basegfx::B2DRectangle &rRect,::cppcanvas::IntSRGBA aFillColor)
constexpr OStringLiteral constDictionaryKeyModificationDate
tuple index
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:27
sal_Int32 getPageCount(const uno::Reference< frame::XModel > &xModel)
constexpr OStringLiteral constDictionaryKeyPopup
constexpr OStringLiteral constDictionaryKeyTitle
OUString getString(const Any &_rAny)
constexpr OStringLiteral constDictionaryKeyInteriorColor