xref: /trunk/main/vcl/unx/headless/svpvd.cxx (revision 9f62ea84)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "svpvd.hxx"
25 #include "svpgdi.hxx"
26 
27 #include <basegfx/vector/b2ivector.hxx>
28 #include <basebmp/scanlineformats.hxx>
29 
30 #include "stdio.h"
31 
32 using namespace basegfx;
33 using namespace basebmp;
34 
~SvpSalVirtualDevice()35 SvpSalVirtualDevice::~SvpSalVirtualDevice()
36 {
37 }
38 
GetGraphics()39 SalGraphics* SvpSalVirtualDevice::GetGraphics()
40 {
41     SvpSalGraphics* pGraphics = new SvpSalGraphics();
42     pGraphics->setDevice( m_aDevice );
43     m_aGraphics.push_back( pGraphics );
44     return pGraphics;
45 }
46 
ReleaseGraphics(SalGraphics * pGraphics)47 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
48 {
49     m_aGraphics.remove( dynamic_cast<SvpSalGraphics*>(pGraphics) );
50     delete pGraphics;
51 }
52 
SetSize(long nNewDX,long nNewDY)53 sal_Bool SvpSalVirtualDevice::SetSize( long nNewDX, long nNewDY )
54 {
55     B2IVector aDevSize( nNewDX, nNewDY );
56     if( aDevSize.getX() == 0 )
57         aDevSize.setX( 1 );
58     if( aDevSize.getY() == 0 )
59         aDevSize.setY( 1 );
60     if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
61     {
62         sal_uInt32 nFormat = SVP_DEFAULT_BITMAP_FORMAT;
63         std::vector< basebmp::Color > aDevPal;
64         switch( m_nBitCount )
65         {
66             case 1: nFormat = Format::ONE_BIT_MSB_PAL;
67                 aDevPal.reserve(2);
68                 aDevPal.push_back( basebmp::Color( 0, 0, 0 ) );
69                 aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
70                 break;
71             case 4: nFormat = Format::FOUR_BIT_MSB_PAL; break;
72             case 8: nFormat = Format::EIGHT_BIT_PAL; break;
73 #ifdef OSL_BIGENDIAN
74             case 16: nFormat = Format::SIXTEEN_BIT_MSB_TC_MASK; break;
75 #else
76             case 16: nFormat = Format::SIXTEEN_BIT_LSB_TC_MASK; break;
77 #endif
78             case 0:
79             case 24: nFormat = Format::TWENTYFOUR_BIT_TC_MASK; break;
80             case 32: nFormat = Format::THIRTYTWO_BIT_TC_MASK; break;
81         }
82         m_aDevice = aDevPal.empty()
83                     ? createBitmapDevice( aDevSize, false, nFormat )
84                     : createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
85 
86         // update device in existing graphics
87         for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
88              it != m_aGraphics.end(); ++it )
89              (*it)->setDevice( m_aDevice );
90 
91     }
92     return true;
93 }
94 
GetSize(long & rWidth,long & rHeight)95 void SvpSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
96 {
97     if( m_aDevice.get() )
98     {
99         B2IVector aDevSize( m_aDevice->getSize() );
100         rWidth = aDevSize.getX();
101         rHeight = aDevSize.getY();
102     }
103     else
104         rWidth = rHeight = 0;
105 }
106 
107