uifw/AvKon/src/AknLayoutFont.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:  A scaleable font with layout API
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <w32std.h>
       
    22 #include "AknLayoutFont.h"
       
    23 #include <AknFontSpecification.h>
       
    24 #include <aknenv.h>
       
    25 #include "AknFontRegistry.h"
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 /**
       
    32 * C++ Constructor.
       
    33 */
       
    34 CAknLayoutFont::CAknLayoutFont( CBitmapDevice& aScreenDevice ) : 
       
    35     CFbsFont(), iScreenDevice(aScreenDevice)
       
    36     {
       
    37     Register();
       
    38     }
       
    39 
       
    40 CAknLayoutFont::~CAknLayoutFont()
       
    41     {
       
    42     Deregister();
       
    43     iScreenDevice.ReleaseFont(iNonDynamicFont);
       
    44     }  
       
    45 
       
    46 
       
    47 EXPORT_C void CAknLayoutFont::Update()
       
    48     {
       
    49     CFbsFont* newNonDynamicFont = NULL;
       
    50 
       
    51     // Ask concrete type for a font
       
    52     TRAPD(err, newNonDynamicFont = SupplyFont());
       
    53 
       
    54     if (err == KErrNone)
       
    55         {
       
    56         // Release the old 'real' font ...
       
    57         iScreenDevice.ReleaseFont(iNonDynamicFont);
       
    58 
       
    59         // Copy this new font into the current object 
       
    60         iNonDynamicFont = newNonDynamicFont;
       
    61         (void) Duplicate( iNonDynamicFont->Handle() );
       
    62         }
       
    63     }
       
    64 
       
    65 EXPORT_C TInt CAknLayoutFont::MaxAscent() const
       
    66     {
       
    67     return iExcessAscent + AscentInPixels();
       
    68     }
       
    69 
       
    70 EXPORT_C TInt CAknLayoutFont::MaxDescent() const
       
    71     {
       
    72     return iExcessDescent + DescentInPixels();
       
    73     }
       
    74 
       
    75 EXPORT_C TInt CAknLayoutFont::TextPaneTopToBaseline() const
       
    76     {
       
    77     return iTextPaneHeight - BaselineToTextPaneBottom();
       
    78     }
       
    79 
       
    80 EXPORT_C TInt CAknLayoutFont::BaselineToTextPaneBottom() const
       
    81     {
       
    82     return ( iBottomShortfall + MaxDescent() );
       
    83     }
       
    84 
       
    85 EXPORT_C TInt CAknLayoutFont::TextPaneHeight() const
       
    86     {
       
    87     return iTextPaneHeight;
       
    88     }
       
    89 
       
    90 void CAknLayoutFont::SetExcessAscent( TInt aExcessAscent )
       
    91     {
       
    92     iExcessAscent = aExcessAscent;
       
    93     }
       
    94 
       
    95 void CAknLayoutFont::SetExcessDescent( TInt aExcessDescent )
       
    96     {
       
    97     iExcessDescent = aExcessDescent;
       
    98     }
       
    99 
       
   100 void CAknLayoutFont::SetBottomShortfall( TInt aBottomShortfall )
       
   101     {
       
   102     iBottomShortfall = aBottomShortfall;
       
   103     }
       
   104 
       
   105 void CAknLayoutFont::SetTextPaneHeight( TInt aTextPaneHeight )
       
   106     {
       
   107     iTextPaneHeight = aTextPaneHeight;
       
   108     }
       
   109 
       
   110 TInt CAknLayoutFont::AscentForCharacter( TChar aCharacter ) const
       
   111     {
       
   112     return DoAscentForCharacter( aCharacter );
       
   113     }
       
   114 
       
   115 TInt CAknLayoutFont::DoAscentForCharacter( TChar /*aCharacter*/ ) const
       
   116     {
       
   117     // Default implementation. 
       
   118     return AscentInPixels();
       
   119     }
       
   120 
       
   121 EXPORT_C const CAknLayoutFont* CAknLayoutFont::AsCAknLayoutFontOrNull( const CFont* aFont )
       
   122     {
       
   123     const CAknLayoutFont* layoutFontOrNull = NULL;
       
   124     if ( AVKONENV->FontRegistry().IsRegistered( aFont ) )
       
   125         {
       
   126         layoutFontOrNull = static_cast<const CAknLayoutFont*>( aFont );
       
   127         }
       
   128     return layoutFontOrNull;
       
   129     }
       
   130 
       
   131 EXPORT_C TAknTextDecorationMetrics CAknLayoutFont::TextDecorationMetrics() const
       
   132     {
       
   133     return DoTextDecorationMetrics();
       
   134     }
       
   135 
       
   136 EXPORT_C TAknFontSpecification CAknLayoutFont::FontSpecification() const
       
   137     {
       
   138     return DoFontSpecification();
       
   139     }
       
   140 
       
   141 void CAknLayoutFont::Register()
       
   142     {
       
   143     AVKONENV->FontRegistry().RegisterFont( this );
       
   144     }
       
   145 
       
   146 void CAknLayoutFont::Deregister()
       
   147     {
       
   148     AVKONENV->FontRegistry().DeRegisterFont( this );
       
   149     }
       
   150 
       
   151 void CAknLayoutFont::CAknLayoutFont_Reserved_1()
       
   152     {}
       
   153 
       
   154 EXPORT_C TAknFontCategory CAknLayoutFont::FontCategory() const
       
   155     {
       
   156     TAknFontSpecification spec = FontSpecification();
       
   157     return spec.FontCategory();
       
   158     }
       
   159     
       
   160 TFontSpec CAknLayoutFont::DoFontSpecInTwips() const
       
   161     {
       
   162     // Implementation should be (prior to the iHeight patching at the end):
       
   163     //    TFontSpec fontSpec = CFbsFont::DoFontSpecInTwips(); currently private
       
   164     // So for now, have copied implementation from CFbsFont:
       
   165     TFontSpec fontSpec;
       
   166     if (!iHandle)
       
   167         return fontSpec;
       
   168     fontSpec = Address()->FontSpecInTwips();    
       
   169     // Patch up the iHeight for the correct device's twips/pixel ratio
       
   170     fontSpec.iHeight = iScreenDevice.VerticalPixelsToTwips( HeightInPixels() );   
       
   171     return fontSpec;
       
   172     }
       
   173 
       
   174 CBitmapDevice& CAknLayoutFont::BitmapDevice() const
       
   175     {
       
   176     return iScreenDevice;
       
   177     }
       
   178 
       
   179 //  End of File
       
   180