1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sot/factory.hxx> 28cdf0e10cSrcweir #include <tools/urlobj.hxx> 29cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 30cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 31cdf0e10cSrcweir #include <tools/poly.hxx> 32cdf0e10cSrcweir #include <vcl/virdev.hxx> 33cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 34cdf0e10cSrcweir #include <svl/solar.hrc> 35cdf0e10cSrcweir #include <sfx2/docfile.hxx> 36cdf0e10cSrcweir #include <sfx2/app.hxx> 37cdf0e10cSrcweir #include "svx/xoutbmp.hxx" 38cdf0e10cSrcweir #include <svtools/FilterConfigItem.hxx> 39cdf0e10cSrcweir #include <svtools/filter.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir // ----------- 42cdf0e10cSrcweir // - Defines - 43cdf0e10cSrcweir // ----------- 44cdf0e10cSrcweir 45cdf0e10cSrcweir #define FORMAT_BMP String(RTL_CONSTASCII_USTRINGPARAM("bmp")) 46cdf0e10cSrcweir #define FORMAT_GIF String(RTL_CONSTASCII_USTRINGPARAM("gif")) 47cdf0e10cSrcweir #define FORMAT_JPG String(RTL_CONSTASCII_USTRINGPARAM("jpg")) 48cdf0e10cSrcweir #define FORMAT_PNG String(RTL_CONSTASCII_USTRINGPARAM("png")) 49cdf0e10cSrcweir 50cdf0e10cSrcweir // -------------- 51cdf0e10cSrcweir // - XOutBitmap - 52cdf0e10cSrcweir // -------------- 53cdf0e10cSrcweir 54cdf0e10cSrcweir GraphicFilter* XOutBitmap::pGrfFilter = NULL; 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ----------------------------------------------------------------------------- 57cdf0e10cSrcweir 58cdf0e10cSrcweir BitmapEx XOutBitmap::CreateQuickDrawBitmapEx( const Graphic& rGraphic, const OutputDevice& rCompDev, 59cdf0e10cSrcweir const MapMode& rMapMode, const Size& rLogSize, 60cdf0e10cSrcweir const Point& rPoint, const Size& rSize ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir BitmapEx aRetBmp; 63cdf0e10cSrcweir 64cdf0e10cSrcweir if( rGraphic.IsAlpha() ) 65cdf0e10cSrcweir aRetBmp = rGraphic.GetBitmapEx(); 66cdf0e10cSrcweir else 67cdf0e10cSrcweir { 68cdf0e10cSrcweir VirtualDevice aVDev( rCompDev ); 69cdf0e10cSrcweir MapMode aMap( rMapMode ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir aMap.SetOrigin( Point() ); 72cdf0e10cSrcweir aVDev.SetMapMode( aMap ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir Point aPoint( aVDev.LogicToPixel( rPoint ) ); 75cdf0e10cSrcweir Size aOldSize( aVDev.LogicToPixel( rSize ) ); 76cdf0e10cSrcweir Size aAbsSize( aOldSize ); 77cdf0e10cSrcweir Size aQSizePix( aVDev.LogicToPixel( rLogSize ) ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir aVDev.SetMapMode( MapMode() ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir if( aOldSize.Width() < 0 ) 82cdf0e10cSrcweir aAbsSize.Width() = -aAbsSize.Width(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir if( aOldSize.Height() < 0 ) 85cdf0e10cSrcweir aAbsSize.Height() = -aAbsSize.Height(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir if( aVDev.SetOutputSizePixel( aAbsSize ) ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir Point aNewOrg( -aPoint.X(), -aPoint.Y() ); 90cdf0e10cSrcweir const Point aNullPoint; 91cdf0e10cSrcweir 92cdf0e10cSrcweir // horizontale Spiegelung ggf. beruecksichtigen 93cdf0e10cSrcweir if( aOldSize.Width() < 0 ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir aNewOrg.X() -= aOldSize.Width(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir // und jetzt noch einen abziehen 98cdf0e10cSrcweir aNewOrg.X()--; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // vertikale Spiegelung ggf. beruecksichtigen 102cdf0e10cSrcweir if( rSize.Height() < 0 ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir aNewOrg.Y() -= aOldSize.Height(); 105cdf0e10cSrcweir 106cdf0e10cSrcweir // und jetzt noch einen abziehen 107cdf0e10cSrcweir aNewOrg.Y()--; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir if( rGraphic.GetType() != GRAPHIC_BITMAP ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir rGraphic.Draw( &aVDev, aNewOrg, aQSizePix ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir const Bitmap aBmp( aVDev.GetBitmap( aNullPoint, aAbsSize ) ); 115cdf0e10cSrcweir Bitmap aMask; 116cdf0e10cSrcweir 117cdf0e10cSrcweir Graphic( rGraphic.GetGDIMetaFile().GetMonochromeMtf( COL_BLACK ) ).Draw( &aVDev, aNewOrg, aQSizePix ); 118cdf0e10cSrcweir aMask = aVDev.GetBitmap( aNullPoint, aAbsSize ); 119cdf0e10cSrcweir aRetBmp = BitmapEx( aBmp, aMask ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir else 122cdf0e10cSrcweir { 123cdf0e10cSrcweir Bitmap aBmp( rGraphic.GetBitmap() ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // UNX has got problems with 1x1 bitmaps which are transparent (KA 02.11.1998) 126cdf0e10cSrcweir #ifdef UNX 127cdf0e10cSrcweir const Size aBmpSize( aBmp.GetSizePixel() ); 128cdf0e10cSrcweir sal_Bool bFullTrans = sal_False; 129cdf0e10cSrcweir 130cdf0e10cSrcweir if( aBmpSize.Width() == 1 && aBmpSize.Height() == 1 && rGraphic.IsTransparent() ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir Bitmap aTrans( rGraphic.GetBitmapEx().GetMask() ); 133cdf0e10cSrcweir BitmapReadAccess* pMAcc = aBmp.AcquireReadAccess(); 134cdf0e10cSrcweir 135cdf0e10cSrcweir if( pMAcc ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir if( pMAcc->GetColor( 0, 0 ) == BitmapColor( Color( COL_WHITE ) ) ) 138cdf0e10cSrcweir bFullTrans = sal_True; 139cdf0e10cSrcweir 140cdf0e10cSrcweir aTrans.ReleaseAccess( pMAcc ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir if( !bFullTrans ) 145cdf0e10cSrcweir #endif // UNX 146cdf0e10cSrcweir 147cdf0e10cSrcweir { 148cdf0e10cSrcweir DitherBitmap( aBmp ); 149cdf0e10cSrcweir aVDev.DrawBitmap( aNewOrg, aQSizePix, aBmp ); 150cdf0e10cSrcweir aBmp = aVDev.GetBitmap( aNullPoint, aAbsSize ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir if( !rGraphic.IsTransparent() ) 153cdf0e10cSrcweir aRetBmp = BitmapEx( aBmp ); 154cdf0e10cSrcweir else 155cdf0e10cSrcweir { 156cdf0e10cSrcweir Bitmap aTrans( rGraphic.GetBitmapEx().GetMask() ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir if( !aTrans ) 159cdf0e10cSrcweir aRetBmp = BitmapEx( aBmp, rGraphic.GetBitmapEx().GetTransparentColor() ); 160cdf0e10cSrcweir else 161cdf0e10cSrcweir { 162cdf0e10cSrcweir aVDev.DrawBitmap( aNewOrg, aQSizePix, aTrans ); 163cdf0e10cSrcweir aRetBmp = BitmapEx( aBmp, aVDev.GetBitmap( Point(), aAbsSize ) ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir return aRetBmp; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ------------------------------------------------------------------------ 175cdf0e10cSrcweir 176cdf0e10cSrcweir void XOutBitmap::DrawQuickDrawBitmapEx( OutputDevice* pOutDev, const Point& rPt, 177cdf0e10cSrcweir const Size& rSize, const BitmapEx& rBmpEx ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir const Size aBmpSizePix( rBmpEx.GetSizePixel() ); 180cdf0e10cSrcweir const Size aSizePix( pOutDev->LogicToPixel( rSize ) ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir if ( ( aSizePix.Width() - aBmpSizePix.Width() ) || ( aSizePix.Height() - aBmpSizePix.Height() ) ) 183cdf0e10cSrcweir rBmpEx.Draw( pOutDev, rPt, rSize ); 184cdf0e10cSrcweir else 185cdf0e10cSrcweir rBmpEx.Draw( pOutDev, rPt ); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir // ------------------------------------------------------------------------ 189cdf0e10cSrcweir 190cdf0e10cSrcweir void XOutBitmap::DrawTiledBitmapEx( OutputDevice* pOutDev, 191cdf0e10cSrcweir const Point& rStartPt, const Size& rGrfSize, 192cdf0e10cSrcweir const Rectangle& rTileRect, const BitmapEx& rBmpEx ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir Rectangle aClipRect( pOutDev->LogicToPixel( pOutDev->GetClipRegion().GetBoundRect() ) ); 195cdf0e10cSrcweir Rectangle aPixRect( pOutDev->LogicToPixel( rTileRect ) ); 196cdf0e10cSrcweir const Size aPixSize( pOutDev->LogicToPixel( rGrfSize ) ); 197cdf0e10cSrcweir const Point aPixPoint( pOutDev->LogicToPixel( rStartPt ) ); 198cdf0e10cSrcweir Point aOrg; 199cdf0e10cSrcweir const long nWidth = aPixSize.Width(); 200cdf0e10cSrcweir const long nHeight = aPixSize.Height(); 201cdf0e10cSrcweir long nXPos = aPixPoint.X() + ( ( aPixRect.Left() - aPixPoint.X() ) / nWidth ) * nWidth; 202cdf0e10cSrcweir long nYPos = aPixPoint.Y() + ( ( aPixRect.Top() - aPixPoint.Y() ) / nHeight ) * nHeight; 203cdf0e10cSrcweir const long nBottom = aPixRect.Bottom(); 204cdf0e10cSrcweir const long nRight = aPixRect.Right(); 205cdf0e10cSrcweir const long nLeft = nXPos; 206cdf0e10cSrcweir const sal_Bool bNoSize = ( aPixSize == rBmpEx.GetSizePixel() ); 207cdf0e10cSrcweir 208cdf0e10cSrcweir pOutDev->Push(); 209cdf0e10cSrcweir pOutDev->SetMapMode( MapMode() ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir // ggf. neue ClipRegion berechnen und setzen 212cdf0e10cSrcweir if ( pOutDev->IsClipRegion() ) 213cdf0e10cSrcweir aPixRect.Intersection( aClipRect ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir pOutDev->SetClipRegion( aPixRect ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir while( nYPos <= nBottom ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir while( nXPos <= nRight ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir if ( bNoSize ) 222cdf0e10cSrcweir rBmpEx.Draw( pOutDev, Point( nXPos, nYPos ) ); 223cdf0e10cSrcweir else 224cdf0e10cSrcweir rBmpEx.Draw( pOutDev, Point( nXPos, nYPos ), aPixSize ); 225cdf0e10cSrcweir 226cdf0e10cSrcweir nXPos += nWidth; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir nXPos = nLeft; 230cdf0e10cSrcweir nYPos += nHeight; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir pOutDev->Pop(); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir // ------------------------------------------------------------------------ 237cdf0e10cSrcweir 238cdf0e10cSrcweir Animation XOutBitmap::MirrorAnimation( const Animation& rAnimation, sal_Bool bHMirr, sal_Bool bVMirr ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir Animation aNewAnim( rAnimation ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir if( bHMirr || bVMirr ) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir const Size& rGlobalSize = aNewAnim.GetDisplaySizePixel(); 245cdf0e10cSrcweir sal_uIntPtr nMirrorFlags = 0L; 246cdf0e10cSrcweir 247cdf0e10cSrcweir if( bHMirr ) 248cdf0e10cSrcweir nMirrorFlags |= BMP_MIRROR_HORZ; 249cdf0e10cSrcweir 250cdf0e10cSrcweir if( bVMirr ) 251cdf0e10cSrcweir nMirrorFlags |= BMP_MIRROR_VERT; 252cdf0e10cSrcweir 253cdf0e10cSrcweir for( sal_uInt16 i = 0, nCount = aNewAnim.Count(); i < nCount; i++ ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir AnimationBitmap aAnimBmp( aNewAnim.Get( i ) ); 256cdf0e10cSrcweir 257cdf0e10cSrcweir // BitmapEx spiegeln 258cdf0e10cSrcweir aAnimBmp.aBmpEx.Mirror( nMirrorFlags ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir // Die Positionen innerhalb der Gesamtbitmap 261cdf0e10cSrcweir // muessen natuerlich auch angepasst werden 262cdf0e10cSrcweir if( bHMirr ) 263cdf0e10cSrcweir aAnimBmp.aPosPix.X() = rGlobalSize.Width() - aAnimBmp.aPosPix.X() - 264cdf0e10cSrcweir aAnimBmp.aSizePix.Width(); 265cdf0e10cSrcweir 266cdf0e10cSrcweir if( bVMirr ) 267cdf0e10cSrcweir aAnimBmp.aPosPix.Y() = rGlobalSize.Height() - aAnimBmp.aPosPix.Y() - 268cdf0e10cSrcweir aAnimBmp.aSizePix.Height(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir aNewAnim.Replace( aAnimBmp, i ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir return aNewAnim; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir // ------------------------------------------------------------------------ 278cdf0e10cSrcweir 279cdf0e10cSrcweir Graphic XOutBitmap::MirrorGraphic( const Graphic& rGraphic, const sal_uIntPtr nMirrorFlags ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir Graphic aRetGraphic; 282cdf0e10cSrcweir 283cdf0e10cSrcweir if( nMirrorFlags ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir if( rGraphic.IsAnimated() ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir aRetGraphic = MirrorAnimation( rGraphic.GetAnimation(), 288cdf0e10cSrcweir ( nMirrorFlags & BMP_MIRROR_HORZ ) == BMP_MIRROR_HORZ, 289cdf0e10cSrcweir ( nMirrorFlags & BMP_MIRROR_VERT ) == BMP_MIRROR_VERT ); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir else 292cdf0e10cSrcweir { 293cdf0e10cSrcweir if( rGraphic.IsTransparent() ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir aBmpEx.Mirror( nMirrorFlags ); 298cdf0e10cSrcweir aRetGraphic = aBmpEx; 299cdf0e10cSrcweir } 300cdf0e10cSrcweir else 301cdf0e10cSrcweir { 302cdf0e10cSrcweir Bitmap aBmp( rGraphic.GetBitmap() ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir aBmp.Mirror( nMirrorFlags ); 305cdf0e10cSrcweir aRetGraphic = aBmp; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir else 310cdf0e10cSrcweir aRetGraphic = rGraphic; 311cdf0e10cSrcweir 312cdf0e10cSrcweir return aRetGraphic; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // ------------------------------------------------------------------------ 316cdf0e10cSrcweir 317cdf0e10cSrcweir sal_uInt16 XOutBitmap::WriteGraphic( const Graphic& rGraphic, String& rFileName, 318cdf0e10cSrcweir const String& rFilterName, const sal_uIntPtr nFlags, 319cdf0e10cSrcweir const Size* pMtfSize_100TH_MM ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir if( rGraphic.GetType() != GRAPHIC_NONE ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir INetURLObject aURL( rFileName ); 324cdf0e10cSrcweir Graphic aGraphic; 325cdf0e10cSrcweir String aExt; 326cdf0e10cSrcweir GraphicFilter* pFilter = GraphicFilter::GetGraphicFilter(); 327cdf0e10cSrcweir sal_uInt16 nErr = GRFILTER_FILTERERROR, nFilter = GRFILTER_FORMAT_NOTFOUND; 328cdf0e10cSrcweir sal_Bool bTransparent = rGraphic.IsTransparent(), bAnimated = rGraphic.IsAnimated(); 329cdf0e10cSrcweir 330cdf0e10cSrcweir DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "XOutBitmap::WriteGraphic(...): invalid URL" ); 331cdf0e10cSrcweir 332cdf0e10cSrcweir // calculate correct file name 333cdf0e10cSrcweir if( !( nFlags & XOUTBMP_DONT_EXPAND_FILENAME ) ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir String aName( aURL.getBase() ); 336cdf0e10cSrcweir aName += '_'; 337cdf0e10cSrcweir aName += String(aURL.getExtension()); 338cdf0e10cSrcweir aName += '_'; 339cdf0e10cSrcweir String aStr( String::CreateFromInt32( rGraphic.GetChecksum(), 16 ) ); 340cdf0e10cSrcweir if ( aStr.GetChar(0) == '-' ) 341cdf0e10cSrcweir aStr.SetChar(0,'m'); 342cdf0e10cSrcweir aName += aStr; 343cdf0e10cSrcweir aURL.setBase( aName ); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 34661472d26SArmin Le Grand // #121128# use shortcut to write SVG data in original form (if possible) 34761472d26SArmin Le Grand const SvgDataPtr aSvgDataPtr(rGraphic.getSvgData()); 34861472d26SArmin Le Grand 34961472d26SArmin Le Grand if(aSvgDataPtr.get() 35061472d26SArmin Le Grand && aSvgDataPtr->getSvgDataArrayLength() 35161472d26SArmin Le Grand && rFilterName.EqualsIgnoreCaseAscii("svg")) 35261472d26SArmin Le Grand { 35361472d26SArmin Le Grand if(!(nFlags & XOUTBMP_DONT_ADD_EXTENSION)) 35461472d26SArmin Le Grand { 35561472d26SArmin Le Grand aURL.setExtension(rFilterName); 35661472d26SArmin Le Grand } 35761472d26SArmin Le Grand 35861472d26SArmin Le Grand rFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); 35961472d26SArmin Le Grand SfxMedium aMedium(aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE|STREAM_SHARE_DENYNONE|STREAM_TRUNC, true); 36061472d26SArmin Le Grand SvStream* pOStm = aMedium.GetOutStream(); 36161472d26SArmin Le Grand 36261472d26SArmin Le Grand if(pOStm) 36361472d26SArmin Le Grand { 36461472d26SArmin Le Grand pOStm->Write(aSvgDataPtr->getSvgDataArray().get(), aSvgDataPtr->getSvgDataArrayLength()); 36561472d26SArmin Le Grand aMedium.Commit(); 36661472d26SArmin Le Grand 36761472d26SArmin Le Grand if(!aMedium.GetError()) 36861472d26SArmin Le Grand { 36961472d26SArmin Le Grand nErr = GRFILTER_OK; 37061472d26SArmin Le Grand } 37161472d26SArmin Le Grand } 37261472d26SArmin Le Grand } 37361472d26SArmin Le Grand 37461472d26SArmin Le Grand if( GRFILTER_OK != nErr ) 37561472d26SArmin Le Grand { 376cdf0e10cSrcweir if( ( nFlags & XOUTBMP_USE_NATIVE_IF_POSSIBLE ) && 377cdf0e10cSrcweir !( nFlags & XOUTBMP_MIRROR_HORZ ) && 378cdf0e10cSrcweir !( nFlags & XOUTBMP_MIRROR_VERT ) && 379cdf0e10cSrcweir ( rGraphic.GetType() != GRAPHIC_GDIMETAFILE ) && rGraphic.IsLink() ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir // try to write native link 382cdf0e10cSrcweir const GfxLink aGfxLink( ( (Graphic&) rGraphic ).GetLink() ); 383cdf0e10cSrcweir 384cdf0e10cSrcweir switch( aGfxLink.GetType() ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_GIF ): aExt = FORMAT_GIF; break; 387cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_JPG ): aExt = FORMAT_JPG; break; 388cdf0e10cSrcweir case( GFX_LINK_TYPE_NATIVE_PNG ): aExt = FORMAT_PNG; break; 389cdf0e10cSrcweir 390cdf0e10cSrcweir default: 391cdf0e10cSrcweir break; 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir if( aExt.Len() ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION)) 397cdf0e10cSrcweir aURL.setExtension( aExt ); 398cdf0e10cSrcweir rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE ); 399cdf0e10cSrcweir 400cdf0e10cSrcweir SfxMedium aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True ); 401cdf0e10cSrcweir SvStream* pOStm = aMedium.GetOutStream(); 402cdf0e10cSrcweir 403cdf0e10cSrcweir if( pOStm && aGfxLink.GetDataSize() && aGfxLink.GetData() ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() ); 406cdf0e10cSrcweir aMedium.Commit(); 407cdf0e10cSrcweir 408cdf0e10cSrcweir if( !aMedium.GetError() ) 409cdf0e10cSrcweir nErr = GRFILTER_OK; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 41361472d26SArmin Le Grand } 414cdf0e10cSrcweir 415cdf0e10cSrcweir if( GRFILTER_OK != nErr ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir String aFilter( rFilterName ); 418cdf0e10cSrcweir sal_Bool bWriteTransGrf = ( aFilter.EqualsIgnoreCaseAscii( "transgrf" ) ) || 419cdf0e10cSrcweir ( aFilter.EqualsIgnoreCaseAscii( "gif" ) ) || 420cdf0e10cSrcweir ( nFlags & XOUTBMP_USE_GIF_IF_POSSIBLE ) || 421cdf0e10cSrcweir ( ( nFlags & XOUTBMP_USE_GIF_IF_SENSIBLE ) && ( bAnimated || bTransparent ) ); 422cdf0e10cSrcweir 423cdf0e10cSrcweir // get filter and extension 424cdf0e10cSrcweir if( bWriteTransGrf ) 425cdf0e10cSrcweir aFilter = FORMAT_GIF; 426cdf0e10cSrcweir 427cdf0e10cSrcweir nFilter = pFilter->GetExportFormatNumberForShortName( aFilter ); 428cdf0e10cSrcweir 429cdf0e10cSrcweir if( GRFILTER_FORMAT_NOTFOUND == nFilter ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_JPG ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir if( GRFILTER_FORMAT_NOTFOUND == nFilter ) 434cdf0e10cSrcweir nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_BMP ); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir if( GRFILTER_FORMAT_NOTFOUND != nFilter ) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir aExt = pFilter->GetExportFormatShortName( nFilter ).ToLowerAscii(); 440cdf0e10cSrcweir 441cdf0e10cSrcweir if( bWriteTransGrf ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir if( bAnimated ) 444cdf0e10cSrcweir aGraphic = rGraphic; 445cdf0e10cSrcweir else 446cdf0e10cSrcweir { 447cdf0e10cSrcweir if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir VirtualDevice aVDev; 450cdf0e10cSrcweir const Size aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) ); 451cdf0e10cSrcweir 452cdf0e10cSrcweir if( aVDev.SetOutputSizePixel( aSize ) ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir const Wallpaper aWallpaper( aVDev.GetBackground() ); 455cdf0e10cSrcweir const Point aPt; 456cdf0e10cSrcweir 457cdf0e10cSrcweir aVDev.SetBackground( Wallpaper( Color( COL_BLACK ) ) ); 458cdf0e10cSrcweir aVDev.Erase(); 459cdf0e10cSrcweir rGraphic.Draw( &aVDev, aPt, aSize ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir const Bitmap aBitmap( aVDev.GetBitmap( aPt, aSize ) ); 462cdf0e10cSrcweir 463cdf0e10cSrcweir aVDev.SetBackground( aWallpaper ); 464cdf0e10cSrcweir aVDev.Erase(); 465cdf0e10cSrcweir rGraphic.Draw( &aVDev, aPt, aSize ); 466cdf0e10cSrcweir 467cdf0e10cSrcweir aVDev.SetRasterOp( ROP_XOR ); 468cdf0e10cSrcweir aVDev.DrawBitmap( aPt, aSize, aBitmap ); 469cdf0e10cSrcweir aGraphic = BitmapEx( aBitmap, aVDev.GetBitmap( aPt, aSize ) ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir else 472cdf0e10cSrcweir aGraphic = rGraphic.GetBitmapEx(); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir else 475cdf0e10cSrcweir aGraphic = rGraphic.GetBitmapEx(); 476cdf0e10cSrcweir } 477cdf0e10cSrcweir } 478cdf0e10cSrcweir else 479cdf0e10cSrcweir { 480cdf0e10cSrcweir if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir VirtualDevice aVDev; 483cdf0e10cSrcweir const Size aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir if( aVDev.SetOutputSizePixel( aSize ) ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir rGraphic.Draw( &aVDev, Point(), aSize ); 488cdf0e10cSrcweir aGraphic = aVDev.GetBitmap( Point(), aSize ); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir else 491cdf0e10cSrcweir aGraphic = rGraphic.GetBitmap(); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir else 494cdf0e10cSrcweir aGraphic = rGraphic.GetBitmap(); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir 497cdf0e10cSrcweir // mirror? 498cdf0e10cSrcweir if( ( nFlags & XOUTBMP_MIRROR_HORZ ) || ( nFlags & XOUTBMP_MIRROR_VERT ) ) 499cdf0e10cSrcweir aGraphic = MirrorGraphic( aGraphic, nFlags ); 500cdf0e10cSrcweir 501cdf0e10cSrcweir if( ( GRFILTER_FORMAT_NOTFOUND != nFilter ) && ( aGraphic.GetType() != GRAPHIC_NONE ) ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION)) 504cdf0e10cSrcweir aURL.setExtension( aExt ); 505cdf0e10cSrcweir rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE ); 506cdf0e10cSrcweir nErr = ExportGraphic( aGraphic, aURL, *pFilter, nFilter, NULL ); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir return nErr; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir else 514cdf0e10cSrcweir { 515cdf0e10cSrcweir return GRFILTER_OK; 516cdf0e10cSrcweir } 517cdf0e10cSrcweir } 518cdf0e10cSrcweir 519cdf0e10cSrcweir // ------------------------------------------------------------------------ 520cdf0e10cSrcweir 521cdf0e10cSrcweir #ifdef _MSC_VER 522cdf0e10cSrcweir #pragma optimize ( "", off ) 523cdf0e10cSrcweir #endif 524cdf0e10cSrcweir 525cdf0e10cSrcweir sal_uInt16 XOutBitmap::ExportGraphic( const Graphic& rGraphic, const INetURLObject& rURL, 526cdf0e10cSrcweir GraphicFilter& rFilter, const sal_uInt16 nFormat, 527cdf0e10cSrcweir const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "XOutBitmap::ExportGraphic(...): invalid URL" ); 530cdf0e10cSrcweir 531cdf0e10cSrcweir SfxMedium aMedium( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True ); 532cdf0e10cSrcweir SvStream* pOStm = aMedium.GetOutStream(); 533cdf0e10cSrcweir sal_uInt16 nRet = GRFILTER_IOERROR; 534cdf0e10cSrcweir 535cdf0e10cSrcweir if( pOStm ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir pGrfFilter = &rFilter; 538cdf0e10cSrcweir 539cdf0e10cSrcweir nRet = rFilter.ExportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pOStm, nFormat, pFilterData ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir pGrfFilter = NULL; 542cdf0e10cSrcweir aMedium.Commit(); 543cdf0e10cSrcweir 544cdf0e10cSrcweir if( aMedium.GetError() && ( GRFILTER_OK == nRet ) ) 545cdf0e10cSrcweir nRet = GRFILTER_IOERROR; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir 548cdf0e10cSrcweir return nRet; 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir #ifdef _MSC_VER 552cdf0e10cSrcweir #pragma optimize ( "", on ) 553cdf0e10cSrcweir #endif 554cdf0e10cSrcweir 555cdf0e10cSrcweir // ------------------------------------------------------------------------ 556cdf0e10cSrcweir 557cdf0e10cSrcweir Bitmap XOutBitmap::DetectEdges( const Bitmap& rBmp, const sal_uInt8 cThreshold ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir const Size aSize( rBmp.GetSizePixel() ); 560cdf0e10cSrcweir Bitmap aRetBmp; 561cdf0e10cSrcweir sal_Bool bRet = sal_False; 562cdf0e10cSrcweir 563cdf0e10cSrcweir if( ( aSize.Width() > 2L ) && ( aSize.Height() > 2L ) ) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir Bitmap aWorkBmp( rBmp ); 566cdf0e10cSrcweir 567cdf0e10cSrcweir if( aWorkBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) ) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir Bitmap aDstBmp( aSize, 1 ); 570cdf0e10cSrcweir BitmapReadAccess* pReadAcc = aWorkBmp.AcquireReadAccess(); 571cdf0e10cSrcweir BitmapWriteAccess* pWriteAcc = aDstBmp.AcquireWriteAccess(); 572cdf0e10cSrcweir 573cdf0e10cSrcweir if( pReadAcc && pWriteAcc ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir const long nWidth = aSize.Width(); 576cdf0e10cSrcweir const long nWidth2 = nWidth - 2L; 577cdf0e10cSrcweir const long nHeight = aSize.Height(); 578cdf0e10cSrcweir const long nHeight2 = nHeight - 2L; 579cdf0e10cSrcweir const long lThres2 = (long) cThreshold * cThreshold; 580*87bc88d3SHerbert Dürr const sal_uInt8 nWhitePalIdx = pWriteAcc->GetBestPaletteIndex( Color( COL_WHITE ) ); 581*87bc88d3SHerbert Dürr const sal_uInt8 nBlackPalIdx = pWriteAcc->GetBestPaletteIndex( Color( COL_BLACK ) ); 582cdf0e10cSrcweir long nSum1; 583cdf0e10cSrcweir long nSum2; 584cdf0e10cSrcweir long lGray; 585cdf0e10cSrcweir 586*87bc88d3SHerbert Dürr // initialize border with white pixels 587cdf0e10cSrcweir pWriteAcc->SetLineColor( Color( COL_WHITE) ); 588cdf0e10cSrcweir pWriteAcc->DrawLine( Point(), Point( nWidth - 1L, 0L ) ); 589cdf0e10cSrcweir pWriteAcc->DrawLine( Point( nWidth - 1L, 0L ), Point( nWidth - 1L, nHeight - 1L ) ); 590cdf0e10cSrcweir pWriteAcc->DrawLine( Point( nWidth - 1L, nHeight - 1L ), Point( 0L, nHeight - 1L ) ); 591cdf0e10cSrcweir pWriteAcc->DrawLine( Point( 0, nHeight - 1L ), Point() ); 592cdf0e10cSrcweir 593cdf0e10cSrcweir for( long nY = 0L, nY1 = 1L, nY2 = 2; nY < nHeight2; nY++, nY1++, nY2++ ) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir for( long nX = 0L, nXDst = 1L, nXTmp; nX < nWidth2; nX++, nXDst++ ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir nXTmp = nX; 598cdf0e10cSrcweir 599*87bc88d3SHerbert Dürr nSum1 = -( nSum2 = lGray = pReadAcc->GetPixelIndex( nY, nXTmp++ ) ); 600*87bc88d3SHerbert Dürr nSum2 += ( (long) pReadAcc->GetPixelIndex( nY, nXTmp++ ) ) << 1; 601*87bc88d3SHerbert Dürr nSum1 += ( lGray = pReadAcc->GetPixelIndex( nY, nXTmp ) ); 602cdf0e10cSrcweir nSum2 += lGray; 603cdf0e10cSrcweir 604*87bc88d3SHerbert Dürr nSum1 += ( (long) pReadAcc->GetPixelIndex( nY1, nXTmp ) ) << 1; 605*87bc88d3SHerbert Dürr nSum1 -= ( (long) pReadAcc->GetPixelIndex( nY1, nXTmp -= 2 ) ) << 1; 606cdf0e10cSrcweir 607*87bc88d3SHerbert Dürr nSum1 += ( lGray = -(long) pReadAcc->GetPixelIndex( nY2, nXTmp++ ) ); 608cdf0e10cSrcweir nSum2 += lGray; 609*87bc88d3SHerbert Dürr nSum2 -= ( (long) pReadAcc->GetPixelIndex( nY2, nXTmp++ ) ) << 1; 610*87bc88d3SHerbert Dürr nSum1 += ( lGray = (long) pReadAcc->GetPixelIndex( nY2, nXTmp ) ); 611cdf0e10cSrcweir nSum2 -= lGray; 612cdf0e10cSrcweir 613cdf0e10cSrcweir if( ( nSum1 * nSum1 + nSum2 * nSum2 ) < lThres2 ) 614*87bc88d3SHerbert Dürr pWriteAcc->SetPixelIndex( nY1, nXDst, nWhiteIdx ); 615cdf0e10cSrcweir else 616*87bc88d3SHerbert Dürr pWriteAcc->SetPixelIndex( nY1, nXDst, nBlackIdx ); 617cdf0e10cSrcweir } 618cdf0e10cSrcweir } 619cdf0e10cSrcweir 620cdf0e10cSrcweir bRet = sal_True; 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir aWorkBmp.ReleaseAccess( pReadAcc ); 624cdf0e10cSrcweir aDstBmp.ReleaseAccess( pWriteAcc ); 625cdf0e10cSrcweir 626cdf0e10cSrcweir if( bRet ) 627cdf0e10cSrcweir aRetBmp = aDstBmp; 628cdf0e10cSrcweir } 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir if( !aRetBmp ) 632cdf0e10cSrcweir aRetBmp = rBmp; 633cdf0e10cSrcweir else 634cdf0e10cSrcweir { 635cdf0e10cSrcweir aRetBmp.SetPrefMapMode( rBmp.GetPrefMapMode() ); 636cdf0e10cSrcweir aRetBmp.SetPrefSize( rBmp.GetPrefSize() ); 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir return aRetBmp; 640cdf0e10cSrcweir }; 641cdf0e10cSrcweir 642cdf0e10cSrcweir // ------------------------------------------------------------------------ 643cdf0e10cSrcweir 644cdf0e10cSrcweir Polygon XOutBitmap::GetCountour( const Bitmap& rBmp, const sal_uIntPtr nFlags, 645cdf0e10cSrcweir const sal_uInt8 cEdgeDetectThreshold, const Rectangle* pWorkRectPixel ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir Bitmap aWorkBmp; 648cdf0e10cSrcweir Polygon aRetPoly; 649cdf0e10cSrcweir Point aTmpPoint; 650cdf0e10cSrcweir Rectangle aWorkRect( aTmpPoint, rBmp.GetSizePixel() ); 651cdf0e10cSrcweir 652cdf0e10cSrcweir if( pWorkRectPixel ) 653cdf0e10cSrcweir aWorkRect.Intersection( *pWorkRectPixel ); 654cdf0e10cSrcweir 655cdf0e10cSrcweir aWorkRect.Justify(); 656cdf0e10cSrcweir 657cdf0e10cSrcweir if( ( aWorkRect.GetWidth() > 4 ) && ( aWorkRect.GetHeight() > 4 ) ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir // falls Flag gesetzt, muessen wir Kanten detektieren 660cdf0e10cSrcweir if( nFlags & XOUTBMP_CONTOUR_EDGEDETECT ) 661cdf0e10cSrcweir aWorkBmp = DetectEdges( rBmp, cEdgeDetectThreshold ); 662cdf0e10cSrcweir else 663cdf0e10cSrcweir aWorkBmp = rBmp; 664cdf0e10cSrcweir 665cdf0e10cSrcweir BitmapReadAccess* pAcc = aWorkBmp.AcquireReadAccess(); 666cdf0e10cSrcweir 667cdf0e10cSrcweir if( pAcc ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir const Size& rPrefSize = aWorkBmp.GetPrefSize(); 670cdf0e10cSrcweir const long nWidth = pAcc->Width(); 671cdf0e10cSrcweir const long nHeight = pAcc->Height(); 672cdf0e10cSrcweir const double fFactorX = (double) rPrefSize.Width() / nWidth; 673cdf0e10cSrcweir const double fFactorY = (double) rPrefSize.Height() / nHeight; 674cdf0e10cSrcweir const long nStartX1 = aWorkRect.Left() + 1L; 675cdf0e10cSrcweir const long nEndX1 = aWorkRect.Right(); 676cdf0e10cSrcweir const long nStartX2 = nEndX1 - 1L; 677cdf0e10cSrcweir // const long nEndX2 = nStartX1 - 1L; 678cdf0e10cSrcweir const long nStartY1 = aWorkRect.Top() + 1L; 679cdf0e10cSrcweir const long nEndY1 = aWorkRect.Bottom(); 680cdf0e10cSrcweir const long nStartY2 = nEndY1 - 1L; 681cdf0e10cSrcweir // const long nEndY2 = nStartY1 - 1L; 682cdf0e10cSrcweir Point* pPoints1 = NULL; 683cdf0e10cSrcweir Point* pPoints2 = NULL; 684cdf0e10cSrcweir long nX, nY; 685cdf0e10cSrcweir sal_uInt16 nPolyPos = 0; 686cdf0e10cSrcweir const BitmapColor aBlack = pAcc->GetBestMatchingColor( Color( COL_BLACK ) ); 687cdf0e10cSrcweir 688cdf0e10cSrcweir if( nFlags & XOUTBMP_CONTOUR_VERT ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir pPoints1 = new Point[ nWidth ]; 691cdf0e10cSrcweir pPoints2 = new Point[ nWidth ]; 692cdf0e10cSrcweir 693cdf0e10cSrcweir for( nX = nStartX1; nX < nEndX1; nX++ ) 694cdf0e10cSrcweir { 695cdf0e10cSrcweir nY = nStartY1; 696cdf0e10cSrcweir 697cdf0e10cSrcweir // zunaechst Zeile von Links nach Rechts durchlaufen 698cdf0e10cSrcweir while( nY < nEndY1 ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir if( aBlack == pAcc->GetPixel( nY, nX ) ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir pPoints1[ nPolyPos ] = Point( nX, nY ); 703cdf0e10cSrcweir nY = nStartY2; 704cdf0e10cSrcweir 705cdf0e10cSrcweir // diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist 706cdf0e10cSrcweir while( sal_True ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir if( aBlack == pAcc->GetPixel( nY, nX ) ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir pPoints2[ nPolyPos ] = Point( nX, nY ); 711cdf0e10cSrcweir break; 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir nY--; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717cdf0e10cSrcweir nPolyPos++; 718cdf0e10cSrcweir break; 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir nY++; 722cdf0e10cSrcweir } 723cdf0e10cSrcweir } 724cdf0e10cSrcweir } 725cdf0e10cSrcweir else 726cdf0e10cSrcweir { 727cdf0e10cSrcweir pPoints1 = new Point[ nHeight ]; 728cdf0e10cSrcweir pPoints2 = new Point[ nHeight ]; 729cdf0e10cSrcweir 730cdf0e10cSrcweir for ( nY = nStartY1; nY < nEndY1; nY++ ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir nX = nStartX1; 733cdf0e10cSrcweir 734cdf0e10cSrcweir // zunaechst Zeile von Links nach Rechts durchlaufen 735cdf0e10cSrcweir while( nX < nEndX1 ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir if( aBlack == pAcc->GetPixel( nY, nX ) ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir pPoints1[ nPolyPos ] = Point( nX, nY ); 740cdf0e10cSrcweir nX = nStartX2; 741cdf0e10cSrcweir 742cdf0e10cSrcweir // diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist 743cdf0e10cSrcweir while( sal_True ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir if( aBlack == pAcc->GetPixel( nY, nX ) ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir pPoints2[ nPolyPos ] = Point( nX, nY ); 748cdf0e10cSrcweir break; 749cdf0e10cSrcweir } 750cdf0e10cSrcweir 751cdf0e10cSrcweir nX--; 752cdf0e10cSrcweir } 753cdf0e10cSrcweir 754cdf0e10cSrcweir nPolyPos++; 755cdf0e10cSrcweir break; 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir nX++; 759cdf0e10cSrcweir } 760cdf0e10cSrcweir } 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763cdf0e10cSrcweir const sal_uInt16 nNewSize1 = nPolyPos << 1; 764cdf0e10cSrcweir 765cdf0e10cSrcweir aRetPoly = Polygon( nPolyPos, pPoints1 ); 766cdf0e10cSrcweir aRetPoly.SetSize( nNewSize1 + 1 ); 767cdf0e10cSrcweir aRetPoly[ nNewSize1 ] = aRetPoly[ 0 ]; 768cdf0e10cSrcweir 769cdf0e10cSrcweir for( sal_uInt16 j = nPolyPos; nPolyPos < nNewSize1; ) 770cdf0e10cSrcweir aRetPoly[ nPolyPos++ ] = pPoints2[ --j ]; 771cdf0e10cSrcweir 772cdf0e10cSrcweir if( ( fFactorX != 0. ) && ( fFactorY != 0. ) ) 773cdf0e10cSrcweir aRetPoly.Scale( fFactorX, fFactorY ); 774cdf0e10cSrcweir 775cdf0e10cSrcweir delete[] pPoints1; 776cdf0e10cSrcweir delete[] pPoints2; 777cdf0e10cSrcweir } 778cdf0e10cSrcweir } 779cdf0e10cSrcweir 780cdf0e10cSrcweir return aRetPoly; 781cdf0e10cSrcweir }; 782cdf0e10cSrcweir 783cdf0e10cSrcweir // ---------------- 784cdf0e10cSrcweir // - DitherBitmap - 785cdf0e10cSrcweir // ---------------- 786cdf0e10cSrcweir 787cdf0e10cSrcweir sal_Bool DitherBitmap( Bitmap& rBitmap ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir sal_Bool bRet = sal_False; 790cdf0e10cSrcweir 791cdf0e10cSrcweir if( ( rBitmap.GetBitCount() >= 8 ) && ( Application::GetDefaultDevice()->GetColorCount() < 257 ) ) 792cdf0e10cSrcweir bRet = rBitmap.Dither( BMP_DITHER_FLOYD ); 793cdf0e10cSrcweir else 794cdf0e10cSrcweir bRet = sal_False; 795cdf0e10cSrcweir 796cdf0e10cSrcweir return bRet; 797cdf0e10cSrcweir } 798