summaryrefslogtreecommitdiff
path: root/include/vcl/pdfextoutdevdata.hxx
blob: ea5466b8610f65d5cf297f8e947007d40683bcce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_VCL_PDFEXTOUTDEVDATA_HXX
#define INCLUDED_VCL_PDFEXTOUTDEVDATA_HXX

#include <vcl/dllapi.h>

#include <vcl/pdfwriter.hxx>
#include <vcl/extoutdevdata.hxx>
#include <vector>
#include <memory>

class Graphic;
class GDIMetaFile;

namespace vcl
{

/*
    A PDFExtOutDevBookmarkEntry is being created by the EditEngine if
    a bookmark URL has been parsed. The Application is requested to take
    care of each bookmark entry by emptying out the bookmark vector.
*/
struct PDFExtOutDevBookmarkEntry
{
    /** ID of the link pointing to the bookmark, or -1 if the entry denotes a destination instead of a link.
    */
    sal_Int32       nLinkId;

    /** ID of the named destination denoted by the bookmark, or -1 if the entry denotes a link instead of a named destination.
    */
    sal_Int32       nDestId;

    /** link target name, respectively destination name
    */
    OUString   aBookmark;

    PDFExtOutDevBookmarkEntry()
        :nLinkId( -1 )
        ,nDestId( -1 )
        ,aBookmark()
    {
    }
};

/*
 Class that is being set at the OutputDevice allowing the
 application to send enhanced PDF commands like CreateLink
*/
struct PageSyncData;
struct GlobalSyncData;
class VCL_DLLPUBLIC PDFExtOutDevData : public ExtOutDevData
{

    const OutputDevice&         mrOutDev;

    bool                        mbTaggedPDF;
    bool                        mbExportNotes;
    bool                        mbExportNotesPages;
    bool                        mbTransitionEffects;
    bool                        mbUseLosslessCompression;
    bool                        mbReduceImageResolution;
    bool                        mbExportFormFields;
    bool                        mbExportBookmarks;
    bool                        mbExportHiddenSlides;
    bool                        mbSinglePageSheets;
    bool                        mbExportNDests; //i56629
    sal_Int32                   mnPage;
    sal_Int32                   mnCompressionQuality;
    css::lang::Locale           maDocLocale;

    std::unique_ptr<PageSyncData> mpPageSyncData;
    std::unique_ptr<GlobalSyncData> mpGlobalSyncData;

    std::vector< PDFExtOutDevBookmarkEntry > maBookmarks;
    std::vector<OUString> maChapterNames;

public:

    PDFExtOutDevData( const OutputDevice& rOutDev );
    virtual ~PDFExtOutDevData() override;

    bool PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const GDIMetaFile& rMtf );
    void ResetSyncData();

    void PlayGlobalActions( PDFWriter& rWriter );

    bool    GetIsExportNotes() const { return mbExportNotes;}
    void        SetIsExportNotes( const bool bExportNotes );

    bool    GetIsExportNotesPages() const { return mbExportNotesPages;}
    void        SetIsExportNotesPages( const bool bExportNotesPages );

    bool    GetIsExportTaggedPDF() const { return mbTaggedPDF;}
    void        SetIsExportTaggedPDF( const bool bTaggedPDF );

    bool    GetIsExportTransitionEffects() const { return mbTransitionEffects;}
    void        SetIsExportTransitionEffects( const bool bTransitionalEffects );

    bool    GetIsExportFormFields() const { return mbExportFormFields;}
    void        SetIsExportFormFields( const bool bExportFormFields );

    bool    GetIsExportBookmarks() const { return mbExportBookmarks;}
    void        SetIsExportBookmarks( const bool bExportBookmarks );

    bool    GetIsExportHiddenSlides() const { return mbExportHiddenSlides;}
    void        SetIsExportHiddenSlides( const bool bExportHiddenSlides );

    void        SetIsSinglePageSheets( const bool bSinglePageSheets );

    bool    GetIsExportNamedDestinations() const { return mbExportNDests;} //i56629
    void        SetIsExportNamedDestinations( const bool bExportNDests ); //i56629

    // PageNumber, Compression is being set by the PDFExport
    sal_Int32   GetCurrentPageNumber() const { return mnPage;}
    void        SetCurrentPageNumber( const sal_Int32 nPage );

    bool        GetIsLosslessCompression() const { return mbUseLosslessCompression;}
    void        SetIsLosslessCompression( const bool bLosslessCompression );

    void        SetCompressionQuality( const sal_Int32 nQuality );

    bool        GetIsReduceImageResolution() const { return mbReduceImageResolution;}
    void        SetIsReduceImageResolution( const bool bReduceImageResolution );

    const css::lang::Locale& GetDocumentLocale() const { return maDocLocale;}
    void        SetDocumentLocale( const css::lang::Locale& rLoc );

    std::vector< PDFExtOutDevBookmarkEntry >& GetBookmarks() { return maBookmarks;}
    const std::vector<OUString>& GetChapterNames() const { return maChapterNames; }

    const Graphic& GetCurrentGraphic() const;

    /** Start a new group of render output

        Use this method to group render output.
     */
    void        BeginGroup();

    /** End render output

        This method ends grouped render output, that can be
        represented by a GfxLink. This is typically used for
        external graphic files, such as JPEGs, EPS files etc.
        The BeginGroup/EndGroup calls must exactly enclose the
        relevant OutputDevice calls issued to render the
        graphic the normal way.

        @param rGraphic
        The link to the original graphic

        @param nTransparency
        Eight bit transparency value, with 0 denoting full opacity,
        and 255 full transparency.

        @param rOutputRect
        The output rectangle of the graphic.

        @param rVisibleOutputRect
        The visible part of the output. This might be less than
        rOutputRect, e.g. for cropped graphics.
     */
    void        EndGroup( const Graphic&    rGraphic,
                          sal_uInt8         nTransparency,
                          const tools::Rectangle&  rOutputRect,
                          const tools::Rectangle&  rVisibleOutputRect );

    /// Detect if stream is compressed enough to avoid de-compress / scale & re-compress
    bool        HasAdequateCompression( const Graphic &rGraphic,
                                        const tools::Rectangle &rOutputRect,
                                        const tools::Rectangle &rVisibleOutputRect ) const;

//--->i56629
    /** Create a new named destination to be used in a link to this document from another PDF document
 (see PDF spec 1.4, 8.2.1)

    @param sDestName
    the name this destination will be addressed with from others PDF document

    @param rRect
    target rectangle on page to be displayed if dest is jumped to

    @param nPageNr
    number of page the dest is on (as returned by NewPage)
    or -1 in which case the current page is used

    @returns
    the destination id (to be used in SetLinkDest) or
    -1 if page id does not exist
    */
    sal_Int32 CreateNamedDest( const OUString& sDestName,  const tools::Rectangle& rRect, sal_Int32 nPageNr = -1 );

    /** registers a destination for which a destination ID needs to be known immediately, instead of later on setting it via
        SetLinkDest.

        This is used in contexts where a destination is referenced by means other than a link.

        Later in the export process, a call to DescribeRegisteredDest must be made, providing the information about
        the destination.

        @return
            the unique Id of the destination
    */
    sal_Int32   RegisterDest();

    /** provides detailed information about a destination range which previously has been registered using RegisterDest.
    */
    void        DescribeRegisteredDest( sal_Int32 nDestId, const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType = PDFWriter::DestAreaType::XYZ );

//<---i56629

    /** Create a new destination to be used in a link

    @param rRect
    target rectangle on page to be displayed if dest is jumped to

    @param nPageNr
    number of page the dest is on (as returned by NewPage)
    or -1 in which case the current page is used

    @param eType
    what dest type to use

    @returns
    the destination id (to be used in SetLinkDest) or
    -1 if page id does not exist
    */
    sal_Int32 CreateDest( const tools::Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::DestAreaType::XYZ );
    /** Create a new link on a page

    @param rRect
    active rectangle of the link (that is the area that has to be
    hit to activate the link)

    @param nPageNr
    number of page the link is on (as returned by NewPage)
    or -1 in which case the current page is used

    @returns
    the link id (to be used in SetLinkDest, SetLinkURL) or
    -1 if page id does not exist
    */
    sal_Int32 CreateLink( const tools::Rectangle& rRect, sal_Int32 nPageNr = -1 );

    /// Create a Screen annotation.
    sal_Int32 CreateScreen(const tools::Rectangle& rRect, sal_Int32 nPageNr);

    /** Set the destination for a link
        <p>will change a URL type link to a dest link if necessary</p>

        @param nLinkId
        the link to be changed

        @param nDestId
        the dest the link shall point to
    */
    void SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
    /** Set the URL for a link
        <p>will change a dest type link to a URL type link if necessary</p>
        @param nLinkId
        the link to be changed

        @param rURL
        the URL the link shall point to.
        there will be no error checking or any kind of
        conversion done to this parameter execept this:
        it will be output as 7bit Ascii. The URL
        will appear literally in the PDF file produced
    */
    void SetLinkURL( sal_Int32 nLinkId, const OUString& rURL );

    /// Set URL for a linked Screen annotation.
    void SetScreenURL(sal_Int32 nScreenId, const OUString& rURL);
    /// Set URL for an embedded Screen annotation.
    void SetScreenStream(sal_Int32 nScreenId, const OUString& rURL);

    /** Create a new outline item

        @param nParent
        declares the parent of the new item in the outline hierarchy.
        An invalid value will result in a new toplevel item.

        @param rText
        sets the title text of the item

        @param nDestID
        declares which Dest (created with CreateDest) the outline item
        will point to

        @returns
        the outline item id of the new item
    */
    sal_Int32 CreateOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID );

    /** Create a new note on a page

    @param rRect
    active rectangle of the note (that is the area that has to be
    hit to popup the annotation)

    @param rNote
    specifies the contents of the note

    @param nPageNr
    number of page the note is on (as returned by NewPage)
    or -1 in which case the current page is used
    */
    void CreateNote( const tools::Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr = -1 );

    /** begin a new logical structure element

    BeginStructureElement/EndStructureElement calls build the logical structure
    of the PDF - the basis for tagged PDF. Structural elements are implemented
    using marked content tags. Each structural element can contain sub elements
    (e.g. a section can contain a heading and a paragraph). The structure hierarchy
    is build automatically from the Begin/EndStructureElement calls.

    A structural element need not be contained on one page; e.g. paragraphs often
    run from one page to the next. In this case the corresponding EndStructureElement
    must be called while drawing the next page.

    BeginStructureElement and EndStructureElement must be called only after
    PDFWriter::NewPage has been called and before
    PDFWriter::Emit gets called. The current page
    number is an implicit context parameter for Begin/EndStructureElement.

    For pagination artifacts that are not part of the logical structure
    of the document (like header, footer or page number) the special
    StructElement NonStructElement exists. To place content
    outside of the structure tree simply call
    BeginStructureElement( NonStructElement ) then draw your
    content and then call EndStructureElement(). Any children
    of a NonStructElement will not be part of the structure as well.

    @param eType
    denotes what kind of element to begin (e.g. a heading or paragraph)

    @param rAlias
    the specified alias will be used as structure tag. Also an entry in the PDF's
    role map will be created mapping alias to regular structure type.

    @returns
    the id of the newly created structural element
     */
     sal_Int32 BeginStructureElement( PDFWriter::StructElement eType, const OUString& rAlias = OUString() );
    /** end a logical structure element

    @see BeginStructureElement
     */
    void EndStructureElement();
    /** set the current structure element

    <p>
    For different purposes it may be useful to paint a structure element's
    content discontinuously. In that case an already existing structure element
    can be appended to by using SetCurrentStructureElement. The
    referenced structure element becomes the current structure element with
    all consequences: all following structure elements are appended as children
    of the current element.
    </p>

    @param nElement
    the id of the new current structure element

    @returns
    True if the current structure element could be set successfully
    False if the current structure element could not be changed
    (e.g. if the passed element id is invalid)
     */
    bool SetCurrentStructureElement( sal_Int32 nElement );
    /** get the current structure element id

    @returns
    the id of the current structure element
    */
    sal_Int32 GetCurrentStructureElement() const;

    /** set a structure attribute on the current structural element

    SetStructureAttribute sets an attribute of the current structural element to a
    new value. A consistency check is performed before actually setting the value;
    if the check fails, the function returns False and the attribute remains
    unchanged.

    @param eAttr
    denotes what attribute to change

    @param eVal
    the value to set the attribute to
     */
    void SetStructureAttribute( PDFWriter::StructAttribute eAttr, PDFWriter::StructAttributeValue eVal );
    /** set a structure attribute on the current structural element

    SetStructureAttributeNumerical sets an attribute of the current structural element
    to a new numerical value. A consistency check is performed before actually setting
    the value; if the check fails, the function returns False and the attribute
    remains unchanged.

    @param eAttr
    denotes what attribute to change

    @param nValue
    the value to set the attribute to
     */
    void SetStructureAttributeNumerical( PDFWriter::StructAttribute eAttr, sal_Int32 nValue );
    /** set the bounding box of a structural element

    SetStructureBoundingBox sets the BBox attribute to a new value. Since the BBox
    attribute can only be applied to Table, Figure,
    Form and Formula elements, a call of this function
    for other element types will be ignored and the BBox attribute not be set.

    @param rRect
    the new bounding box for the structural element
     */
    void SetStructureBoundingBox( const tools::Rectangle& rRect );

    /** set the ActualText attribute of a structural element

    ActualText contains the Unicode text without layout artifacts that is shown by
    a structural element. For example if a line is ended prematurely with a break in
    a word and continued on the next line (e.g. "happen-<newline>stance") the
    corresponding ActualText would contain the unbroken line (e.g. "happenstance").

    @param rText
    contains the complete logical text the structural element displays.
     */
    void SetActualText( const OUString& rText );

    /** set the Alt attribute of a strutural element

    Alt is s replacement text describing the contents of a structural element. This
    is mainly used by accessibility applications; e.g. a screen reader would read
    the Alt replacement text for an image to a visually impaired user.

    @param rText
    contains the replacement text for the structural element
    */
    void SetAlternateText( const OUString& rText );

    /** Sets the transitional effect to be applied when the current page gets shown.

    @param eType
    the kind of effect to be used; use Regular to disable transitional effects
    for this page

    @param nMilliSec
    the duration of the transitional effect in milliseconds;
    set 0 to disable transitional effects
    */
    void SetPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec );

    /** create a new form control

    This function creates a new form control in the PDF and sets its various
    properties. Do not pass an actual AnyWidget as rControlType
    will be cast to the type described by the type member.

    @param rControlType
    a descendant of AnyWidget determining the control's properties
     */
    void    CreateControl( const PDFWriter::AnyWidget& rControlType );
};

}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */