Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/printdata.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
#ifndef INCLUDED_SW_INC_PRINTDATA_HXX
20
#define INCLUDED_SW_INC_PRINTDATA_HXX
21
22
#include <sal/types.h>
23
#include <rtl/ustring.hxx>
24
#include <vcl/print.hxx>
25
#include <sfx2/objsh.hxx>
26
27
#include <o3tl/sorted_vector.hxx>
28
#include <map>
29
#include <vector>
30
#include <utility>
31
#include <memory>
32
33
class SwDoc;
34
class SwDocShell;
35
class SetGetExpFields;
36
class SwViewOption;
37
class SwViewOptionAdjust_Impl;
38
class SwViewShell;
39
class SwRenderData;
40
41
/** this must match the definitions in css::text::NotePrintMode */
42
enum class SwPostItMode
43
{
44
    NONE    = 0,
45
    Only    = 1,
46
    EndDoc  = 2,
47
    EndPage = 3,
48
    InMargins = 4
49
};
50
51
52
class SwPrintData
53
{
54
    const SwRenderData *        m_pRenderData;      // not owner
55
56
public:
57
58
    bool m_bPrintGraphic, m_bPrintControl, m_bPrintPageBackground,
59
             m_bPrintBlackFont,
60
             //#i81434# - printing of hidden text
61
             m_bPrintHiddenText, m_bPrintTextPlaceholder,
62
             m_bPrintLeftPages, m_bPrintRightPages, m_bPrintProspect,
63
             m_bPrintProspectRTL,
64
             m_bPaperFromSetup,
65
             /// Print empty pages
66
             m_bPrintEmptyPages;
67
68
    SwPostItMode    m_nPrintPostIts;
69
    OUString       m_sFaxName;
70
71
    SwPrintData()
72
43.2k
    {
73
43.2k
        m_pRenderData        = nullptr;
74
75
43.2k
        m_bPrintGraphic           =
76
43.2k
        m_bPrintControl           =
77
43.2k
        m_bPrintLeftPages         =
78
43.2k
        m_bPrintRightPages        =
79
43.2k
        m_bPrintPageBackground    =
80
43.2k
        m_bPrintEmptyPages        = true;
81
82
43.2k
        m_bPaperFromSetup         =
83
43.2k
        m_bPrintProspect          =
84
43.2k
        m_bPrintProspectRTL       =
85
43.2k
        m_bPrintBlackFont         =
86
43.2k
        m_bPrintHiddenText        =
87
43.2k
        m_bPrintTextPlaceholder   = false;
88
89
43.2k
        m_nPrintPostIts           = SwPostItMode::NONE;
90
43.2k
    }
91
92
144k
    virtual ~SwPrintData() {}
93
94
101k
    SwPrintData(SwPrintData const &) = default;
95
    SwPrintData(SwPrintData &&) = default;
96
27.3k
    SwPrintData & operator =(SwPrintData const &) = default;
97
12.2k
    SwPrintData & operator =(SwPrintData &&) = default;
98
99
    bool operator==(const SwPrintData& rData)const
100
0
    {
101
0
        return
102
0
        m_bPrintGraphic       ==   rData.m_bPrintGraphic        &&
103
0
        m_bPrintControl       ==   rData.m_bPrintControl        &&
104
0
        m_bPrintPageBackground==   rData.m_bPrintPageBackground &&
105
0
        m_bPrintBlackFont     ==   rData.m_bPrintBlackFont      &&
106
0
        m_bPrintLeftPages     ==   rData.m_bPrintLeftPages      &&
107
0
        m_bPrintRightPages    ==   rData.m_bPrintRightPages     &&
108
0
        m_bPrintProspect      ==   rData.m_bPrintProspect       &&
109
0
        m_bPrintProspectRTL   ==   rData.m_bPrintProspectRTL    &&
110
0
        m_bPaperFromSetup     ==   rData.m_bPaperFromSetup      &&
111
0
        m_bPrintEmptyPages    ==   rData.m_bPrintEmptyPages     &&
112
0
        m_nPrintPostIts       ==   rData.m_nPrintPostIts        &&
113
0
        m_sFaxName            ==   rData.m_sFaxName             &&
114
0
        m_bPrintHiddenText    ==   rData.m_bPrintHiddenText     &&
115
0
        m_bPrintTextPlaceholder   ==   rData.m_bPrintTextPlaceholder;
116
0
    }
117
118
    /** Note: in the context where this class is used the pointers should always be valid
119
       during the lifetime of this object */
120
140k
    const SwRenderData &        GetRenderData() const           { return *m_pRenderData; }
121
8.61k
    void  SetRenderData( const SwRenderData *pData )            { m_pRenderData = pData; }
122
123
0
    bool IsPrintGraphic() const             { return m_bPrintGraphic; }
124
0
    bool IsPrintControl() const             { return m_bPrintControl; }
125
0
    bool IsPrintLeftPage() const            { return m_bPrintLeftPages; }
126
0
    bool IsPrintRightPage() const           { return m_bPrintRightPages; }
127
0
    bool IsPaperFromSetup() const           { return m_bPaperFromSetup; }
128
8.61k
    bool IsPrintEmptyPages() const          { return m_bPrintEmptyPages; }
129
0
    bool IsPrintProspect() const            { return m_bPrintProspect; }
130
0
    bool IsPrintProspectRTL() const         { return m_bPrintProspectRTL; }
131
0
    bool IsPrintPageBackground() const      { return m_bPrintPageBackground; }
132
0
    bool IsPrintBlackFont() const           { return m_bPrintBlackFont; }
133
77.8k
    SwPostItMode GetPrintPostIts() const           { return m_nPrintPostIts; }
134
0
    const OUString& GetFaxName() const      { return m_sFaxName; }
135
0
    bool IsPrintHiddenText() const          { return m_bPrintHiddenText; }
136
0
    bool IsPrintTextPlaceholder() const     { return m_bPrintTextPlaceholder; }
137
138
9.30k
    void SetPrintGraphic( bool b )              { doSetModified(); m_bPrintGraphic = b; }
139
8.61k
    void SetPrintControl( bool b )              { doSetModified(); m_bPrintControl = b; }
140
8.61k
    void SetPrintLeftPage( bool b )             { doSetModified(); m_bPrintLeftPages = b; }
141
8.61k
    void SetPrintRightPage( bool b )            { doSetModified(); m_bPrintRightPages = b; }
142
8.61k
    void SetPaperFromSetup( bool b )            { doSetModified(); m_bPaperFromSetup = b; }
143
8.61k
    void SetPrintEmptyPages( bool b )           { doSetModified(); m_bPrintEmptyPages = b; }
144
79.0k
    void SetPrintPostIts( SwPostItMode n )      { doSetModified(); m_nPrintPostIts = n; }
145
8.61k
    void SetPrintProspect( bool b )             { doSetModified(); m_bPrintProspect = b; }
146
9.23k
    void SetPrintProspect_RTL( bool b )         { doSetModified(); m_bPrintProspectRTL = b; }
147
8.61k
    void SetPrintPageBackground( bool b )       { doSetModified(); m_bPrintPageBackground = b; }
148
8.61k
    void SetPrintBlackFont( bool b )            { doSetModified(); m_bPrintBlackFont = b; }
149
0
    void SetFaxName( const OUString& rSet )     { m_sFaxName = rSet; }
150
8.61k
    void SetPrintHiddenText( bool b )           { doSetModified(); m_bPrintHiddenText = b; }
151
8.61k
    void SetPrintTextPlaceholder( bool b )      { doSetModified(); m_bPrintTextPlaceholder = b; }
152
153
183k
    virtual void doSetModified () {}
154
};
155
156
class SwPrintUIOptions final : public vcl::PrinterOptionsHelper
157
{
158
    VclPtr< OutputDevice > m_pLast;
159
    const SwPrintData & m_rDefaultPrintData;
160
161
public:
162
    SwPrintUIOptions( sal_uInt16 nCurrentPage, bool bWeb, bool bSwSrcView, bool bHasSelection, bool bHasPostIts, const SwPrintData &rDefaultPrintData );
163
    ~SwPrintUIOptions();
164
165
    bool processPropertiesAndCheckFormat( const css::uno::Sequence< css::beans::PropertyValue >& i_rNewProp );
166
167
17.2k
    bool IsPrintFormControls() const            { return getBoolValue( "PrintControls",        m_rDefaultPrintData.m_bPrintControl ); }
168
17.2k
    bool IsPrintPageBackground() const          { return getBoolValue( "PrintPageBackground",  m_rDefaultPrintData.m_bPrintPageBackground ); }
169
17.2k
    bool IsPrintProspect() const                { return getBoolValue( "PrintProspect",        m_rDefaultPrintData.m_bPrintProspect ); }
170
17.2k
    bool IsPrintProspectRTL() const             { return getIntValue( "PrintProspectRTL",      m_rDefaultPrintData.m_bPrintProspectRTL ? 1 : 0 ) != 0; }
171
17.2k
    bool IsPrintTextPlaceholders() const        { return getBoolValue( "PrintTextPlaceholder", m_rDefaultPrintData.m_bPrintTextPlaceholder ); }
172
17.2k
    bool IsPrintHiddenText() const              { return getBoolValue( "PrintHiddenText",      m_rDefaultPrintData.m_bPrintHiddenText ); }
173
17.2k
    bool IsPrintWithBlackTextColor() const      { return getBoolValue( "PrintBlackFonts",      m_rDefaultPrintData.m_bPrintBlackFont ); }
174
17.2k
    SwPostItMode GetPrintPostItsType() const       { return static_cast< SwPostItMode >(getIntValue( "PrintAnnotationMode", static_cast<sal_uInt16>(m_rDefaultPrintData.m_nPrintPostIts) )); }
175
17.2k
    bool IsPaperFromSetup() const               { return getBoolValue( "PrintPaperFromSetup",  m_rDefaultPrintData.m_bPaperFromSetup ); }
176
177
    bool IsPrintLeftPages() const;
178
    bool IsPrintRightPages() const;
179
    bool IsPrintEmptyPages( bool bIsPDFExport ) const;
180
    bool IsPrintGraphics() const;
181
};
182
183
/** A class that stores temporary data that is needed for rendering the document.
184
   Usually this data is created when 'getRendererCount' is called and
185
   and it is used in the 'render' function of that same interface */
186
class SwRenderData
187
{
188
    /** pages valid for printing (according to the current settings)
189
     This set of pages does NOT depend on the 'PageRange' that is used as a printing option! */
190
    o3tl::sorted_vector< sal_Int32 >            m_aValidPages;          ///< the set of possible pages (see StringRangeEnumerator::getRangesFromString )
191
192
    /// printer paper tray to use for each of the m_aValidPages above
193
    std::map< sal_Int32, sal_Int32 >            m_aPrinterPaperTrays;
194
195
    /** vector of pages and their order to be printed (duplicates and any order allowed!)
196
       (see 'render' in unotxdoc.cxx)
197
       negative entry indicates the page to be printed is from the post-it doc */
198
    std::vector< sal_Int32 >                    m_aPagesToPrint;
199
200
    /** for prospect printing: the pairs of pages to be printed together on a single prospect page.
201
       -1 indicates a half page to be left empty. */
202
    std::vector< std::pair< sal_Int32, sal_Int32 > >    m_aPagePairs;
203
204
    OUString               m_aPageRange;
205
206
    /** temp print document -- must live longer than m_pViewOptionAdjust!
207
       also this is a Lock and not a Ref because Ref does not delete the doc */
208
    SfxObjectShellLock m_xTempDocShell;
209
210
    /// the view options to be applied for printing
211
    std::unique_ptr<SwViewOptionAdjust_Impl> m_pViewOptionAdjust;
212
213
    std::unique_ptr<SwPrintData>    m_pPrtOptions;
214
215
public:
216
217
    // PostIt relevant data
218
    /// an array of "SetGetExpField *" sorted by page and line numbers
219
    std::unique_ptr<SetGetExpFields> m_pPostItFields;
220
    /// this contains a SwDoc with the post-it content
221
    std::unique_ptr<SwViewShell>      m_pPostItShell;
222
223
public:
224
    SwRenderData();
225
    ~SwRenderData();
226
227
8.59k
    bool HasPostItData() const  { return m_pPostItShell != nullptr; }
228
    void CreatePostItData( SwDoc& rDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev );
229
    void DeletePostItData();
230
231
0
    SfxObjectShellLock const& GetTempDocShell() const { return m_xTempDocShell;}
232
    void SetTempDocShell(SfxObjectShellLock const&);
233
234
17.2k
    bool IsViewOptionAdjust() const  { return m_pViewOptionAdjust != nullptr; }
235
    bool NeedNewViewOptionAdjust( const SwViewShell& ) const;
236
    void ViewOptionAdjustStart( SwViewShell &rSh, const SwViewOption &rViewOptions);
237
    void ViewOptionAdjust( SwPrintData const* const pPrtOptions, bool setShowPlaceHoldersInPDF );
238
    void ViewOptionAdjustStop();
239
    void ViewOptionAdjustCrashPreventionKludge();
240
241
70.4k
    bool HasSwPrtOptions() const    { return m_pPrtOptions != nullptr; }
242
70.4k
    SwPrintData const*  GetSwPrtOptions() const { return m_pPrtOptions.get(); }
243
    void MakeSwPrtOptions( SwDocShell const*const pDocShell,
244
            SwPrintUIOptions const*const pOpt, bool const bIsPDFExport );
245
246
    typedef std::vector< std::pair< sal_Int32, sal_Int32 > >    PagePairsVec_t;
247
248
17.2k
    o3tl::sorted_vector< sal_Int32 > &       GetValidPagesSet()          { return m_aValidPages; }
249
0
    const o3tl::sorted_vector< sal_Int32 > & GetValidPagesSet() const    { return m_aValidPages; }
250
251
    /** a map for printer paper tray numbers to use for each document page
252
       a value of -1 for the tray means that there is no specific tray defined */
253
79.0k
    std::map< sal_Int32, sal_Int32 >&        GetPrinterPaperTrays()          { return m_aPrinterPaperTrays; }
254
0
    const std::map< sal_Int32, sal_Int32 >&  GetPrinterPaperTrays() const    { return m_aPrinterPaperTrays; }
255
256
    /** used for 'normal' printing
257
       A page value of 0 as entry indicates that this page is not from the document but
258
       from the post-it document. (See also GetPostItStartFrame below) */
259
228k
    std::vector< sal_Int32 > &          GetPagesToPrint()           { return m_aPagesToPrint; }
260
140k
    const std::vector< sal_Int32 > &    GetPagesToPrint() const     { return m_aPagesToPrint; }
261
262
    /// used for prospect printing only
263
0
    PagePairsVec_t &                    GetPagePairsForProspectPrinting()           { return m_aPagePairs; }
264
0
    const PagePairsVec_t &              GetPagePairsForProspectPrinting() const     { return m_aPagePairs; }
265
266
0
    const OUString& GetPageRange() const                            { return m_aPageRange; }
267
8.61k
    void            SetPageRange( const OUString &rRange )     { m_aPageRange = rRange; }
268
};
269
270
namespace sw {
271
272
void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb);
273
274
} ///< namespace sw
275
276
#endif // INCLUDED_SW_INC_PRINTDATA_HXX
277
278
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */