Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/inc/printfun.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
#pragma once
21
22
#include <memory>
23
#include <map>
24
#include <pagepar.hxx>
25
#include <editutil.hxx>
26
27
class SfxPrinter;
28
class ScDocShell;
29
class ScDocument;
30
class ScViewData;
31
class SfxItemSet;
32
class ScPageHFItem;
33
class EditTextObject;
34
class MultiSelection;
35
class ScPageBreakData;
36
class ScPreviewLocationData;
37
class ScPrintOptions;
38
class SvxBoxItem;
39
class SvxBrushItem;
40
class SvxShadowItem;
41
class FmFormView;
42
43
119k
#define RANGENO_NORANGE             USHRT_MAX
44
45
constexpr sal_Int64 PRINT_HEADER_WIDTH = o3tl::toTwips(1, o3tl::Length::cm);
46
constexpr sal_Int64 PRINT_HEADER_HEIGHT = o3tl::toTwips(12.8, o3tl::Length::pt);
47
48
                                            // Settings for headers/footers
49
struct ScPrintHFParam
50
{
51
    bool                bEnable;
52
    bool                bDynamic;
53
    bool                bShared;
54
    bool                bSharedFirst;
55
    tools::Long                nHeight;            // in total (height + distance + frames)
56
    tools::Long                nManHeight;         // set size (min when dynamic)
57
    sal_uInt16          nDistance;
58
    sal_uInt16          nLeft;              // edges
59
    sal_uInt16          nRight;
60
    const ScPageHFItem* pLeft;
61
    const ScPageHFItem* pRight;
62
    const ScPageHFItem* pFirst;
63
    const SvxBoxItem*   pBorder;
64
    const SvxBrushItem* pBack;
65
    const SvxShadowItem* pShadow;
66
};
67
68
class ScPageRowEntry
69
{
70
private:
71
    SCROW                    nStartRow;
72
    SCROW                    nEndRow;
73
    size_t                   nPagesX;
74
    std::vector<bool>        aHidden;
75
    //!     Cache Number of really visible?
76
77
public:
78
39.8k
            ScPageRowEntry()    { nStartRow = nEndRow = 0; nPagesX = 0; }
79
80
            ScPageRowEntry(const ScPageRowEntry& r);
81
    ScPageRowEntry& operator=(const ScPageRowEntry& r);
82
83
0
    SCROW   GetStartRow() const     { return nStartRow; }
84
0
    SCROW   GetEndRow() const       { return nEndRow; }
85
0
    size_t  GetPagesX() const       { return nPagesX; }
86
39.8k
    void    SetStartRow(SCROW n)    { nStartRow = n; }
87
39.8k
    void    SetEndRow(SCROW n)      { nEndRow = n; }
88
89
    void    SetPagesX(size_t nNew);
90
    void    SetHidden(size_t nX);
91
    bool    IsHidden(size_t nX) const;
92
93
    size_t  CountVisible() const;
94
};
95
96
namespace sc
97
{
98
99
struct PrintPageRangesInput
100
{
101
    bool m_bSkipEmpty;
102
    bool m_bPrintArea;
103
    ScRange m_aRange;
104
    Size  m_aDocSize;
105
106
    PrintPageRangesInput()
107
40.8k
        : m_bSkipEmpty(false)
108
40.8k
        , m_bPrintArea(false)
109
40.8k
    {}
110
111
    PrintPageRangesInput(bool bSkipEmpty, bool bPrintArea, ScRange const& rRange, Size const& rDocSize)
112
39.8k
        : m_bSkipEmpty(bSkipEmpty)
113
39.8k
        , m_bPrintArea(bPrintArea)
114
39.8k
        , m_aRange(rRange)
115
39.8k
        , m_aDocSize(rDocSize)
116
39.8k
    {}
117
118
    bool operator==(PrintPageRangesInput const& rInput) const
119
39.8k
    {
120
39.8k
        return
121
39.8k
            m_bSkipEmpty == rInput.m_bSkipEmpty &&
122
39.8k
            m_bPrintArea == rInput.m_bPrintArea &&
123
39.7k
            m_aRange == rInput.m_aRange &&
124
38.1k
            m_aDocSize   == rInput.m_aDocSize;
125
39.8k
    }
126
127
    PrintPageRangesInput& operator=(PrintPageRangesInput const& rInput)
128
39.8k
    {
129
39.8k
        m_bSkipEmpty = rInput.m_bSkipEmpty;
130
39.8k
        m_bPrintArea = rInput.m_bPrintArea;
131
39.8k
        m_aRange = rInput.m_aRange;
132
39.8k
        m_aDocSize = rInput.m_aDocSize;
133
134
39.8k
        return *this;
135
39.8k
    }
136
137
    SCROW getStartRow() const
138
162k
    {
139
162k
        return m_aRange.aStart.Row();
140
162k
    }
141
142
    SCROW getEndRow() const
143
201k
    {
144
201k
        return m_aRange.aEnd.Row();
145
201k
    }
146
147
    SCCOL getStartColumn() const
148
86.0k
    {
149
86.0k
        return m_aRange.aStart.Col();
150
86.0k
    }
151
152
    SCCOL getEndColumn() const
153
125k
    {
154
125k
        return m_aRange.aEnd.Col();
155
125k
    }
156
157
    SCTAB getPrintTab() const
158
251k
    {
159
251k
        return m_aRange.aStart.Tab();
160
251k
    }
161
};
162
163
class PrintPageRanges
164
{
165
public:
166
    PrintPageRanges();
167
168
    // use shared_ptr to avoid copying this (potentially large) data back and forth
169
    std::shared_ptr<std::vector<SCCOL>> m_xPageEndX;
170
    std::shared_ptr<std::vector<SCROW>> m_xPageEndY;
171
    std::shared_ptr<std::map<size_t, ScPageRowEntry>> m_xPageRows;
172
173
    size_t m_nPagesX;
174
    size_t m_nPagesY;
175
    size_t m_nTotalY;
176
177
    PrintPageRangesInput m_aInput;
178
179
    void calculate(ScDocument& rDoc, PrintPageRangesInput const& rInput);
180
};
181
182
} // end sc namespace
183
184
// Used to save expensive-to-compute data from ScPrintFunc in between
185
// uses of ScPrintFunc
186
struct ScPrintState
187
{
188
    SCTAB   nPrintTab;
189
    SCCOL   nStartCol;
190
    SCROW   nStartRow;
191
    SCCOL   nEndCol;
192
    SCROW   nEndRow;
193
    bool    bPrintAreaValid; // the 4 variables above are set
194
    sal_uInt16  nZoom;
195
    tools::Long    nTabPages;
196
    tools::Long    nTotalPages;
197
    tools::Long    nPageStart;
198
    tools::Long    nDocPages;
199
200
    // Additional state of page ranges
201
    sc::PrintPageRanges m_aRanges;
202
203
    ScPrintState()
204
0
        : nPrintTab(0)
205
0
        , nStartCol(0)
206
0
        , nStartRow(0)
207
0
        , nEndCol(0)
208
0
        , nEndRow(0)
209
0
        , bPrintAreaValid(false)
210
0
        , nZoom(0)
211
0
        , nTabPages(0)
212
0
        , nTotalPages(0)
213
0
        , nPageStart(0)
214
0
        , nDocPages(0)
215
0
    {}
216
};
217
218
class ScPrintFunc
219
{
220
private:
221
    ScDocShell&         rDocShell;
222
    ScDocument&         rDoc;
223
    VclPtr<SfxPrinter>   pPrinter;
224
    VclPtr<OutputDevice> pDev;
225
    FmFormView*         pDrawView;
226
227
    MapMode             aOldPrinterMode;    //  MapMode before the call
228
229
    Point               aSrcOffset;         //  Paper-1/100 mm
230
    Point               aOffset;            //  scaled by a factor of page size
231
    sal_uInt16          nManualZoom;        //  Zoom in Preview (percent)
232
    bool                bClearWin;          //  Clear output before
233
    bool                bUseStyleColor;
234
    bool                bIsRender;
235
236
    SCTAB               nPrintTab;
237
    tools::Long                nPageStart;         //  Offset for the first page
238
    tools::Long                nDocPages;          //  Number of Pages in Document
239
240
    const ScRange*      pUserArea;          //  Selection, if set in dialog
241
242
    const SfxItemSet*   pParamSet;          //  Selected template
243
    bool                bFromPrintState;    // created from State-struct
244
245
                                            //  Parameter from template:
246
    sal_uInt16          nLeftMargin;
247
    sal_uInt16          nTopMargin;
248
    sal_uInt16          nRightMargin;
249
    sal_uInt16          nBottomMargin;
250
    bool                bCenterHor;
251
    bool                bCenterVer;
252
    bool                bLandscape;
253
    bool                bSourceRangeValid;
254
255
    SvxPageUsage        nPageUsage;
256
    Size                aPageSize;          // Printer Twips
257
    const SvxBoxItem*   pBorderItem;
258
    const SvxBrushItem* pBackgroundItem;
259
    const SvxShadowItem* pShadowItem;
260
261
    ScRange             aLastSourceRange;
262
    ScPrintHFParam      aHdr;
263
    ScPrintHFParam      aFtr;
264
    ScPageTableParam    aTableParam;
265
    ScPageAreaParam     aAreaParam;
266
267
                                            // Calculated values:
268
    sal_uInt16          nZoom;
269
    bool                bPrintCurrentTable;
270
    bool                bMultiArea;
271
    bool                mbHasPrintRange;
272
    tools::Long                nTabPages;
273
    tools::Long                nTotalPages;
274
275
    tools::Rectangle           aPageRect;          // Document Twips
276
277
    MapMode             aLogicMode;         // Set in DoPrint
278
    MapMode             aOffsetMode;
279
    MapMode             aTwipMode;
280
    double              nScaleX;
281
    double              nScaleY;
282
283
    SCCOL               nRepeatStartCol;
284
    SCCOL               nRepeatEndCol;
285
    SCROW               nRepeatStartRow;
286
    SCROW               nRepeatEndRow;
287
288
    SCCOL               nStartCol;
289
    SCROW               nStartRow;
290
    SCCOL               nEndCol;
291
    SCROW               nEndRow;
292
    bool                bPrintAreaValid; // the 4 variables above are set
293
294
    sc::PrintPageRanges m_aRanges;
295
296
    std::unique_ptr<ScHeaderEditEngine> pEditEngine;
297
    std::unique_ptr<SfxItemSet>         pEditDefaults;
298
299
    ScHeaderFieldData   aFieldData;
300
301
    std::vector<ScAddress> aNotePosList;        // The order of notes
302
303
    ScPageBreakData*    pPageData;          // for recording the breaks etc.
304
305
    Size                aPrintPageSize;         // print page size in Print dialog
306
    bool                bPrintPageLandscape;    // print page orientation in Print dialog
307
    bool                bUsePrintDialogSetting; // use Print dialog setting
308
309
public:
310
                    ScPrintFunc( ScDocShell& rShell, SfxPrinter* pNewPrinter, SCTAB nTab,
311
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
312
                                 const ScRange* pArea = nullptr,
313
                                 const ScPrintOptions* pOptions = nullptr,
314
                                 ScPageBreakData* pData = nullptr,
315
                                 Size aPrintPageSize = {},
316
                                 bool bPrintPageLandscape = false,
317
                                 bool bUsePrintDialogSetting = false );
318
319
                    ScPrintFunc( ScDocShell& rShell, SfxPrinter* pNewPrinter,
320
                                const ScPrintState& rState, const ScPrintOptions* pOptions,
321
                                Size aPrintPageSize = {},
322
                                bool bPrintPageLandscape = false,
323
                                bool bUsePrintDialogSetting = false );
324
325
                    // ctors for device other than printer - for preview and pdf:
326
327
                    ScPrintFunc( OutputDevice* pOutDev, ScDocShell& rShell, SCTAB nTab,
328
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
329
                                 const ScRange* pArea = nullptr,
330
                                 const ScPrintOptions* pOptions = nullptr );
331
332
                    ScPrintFunc( OutputDevice* pOutDev, ScDocShell& rShell,
333
                                 const ScPrintState& rState,
334
                                 const ScPrintOptions* pOptions, Size aPrintPageSize = {},
335
                                 bool bPrintPageLandscape = false,
336
                                 bool bUsePrintDialogSetting = false);
337
338
                    ~ScPrintFunc();
339
340
    static void     DrawToDev( ScDocument& rDoc, OutputDevice* pDev, double nPrintFactor,
341
                               const tools::Rectangle& rBound, ScViewData& rViewData, bool bMetaFile );
342
343
    void            SetDrawView( FmFormView* pNew );
344
345
    void            SetOffset( const Point& rOfs );
346
    void            SetManualZoom( sal_uInt16 nNewZoom );
347
    void            SetDateTime( const DateTime& );
348
349
    void            SetClearFlag( bool bFlag );
350
    void            SetUseStyleColor( bool bFlag );
351
    void            SetRenderFlag( bool bFlag );
352
353
    void            SetExclusivelyDrawOleAndDrawObjects();//for printing selected objects without surrounding cell contents
354
355
    bool            UpdatePages();
356
357
    void            ApplyPrintSettings();       // Already called from DoPrint()
358
    tools::Long            DoPrint( const MultiSelection& rPageRanges,
359
                                tools::Long nStartPage, tools::Long nDisplayStart, bool bDoPrint,
360
                                ScPreviewLocationData* pLocationData );
361
362
                    // Query values - immediately
363
364
0
    const Size&     GetPageSize() const { return aPageSize; }
365
    Size            GetDataSize() const;
366
    void            GetScaleData( Size& rPhysSize, tools::Long& rDocHdr, tools::Long& rDocFtr );
367
0
    tools::Long            GetFirstPageNo() const  { return aTableParam.nFirstPageNo; }
368
369
0
    tools::Long            GetTotalPages() const { return nTotalPages; }
370
0
    sal_uInt16      GetZoom() const { return nZoom; }
371
372
    void            ResetBreaks( SCTAB nTab );
373
374
    void            GetPrintState(ScPrintState& rState);
375
    bool            GetLastSourceRange( ScRange& rRange ) const;
376
0
    sal_uInt16      GetLeftMargin() const{return nLeftMargin;}
377
0
    sal_uInt16      GetRightMargin() const{return nRightMargin;}
378
0
    sal_uInt16      GetTopMargin() const{return nTopMargin;}
379
0
    sal_uInt16      GetBottomMargin() const{return nBottomMargin;}
380
0
    const ScPrintHFParam& GetHeader() const {return aHdr;}
381
0
    const ScPrintHFParam& GetFooter() const {return aFtr;}
382
383
0
    bool HasPrintRange() const { return mbHasPrintRange;}
384
385
private:
386
    void            Construct( const ScPrintOptions* pOptions );
387
    void            InitParam( const ScPrintOptions* pOptions );
388
    void            CalcZoom( sal_uInt16 nRangeNo );
389
    void            CalcPages();
390
    tools::Long            CountPages();
391
    tools::Long            CountNotePages();
392
393
    bool            AdjustPrintArea( bool bNew );
394
395
    Size            GetDocPageSize();
396
397
    tools::Long            TextHeight( const EditTextObject* pObject );
398
    void            MakeEditEngine();
399
    void            UpdateHFHeight( ScPrintHFParam& rParam );
400
401
    void            InitModes();
402
403
    bool            IsLeft( tools::Long nPageNo );
404
    bool            IsMirror( tools::Long nPageNo );
405
    void            MakeTableString();                  // sets aTableStr
406
407
    void            PrintPage( tools::Long nPageNo,
408
                                    SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
409
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );
410
    void            PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
411
                                    tools::Long nScrX, tools::Long nScrY,
412
                                    bool bShLeft, bool bShTop, bool bShRight, bool bShBottom );
413
    void            LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
414
                                    tools::Long nScrX, tools::Long nScrY, bool bRepCol, bool bRepRow,
415
                                    ScPreviewLocationData& rLocationData );
416
    void            PrintColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY );
417
    void            PrintRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY );
418
    void            LocateColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY,
419
                                bool bRepCol, ScPreviewLocationData& rLocationData );
420
    void            LocateRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY,
421
                                bool bRepRow, ScPreviewLocationData& rLocationData );
422
    void            PrintHF( tools::Long nPageNo, bool bHeader, tools::Long nStartY,
423
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );
424
425
    tools::Long            PrintNotes( tools::Long nPageNo, tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
426
    tools::Long            DoNotes( tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
427
428
    void            DrawBorder( tools::Long nScrX, tools::Long nScrY, tools::Long nScrW, tools::Long nScrH,
429
                                    const SvxBoxItem* pBorderData,
430
                                    const SvxBrushItem* pBackground,
431
                                    const SvxShadowItem* pShadow );
432
433
    void            FillPageData();
434
};
435
436
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */