xref: /aoo41x/main/vcl/source/gdi/cvtgrf.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/metaact.hxx>
28cdf0e10cSrcweir #include <vcl/cvtgrf.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <salinst.hxx>
31cdf0e10cSrcweir #include <svdata.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // --------------
34cdf0e10cSrcweir // - Callback	-
35cdf0e10cSrcweir // --------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // --------------------
38cdf0e10cSrcweir // - GraphicConverter -
39cdf0e10cSrcweir // --------------------
40cdf0e10cSrcweir 
GraphicConverter()41cdf0e10cSrcweir GraphicConverter::GraphicConverter() :
42cdf0e10cSrcweir 	mpConvertData( NULL )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ------------------------------------------------------------------------
47cdf0e10cSrcweir 
~GraphicConverter()48cdf0e10cSrcweir GraphicConverter::~GraphicConverter()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // ------------------------------------------------------------------------
53cdf0e10cSrcweir 
ImplConvert(sal_uLong nInFormat,void * pInBuffer,sal_uLong nInBufSize,void ** ppOutBuffer,sal_uLong nOutFormat)54cdf0e10cSrcweir sal_uLong GraphicConverter::ImplConvert( sal_uLong nInFormat, void* pInBuffer, sal_uLong nInBufSize,
55cdf0e10cSrcweir 									 void** ppOutBuffer, sal_uLong nOutFormat )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	sal_uLong nRetBufSize = 0UL;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	if( ( nInFormat != nOutFormat ) && pInBuffer )
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir 		if( ( nInFormat == CVT_SVM ) || ( nInFormat == CVT_BMP ) )
62cdf0e10cSrcweir 		{
63cdf0e10cSrcweir 			SvMemoryStream	aIStm;
64cdf0e10cSrcweir 			Graphic			aGraphic;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 			aIStm.SetBuffer( (char*) pInBuffer, nInBufSize, sal_False, nInBufSize );
67cdf0e10cSrcweir 			aIStm >> aGraphic;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 			if( !aIStm.GetError() )
70cdf0e10cSrcweir 			{
71cdf0e10cSrcweir 				SvMemoryStream aOStm( 64535, 64535 );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 				mpConvertData = new ConvertData( aGraphic, aOStm, nOutFormat );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 				if( maFilterHdl.IsSet() && maFilterHdl.Call( mpConvertData ) )
76cdf0e10cSrcweir 				{
77cdf0e10cSrcweir 					nRetBufSize = aOStm.Seek( STREAM_SEEK_TO_END );
78cdf0e10cSrcweir 					*ppOutBuffer = (void*) aOStm.GetData();
79cdf0e10cSrcweir 					aOStm.ObjectOwnsMemory( sal_False );
80cdf0e10cSrcweir 				}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 				delete mpConvertData;
83cdf0e10cSrcweir 				mpConvertData = NULL;
84cdf0e10cSrcweir 			}
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 		else if( ( nOutFormat == CVT_SVM ) || ( nOutFormat == CVT_BMP ) )
87cdf0e10cSrcweir 		{
88cdf0e10cSrcweir 			SvMemoryStream	aIStm;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			aIStm.SetBuffer( (char*) pInBuffer, nInBufSize, sal_False, nInBufSize );
91cdf0e10cSrcweir 			mpConvertData = new ConvertData( Graphic(), aIStm, nInFormat );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 			if( maFilterHdl.IsSet() && maFilterHdl.Call( mpConvertData ) )
94cdf0e10cSrcweir 			{
95cdf0e10cSrcweir 				SvMemoryStream	aOStm( 645535, 64535 );
96cdf0e10cSrcweir 				Graphic&		rGraphic = mpConvertData->maGraphic;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 				if( ( rGraphic.GetType() == GRAPHIC_BITMAP ) && ( CVT_SVM == nOutFormat ) )
99cdf0e10cSrcweir 				{
100cdf0e10cSrcweir 					GDIMetaFile aMtf;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 					aMtf.SetPrefSize( rGraphic.GetPrefSize() );
103cdf0e10cSrcweir 					aMtf.SetPrefMapMode( rGraphic.GetPrefMapMode() );
104cdf0e10cSrcweir 					aMtf.AddAction( new MetaBmpExScaleAction( Point(), aMtf.GetPrefSize(), rGraphic.GetBitmapEx() ) );
105cdf0e10cSrcweir 					rGraphic = aMtf;
106cdf0e10cSrcweir 				}
107cdf0e10cSrcweir 				else if( ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) && ( CVT_BMP == nOutFormat ) )
108cdf0e10cSrcweir 					rGraphic = rGraphic.GetBitmapEx();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 				aOStm << rGraphic;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 				if( !aOStm.GetError() )
113cdf0e10cSrcweir 				{
114cdf0e10cSrcweir 					nRetBufSize = aOStm.Seek( STREAM_SEEK_TO_END );
115cdf0e10cSrcweir 					*ppOutBuffer = (void*) aOStm.GetData();
116cdf0e10cSrcweir 					aOStm.ObjectOwnsMemory( sal_False );
117cdf0e10cSrcweir 				}
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 			delete mpConvertData;
121cdf0e10cSrcweir 			mpConvertData = NULL;
122cdf0e10cSrcweir 		}
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	return nRetBufSize;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // ------------------------------------------------------------------------
129cdf0e10cSrcweir 
Import(SvStream & rIStm,Graphic & rGraphic,sal_uLong nFormat)130cdf0e10cSrcweir sal_uLong GraphicConverter::Import( SvStream& rIStm, Graphic& rGraphic, sal_uLong nFormat )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	GraphicConverter*	pCvt = ImplGetSVData()->maGDIData.mpGrfConverter;
133cdf0e10cSrcweir 	sal_uLong				nRet = ERRCODE_IO_GENERAL;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if( pCvt && pCvt->GetFilterHdl().IsSet() )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		ConvertData	aData( rGraphic, rIStm, nFormat );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		if( pCvt->GetFilterHdl().Call( &aData ) )
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			rGraphic = aData.maGraphic;
142cdf0e10cSrcweir 			nRet = ERRCODE_NONE;
143cdf0e10cSrcweir 		}
144cdf0e10cSrcweir 		else if( rIStm.GetError() )
145cdf0e10cSrcweir 			nRet = rIStm.GetError();
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return nRet;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir // ------------------------------------------------------------------------
152cdf0e10cSrcweir 
Export(SvStream & rOStm,const Graphic & rGraphic,sal_uLong nFormat)153cdf0e10cSrcweir sal_uLong GraphicConverter::Export( SvStream& rOStm, const Graphic& rGraphic, sal_uLong nFormat )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	GraphicConverter*	pCvt = ImplGetSVData()->maGDIData.mpGrfConverter;
156cdf0e10cSrcweir 	sal_uLong				nRet = ERRCODE_IO_GENERAL;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	if( pCvt && pCvt->GetFilterHdl().IsSet() )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		ConvertData	aData( rGraphic, rOStm, nFormat );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		if( pCvt->GetFilterHdl().Call( &aData ) )
163cdf0e10cSrcweir 			nRet = ERRCODE_NONE;
164cdf0e10cSrcweir 		else if( rOStm.GetError() )
165cdf0e10cSrcweir 			nRet = rOStm.GetError();
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	return nRet;
169cdf0e10cSrcweir }
170