LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/gallery2 - galobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 266 33.8 %
Date: 2013-07-09 Functions: 12 36 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      22             : #include <sfx2/objsh.hxx>
      23             : #include <sfx2/docfac.hxx>
      24             : #include <comphelper/classids.hxx>
      25             : #include <comphelper/string.hxx>
      26             : #include <unotools/pathoptions.hxx>
      27             : #include <tools/rcid.h>
      28             : #include <tools/vcompat.hxx>
      29             : #include <tools/helpers.hxx>
      30             : #include <vcl/virdev.hxx>
      31             : #include <svl/itempool.hxx>
      32             : #include <svx/fmmodel.hxx>
      33             : #include <svx/fmview.hxx>
      34             : #include <svx/fmpage.hxx>
      35             : #include "gallery.hrc"
      36             : #include "svx/galmisc.hxx"
      37             : #include "galobj.hxx"
      38             : #include <vcl/svapp.hxx>
      39             : #include <vcl/dibtools.hxx>
      40             : #include "gallerydrawmodel.hxx"
      41             : 
      42             : using namespace ::com::sun::star;
      43             : 
      44             : // -------------
      45             : // - SgaObject -
      46             : // -------------
      47             : 
      48         503 : SgaObject::SgaObject()
      49             : :   bIsValid    ( sal_False ),
      50         503 :     bIsThumbBmp ( sal_True )
      51             : {
      52         503 : }
      53             : 
      54           0 : BitmapEx SgaObject::createPreviewBitmapEx(const Size& rSizePixel) const
      55             : {
      56           0 :     BitmapEx aRetval;
      57             : 
      58           0 :     if(rSizePixel.Width() && rSizePixel.Height())
      59             :     {
      60           0 :         if(SGA_OBJ_SOUND == GetObjKind())
      61             :         {
      62           0 :             aRetval = GAL_RES(RID_SVXBMP_GALLERY_MEDIA);
      63             :         }
      64           0 :         else if(IsThumbBitmap())
      65             :         {
      66           0 :             aRetval = GetThumbBmp();
      67             :         }
      68             :         else
      69             :         {
      70           0 :             const Graphic aGraphic(GetThumbMtf());
      71             : 
      72           0 :             aRetval = aGraphic.GetBitmapEx();
      73             :         }
      74             : 
      75           0 :         if(!aRetval.IsEmpty())
      76             :         {
      77           0 :             const Size aCurrentSizePixel(aRetval.GetSizePixel());
      78           0 :             const double fScaleX((double)rSizePixel.Width() / (double)aCurrentSizePixel.Width());
      79           0 :             const double fScaleY((double)rSizePixel.Height() / (double)aCurrentSizePixel.Height());
      80           0 :             const double fScale(std::min(fScaleX, fScaleY));
      81             : 
      82             :             // only scale when need to decrease, no need to make bigger as original. Also
      83             :             // prevent scaling close to 1.0 which is not needed for pixel graphics
      84           0 :             if(fScale < 1.0 && fabs(1.0 - fScale) > 0.005)
      85             :             {
      86             :                 static sal_uInt32 nScaleFlag = BMP_SCALE_BESTQUALITY;
      87             : 
      88           0 :                 aRetval.Scale(fScale, fScale, nScaleFlag);
      89             :             }
      90             :         }
      91             :     }
      92             : 
      93           0 :     return aRetval;
      94             : }
      95             : 
      96             : // ------------------------------------------------------------------------
      97             : 
      98         468 : sal_Bool SgaObject::CreateThumb( const Graphic& rGraphic )
      99             : {
     100         468 :     sal_Bool bRet = sal_False;
     101             : 
     102         468 :     if( rGraphic.GetType() == GRAPHIC_BITMAP )
     103             :     {
     104         467 :         BitmapEx    aBmpEx( rGraphic.GetBitmapEx() );
     105         467 :         Size        aBmpSize( aBmpEx.GetSizePixel() );
     106             : 
     107         467 :         if( aBmpSize.Width() && aBmpSize.Height() )
     108             :         {
     109        1226 :             if( aBmpEx.GetPrefMapMode().GetMapUnit() != MAP_PIXEL &&
     110         759 :                 aBmpEx.GetPrefSize().Width() > 0 &&
     111         292 :                 aBmpEx.GetPrefSize().Height() > 0 )
     112             :             {
     113         292 :                 Size aLogSize( OutputDevice::LogicToLogic( aBmpEx.GetPrefSize(), aBmpEx.GetPrefMapMode(), MAP_100TH_MM ) );
     114             : 
     115         292 :                 if( aLogSize.Width() > 0 && aLogSize.Height() > 0 )
     116             :                 {
     117         292 :                     double  fFactorLog = static_cast< double >( aLogSize.Width() ) / aLogSize.Height();
     118         292 :                     double  fFactorPix = static_cast< double >( aBmpSize.Width() ) / aBmpSize.Height();
     119             : 
     120         292 :                     if( fFactorPix > fFactorLog )
     121         111 :                         aBmpSize.Width() = FRound( aBmpSize.Height() * fFactorLog );
     122             :                     else
     123         181 :                         aBmpSize.Height() = FRound( aBmpSize.Width() / fFactorLog );
     124             : 
     125         292 :                     aBmpEx.SetSizePixel( aBmpSize, BMP_SCALE_BESTQUALITY );
     126             :                 }
     127             :             }
     128             : 
     129             :             // take over BitmapEx
     130         467 :             aThumbBmp = aBmpEx;
     131             : 
     132         467 :             if( ( aBmpSize.Width() <= S_THUMB ) && ( aBmpSize.Height() <= S_THUMB ) )
     133             :             {
     134          13 :                 aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     135          13 :                 bRet = sal_True;
     136             :             }
     137             :             else
     138             :             {
     139         454 :                 const float fFactor  = (float) aBmpSize.Width() / aBmpSize.Height();
     140         908 :                 const Size  aNewSize( std::max( (long) (fFactor < 1. ? S_THUMB * fFactor : S_THUMB), 8L ),
     141        1362 :                                       std::max( (long) (fFactor < 1. ? S_THUMB : S_THUMB / fFactor), 8L ) );
     142         908 :                 if(aThumbBmp.Scale(
     143         454 :                     (double) aNewSize.Width() / aBmpSize.Width(),
     144         454 :                     (double) aNewSize.Height() / aBmpSize.Height(),
     145        1362 :                     BMP_SCALE_BESTQUALITY ) )
     146             :                 {
     147         454 :                     aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     148         454 :                     bRet = sal_True;
     149             :                 }
     150             :             }
     151         467 :         }
     152             :     }
     153           1 :     else if( rGraphic.GetType() == GRAPHIC_GDIMETAFILE )
     154             :     {
     155           1 :         const Size aPrefSize( rGraphic.GetPrefSize() );
     156           1 :         const double fFactor  = (double)aPrefSize.Width() / (double)aPrefSize.Height();
     157           1 :         Size aSize( S_THUMB, S_THUMB );
     158           1 :         if ( fFactor < 1.0 )
     159           0 :             aSize.Width() = (sal_Int32)( S_THUMB * fFactor );
     160             :         else
     161           1 :             aSize.Height() = (sal_Int32)( S_THUMB / fFactor );
     162             : 
     163           1 :         const GraphicConversionParameters aParameters(aSize, false, true, true /*TODO: extra ", true" post-#i121194#*/);
     164           1 :         aThumbBmp = rGraphic.GetBitmapEx(aParameters);
     165             : 
     166           1 :         if( !aThumbBmp.IsEmpty() )
     167             :         {
     168           1 :             aThumbBmp.Convert( BMP_CONVERSION_8BIT_COLORS );
     169           1 :             bRet = sal_True;
     170             :         }
     171             :     }
     172             : 
     173         468 :     return bRet;
     174             : }
     175             : 
     176             : // ------------------------------------------------------------------------
     177             : 
     178         503 : void SgaObject::WriteData( SvStream& rOut, const String& rDestDir ) const
     179             : {
     180             :     static const sal_uInt32 nInventor = COMPAT_FORMAT( 'S', 'G', 'A', '3' );
     181             : 
     182         503 :     rOut << nInventor << (sal_uInt16) 0x0004 << GetVersion() << (sal_uInt16) GetObjKind();
     183         503 :     rOut << bIsThumbBmp;
     184             : 
     185         503 :     if( bIsThumbBmp )
     186             :     {
     187         503 :         const sal_uInt16    nOldCompressMode = rOut.GetCompressMode();
     188         503 :         const sal_uIntPtr       nOldVersion = rOut.GetVersion();
     189             : 
     190         503 :         rOut.SetCompressMode( COMPRESSMODE_ZBITMAP );
     191         503 :         rOut.SetVersion( SOFFICE_FILEFORMAT_50 );
     192             : 
     193         503 :         WriteDIBBitmapEx(aThumbBmp, rOut);
     194             : 
     195         503 :         rOut.SetVersion( nOldVersion );
     196         503 :         rOut.SetCompressMode( nOldCompressMode );
     197             :     }
     198             :     else
     199           0 :         rOut << aThumbMtf;
     200             : 
     201         503 :     String aURLWithoutDestDir = String(aURL.GetMainURL( INetURLObject::NO_DECODE ));
     202         503 :     aURLWithoutDestDir.SearchAndReplace(rDestDir, String());
     203         503 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aURLWithoutDestDir, RTL_TEXTENCODING_UTF8);
     204         503 : }
     205             : 
     206             : // ------------------------------------------------------------------------
     207             : 
     208           0 : void SgaObject::ReadData(SvStream& rIn, sal_uInt16& rReadVersion )
     209             : {
     210             :     sal_uInt32      nTmp32;
     211             :     sal_uInt16      nTmp16;
     212             : 
     213           0 :     rIn >> nTmp32 >> nTmp16 >> rReadVersion >> nTmp16 >> bIsThumbBmp;
     214             : 
     215           0 :     if( bIsThumbBmp )
     216             :     {
     217           0 :         ReadDIBBitmapEx(aThumbBmp, rIn);
     218             :     }
     219             :     else
     220             :     {
     221           0 :         rIn >> aThumbMtf;
     222             :     }
     223             : 
     224           0 :     OUString aTmpStr = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     225           0 :     aURL = INetURLObject(aTmpStr);
     226           0 : }
     227             : 
     228             : // ------------------------------------------------------------------------
     229             : 
     230           0 : const String SgaObject::GetTitle() const
     231             : {
     232           0 :     String aReturnValue( aTitle );
     233           0 :     if ( !getenv( "GALLERY_SHOW_PRIVATE_TITLE" ) )
     234             :     {
     235           0 :         if ( comphelper::string::getTokenCount(aReturnValue, ':') == 3 )
     236             :         {
     237           0 :             String      aPrivateInd  ( aReturnValue.GetToken( 0, ':' ) );
     238           0 :             String      aResourceName( aReturnValue.GetToken( 1, ':' ) );
     239           0 :             sal_Int32   nResId       ( aReturnValue.GetToken( 2, ':' ).ToInt32() );
     240           0 :             if ( aPrivateInd.EqualsAscii( "private" ) &&
     241           0 :                 aResourceName.Len() && ( nResId > 0 ) && ( nResId < 0x10000 ) )
     242             :             {
     243           0 :                 OString aMgrName(OUStringToOString(aResourceName, RTL_TEXTENCODING_UTF8));
     244             :                 ResMgr* pResMgr = ResMgr::CreateResMgr( aMgrName.getStr(),
     245           0 :                             Application::GetSettings().GetUILanguageTag() );
     246           0 :                 if ( pResMgr )
     247             :                 {
     248           0 :                     ResId aResId( (sal_uInt16)nResId, *pResMgr );
     249           0 :                     aResId.SetRT( RSC_STRING );
     250           0 :                     if ( pResMgr->IsAvailable( aResId ) )
     251             :                     {
     252           0 :                         aReturnValue = aResId.toString();
     253             :                     }
     254           0 :                     delete pResMgr;
     255           0 :                 }
     256           0 :             }
     257             :         }
     258             :     }
     259           0 :     return aReturnValue;
     260             : }
     261             : 
     262             : // ------------------------------------------------------------------------
     263             : 
     264           0 : void SgaObject::SetTitle( const String& rTitle )
     265             : {
     266           0 :     aTitle = rTitle;
     267           0 : }
     268             : 
     269             : // ------------------------------------------------------------------------
     270             : 
     271           0 : SvStream& operator<<( SvStream& rOut, const SgaObject& rObj )
     272             : {
     273           0 :     rObj.WriteData( rOut, String() );
     274           0 :     return rOut;
     275             : }
     276             : 
     277             : // ------------------------------------------------------------------------
     278             : 
     279           0 : SvStream& operator>>( SvStream& rIn, SgaObject& rObj )
     280             : {
     281             :     sal_uInt16 nReadVersion;
     282             : 
     283           0 :     rObj.ReadData( rIn, nReadVersion );
     284           0 :     rObj.bIsValid = ( rIn.GetError() == ERRCODE_NONE );
     285             : 
     286           0 :     return rIn;
     287             : }
     288             : 
     289             : // ----------------
     290             : // - SgaObjectBmp -
     291             : // ----------------
     292             : 
     293           0 : SgaObjectBmp::SgaObjectBmp()
     294             : {
     295           0 : }
     296             : 
     297             : // ------------------------------------------------------------------------
     298             : 
     299           0 : SgaObjectBmp::SgaObjectBmp( const INetURLObject& rURL )
     300             : {
     301           0 :     Graphic aGraphic;
     302           0 :     String  aFilter;
     303             : 
     304           0 :     if ( SGA_IMPORT_NONE != GalleryGraphicImport( rURL, aGraphic, aFilter ) )
     305           0 :         Init( aGraphic, rURL );
     306           0 : }
     307             : 
     308             : // ------------------------------------------------------------------------
     309             : 
     310         468 : SgaObjectBmp::SgaObjectBmp( const Graphic& rGraphic, const INetURLObject& rURL, const String& )
     311             : {
     312         468 :     if( FileExists( rURL ) )
     313         468 :         Init( rGraphic, rURL );
     314         468 : }
     315             : 
     316             : // ------------------------------------------------------------------------
     317             : 
     318         468 : void SgaObjectBmp::Init( const Graphic& rGraphic, const INetURLObject& rURL )
     319             : {
     320         468 :     aURL = rURL;
     321         468 :     bIsValid = CreateThumb( rGraphic );
     322         468 : }
     323             : 
     324             : // ------------------------------------------------------------------------
     325             : 
     326         468 : void SgaObjectBmp::WriteData( SvStream& rOut, const String& rDestDir ) const
     327             : {
     328             :     // Version setzen
     329         468 :     SgaObject::WriteData( rOut, rDestDir );
     330             :     char aDummy[ 10 ];
     331         468 :     rOut.Write( aDummy, 10 );
     332         468 :     write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rOut, OString()); //dummy
     333         468 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     334         468 : }
     335             : 
     336             : // ------------------------------------------------------------------------
     337             : 
     338           0 : void SgaObjectBmp::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     339             : {
     340             : 
     341           0 :     SgaObject::ReadData( rIn, rReadVersion );
     342           0 :     rIn.SeekRel( 10 ); // 16, 16, 32, 16
     343           0 :     read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIn); //dummy
     344             : 
     345           0 :     if( rReadVersion >= 5 )
     346           0 :         aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     347           0 : }
     348             : 
     349             : // ------------------
     350             : // - SgaObjectSound -
     351             : // ------------------
     352             : DBG_NAME(SgaObjectSound)
     353             : 
     354           0 : SgaObjectSound::SgaObjectSound() :
     355           0 :     eSoundType( SOUND_STANDARD )
     356             : {
     357             :     DBG_CTOR(SgaObjectSound,NULL);
     358           0 : }
     359             : 
     360             : // ------------------------------------------------------------------------
     361             : 
     362          35 : SgaObjectSound::SgaObjectSound( const INetURLObject& rURL ) :
     363          35 :     eSoundType( SOUND_STANDARD )
     364             : {
     365             :     DBG_CTOR(SgaObjectSound,NULL);
     366             : 
     367          35 :     if( FileExists( rURL ) )
     368             :     {
     369          35 :         aURL = rURL;
     370          35 :         aThumbBmp = Bitmap( Size( 1, 1 ), 1 );
     371          35 :         bIsValid = sal_True;
     372             :     }
     373             :     else
     374           0 :         bIsValid = sal_False;
     375          35 : }
     376             : 
     377             : // ------------------------------------------------------------------------
     378             : 
     379          70 : SgaObjectSound::~SgaObjectSound()
     380             : {
     381             :     DBG_DTOR(SgaObjectSound,NULL);
     382          70 : }
     383             : 
     384             : // ------------------------------------------------------------------------
     385             : 
     386           0 : BitmapEx SgaObjectSound::GetThumbBmp() const
     387             : {
     388             :     sal_uInt16 nId;
     389             : 
     390           0 :     switch( eSoundType )
     391             :     {
     392           0 :         case( SOUND_COMPUTER ): nId = RID_SVXBMP_GALLERY_SOUND_1; break;
     393           0 :         case( SOUND_MISC ): nId = RID_SVXBMP_GALLERY_SOUND_2; break;
     394           0 :         case( SOUND_MUSIC ): nId = RID_SVXBMP_GALLERY_SOUND_3; break;
     395           0 :         case( SOUND_NATURE ): nId = RID_SVXBMP_GALLERY_SOUND_4; break;
     396           0 :         case( SOUND_SPEECH ): nId = RID_SVXBMP_GALLERY_SOUND_5; break;
     397           0 :         case( SOUND_TECHNIC ): nId = RID_SVXBMP_GALLERY_SOUND_6; break;
     398           0 :         case( SOUND_ANIMAL ): nId = RID_SVXBMP_GALLERY_SOUND_7; break;
     399             : 
     400             :         // standard
     401             :         default:
     402           0 :              nId = RID_SVXBMP_GALLERY_MEDIA;
     403           0 :         break;
     404             :     }
     405             : 
     406           0 :     const BitmapEx  aBmpEx( GAL_RES( nId ) );
     407             : 
     408           0 :     return aBmpEx;
     409             : }
     410             : 
     411             : // ------------------------------------------------------------------------
     412             : 
     413          35 : void SgaObjectSound::WriteData( SvStream& rOut, const String& rDestDir ) const
     414             : {
     415          35 :     SgaObject::WriteData( rOut, rDestDir );
     416          35 :     rOut << (sal_uInt16) eSoundType;
     417          35 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     418          35 : }
     419             : 
     420             : // ------------------------------------------------------------------------
     421             : 
     422           0 : void SgaObjectSound::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     423             : {
     424           0 :     SgaObject::ReadData( rIn, rReadVersion );
     425             : 
     426           0 :     if( rReadVersion >= 5 )
     427             :     {
     428             :         sal_uInt16      nTmp16;
     429             : 
     430           0 :         rIn >> nTmp16; eSoundType = (GalSoundType) nTmp16;
     431             : 
     432           0 :         if( rReadVersion >= 6 )
     433           0 :             aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     434             :     }
     435           0 : }
     436             : 
     437             : // -----------------
     438             : // - SgaObjectAnim -
     439             : // -----------------
     440             : 
     441           0 : SgaObjectAnim::SgaObjectAnim()
     442             : {
     443           0 : }
     444             : 
     445             : // ------------------------------------------------------------------------
     446             : 
     447           0 : SgaObjectAnim::SgaObjectAnim( const Graphic& rGraphic,
     448             :                               const INetURLObject& rURL,
     449           0 :                               const String& )
     450             : {
     451           0 :     aURL = rURL;
     452           0 :     bIsValid = CreateThumb( rGraphic );
     453           0 : }
     454             : 
     455             : // -----------------
     456             : // - SgaObjectINet -
     457             : // -----------------
     458             : 
     459           0 : SgaObjectINet::SgaObjectINet()
     460             : {
     461           0 : }
     462             : 
     463             : // ------------------------------------------------------------------------
     464             : 
     465           0 : SgaObjectINet::SgaObjectINet( const Graphic& rGraphic, const INetURLObject& rURL, const String& rFormatName ) :
     466           0 :             SgaObjectAnim   ( rGraphic, rURL, rFormatName )
     467             : {
     468           0 : }
     469             : 
     470             : // -------------------
     471             : // - SgaObjectSvDraw -
     472             : // -------------------
     473             : 
     474           0 : SgaObjectSvDraw::SgaObjectSvDraw()
     475             : {
     476           0 : }
     477             : 
     478             : // ------------------------------------------------------------------------
     479             : 
     480           0 : SgaObjectSvDraw::SgaObjectSvDraw( const FmFormModel& rModel, const INetURLObject& rURL )
     481             : {
     482           0 :     aURL = rURL;
     483           0 :     bIsValid = CreateThumb( rModel );
     484           0 : }
     485             : 
     486             : // ------------------------------------------------------------------------
     487             : DBG_NAME(SvxGalleryDrawModel)
     488             : 
     489           0 : SvxGalleryDrawModel::SvxGalleryDrawModel()
     490           0 : : mpFormModel( 0 )
     491             : {
     492             :     DBG_CTOR(SvxGalleryDrawModel,NULL);
     493             : 
     494           0 :     const String sFactoryURL(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
     495             : 
     496           0 :     mxDoc = SfxObjectShell::CreateObjectByFactoryName( sFactoryURL );
     497             : 
     498           0 :     if( mxDoc.Is() )
     499             :     {
     500           0 :         mxDoc->DoInitNew(0);
     501             : 
     502           0 :         uno::Reference< lang::XUnoTunnel > xTunnel( mxDoc->GetModel(), uno::UNO_QUERY );
     503           0 :         if( xTunnel.is() )
     504             :         {
     505             :             mpFormModel = dynamic_cast< FmFormModel* >(
     506           0 :                 reinterpret_cast<SdrModel*>(xTunnel->getSomething(SdrModel::getUnoTunnelImplementationId())));
     507           0 :             if( mpFormModel )
     508             :             {
     509           0 :                 mpFormModel->InsertPage( mpFormModel->AllocPage( false ) );
     510             :             }
     511           0 :         }
     512           0 :     }
     513           0 : }
     514             : 
     515             : // ------------------------------------------------------------------------
     516             : 
     517           0 : SvxGalleryDrawModel::~SvxGalleryDrawModel()
     518             : {
     519           0 :     if( mxDoc.Is() )
     520           0 :         mxDoc->DoClose();
     521             : 
     522             :     DBG_DTOR(SvxGalleryDrawModel,NULL);
     523           0 : }
     524             : 
     525             : // ------------------------------------------------------------------------
     526             : 
     527           0 : SgaObjectSvDraw::SgaObjectSvDraw( SvStream& rIStm, const INetURLObject& rURL )
     528             : {
     529           0 :     SvxGalleryDrawModel aModel;
     530             : 
     531           0 :     if( aModel.GetModel() )
     532             :     {
     533           0 :         if( GallerySvDrawImport( rIStm, *aModel.GetModel()  ) )
     534             :         {
     535           0 :             aURL = rURL;
     536           0 :             bIsValid = CreateThumb( *aModel.GetModel()  );
     537             :         }
     538           0 :     }
     539           0 : }
     540             : 
     541             : // ------------------------------------------------------------------------
     542             : 
     543           0 : sal_Bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel )
     544             : {
     545           0 :     Graphic     aGraphic;
     546           0 :     ImageMap    aImageMap;
     547           0 :     sal_Bool        bRet = sal_False;
     548             : 
     549           0 :     if ( CreateIMapGraphic( rModel, aGraphic, aImageMap ) )
     550             :     {
     551           0 :         bRet = SgaObject::CreateThumb( aGraphic );
     552             :     }
     553             :     else
     554             :     {
     555           0 :         const FmFormPage* pPage = static_cast< const FmFormPage* >(rModel.GetPage(0));
     556             : 
     557           0 :         if(pPage)
     558             :         {
     559           0 :             const Rectangle aObjRect(pPage->GetAllObjBoundRect());
     560             : 
     561           0 :             if(aObjRect.GetWidth() && aObjRect.GetHeight())
     562             :             {
     563           0 :                 VirtualDevice aVDev;
     564           0 :                 FmFormView aView(const_cast< FmFormModel* >(&rModel), &aVDev);
     565             : 
     566           0 :                 aView.ShowSdrPage(const_cast< FmFormPage* >(pPage));
     567           0 :                 aView.MarkAllObj();
     568           0 :                 aThumbBmp = aView.GetMarkedObjBitmapEx();
     569             : 
     570           0 :                 const Size aDiscreteSize(aThumbBmp.GetSizePixel());
     571             : 
     572           0 :                 if(aDiscreteSize.Width() && aDiscreteSize.Height())
     573             :                 {
     574           0 :                     sal_uInt32 nTargetSizeX(S_THUMB);
     575           0 :                     sal_uInt32 nTargetSizeY(S_THUMB);
     576             : 
     577           0 :                     if(aDiscreteSize.Width() > aDiscreteSize.Height())
     578             :                     {
     579           0 :                         nTargetSizeY = (aDiscreteSize.Height() * nTargetSizeX) / aDiscreteSize.Width();
     580             :                     }
     581             :                     else
     582             :                     {
     583           0 :                         nTargetSizeX = (aDiscreteSize.Width() * nTargetSizeY) / aDiscreteSize.Height();
     584             :                     }
     585             : 
     586           0 :                     if(!!aThumbBmp)
     587             :                     {
     588           0 :                         aThumbBmp.Scale(Size(nTargetSizeX, nTargetSizeY), BMP_SCALE_BESTQUALITY);
     589           0 :                         aThumbBmp.Convert(BMP_CONVERSION_8BIT_COLORS);
     590           0 :                         bRet = true;
     591             :                     }
     592           0 :                 }
     593             :             }
     594             :         }
     595             :     }
     596             : 
     597           0 :     return bRet;
     598             : }
     599             : 
     600             : // ------------------------------------------------------------------------
     601             : 
     602           0 : void SgaObjectSvDraw::WriteData( SvStream& rOut, const String& rDestDir ) const
     603             : {
     604           0 :     SgaObject::WriteData( rOut, rDestDir );
     605           0 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOut, aTitle, RTL_TEXTENCODING_UTF8);
     606           0 : }
     607             : 
     608             : // ------------------------------------------------------------------------
     609             : 
     610           0 : void SgaObjectSvDraw::ReadData( SvStream& rIn, sal_uInt16& rReadVersion )
     611             : {
     612           0 :     SgaObject::ReadData( rIn, rReadVersion );
     613             : 
     614           0 :     if( rReadVersion >= 5 )
     615           0 :         aTitle = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rIn, RTL_TEXTENCODING_UTF8);
     616         258 : }
     617             : 
     618             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10