fbs/fontandbitmapserver/sfbs/TFSTORE.CPP
changeset 0 5d03bc08d59c
child 103 2717213c588a
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32hal.h>
       
    17 #include <fbs.h>
       
    18 #include "UTILS.H"
       
    19 #include <linkedfonts.h>
       
    20 #include "fbsmessage.h"
       
    21 
       
    22 GLREF_C void Panic(TFbsPanic aPanic);
       
    23 
       
    24 CFbsTypefaceStore::CFbsTypefaceStore(CGraphicsDevice* aDevice):
       
    25 	CTypefaceStore(),
       
    26 	iDevice(aDevice),
       
    27 	iTwipsCache(NULL)
       
    28 	{
       
    29 	}
       
    30 
       
    31 /** 
       
    32 @publishedAll 
       
    33 @released
       
    34 */
       
    35 EXPORT_C CFbsTypefaceStore::~CFbsTypefaceStore()
       
    36 	{
       
    37 	if(iTwipsCache)
       
    38 		{
       
    39 		ReleaseTwipsCache();
       
    40 		delete iTwipsCache;
       
    41 		}
       
    42 	}
       
    43 
       
    44 /** Allocates and constructs a CFbsTypefaceStore, specifying a graphics device.
       
    45 @param aDevice A pointer to a graphics device.
       
    46 @return A pointer to the newly created typeface store. 
       
    47 @publishedAll 
       
    48 @released
       
    49 */
       
    50 EXPORT_C CFbsTypefaceStore* CFbsTypefaceStore::NewL(CGraphicsDevice* aDevice)
       
    51 	{
       
    52 	CFbsTypefaceStore* thisptr=new(ELeave) CFbsTypefaceStore(aDevice);
       
    53 	CleanupStack::PushL(thisptr);
       
    54 	thisptr->ConstructL();
       
    55 	CleanupStack::Pop();
       
    56 	return(thisptr);
       
    57 	}
       
    58 
       
    59 
       
    60 void CFbsTypefaceStore::ConstructL()
       
    61 	{
       
    62 	// get the session info from the Tls
       
    63 	iFbs = RFbsSession::GetSession();
       
    64 	if (!iFbs)
       
    65 		{
       
    66 		User::Leave(KErrCouldNotConnect);
       
    67 		}
       
    68 	CTypefaceStore::ConstructL();
       
    69 	iTwipsCache = new(ELeave) CFontCache;
       
    70 	}
       
    71 
       
    72 
       
    73 /** Installs a font store file into the typeface store.
       
    74 All the fonts in added and installed font files are available to the
       
    75 GetNearestFont...() family of functions.
       
    76 Additionally Bitmap Fonts are also available to GetFontById().
       
    77 
       
    78 Installed files remain in the typeface store even after the client which added 
       
    79 them is destroyed. They can be removed using RemoveFile().
       
    80 @param aName The name of the file to be installed.
       
    81 @param aId On return, contains the id of the installed file.
       
    82 @return KErrNone if successful, otherwise another of the system-wide error 
       
    83 codes.
       
    84 @see AddFile()
       
    85 @see RemoveFile()
       
    86 @see GetFontById()
       
    87 @see GetNearestFontToDesignHeightInTwips()
       
    88 @see GetNearestFontToDesignHeightInPixels()
       
    89 @see GetNearestFontToMaxHeightInTwips()
       
    90 @see GetNearestFontToMaxHeightInPixels()
       
    91 @publishedAll 
       
    92 @released
       
    93 */
       
    94 EXPORT_C TInt CFbsTypefaceStore::InstallFile(const TDesC& aName,TInt& aId)
       
    95 	{
       
    96 	TPckgBuf<TIntParcel> ip;
       
    97 	aId=0;
       
    98 	TIpcArgs args(&aName,aName.Length(),&ip);
       
    99 	TInt ret=iFbs->SendCommand(EFbsMessInstallFontStoreFile,args);
       
   100 	if(ret==KErrNone)
       
   101 		aId=ip().iInt;
       
   102 	return(ret);
       
   103 	}
       
   104 
       
   105 /** Adds a font store file to the typeface store.
       
   106 All the fonts in added and installed font files are available to the
       
   107 GetNearestFont...() family of functions.
       
   108 Additionally Bitmap Fonts are also available to GetFontById().
       
   109 
       
   110 This function adds the typeface to a reference counted list of fonts. Each 
       
   111 client that adds the typeface to the store increases the reference count. 
       
   112 The count is decremented when a client using the typeface is destroyed or 
       
   113 calls the RemoveFile() function. The typeface is removed from the store only 
       
   114 when the the reference count is zero (it is not being used by any clients).
       
   115 The InstallFile() function is similar, except that the typeface is not reference 
       
   116 counted, and is hence not removed when all the clients using it are destroyed.
       
   117 @param aName A descriptor containing the filename of the typeface store
       
   118 @param aId On return, contains the id of the typeface.
       
   119 @return KErrNone if successful, otherwise another of the system-wide error 
       
   120 codes.
       
   121 @see InstallFile()
       
   122 @see RemoveFile()
       
   123 @see GetFontById()
       
   124 @see GetNearestFontToDesignHeightInTwips()
       
   125 @see GetNearestFontToDesignHeightInPixels()
       
   126 @see GetNearestFontToMaxHeightInTwips()
       
   127 @see GetNearestFontToMaxHeightInPixels()
       
   128 @publishedAll 
       
   129 @released
       
   130 */
       
   131 EXPORT_C TInt CFbsTypefaceStore::AddFile(const TDesC& aName,TInt& aId)
       
   132 	{
       
   133 	TPckgBuf<TIntParcel> ip;
       
   134 	aId=0;
       
   135 	TIpcArgs args(&aName,aName.Length(),&ip);
       
   136 	TInt ret=iFbs->SendCommand(EFbsMessAddFontStoreFile,args);
       
   137 	if(ret==KErrNone)
       
   138 		aId=ip().iInt;
       
   139 	return(ret);
       
   140 	}
       
   141 
       
   142 /** Decrements the reference count of a file which was added using 
       
   143 AddFile(), and removes it from the store if the reference count reaches zero. 
       
   144 If the font was not found in the list of reference-counted files (see AddFile()) 
       
   145 it is assumed to be an installed file (see InstallFile()) and an attempt is 
       
   146 made to remove it anyway.
       
   147 
       
   148 If the id given is 0, an attempt is made to remove all font objects from the 
       
   149 font store provided none of the fonts in the store are currently accessed,
       
   150 otherwise it has no effect.
       
   151 
       
   152 Note:
       
   153 The id passed to this function has a different meaning depending on whether 
       
   154 or not the file is a Symbian-format bitmap file. If it is a Symbian-format 
       
   155 bitmap file the id is a UID, and is the same from one session to the next. 
       
   156 If it is an Open Font System file (e.g., a TrueType file) the id is an arbitrary 
       
   157 number. Consequently the id may vary from one session to the next, and should 
       
   158 not be saved in a file: however it may be kept and used by a client as 
       
   159 long as the client is running.
       
   160 
       
   161 @param aId The id of the file to be removed/decremented, set by AddFile() 
       
   162 or InstallFile().
       
   163 @see AddFile()
       
   164 @see InstallFile()
       
   165 @publishedAll 
       
   166 @released
       
   167 */
       
   168 EXPORT_C void CFbsTypefaceStore::RemoveFile(TInt aId)
       
   169 	{
       
   170 	iFbs->SendCommand(EFbsMessRemoveFontStoreFile,aId);
       
   171 	}
       
   172 
       
   173 /** Gets the number of typefaces supported by this store.
       
   174 @return The number of supported typefaces. 
       
   175 @see CTypefaceStore::NumTypefaces()
       
   176 @publishedAll 
       
   177 @released
       
   178 */
       
   179 EXPORT_C TInt CFbsTypefaceStore::NumTypefaces() const
       
   180 	{
       
   181 	return(iFbs->SendCommand(EFbsMessNumTypefaces));
       
   182 	}
       
   183 
       
   184 /**
       
   185 Gets the font which is the nearest to the given font specification.
       
   186 
       
   187 When the font is no longer needed, call @c ReleaseFont().
       
   188 
       
   189 Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() 
       
   190 yielding (virtually) the same result. However clients are strongly encouraged to use the new
       
   191 @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
       
   192 character within any given text string will fit within the given amount of twips, whereas the design 
       
   193 height is an aesthetic unit decided by the font designer without strict physical meaning, which 
       
   194 may result in cropped characters.
       
   195 
       
   196 Chooses from the fonts loaded at system startup or through the AddFile()
       
   197 or InstallFile() APIs.
       
   198 
       
   199 @param aFont On return, contains a pointer to the nearest font.
       
   200 @param aFontSpec The specification of the font to be matched.
       
   201 @return KErrNone if successful; a system-wide error code otherwise.
       
   202 @publishedAll
       
   203 @see GetNearestFontToDesignHeightInTwips()
       
   204 @see GetNearestFontToMaxHeightInTwips()
       
   205 @see AddFile()
       
   206 @see InstallFile()
       
   207 */
       
   208 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
       
   209 	{
       
   210 	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
       
   211 	}
       
   212 
       
   213 /**
       
   214 Gets the font which is the nearest to the given font specification.
       
   215 
       
   216 When the font is no longer needed, call @c ReleaseFont().
       
   217 
       
   218 Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels() 
       
   219 yielding (virtually) the same result. However clients are strongly encouraged to use the new
       
   220 @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
       
   221 character within any given text string will fit within the given amount of pixels, whereas the design 
       
   222 height is an aesthetic unit decided by the font designer without strict physical meaning, which 
       
   223 may result in cropped characters.
       
   224 
       
   225 Chooses from the fonts loaded at system startup or through the AddFile()
       
   226 or InstallFile() APIs.
       
   227 
       
   228 @param aFont On return, contains a pointer to the nearest font.
       
   229 @param aFontSpec The specification of the font to be matched.
       
   230 @return KErrNone if successful; a system-wide error code otherwise.
       
   231 @publishedAll
       
   232 @deprecated Use GetNearestFontToDesignHeightInPixels
       
   233 @see GetNearestFontToDesignHeightInPixels()
       
   234 @see GetNearestFontToMaxHeightInPixels()
       
   235 @see AddFile()
       
   236 @see InstallFile()
       
   237 */
       
   238 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec)
       
   239 	{
       
   240 	return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
       
   241 	}
       
   242 
       
   243 TInt CFbsTypefaceStore::GetNearestFontInTwipsAndCreateFont(
       
   244 	CFont*&				aFont,
       
   245 	TInt				aFbsMessage, // a TFbsMessage
       
   246 	const TFontSpec&	aFontSpec,
       
   247 	TInt				aMaxHeight)
       
   248 	{
       
   249 	aFont = iTwipsCache->Search(aFontSpec);
       
   250 	if (aFont)
       
   251 		{
       
   252 		if (IncrementFontCount(aFont))
       
   253 			{
       
   254 			return KErrNone;
       
   255 			}
       
   256 		Panic(EFbsTypefaceStoreError);
       
   257 		}
       
   258 
       
   259 	TInt ret = SendGetNearestFontCommandNCreateFont(
       
   260 		aFont, aFbsMessage, aFontSpec, aMaxHeight);
       
   261 	if (KErrNone != ret)
       
   262 		{
       
   263 		return ret;
       
   264 		}
       
   265 
       
   266 	CFont* discard = NULL;
       
   267 	/* We are deliberately storing in the cache the TFontSpec requested by the client 
       
   268 	 * and not the REAL TFontSpec of the font returned by the font matcher.
       
   269 	 * We are doing this for performance reasons: to use the Font Cache as much as possible. 
       
   270 	 * Unless the requested font spec is really complete, including all the different flags 
       
   271 	 * and sub fields, there is only a very small chance that the TFontSpec requested 
       
   272 	 * by the client would be exactly the same as the best match returned by the server.
       
   273 	 * Since some flags (iFontStyle.iFlags and iTypeFace.iFlags) are quite complex and 
       
   274 	 * in general the client don't set up all of them perfectly.
       
   275 	 * So in order to decrease the number of entries in the cache AND also the requests
       
   276 	 * to the server, it's better to associate the TFontSpec asked for by the client 
       
   277 	 * with the CFont found so that next time we ask for it, it will be in the cache.
       
   278 	 * 
       
   279 	 * If we request 2 different font specs that both have the same real font as their 
       
   280 	 * best match then each will appear in the cache but the CFont pointer in both entries
       
   281 	 * will point to the same real CFont (no copies)
       
   282 	 * 
       
   283 	 * PS: a problem is known because of doing this:
       
   284 	 * if we try to get a Font which is not in the system, we obtain the best match
       
   285 	 * then if we add this Font in the system (AddFile) and ask again for this Font,
       
   286 	 * we will still have the previous one which is in the Cache and not the one added.
       
   287 	 * This problem is the result of "bad" programming/testing, in general when we use a Font,
       
   288 	 * we know it's here...
       
   289 	 */
       
   290 	TRAP(ret, discard = iTwipsCache->AddEntryL(aFont,aFontSpec));
       
   291 	if (KErrNone == ret)
       
   292 		{ 
       
   293 		// Font has been added to cache. Increment reference count, so that this font
       
   294 		// will only be destroyed once all client handles to it are released, AND it can 
       
   295 		// not fit in the cache. Even if no clients have a handle to this font, the object
       
   296 		// will still persist until other fonts force it out of the cache.
       
   297 		IncrementFontCount(aFont);
       
   298 		}
       
   299 	if (discard)
       
   300 		{ // a font was bumped out of the cache
       
   301 		ReleaseFont(discard);
       
   302 		}
       
   303 	return KErrNone;
       
   304 	}
       
   305 
       
   306 
       
   307 /**
       
   308  get pixel size in Twips * 1000
       
   309  @internalComponent
       
   310  */
       
   311 void CFbsTypefaceStore::GetPixelSizeInTwips(TSize& aSize) const
       
   312 	{
       
   313 	if(iDevice)
       
   314 		{
       
   315 		aSize.iWidth = iDevice->HorizontalPixelsToTwips(1000);
       
   316 		aSize.iHeight = iDevice->VerticalPixelsToTwips(1000);
       
   317 		}
       
   318 	if(aSize.iWidth==0 || aSize.iHeight==0)
       
   319 		{
       
   320 		TMachineInfoV1Buf mibuf;
       
   321 		UserHal::MachineInfo(mibuf);
       
   322 		TSize twipsize = mibuf().iPhysicalScreenSize;
       
   323 		TSize pixelsize = mibuf().iDisplaySizeInPixels;
       
   324 		aSize.iWidth = twipsize.iWidth*1000 / pixelsize.iWidth;
       
   325 		aSize.iHeight = twipsize.iHeight*1000 / pixelsize.iHeight;
       
   326 		}
       
   327 	}
       
   328 
       
   329 
       
   330 TInt CFbsTypefaceStore::SendGetNearestFontCommandNCreateFont(
       
   331 	CFont*&				aFont,
       
   332 	TInt				aFbsMessage, // a TFbsMessage
       
   333 	const TFontSpec&	aFontSpec,
       
   334 	TInt				aMaxHeight)
       
   335 	{
       
   336 	TPckgBuf<TFontSpec> pckgFontSpec(aFontSpec);
       
   337 	TSize pixelSize;
       
   338 	GetPixelSizeInTwips(pixelSize);
       
   339 	TSizeInfo info(aMaxHeight, pixelSize);
       
   340 	TPckgBuf<TSizeInfo>		pckgMaxHeight(info);
       
   341 	TPckgBuf<TFontInfo> pckgFontInfo;
       
   342 	TIpcArgs args(&pckgFontSpec, &pckgFontInfo, &pckgMaxHeight);
       
   343 	const TInt ret = iFbs->SendCommand(aFbsMessage, args);
       
   344 	if (KErrNone != ret)
       
   345 		{
       
   346 		return ret;
       
   347 		}
       
   348 	return CreateFont(aFont, pckgFontInfo());
       
   349 	}
       
   350 
       
   351 /**
       
   352 Gets the font which is the nearest to the given font specification.
       
   353 
       
   354 When the font is no longer needed, call @c ReleaseFont().
       
   355 
       
   356 This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the 
       
   357 same result. However clients are strongly encouraged to use the new
       
   358 @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
       
   359 character within any given text string will fit within the given amount of twips, whereas the design 
       
   360 height is an aesthetic unit decided by the font designer without strict physical meaning, which 
       
   361 may result in cropped characters.
       
   362 
       
   363 Chooses from the fonts loaded at system startup or through the AddFile()
       
   364 or InstallFile() APIs.
       
   365 
       
   366 @param aFont On return, contains a pointer to the nearest font.
       
   367 @param aFontSpec The specification of the font to be matched.
       
   368 @return KErrNone if successful; a system-wide error code otherwise.
       
   369 @publishedAll
       
   370 @released
       
   371 @see GetNearestFontToMaxHeightInTwips()
       
   372 @see AddFile()
       
   373 @see InstallFile()
       
   374 */
       
   375 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
       
   376 	{
       
   377 	return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInTwips, aFontSpec);
       
   378 	}
       
   379 
       
   380 /**
       
   381 Gets the font which is the nearest to the given font specification.
       
   382 
       
   383 When the font is no longer needed, call @c ReleaseFont().
       
   384 
       
   385 This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the 
       
   386 same result. However clients are strongly encouraged to use the new
       
   387 @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
       
   388 character within any given text string will fit within the given amount of pixels, whereas the design 
       
   389 height is an aesthetic unit decided by the font designer without strict physical meaning, which 
       
   390 may result in cropped characters.
       
   391 
       
   392 Chooses from the fonts loaded at system startup or through the AddFile()
       
   393 or InstallFile() APIs.
       
   394 
       
   395 @param aFont On return, contains a pointer to the nearest font.
       
   396 @param aFontSpec The specification of the font to be matched.
       
   397 @return KErrNone if successful; a system-wide error code otherwise.
       
   398 @publishedAll
       
   399 @released
       
   400 @see GetNearestFontToMaxHeightInPixels()
       
   401 @see AddFile()
       
   402 @see InstallFile()
       
   403 */
       
   404 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
       
   405 	{
       
   406 	return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInPixels, aFontSpec);
       
   407 	}
       
   408 
       
   409 /**
       
   410 Gets the font which is the nearest to the given font specification.
       
   411 
       
   412 When the font is no longer needed, call @c ReleaseFont().
       
   413 
       
   414 The font and bitmap server returns a pointer to the nearest matching font 
       
   415 from those available. Matches to max height of font - this does its best 
       
   416 to return a font that will fit within the maximum height specified (but 
       
   417 note that variations due to hinting algorithms may rarely result in this 
       
   418 height being exceeded by up to one pixel). Problems can also be 
       
   419 encountered with bitmap fonts where the typeface exists but doesn't have 
       
   420 a font small enough.
       
   421 
       
   422 Chooses from the fonts loaded at system startup or through the AddFile()
       
   423 or InstallFile() APIs.
       
   424 
       
   425 @param aFont On return, contains a pointer to the nearest font.
       
   426 @param aFontSpec The specification of the font to be matched.
       
   427 @param aMaxHeight The maximum height within which the font must fit.
       
   428 This overrides the height specified in aFontSpec.
       
   429 @return KErrNone if successful; a system-wide error code otherwise.
       
   430 @publishedAll
       
   431 @released
       
   432 @see GetNearestFontToDesignHeightInTwips()
       
   433 @see AddFile()
       
   434 @see InstallFile()
       
   435 */
       
   436 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
       
   437 	{
       
   438 	return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInTwips, aFontSpec, aMaxHeight);
       
   439 	}
       
   440 
       
   441 /**
       
   442 Gets the font which is the nearest to the given font specification.
       
   443 
       
   444 When the font is no longer needed, call @c ReleaseFont().
       
   445 
       
   446 The font and bitmap server returns a pointer to the nearest matching font 
       
   447 from those available. Matches to max height of font - this does its best 
       
   448 to return a font that will fit within the maximum height specified (but 
       
   449 note that variations due to hinting algorithms may rarely result in this 
       
   450 height being exceeded by up to one pixel). Problems can also be 
       
   451 encountered with bitmap fonts where the typeface exists but doesn't have 
       
   452 a font small enough.
       
   453 
       
   454 Chooses from the fonts loaded at system startup or through the AddFile()
       
   455 or InstallFile() APIs.
       
   456 
       
   457 @param aFont On return, contains a pointer to the nearest font.
       
   458 @param aFontSpec The specification of the font to be matched.
       
   459 @param aMaxHeight The maximum height within which the font must fit.
       
   460 This overrides the height specified in aFontSpec.
       
   461 @return KErrNone if successful; a system-wide error code otherwise.
       
   462 @publishedAll
       
   463 @released
       
   464 @see GetNearestFontToDesignHeightInPixels()
       
   465 @see AddFile()
       
   466 @see InstallFile()
       
   467 */
       
   468 EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
       
   469 	{
       
   470 	return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInPixels, aFontSpec, aMaxHeight);
       
   471 	}
       
   472 
       
   473 /** Gets a Bitmap Font by unique identifier and algorithmic drawing style.
       
   474 Chooses from the Bitmap fonts loaded at system startup or through the AddFile()
       
   475 or InstallFile() APIs.
       
   476 
       
   477 @param aFont On return, contains a pointer to the retrieved font.
       
   478 @param aUid The unique identifier of the font to be retrieved.
       
   479 @param aAlgStyle Algorithmic style to be applied. e.g. Sets things like algorithmic 
       
   480 bolding, or slant for pseudo-italics.
       
   481 @return KErrNone if successful, otherwise another of the system-wide error 
       
   482 codes.
       
   483 @publishedAll 
       
   484 @released
       
   485 @see GetNearestFontToMaxHeightInTwips()
       
   486 @see GetNearestFontToDesignHeightInTwips()
       
   487 @see GetNearestFontToMaxHeightInPixels()
       
   488 @see GetNearestFontToDesignHeightInPixels()
       
   489 @see AddFile()
       
   490 @see InstallFile()
       
   491 */
       
   492 EXPORT_C TInt CFbsTypefaceStore::GetFontById(CFont*& aFont,TUid aUid,const TAlgStyle& aAlgStyle)
       
   493 	{
       
   494 	TPckgBuf<TFontInfo> tfpckg;
       
   495 	TSize pixelSize;
       
   496 	GetPixelSizeInTwips(pixelSize);
       
   497 	TPckgBuf<TSize> sizePkg(pixelSize);
       
   498 	TPckgBuf<TAlgStyle> stylepckg(aAlgStyle);
       
   499 	TIpcArgs args(&tfpckg,&stylepckg,aUid.iUid, &sizePkg);
       
   500 	TInt ret=iFbs->SendCommand(EFbsMessGetFontById,args);
       
   501 	if(ret!=KErrNone) return(ret);
       
   502 	return(CreateFont(aFont,tfpckg()));
       
   503 	}
       
   504 
       
   505 TInt CFbsTypefaceStore::CreateFont(CFont*& aFont, const TFontInfo& aFontInfo)
       
   506 	{
       
   507 	if (!aFontInfo.iHandle)
       
   508 		{
       
   509 		Panic(EFbsFontCreateFailed);
       
   510 		}
       
   511 	if (IsFontLoaded(aFont, aFontInfo))
       
   512 		{
       
   513 		// By now, a new server-side font object has been created for the requested 
       
   514 		// TFontSpec. However IsFontLoaded() is true, meaning the client already has a 
       
   515 		// font at this address. This can happen if a closely matching (but not exact, 
       
   516 		// otherwise it would be found in the twipscache already) TFontSpec is sent to 
       
   517 		// the server. 
       
   518 		// This means the new server-side font is a duplicate another server-side font. 
       
   519 		// Therefore tell the server to destroy the one just created, and return the 
       
   520 		// font that was already created.
       
   521 		iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle);
       
   522 		return KErrNone;
       
   523 		}
       
   524 
       
   525 	CFbsFont* font = new CFbsFont;
       
   526 	if (!font)
       
   527 		{
       
   528 		iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle);
       
   529 		return KErrNoMemory;
       
   530 		}
       
   531 	font->iHandle = aFontInfo.iHandle;
       
   532 	font->iServerHandle = aFontInfo.iServerHandle;
       
   533 	font->iAddressPointer = (CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset);
       
   534 	TRAPD(ret, AddFontL(font));
       
   535 	if (KErrNone == ret)
       
   536 		{
       
   537 		aFont = font;
       
   538 		}
       
   539 	else
       
   540 		{
       
   541 		delete font;
       
   542 		}
       
   543 	return ret;
       
   544 	}
       
   545 
       
   546 TBool CFbsTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontInfo& aFontInfo) const
       
   547 /**
       
   548 @see CFontStore::IsFontLoaded
       
   549 @see CPdrTypefaceStore::IsFontLoaded
       
   550 */
       
   551 	{
       
   552 	const TInt count = iFontAccess->Count();
       
   553 	for (TInt i = 0; i < count; i++)
       
   554 		{
       
   555 		CFont* font = (*iFontAccess)[i].iFont;
       
   556 		if (((CFbsFont*)font)->iAddressPointer ==
       
   557 			(CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset))
       
   558 			{
       
   559 			(*iFontAccess)[i].iAccessCount++;
       
   560 			aFont = font;
       
   561 			return ETrue;
       
   562 			}
       
   563 		}
       
   564 	return EFalse;
       
   565 	}
       
   566 
       
   567 /** Gets typeface information for a specified typeface index.
       
   568 This information is returned in aTypefaceSupport, and includes the typeface 
       
   569 name and typeface attributes, the number of font heights, the maximum and 
       
   570 minimum font heights, and whether it is a scaleable typeface.
       
   571 
       
   572 Returns benignly with an empty TTypefaceSupport if the index is too high; 
       
   573 this can happen if another process removes a typeface after the first process 
       
   574 has already got the number of typefaces. However, if the aTypefaceIndex<0 
       
   575 the function panics with EFbsTypefaceIndexOutOfRange.
       
   576 
       
   577 @param aTypefaceSupport On return, if the function executed successfully, 
       
   578 this object contains the typeface information. 
       
   579 @param aTypefaceIndex A typeface index number, in the range: zero to (NumTypefaces() - 1). 
       
   580 @see CTypefaceStore::TypefaceSupport() 
       
   581 @publishedAll 
       
   582 @released
       
   583 */
       
   584 EXPORT_C void CFbsTypefaceStore::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
       
   585 	{
       
   586 	__ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) );
       
   587 	TSize pixelSize;
       
   588 	GetPixelSizeInTwips(pixelSize);
       
   589 	TPckgBuf<TSize> sizePkg(pixelSize);
       
   590 	TPckgBuf<TTypefaceSupport> tfi;
       
   591 	TIpcArgs args(aTypefaceIndex,&tfi, &sizePkg);
       
   592 	iFbs->SendCommand(EFbsMessTypefaceSupport,args);
       
   593 	aTypefaceSupport=tfi();
       
   594 	}
       
   595 
       
   596 /** Gets the height of the font with specified height and typeface indices, in 
       
   597 twips.
       
   598 The value returned is rounded up or down to the nearest font height in twips.
       
   599 
       
   600 If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. 
       
   601 If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 
       
   602 then the function returns 0. If aHeightIndex is greater than the number of 
       
   603 heights then the function returns the biggest height. 
       
   604 
       
   605 @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
       
   606 @param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). 
       
   607 Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). 
       
   608 @return The height of the font, in twips.
       
   609 @see CTypefaceStore::FontHeightInTwips()
       
   610 @publishedAll 
       
   611 @released
       
   612 */
       
   613 EXPORT_C TInt CFbsTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
       
   614 	{
       
   615 	return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInTwips);
       
   616 	}
       
   617 
       
   618 /** Gets the height of the font with specified height and typeface indices, in 
       
   619 pixels.
       
   620 The value returned is rounded up or down to the nearest font height in pixels.
       
   621 
       
   622 If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. 
       
   623 If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 
       
   624 then the function returns 0. If aHeightIndex is greater than the number of 
       
   625 heights then the function returns the biggest height. 
       
   626 
       
   627 @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
       
   628 @param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). 
       
   629 Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). 
       
   630 @return The height of the font, in pixels.
       
   631 @publishedAll 
       
   632 @released
       
   633 */
       
   634 EXPORT_C TInt CFbsTypefaceStore::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const
       
   635 	{
       
   636 	return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInPixels);
       
   637 	}
       
   638 
       
   639 TInt CFbsTypefaceStore::FontHeight(TInt aTypefaceIndex,TInt aHeightIndex,TInt aMessage) const
       
   640 	{
       
   641 	__ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) );
       
   642 	TSize pixelSize;
       
   643 	GetPixelSizeInTwips(pixelSize);
       
   644 	TPckgBuf<TSize> sizePkg(pixelSize);
       
   645 	TIpcArgs args(aTypefaceIndex, aHeightIndex, &sizePkg);
       
   646 	return iFbs->SendCommand(aMessage, args);
       
   647 	}
       
   648 
       
   649 /** Gets the default anti-aliasing setting for scalable fonts.
       
   650 @return Indicates whether or not scalable fonts should be drawn using 
       
   651 anti-aliasing.
       
   652 @publishedAll 
       
   653 @released
       
   654 */
       
   655 EXPORT_C TGlyphBitmapType CFbsTypefaceStore::DefaultBitmapType() const
       
   656 	{
       
   657 	return (TGlyphBitmapType)iFbs->SendCommand(EFbsMessGetDefaultGlyphBitmapType);
       
   658 	}
       
   659 
       
   660 /** Sets the default anti-aliasing setting for scalable fonts. Unless this 
       
   661 default setting is overridden so that a font is explicitly requested with 
       
   662 anti-aliasing turned on or off, (see TOpenFontSpec::SetBitmapType() or 
       
   663 TFontStyle::SetBitmapType()), fonts will use the default setting. The default 
       
   664 setting would typically only be changed via the Control Panel. The new setting 
       
   665 affects fonts requested after the change has been made.
       
   666 There is currently no anti-aliasing support for bitmapped fonts.
       
   667 @param aType Indicates whether or not scalable fonts should be drawn using 
       
   668 anti-aliasing.
       
   669 @see TOpenFontSpec::SetBitmapType()
       
   670 @see TFontStyle::SetBitmapType()
       
   671 @publishedAll 
       
   672 @released
       
   673 */
       
   674 EXPORT_C void CFbsTypefaceStore::SetDefaultBitmapType(TGlyphBitmapType aType) const
       
   675 	{
       
   676 	iFbs->SendCommand(EFbsMessSetDefaultGlyphBitmapType,aType);
       
   677 	}
       
   678 
       
   679 /** Sets an alias for a font name.
       
   680 
       
   681 If a requested font cannot be found and its name occurs in the alias list
       
   682 then it will be searched for again using the font name corresponding to
       
   683 that alias. If an empty font name is passed then the alias will be removed
       
   684 the list.
       
   685 @param  TDesC& The font name alias to set.
       
   686 @param TDesC&  The actual font name to use for this alias. May be empty.
       
   687 @publishedAll 
       
   688 @released
       
   689 */
       
   690 EXPORT_C void CFbsTypefaceStore::SetFontNameAliasL(const TDesC& aFontAlias,const TDesC& aFontName) const
       
   691 	{
       
   692 	TIpcArgs args(&aFontAlias,aFontAlias.Length(),&aFontName,aFontName.Length());
       
   693 	User::LeaveIfError(iFbs->SendCommand(EFbsMessFontNameAlias,args));
       
   694 	}
       
   695 
       
   696 /** Specifies the default language with which font metrics calculation will be based on.
       
   697 The default language will be used if none is set on the font specification.
       
   698 @publishedAll 
       
   699 @released
       
   700 @see TFontSpec::SetScriptTypeForMetrics
       
   701 */
       
   702 EXPORT_C void CFbsTypefaceStore::SetDefaultLanguageForMetrics(TLanguage aLanguage) const
       
   703 	{
       
   704 	iFbs->SendCommand(EFbsMessDefaultLanguageForMetrics, aLanguage);
       
   705 	}
       
   706 
       
   707 /**
       
   708 Unload all fonts loaded from RAM or removable media
       
   709 @internalTechnology
       
   710 @deprecated
       
   711 */
       
   712 EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL()
       
   713 	{
       
   714 	User::Leave(KErrNotSupported);
       
   715 	}
       
   716 
       
   717 /**
       
   718 Unload all fonts (of specified type) loaded from named drive
       
   719 @internalTechnology
       
   720 */
       
   721 EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aDrive*/, TBool /*aAllFonts*/)
       
   722 	{
       
   723 	User::Leave(KErrNotSupported);
       
   724 	}
       
   725 
       
   726 /**
       
   727 Unload the named font file
       
   728 @internalTechnology
       
   729 */
       
   730 EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aFileName*/)
       
   731 	{
       
   732 	User::Leave(KErrNotSupported);
       
   733 	}
       
   734 
       
   735 /** Reset the twips cache.
       
   736 
       
   737 The Typeface Store remembers font matches found through GetNearestFont...InTwips() family 
       
   738 of functions in a cache for quicker matching.  This function empties the cache, and should be
       
   739 called after the screen mode is changed as the Twips to pixels relationship may have changed.
       
   740 @publishedAll
       
   741 */
       
   742 EXPORT_C void CFbsTypefaceStore::ReleaseTwipsCache()
       
   743 	{
       
   744 	if(iTwipsCache)
       
   745 		{
       
   746 		CFont* font=iTwipsCache->RemoveFirstEntry();
       
   747 		while(font!=NULL)
       
   748 			{
       
   749 			ReleaseFont(font);
       
   750 			font=iTwipsCache->RemoveFirstEntry();
       
   751 			}
       
   752 		}
       
   753 	}
       
   754 
       
   755 /**
       
   756 Sets the system default font typeface. This font will be used when finding the nearest font and the font specified is
       
   757 an empty descriptor.
       
   758 If the system default font is not set, then the default behaviour is to find the nearest match.
       
   759 
       
   760 @capability WriteDeviceData
       
   761 @param aFontTypefacename is the font typeface to use as the system default. A font alias cannot be used.
       
   762 */
       
   763 EXPORT_C void CFbsTypefaceStore::SetSystemDefaultTypefaceNameL(const TDesC& aFontTypefaceName)
       
   764 	{
       
   765 	if (aFontTypefaceName.Length() <= KMaxTypefaceNameLength)
       
   766 		{
       
   767 		TIpcArgs args(&aFontTypefaceName);
       
   768 		User::LeaveIfError(iFbs->SendCommand(EFbsSetSystemDefaultTypefaceName, args));		
       
   769 		}
       
   770 	else
       
   771 		User::Leave(KErrTooBig);	// Typeface name is too large
       
   772 	}
       
   773 
       
   774 /**
       
   775 Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
       
   776 @capability ECapabilityWriteDeviceData
       
   777 @publishedPartner
       
   778 @released
       
   779 @param aLinkedTypefaceSpec  The typeface specification to be added.  Ownership is not transferred.
       
   780 @param aId A unique identifier
       
   781 @return A global error code
       
   782 @see CLinkedTypefaceSpecification
       
   783 @deprecated
       
   784 */
       
   785 EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& /*aLinkedTypefaceSpec*/, TInt& /*aId*/)
       
   786 	{
       
   787 	return KErrNotSupported;
       
   788 	}
       
   789 
       
   790 /**
       
   791 	Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
       
   792 	@capability ECapabilityWriteDeviceData
       
   793 	@publishedPartner
       
   794 	@released
       
   795 	@param aLinkedTypefaceSpec.  The typeface specification to be added.  Ownership is not transferred.
       
   796 	@return a global error code
       
   797 	@see CLinkedTypefaceSpecification
       
   798 	*/
       
   799 EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
       
   800 	{
       
   801 	__ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection));
       
   802 	
       
   803 	// send the name
       
   804 	TPckgBuf <TLinkedTypefaceSpecificationArgs> pckgbuf;
       
   805 	TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf();
       
   806 	
       
   807 	typefaceArgs = aLinkedTypefaceSpec;
       
   808 
       
   809 	TIpcArgs args(&pckgbuf,sizeof(TPckgBuf <TLinkedTypefaceSpecificationArgs>));
       
   810 	
       
   811 	return iFbs->SendCommand(EFbsMessRegisterLinkedTypeface,args);
       
   812 	}
       
   813 /**
       
   814 Function to retrieve a linked typeface specification from the installed rasterizer.
       
   815 If there is not a rasterizer present supporting font linking then KErrNotSupported will be returned.
       
   816 The rasterizer is name specified within the passed specification and fills in the elements and
       
   817 groups if the typeface exists.
       
   818 
       
   819 	@param CLinkedTypefaceSpecificaion& The typeface Specification with the name set to be the typeface to be retrieved.
       
   820 	
       
   821 	@leave KErrNoMemory if there is insufficient memory available
       
   822 	@leave KErrServerTerminated if the server no longer present 
       
   823 	@leave KErrServerBusy if there are no message slots available  
       
   824  */
       
   825 EXPORT_C void CFbsTypefaceStore::GetLinkedTypefaceL(CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
       
   826 	{
       
   827 	TBuf<KMaxTypefaceNameLength> linkedName = aLinkedTypefaceSpec.Name();
       
   828 	
       
   829 	TLinkedTypefaceSpecificationArgs returnSpec;
       
   830 	TPckgBuf<TLinkedTypefaceSpecificationArgs> specPkg;
       
   831 	
       
   832 	TIpcArgs args;
       
   833 	args.Set(0,&linkedName);
       
   834 	args.Set(2,&specPkg);
       
   835 
       
   836 	User::LeaveIfError(iFbs->SendCommand(EFbsMessFetchLinkedTypeface, args));
       
   837 	
       
   838 	aLinkedTypefaceSpec.Clear();
       
   839 	returnSpec = specPkg();
       
   840 	
       
   841 	TInt i;
       
   842 	for (i = 0 ; i < returnSpec.iGroupSize ; i++)
       
   843 		{
       
   844 		CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(returnSpec.iGroups[i].iGroupId);
       
   845 		grp->SetBaselineShift(returnSpec.iGroups[i].iBaselineShift);
       
   846 		grp->SetScalingOption(returnSpec.iGroups[i].iScalingOption);
       
   847 		grp->SetBoldnessPercentage(returnSpec.iGroups[i].iBoldnessPercentage);
       
   848 		grp->SetItalicAngle(returnSpec.iGroups[i].iItalicAngle);
       
   849 		aLinkedTypefaceSpec.AddLinkedTypefaceGroupL(*grp);
       
   850 		CleanupStack::Pop(grp);
       
   851 		}
       
   852 	for (i = 0 ; i < returnSpec.iSize ; i++)
       
   853 		{
       
   854 		CLinkedTypefaceElementSpec* ele = CLinkedTypefaceElementSpec::NewLC(returnSpec.iTypefaces[i].iName, returnSpec.iTypefaces[i].iGroupId);
       
   855 		ele->SetCanonical(returnSpec.iTypefaces[i].iIsCanonical);
       
   856 		aLinkedTypefaceSpec.AddTypefaceAtBackL(*ele);
       
   857 		CleanupStack::Pop(ele);
       
   858 		}
       
   859 	}
       
   860 
       
   861 /**
       
   862 Function to update an existing linked typeface with a new specification. If successful a temporary file is generated and this will replace the
       
   863 linked font after a reboot. Calls to FetchLinkedTypefaceSpecificationL will return the currently loaded linked font spec and not the
       
   864 updated specification. 
       
   865 
       
   866 @param aLinkedTypefaceSpec A new linked font specification to replace an existing file
       
   867 
       
   868 @panic EFbsPanicNoConnection There is no connection to FontBitmap Server
       
   869 
       
   870 @return TInt One of the system wide error codes
       
   871 */
       
   872 EXPORT_C TInt CFbsTypefaceStore::UpdateLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
       
   873 	{
       
   874 	__ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection));
       
   875 
       
   876 	TPckgBuf <TLinkedTypefaceSpecificationArgs> pckgbuf;
       
   877 	TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf();
       
   878 	
       
   879 	typefaceArgs = aLinkedTypefaceSpec;
       
   880 
       
   881 	TIpcArgs args(&pckgbuf,sizeof(TPckgBuf <TLinkedTypefaceSpecificationArgs>));
       
   882 	
       
   883 	return iFbs->SendCommand(EFbsMessUpdateLinkedTypeface,args);
       
   884 	}
       
   885