messagingfw/msgcommonutils/src/MsgSvgUtils.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *           Miscellaneous SVG-T related utility methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ========== INCLUDE FILES ================================
       
    22 
       
    23 #include "MsgSvgUtils.h"
       
    24 
       
    25 #include <SVGEngineInterfaceImpl.h>
       
    26 
       
    27 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    28 
       
    29 
       
    30 // ========== MEMBER FUNCTIONS =============================
       
    31 
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CMsgSvgUtils::CMsgSvgUtils
       
    35 // 
       
    36 // C++ constructor.
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CMsgSvgUtils::CMsgSvgUtils()
       
    40     {
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CMsgSvgUtils::~CMsgSvgUtils
       
    45 // 
       
    46 // Destructor.
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 CMsgSvgUtils::~CMsgSvgUtils()
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CMsgSvgUtils::GenerateThumbnailL
       
    55 // 
       
    56 // Creates SVG-T engine instance and opens the given file handle
       
    57 // to it. Calculates the correctly "fitted" thumbnail size from
       
    58 // the given maximum size and either from SVG-T engine scaled size
       
    59 // or if this is not set then from original SVG-T file dimensions.
       
    60 // Finally renders the thumbnail frame to the bitmap & mask.
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 
       
    64 #ifdef RD_SVGT_IN_MESSAGING
       
    65 
       
    66 EXPORT_C void CMsgSvgUtils::GenerateThumbnailL( RFile& aFile, 
       
    67                                                 CFbsBitmap* aBitmap,
       
    68                                                 CFbsBitmap* aMask,
       
    69                                                 TBool aAutomaticDrmControl,
       
    70                                                 TSize& aContentSize )
       
    71     {
       
    72     TSize maxSize( aContentSize );
       
    73     
       
    74     TFontSpec spec;
       
    75     CSvgEngineInterfaceImpl* svgEngine = CSvgEngineInterfaceImpl::NewL( aBitmap, this, spec );
       
    76     CleanupStack::PushL( svgEngine );
       
    77     
       
    78     svgEngine->SetBackgroundColor( KRgbWhite.Value() );
       
    79     svgEngine->SetDRMRights( aAutomaticDrmControl );
       
    80     
       
    81     TInt domHandle( KNullHandle );
       
    82     MSvgError* result = svgEngine->PrepareDom( aFile, domHandle );
       
    83     
       
    84     HandleSVGEngineErrorL( result );
       
    85         
       
    86     result = svgEngine->UseDom( domHandle, aBitmap, aMask );
       
    87     
       
    88     HandleSVGEngineErrorL( result );
       
    89         
       
    90     aContentSize = svgEngine->Size();
       
    91     
       
    92     if ( aContentSize.iHeight <= 0 &&
       
    93          aContentSize.iWidth <= 0 )
       
    94         {
       
    95         // SVG engine might fail to set proper size so in that case
       
    96         // we use the original size.
       
    97         aContentSize = svgEngine->GetUnscaledContentSize( domHandle );
       
    98         }
       
    99     
       
   100     if ( aContentSize.iHeight > 0 &&
       
   101          aContentSize.iWidth > 0 )
       
   102         { 
       
   103         TReal widthRatio = static_cast<TReal>( maxSize.iWidth ) / 
       
   104                            static_cast<TReal>( aContentSize.iWidth );
       
   105         TReal heightRatio = static_cast<TReal>( maxSize.iHeight ) / 
       
   106                             static_cast<TReal>( aContentSize.iHeight );
       
   107         
       
   108         // Calculate "meet" ratio                    
       
   109         TReal scaleFactor = ( widthRatio < heightRatio ) ? widthRatio : heightRatio;
       
   110         
       
   111         aContentSize.iHeight *= scaleFactor;
       
   112         aContentSize.iWidth *= scaleFactor;
       
   113         
       
   114         svgEngine->SetSvgDimensionToFrameBuffer( aContentSize.iWidth, aContentSize.iHeight );
       
   115         
       
   116         // Chooses view box for SVG files where it has not bee set.
       
   117         svgEngine->ChooseViewBoxIfNotSet( domHandle );    
       
   118         svgEngine->InitializeEngine();
       
   119         
       
   120         // Render the content on consumer provided bitmap
       
   121         svgEngine->RenderFrame( NULL, 0 );
       
   122         }
       
   123     
       
   124     CleanupStack::PopAndDestroy( svgEngine );
       
   125     }
       
   126 
       
   127 #else
       
   128 
       
   129 EXPORT_C void CMsgSvgUtils::GenerateThumbnailL( RFile& /*aFile*/, 
       
   130                                                 CFbsBitmap* /*aBitmap*/,
       
   131                                                 CFbsBitmap* /*aMask*/,
       
   132                                                 TBool /*aAutomaticDrmControl*/,
       
   133                                                 TSize& /*aContentSize*/ )
       
   134     {
       
   135     User::Leave( KErrNotSupported );
       
   136     }
       
   137     
       
   138 #endif
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CMsgSvgUtils::UpdateScreen
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CMsgSvgUtils::UpdateScreen()
       
   146     {    
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CMsgSvgUtils::ScriptCall
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TBool CMsgSvgUtils::ScriptCall( const TDesC& /*aScript*/, CSvgElementImpl* /*aCallerElement*/ )
       
   155     {
       
   156     return EFalse;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMsgSvgUtils::FetchImage
       
   161 // (other items were commented in a header).
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 TInt CMsgSvgUtils::FetchImage( const TDesC& /*aUri*/, RFs& /*aSession*/, RFile& /*aFileHandle*/ )
       
   165     {
       
   166     return KErrNotFound;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMsgSvgUtils::FetchFont
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TInt CMsgSvgUtils::FetchFont( const TDesC& /*aUri*/, RFs& /*aSession*/, RFile& /*aFileHandle*/ )
       
   175     {
       
   176     return KErrNotFound;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CMsgSvgUtils::UpdatePresentation
       
   181 // (other items were commented in a header).
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CMsgSvgUtils::UpdatePresentation( const TInt32&  /*aNoOfAnimation*/ )
       
   185     {
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------
       
   189 // CMsgSvgUtils::HandleSVGEngineErrorL
       
   190 // 
       
   191 // Performs SVG-T engine error resolving.
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 void CMsgSvgUtils::HandleSVGEngineErrorL( MSvgError* aError ) const
       
   195     {
       
   196     if ( !aError )
       
   197         {
       
   198         User::Leave( KErrNoMemory ); 
       
   199         }
       
   200     else if ( aError->HasError() && !aError->IsWarning() )
       
   201         {
       
   202         User::Leave( aError->SystemErrorCode() ); 
       
   203         }
       
   204     }
       
   205 
       
   206 //  End of File