svgtviewer/SvgtViewerPlugin/UIControlSrc/SVGTThumbnailUtil.cpp
branchRCL_3
changeset 20 5fd161fa28b6
parent 0 632761c941a7
equal deleted inserted replaced
17:e52958d06c29 20:5fd161fa28b6
       
     1 /*
       
     2 * Copyright (c) 2004,2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This file implements the SVGT Thumbnail functionality
       
    15 *                to display SVGT content
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <AknIconUtils.h>
       
    23 #include <e32def.h>
       
    24 #include <e32base.h>
       
    25 #include <eikenv.h>
       
    26 #include <fbs.h>
       
    27 #include <gdi.h>
       
    28 #include <bautils.h>
       
    29 #include <SVGEngineInterfaceImpl.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 
       
    32 // User Includes
       
    33 #include "SVGTUIControlDbgFlags.hrh"
       
    34 #include "SVGTThumbnailUtil.h"
       
    35 
       
    36 // Constants
       
    37 // General Constants
       
    38 const TInt KSccConstMinusOne = -1;
       
    39 const TInt KSccConstZero = 0;
       
    40 const TUint KSccBackground = 0xffffffff;
       
    41 
       
    42 
       
    43 // SMIL Fit Value
       
    44 _LIT( KSccSmilFitValue,"meet" );
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 // -----------------------------------------------------------------------------
       
    48 // CSVGTThumbnailUtil::GenerateThumbnailLD
       
    49 // Generate thumbnails for SVGT content.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C TBool CSVGTThumbnailUtil::GenerateThumbnailLD(
       
    53     RFile& aFileHandle,                 // Filehandle of SVGT
       
    54     CFbsBitmap& aThumbnailBitmap,       // Thumbnail Bitmap
       
    55     CFbsBitmap& aThumbnailBitmapMask )  // BitMap mask    
       
    56     {
       
    57     CSVGTThumbnailUtil *tnUtilPtr = CSVGTThumbnailUtil::NewLC( aFileHandle, 
       
    58             aThumbnailBitmap,
       
    59             aThumbnailBitmapMask );
       
    60     TBool retVal = tnUtilPtr->GenerateThumbnail();
       
    61     CleanupStack::PopAndDestroy( tnUtilPtr );
       
    62     return retVal;
       
    63     }
       
    64 
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSVGTThumbnailUtil::UpdateScreen
       
    69 // Implements MSvgRequestObserver::UpdateScreen.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CSVGTThumbnailUtil::UpdateScreen()
       
    73     {
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CSVGTThumbnailUtil::ScriptCall
       
    78 // Implements MSvgRequestObserver::ScriptCall.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TBool CSVGTThumbnailUtil::ScriptCall( const TDesC& /*aScript*/,
       
    82                                   CSvgElementImpl* /*aCallerElement*/ )
       
    83     {
       
    84     return EFalse;
       
    85     }
       
    86 
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSVGTThumbnailUtil::FetchImage
       
    90 // Implements MSvgRequestObserver::FetchImage. Calls the application call
       
    91 // back corresponding to this function if exists, else returns EFalse
       
    92 // indicating to the engine that the image was not retrieved.
       
    93 // -----------------------------------------------------------------------------
       
    94 //     
       
    95 TInt  CSVGTThumbnailUtil::FetchImage( const TDesC& /*aUri*/, 
       
    96              RFs& /*aSession*/, RFile& /*aFileHandle*/ )
       
    97     {
       
    98     return KErrNotFound;        
       
    99     }
       
   100 
       
   101 TInt CSVGTThumbnailUtil::FetchFont( const TDesC& /* aUri */, 
       
   102                                     RFs& /* aSession */, RFile& /* aFileHandle */ )
       
   103     {
       
   104     return KErrNotSupported;
       
   105     }
       
   106     
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSVGTThumbnailUtil:: GetSmilFitValue
       
   109 // Implements the MSvgRequestObserver::GetSmilFitValue.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CSVGTThumbnailUtil::GetSmilFitValue( TDes& aSmilValue )
       
   113     {
       
   114     aSmilValue.Copy( KSccSmilFitValue );
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSVGTThumbnailUtil::UpdatePresentation
       
   119 // Implements MSvgRequestObserver::UpdatePresentation.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void  CSVGTThumbnailUtil::UpdatePresentation( const TInt32&  
       
   123     /* aNoOfAnimation */ )
       
   124     {
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CSVGTThumbnailUtil::InitializeEngineL
       
   129 // Initiliazes the interface with the SVG engine.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CSVGTThumbnailUtil::InitializeEngineL()
       
   133     {
       
   134     if ( !iSvgModule )
       
   135        {
       
   136        TFontSpec spec;
       
   137 
       
   138        if ( !iSVGTBitMapDummy )
       
   139            {
       
   140            // For thumbnails, the user provided bitmap is used,
       
   141            // Have to give some dummy bitmap to the engine in the constructor.
       
   142            iSVGTBitMapDummy  = new( ELeave ) CFbsBitmap;
       
   143            User::LeaveIfError( iSVGTBitMapDummy->Create(
       
   144             TSize( KSccConstZero, KSccConstZero ), EGray2 ) );
       
   145            }
       
   146 
       
   147        iSvgModule = CSvgEngineInterfaceImpl::NewL( iSVGTBitMapDummy,
       
   148                this, spec );
       
   149        iSvgModule->SetBackgroundColor( KSccBackground );
       
   150        }
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSVGTThumbnailUtil::GenerateThumbnail
       
   155 // Helper function that generates Thumbnail for the SVG content.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 TBool CSVGTThumbnailUtil::GenerateThumbnail()
       
   159     {
       
   160     if ( iSvgModule )
       
   161         {
       
   162         MSvgError* result;
       
   163         result = iSvgModule->PrepareDom( iContentFileHandle, iThumbnailHandle );
       
   164 
       
   165         // NULL is returned, possible out of memory when create error object.
       
   166         if ( ( !result ) || ( result->HasError() ) )
       
   167             {
       
   168             return EFalse;
       
   169             }
       
   170 #ifdef SVGTUICONTROL_DBG_DRM_THUMBNAIL_API_ENABLE        
       
   171         // Set thumbnail mode On
       
   172         iSvgModule->SetThumbNailMode( ETrue );                          
       
   173 #endif // SVGTUICONTROL_DBG_DRM_THUMBNAIL_API_ENABLE
       
   174 
       
   175         // Setup the engine to use the DOM
       
   176         result = iSvgModule->UseDom( iThumbnailHandle, iThumbnailBitmap );
       
   177         if ( result->HasError() && !result->IsWarning() )
       
   178             {                
       
   179             return EFalse;
       
   180             }
       
   181 
       
   182         // View Box define for Dom associated frame
       
   183         iSvgModule->ChooseViewBoxIfNotSet(iThumbnailHandle);
       
   184         iSvgModule->InitializeEngine();
       
   185         iSvgModule->RenderFrame( NULL, 0);
       
   186 
       
   187         // Render the Mask Bitmap
       
   188         iSvgModule->GenerateMask( iThumbnailBitmapMask );
       
   189 #ifdef SVGTUICONTROL_DBG_DRM_THUMBNAIL_API_ENABLE        
       
   190         // Set thumbnail mode Off
       
   191         iSvgModule->SetThumbNailMode( EFalse );            
       
   192 #endif // SVGTUICONTROL_DBG_DRM_THUMBNAIL_API_ENABLE
       
   193 
       
   194         return ETrue;
       
   195         }
       
   196     else
       
   197         {
       
   198         return EFalse;
       
   199         }
       
   200         
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CSVGTThumbnailUtil::CSVGTThumbnailUtil
       
   205 // C++ default constructor.
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 CSVGTThumbnailUtil::CSVGTThumbnailUtil( RFile& aFileHandle ) : 
       
   209     // Thumbnail Variables
       
   210     iThumbnailHandle( KSccConstMinusOne ),
       
   211     iContentFileHandle( aFileHandle )
       
   212 {
       
   213 }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CSVGTThumbnailUtil::ConstructL
       
   217 // Symbian 2nd phase constructor.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CSVGTThumbnailUtil::ConstructL(
       
   221     CFbsBitmap& aThumbnailBitmap,     // Bitmap on which content is to be
       
   222                                       // rendered
       
   223     CFbsBitmap& aThumbnailBitmapMask )// Bitmap Mask
       
   224     {
       
   225     // Save the user parameters for later access.
       
   226     iSvgModule = NULL;
       
   227     iSVGTBitMapDummy = NULL;
       
   228     iThumbnailBitmap = &aThumbnailBitmap;
       
   229     iThumbnailBitmapMask = &aThumbnailBitmapMask;
       
   230     InitializeEngineL();
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CSVGTThumbnailUtil::NewL
       
   235 // Factory function for creating CSVGTThumbnailUtil objects for thumbnail
       
   236 // generation.
       
   237 // Returns: CSVGTThumbnailUtil* ; Pointer to the created object.
       
   238 //          Leaves if error occurs during creation.
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 CSVGTThumbnailUtil* CSVGTThumbnailUtil::NewL(
       
   242     RFile& aFileHandle,               // File handle of SVGT Content
       
   243     CFbsBitmap& aThumbnailBitmap,     // Bitmap on which content is to be
       
   244                                       // rendered
       
   245     CFbsBitmap& aThumbnailBitmapMask )// Bitmap Mask
       
   246     {
       
   247     CSVGTThumbnailUtil* self = CSVGTThumbnailUtil::NewLC( aFileHandle,
       
   248                                                       aThumbnailBitmap,
       
   249                                                       aThumbnailBitmapMask );
       
   250     CleanupStack::Pop( self );
       
   251     return self;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CSVGTThumbnailUtil::NewLC
       
   256 // Factory function for creating CSVGTThumbnailUtil objects for thumbnail
       
   257 // generation.
       
   258 // Returns: CSVGTThumbnailUtil* ; Pointer to the created object.
       
   259 //          Leaves if error occurs during creation.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 CSVGTThumbnailUtil* CSVGTThumbnailUtil::NewLC(
       
   263     RFile& aFileHandle,               // File Handle of SVGT Content
       
   264     CFbsBitmap& aThumbnailBitmap,     // Bitmap on which content is to be
       
   265                                       // rendered
       
   266     CFbsBitmap& aThumbnailBitmapMask) // Bitmap Mask
       
   267     {
       
   268     CSVGTThumbnailUtil* self = new ( ELeave ) CSVGTThumbnailUtil( 
       
   269         aFileHandle );
       
   270     CleanupStack::PushL( self );
       
   271     self->ConstructL( aThumbnailBitmap, aThumbnailBitmapMask );
       
   272     return self;
       
   273     }
       
   274 
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CSVGTThumbnailUtil::~CSVGTThumbnailUtil
       
   278 // Destructor
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 CSVGTThumbnailUtil::~CSVGTThumbnailUtil()
       
   282     {
       
   283     if ( iThumbnailHandle != KSccConstMinusOne )
       
   284         {
       
   285         if ( iSvgModule )
       
   286             {
       
   287             iSvgModule->DeleteDom( iThumbnailHandle );            
       
   288             }
       
   289         }
       
   290    
       
   291     // Dummy bitmap
       
   292     delete iSVGTBitMapDummy;
       
   293     
       
   294     // SVG Engine
       
   295     delete iSvgModule;
       
   296     
       
   297     // Reset the Thumbnail and Mask as this is owned by the caller
       
   298     iThumbnailBitmap = NULL;
       
   299     iThumbnailBitmapMask = NULL;
       
   300     }
       
   301 
       
   302 
       
   303 // End of File