Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
19.4k
{
48
19.4k
    bool bEncrypted;
49
50
19.4k
    return ImportPDF(rStream, rGraphic, -1, nullptr, bEncrypted);
51
19.4k
}
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
85
class PDFGraphicResult
86
{
87
    Graphic maGraphic;
88
    // Size in HMM
89
    Size maSize;
90
91
    std::vector<PDFGraphicAnnotation> maAnnotations;
92
    std::vector<std::pair<basegfx::B2DRectangle, OUString>> maLinksInfo;
93
94
public:
95
    PDFGraphicResult(Graphic aGraphic, Size const& rSize,
96
                     std::vector<PDFGraphicAnnotation> aAnnotations,
97
                     std::vector<std::pair<basegfx::B2DRectangle, OUString>> aLinks)
98
246
        : maGraphic(std::move(aGraphic))
99
246
        , maSize(rSize)
100
246
        , maAnnotations(std::move(aAnnotations))
101
246
        , maLinksInfo(std::move(aLinks))
102
246
    {
103
246
    }
104
105
246
    const Graphic& GetGraphic() const { return maGraphic; }
106
246
    const Size& GetSize() const { return maSize; }
107
246
    const std::vector<PDFGraphicAnnotation>& GetAnnotations() const { return maAnnotations; }
108
    const std::vector<std::pair<basegfx::B2DRectangle, OUString>>& GetLinksInfo() const
109
246
    {
110
246
        return maLinksInfo;
111
246
    }
112
};
113
114
/// Import PDF as Graphic images (1 per page), but not loaded yet.
115
/// Returns the number of pages read.
116
VCL_DLLPUBLIC size_t ImportPDFUnloaded(const OUString& rURL,
117
                                       std::vector<PDFGraphicResult>& rGraphics);
118
VCL_DLLPUBLIC size_t ImportPDFUnloaded(SvStream& rStream, std::vector<PDFGraphicResult>& rGraphics);
119
}
120
121
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
122
123
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */