nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / view / viewpg.cxx
blob98df167150596c4f63470143e27e213552de6e9f
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 <tools/fract.hxx>
21 #include <viewsh.hxx>
22 #include <pagefrm.hxx>
23 #include <viewimp.hxx>
24 #include <printdata.hxx>
25 #include <ptqueue.hxx>
26 #include <fntcache.hxx>
28 #include "vprint.hxx"
30 using namespace ::com::sun::star;
32 SwPagePreviewLayout* SwViewShell::PagePreviewLayout()
34 return Imp()->PagePreviewLayout();
37 void SwViewShell::ShowPreviewSelection( sal_uInt16 nSelPage )
39 Imp()->InvalidateAccessiblePreviewSelection( nSelPage );
42 // adjust view options for page preview
43 void SwViewShell::AdjustOptionsForPagePreview(SwPrintData const& rPrintOptions)
45 if ( !IsPreview() )
47 OSL_FAIL( "view shell doesn't belongs to a page preview - no adjustment of its view options");
48 return;
51 PrepareForPrint( rPrintOptions );
54 /// print brochure
55 // consider empty pages on calculation of the scaling
56 // for a page to be printed.
57 void SwViewShell::PrintProspect(
58 OutputDevice *pOutDev,
59 const SwPrintData &rPrintData,
60 sal_Int32 nRenderer // the index in the vector of prospect pages to be printed
63 const sal_Int32 nMaxRenderer = rPrintData.GetRenderData().GetPagePairsForProspectPrinting().size() - 1;
64 OSL_ENSURE( 0 <= nRenderer && nRenderer <= nMaxRenderer, "nRenderer out of bounds");
65 Printer *pPrinter = dynamic_cast< Printer * >(pOutDev);
66 if (!pPrinter || nMaxRenderer < 0 || nRenderer < 0 || nRenderer > nMaxRenderer)
67 return;
69 // save settings of OutputDevice (should be done always since the
70 // output device is now provided by a call from outside the Writer)
71 pPrinter->Push();
73 std::pair< sal_Int32, sal_Int32 > rPagesToPrint =
74 rPrintData.GetRenderData().GetPagePairsForProspectPrinting()[ nRenderer ];
75 OSL_ENSURE( rPagesToPrint.first == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.first ) == 1, "first Page not valid" );
76 OSL_ENSURE( rPagesToPrint.second == -1 || rPrintData.GetRenderData().GetValidPagesSet().count( rPagesToPrint.second ) == 1, "second Page not valid" );
78 // create a new shell for the printer
79 SwViewShell aShell( *this, nullptr, pPrinter );
81 CurrShell aCurr( &aShell );
83 aShell.PrepareForPrint( rPrintData );
85 //!! applying view options and formatting the document should now only be done in getRendererCount!
87 MapMode aMapMode( MapUnit::MapTwip );
88 Size aPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
90 SwTwips nMaxRowSz, nMaxColSz;
92 const SwPageFrame *pStPage = nullptr;
93 const SwPageFrame *pNxtPage = nullptr;
94 if (rPagesToPrint.first > 0)
96 pStPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.first);
98 if (rPagesToPrint.second > 0)
100 pNxtPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.second);
103 // i#14016 consider empty pages on calculation
104 // of page size, used for calculation of scaling.
105 Size aSttPageSize;
106 if ( pStPage )
108 if ( pStPage->IsEmptyPage() )
110 if ( pStPage->GetPhyPageNum() % 2 == 0 )
111 aSttPageSize = pStPage->GetPrev()->getFrameArea().SSize();
112 else
113 aSttPageSize = pStPage->GetNext()->getFrameArea().SSize();
115 else
117 aSttPageSize = pStPage->getFrameArea().SSize();
120 Size aNxtPageSize;
121 if ( pNxtPage )
123 if ( pNxtPage->IsEmptyPage() )
125 if ( pNxtPage->GetPhyPageNum() % 2 == 0 )
126 aNxtPageSize = pNxtPage->GetPrev()->getFrameArea().SSize();
127 else
128 aNxtPageSize = pNxtPage->GetNext()->getFrameArea().SSize();
130 else
132 aNxtPageSize = pNxtPage->getFrameArea().SSize();
136 if( !pStPage )
138 nMaxColSz = 2 * aNxtPageSize.Width();
139 nMaxRowSz = aNxtPageSize.Height();
141 else if( !pNxtPage )
143 nMaxColSz = 2 * aSttPageSize.Width();
144 nMaxRowSz = aSttPageSize.Height();
146 else
148 nMaxColSz = aNxtPageSize.Width() + aSttPageSize.Width();
149 nMaxRowSz = std::max( aNxtPageSize.Height(), aSttPageSize.Height() );
152 // set the MapMode
153 aMapMode.SetOrigin( Point() );
155 Fraction aScX( aPrtSize.Width(), nMaxColSz );
156 Fraction aScY( aPrtSize.Height(), nMaxRowSz );
157 if( aScX < aScY )
158 aScY = aScX;
161 // Round percentages for Drawings so that these can paint their objects properly
162 aScY *= Fraction( 1000, 1 );
163 tools::Long nTmp = static_cast<tools::Long>(aScY);
164 if( 1 < nTmp )
165 --nTmp;
166 else
167 nTmp = 1;
168 aScY = Fraction( nTmp, 1000 );
171 aMapMode.SetScaleY( aScY );
172 aMapMode.SetScaleX( aScY );
175 Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
177 // calculate start point for equal border on all sides
178 Point aSttPt( (aTmpPrtSize.Width() - nMaxColSz) / 2,
179 (aTmpPrtSize.Height() - nMaxRowSz) / 2 );
180 for( int nC = 0; nC < 2; ++nC )
182 if( pStPage )
184 aShell.Imp()->SetFirstVisPageInvalid();
185 aShell.maVisArea = pStPage->getFrameArea();
187 Point aPos( aSttPt );
188 aPos -= aShell.maVisArea.Pos();
189 aMapMode.SetOrigin( aPos );
190 pPrinter->SetMapMode( aMapMode );
191 pStPage->GetUpper()->PaintSwFrame( *pOutDev, pStPage->getFrameArea() );
194 pStPage = pNxtPage;
195 aSttPt.AdjustX(aTmpPrtSize.Width() / 2 );
198 SwPaintQueue::Repaint();
200 //!! applying/modifying view options and formatting the document should now only be done in getRendererCount!
202 pFntCache->Flush();
204 // restore settings of OutputDevice (should be done always now since the
205 // output device is now provided by a call from outside the Writer)
206 pPrinter->Pop();
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */