LibreOffice Module sw (master) 1
viewpg.cxx
Go to the documentation of this file.
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#include <config_wasm_strip.h>
21
22#include <tools/fract.hxx>
23#include <osl/diagnose.h>
24#include <viewsh.hxx>
25#include <pagefrm.hxx>
26#include <viewimp.hxx>
27#include <printdata.hxx>
28#include <ptqueue.hxx>
29#include <fntcache.hxx>
30
31#include <vprint.hxx>
32
33using namespace ::com::sun::star;
34
36{
37 return Imp()->PagePreviewLayout();
38}
39
40void SwViewShell::ShowPreviewSelection( sal_uInt16 nSelPage )
41{
42#if !ENABLE_WASM_STRIP_ACCESSIBILITY
44#else
45 (void)nSelPage;
46#endif
47}
48
49// adjust view options for page preview
51{
52 if ( !IsPreview() )
53 {
54 OSL_FAIL( "view shell doesn't belongs to a page preview - no adjustment of its view options");
55 return;
56 }
57
58 PrepareForPrint( rPrintOptions );
59}
60
62// consider empty pages on calculation of the scaling
63// for a page to be printed.
65 OutputDevice *pOutDev,
66 const SwPrintData &rPrintData,
67 sal_Int32 nRenderer // the index in the vector of prospect pages to be printed
68 )
69{
70 const sal_Int32 nMaxRenderer = rPrintData.GetRenderData().GetPagePairsForProspectPrinting().size() - 1;
71 OSL_ENSURE( 0 <= nRenderer && nRenderer <= nMaxRenderer, "nRenderer out of bounds");
72 Printer *pPrinter = dynamic_cast< Printer * >(pOutDev);
73 if (!pPrinter || nMaxRenderer < 0 || nRenderer < 0 || nRenderer > nMaxRenderer)
74 return;
75
76 // save settings of OutputDevice (should be done always since the
77 // output device is now provided by a call from outside the Writer)
78 pPrinter->Push();
79
80 std::pair< sal_Int32, sal_Int32 > rPagesToPrint =
81 rPrintData.GetRenderData().GetPagePairsForProspectPrinting()[ nRenderer ];
82 OSL_ENSURE( rPagesToPrint.first == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.first ) == 1, "first Page not valid" );
83 OSL_ENSURE( rPagesToPrint.second == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.second ) == 1, "second Page not valid" );
84
85 // create a new shell for the printer
86 SwViewShell aShell( *this, nullptr, pPrinter );
87
88 CurrShell aCurr( &aShell );
89
90 aShell.PrepareForPrint( rPrintData );
91
93
94 MapMode aMapMode( MapUnit::MapTwip );
95 Size aPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
96
97 SwTwips nMaxRowSz, nMaxColSz;
98
99 const SwPageFrame *pStPage = nullptr;
100 const SwPageFrame *pNxtPage = nullptr;
101 if (rPagesToPrint.first > 0)
102 {
103 pStPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.first);
104 }
105 if (rPagesToPrint.second > 0)
106 {
107 pNxtPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.second);
108 }
109
110 // i#14016 consider empty pages on calculation
111 // of page size, used for calculation of scaling.
112 Size aSttPageSize;
113 if ( pStPage )
114 {
115 if ( pStPage->IsEmptyPage() )
116 {
117 if ( pStPage->GetPhyPageNum() % 2 == 0 )
118 aSttPageSize = pStPage->GetPrev()->getFrameArea().SSize();
119 else
120 aSttPageSize = pStPage->GetNext()->getFrameArea().SSize();
121 }
122 else
123 {
124 aSttPageSize = pStPage->getFrameArea().SSize();
125 }
126 }
127 Size aNxtPageSize;
128 if ( pNxtPage )
129 {
130 if ( pNxtPage->IsEmptyPage() )
131 {
132 if ( pNxtPage->GetPhyPageNum() % 2 == 0 )
133 aNxtPageSize = pNxtPage->GetPrev()->getFrameArea().SSize();
134 else
135 aNxtPageSize = pNxtPage->GetNext()->getFrameArea().SSize();
136 }
137 else
138 {
139 aNxtPageSize = pNxtPage->getFrameArea().SSize();
140 }
141 }
142
143 if( !pStPage )
144 {
145 nMaxColSz = 2 * aNxtPageSize.Width();
146 nMaxRowSz = aNxtPageSize.Height();
147 }
148 else if( !pNxtPage )
149 {
150 nMaxColSz = 2 * aSttPageSize.Width();
151 nMaxRowSz = aSttPageSize.Height();
152 }
153 else
154 {
155 nMaxColSz = aNxtPageSize.Width() + aSttPageSize.Width();
156 nMaxRowSz = std::max( aNxtPageSize.Height(), aSttPageSize.Height() );
157 }
158
159 // set the MapMode
160 aMapMode.SetOrigin( Point() );
161 {
162 Fraction aScX( aPrtSize.Width(), nMaxColSz );
163 Fraction aScY( aPrtSize.Height(), nMaxRowSz );
164 if( aScX < aScY )
165 aScY = aScX;
166
167 {
168 // Round percentages for Drawings so that these can paint their objects properly
169 aScY *= Fraction( 1000, 1 );
170 tools::Long nTmp = static_cast<tools::Long>(aScY);
171 if( 1 < nTmp )
172 --nTmp;
173 else
174 nTmp = 1;
175 aScY = Fraction( nTmp, 1000 );
176 }
177
178 aMapMode.SetScaleY( aScY );
179 aMapMode.SetScaleX( aScY );
180 }
181
182 Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
183
184 // calculate start point for equal border on all sides
185 Point aSttPt( (aTmpPrtSize.Width() - nMaxColSz) / 2,
186 (aTmpPrtSize.Height() - nMaxRowSz) / 2 );
187 for( int nC = 0; nC < 2; ++nC )
188 {
189 if( pStPage )
190 {
191 aShell.Imp()->SetFirstVisPageInvalid();
192 aShell.maVisArea = pStPage->getFrameArea();
193
194 Point aPos( aSttPt );
195 aPos -= aShell.maVisArea.Pos();
196 aMapMode.SetOrigin( aPos );
197 pPrinter->SetMapMode( aMapMode );
198 pStPage->GetUpper()->PaintSwFrame( *pOutDev, pStPage->getFrameArea() );
199 }
200
201 pStPage = pNxtPage;
202 aSttPt.AdjustX(aTmpPrtSize.Width() / 2 );
203 }
204
206
208
209 pFntCache->Flush();
210
211 // restore settings of OutputDevice (should be done always now since the
212 // output device is now provided by a call from outside the Writer)
213 pPrinter->Pop();
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetOrigin(const Point &rOrigin)
void SetScaleY(const Fraction &rScaleY)
void SetScaleX(const Fraction &rScaleX)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
void SetMapMode()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
tools::Long AdjustX(tools::Long nHorzMove)
const Size & GetPaperSizePixel() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void Flush()
Definition: fntcache.cxx:76
const SwRect & getFrameArea() const
Definition: frame.hxx:179
SwFrame * GetNext()
Definition: frame.hxx:682
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
SwFrame * GetPrev()
Definition: frame.hxx:683
virtual void PaintSwFrame(vcl::RenderContext &rRenderContext, SwRect const &, SwPrintData const *const pPrintData=nullptr) const override
Definition: paintfrm.cxx:3511
A page of the document layout.
Definition: pagefrm.hxx:60
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:209
bool IsEmptyPage() const
Definition: pagefrm.hxx:161
page preview functionality in the writer
static void Repaint()
Definition: vprint.cxx:105
const SwRenderData & GetRenderData() const
Note: in the context where this class is used the pointers should always be valid during the lifetime...
Definition: printdata.hxx:128
void Pos(const Point &rNew)
Definition: swrect.hxx:171
void SSize(const Size &rNew)
Definition: swrect.hxx:180
PagePairsVec_t & GetPagePairsForProspectPrinting()
used for prospect printing only
Definition: printdata.hxx:280
o3tl::sorted_vector< sal_Int32 > & GetValidPagesSet()
Definition: printdata.hxx:265
void InvalidateAccessiblePreviewSelection(sal_uInt16 nSelPage)
Definition: viewimp.cxx:508
void SetFirstVisPageInvalid()
Definition: viewimp.hxx:149
SwPagePreviewLayout * PagePreviewLayout()
Definition: viewimp.hxx:222
bool IsPreview() const
Definition: viewsh.hxx:517
SwPagePreviewLayout * PagePreviewLayout()
Definition: viewpg.cxx:35
SwViewShellImp * Imp()
Definition: viewsh.hxx:211
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
void PrintProspect(OutputDevice *pOutDev, const SwPrintData &rPrintData, sal_Int32 nRenderer)
print brochure
Definition: viewpg.cxx:64
SwRect maVisArea
The modern version of VisArea.
Definition: viewsh.hxx:197
void AdjustOptionsForPagePreview(SwPrintData const &rPrintOptions)
adjust view options for page preview
Definition: viewpg.cxx:50
SAL_DLLPRIVATE void PrepareForPrint(const SwPrintData &rOptions, bool bIsPDFExport=false)
Definition: vprint.cxx:651
void ShowPreviewSelection(sal_uInt16 nSelPage)
Definition: viewpg.cxx:40
size_type count(const Value &v) const
SwFntCache * pFntCache
Definition: fntcache.cxx:66
long Long
tools::Long SwTwips
Definition: swtypes.hxx:51
SwPageFrame const * sw_getPage(SwRootFrame const &rLayout, sal_Int32 const nPage)
Definition: vprint.cxx:416