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 "headless/svpvd.hxx"
21 #include "headless/svpgdi.hxx"
23 #include <basegfx/vector/b2ivector.hxx>
24 #include <basebmp/scanlineformats.hxx>
28 using namespace basegfx
;
29 using namespace basebmp
;
31 SvpSalVirtualDevice::~SvpSalVirtualDevice()
35 SalGraphics
* SvpSalVirtualDevice::GetGraphics()
37 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
38 pGraphics
->setDevice( m_aDevice
);
39 m_aGraphics
.push_back( pGraphics
);
43 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics
* pGraphics
)
45 m_aGraphics
.remove( dynamic_cast<SvpSalGraphics
*>(pGraphics
) );
49 sal_Bool
SvpSalVirtualDevice::SetSize( long nNewDX
, long nNewDY
)
51 return SetSizeUsingBuffer( nNewDX
, nNewDY
, basebmp::RawMemorySharedArray() );
54 sal_Bool
SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX
, long nNewDY
, const basebmp::RawMemorySharedArray
&pBuffer
)
56 B2IVector
aDevSize( nNewDX
, nNewDY
);
57 if( aDevSize
.getX() == 0 )
59 if( aDevSize
.getY() == 0 )
61 if( ! m_aDevice
.get() || m_aDevice
->getSize() != aDevSize
)
63 sal_uInt32 nFormat
= SVP_DEFAULT_BITMAP_FORMAT
;
64 std::vector
< basebmp::Color
> aDevPal
;
67 case 1: nFormat
= Format::ONE_BIT_MSB_PAL
;
69 aDevPal
.push_back( basebmp::Color( 0, 0, 0 ) );
70 aDevPal
.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
72 case 4: nFormat
= Format::FOUR_BIT_MSB_PAL
; break;
73 case 8: nFormat
= Format::EIGHT_BIT_PAL
; break;
75 case 16: nFormat
= Format::SIXTEEN_BIT_MSB_TC_MASK
; break;
77 case 16: nFormat
= Format::SIXTEEN_BIT_LSB_TC_MASK
; break;
79 case 24: nFormat
= Format::TWENTYFOUR_BIT_TC_MASK
; break;
80 case 32: nFormat
= Format::THIRTYTWO_BIT_TC_MASK
; break;
81 #if defined(ANDROID) || defined(IOS)
82 case 0: nFormat
= Format::THIRTYTWO_BIT_TC_MASK_RGBA
; break;
84 case 0: nFormat
= Format::TWENTYFOUR_BIT_TC_MASK
; break;
87 m_aDevice
= aDevPal
.empty()
89 ? createBitmapDevice( aDevSize
, false, nFormat
, pBuffer
, PaletteMemorySharedVector() )
90 : createBitmapDevice( aDevSize
, false, nFormat
)
92 : createBitmapDevice( aDevSize
, false, nFormat
, PaletteMemorySharedVector( new std::vector
< basebmp::Color
>(aDevPal
) ) );
94 // update device in existing graphics
95 for( std::list
< SvpSalGraphics
* >::iterator it
= m_aGraphics
.begin();
96 it
!= m_aGraphics
.end(); ++it
)
97 (*it
)->setDevice( m_aDevice
);
103 void SvpSalVirtualDevice::GetSize( long& rWidth
, long& rHeight
)
105 if( m_aDevice
.get() )
107 B2IVector
aDevSize( m_aDevice
->getSize() );
108 rWidth
= aDevSize
.getX();
109 rHeight
= aDevSize
.getY();
112 rWidth
= rHeight
= 0;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */