Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / layout / virtoutp.cxx
blobdd044317dbd0dddb286f0ddc266422733c365448
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 "virtoutp.hxx"
21 #include <viewopt.hxx>
22 #include <rootfrm.hxx>
23 #include <osl/diagnose.h>
25 /* The SWLayVout class manages the virtual output devices.
26 * RootFrame has a static member of this class which is created in FrameInit
27 * and destroyed in FrameFinit.
28 * */
30 bool SwRootFrame::FlushVout()
32 if (SwRootFrame::s_pVout->IsFlushable())
34 SwRootFrame::s_pVout->Flush_();
35 return true;
37 return false;
40 bool SwRootFrame::HasSameRect( const SwRect& rRect )
42 if (SwRootFrame::s_pVout->IsFlushable())
43 return ( rRect == SwRootFrame::s_pVout->GetOrgRect() );
44 return false;
47 /** method to set mapping/pixel offset for virtual output device
49 OD 12.11.2002 #96272# - method implements two solutions for the mapping of
50 the virtual output device:
51 The old solution set the origin of the mapping mode, which will be used in
52 the virtual output device. This causes several paint errors, because of the
53 different roundings in the virtual output device and the original output device.
54 The new solution avoids the rounding differences between virtual and original
55 output device by setting a pixel offset at the virtual output device.
56 A define controls, which solution is used, in order to switch in escalation
57 back to old solution.
59 @param _pOrgOutDev
60 input parameter - constant instance of the original output device, for which
61 the virtual output device is created.
63 @param _pVirDev
64 input/output parameter - instance of the virtual output device.
66 @param _rNewOrigin
67 input parameter - constant instance of the origin, which will be used in
68 the virtual output device
70 // define to control, if old or new solution for setting the mapping for
71 // a virtual output device is used.
72 static void SetMappingForVirtDev( const Point& _rNewOrigin,
73 const vcl::RenderContext* _pOrgOutDev,
74 vcl::RenderContext* _pVirDev )
76 // new solution: set pixel offset at virtual output device
77 Point aPixelOffset = _pOrgOutDev->LogicToPixel( _rNewOrigin );
78 _pVirDev->SetPixelOffset( Size( -aPixelOffset.X(), -aPixelOffset.Y() ) );
81 // rSize must be pixel coordinates!
82 bool SwLayVout::DoesFit( const Size &rNew )
84 if( rNew.Height() > VIRTUALHEIGHT )
85 return false;
86 if( rNew.IsEmpty() )
87 return false;
88 if( rNew.Width() <= m_aSize.Width() )
89 return true;
90 if( !m_pVirDev )
92 m_pVirDev = VclPtr<VirtualDevice>::Create();
93 m_pVirDev->SetLineColor();
94 if( m_pOut )
96 if( m_pVirDev->GetFillColor() != m_pOut->GetFillColor() )
97 m_pVirDev->SetFillColor( m_pOut->GetFillColor() );
101 if( rNew.Width() > m_aSize.Width() )
103 m_aSize.setWidth( rNew.Width() );
104 if( !m_pVirDev->SetOutputSizePixel( m_aSize ) )
106 m_pVirDev.disposeAndClear();
107 m_aSize.setWidth( 0 );
108 return false;
111 return true;
114 /// change 2nd parameter <rRect> - no longer <const>
115 /// in order to return value of class member variable <aRect>, if virtual
116 /// output is used.
117 /// <aRect> contains the rectangle that represents the area the virtual
118 /// output device is used for and that is flushed at the end.
119 void SwLayVout::Enter( SwViewShell *pShell, SwRect &rRect, bool bOn )
121 Flush();
123 #ifdef DBG_UTIL
124 if( pShell->GetViewOptions()->IsTest3() )
126 ++m_nCount;
127 return;
129 #endif
131 bOn = bOn && !m_nCount && rRect.HasArea() && pShell->GetWin();
132 ++m_nCount;
133 if( !bOn )
134 return;
136 m_pShell = pShell;
137 m_pOut = nullptr;
138 OutputDevice *pO = m_pShell->GetOut();
139 // We don't cheat on printers or virtual output devices...
140 if( OUTDEV_WINDOW != pO->GetOutDevType() )
141 return;
143 m_pOut = pO;
144 Size aPixSz( m_pOut->PixelToLogic( Size( 1,1 )) );
145 SwRect aTmp( rRect );
146 aTmp.AddWidth(aPixSz.Width()/2 + 1 );
147 aTmp.AddHeight(aPixSz.Height()/2 + 1 );
148 tools::Rectangle aTmpRect( pO->LogicToPixel( aTmp.SVRect() ) );
150 OSL_ENSURE( !m_pShell->GetWin()->IsReallyVisible() ||
151 aTmpRect.GetWidth() <= m_pShell->GetWin()->GetOutputSizePixel().Width() + 2,
152 "Paintwidth bigger than visarea?" );
153 // Does the rectangle fit in our buffer?
154 if( !DoesFit( aTmpRect.GetSize() ) )
156 m_pOut = nullptr;
157 return;
160 m_aRect = SwRect( pO->PixelToLogic( aTmpRect ) );
162 SetOutDev( m_pShell, m_pVirDev );
164 if( m_pVirDev->GetFillColor() != m_pOut->GetFillColor() )
165 m_pVirDev->SetFillColor( m_pOut->GetFillColor() );
167 MapMode aMapMode( m_pOut->GetMapMode() );
168 // use method to set mapping
169 //aMapMode.SetOrigin( Point(0,0) - aRect.Pos() );
170 ::SetMappingForVirtDev( m_aRect.Pos(), m_pOut, m_pVirDev );
172 if( aMapMode != m_pVirDev->GetMapMode() )
173 m_pVirDev->SetMapMode( aMapMode );
175 // set value of parameter <rRect>
176 rRect = m_aRect;
180 void SwLayVout::Flush_()
182 OSL_ENSURE( m_pVirDev, "SwLayVout::DrawOut: nothing left Toulouse" );
183 m_pOut->DrawOutDev( m_aRect.Pos(), m_aRect.SSize(),
184 m_aRect.Pos(), m_aRect.SSize(), *m_pVirDev );
185 SetOutDev( m_pShell, m_pOut );
186 m_pOut = nullptr;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */