graphics/gdi/src/T_DataTypefaceStore.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataTypefaceStore
       
    23 */
       
    24 
       
    25 #include "T_DataTypefaceStore.h"
       
    26 
       
    27 /*@{*/
       
    28 ///	Parameters
       
    29 _LIT(KFont,											"font");
       
    30 _LIT(KFontDataObjectName,							"font_data_object_name");
       
    31 _LIT(KFontMaxHeight,								"font_max_height");
       
    32 _LIT(KTypefaceIndex,								"typeface_index");
       
    33 _LIT(KHeightIndex,									"height_index");
       
    34 _LIT(KTypefaces,									"typefaces");
       
    35 _LIT(KCheckHeightPositive,							"check_height_positive");
       
    36 
       
    37 ///	Commands
       
    38 _LIT(KCmdFontHeightInTwips,					 		"FontHeightInTwips");
       
    39 _LIT(KCmdGetNearestFontInTwips,						"GetNearestFontInTwips");
       
    40 _LIT(KCmdGetNearestFontToDesignHeightInTwips,		"GetNearestFontToDesignHeightInTwips");
       
    41 _LIT(KCmdGetNearestFontToMaxHeightInTwips,			"GetNearestFontToMaxHeightInTwips");
       
    42 _LIT(KCmdNumTypefaces, 			 					"NumTypefaces");
       
    43 _LIT(KCmdReleaseFont,								"ReleaseFont");
       
    44 _LIT(KCmdTypefaceSupport,				 			"TypefaceSupport");
       
    45 
       
    46 ///	Logging
       
    47 _LIT(KLogError,										"Error=%d");
       
    48 _LIT(KLogMissingParameter,							"Missing parameter '%S'");
       
    49 /*@}*/
       
    50 
       
    51 /**
       
    52 * Constructor. First phase construction
       
    53 */
       
    54 CT_DataTypefaceStore::CT_DataTypefaceStore()
       
    55 :	CDataWrapperBase()
       
    56 	{
       
    57 	}
       
    58 
       
    59 
       
    60 /**
       
    61 * Process a command read from the ini file
       
    62 *
       
    63 * @param aDataWrapper	test step requiring command to be processed
       
    64 * @param aCommand	the command to process
       
    65 * @param aSection		the entry in the ini file requiring the command to be processed
       
    66 *
       
    67 * @return ETrue if the command is processed
       
    68 */
       
    69 TBool CT_DataTypefaceStore::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
    70 	{
       
    71 	TBool retVal = ETrue;
       
    72 
       
    73 	if (aCommand == KCmdGetNearestFontInTwips)
       
    74 		{
       
    75 		DoCmdGetNearestFontInTwipsL(aSection);
       
    76 		}
       
    77 	else if (aCommand == KCmdGetNearestFontToMaxHeightInTwips)
       
    78 		{
       
    79 		DoCmdGetNearestFontToMaxHeightInTwipsL(aSection);
       
    80 		}
       
    81 	else if (aCommand == KCmdNumTypefaces)
       
    82 		{
       
    83 		DoCmdNumTypefaces(aSection);
       
    84 		}
       
    85 	else if (aCommand == KCmdTypefaceSupport)
       
    86 		{
       
    87 		DoCmdTypefaceSupport(aSection);
       
    88 		}
       
    89 	else if (aCommand == KCmdFontHeightInTwips)
       
    90 		{
       
    91 		DoCmdFontHeightInTwips(aSection);
       
    92 		}
       
    93 	else if (aCommand == KCmdGetNearestFontToDesignHeightInTwips)
       
    94 		{
       
    95 		DoCmdGetNearestFontToDesignHeightInTwipsL(aSection);
       
    96 		}
       
    97 	else if (aCommand == KCmdReleaseFont)
       
    98 		{
       
    99 		DoCmdReleaseFontL(aSection);
       
   100 		}
       
   101 	else
       
   102 		{
       
   103 		retVal = EFalse;
       
   104 		}
       
   105 
       
   106 	return retVal;
       
   107 	}
       
   108 
       
   109 
       
   110 ////////////////// COMMANDS IMPLEMENTATION  ////////////////////////
       
   111 
       
   112 
       
   113 /** Call CTypefaceStore::GetNearestFontInTwips() */
       
   114 void CT_DataTypefaceStore::DoCmdGetNearestFontInTwipsL(const TDesC& aSection)
       
   115 	{
       
   116 	INFO_PRINTF1(_L("Call CTypefaceStore::GetNearestFontInTwips()"));
       
   117 
       
   118 	TFontSpec	fontSpec;
       
   119 	if ( !GetFontSpecFromConfig(aSection, KFont, fontSpec) )
       
   120 		{
       
   121 		ERR_PRINTF2(KLogMissingParameter, &KFont());
       
   122 		SetBlockResult(EFail);
       
   123 		}
       
   124 	else
       
   125 		{
       
   126 		// call CTypefaceStore::GetNearestFontInTwips()
       
   127 		CFont*		font = NULL;
       
   128 		TInt		err = GetTypefaceStore()->GetNearestFontInTwips(font, fontSpec);
       
   129 
       
   130 		// check error code
       
   131 		if (err != KErrNone)
       
   132 			{
       
   133 			ERR_PRINTF2(KLogError, err);
       
   134 			SetError(err);
       
   135 			}
       
   136 		else
       
   137 			{
       
   138 			// set font data object of provided
       
   139 			SetFontDataObjectIfPassedAsParameterL(font, aSection);
       
   140 			}
       
   141 		}
       
   142 	}
       
   143 
       
   144 
       
   145 /** Call CTypefaceStore::GetNearestFontToDesignHeightInTwips() */
       
   146 void CT_DataTypefaceStore::DoCmdGetNearestFontToDesignHeightInTwipsL(const TDesC& aSection)
       
   147 	{
       
   148 	INFO_PRINTF1(_L("Call CTypefaceStore::GetNearestFontToDesignHeightInTwips()"));
       
   149 
       
   150 	TFontSpec	fontSpec;
       
   151 	if ( !GetFontSpecFromConfig(aSection, KFont, fontSpec) )
       
   152 		{
       
   153 		ERR_PRINTF2(KLogMissingParameter, &KFont());
       
   154 		SetBlockResult(EFail);
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		// call CTypefaceStore::GetNearestFontToDesignHeightInTwips()
       
   159 		CFont*		font = NULL;
       
   160 		TInt		err = GetTypefaceStore()->GetNearestFontToDesignHeightInTwips(font, fontSpec);
       
   161 
       
   162 		// check error code
       
   163 		if (err != KErrNone)
       
   164 			{
       
   165 			ERR_PRINTF2(KLogError, err);
       
   166 			SetError(err);
       
   167 			}
       
   168 		else
       
   169 			{
       
   170 			// set font data object of provided
       
   171 			SetFontDataObjectIfPassedAsParameterL(font, aSection);
       
   172 			}
       
   173 		}
       
   174 	}
       
   175 
       
   176 
       
   177 /** Call CTypefaceStore::GetNearestFontToMaxHeightInTwips() */
       
   178 void CT_DataTypefaceStore::DoCmdGetNearestFontToMaxHeightInTwipsL(const TDesC& aSection)
       
   179 	{
       
   180 	INFO_PRINTF1(_L("Call CTypefaceStore::GetNearestFontToMaxHeightInTwips()"));
       
   181 
       
   182 	TBool		dataOk=ETrue;
       
   183 
       
   184 	TFontSpec	fontSpec;
       
   185 	if ( !GetFontSpecFromConfig(aSection, KFont, fontSpec) )
       
   186 		{
       
   187 		dataOk=EFalse;
       
   188 		ERR_PRINTF2(KLogMissingParameter, &KFont());
       
   189 		SetBlockResult(EFail);
       
   190 		}
       
   191 
       
   192 	// get font maximum height from parameters
       
   193 	TInt	fontMaxHeight;
       
   194 	if(!GetIntFromConfig(aSection, KFontMaxHeight(), fontMaxHeight))
       
   195 		{
       
   196 		dataOk=EFalse;
       
   197 		ERR_PRINTF2(KLogMissingParameter, &KFontMaxHeight());
       
   198 		SetBlockResult(EFail);
       
   199 		}
       
   200 
       
   201 	if ( dataOk )
       
   202 		{
       
   203 		// call CTypefaceStore::GetNearestFontToMaxHeightInTwips()
       
   204 		CFont*		font = NULL;
       
   205 		TInt		err = GetTypefaceStore()->GetNearestFontToMaxHeightInTwips(font, fontSpec, fontMaxHeight);
       
   206 
       
   207 		// check error code
       
   208 		if (err != KErrNone)
       
   209 			{
       
   210 			ERR_PRINTF2(_L("Get nearest font to max height in twips error: %d"), err);
       
   211 			SetError(err);
       
   212 			}
       
   213 		else
       
   214 			{
       
   215 			// set font data object of provided
       
   216 			SetFontDataObjectIfPassedAsParameterL(font, aSection);
       
   217 
       
   218 			// check that the height of the returned font is not greater that the maximum specified
       
   219 			TFontSpec	fontSpecInTwips = font->FontSpecInTwips();
       
   220 			TInt		actualHeight = fontSpecInTwips.iHeight;
       
   221 			if (actualHeight > fontMaxHeight)
       
   222 				{
       
   223 				ERR_PRINTF3(_L("Font doesn't match in maximum specified, height: %d, maximum: %d"), actualHeight, fontMaxHeight);
       
   224 				SetBlockResult(EFail);
       
   225 				}
       
   226 			}
       
   227 		}
       
   228 	}
       
   229 
       
   230 
       
   231 /** Call CTypefaceStore::NumTypefaces() */
       
   232 void CT_DataTypefaceStore::DoCmdNumTypefaces(const TDesC& aSection)
       
   233 	{
       
   234 	TInt	actual=GetTypefaceStore()->NumTypefaces();
       
   235 	INFO_PRINTF2(_L("Call CTypefaceStore::NumTypefaces() %d"), actual);
       
   236 	TInt	expected;
       
   237 	if ( GetIntFromConfig(aSection, KTypefaces(), expected) )
       
   238 		{
       
   239 		if (  actual != expected )
       
   240 			{
       
   241 			ERR_PRINTF3(_L("Actual typfaces %d does not match expected %d"), actual, expected);
       
   242 			SetBlockResult(EFail);
       
   243 			}
       
   244 		}
       
   245 	}
       
   246 
       
   247 
       
   248 /** Call CTypefaceStore::TypefaceSupport() for the given index */
       
   249 void CT_DataTypefaceStore::DoCmdTypefaceSupport(const TDesC& aSection)
       
   250 	{
       
   251 	INFO_PRINTF1(_L("Call CTypefaceStore::TypefaceSupport() for the given index"));
       
   252 	// get typeface index from parameters
       
   253 	TInt	typefaceIndex;
       
   254 	if(!GetIntFromConfig(aSection, KTypefaceIndex(), typefaceIndex))
       
   255 		{
       
   256 		ERR_PRINTF2(_L("No %S"), &KTypefaceIndex());
       
   257 		SetBlockResult(EFail);
       
   258 		}
       
   259 	else
       
   260 		{
       
   261 		// call TypefaceSupport()
       
   262 		TTypefaceSupport	typefaceSupport;
       
   263 		GetTypefaceStore()->TypefaceSupport(typefaceSupport, typefaceIndex);
       
   264 		INFO_PRINTF2(_L("iIsScalable       %d"), typefaceSupport.iIsScalable);
       
   265 		INFO_PRINTF2(_L("iMaxHeightInTwips %d"), typefaceSupport.iMaxHeightInTwips);
       
   266 		INFO_PRINTF2(_L("iMinHeightInTwips %d"), typefaceSupport.iMinHeightInTwips);
       
   267 		INFO_PRINTF2(_L("iNumHeights       %d"), typefaceSupport.iNumHeights);
       
   268 		}
       
   269 	}
       
   270 
       
   271 
       
   272 /** Call CTypefaceStore::FontHeightInTwips() */
       
   273 void CT_DataTypefaceStore::DoCmdFontHeightInTwips(const TDesC& aSection)
       
   274 	{
       
   275 	INFO_PRINTF1(_L("Call CTypefaceStore::FontHeightInTwips()"));
       
   276 	TBool								dataOk=ETrue;
       
   277 
       
   278 	// get typeface index from parameters
       
   279 	TInt	typefaceIndex;
       
   280 	if(!GetIntFromConfig(aSection, KTypefaceIndex(), typefaceIndex))
       
   281 		{
       
   282 		ERR_PRINTF2(_L("No %S"), &KTypefaceIndex());
       
   283 		SetBlockResult(EFail);
       
   284 		dataOk=EFalse;
       
   285 		}
       
   286 
       
   287 	// get height index from parameters
       
   288 	TInt	heightIndex;
       
   289 	if(!GetIntFromConfig(aSection, KHeightIndex(), heightIndex))
       
   290 		{
       
   291 		ERR_PRINTF2(_L("No %S"), &KHeightIndex());
       
   292 		SetBlockResult(EFail);
       
   293 		dataOk=EFalse;
       
   294 		}
       
   295 
       
   296 	if ( dataOk )
       
   297 		{
       
   298 		TInt	typefaceHeight = GetTypefaceStore()->FontHeightInTwips(typefaceIndex, heightIndex);
       
   299 		INFO_PRINTF2(_L("Typeface height %d"), typefaceHeight);
       
   300 
       
   301 		// get positive height check flag from parameters
       
   302 		TBool	checkHeightPositive = EFalse;
       
   303 		GetBoolFromConfig(aSection, KCheckHeightPositive(), checkHeightPositive);
       
   304 
       
   305 		// check that typeface height is positive
       
   306 		if ( checkHeightPositive && (typefaceHeight<=0) )
       
   307 			{
       
   308 			ERR_PRINTF2(_L("Typeface height is not greater than 0, height: %d"), typefaceHeight);
       
   309 			SetBlockResult(EFail);
       
   310 			}
       
   311 		}
       
   312 	}
       
   313 
       
   314 
       
   315 /** CTypefaceStore::ReleaseFont() call */
       
   316 void CT_DataTypefaceStore::DoCmdReleaseFontL(const TDesC& aSection)
       
   317 	{
       
   318 	INFO_PRINTF1(_L("CTypefaceStore::ReleaseFont() call"));
       
   319 
       
   320 	CT_DataFont*	fontDataObject=GetFontDataObjectFromParameterL(KFontDataObjectName(), aSection);
       
   321 
       
   322 	if (fontDataObject == NULL)
       
   323 		{
       
   324 		ERR_PRINTF1(_L("Font data wrapper was not found"));
       
   325 		SetBlockResult(EFail);
       
   326 		}
       
   327 	else
       
   328 		{
       
   329 		GetTypefaceStore()->ReleaseFont(static_cast<CFont*>(fontDataObject->GetObject()));
       
   330 		}
       
   331 	}
       
   332 
       
   333 
       
   334 ///////////////////////////////// UTIL METHODS //////////////////////////////////////
       
   335 
       
   336 
       
   337 /**
       
   338 * Utility method that sets CT_DataFont with a new font if the name of the data object was passed as a parameter from INI-file.
       
   339 */
       
   340 void CT_DataTypefaceStore::SetFontDataObjectIfPassedAsParameterL(CFont* aFont, const TDesC& aSection)
       
   341 	{
       
   342 	// fetch data object
       
   343 	CT_DataFont*	fontDataObject = GetFontDataObjectFromParameterL(KFontDataObjectName(), aSection);
       
   344 	if ( fontDataObject != NULL )
       
   345 		{
       
   346 		// set obtained font for the data object
       
   347 		fontDataObject->SetObjectL(aFont);
       
   348 		}
       
   349 	}
       
   350 
       
   351 
       
   352 /**
       
   353 * Utility method that fetches CT_DataFont pointer by command parameter name from INI-file.
       
   354 */
       
   355 CT_DataFont* CT_DataTypefaceStore::GetFontDataObjectFromParameterL(const TDesC& aParameterName, const TDesC& aSection)
       
   356 	{
       
   357 	CT_DataFont*	ret = NULL;
       
   358 
       
   359 	// get FontData object from parameters
       
   360 	TPtrC	fontDataObjectName;
       
   361 	if ( GetStringFromConfig(aSection, aParameterName, fontDataObjectName) )
       
   362 		{
       
   363 		// check that the data object was found
       
   364 		ret = static_cast<CT_DataFont*>(GetDataWrapperL(fontDataObjectName));
       
   365 		}
       
   366 
       
   367 	return ret;
       
   368 	}