Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/inc/svdpdf.hxx
Line
Count
Source
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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#ifndef INCLUDED_SVX_SOURCE_SVDRAW_SVDPDF_HXX
21
#define INCLUDED_SVX_SOURCE_SVDRAW_SVDPDF_HXX
22
23
#include <sal/config.h>
24
25
#include <memory>
26
#include <map>
27
28
#include <tools/fract.hxx>
29
#include <vcl/virdev.hxx>
30
#include <vcl/gfxlink.hxx>
31
#include <vcl/graph.hxx>
32
#include <svx/svdobj.hxx>
33
#include <svx/xdash.hxx>
34
35
#include <basegfx/matrix/b2dhommatrix.hxx>
36
#include <basegfx/vector/b2dsize.hxx>
37
38
#include <vcl/filter/PDFiumLibrary.hxx>
39
40
// Forward Declarations
41
42
class SfxItemSet;
43
class SdrObjList;
44
class SdrModel;
45
class SdrObject;
46
class SvdProgressInfo;
47
48
// Fonts are typically saved in pdf files as multiple subsets.
49
// This describes a single font subset:
50
struct FontSubSet
51
{
52
    // The location of a file containing the dumped info about the font
53
    OUString cidFontInfoUrl;
54
    // The location of a 'mergefile' derived from glyphToChars/charsToGlyph
55
    // that indicates what positions the glyphs of this font should go in
56
    // a final font merged from multiple subsets
57
    OUString toMergedMapUrl;
58
    // The location of the extracted font, converted to a cid font.
59
    OUString pfaCIDUrl;
60
    // What glyphs are in the subset and what characters those represent.
61
    std::map<sal_Int32, OString> glyphToChars;
62
    std::map<OString, sal_Int32> charsToGlyph;
63
    // What glyphs ranges are in the subset
64
    std::map<sal_Int32, Range> glyphRangesToChars;
65
    int nGlyphCount;
66
};
67
68
// The collection of all font subsets in the document.
69
struct SubSetInfo
70
{
71
    std::vector<FontSubSet> aComponents;
72
};
73
74
// Describes a final, possibly merged from multiple input fontsubsets,
75
// font of a given name and fontweight available as fontfile
76
struct EmbeddedFontInfo
77
{
78
    OUString sFontName;
79
    OUString sFontFile;
80
    FontWeight eFontWeight;
81
};
82
83
// Helper Class to import PDF
84
class ImpSdrPdfImport final
85
{
86
    std::vector<rtl::Reference<SdrObject>> maTmpList;
87
88
    ScopedVclPtr<VirtualDevice> mpVD;
89
    tools::Rectangle maScaleRect;
90
    size_t mnMapScalingOfs; // from here on, not edited with MapScaling
91
    std::unique_ptr<SfxItemSet> mpLineAttr;
92
    std::unique_ptr<SfxItemSet> mpFillAttr;
93
    std::unique_ptr<SfxItemSet> mpTextAttr;
94
    SdrModel* mpModel;
95
    std::shared_ptr<ImportedFontMap> mxImportedFonts;
96
    SdrLayerID mnLayer;
97
    sal_Int32 mnLineWidth;
98
    static constexpr css::drawing::LineCap gaLineCap = css::drawing::LineCap_BUTT;
99
    XDash maDash;
100
    std::optional<Color> moFillColor;
101
    std::optional<Bitmap> moFillPattern;
102
103
    bool mbMov;
104
    bool mbSize;
105
    Point maOfs;
106
    double mfScaleX;
107
    double mfScaleY;
108
    Fraction maScaleX;
109
    Fraction maScaleY;
110
111
    bool mbFntDirty;
112
113
    // to optimize (PenNULL,Brush,DrawPoly),(Pen,BrushNULL,DrawPoly) -> two-in-one
114
    bool mbLastObjWasPolyWithoutLine;
115
    bool mbNoLine;
116
    bool mbNoFill;
117
118
    std::unique_ptr<vcl::pdf::PDFiumDocument> mpPdfDocument;
119
    int mnPageCount;
120
    double mdPageHeightPts;
121
    /// The current transformation matrix, typically used with Form objects.
122
    basegfx::B2DHomMatrix maCurrentMatrix;
123
124
    /// Correct the vertical coordinate to start at the top.
125
    /// PDF coordinate system has origin at the bottom right.
126
3.20k
    double correctVertOrigin(double offsetPts) const { return mdPageHeightPts - offsetPts; }
127
    /// Convert PDF points to logic (twips).
128
    tools::Rectangle PointsToLogic(double left, double right, double top, double bottom) const;
129
    Point PointsToLogic(double x, double y) const;
130
131
    std::shared_ptr<vcl::pdf::PDFium> mpPDFium;
132
133
    Color getStrokeColor(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
134
                         std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage);
135
    Color getFillColor(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
136
                       std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage);
137
138
    void ImportPdfObject(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
139
                         std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage,
140
                         std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
141
                         int nPageObjectIndex);
142
    void ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
143
                    std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage,
144
                    std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
145
                    int nPageObjectIndex);
146
    void ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
147
                     int nPageObjectIndex);
148
    void ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
149
                    std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage, int nPageObjectIndex);
150
    void ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
151
                    std::unique_ptr<vcl::pdf::PDFiumPage> const& pPage,
152
                    std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
153
                    int nPageObjectIndex);
154
    void InsertTextObject(const Point& rPos, const Size& rSize, const OUString& rStr,
155
                          bool bInvisible);
156
157
    void SetupPageScale(const double dPageWidth, const double dPageHeight);
158
    void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false);
159
    void InsertObj(SdrObject* pObj, bool bScale = true);
160
    void MapScaling();
161
162
    void appendSegmentsToPolyPoly(
163
        basegfx::B2DPolyPolygon& rPolyPoly,
164
        const std::vector<std::unique_ptr<vcl::pdf::PDFiumPathSegment>>& rPathSegments,
165
        const basegfx::B2DHomMatrix& rPathMatrix);
166
167
    basegfx::B2DPolyPolygon GetClip(const std::unique_ptr<vcl::pdf::PDFiumClipPath>& rClipPath,
168
                                    const basegfx::B2DHomMatrix& rPathMatrix,
169
                                    const basegfx::B2DHomMatrix& rTransform);
170
171
    // #i73407# reformulation to use new B2DPolygon classes
172
    bool CheckLastPolyLineAndFillMerge(const basegfx::B2DPolyPolygon& rPolyPolygon);
173
174
    void DoObjects(SvdProgressInfo* pProgrInfo, sal_uInt32* pActionsToReport, int nPageIndex);
175
176
    static ImportedFontMap CollectFonts(sal_Int64 nPrefix, vcl::pdf::PDFiumDocument& rPdfDocument);
177
178
24
    sal_Int64 getPrefix() const { return reinterpret_cast<sal_Int64>(this); }
179
180
    static EmbeddedFontInfo convertToOTF(sal_Int64 nPrefix, SubSetInfo& rSubSetInfo,
181
                                         const OUString& fileUrl, const OUString& fontName,
182
                                         const OUString& baseFontName,
183
                                         std::u16string_view fontFileName,
184
                                         const std::vector<uint8_t>& toUnicodeData,
185
                                         const vcl::pdf::PDFiumFont& font);
186
187
    // Copy assignment is forbidden and not implemented.
188
    ImpSdrPdfImport(const ImpSdrPdfImport&) = delete;
189
    ImpSdrPdfImport& operator=(const ImpSdrPdfImport&) = delete;
190
191
public:
192
    ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools::Rectangle& rRect,
193
                    Graphic const& rGraphic);
194
195
    ~ImpSdrPdfImport();
196
197
27
    int GetPageCount() const { return mnPageCount; }
198
    size_t DoImport(SdrObjList& rDestList, size_t nInsPos, int nPageNumber,
199
                    SvdProgressInfo* pProgrInfo = nullptr);
200
};
201
202
#endif // INCLUDED_SVX_SOURCE_SVDRAW_SVDPDF_HXX
203
204
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */