1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: virdev.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
37 #include <vcl/salinst.hxx>
38 #include <vcl/salgdi.hxx>
39 #include <vcl/salframe.hxx>
40 #include <vcl/salvd.hxx>
41 #include <tools/debug.hxx>
42 #include <vcl/svdata.hxx>
43 #include <vcl/settings.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/wrkwin.hxx>
46 #include <vcl/outdev.h>
47 #include <vcl/virdev.hxx>
49 using namespace ::com::sun::star::uno
;
51 // =======================================================================
53 void VirtualDevice::ImplInitVirDev( const OutputDevice
* pOutDev
,
54 long nDX
, long nDY
, USHORT nBitCount
, const SystemGraphicsData
*pData
)
56 DBG_ASSERT( nBitCount
<= 1,
57 "VirtualDevice::VirtualDevice(): Only 0 or 1 is for BitCount allowed" );
65 ImplSVData
* pSVData
= ImplGetSVData();
68 pOutDev
= ImplGetDefaultWindow();
72 SalGraphics
* pGraphics
;
73 if ( !pOutDev
->mpGraphics
)
74 ((OutputDevice
*)pOutDev
)->ImplGetGraphics();
75 pGraphics
= pOutDev
->mpGraphics
;
77 mpVirDev
= pSVData
->mpDefInst
->CreateVirtualDevice( pGraphics
, nDX
, nDY
, nBitCount
, pData
);
82 // do not abort but throw an exception, may be the current thread terminates anyway (plugin-scenario)
83 throw ::com::sun::star::uno::RuntimeException(
84 OUString( RTL_CONSTASCII_USTRINGPARAM( "Could not create system bitmap!" ) ),
85 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>() );
86 //GetpApp()->Exception( EXC_SYSOBJNOTCREATED );
89 mnBitCount
= ( nBitCount
? nBitCount
: pOutDev
->GetBitCount() );
95 // #i59315# init vdev size from system object, when passed a
96 // SystemGraphicsData. Otherwise, output size will always
97 // incorrectly stay at (1,1)
98 if( pData
&& mpVirDev
)
99 mpVirDev
->GetSize(mnOutWidth
,mnOutHeight
);
102 SetAntialiasing( ANTIALIASING_DISABLE_TEXT
);
104 if ( pOutDev
->GetOutDevType() == OUTDEV_PRINTER
)
105 mbScreenComp
= FALSE
;
106 else if ( pOutDev
->GetOutDevType() == OUTDEV_VIRDEV
)
107 mbScreenComp
= ((VirtualDevice
*)pOutDev
)->mbScreenComp
;
109 meOutDevType
= OUTDEV_VIRDEV
;
111 mpFontList
= pSVData
->maGDIData
.mpScreenFontList
;
112 mpFontCache
= pSVData
->maGDIData
.mpScreenFontCache
;
113 mnDPIX
= pOutDev
->mnDPIX
;
114 mnDPIY
= pOutDev
->mnDPIY
;
115 maFont
= pOutDev
->maFont
;
117 if( maTextColor
!= pOutDev
->maTextColor
)
119 maTextColor
= pOutDev
->maTextColor
;
120 mbInitTextColor
= true;
123 // Virtuelle Devices haben defaultmaessig einen weissen Hintergrund
124 SetBackground( Wallpaper( Color( COL_WHITE
) ) );
126 // #i59283# don't erase user-provided surface
130 // VirDev in Liste eintragen
131 mpNext
= pSVData
->maGDIData
.mpFirstVirDev
;
134 mpNext
->mpPrev
= this;
136 pSVData
->maGDIData
.mpLastVirDev
= this;
137 pSVData
->maGDIData
.mpFirstVirDev
= this;
140 // -----------------------------------------------------------------------
142 VirtualDevice::VirtualDevice( USHORT nBitCount
)
144 meRefDevMode( REFDEV_NONE
)
146 DBG_TRACE1( "VirtualDevice::VirtualDevice( %hu )", nBitCount
);
148 ImplInitVirDev( Application::GetDefaultDevice(), 1, 1, nBitCount
);
151 // -----------------------------------------------------------------------
153 VirtualDevice::VirtualDevice( const OutputDevice
& rCompDev
, USHORT nBitCount
)
155 meRefDevMode( REFDEV_NONE
)
157 DBG_TRACE1( "VirtualDevice::VirtualDevice( %hu )", nBitCount
);
159 ImplInitVirDev( &rCompDev
, 1, 1, nBitCount
);
162 // -----------------------------------------------------------------------
164 VirtualDevice::VirtualDevice( const OutputDevice
& rCompDev
, USHORT nBitCount
, USHORT nAlphaBitCount
)
166 meRefDevMode( REFDEV_NONE
)
168 DBG_TRACE1( "VirtualDevice::VirtualDevice( %hu )", nBitCount
);
170 ImplInitVirDev( &rCompDev
, 1, 1, nBitCount
);
172 // #110958# Enable alpha channel
173 mnAlphaDepth
= sal::static_int_cast
<sal_Int8
>(nAlphaBitCount
);
176 // -----------------------------------------------------------------------
178 VirtualDevice::VirtualDevice( const SystemGraphicsData
*pData
, USHORT nBitCount
)
180 meRefDevMode( REFDEV_NONE
)
182 DBG_TRACE1( "VirtualDevice::VirtualDevice( %hu )", nBitCount
);
184 ImplInitVirDev( Application::GetDefaultDevice(), 1, 1, nBitCount
, pData
);
187 // -----------------------------------------------------------------------
189 VirtualDevice::~VirtualDevice()
191 DBG_TRACE( "VirtualDevice::~VirtualDevice()" );
193 ImplSVData
* pSVData
= ImplGetSVData();
195 ImplReleaseGraphics();
198 pSVData
->mpDefInst
->DestroyVirtualDevice( mpVirDev
);
200 // remove this VirtualDevice from the double-linked global list
202 mpPrev
->mpNext
= mpNext
;
204 pSVData
->maGDIData
.mpFirstVirDev
= mpNext
;
207 mpNext
->mpPrev
= mpPrev
;
209 pSVData
->maGDIData
.mpLastVirDev
= mpPrev
;
212 // -----------------------------------------------------------------------
214 BOOL
VirtualDevice::ImplSetOutputSizePixel( const Size
& rNewSize
, BOOL bErase
)
216 DBG_TRACE3( "VirtualDevice::ImplSetOutputSizePixel( %ld, %ld, %d )", rNewSize
.Width(), rNewSize
.Height(), (int)bErase
);
220 else if ( rNewSize
== GetOutputSizePixel() )
228 long nNewWidth
= rNewSize
.Width(), nNewHeight
= rNewSize
.Height();
233 if ( nNewHeight
< 1 )
238 bRet
= mpVirDev
->SetSize( nNewWidth
, nNewHeight
);
242 mnOutWidth
= rNewSize
.Width();
243 mnOutHeight
= rNewSize
.Height();
249 SalVirtualDevice
* pNewVirDev
;
250 ImplSVData
* pSVData
= ImplGetSVData();
252 // we need a graphics
255 if ( !ImplGetGraphics() )
259 pNewVirDev
= pSVData
->mpDefInst
->CreateVirtualDevice( mpGraphics
, nNewWidth
, nNewHeight
, mnBitCount
);
262 SalGraphics
* pGraphics
= pNewVirDev
->GetGraphics();
268 if ( mnOutWidth
< nNewWidth
)
272 if ( mnOutHeight
< nNewHeight
)
273 nHeight
= mnOutHeight
;
275 nHeight
= nNewHeight
;
278 aPosAry
.mnSrcWidth
= nWidth
;
279 aPosAry
.mnSrcHeight
= nHeight
;
282 aPosAry
.mnDestWidth
= nWidth
;
283 aPosAry
.mnDestHeight
= nHeight
;
285 pGraphics
->CopyBits( &aPosAry
, mpGraphics
, this, this );
286 pNewVirDev
->ReleaseGraphics( pGraphics
);
287 ImplReleaseGraphics();
288 pSVData
->mpDefInst
->DestroyVirtualDevice( mpVirDev
);
289 mpVirDev
= pNewVirDev
;
290 mnOutWidth
= rNewSize
.Width();
291 mnOutHeight
= rNewSize
.Height();
297 pSVData
->mpDefInst
->DestroyVirtualDevice( pNewVirDev
);
307 // -----------------------------------------------------------------------
309 // #i32109#: Fill opaque areas correctly (without relying on
310 // fill/linecolor state)
311 void VirtualDevice::ImplFillOpaqueRectangle( const Rectangle
& rRect
)
313 // Set line and fill color to black (->opaque),
314 // fill rect with that (linecolor, too, because of
315 // those pesky missing pixel problems)
316 Push( PUSH_LINECOLOR
| PUSH_FILLCOLOR
);
317 SetLineColor( COL_BLACK
);
318 SetFillColor( COL_BLACK
);
323 // -----------------------------------------------------------------------
325 BOOL
VirtualDevice::SetOutputSizePixel( const Size
& rNewSize
, BOOL bErase
)
327 if( ImplSetOutputSizePixel(rNewSize
, bErase
) )
329 if( mnAlphaDepth
!= -1 )
331 // #110958# Setup alpha bitmap
332 if(mpAlphaVDev
&& mpAlphaVDev
->GetOutputSizePixel() != rNewSize
)
340 mpAlphaVDev
= new VirtualDevice( *this, mnAlphaDepth
);
341 mpAlphaVDev
->ImplSetOutputSizePixel(rNewSize
, bErase
);
344 // TODO: copy full outdev state to new one, here. Also needed in outdev2.cxx:DrawOutDev
345 if( GetLineColor() != Color( COL_TRANSPARENT
) )
346 mpAlphaVDev
->SetLineColor( COL_BLACK
);
348 if( GetFillColor() != Color( COL_TRANSPARENT
) )
349 mpAlphaVDev
->SetFillColor( COL_BLACK
);
351 mpAlphaVDev
->SetMapMode( GetMapMode() );
360 // -----------------------------------------------------------------------
362 void VirtualDevice::SetReferenceDevice( RefDevMode eRefDevMode
)
364 switch( eRefDevMode
)
368 DBG_ASSERT( FALSE
, "VDev::SetRefDev illegal argument!" );
371 mnDPIX
= mnDPIY
= 600;
374 mnDPIX
= mnDPIY
= 4800;
376 case REFDEV_MODE_MSO1
:
377 mnDPIX
= mnDPIY
= 6*1440;
379 case REFDEV_MODE_PDF1
:
380 mnDPIX
= mnDPIY
= 720;
384 EnableOutput( FALSE
); // prevent output on reference device
385 mbScreenComp
= FALSE
;
387 // invalidate currently selected fonts
391 // avoid adjusting font lists when already in refdev mode
392 BYTE nOldRefDevMode
= meRefDevMode
;
393 BYTE nOldCompatFlag
= (BYTE
)meRefDevMode
& REFDEV_FORCE_ZERO_EXTLEAD
;
394 meRefDevMode
= (BYTE
)(eRefDevMode
| nOldCompatFlag
);
395 if( (nOldRefDevMode
^ nOldCompatFlag
) != REFDEV_NONE
)
398 // the reference device should have only scalable fonts
399 // => clean up the original font lists before getting new ones
402 mpFontCache
->Release( mpFontEntry
);
405 if ( mpGetDevFontList
)
407 delete mpGetDevFontList
;
408 mpGetDevFontList
= NULL
;
410 if ( mpGetDevSizeList
)
412 delete mpGetDevSizeList
;
413 mpGetDevSizeList
= NULL
;
416 // preserve global font lists
417 ImplSVData
* pSVData
= ImplGetSVData();
418 if( mpFontList
&& (mpFontList
!= pSVData
->maGDIData
.mpScreenFontList
) )
420 if( mpFontCache
&& (mpFontCache
!= pSVData
->maGDIData
.mpScreenFontCache
) )
423 // get font list with scalable fonts only
425 mpFontList
= pSVData
->maGDIData
.mpScreenFontList
->Clone( true, false );
427 // prepare to use new font lists
428 mpFontCache
= new ImplFontCache( false );
431 // -----------------------------------------------------------------------
433 void VirtualDevice::Compat_ZeroExtleadBug()
435 meRefDevMode
= (BYTE
)meRefDevMode
| REFDEV_FORCE_ZERO_EXTLEAD
;
438 // -----------------------------------------------------------------------