1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <vcl/metaact.hxx> 32*cdf0e10cSrcweir #include <vcl/cvtgrf.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <salinst.hxx> 35*cdf0e10cSrcweir #include <svdata.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // -------------- 38*cdf0e10cSrcweir // - Callback - 39*cdf0e10cSrcweir // -------------- 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // -------------------- 42*cdf0e10cSrcweir // - GraphicConverter - 43*cdf0e10cSrcweir // -------------------- 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir GraphicConverter::GraphicConverter() : 46*cdf0e10cSrcweir mpConvertData( NULL ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ------------------------------------------------------------------------ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir GraphicConverter::~GraphicConverter() 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // ------------------------------------------------------------------------ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir sal_uLong GraphicConverter::ImplConvert( sal_uLong nInFormat, void* pInBuffer, sal_uLong nInBufSize, 59*cdf0e10cSrcweir void** ppOutBuffer, sal_uLong nOutFormat ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir sal_uLong nRetBufSize = 0UL; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir if( ( nInFormat != nOutFormat ) && pInBuffer ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir if( ( nInFormat == CVT_SVM ) || ( nInFormat == CVT_BMP ) ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir SvMemoryStream aIStm; 68*cdf0e10cSrcweir Graphic aGraphic; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir aIStm.SetBuffer( (char*) pInBuffer, nInBufSize, sal_False, nInBufSize ); 71*cdf0e10cSrcweir aIStm >> aGraphic; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir if( !aIStm.GetError() ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir SvMemoryStream aOStm( 64535, 64535 ); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir mpConvertData = new ConvertData( aGraphic, aOStm, nOutFormat ); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if( maFilterHdl.IsSet() && maFilterHdl.Call( mpConvertData ) ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir nRetBufSize = aOStm.Seek( STREAM_SEEK_TO_END ); 82*cdf0e10cSrcweir *ppOutBuffer = (void*) aOStm.GetData(); 83*cdf0e10cSrcweir aOStm.ObjectOwnsMemory( sal_False ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir delete mpConvertData; 87*cdf0e10cSrcweir mpConvertData = NULL; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir else if( ( nOutFormat == CVT_SVM ) || ( nOutFormat == CVT_BMP ) ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir SvMemoryStream aIStm; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir aIStm.SetBuffer( (char*) pInBuffer, nInBufSize, sal_False, nInBufSize ); 95*cdf0e10cSrcweir mpConvertData = new ConvertData( Graphic(), aIStm, nInFormat ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if( maFilterHdl.IsSet() && maFilterHdl.Call( mpConvertData ) ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir SvMemoryStream aOStm( 645535, 64535 ); 100*cdf0e10cSrcweir Graphic& rGraphic = mpConvertData->maGraphic; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir if( ( rGraphic.GetType() == GRAPHIC_BITMAP ) && ( CVT_SVM == nOutFormat ) ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir GDIMetaFile aMtf; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir aMtf.SetPrefSize( rGraphic.GetPrefSize() ); 107*cdf0e10cSrcweir aMtf.SetPrefMapMode( rGraphic.GetPrefMapMode() ); 108*cdf0e10cSrcweir aMtf.AddAction( new MetaBmpExScaleAction( Point(), aMtf.GetPrefSize(), rGraphic.GetBitmapEx() ) ); 109*cdf0e10cSrcweir rGraphic = aMtf; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir else if( ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) && ( CVT_BMP == nOutFormat ) ) 112*cdf0e10cSrcweir rGraphic = rGraphic.GetBitmapEx(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir aOStm << rGraphic; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if( !aOStm.GetError() ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir nRetBufSize = aOStm.Seek( STREAM_SEEK_TO_END ); 119*cdf0e10cSrcweir *ppOutBuffer = (void*) aOStm.GetData(); 120*cdf0e10cSrcweir aOStm.ObjectOwnsMemory( sal_False ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir delete mpConvertData; 125*cdf0e10cSrcweir mpConvertData = NULL; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return nRetBufSize; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // ------------------------------------------------------------------------ 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir sal_uLong GraphicConverter::Import( SvStream& rIStm, Graphic& rGraphic, sal_uLong nFormat ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir GraphicConverter* pCvt = ImplGetSVData()->maGDIData.mpGrfConverter; 137*cdf0e10cSrcweir sal_uLong nRet = ERRCODE_IO_GENERAL; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir if( pCvt && pCvt->GetFilterHdl().IsSet() ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir ConvertData aData( rGraphic, rIStm, nFormat ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir if( pCvt->GetFilterHdl().Call( &aData ) ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir rGraphic = aData.maGraphic; 146*cdf0e10cSrcweir nRet = ERRCODE_NONE; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else if( rIStm.GetError() ) 149*cdf0e10cSrcweir nRet = rIStm.GetError(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir return nRet; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // ------------------------------------------------------------------------ 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir sal_uLong GraphicConverter::Export( SvStream& rOStm, const Graphic& rGraphic, sal_uLong nFormat ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir GraphicConverter* pCvt = ImplGetSVData()->maGDIData.mpGrfConverter; 160*cdf0e10cSrcweir sal_uLong nRet = ERRCODE_IO_GENERAL; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if( pCvt && pCvt->GetFilterHdl().IsSet() ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir ConvertData aData( rGraphic, rOStm, nFormat ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if( pCvt->GetFilterHdl().Call( &aData ) ) 167*cdf0e10cSrcweir nRet = ERRCODE_NONE; 168*cdf0e10cSrcweir else if( rOStm.GetError() ) 169*cdf0e10cSrcweir nRet = rOStm.GetError(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir return nRet; 173*cdf0e10cSrcweir } 174