Coverage Report

Created: 2026-10-14 09:33

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
3.15k
#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
1.05k
            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
1.05k
    void    SetStartRow(SCROW n)    { nStartRow = n; }
87
1.05k
    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
1.08k
        : m_bSkipEmpty(false)
108
1.08k
        , m_bPrintArea(false)
109
1.08k
    {}
110
111
    PrintPageRangesInput(bool bSkipEmpty, bool bPrintArea, ScRange const& rRange, Size const& rDocSize)
112
1.05k
        : m_bSkipEmpty(bSkipEmpty)
113
1.05k
        , m_bPrintArea(bPrintArea)
114
1.05k
        , m_aRange(rRange)
115
1.05k
        , m_aDocSize(rDocSize)
116
1.05k
    {}
117
118
    bool operator==(PrintPageRangesInput const& rInput) const
119
1.05k
    {
120
1.05k
        return
121
1.05k
            m_bSkipEmpty == rInput.m_bSkipEmpty &&
122
1.05k
            m_bPrintArea == rInput.m_bPrintArea &&
123
965
            m_aRange == rInput.m_aRange &&
124
426
            m_aDocSize   == rInput.m_aDocSize;
125
1.05k
    }
126
127
    PrintPageRangesInput& operator=(PrintPageRangesInput const& rInput)
128
1.05k
    {
129
1.05k
        m_bSkipEmpty = rInput.m_bSkipEmpty;
130
1.05k
        m_bPrintArea = rInput.m_bPrintArea;
131
1.05k
        m_aRange = rInput.m_aRange;
132
1.05k
        m_aDocSize = rInput.m_aDocSize;
133
134
1.05k
        return *this;
135
1.05k
    }
136
137
    SCROW getStartRow() const
138
6.77k
    {
139
6.77k
        return m_aRange.aStart.Row();
140
6.77k
    }
141
142
    SCROW getEndRow() const
143
6.77k
    {
144
6.77k
        return m_aRange.aEnd.Row();
145
6.77k
    }
146
147
    SCCOL getStartColumn() const
148
3.45k
    {
149
3.45k
        return m_aRange.aStart.Col();
150
3.45k
    }
151
152
    SCCOL getEndColumn() const
153
4.50k
    {
154
4.50k
        return m_aRange.aEnd.Col();
155
4.50k
    }
156
157
    SCTAB getPrintTab() const
158
9.01k
    {
159
9.01k
        return m_aRange.aStart.Tab();
160
9.01k
    }
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
    // The ranges above were calculated for this input. Every copy shares both, so the input
178
    // always matches the result.
179
    std::shared_ptr<PrintPageRangesInput> m_pInput;
180
181
    void calculate(ScDocument& rDoc, PrintPageRangesInput const& rInput);
182
};
183
184
} // end sc namespace
185
186
// Used to save expensive-to-compute data from ScPrintFunc in between
187
// uses of ScPrintFunc
188
struct ScPrintState
189
{
190
    SCTAB   nPrintTab;
191
    SCCOL   nStartCol;
192
    SCROW   nStartRow;
193
    SCCOL   nEndCol;
194
    SCROW   nEndRow;
195
    bool    bPrintAreaValid; // the 4 variables above are set
196
    sal_uInt16  nZoom;
197
    tools::Long    nTabPages;
198
    tools::Long    nTotalPages;
199
    tools::Long    nPageStart;
200
    tools::Long    nDocPages;
201
202
    // Additional state of page ranges
203
    sc::PrintPageRanges m_aRanges;
204
205
    ScPrintState()
206
0
        : nPrintTab(0)
207
0
        , nStartCol(0)
208
0
        , nStartRow(0)
209
0
        , nEndCol(0)
210
0
        , nEndRow(0)
211
0
        , bPrintAreaValid(false)
212
0
        , nZoom(0)
213
0
        , nTabPages(0)
214
0
        , nTotalPages(0)
215
0
        , nPageStart(0)
216
0
        , nDocPages(0)
217
0
    {}
218
};
219
220
class ScPrintFunc
221
{
222
private:
223
    ScDocShell&         rDocShell;
224
    ScDocument&         rDoc;
225
    VclPtr<SfxPrinter>   pPrinter;
226
    VclPtr<OutputDevice> pDev;
227
    FmFormView*         pDrawView;
228
229
    MapMode             aOldPrinterMode;    //  MapMode before the call
230
231
    Point               aSrcOffset;         //  Paper-1/100 mm
232
    Point               aOffset;            //  scaled by a factor of page size
233
    sal_uInt16          nManualZoom;        //  Zoom in Preview (percent)
234
    bool                bClearWin;          //  Clear output before
235
    bool                bUseStyleColor;
236
    bool                bIsRender;
237
238
    SCTAB               nPrintTab;
239
    tools::Long                nPageStart;         //  Offset for the first page
240
    tools::Long                nDocPages;          //  Number of Pages in Document
241
242
    const ScRange*      pUserArea;          //  Selection, if set in dialog
243
244
    const SfxItemSet*   pParamSet;          //  Selected template
245
    bool                bFromPrintState;    // created from State-struct
246
247
                                            //  Parameter from template:
248
    sal_uInt16          nLeftMargin;
249
    sal_uInt16          nTopMargin;
250
    sal_uInt16          nRightMargin;
251
    sal_uInt16          nBottomMargin;
252
    bool                bCenterHor;
253
    bool                bCenterVer;
254
    bool                bLandscape;
255
    bool                bSourceRangeValid;
256
257
    SvxPageUsage        nPageUsage;
258
    Size                aPageSize;          // Printer Twips
259
    const SvxBoxItem*   pBorderItem;
260
    const SvxBrushItem* pBackgroundItem;
261
    const SvxShadowItem* pShadowItem;
262
263
    ScRange             aLastSourceRange;
264
    ScPrintHFParam      aHdr;
265
    ScPrintHFParam      aFtr;
266
    ScPageTableParam    aTableParam;
267
    ScPageAreaParam     aAreaParam;
268
269
                                            // Calculated values:
270
    sal_uInt16          nZoom;
271
    bool                bPrintCurrentTable;
272
    bool                bMultiArea;
273
    bool                mbHasPrintRange;
274
    tools::Long                nTabPages;
275
    tools::Long                nTotalPages;
276
277
    tools::Rectangle           aPageRect;          // Document Twips
278
279
    MapMode             aLogicMode;         // Set in DoPrint
280
    MapMode             aOffsetMode;
281
    MapMode             aTwipMode;
282
    double              nScaleX;
283
    double              nScaleY;
284
285
    SCCOL               nRepeatStartCol;
286
    SCCOL               nRepeatEndCol;
287
    SCROW               nRepeatStartRow;
288
    SCROW               nRepeatEndRow;
289
290
    SCCOL               nStartCol;
291
    SCROW               nStartRow;
292
    SCCOL               nEndCol;
293
    SCROW               nEndRow;
294
    bool                bPrintAreaValid; // the 4 variables above are set
295
296
    sc::PrintPageRanges m_aRanges;
297
298
    std::unique_ptr<ScHeaderEditEngine> pEditEngine;
299
    std::unique_ptr<SfxItemSet>         pEditDefaults;
300
301
    ScHeaderFieldData   aFieldData;
302
303
    std::vector<ScAddress> aNotePosList;        // The order of notes
304
305
    ScPageBreakData*    pPageData;          // for recording the breaks etc.
306
307
    Size                aPrintPageSize;         // print page size in Print dialog
308
    bool                bPrintPageLandscape;    // print page orientation in Print dialog
309
    bool                bUsePrintDialogSetting; // use Print dialog setting
310
311
public:
312
                    ScPrintFunc( ScDocShell& rShell, SfxPrinter* pNewPrinter, SCTAB nTab,
313
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
314
                                 const ScRange* pArea = nullptr,
315
                                 const ScPrintOptions* pOptions = nullptr,
316
                                 ScPageBreakData* pData = nullptr,
317
                                 Size aPrintPageSize = {},
318
                                 bool bPrintPageLandscape = false,
319
                                 bool bUsePrintDialogSetting = false );
320
321
                    ScPrintFunc( ScDocShell& rShell, SfxPrinter* pNewPrinter,
322
                                const ScPrintState& rState, const ScPrintOptions* pOptions,
323
                                Size aPrintPageSize = {},
324
                                bool bPrintPageLandscape = false,
325
                                bool bUsePrintDialogSetting = false );
326
327
                    // ctors for device other than printer - for preview and pdf:
328
329
                    ScPrintFunc( OutputDevice* pOutDev, ScDocShell& rShell, SCTAB nTab,
330
                                 tools::Long nPage = 0, tools::Long nDocP = 0,
331
                                 const ScRange* pArea = nullptr,
332
                                 const ScPrintOptions* pOptions = nullptr );
333
334
                    ScPrintFunc( OutputDevice* pOutDev, ScDocShell& rShell,
335
                                 const ScPrintState& rState,
336
                                 const ScPrintOptions* pOptions, Size aPrintPageSize = {},
337
                                 bool bPrintPageLandscape = false,
338
                                 bool bUsePrintDialogSetting = false);
339
340
                    ~ScPrintFunc();
341
342
    static void     DrawToDev( ScDocument& rDoc, OutputDevice* pDev, double nPrintFactor,
343
                               const tools::Rectangle& rBound, ScViewData& rViewData, bool bMetaFile );
344
345
    void            SetDrawView( FmFormView* pNew );
346
347
    void            SetOffset( const Point& rOfs );
348
    void            SetManualZoom( sal_uInt16 nNewZoom );
349
    void            SetDateTime( const DateTime& );
350
351
    void            SetClearFlag( bool bFlag );
352
    void            SetUseStyleColor( bool bFlag );
353
    void            SetRenderFlag( bool bFlag );
354
355
    void            SetExclusivelyDrawOleAndDrawObjects();//for printing selected objects without surrounding cell contents
356
357
    bool            UpdatePages();
358
359
    void            ApplyPrintSettings();       // Already called from DoPrint()
360
    tools::Long            DoPrint( const MultiSelection& rPageRanges,
361
                                tools::Long nStartPage, tools::Long nDisplayStart, bool bDoPrint,
362
                                ScPreviewLocationData* pLocationData );
363
364
                    // Query values - immediately
365
366
0
    const Size&     GetPageSize() const { return aPageSize; }
367
    Size            GetDataSize() const;
368
    void            GetScaleData( Size& rPhysSize, tools::Long& rDocHdr, tools::Long& rDocFtr );
369
0
    tools::Long            GetFirstPageNo() const  { return aTableParam.nFirstPageNo; }
370
371
0
    tools::Long            GetTotalPages() const { return nTotalPages; }
372
0
    sal_uInt16      GetZoom() const { return nZoom; }
373
374
    void            ResetBreaks( SCTAB nTab );
375
376
    void            GetPrintState(ScPrintState& rState);
377
    bool            GetLastSourceRange( ScRange& rRange ) const;
378
0
    sal_uInt16      GetLeftMargin() const{return nLeftMargin;}
379
0
    sal_uInt16      GetRightMargin() const{return nRightMargin;}
380
0
    sal_uInt16      GetTopMargin() const{return nTopMargin;}
381
0
    sal_uInt16      GetBottomMargin() const{return nBottomMargin;}
382
0
    const ScPrintHFParam& GetHeader() const {return aHdr;}
383
0
    const ScPrintHFParam& GetFooter() const {return aFtr;}
384
385
0
    bool HasPrintRange() const { return mbHasPrintRange;}
386
387
private:
388
    void            Construct( const ScPrintOptions* pOptions );
389
    void            InitParam( const ScPrintOptions* pOptions );
390
    void            CalcZoom( sal_uInt16 nRangeNo );
391
    void            CalcPages();
392
    tools::Long            CountPages();
393
    tools::Long            CountNotePages();
394
395
    bool            AdjustPrintArea( bool bNew );
396
397
    Size            GetDocPageSize();
398
399
    tools::Long            TextHeight( const EditTextObject* pObject );
400
    void            MakeEditEngine();
401
    void            UpdateHFHeight( ScPrintHFParam& rParam );
402
403
    void            InitModes();
404
405
    bool            IsLeft( tools::Long nPageNo );
406
    bool            IsMirror( tools::Long nPageNo );
407
    void            MakeTableString();                  // sets aTableStr
408
409
    void            PrintPage( tools::Long nPageNo,
410
                                    SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
411
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );
412
    void            PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
413
                                    tools::Long nScrX, tools::Long nScrY,
414
                                    bool bShLeft, bool bShTop, bool bShRight, bool bShBottom );
