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