fontsupport/fontutils/FontUtils/src/AknFontSpecification.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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:   Object representing a Series 60 font request
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <coemain.h>
       
    23 #include <AknLayout2DataDef.h>
       
    24 #include <cdlfont.cdl.h>
       
    25 #include <CdlRefs.h>
       
    26 
       
    27 #include "AknFontIdOffsets.hrh"
       
    28 #include "AknFontSpecification.h"
       
    29 #include "AknFontUtilsPanic.h"
       
    30 #include "AknFontId.h"
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 enum TAknFontSpecifiationBitIndex
       
    37     {
       
    38     EScalesInTwips = 0,
       
    39     ERequiresExactMatch,
       
    40     ETextPaneIsDesignHeight    
       
    41     };
       
    42     
       
    43 EXPORT_C TAknFontSpecification::TAknFontSpecification( TInt aFontId )
       
    44     {
       
    45 
       
    46     if( TAknFontId::IsEncodedFont(aFontId) )
       
    47         {
       
    48         iBaseFontCategory = TAknFontId::ExtractCategoryFromFontId(aFontId);
       
    49         iRequiredStyle.SetStrokeWeight(TAknFontId::ExtractWeightFromFontId(aFontId) == 0 ? EStrokeWeightNormal : EStrokeWeightBold);
       
    50         iRequiredStyle.SetPosture(TAknFontId::ExtractPostureFromFontId(aFontId) == 0 ? EPostureUpright : EPostureItalic);
       
    51         iRequiredStyle.SetEffects(FontEffect::EOutline, TAknFontId::ExtractOutlineFromFontId(aFontId) == 0 ? EFalse : ETrue);
       
    52         iTextPaneHeight = (TInt16)TAknFontId::ExtractHeightFromFontId(aFontId);
       
    53         }
       
    54     else
       
    55         {
       
    56         if (!CDL_Font::IsCustomisationStarted())
       
    57             {
       
    58             TRAPD( error, LoadAnyCDLFontInstanceL() );
       
    59             __ASSERT_ALWAYS( error == KErrNone, Panic(EAknPanicLayoutMissing) );
       
    60             }
       
    61         
       
    62         // process legacy and logical font ids
       
    63         if ( KHighestFixedLayoutFont < aFontId && aFontId <= KAknHighestLogicalFont )
       
    64             {
       
    65             TCdlArray<SLogicalIdMetricsIdPair> const& logicalidmaparray = CDL_Font::logicalIdMapArray();
       
    66             TInt nLogicals= logicalidmaparray.Count();
       
    67             for ( TInt index = 0; index < nLogicals; index++)
       
    68                 {
       
    69                 if ( aFontId == logicalidmaparray[index].iLogicalId )
       
    70                     {
       
    71                     aFontId = logicalidmaparray[index].iFontMetricsId;
       
    72                     break;
       
    73                     }
       
    74                 }
       
    75             }
       
    76 
       
    77         TCdlArray<SIdMetricsPair> const& metricsarray = CDL_Font::metricsArray();
       
    78 
       
    79         TInt nMetrics= metricsarray.Count();
       
    80         TInt foundIndex = KErrNotFound;
       
    81         for ( TInt index = 0; index < nMetrics; index++)
       
    82             {
       
    83             if ( aFontId == metricsarray[index].iFontId )
       
    84                 {
       
    85                 foundIndex = index;
       
    86                 break;
       
    87                 }
       
    88             }
       
    89             
       
    90         if ( foundIndex == KErrNotFound )
       
    91             {
       
    92             foundIndex = 0;
       
    93             }
       
    94 
       
    95         // Set the member data of the font specification
       
    96         iTextPaneHeight = metricsarray[foundIndex].iBodyHeight;
       
    97         iBaseFontCategory = (TAknFontCategory)metricsarray[foundIndex].iFontCategory;
       
    98         iRequiredStyle.SetStrokeWeight( metricsarray[foundIndex].iBold == 0 
       
    99             ? EStrokeWeightNormal : EStrokeWeightBold);
       
   100         iRequiredStyle.SetPosture( metricsarray[foundIndex].iItalic == 0 
       
   101             ? EPostureUpright : EPostureItalic );
       
   102         }
       
   103     }
       
   104 
       
   105 EXPORT_C TAknFontSpecification::TAknFontSpecification( TAknFontCategory aCategory, 
       
   106                                            const TFontSpec& aFontSpec, 
       
   107                                            const MGraphicsDeviceMap* aDeviceMap )
       
   108                                            :iBaseFontCategory( aCategory )
       
   109     {
       
   110     const MGraphicsDeviceMap* map;
       
   111     if ( aDeviceMap )
       
   112         map = aDeviceMap;
       
   113     else
       
   114         map =  CCoeEnv::Static()->ScreenDevice();
       
   115 
       
   116     // Use the map to get font height in pixels
       
   117     TPoint point(aFontSpec.iHeight, aFontSpec.iHeight);
       
   118     TPoint newPoint = map->TwipsToPixels(point);
       
   119     iTextPaneHeight = newPoint.iY;
       
   120     iRequiredStyle = aFontSpec.iFontStyle;
       
   121     }
       
   122 
       
   123 EXPORT_C TAknFontCategory TAknFontSpecification::FontCategory() const
       
   124     {
       
   125     return (TAknFontCategory)iBaseFontCategory;
       
   126     }
       
   127 
       
   128 EXPORT_C TInt TAknFontSpecification::TextPaneHeight() const
       
   129     {
       
   130     return iTextPaneHeight;
       
   131     }
       
   132 
       
   133 EXPORT_C TFontStrokeWeight TAknFontSpecification::Weight() const
       
   134     {
       
   135     return iRequiredStyle.StrokeWeight();
       
   136     }
       
   137 
       
   138 EXPORT_C TFontPosture TAknFontSpecification::Posture() const
       
   139     {
       
   140     return iRequiredStyle.Posture();
       
   141     }
       
   142 
       
   143 EXPORT_C TBool TAknFontSpecification::IsOutlineEffectOn() const
       
   144     {
       
   145     return iRequiredStyle.IsEffectOn(FontEffect::EOutline);
       
   146     }
       
   147 
       
   148 void TAknFontSpecification::LoadAnyCDLFontInstanceL()
       
   149     {
       
   150 	// find any instances that implement CDL_Font, and load the first one!
       
   151     // This stuff may leave so we should attempt to ensure CDL engine is started up already, avoiding
       
   152     // the requirement for this code
       
   153     CCdlRefCollection* refs = CdlEngine::FileContentsLC(KAknLayoutDllName);
       
   154     TInt count = refs->CountRefs();
       
   155 	for (TInt ii=0; ii<count; ii++)
       
   156 	    {
       
   157 		if (refs->Ref(ii).iUid == CDL_Font::KCdlInterfaceUid)
       
   158             {
       
   159 		    CDL_Font::LoadCustomisationL(refs->Ref(ii));
       
   160 			break;
       
   161 			}
       
   162 		}
       
   163 	CleanupStack::PopAndDestroy(refs);
       
   164 	}
       
   165 
       
   166 EXPORT_C void TAknFontSpecification::SetTextPaneHeight( TInt aNewHeight )
       
   167     {
       
   168     iTextPaneHeight = aNewHeight;
       
   169     }
       
   170     
       
   171 EXPORT_C void TAknFontSpecification::SetFontCategory( TAknFontCategory aCategory)
       
   172     {
       
   173     iBaseFontCategory = aCategory;
       
   174     }
       
   175     
       
   176 EXPORT_C void TAknFontSpecification::SetWeight( TFontStrokeWeight aWeight )
       
   177     {
       
   178     iRequiredStyle.SetStrokeWeight(aWeight);
       
   179     }
       
   180     
       
   181 EXPORT_C void TAknFontSpecification::SetPosture( TFontPosture aPosture )
       
   182     {
       
   183     iRequiredStyle.SetPosture(aPosture);
       
   184     }   
       
   185     
       
   186 EXPORT_C void TAknFontSpecification::SetTextPaneHeightIsDesignHeight( TBool aTextPaneHeightIsDesignHeight )
       
   187     {
       
   188     iFlags.Assign(ETextPaneIsDesignHeight, aTextPaneHeightIsDesignHeight);   
       
   189     }
       
   190     
       
   191 EXPORT_C void TAknFontSpecification::SetExactMatchRequired ( TBool aRequiresExactMatch )
       
   192     {
       
   193     iFlags.Assign(ERequiresExactMatch, aRequiresExactMatch);   
       
   194     }
       
   195 
       
   196 EXPORT_C void TAknFontSpecification::SetUnits ( TAknFontSpecificationUnits aUnits )
       
   197     {
       
   198     iFlags.Assign(EScalesInTwips, aUnits == TAknFontSpecification::ETwips );
       
   199     }
       
   200     
       
   201 EXPORT_C TBool TAknFontSpecification::ExactMatchRequired() const
       
   202     {
       
   203     return iFlags[ERequiresExactMatch];
       
   204     }
       
   205     
       
   206 EXPORT_C TBool TAknFontSpecification::TextPaneIsDesignHeight() const
       
   207     {
       
   208     return iFlags[ETextPaneIsDesignHeight];    
       
   209     }
       
   210     
       
   211 EXPORT_C TAknFontSpecification::TAknFontSpecificationUnits TAknFontSpecification::Units() const
       
   212     {
       
   213     TAknFontSpecification::TAknFontSpecificationUnits units(EPixels);   
       
   214     if ( iFlags[EScalesInTwips] )
       
   215         {
       
   216         units = TAknFontSpecification::ETwips;
       
   217         }
       
   218     return units;
       
   219     }
       
   220    
       
   221     
       
   222 //  End of File