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 <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>
27 
28 #include "vprint.hxx"
29 
30 using namespace ::com::sun::star;
31 
33 {
34  return Imp()->PagePreviewLayout();
35 }
36 
37 void SwViewShell::ShowPreviewSelection( sal_uInt16 nSelPage )
38 {
40 }
41 
42 // adjust view options for page preview
44 {
45  if ( !IsPreview() )
46  {
47  OSL_FAIL( "view shell doesn't belongs to a page preview - no adjustment of its view options");
48  return;
49  }
50 
51  PrepareForPrint( rPrintOptions );
52 }
53 
55 // consider empty pages on calculation of the scaling
56 // for a page to be printed.
58  OutputDevice *pOutDev,
59  const SwPrintData &rPrintData,
60  sal_Int32 nRenderer // the index in the vector of prospect pages to be printed
61  )
62 {
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;
68 
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();
72 
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" );
77 
78  // create a new shell for the printer
79  SwViewShell aShell( *this, nullptr, pPrinter );
80 
81  CurrShell aCurr( &aShell );
82 
83  aShell.PrepareForPrint( rPrintData );
84 
86 
87  MapMode aMapMode( MapUnit::MapTwip );
88  Size aPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
89 
90  SwTwips nMaxRowSz, nMaxColSz;
91 
92  const SwPageFrame *pStPage = nullptr;
93  const SwPageFrame *pNxtPage = nullptr;
94  if (rPagesToPrint.first > 0)
95  {
96  pStPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.first);
97  }
98  if (rPagesToPrint.second > 0)
99  {
100  pNxtPage = sw_getPage(*aShell.GetLayout(), rPagesToPrint.second);
101  }
102 
103  // i#14016 consider empty pages on calculation
104  // of page size, used for calculation of scaling.
105  Size aSttPageSize;
106  if ( pStPage )
107  {
108  if ( pStPage->IsEmptyPage() )
109  {
110  if ( pStPage->GetPhyPageNum() % 2 == 0 )
111  aSttPageSize = pStPage->GetPrev()->getFrameArea().SSize();
112  else
113  aSttPageSize = pStPage->GetNext()->getFrameArea().SSize();
114  }
115  else
116  {
117  aSttPageSize = pStPage->getFrameArea().SSize();
118  }
119  }
120  Size aNxtPageSize;
121  if ( pNxtPage )
122  {
123  if ( pNxtPage->IsEmptyPage() )
124  {
125  if ( pNxtPage->GetPhyPageNum() % 2 == 0 )
126  aNxtPageSize = pNxtPage->GetPrev()->getFrameArea().SSize();
127  else
128  aNxtPageSize = pNxtPage->GetNext()->getFrameArea().SSize();
129  }
130  else
131  {
132  aNxtPageSize = pNxtPage->getFrameArea().SSize();
133  }
134  }
135 
136  if( !pStPage )
137  {
138  nMaxColSz = 2 * aNxtPageSize.Width();
139  nMaxRowSz = aNxtPageSize.Height();
140  }
141  else if( !pNxtPage )
142  {
143  nMaxColSz = 2 * aSttPageSize.Width();
144  nMaxRowSz = aSttPageSize.Height();
145  }
146  else
147  {
148  nMaxColSz = aNxtPageSize.Width() + aSttPageSize.Width();
149  nMaxRowSz = std::max( aNxtPageSize.Height(), aSttPageSize.Height() );
150  }
151 
152  // set the MapMode
153  aMapMode.SetOrigin( Point() );
154  {
155  Fraction aScX( aPrtSize.Width(), nMaxColSz );
156  Fraction aScY( aPrtSize.Height(), nMaxRowSz );
157  if( aScX < aScY )
158  aScY = aScX;
159 
160  {
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 );
169  }
170 
171  aMapMode.SetScaleY( aScY );
172  aMapMode.SetScaleX( aScY );
173  }
174 
175  Size aTmpPrtSize( pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), aMapMode ) );
176 
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 )
181  {
182  if( pStPage )
183  {
184  aShell.Imp()->SetFirstVisPageInvalid();
185  aShell.maVisArea = pStPage->getFrameArea();
186 
187  Point aPos( aSttPt );
188  aPos -= aShell.maVisArea.Pos();
189  aMapMode.SetOrigin( aPos );
190  pPrinter->SetMapMode( aMapMode );
191  pStPage->GetUpper()->PaintSwFrame( *pOutDev, pStPage->getFrameArea() );
192  }
193 
194  pStPage = pNxtPage;
195  aSttPt.AdjustX(aTmpPrtSize.Width() / 2 );
196  }
197 
199 
201 
202  pFntCache->Flush();
203 
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();
207 }
208 
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:663
void ShowPreviewSelection(sal_uInt16 nSelPage)
Definition: viewpg.cxx:37
SwViewShellImp * Imp()
Definition: viewsh.hxx:182
size_type count(const Value &v) const
void AdjustOptionsForPagePreview(SwPrintData const &rPrintOptions)
adjust view options for page preview
Definition: viewpg.cxx:43
long Long
void SetMapMode()
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:191
virtual void PaintSwFrame(vcl::RenderContext &rRenderContext, SwRect const &, SwPrintData const *const pPrintData=nullptr) const override
Definition: paintfrm.cxx:3365
const SwRect & getFrameArea() const
Definition: frame.hxx:178
bool IsEmptyPage() const
Definition: pagefrm.hxx:144
void Flush()
Definition: fntcache.cxx:161
const Size & GetPaperSizePixel() const
SwPagePreviewLayout * PagePreviewLayout()
Definition: viewpg.cxx:32
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:57
void SetScaleX(const Fraction &rScaleX)
page preview functionality in the writer
static void Repaint()
Definition: vprint.cxx:103
bool IsPreview() const
Definition: viewsh.hxx:488
void SetOrigin(const Point &rOrigin)
SwLayoutFrame * GetUpper()
Definition: frame.hxx:661
tools::Long Width() const
SwPagePreviewLayout * PagePreviewLayout()
Definition: viewimp.hxx:212
SwPageFrame const * sw_getPage(SwRootFrame const &rLayout, sal_Int32 const nPage)
Definition: vprint.cxx:410
o3tl::sorted_vector< sal_Int32 > & GetValidPagesSet()
Definition: printdata.hxx:265
void SetScaleY(const Fraction &rScaleY)
SwFrame * GetPrev()
Definition: frame.hxx:660
void SSize(const Size &rNew)
Definition: swrect.hxx:178
SwFntCache * pFntCache
Definition: fntcache.cxx:64
A page of the document layout.
Definition: pagefrm.hxx:41
tools::Long SwTwips
Definition: swtypes.hxx:49
Point PixelToLogic(const Point &rDevicePt) const
tools::Long Height() const
void Push(PushFlags nFlags=PushFlags::ALL)
void InvalidateAccessiblePreviewSelection(sal_uInt16 nSelPage)
Definition: viewimp.cxx:438
SwFrame * GetNext()
Definition: frame.hxx:659