415
    void            LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
416
                                    tools::Long nScrX, tools::Long nScrY, bool bRepCol, bool bRepRow,
417
                                    ScPreviewLocationData& rLocationData );
418
    void            PrintColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY );
419
    void            PrintRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY );
420
    void            LocateColHdr( SCCOL nX1, SCCOL nX2, tools::Long nScrX, tools::Long nScrY,
421
                                bool bRepCol, ScPreviewLocationData& rLocationData );
422
    void            LocateRowHdr( SCROW nY1, SCROW nY2, tools::Long nScrX, tools::Long nScrY,
423
                                bool bRepRow, ScPreviewLocationData& rLocationData );
424
    void            PrintHF( tools::Long nPageNo, bool bHeader, tools::Long nStartY,
425
                                    bool bDoPrint, ScPreviewLocationData* pLocationData );
426
427
    tools::Long            PrintNotes( tools::Long nPageNo, tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
428
    tools::Long            DoNotes( tools::Long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
429
430
    void            DrawBorder( tools::Long nScrX, tools::Long nScrY, tools::Long nScrW, tools::Long nScrH,
431
                                    const SvxBoxItem* pBorderData,
432
                                    const SvxBrushItem* pBackground,
433
                                    const SvxShadowItem* pShadow );
434
435
    void            FillPageData();
436
};
437
438
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */