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