Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / view / viewpg.cxx
blob02ebd1a69e12d3a53f81a99a06a78742d9e29643
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_wasm_strip.h>
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>
31 #include <vprint.hxx>
33 using namespace ::com::sun::star;
35 SwPagePreviewLayout* SwViewShell::PagePreviewLayout()
37 return Imp()->PagePreviewLayout();
40 void SwViewShell::ShowPreviewSelection( sal_uInt16 nSelPage )
42 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
43 Imp()->InvalidateAccessiblePreviewSelection( nSelPage );
44 #else
45 (void)nSelPage;
46 #endif
49 // adjust view options for page preview
50 void SwViewShell::AdjustOptionsForPagePreview(SwPrintData const& rPrintOptions)
52 if ( !IsPreview() )
54 OSL_FAIL( "view shell doesn't belongs to a page preview - no adjustment of its view options");
55 return;
58 PrepareForPrint( rPrintOptions );
61 /// print brochure
62 // consider empty pages on calculation of the scaling
63 // for a page to be printed.
64 void SwViewShell::PrintProspect(
65 OutputDevice *pOutDev,
66 const SwPrintData &rPrintData,
67 sal_Int32 nRenderer // the index in the vector of prospect pages to be printed
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;
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();
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" );
85 // create a new shell for the printer
86 SwViewShell aShell( *this, nullptr, pPrinter );
88 CurrShell aCurr( &aShell );
90 aShell.PrepareForPrint( rPrintData );
92 //!! applying view options and formatting the document should now only be done in getRendererCount!
94 MapMode aMapMode( MapUnit::MapTwip );
95 Size aPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
97 SwTwips nMaxRowSz, nMaxColSz;
99 const SwPageFrame *pStPage = nullptr;
100 const SwPageFrame *pNxtPage = nullptr;
101 if (rPagesToPrint.first > 0)
103 pStPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.first);
105 if (rPagesToPrint.second > 0)
107 pNxtPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.second);
110 // i#14016 consider empty pages on calculation
111 // of page size, used for calculation of scaling.
112 Size aSttPageSize;
113 if ( pStPage )
115 if ( pStPage->IsEmptyPage() )
117 if ( pStPage->GetPhyPageNum() % 2 == 0 )
118 aSttPageSize = pStPage->GetPrev()->getFrameArea().SSize();
119 else
120 aSttPageSize = pStPage->GetNext()->getFrameArea().SSize();
122 else
124 aSttPageSize = pStPage->getFrameArea().SSize();
127 Size aNxtPageSize;
128 if ( pNxtPage )
130 if ( pNxtPage->IsEmptyPage() )
132 if ( pNxtPage->GetPhyPageNum() % 2 == 0 )
133 aNxtPageSize = pNxtPage->GetPrev()->getFrameArea().SSize();
134 else
135 aNxtPageSize = pNxtPage->GetNext()->getFrameArea().SSize();
137 else
139 aNxtPageSize = pNxtPage->getFrameArea().SSize();
143 if( !pStPage )
145 nMaxColSz = 2 * aNxtPageSize.Width();
146 nMaxRowSz = aNxtPageSize.Height();
148 else if( !pNxtPage )
150 nMaxColSz = 2 * aSttPageSize.Width();
151 nMaxRowSz = aSttPageSize.Height();
153 else
155 nMaxColSz = aNxtPageSize.Width() + aSttPageSize.Width();
156 nMaxRowSz = std::max( aNxtPageSize.Height(), aSttPageSize.Height() );
159 // set the MapMode
160 aMapMode.SetOrigin( Point() );
162 Fraction aScX( aPrtSize.Width(), nMaxColSz );
163 Fraction aScY( aPrtSize.Height(), nMaxRowSz );
164 if( aScX < aScY )
165 aScY = aScX;
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 );
178 aMapMode.SetScaleY( aScY );
179 aMapMode.SetScaleX( aScY );
182 Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
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 )
189 if( pStPage )
191 aShell.Imp()->SetFirstVisPageInvalid();
192 aShell.maVisArea = pStPage->getFrameArea();
194 Point aPos( aSttPt );
195 aPos -= aShell.maVisArea.Pos();
196 aMapMode.SetOrigin( aPos );
197 pPrinter->SetMapMode( aMapMode );
198 pStPage->GetUpper()->PaintSwFrame( *pOutDev, pStPage->getFrameArea() );
201 pStPage = pNxtPage;
202 aSttPt.AdjustX(aTmpPrtSize.Width() / 2 );
205 SwPaintQueue::Repaint();
207 //!! applying/modifying view options and formatting the document should now only be done in getRendererCount!
209 pFntCache->Flush();
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();
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */