uifw/AvKon/src/AknFontIdLayoutFont.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Series 60 layout font constructed from a font id.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikdef.h>
       
    21 #include <eikenv.h>
       
    22 #include <aknenv.h>
       
    23 #include "AknFontIdLayoutFont.h"
       
    24 #include <AknFontSpecification.h>
       
    25 #include <CdlEngine.h>
       
    26 
       
    27 #include <AknFontProvider.h>
       
    28 #include <AknFontProviderSuppliedMetrics.h>
       
    29 #include <AknFontId.h>
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 EXPORT_C CAknFontIdLayoutFont* CAknFontIdLayoutFont::NewL( 
       
    36     CWsScreenDevice& aScreenDevice, 
       
    37     TInt aFontId )
       
    38     {
       
    39 	CAknFontIdLayoutFont* self = new (ELeave) CAknFontIdLayoutFont( aScreenDevice, aFontId);
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	CleanupStack::Pop(); //self
       
    43 	return self;
       
    44     }
       
    45 
       
    46 CAknFontIdLayoutFont::~CAknFontIdLayoutFont()
       
    47     {
       
    48     }
       
    49 
       
    50 void CAknFontIdLayoutFont::ConstructL()
       
    51     {
       
    52     CAknLayoutFont::Update();
       
    53     }
       
    54 
       
    55 /** 
       
    56 * Implementation of the framework method for this class
       
    57 *
       
    58 */
       
    59 CFbsFont* CAknFontIdLayoutFont::SupplyFont ()
       
    60     {
       
    61     TAknFontProviderSuppliedMetrics info;
       
    62     CFbsFont* font(0);
       
    63 
       
    64     // Need to check if CDL is initialized if the font is not encoded
       
    65     TInt fontId;
       
    66     if ( TAknFontId::IsEncodedFont(iFontId) || CdlEngine::IsCdlEngineCreated() )
       
    67         {
       
    68         fontId = iFontId;
       
    69         }
       
    70     else
       
    71         {
       
    72         // Fall-back in case of no initialization whatsoever. Use the special fontid for this purpose
       
    73         fontId = TAknFontId::FontIdForStartupNormalFont();
       
    74         }
       
    75 
       
    76     TAknFontSpecification spec( fontId );
       
    77     // Use Font provisioning;
       
    78     font = AknFontProvider::CreateFontFromMetrics( BitmapDevice(), fontId, spec, info, iFontProviderId );
       
    79     SetTextPaneHeight( spec.TextPaneHeight() );
       
    80 
       
    81     SetExcessAscent( info.ExcessAscent() );
       
    82     SetExcessDescent( info.ExcessDescent() );
       
    83     SetBottomShortfall( info.MaxDescentToTextPaneBottom() );
       
    84  
       
    85     return font;
       
    86     }
       
    87     
       
    88 TAknTextDecorationMetrics CAknFontIdLayoutFont::DoTextDecorationMetrics() const
       
    89     {
       
    90     return TAknTextDecorationMetrics( iFontId );
       
    91     }
       
    92 
       
    93 TAknFontSpecification CAknFontIdLayoutFont::DoFontSpecification() const
       
    94     {
       
    95     return TAknFontSpecification( iFontId );
       
    96     }
       
    97 
       
    98 EXPORT_C TInt CAknFontIdLayoutFont::FontId() const
       
    99     { return iFontId;}
       
   100 
       
   101 EXPORT_C void CAknFontIdLayoutFont::UpdateId( TInt aFontId )
       
   102     {
       
   103     iFontId = aFontId;
       
   104     Update();
       
   105     };
       
   106 
       
   107 TInt CAknFontIdLayoutFont::DoAscentForCharacter( TChar aCharacter ) const
       
   108     {
       
   109     TInt ascent = AscentInPixels();
       
   110 
       
   111     if ( AknFontProvider::HasBaselineCorrection( iFontProviderId ) )
       
   112         {
       
   113         TInt baselineLift;
       
   114         TInt denominatorIfFractional;
       
   115         TInt err = AknFontProvider::BaselineDeltaForCharacter( iFontProviderId, 
       
   116                                                      aCharacter, 
       
   117                                                      baselineLift, 
       
   118                                                      denominatorIfFractional );
       
   119         if ( err == KErrNone )
       
   120             {
       
   121             if ( denominatorIfFractional > 0)
       
   122                 {
       
   123                 ascent -= ( baselineLift * ascent ) / denominatorIfFractional;
       
   124                 }
       
   125             else
       
   126                 {
       
   127                 ascent -= baselineLift;
       
   128                 }
       
   129             }
       
   130         }
       
   131     return ascent;
       
   132     }
       
   133 
       
   134 /**
       
   135 * C++ Constructor.
       
   136 */
       
   137 CAknFontIdLayoutFont::CAknFontIdLayoutFont( CWsScreenDevice& aScreenDevice, TInt aFontId ) : 
       
   138     CAknLayoutFont(aScreenDevice), iFontId(aFontId)
       
   139     {}
       
   140 
       
   141 void CAknFontIdLayoutFont::Reserved_1()
       
   142     {}
       
   143 
       
   144 //  End of File
       
   145