1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <pagefrm.hxx>
26 #include <viewimp.hxx>
27 #include <printdata.hxx>
28 #include <ptqueue.hxx>
29 #include <fntcache.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
);
49 // adjust view options for page preview
50 void SwViewShell::AdjustOptionsForPagePreview(SwPrintData
const& rPrintOptions
)
54 OSL_FAIL( "view shell doesn't belongs to a page preview - no adjustment of its view options");
58 PrepareForPrint( rPrintOptions
);
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
)
76 // save settings of OutputDevice (should be done always since the
77 // output device is now provided by a call from outside the Writer)
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.
115 if ( pStPage
->IsEmptyPage() )
117 if ( pStPage
->GetPhyPageNum() % 2 == 0 )
118 aSttPageSize
= pStPage
->GetPrev()->getFrameArea().SSize();
120 aSttPageSize
= pStPage
->GetNext()->getFrameArea().SSize();
124 aSttPageSize
= pStPage
->getFrameArea().SSize();
130 if ( pNxtPage
->IsEmptyPage() )
132 if ( pNxtPage
->GetPhyPageNum() % 2 == 0 )
133 aNxtPageSize
= pNxtPage
->GetPrev()->getFrameArea().SSize();
135 aNxtPageSize
= pNxtPage
->GetNext()->getFrameArea().SSize();
139 aNxtPageSize
= pNxtPage
->getFrameArea().SSize();
145 nMaxColSz
= 2 * aNxtPageSize
.Width();
146 nMaxRowSz
= aNxtPageSize
.Height();
150 nMaxColSz
= 2 * aSttPageSize
.Width();
151 nMaxRowSz
= aSttPageSize
.Height();
155 nMaxColSz
= aNxtPageSize
.Width() + aSttPageSize
.Width();
156 nMaxRowSz
= std::max( aNxtPageSize
.Height(), aSttPageSize
.Height() );
160 aMapMode
.SetOrigin( Point() );
162 Fraction
aScX( aPrtSize
.Width(), nMaxColSz
);
163 Fraction
aScY( aPrtSize
.Height(), nMaxRowSz
);
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
);
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
)
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() );
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!
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)
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */