1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #ifndef INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
11 #define INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
14 #include <tools/gen.hxx>
15 #include <tools/stream.hxx>
16 #include <tools/color.hxx>
17 #include <vcl/graph.hxx>
18 #include <basegfx/range/b2drectangle.hxx>
19 #include <com/sun/star/util/DateTime.hpp>
21 #include <vcl/pdf/PDFAnnotationSubType.hxx>
22 #include <vcl/pdf/PDFAnnotationMarker.hxx>
24 namespace com::sun::star::uno
26 template <typename
> class Sequence
;
32 /// Fills the rBitmaps vector with rendered pages.
33 VCL_DLLPUBLIC
size_t RenderPDFBitmaps(const void* pBuffer
, int nSize
,
34 std::vector
<BitmapEx
>& rBitmaps
, size_t nFirstPage
= 0,
35 int nPages
= 1, const basegfx::B2DTuple
* pSizeHint
= nullptr);
37 /// Imports a PDF stream as a VectorGraphicData.
39 importPdfVectorGraphicData(SvStream
& rStream
,
40 std::shared_ptr
<VectorGraphicData
>& rVectorGraphicData
);
42 /// Imports a PDF stream into rGraphic.
43 VCL_DLLPUBLIC
bool ImportPDF(SvStream
& rStream
, Graphic
& rGraphic
);
45 // When inserting a PDF file as an image or pasting PDF data from the clipboard, at least on a
46 // Retina iMac, the resulting rendered image does not look sharp without this surprisingly large
47 // extra scaling factor. Exact reasons unknown. And it isn't enough to have it be just 2 (which is
48 // the actual Retina factor on my iMac). Possibly the fuzziness is related to what Pdfium uses to
51 // Also, look at CountDPIScaleFactor() in vcl/source/window/window.cxx. The GetDPIScaleFactor() API
52 // lies on macOS even more than it does on other platforms, it claims that the DPI scale factor is
53 // always 1. But in fact most Macs nowadays have a HiDPI ("Retina") display. But we can't just "fix"
54 // things by making GetDPIScaleFactor() always return 2 on macOS, even if that wouldn't be any more
55 // wrong, because that then causes other regressions that I have no time to look into now.
58 constexpr int PDF_INSERT_MAGIC_SCALE_FACTOR
= 8;
60 constexpr int PDF_INSERT_MAGIC_SCALE_FACTOR
= 1;
63 struct PDFGraphicAnnotation
68 basegfx::B2DRectangle maRectangle
; // In HMM
69 css::util::DateTime maDateTime
;
73 pdf::PDFAnnotationSubType meSubType
;
74 std::shared_ptr
<pdf::PDFAnnotationMarker
> mpMarker
;
77 class PDFGraphicResult
83 std::vector
<PDFGraphicAnnotation
> maAnnotations
;
86 PDFGraphicResult(Graphic aGraphic
, Size
const& rSize
,
87 std::vector
<PDFGraphicAnnotation
> aAnnotations
)
88 : maGraphic(std::move(aGraphic
))
90 , maAnnotations(std::move(aAnnotations
))
94 const Graphic
& GetGraphic() const { return maGraphic
; }
95 const Size
& GetSize() const { return maSize
; }
96 const std::vector
<PDFGraphicAnnotation
>& GetAnnotations() const { return maAnnotations
; }
99 /// Import PDF as Graphic images (1 per page), but not loaded yet.
100 /// Returns the number of pages read.
101 VCL_DLLPUBLIC
size_t ImportPDFUnloaded(const OUString
& rURL
,
102 std::vector
<PDFGraphicResult
>& rGraphics
);
105 #endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */