/src/libreoffice/include/vcl/pdfread.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
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 | | #ifndef INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX |
11 | | #define INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX |
12 | | |
13 | | #include <vector> |
14 | | #include <tools/gen.hxx> |
15 | | #include <tools/color.hxx> |
16 | | #include <vcl/graph.hxx> |
17 | | #include <basegfx/range/b2drectangle.hxx> |
18 | | #include <com/sun/star/util/DateTime.hpp> |
19 | | |
20 | | class SvStream; |
21 | | namespace com::sun::star::task |
22 | | { |
23 | | class XInteractionHandler; |
24 | | } |
25 | | namespace vcl::pdf |
26 | | { |
27 | | enum class PDFAnnotationSubType; |
28 | | } |
29 | | namespace vcl::pdf |
30 | | { |
31 | | struct PDFAnnotationMarker; |
32 | | } |
33 | | |
34 | | namespace vcl |
35 | | { |
36 | | /// Fills the rBitmaps vector with rendered pages. |
37 | | VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBitmaps, |
38 | | size_t nFirstPage = 0, int nPages = 1, |
39 | | const basegfx::B2DTuple* pSizeHint = nullptr); |
40 | | |
41 | | VCL_DLLPUBLIC bool |
42 | | ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex, |
43 | | const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler, |
44 | | bool& bEncrypted); |
45 | | |
46 | | inline bool ImportPDF(SvStream& rStream, Graphic& rGraphic) |
47 | 1.80k | { |
48 | 1.80k | bool bEncrypted; |
49 | | |
50 | 1.80k | return ImportPDF(rStream, rGraphic, -1, nullptr, bEncrypted); |
51 | 1.80k | } |
52 | | |
53 | | // When inserting a PDF file as an image or pasting PDF data from the clipboard, at least on a |
54 | | // Retina iMac, the resulting rendered image does not look sharp without this surprisingly large |
55 | | // extra scaling factor. Exact reasons unknown. And it isn't enough to have it be just 2 (which is |
56 | | // the actual Retina factor on my iMac). Possibly the fuzziness is related to what Pdfium uses to |
57 | | // render text. |
58 | | |
59 | | // Also, look at CountDPIScaleFactor() in vcl/source/window/window.cxx. The GetDPIScaleFactor() API |
60 | | // lies on macOS even more than it does on other platforms, it claims that the DPI scale factor is |
61 | | // always 1. But in fact most Macs nowadays have a HiDPI ("Retina") display. But we can't just "fix" |
62 | | // things by making GetDPIScaleFactor() always return 2 on macOS, even if that wouldn't be any more |
63 | | // wrong, because that then causes other regressions that I have no time to look into now. |
64 | | |
65 | | #ifdef MACOSX |
66 | | constexpr int PDF_INSERT_MAGIC_SCALE_FACTOR = 8; |
67 | | #else |
68 | | constexpr int PDF_INSERT_MAGIC_SCALE_FACTOR = 1; |
69 | | #endif |
70 | | |
71 | | struct PDFGraphicAnnotation |
72 | | { |
73 | | OUString maAuthor; |
74 | | OUString maText; |
75 | | |
76 | | basegfx::B2DRectangle maRectangle; // In HMM |
77 | | css::util::DateTime maDateTime; |
78 | | |
79 | | Color maColor; |
80 | | |
81 | | pdf::PDFAnnotationSubType meSubType; |
82 | | std::shared_ptr<pdf::PDFAnnotationMarker> mpMarker; |
83 | | |
84 | | /// Raw /F value (annotation flags bitfield). 0 if absent. |
85 | | int mnFlags = 0; |
86 | | /// Pdfium index of this annotation on its page. Indices are page-scoped; PDF spec requires |
87 | | /// /IRT parents to live on the same page as the referring annotation, so a per-page map is |
88 | | /// sufficient to resolve them. |
89 | | int mnPdfiumIndex = -1; |
90 | | /// Pdfium index of the parent annotation (/IRT) on the same page; -1 if root (no /IRT) or |
91 | | /// if the PDF is malformed and /IRT pointed to a different page. |
92 | | int mnParentPdfiumIndex = -1; |
93 | | /// /RT (reply type): "R" = reply (default), "Group" = grouped with parent but not a reply. |
94 | | OUString maReplyType = u"R"_ustr; |
95 | | /// Raw /State value (e.g. "Marked", "Unmarked", "Accepted", "Completed"). |
96 | | OUString maState; |
97 | | /// Raw /StateModel value ("Marked" or "Review"). |
98 | | OUString maStateModel; |
99 | | }; |
100 | | |
101 | | class PDFGraphicResult |
102 | | { |
103 | | Graphic maGraphic; |
104 | | // Size in HMM |
105 | | Size maSize; |
106 | | |
107 | | std::vector<PDFGraphicAnnotation> maAnnotations; |
108 | | std::vector<std::pair<basegfx::B2DRectangle, OUString>> maLinksInfo; |
109 | | |
110 | | public: |
111 | | PDFGraphicResult(Graphic aGraphic, Size const& rSize, |
112 | | std::vector<PDFGraphicAnnotation> aAnnotations, |
113 | | std::vector<std::pair<basegfx::B2DRectangle, OUString>> aLinks) |
114 | 101 | : maGraphic(std::move(aGraphic)) |
115 | 101 | , maSize(rSize) |
116 | 101 | , maAnnotations(std::move(aAnnotations)) |
117 | 101 | , maLinksInfo(std::move(aLinks)) |
118 | 101 | { |
119 | 101 | } |
120 | | |
121 | 101 | const Graphic& GetGraphic() const { return maGraphic; } |
122 | 101 | const Size& GetSize() const { return maSize; } |
123 | 101 | const std::vector<PDFGraphicAnnotation>& GetAnnotations() const { return maAnnotations; } |
124 | | const std::vector<std::pair<basegfx::B2DRectangle, OUString>>& GetLinksInfo() const |
125 | 101 | { |
126 | 101 | return maLinksInfo; |
127 | 101 | } |
128 | | }; |
129 | | |
130 | | /// Import PDF as Graphic images (1 per page), but not loaded yet. |
131 | | /// Returns the number of pages read. |
132 | | /// xInteractionHandler and rPassword let an encrypted (and/or too-new) PDF be |
133 | | /// decrypted for the version downgrade - the password is used directly when |
134 | | /// given, otherwise the handler is asked. |
135 | | VCL_DLLPUBLIC size_t ImportPDFUnloaded( |
136 | | const OUString& rURL, std::vector<PDFGraphicResult>& rGraphics, |
137 | | const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr, |
138 | | const OUString& rPassword = OUString()); |
139 | | VCL_DLLPUBLIC size_t ImportPDFUnloaded( |
140 | | SvStream& rStream, std::vector<PDFGraphicResult>& rGraphics, |
141 | | const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr, |
142 | | const OUString& rPassword = OUString()); |
143 | | } |
144 | | |
145 | | #endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX |
146 | | |
147 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |