xref: /aoo41x/main/vcl/unx/headless/svpvd.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "svpvd.hxx"
29 #include "svpgdi.hxx"
30 
31 #include <basegfx/vector/b2ivector.hxx>
32 #include <basebmp/scanlineformats.hxx>
33 
34 #include "stdio.h"
35 
36 using namespace basegfx;
37 using namespace basebmp;
38 
39 SvpSalVirtualDevice::~SvpSalVirtualDevice()
40 {
41 }
42 
43 SalGraphics* SvpSalVirtualDevice::GetGraphics()
44 {
45     SvpSalGraphics* pGraphics = new SvpSalGraphics();
46     pGraphics->setDevice( m_aDevice );
47     m_aGraphics.push_back( pGraphics );
48     return pGraphics;
49 }
50 
51 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
52 {
53     m_aGraphics.remove( dynamic_cast<SvpSalGraphics*>(pGraphics) );
54     delete pGraphics;
55 }
56 
57 sal_Bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
58 {
59     B2IVector aDevSize( nNewDX, nNewDY );
60     if( aDevSize.getX() == 0 )
61         aDevSize.setX( 1 );
62     if( aDevSize.getY() == 0 )
63         aDevSize.setY( 1 );
64     if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
65     {
66         sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
67         std::vector< basebmp::Color > aDevPal;
68         switch( m_nBitCount )
69         {
70             case 1: nFormat = Format::ONE_BIT_MSB_PAL;
71                 aDevPal.reserve(2);
72                 aDevPal.push_back( basebmp::Color( 0, 0, 0 ) );
73                 aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
74                 break;
75             case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
76             case 8: nFormat = Format::EIGHT_BIT_PAL; break;
77 #ifdef OSL_BIGENDIAN
78             case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
79 #else
80             case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
81 #endif
82             case 0:
83             case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
84             case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
85         }
86         m_aDevice = aDevPal.empty()
87                     ? createBitmapDevice( aDevSize, false, nFormat )
88                     : createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
89 
90         // update device in existing graphics
91         for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
92              it != m_aGraphics.end(); ++it )
93              (*it)->setDevice( m_aDevice );
94 
95     }
96     return true;
97 }
98 
99 void SvpSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
100 {
101     if( m_aDevice.get() )
102     {
103         B2IVector aDevSize( m_aDevice->getSize() );
104         rWidth = aDevSize.getX();
105         rHeight = aDevSize.getY();
106     }
107     else
108         rWidth = rHeight = 0;
109 }
110 
111