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: cvtgrf.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/metaact.hxx>
38 #include <vcl/salinst.hxx>
39 #include <vcl/svdata.hxx>
40 #include <vcl/cvtgrf.hxx>
46 // --------------------
47 // - GraphicConverter -
48 // --------------------
50 GraphicConverter::GraphicConverter() :
55 // ------------------------------------------------------------------------
57 GraphicConverter::~GraphicConverter()
61 // ------------------------------------------------------------------------
63 ULONG
GraphicConverter::ImplConvert( ULONG nInFormat
, void* pInBuffer
, ULONG nInBufSize
,
64 void** ppOutBuffer
, ULONG nOutFormat
)
66 ULONG nRetBufSize
= 0UL;
68 if( ( nInFormat
!= nOutFormat
) && pInBuffer
)
70 if( ( nInFormat
== CVT_SVM
) || ( nInFormat
== CVT_BMP
) )
75 aIStm
.SetBuffer( (char*) pInBuffer
, nInBufSize
, FALSE
, nInBufSize
);
78 if( !aIStm
.GetError() )
80 SvMemoryStream
aOStm( 64535, 64535 );
82 mpConvertData
= new ConvertData( aGraphic
, aOStm
, nOutFormat
);
84 if( maFilterHdl
.IsSet() && maFilterHdl
.Call( mpConvertData
) )
86 nRetBufSize
= aOStm
.Seek( STREAM_SEEK_TO_END
);
87 *ppOutBuffer
= (void*) aOStm
.GetData();
88 aOStm
.ObjectOwnsMemory( FALSE
);
95 else if( ( nOutFormat
== CVT_SVM
) || ( nOutFormat
== CVT_BMP
) )
99 aIStm
.SetBuffer( (char*) pInBuffer
, nInBufSize
, FALSE
, nInBufSize
);
100 mpConvertData
= new ConvertData( Graphic(), aIStm
, nInFormat
);
102 if( maFilterHdl
.IsSet() && maFilterHdl
.Call( mpConvertData
) )
104 SvMemoryStream
aOStm( 645535, 64535 );
105 Graphic
& rGraphic
= mpConvertData
->maGraphic
;
107 if( ( rGraphic
.GetType() == GRAPHIC_BITMAP
) && ( CVT_SVM
== nOutFormat
) )
111 aMtf
.SetPrefSize( rGraphic
.GetPrefSize() );
112 aMtf
.SetPrefMapMode( rGraphic
.GetPrefMapMode() );
113 aMtf
.AddAction( new MetaBmpExScaleAction( Point(), aMtf
.GetPrefSize(), rGraphic
.GetBitmapEx() ) );
116 else if( ( rGraphic
.GetType() == GRAPHIC_GDIMETAFILE
) && ( CVT_BMP
== nOutFormat
) )
117 rGraphic
= rGraphic
.GetBitmapEx();
121 if( !aOStm
.GetError() )
123 nRetBufSize
= aOStm
.Seek( STREAM_SEEK_TO_END
);
124 *ppOutBuffer
= (void*) aOStm
.GetData();
125 aOStm
.ObjectOwnsMemory( FALSE
);
129 delete mpConvertData
;
130 mpConvertData
= NULL
;
137 // ------------------------------------------------------------------------
139 ULONG
GraphicConverter::Import( SvStream
& rIStm
, Graphic
& rGraphic
, ULONG nFormat
)
141 GraphicConverter
* pCvt
= ImplGetSVData()->maGDIData
.mpGrfConverter
;
142 ULONG nRet
= ERRCODE_IO_GENERAL
;
144 if( pCvt
&& pCvt
->GetFilterHdl().IsSet() )
146 ConvertData
aData( rGraphic
, rIStm
, nFormat
);
148 if( pCvt
->GetFilterHdl().Call( &aData
) )
150 rGraphic
= aData
.maGraphic
;
153 else if( rIStm
.GetError() )
154 nRet
= rIStm
.GetError();
160 // ------------------------------------------------------------------------
162 ULONG
GraphicConverter::Export( SvStream
& rOStm
, const Graphic
& rGraphic
, ULONG nFormat
)
164 GraphicConverter
* pCvt
= ImplGetSVData()->maGDIData
.mpGrfConverter
;
165 ULONG nRet
= ERRCODE_IO_GENERAL
;
167 if( pCvt
&& pCvt
->GetFilterHdl().IsSet() )
169 ConvertData
aData( rGraphic
, rOStm
, nFormat
);
171 if( pCvt
->GetFilterHdl().Call( &aData
) )
173 else if( rOStm
.GetError() )
174 nRet
= rOStm
.GetError();