Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/vcl/pdfextoutdevdata.hxx
Line
Count
Source (jump to first uncovered line)
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_VCL_PDFEXTOUTDEVDATA_HXX
21
#define INCLUDED_VCL_PDFEXTOUTDEVDATA_HXX
22
23
#include <vcl/dllapi.h>
24
25
#include <vcl/pdfwriter.hxx>
26
#include <vcl/extoutdevdata.hxx>
27
#include <vector>
28
#include <map>
29
#include <memory>
30
31
class Graphic;
32
class GDIMetaFile;
33
class SdrObject;
34
struct SwEnhancedPDFState;
35
struct ScEnhancedPDFState;
36
37
namespace vcl
38
{
39
40
/*
41
    A PDFExtOutDevBookmarkEntry is being created by the EditEngine if
42
    a bookmark URL has been parsed. The Application is requested to take
43
    care of each bookmark entry by emptying out the bookmark vector.
44
*/
45
struct PDFExtOutDevBookmarkEntry
46
{
47
    /** ID of the link pointing to the bookmark, or -1 if the entry denotes a destination instead of a link.
48
    */
49
    sal_Int32       nLinkId;
50
51
    /** ID of the named destination denoted by the bookmark, or -1 if the entry denotes a link instead of a named destination.
52
    */
53
    sal_Int32       nDestId;
54
55
    /** link target name, respectively destination name
56
    */
57
    OUString   aBookmark;
58
59
    PDFExtOutDevBookmarkEntry()
60
        :nLinkId( -1 )
61
        ,nDestId( -1 )
62
0
    {
63
0
    }
64
};
65
66
/*
67
 Class that is being set at the OutputDevice allowing the
68
 application to send enhanced PDF commands like CreateLink
69
*/
70
struct PageSyncData;
71
struct GlobalSyncData;
72
class VCL_DLLPUBLIC PDFExtOutDevData final : public ExtOutDevData
73
{
74
75
    const OutputDevice&         mrOutDev;
76
77
    bool                        mbTaggedPDF;
78
    bool                        mbExportNotes;
79
    bool                        mbExportNotesInMargin;
80
    bool                        mbExportNotesPages;
81
    bool                        mbTransitionEffects;
82
    bool                        mbUseLosslessCompression;
83
    bool                        mbReduceImageResolution;
84
    bool                        mbExportFormFields;
85
    bool                        mbExportBookmarks;
86
    bool                        mbExportHiddenSlides;
87
    bool                        mbSinglePageSheets;
88
    bool                        mbExportNDests; //i56629
89
    sal_Int32                   mnPage;
90
    sal_Int32                   mnCompressionQuality;
91
    css::lang::Locale           maDocLocale;
92
93
    std::unique_ptr<PageSyncData> mpPageSyncData;
94
    std::unique_ptr<GlobalSyncData> mpGlobalSyncData;
95
96
    std::vector< PDFExtOutDevBookmarkEntry > maBookmarks;
97
    std::vector<OUString> maChapterNames;
98
    // map from annotation SdrObject to annotation index
99
    ::std::map<SdrObject const*, ::std::vector<sal_Int32>> m_ScreenAnnotations;
100
101
    SwEnhancedPDFState * m_pSwPDFState = nullptr;
102
    ScEnhancedPDFState * m_pScPDFState = nullptr;
103
104
public:
105
106
    PDFExtOutDevData( const OutputDevice& rOutDev );
107
    virtual ~PDFExtOutDevData() override;
108
109
    bool PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const GDIMetaFile& rMtf );
110
    void ResetSyncData(PDFWriter * pWriterIfRemoveTransparencies);
111
112
    void PlayGlobalActions( PDFWriter& rWriter );
113
114
8.47k
    bool    GetIsExportNotes() const { return mbExportNotes;}
115
    void        SetIsExportNotes( const bool bExportNotes );
116
117
0
    bool    GetIsExportNotesInMargin() const { return mbExportNotesInMargin;}
118
    void        SetIsExportNotesInMargin( const bool bExportNotesInMargin );
119
120
0
    bool    GetIsExportNotesPages() const { return mbExportNotesPages;}
121
    void        SetIsExportNotesPages( const bool bExportNotesPages );
122
123
4.25M
    bool    GetIsExportTaggedPDF() const { return mbTaggedPDF;}
124
    void        SetIsExportTaggedPDF( const bool bTaggedPDF );
125
126
0
    bool    GetIsExportTransitionEffects() const { return mbTransitionEffects;}
127
    void        SetIsExportTransitionEffects( const bool bTransitionalEffects );
128
129
0
    bool    GetIsExportFormFields() const { return mbExportFormFields;}
130
    void        SetIsExportFormFields( const bool bExportFormFields );
131
132
8.47k
    bool    GetIsExportBookmarks() const { return mbExportBookmarks;}
133
    void        SetIsExportBookmarks( const bool bExportBookmarks );
134
135
0
    bool    GetIsExportHiddenSlides() const { return mbExportHiddenSlides;}
136
    void        SetIsExportHiddenSlides( const bool bExportHiddenSlides );
137
138
    void        SetIsSinglePageSheets( const bool bSinglePageSheets );
139
140
8.47k
    bool    GetIsExportNamedDestinations() const { return mbExportNDests;} //i56629
141
    void        SetIsExportNamedDestinations( const bool bExportNDests ); //i56629
142
143
    // PageNumber, Compression is being set by the PDFExport
144
0
    sal_Int32   GetCurrentPageNumber() const { return mnPage;}
145
    void        SetCurrentPageNumber( const sal_Int32 nPage );
146
147
0
    bool        GetIsLosslessCompression() const { return mbUseLosslessCompression;}
148
    void        SetIsLosslessCompression( const bool bLosslessCompression );
149
150
    void        SetCompressionQuality( const sal_Int32 nQuality );
151
152
0
    bool        GetIsReduceImageResolution() const { return mbReduceImageResolution;}
153
    void        SetIsReduceImageResolution( const bool bReduceImageResolution );
154
155
8.47k
    const css::lang::Locale& GetDocumentLocale() const { return maDocLocale;}
156
    void        SetDocumentLocale( const css::lang::Locale& rLoc );
157
158
8.47k
    std::vector< PDFExtOutDevBookmarkEntry >& GetBookmarks() { return maBookmarks;}
159
0
    const std::vector<OUString>& GetChapterNames() const { return maChapterNames; }
160
161
384k
    SwEnhancedPDFState * GetSwPDFState() { return m_pSwPDFState; }
162
16.9k
    void SetSwPDFState(SwEnhancedPDFState *const pSwPDFState) { m_pSwPDFState = pSwPDFState; }
163
164
0
    ScEnhancedPDFState* GetScPDFState() { return m_pScPDFState; }
165
0
    void SetScPDFState(ScEnhancedPDFState* const pScPDFState) { m_pScPDFState = pScPDFState; }
166
167
    const Graphic& GetCurrentGraphic() const;
168
169
    /** Start a new group of render output
170
171
        Use this method to group render output.
172
     */
173
    void        BeginGroup();
174
175
    /** End render output
176
177
        This method ends grouped render output, that can be
178
        represented by a GfxLink. This is typically used for
179
        external graphic files, such as JPEGs, EPS files etc.
180
        The BeginGroup/EndGroup calls must exactly enclose the
181
        relevant OutputDevice calls issued to render the
182
        graphic the normal way.
183
184
        @param rGraphic
185
        The link to the original graphic
186
187
        @param nTransparency
188
        Eight bit transparency value, with 0 denoting full opacity,
189
        and 255 full transparency.
190
191
        @param rOutputRect
192
        The output rectangle of the graphic.
193
194
        @param rVisibleOutputRect
195
        The visible part of the output. This might be less than
196
        rOutputRect, e.g. for cropped graphics.
197
     */
198
    void        EndGroup( const Graphic&    rGraphic,
199
                          sal_uInt8         nTransparency,
200
                          const tools::Rectangle&  rOutputRect,
201
                          const tools::Rectangle&  rVisibleOutputRect );
202
203
    /// Detect if stream is compressed enough to avoid de-compress / scale & re-compress
204
    bool        HasAdequateCompression( const Graphic &rGraphic,
205
                                        const tools::Rectangle &rOutputRect,
206
                                        const tools::Rectangle &rVisibleOutputRect ) const;
207
208
//--->i56629
209
    /** Create a new named destination to be used in a link to this document from another PDF document
210
 (see PDF spec 1.4, 8.2.1)
211
212
    @param sDestName
213
    the name this destination will be addressed with from others PDF document
214
215
    @param rRect
216
    target rectangle on page to be displayed if dest is jumped to
217
218
    @param nPageNr
219
    number of page the dest is on (as returned by NewPage)
220
    or -1 in which case the current page is used
221
222
    @returns
223
    the destination id (to be used in SetLinkDest) or
224
    -1 if page id does not exist
225
    */
226
    sal_Int32 CreateNamedDest( const OUString& sDestName,  const tools::Rectangle& rRect, sal_Int32 nPageNr = -1 );
227
228
    /** registers a destination for which a destination ID needs to be known immediately, instead of later on setting it via
229
        SetLinkDest.
230
231
        This is used in contexts where a destination is referenced by means other than a link.
232
233
        Later in the export process, a call to DescribeRegisteredDest must be made, providing the information about
234
        the destination.
235
236
        @return
237
            the unique Id of the destination
238
    */
239
    sal_Int32   RegisterDest();
240
241
    /** provides detailed information about a destination range which previously has been registered using RegisterDest.
242
    */
243
    void        DescribeRegisteredDest( sal_Int32 nDestId, const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType = PDFWriter::DestAreaType::XYZ );
244
245
//<---i56629
246
247
    /** Create a new destination to be used in a link
248
249
    @param rRect
250
    target rectangle on page to be displayed if dest is jumped to
251
252
    @param nPageNr
253
    number of page the dest is on (as returned by NewPage)
254
    or -1 in which case the current page is used
255
256
    @param eType
257
    what dest type to use
258
259
    @returns
260
    the destination id (to be used in SetLinkDest) or
261
    -1 if page id does not exist
262
    */
263
    sal_Int32 CreateDest( const tools::Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::DestAreaType::XYZ );
264
    /** Create a new link on a page
265
266
    @param rRect
267
    active rectangle of the link (that is the area that has to be
268
    hit to activate the link)
269
270
    @param nPageNr
271
    number of page the link is on (as returned by NewPage)
272
    or -1 in which case the current page is used
273
274
    @param rAltText
275
    Alt text for the link
276
277
    @returns
278
    the link id (to be used in SetLinkDest, SetLinkURL) or
279
    -1 if page id does not exist
280
    */
281
    sal_Int32 CreateLink(const tools::Rectangle& rRect, OUString const& rAltText, sal_Int32 nPageNr = -1);
282
283
    /// Create a Screen annotation.
284
    sal_Int32 CreateScreen(const tools::Rectangle& rRect, OUString const& rAltText, OUString const& rMimeType, sal_Int32 nPageNr, SdrObject const* pObj);
285
286
    /// Get back the annotations created for one SdrObject.
287
    ::std::vector<sal_Int32> const& GetScreenAnnotIds(SdrObject const* pObj) const;
288
289
    /** Set the destination for a link
290
        <p>will change a URL type link to a dest link if necessary</p>
291
292
        @param nLinkId
293
        the link to be changed
294
295
        @param nDestId
296
        the dest the link shall point to
297
    */
298
    void SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
299
    /** Set the URL for a link
300
        <p>will change a dest type link to a URL type link if necessary</p>
301
        @param nLinkId
302
        the link to be changed
303
304
        @param rURL
305
        the URL the link shall point to.
306
        there will be no error checking or any kind of
307
        conversion done to this parameter except this:
308
        it will be output as 7bit Ascii. The URL
309
        will appear literally in the PDF file produced
310
    */
311
    void SetLinkURL( sal_Int32 nLinkId, const OUString& rURL );
312
313
    /// Set URL for a linked Screen annotation.
314
    void SetScreenURL(sal_Int32 nScreenId, const OUString& rURL);
315
    /// Set URL for an embedded Screen annotation.
316
    void SetScreenStream(sal_Int32 nScreenId, const OUString& rURL);
317
318
    /** Create a new outline item
319
320
        @param nParent
321
        declares the parent of the new item in the outline hierarchy.
322
        An invalid value will result in a new toplevel item.
323
324
        @param rText
325
        sets the title text of the item
326
327
        @param nDestID
328
        declares which Dest (created with CreateDest) the outline item
329
        will point to
330
331
        @returns
332
        the outline item id of the new item
333
    */
334
    sal_Int32 CreateOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID );
335
336
    /** Create a new note on a page
337
338
    @param rRect
339
    active rectangle of the note (that is the area that has to be
340
    hit to popup the annotation)
341
342
    @param rNote
343
    specifies the contents of the note
344
345
    @param rPopupRect
346
    specifies the rectangle of the popup window for the note
347
348
    @param nPageNr
349
    number of page the note is on (as returned by NewPage)
350
    or -1 in which case the current page is used
351
    */
352
    sal_Int32 CreateNote(const tools::Rectangle& rRect, const vcl::pdf::PDFNote& rNote, const tools::Rectangle& rPopupRect, sal_Int32 nPageNr = -1);
353
354
    /** begin a new logical structure element
355
356
    BeginStructureElement/EndStructureElement calls build the logical structure
357
    of the PDF - the basis for tagged PDF. Structural elements are implemented
358
    using marked content tags. Each structural element can contain sub elements
359
    (e.g. a section can contain a heading and a paragraph). The structure hierarchy
360
    is build automatically from the Begin/EndStructureElement calls.
361
362
    The easy way is to call WrapBeginStructureElement, but it's also possible
363
    to call EnsureStructureElement/InitStructureElement/BeginStructureElement
364
    (its 3 parts) manually for more control; this way a placeholder SE can be
365
    inserted and initialised later.
366
367
    A structural element need not be contained on one page; e.g. paragraphs often
368
    run from one page to the next. In this case the corresponding EndStructureElement
369
    must be called while drawing the next page.
370
371
    BeginStructureElement and EndStructureElement must be called only after
372
    PDFWriter::NewPage has been called and before
373
    PDFWriter::Emit gets called. The current page
374
    number is an implicit context parameter for Begin/EndStructureElement.
375
376
    For pagination artifacts that are not part of the logical structure
377
    of the document (like header, footer or page number) the special
378
    StructElement NonStructElement exists. To place content
379
    outside of the structure tree simply call
380
    BeginStructureElement( NonStructElement ) then draw your
381
    content and then call EndStructureElement(). Any children
382
    of a NonStructElement will not be part of the structure as well.
383
384
    @param eType
385
    denotes what kind of element to begin (e.g. a heading or paragraph)
386
387
    @param rAlias
388
    the specified alias will be used as structure tag. Also an entry in the PDF's
389
    role map will be created mapping alias to regular structure type.
390
391
    @returns
392
    the id of the newly created structural element
393
     */
394
    sal_Int32 WrapBeginStructureElement(vcl::pdf::StructElement eType, const OUString& rAlias = OUString());
395
    sal_Int32 EnsureStructureElement(void const* key);
396
    void InitStructureElement(sal_Int32 id, vcl::pdf::StructElement eType, const OUString& rAlias);
397
    void BeginStructureElement(sal_Int32 id);
398
399
    /** end a logical structure element
400
401
    @see BeginStructureElement
402
     */
403
    void EndStructureElement();
404
    /** set the current structure element
405
406
    <p>
407
    For different purposes it may be useful to paint a structure element's
408
    content discontinuously. In that case an already existing structure element
409
    can be appended to by using SetCurrentStructureElement. The
410
    referenced structure element becomes the current structure element with
411
    all consequences: all following structure elements are appended as children
412
    of the current element.
413
    </p>
414
415
    @param nElement
416
    the id of the new current structure element, which must be valid
417
     */
418
    void SetCurrentStructureElement( sal_Int32 nElement );
419
    /** get the current structure element id
420
421
    @returns
422
    the id of the current structure element
423
    */
424
    sal_Int32 GetCurrentStructureElement() const;
425
426
    /** set a structure attribute on the current structural element
427
428
    SetStructureAttribute sets an attribute of the current structural element to a
429
    new value. A consistency check is performed before actually setting the value;
430
    if the check fails, the function returns False and the attribute remains
431
    unchanged.
432
433
    @param eAttr
434
    denotes what attribute to change
435
436
    @param eVal
437
    the value to set the attribute to
438
     */
439
    void SetStructureAttribute( PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal );
440
    /** set a structure attribute on the current structural element
441
442
    SetStructureAttributeNumerical sets an attribute of the current structural element
443
    to a new numerical value. A consistency check is performed before actually setting
444
    the value; if the check fails, the function returns False and the attribute
445
    remains unchanged.
446
447
    @param eAttr
448
    denotes what attribute to change
449
450
    @param nValue
451
    the value to set the attribute to
452
     */
453
    void SetStructureAttributeNumerical( PDFWriter::StructAttribute eAttr, sal_Int32 nValue );
454
    /** set the bounding box of a structural element
455
456
    SetStructureBoundingBox sets the BBox attribute to a new value. Since the BBox
457
    attribute can only be applied to Table, Figure,
458
    Form and Formula elements, a call of this function
459
    for other element types will be ignored and the BBox attribute not be set.
460
461
    @param rRect
462
    the new bounding box for the structural element
463
     */
464
    void SetStructureBoundingBox( const tools::Rectangle& rRect );
465
466
    /** set the annotations that should be referenced as children of the
467
        current structural element.
468
     */
469
    void SetStructureAnnotIds(::std::vector<sal_Int32> const& rAnnotIds);
470
471
    /** set the ActualText attribute of a structural element
472
473
    ActualText contains the Unicode text without layout artifacts that is shown by
474
    a structural element. For example if a line is ended prematurely with a break in
475
    a word and continued on the next line (e.g. "happen-<newline>stance") the
476
    corresponding ActualText would contain the unbroken line (e.g. "happenstance").
477
478
    @param rText
479
    contains the complete logical text the structural element displays.
480
     */
481
    void SetActualText( const OUString& rText );
482
483
    /** set the Alt attribute of a structural element
484
485
    Alt is s replacement text describing the contents of a structural element. This
486
    is mainly used by accessibility applications; e.g. a screen reader would read
487
    the Alt replacement text for an image to a visually impaired user.
488
489
    @param rText
490
    contains the replacement text for the structural element
491
    */
492
    void SetAlternateText( const OUString& rText );
493
494
    /** Sets the transitional effect to be applied when the current page gets shown.
495
496
    @param eType
497
    the kind of effect to be used; use Regular to disable transitional effects
498
    for this page
499
500
    @param nMilliSec
501
    the duration of the transitional effect in milliseconds;
502
    set 0 to disable transitional effects
503
    */
504
    void SetPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec );
505
506
    /** create a new form control
507
508
    This function creates a new form control in the PDF and sets its various
509
    properties. Do not pass an actual AnyWidget as rControlType
510
    will be cast to the type described by the type member.
511
512
    @param rControlType
513
    a descendant of AnyWidget determining the control's properties
514
     */
515
    void    CreateControl( const PDFWriter::AnyWidget& rControlType );
516
};
517
518
}
519
520
#endif
521
522
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */