os/graphics/fbs/fontandbitmapserver/sfbs/TFSTORE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/sfbs/TFSTORE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,885 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32hal.h>
    1.20 +#include <fbs.h>
    1.21 +#include "UTILS.H"
    1.22 +#include <linkedfonts.h>
    1.23 +#include "FbsMessage.H"
    1.24 +
    1.25 +GLREF_C void Panic(TFbsPanic aPanic);
    1.26 +
    1.27 +CFbsTypefaceStore::CFbsTypefaceStore(CGraphicsDevice* aDevice):
    1.28 +	CTypefaceStore(),
    1.29 +	iDevice(aDevice),
    1.30 +	iTwipsCache(NULL)
    1.31 +	{
    1.32 +	}
    1.33 +
    1.34 +/** 
    1.35 +@publishedAll 
    1.36 +@released
    1.37 +*/
    1.38 +EXPORT_C CFbsTypefaceStore::~CFbsTypefaceStore()
    1.39 +	{
    1.40 +	if(iTwipsCache)
    1.41 +		{
    1.42 +		ReleaseTwipsCache();
    1.43 +		delete iTwipsCache;
    1.44 +		}
    1.45 +	}
    1.46 +
    1.47 +/** Allocates and constructs a CFbsTypefaceStore, specifying a graphics device.
    1.48 +@param aDevice A pointer to a graphics device.
    1.49 +@return A pointer to the newly created typeface store. 
    1.50 +@publishedAll 
    1.51 +@released
    1.52 +*/
    1.53 +EXPORT_C CFbsTypefaceStore* CFbsTypefaceStore::NewL(CGraphicsDevice* aDevice)
    1.54 +	{
    1.55 +	CFbsTypefaceStore* thisptr=new(ELeave) CFbsTypefaceStore(aDevice);
    1.56 +	CleanupStack::PushL(thisptr);
    1.57 +	thisptr->ConstructL();
    1.58 +	CleanupStack::Pop();
    1.59 +	return(thisptr);
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +void CFbsTypefaceStore::ConstructL()
    1.64 +	{
    1.65 +	// get the session info from the Tls
    1.66 +	iFbs = RFbsSession::GetSession();
    1.67 +	if (!iFbs)
    1.68 +		{
    1.69 +		User::Leave(KErrCouldNotConnect);
    1.70 +		}
    1.71 +	CTypefaceStore::ConstructL();
    1.72 +	iTwipsCache = new(ELeave) CFontCache;
    1.73 +	}
    1.74 +
    1.75 +
    1.76 +/** Installs a font store file into the typeface store.
    1.77 +All the fonts in added and installed font files are available to the
    1.78 +GetNearestFont...() family of functions.
    1.79 +Additionally Bitmap Fonts are also available to GetFontById().
    1.80 +
    1.81 +Installed files remain in the typeface store even after the client which added 
    1.82 +them is destroyed. They can be removed using RemoveFile().
    1.83 +@param aName The name of the file to be installed.
    1.84 +@param aId On return, contains the id of the installed file.
    1.85 +@return KErrNone if successful, otherwise another of the system-wide error 
    1.86 +codes.
    1.87 +@see AddFile()
    1.88 +@see RemoveFile()
    1.89 +@see GetFontById()
    1.90 +@see GetNearestFontToDesignHeightInTwips()
    1.91 +@see GetNearestFontToDesignHeightInPixels()
    1.92 +@see GetNearestFontToMaxHeightInTwips()
    1.93 +@see GetNearestFontToMaxHeightInPixels()
    1.94 +@publishedAll 
    1.95 +@released
    1.96 +*/
    1.97 +EXPORT_C TInt CFbsTypefaceStore::InstallFile(const TDesC& aName,TInt& aId)
    1.98 +	{
    1.99 +	TPckgBuf<TIntParcel> ip;
   1.100 +	aId=0;
   1.101 +	TIpcArgs args(&aName,aName.Length(),&ip);
   1.102 +	TInt ret=iFbs->SendCommand(EFbsMessInstallFontStoreFile,args);
   1.103 +	if(ret==KErrNone)
   1.104 +		aId=ip().iInt;
   1.105 +	return(ret);
   1.106 +	}
   1.107 +
   1.108 +/** Adds a font store file to the typeface store.
   1.109 +All the fonts in added and installed font files are available to the
   1.110 +GetNearestFont...() family of functions.
   1.111 +Additionally Bitmap Fonts are also available to GetFontById().
   1.112 +
   1.113 +This function adds the typeface to a reference counted list of fonts. Each 
   1.114 +client that adds the typeface to the store increases the reference count. 
   1.115 +The count is decremented when a client using the typeface is destroyed or 
   1.116 +calls the RemoveFile() function. The typeface is removed from the store only 
   1.117 +when the the reference count is zero (it is not being used by any clients).
   1.118 +The InstallFile() function is similar, except that the typeface is not reference 
   1.119 +counted, and is hence not removed when all the clients using it are destroyed.
   1.120 +@param aName A descriptor containing the filename of the typeface store
   1.121 +@param aId On return, contains the id of the typeface.
   1.122 +@return KErrNone if successful, otherwise another of the system-wide error 
   1.123 +codes.
   1.124 +@see InstallFile()
   1.125 +@see RemoveFile()
   1.126 +@see GetFontById()
   1.127 +@see GetNearestFontToDesignHeightInTwips()
   1.128 +@see GetNearestFontToDesignHeightInPixels()
   1.129 +@see GetNearestFontToMaxHeightInTwips()
   1.130 +@see GetNearestFontToMaxHeightInPixels()
   1.131 +@publishedAll 
   1.132 +@released
   1.133 +*/
   1.134 +EXPORT_C TInt CFbsTypefaceStore::AddFile(const TDesC& aName,TInt& aId)
   1.135 +	{
   1.136 +	TPckgBuf<TIntParcel> ip;
   1.137 +	aId=0;
   1.138 +	TIpcArgs args(&aName,aName.Length(),&ip);
   1.139 +	TInt ret=iFbs->SendCommand(EFbsMessAddFontStoreFile,args);
   1.140 +	if(ret==KErrNone)
   1.141 +		aId=ip().iInt;
   1.142 +	return(ret);
   1.143 +	}
   1.144 +
   1.145 +/** Decrements the reference count of a file which was added using 
   1.146 +AddFile(), and removes it from the store if the reference count reaches zero. 
   1.147 +If the font was not found in the list of reference-counted files (see AddFile()) 
   1.148 +it is assumed to be an installed file (see InstallFile()) and an attempt is 
   1.149 +made to remove it anyway.
   1.150 +
   1.151 +If the id given is 0, an attempt is made to remove all font objects from the 
   1.152 +font store provided none of the fonts in the store are currently accessed,
   1.153 +otherwise it has no effect.
   1.154 +
   1.155 +Note:
   1.156 +The id passed to this function has a different meaning depending on whether 
   1.157 +or not the file is a Symbian-format bitmap file. If it is a Symbian-format 
   1.158 +bitmap file the id is a UID, and is the same from one session to the next. 
   1.159 +If it is an Open Font System file (e.g., a TrueType file) the id is an arbitrary 
   1.160 +number. Consequently the id may vary from one session to the next, and should 
   1.161 +not be saved in a file: however it may be kept and used by a client as 
   1.162 +long as the client is running.
   1.163 +
   1.164 +@param aId The id of the file to be removed/decremented, set by AddFile() 
   1.165 +or InstallFile().
   1.166 +@see AddFile()
   1.167 +@see InstallFile()
   1.168 +@publishedAll 
   1.169 +@released
   1.170 +*/
   1.171 +EXPORT_C void CFbsTypefaceStore::RemoveFile(TInt aId)
   1.172 +	{
   1.173 +	iFbs->SendCommand(EFbsMessRemoveFontStoreFile,aId);
   1.174 +	}
   1.175 +
   1.176 +/** Gets the number of typefaces supported by this store.
   1.177 +@return The number of supported typefaces. 
   1.178 +@see CTypefaceStore::NumTypefaces()
   1.179 +@publishedAll 
   1.180 +@released
   1.181 +*/
   1.182 +EXPORT_C TInt CFbsTypefaceStore::NumTypefaces() const
   1.183 +	{
   1.184 +	return(iFbs->SendCommand(EFbsMessNumTypefaces));
   1.185 +	}
   1.186 +
   1.187 +/**
   1.188 +Gets the font which is the nearest to the given font specification.
   1.189 +
   1.190 +When the font is no longer needed, call @c ReleaseFont().
   1.191 +
   1.192 +Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() 
   1.193 +yielding (virtually) the same result. However clients are strongly encouraged to use the new
   1.194 +@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
   1.195 +character within any given text string will fit within the given amount of twips, whereas the design 
   1.196 +height is an aesthetic unit decided by the font designer without strict physical meaning, which 
   1.197 +may result in cropped characters.
   1.198 +
   1.199 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.200 +or InstallFile() APIs.
   1.201 +
   1.202 +@param aFont On return, contains a pointer to the nearest font.
   1.203 +@param aFontSpec The specification of the font to be matched.
   1.204 +@return KErrNone if successful; a system-wide error code otherwise.
   1.205 +@publishedAll
   1.206 +@see GetNearestFontToDesignHeightInTwips()
   1.207 +@see GetNearestFontToMaxHeightInTwips()
   1.208 +@see AddFile()
   1.209 +@see InstallFile()
   1.210 +*/
   1.211 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
   1.212 +	{
   1.213 +	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
   1.214 +	}
   1.215 +
   1.216 +/**
   1.217 +Gets the font which is the nearest to the given font specification.
   1.218 +
   1.219 +When the font is no longer needed, call @c ReleaseFont().
   1.220 +
   1.221 +Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels() 
   1.222 +yielding (virtually) the same result. However clients are strongly encouraged to use the new
   1.223 +@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
   1.224 +character within any given text string will fit within the given amount of pixels, whereas the design 
   1.225 +height is an aesthetic unit decided by the font designer without strict physical meaning, which 
   1.226 +may result in cropped characters.
   1.227 +
   1.228 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.229 +or InstallFile() APIs.
   1.230 +
   1.231 +@param aFont On return, contains a pointer to the nearest font.
   1.232 +@param aFontSpec The specification of the font to be matched.
   1.233 +@return KErrNone if successful; a system-wide error code otherwise.
   1.234 +@publishedAll
   1.235 +@deprecated Use GetNearestFontToDesignHeightInPixels
   1.236 +@see GetNearestFontToDesignHeightInPixels()
   1.237 +@see GetNearestFontToMaxHeightInPixels()
   1.238 +@see AddFile()
   1.239 +@see InstallFile()
   1.240 +*/
   1.241 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec)
   1.242 +	{
   1.243 +	return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
   1.244 +	}
   1.245 +
   1.246 +TInt CFbsTypefaceStore::GetNearestFontInTwipsAndCreateFont(
   1.247 +	CFont*&				aFont,
   1.248 +	TInt				aFbsMessage, // a TFbsMessage
   1.249 +	const TFontSpec&	aFontSpec,
   1.250 +	TInt				aMaxHeight)
   1.251 +	{
   1.252 +	aFont = iTwipsCache->Search(aFontSpec);
   1.253 +	if (aFont)
   1.254 +		{
   1.255 +		if (IncrementFontCount(aFont))
   1.256 +			{
   1.257 +			return KErrNone;
   1.258 +			}
   1.259 +		Panic(EFbsTypefaceStoreError);
   1.260 +		}
   1.261 +
   1.262 +	TInt ret = SendGetNearestFontCommandNCreateFont(
   1.263 +		aFont, aFbsMessage, aFontSpec, aMaxHeight);
   1.264 +	if (KErrNone != ret)
   1.265 +		{
   1.266 +		return ret;
   1.267 +		}
   1.268 +
   1.269 +	CFont* discard = NULL;
   1.270 +	/* We are deliberately storing in the cache the TFontSpec requested by the client 
   1.271 +	 * and not the REAL TFontSpec of the font returned by the font matcher.
   1.272 +	 * We are doing this for performance reasons: to use the Font Cache as much as possible. 
   1.273 +	 * Unless the requested font spec is really complete, including all the different flags 
   1.274 +	 * and sub fields, there is only a very small chance that the TFontSpec requested 
   1.275 +	 * by the client would be exactly the same as the best match returned by the server.
   1.276 +	 * Since some flags (iFontStyle.iFlags and iTypeFace.iFlags) are quite complex and 
   1.277 +	 * in general the client don't set up all of them perfectly.
   1.278 +	 * So in order to decrease the number of entries in the cache AND also the requests
   1.279 +	 * to the server, it's better to associate the TFontSpec asked for by the client 
   1.280 +	 * with the CFont found so that next time we ask for it, it will be in the cache.
   1.281 +	 * 
   1.282 +	 * If we request 2 different font specs that both have the same real font as their 
   1.283 +	 * best match then each will appear in the cache but the CFont pointer in both entries
   1.284 +	 * will point to the same real CFont (no copies)
   1.285 +	 * 
   1.286 +	 * PS: a problem is known because of doing this:
   1.287 +	 * if we try to get a Font which is not in the system, we obtain the best match
   1.288 +	 * then if we add this Font in the system (AddFile) and ask again for this Font,
   1.289 +	 * we will still have the previous one which is in the Cache and not the one added.
   1.290 +	 * This problem is the result of "bad" programming/testing, in general when we use a Font,
   1.291 +	 * we know it's here...
   1.292 +	 */
   1.293 +	TRAP(ret, discard = iTwipsCache->AddEntryL(aFont,aFontSpec));
   1.294 +	if (KErrNone == ret)
   1.295 +		{ 
   1.296 +		// Font has been added to cache. Increment reference count, so that this font
   1.297 +		// will only be destroyed once all client handles to it are released, AND it can 
   1.298 +		// not fit in the cache. Even if no clients have a handle to this font, the object
   1.299 +		// will still persist until other fonts force it out of the cache.
   1.300 +		IncrementFontCount(aFont);
   1.301 +		}
   1.302 +	if (discard)
   1.303 +		{ // a font was bumped out of the cache
   1.304 +		ReleaseFont(discard);
   1.305 +		}
   1.306 +	return KErrNone;
   1.307 +	}
   1.308 +
   1.309 +
   1.310 +/**
   1.311 + get pixel size in Twips * 1000
   1.312 + @internalComponent
   1.313 + */
   1.314 +void CFbsTypefaceStore::GetPixelSizeInTwips(TSize& aSize) const
   1.315 +	{
   1.316 +	if(iDevice)
   1.317 +		{
   1.318 +		aSize.iWidth = iDevice->HorizontalPixelsToTwips(1000);
   1.319 +		aSize.iHeight = iDevice->VerticalPixelsToTwips(1000);
   1.320 +		}
   1.321 +	if(aSize.iWidth==0 || aSize.iHeight==0)
   1.322 +		{
   1.323 +		TMachineInfoV1Buf mibuf;
   1.324 +		UserHal::MachineInfo(mibuf);
   1.325 +		TSize twipsize = mibuf().iPhysicalScreenSize;
   1.326 +		TSize pixelsize = mibuf().iDisplaySizeInPixels;
   1.327 +		aSize.iWidth = twipsize.iWidth*1000 / pixelsize.iWidth;
   1.328 +		aSize.iHeight = twipsize.iHeight*1000 / pixelsize.iHeight;
   1.329 +		}
   1.330 +	}
   1.331 +
   1.332 +
   1.333 +TInt CFbsTypefaceStore::SendGetNearestFontCommandNCreateFont(
   1.334 +	CFont*&				aFont,
   1.335 +	TInt				aFbsMessage, // a TFbsMessage
   1.336 +	const TFontSpec&	aFontSpec,
   1.337 +	TInt				aMaxHeight)
   1.338 +	{
   1.339 +	TPckgBuf<TFontSpec> pckgFontSpec(aFontSpec);
   1.340 +	TSize pixelSize;
   1.341 +	GetPixelSizeInTwips(pixelSize);
   1.342 +	TSizeInfo info(aMaxHeight, pixelSize);
   1.343 +	TPckgBuf<TSizeInfo>		pckgMaxHeight(info);
   1.344 +	TPckgBuf<TFontInfo> pckgFontInfo;
   1.345 +	TIpcArgs args(&pckgFontSpec, &pckgFontInfo, &pckgMaxHeight);
   1.346 +	const TInt ret = iFbs->SendCommand(aFbsMessage, args);
   1.347 +	if (KErrNone != ret)
   1.348 +		{
   1.349 +		return ret;
   1.350 +		}
   1.351 +	return CreateFont(aFont, pckgFontInfo());
   1.352 +	}
   1.353 +
   1.354 +/**
   1.355 +Gets the font which is the nearest to the given font specification.
   1.356 +
   1.357 +When the font is no longer needed, call @c ReleaseFont().
   1.358 +
   1.359 +This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the 
   1.360 +same result. However clients are strongly encouraged to use the new
   1.361 +@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
   1.362 +character within any given text string will fit within the given amount of twips, whereas the design 
   1.363 +height is an aesthetic unit decided by the font designer without strict physical meaning, which 
   1.364 +may result in cropped characters.
   1.365 +
   1.366 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.367 +or InstallFile() APIs.
   1.368 +
   1.369 +@param aFont On return, contains a pointer to the nearest font.
   1.370 +@param aFontSpec The specification of the font to be matched.
   1.371 +@return KErrNone if successful; a system-wide error code otherwise.
   1.372 +@publishedAll
   1.373 +@released
   1.374 +@see GetNearestFontToMaxHeightInTwips()
   1.375 +@see AddFile()
   1.376 +@see InstallFile()
   1.377 +*/
   1.378 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
   1.379 +	{
   1.380 +	return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInTwips, aFontSpec);
   1.381 +	}
   1.382 +
   1.383 +/**
   1.384 +Gets the font which is the nearest to the given font specification.
   1.385 +
   1.386 +When the font is no longer needed, call @c ReleaseFont().
   1.387 +
   1.388 +This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the 
   1.389 +same result. However clients are strongly encouraged to use the new
   1.390 +@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
   1.391 +character within any given text string will fit within the given amount of pixels, whereas the design 
   1.392 +height is an aesthetic unit decided by the font designer without strict physical meaning, which 
   1.393 +may result in cropped characters.
   1.394 +
   1.395 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.396 +or InstallFile() APIs.
   1.397 +
   1.398 +@param aFont On return, contains a pointer to the nearest font.
   1.399 +@param aFontSpec The specification of the font to be matched.
   1.400 +@return KErrNone if successful; a system-wide error code otherwise.
   1.401 +@publishedAll
   1.402 +@released
   1.403 +@see GetNearestFontToMaxHeightInPixels()
   1.404 +@see AddFile()
   1.405 +@see InstallFile()
   1.406 +*/
   1.407 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
   1.408 +	{
   1.409 +	return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInPixels, aFontSpec);
   1.410 +	}
   1.411 +
   1.412 +/**
   1.413 +Gets the font which is the nearest to the given font specification.
   1.414 +
   1.415 +When the font is no longer needed, call @c ReleaseFont().
   1.416 +
   1.417 +The font and bitmap server returns a pointer to the nearest matching font 
   1.418 +from those available. Matches to max height of font - this does its best 
   1.419 +to return a font that will fit within the maximum height specified (but 
   1.420 +note that variations due to hinting algorithms may rarely result in this 
   1.421 +height being exceeded by up to one pixel). Problems can also be 
   1.422 +encountered with bitmap fonts where the typeface exists but doesn't have 
   1.423 +a font small enough.
   1.424 +
   1.425 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.426 +or InstallFile() APIs.
   1.427 +
   1.428 +@param aFont On return, contains a pointer to the nearest font.
   1.429 +@param aFontSpec The specification of the font to be matched.
   1.430 +@param aMaxHeight The maximum height within which the font must fit.
   1.431 +This overrides the height specified in aFontSpec.
   1.432 +@return KErrNone if successful; a system-wide error code otherwise.
   1.433 +@publishedAll
   1.434 +@released
   1.435 +@see GetNearestFontToDesignHeightInTwips()
   1.436 +@see AddFile()
   1.437 +@see InstallFile()
   1.438 +*/
   1.439 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
   1.440 +	{
   1.441 +	return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInTwips, aFontSpec, aMaxHeight);
   1.442 +	}
   1.443 +
   1.444 +/**
   1.445 +Gets the font which is the nearest to the given font specification.
   1.446 +
   1.447 +When the font is no longer needed, call @c ReleaseFont().
   1.448 +
   1.449 +The font and bitmap server returns a pointer to the nearest matching font 
   1.450 +from those available. Matches to max height of font - this does its best 
   1.451 +to return a font that will fit within the maximum height specified (but 
   1.452 +note that variations due to hinting algorithms may rarely result in this 
   1.453 +height being exceeded by up to one pixel). Problems can also be 
   1.454 +encountered with bitmap fonts where the typeface exists but doesn't have 
   1.455 +a font small enough.
   1.456 +
   1.457 +Chooses from the fonts loaded at system startup or through the AddFile()
   1.458 +or InstallFile() APIs.
   1.459 +
   1.460 +@param aFont On return, contains a pointer to the nearest font.
   1.461 +@param aFontSpec The specification of the font to be matched.
   1.462 +@param aMaxHeight The maximum height within which the font must fit.
   1.463 +This overrides the height specified in aFontSpec.
   1.464 +@return KErrNone if successful; a system-wide error code otherwise.
   1.465 +@publishedAll
   1.466 +@released
   1.467 +@see GetNearestFontToDesignHeightInPixels()
   1.468 +@see AddFile()
   1.469 +@see InstallFile()
   1.470 +*/
   1.471 +EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
   1.472 +	{
   1.473 +	return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInPixels, aFontSpec, aMaxHeight);
   1.474 +	}
   1.475 +
   1.476 +/** Gets a Bitmap Font by unique identifier and algorithmic drawing style.
   1.477 +Chooses from the Bitmap fonts loaded at system startup or through the AddFile()
   1.478 +or InstallFile() APIs.
   1.479 +
   1.480 +@param aFont On return, contains a pointer to the retrieved font.
   1.481 +@param aUid The unique identifier of the font to be retrieved.
   1.482 +@param aAlgStyle Algorithmic style to be applied. e.g. Sets things like algorithmic 
   1.483 +bolding, or slant for pseudo-italics.
   1.484 +@return KErrNone if successful, otherwise another of the system-wide error 
   1.485 +codes.
   1.486 +@publishedAll 
   1.487 +@released
   1.488 +@see GetNearestFontToMaxHeightInTwips()
   1.489 +@see GetNearestFontToDesignHeightInTwips()
   1.490 +@see GetNearestFontToMaxHeightInPixels()
   1.491 +@see GetNearestFontToDesignHeightInPixels()
   1.492 +@see AddFile()
   1.493 +@see InstallFile()
   1.494 +*/
   1.495 +EXPORT_C TInt CFbsTypefaceStore::GetFontById(CFont*& aFont,TUid aUid,const TAlgStyle& aAlgStyle)
   1.496 +	{
   1.497 +	TPckgBuf<TFontInfo> tfpckg;
   1.498 +	TSize pixelSize;
   1.499 +	GetPixelSizeInTwips(pixelSize);
   1.500 +	TPckgBuf<TSize> sizePkg(pixelSize);
   1.501 +	TPckgBuf<TAlgStyle> stylepckg(aAlgStyle);
   1.502 +	TIpcArgs args(&tfpckg,&stylepckg,aUid.iUid, &sizePkg);
   1.503 +	TInt ret=iFbs->SendCommand(EFbsMessGetFontById,args);
   1.504 +	if(ret!=KErrNone) return(ret);
   1.505 +	return(CreateFont(aFont,tfpckg()));
   1.506 +	}
   1.507 +
   1.508 +TInt CFbsTypefaceStore::CreateFont(CFont*& aFont, const TFontInfo& aFontInfo)
   1.509 +	{
   1.510 +	if (!aFontInfo.iHandle)
   1.511 +		{
   1.512 +		Panic(EFbsFontCreateFailed);
   1.513 +		}
   1.514 +	if (IsFontLoaded(aFont, aFontInfo))
   1.515 +		{
   1.516 +		// By now, a new server-side font object has been created for the requested 
   1.517 +		// TFontSpec. However IsFontLoaded() is true, meaning the client already has a 
   1.518 +		// font at this address. This can happen if a closely matching (but not exact, 
   1.519 +		// otherwise it would be found in the twipscache already) TFontSpec is sent to 
   1.520 +		// the server. 
   1.521 +		// This means the new server-side font is a duplicate another server-side font. 
   1.522 +		// Therefore tell the server to destroy the one just created, and return the 
   1.523 +		// font that was already created.
   1.524 +		iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle);
   1.525 +		return KErrNone;
   1.526 +		}
   1.527 +
   1.528 +	CFbsFont* font = new CFbsFont;
   1.529 +	if (!font)
   1.530 +		{
   1.531 +		iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle);
   1.532 +		return KErrNoMemory;
   1.533 +		}
   1.534 +	font->iHandle = aFontInfo.iHandle;
   1.535 +	font->iServerHandle = aFontInfo.iServerHandle;
   1.536 +	font->iAddressPointer = (CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset);
   1.537 +	TRAPD(ret, AddFontL(font));
   1.538 +	if (KErrNone == ret)
   1.539 +		{
   1.540 +		aFont = font;
   1.541 +		}
   1.542 +	else
   1.543 +		{
   1.544 +		delete font;
   1.545 +		}
   1.546 +	return ret;
   1.547 +	}
   1.548 +
   1.549 +TBool CFbsTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontInfo& aFontInfo) const
   1.550 +/**
   1.551 +@see CFontStore::IsFontLoaded
   1.552 +@see CPdrTypefaceStore::IsFontLoaded
   1.553 +*/
   1.554 +	{
   1.555 +	const TInt count = iFontAccess->Count();
   1.556 +	for (TInt i = 0; i < count; i++)
   1.557 +		{
   1.558 +		CFont* font = (*iFontAccess)[i].iFont;
   1.559 +		if (((CFbsFont*)font)->iAddressPointer ==
   1.560 +			(CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset))
   1.561 +			{
   1.562 +			(*iFontAccess)[i].iAccessCount++;
   1.563 +			aFont = font;
   1.564 +			return ETrue;
   1.565 +			}
   1.566 +		}
   1.567 +	return EFalse;
   1.568 +	}
   1.569 +
   1.570 +/** Gets typeface information for a specified typeface index.
   1.571 +This information is returned in aTypefaceSupport, and includes the typeface 
   1.572 +name and typeface attributes, the number of font heights, the maximum and 
   1.573 +minimum font heights, and whether it is a scaleable typeface.
   1.574 +
   1.575 +Returns benignly with an empty TTypefaceSupport if the index is too high; 
   1.576 +this can happen if another process removes a typeface after the first process 
   1.577 +has already got the number of typefaces. However, if the aTypefaceIndex<0 
   1.578 +the function panics with EFbsTypefaceIndexOutOfRange.
   1.579 +
   1.580 +@param aTypefaceSupport On return, if the function executed successfully, 
   1.581 +this object contains the typeface information. 
   1.582 +@param aTypefaceIndex A typeface index number, in the range: zero to (NumTypefaces() - 1). 
   1.583 +@see CTypefaceStore::TypefaceSupport() 
   1.584 +@publishedAll 
   1.585 +@released
   1.586 +*/
   1.587 +EXPORT_C void CFbsTypefaceStore::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
   1.588 +	{
   1.589 +	__ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) );
   1.590 +	TSize pixelSize;
   1.591 +	GetPixelSizeInTwips(pixelSize);
   1.592 +	TPckgBuf<TSize> sizePkg(pixelSize);
   1.593 +	TPckgBuf<TTypefaceSupport> tfi;
   1.594 +	TIpcArgs args(aTypefaceIndex,&tfi, &sizePkg);
   1.595 +	iFbs->SendCommand(EFbsMessTypefaceSupport,args);
   1.596 +	aTypefaceSupport=tfi();
   1.597 +	}
   1.598 +
   1.599 +/** Gets the height of the font with specified height and typeface indices, in 
   1.600 +twips.
   1.601 +The value returned is rounded up or down to the nearest font height in twips.
   1.602 +
   1.603 +If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. 
   1.604 +If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 
   1.605 +then the function returns 0. If aHeightIndex is greater than the number of 
   1.606 +heights then the function returns the biggest height. 
   1.607 +
   1.608 +@param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
   1.609 +@param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). 
   1.610 +Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). 
   1.611 +@return The height of the font, in twips.
   1.612 +@see CTypefaceStore::FontHeightInTwips()
   1.613 +@publishedAll 
   1.614 +@released
   1.615 +*/
   1.616 +EXPORT_C TInt CFbsTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
   1.617 +	{
   1.618 +	return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInTwips);
   1.619 +	}
   1.620 +
   1.621 +/** Gets the height of the font with specified height and typeface indices, in 
   1.622 +pixels.
   1.623 +The value returned is rounded up or down to the nearest font height in pixels.
   1.624 +
   1.625 +If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. 
   1.626 +If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 
   1.627 +then the function returns 0. If aHeightIndex is greater than the number of 
   1.628 +heights then the function returns the biggest height. 
   1.629 +
   1.630 +@param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). 
   1.631 +@param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). 
   1.632 +Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). 
   1.633 +@return The height of the font, in pixels.
   1.634 +@publishedAll 
   1.635 +@released
   1.636 +*/
   1.637 +EXPORT_C TInt CFbsTypefaceStore::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const
   1.638 +	{
   1.639 +	return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInPixels);
   1.640 +	}
   1.641 +
   1.642 +TInt CFbsTypefaceStore::FontHeight(TInt aTypefaceIndex,TInt aHeightIndex,TInt aMessage) const
   1.643 +	{
   1.644 +	__ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) );
   1.645 +	TSize pixelSize;
   1.646 +	GetPixelSizeInTwips(pixelSize);
   1.647 +	TPckgBuf<TSize> sizePkg(pixelSize);
   1.648 +	TIpcArgs args(aTypefaceIndex, aHeightIndex, &sizePkg);
   1.649 +	return iFbs->SendCommand(aMessage, args);
   1.650 +	}
   1.651 +
   1.652 +/** Gets the default anti-aliasing setting for scalable fonts.
   1.653 +@return Indicates whether or not scalable fonts should be drawn using 
   1.654 +anti-aliasing.
   1.655 +@publishedAll 
   1.656 +@released
   1.657 +*/
   1.658 +EXPORT_C TGlyphBitmapType CFbsTypefaceStore::DefaultBitmapType() const
   1.659 +	{
   1.660 +	return (TGlyphBitmapType)iFbs->SendCommand(EFbsMessGetDefaultGlyphBitmapType);
   1.661 +	}
   1.662 +
   1.663 +/** Sets the default anti-aliasing setting for scalable fonts. Unless this 
   1.664 +default setting is overridden so that a font is explicitly requested with 
   1.665 +anti-aliasing turned on or off, (see TOpenFontSpec::SetBitmapType() or 
   1.666 +TFontStyle::SetBitmapType()), fonts will use the default setting. The default 
   1.667 +setting would typically only be changed via the Control Panel. The new setting 
   1.668 +affects fonts requested after the change has been made.
   1.669 +There is currently no anti-aliasing support for bitmapped fonts.
   1.670 +@param aType Indicates whether or not scalable fonts should be drawn using 
   1.671 +anti-aliasing.
   1.672 +@see TOpenFontSpec::SetBitmapType()
   1.673 +@see TFontStyle::SetBitmapType()
   1.674 +@publishedAll 
   1.675 +@released
   1.676 +*/
   1.677 +EXPORT_C void CFbsTypefaceStore::SetDefaultBitmapType(TGlyphBitmapType aType) const
   1.678 +	{
   1.679 +	iFbs->SendCommand(EFbsMessSetDefaultGlyphBitmapType,aType);
   1.680 +	}
   1.681 +
   1.682 +/** Sets an alias for a font name.
   1.683 +
   1.684 +If a requested font cannot be found and its name occurs in the alias list
   1.685 +then it will be searched for again using the font name corresponding to
   1.686 +that alias. If an empty font name is passed then the alias will be removed
   1.687 +the list.
   1.688 +@param  TDesC& The font name alias to set.
   1.689 +@param TDesC&  The actual font name to use for this alias. May be empty.
   1.690 +@publishedAll 
   1.691 +@released
   1.692 +*/
   1.693 +EXPORT_C void CFbsTypefaceStore::SetFontNameAliasL(const TDesC& aFontAlias,const TDesC& aFontName) const
   1.694 +	{
   1.695 +	TIpcArgs args(&aFontAlias,aFontAlias.Length(),&aFontName,aFontName.Length());
   1.696 +	User::LeaveIfError(iFbs->SendCommand(EFbsMessFontNameAlias,args));
   1.697 +	}
   1.698 +
   1.699 +/** Specifies the default language with which font metrics calculation will be based on.
   1.700 +The default language will be used if none is set on the font specification.
   1.701 +@publishedAll 
   1.702 +@released
   1.703 +@see TFontSpec::SetScriptTypeForMetrics
   1.704 +*/
   1.705 +EXPORT_C void CFbsTypefaceStore::SetDefaultLanguageForMetrics(TLanguage aLanguage) const
   1.706 +	{
   1.707 +	iFbs->SendCommand(EFbsMessDefaultLanguageForMetrics, aLanguage);
   1.708 +	}
   1.709 +
   1.710 +/**
   1.711 +Unload all fonts loaded from RAM or removable media
   1.712 +@internalTechnology
   1.713 +@deprecated
   1.714 +*/
   1.715 +EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL()
   1.716 +	{
   1.717 +	User::Leave(KErrNotSupported);
   1.718 +	}
   1.719 +
   1.720 +/**
   1.721 +Unload all fonts (of specified type) loaded from named drive
   1.722 +@internalTechnology
   1.723 +*/
   1.724 +EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aDrive*/, TBool /*aAllFonts*/)
   1.725 +	{
   1.726 +	User::Leave(KErrNotSupported);
   1.727 +	}
   1.728 +
   1.729 +/**
   1.730 +Unload the named font file
   1.731 +@internalTechnology
   1.732 +*/
   1.733 +EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aFileName*/)
   1.734 +	{
   1.735 +	User::Leave(KErrNotSupported);
   1.736 +	}
   1.737 +
   1.738 +/** Reset the twips cache.
   1.739 +
   1.740 +The Typeface Store remembers font matches found through GetNearestFont...InTwips() family 
   1.741 +of functions in a cache for quicker matching.  This function empties the cache, and should be
   1.742 +called after the screen mode is changed as the Twips to pixels relationship may have changed.
   1.743 +@publishedAll
   1.744 +*/
   1.745 +EXPORT_C void CFbsTypefaceStore::ReleaseTwipsCache()
   1.746 +	{
   1.747 +	if(iTwipsCache)
   1.748 +		{
   1.749 +		CFont* font=iTwipsCache->RemoveFirstEntry();
   1.750 +		while(font!=NULL)
   1.751 +			{
   1.752 +			ReleaseFont(font);
   1.753 +			font=iTwipsCache->RemoveFirstEntry();
   1.754 +			}
   1.755 +		}
   1.756 +	}
   1.757 +
   1.758 +/**
   1.759 +Sets the system default font typeface. This font will be used when finding the nearest font and the font specified is
   1.760 +an empty descriptor.
   1.761 +If the system default font is not set, then the default behaviour is to find the nearest match.
   1.762 +
   1.763 +@capability WriteDeviceData
   1.764 +@param aFontTypefacename is the font typeface to use as the system default. A font alias cannot be used.
   1.765 +*/
   1.766 +EXPORT_C void CFbsTypefaceStore::SetSystemDefaultTypefaceNameL(const TDesC& aFontTypefaceName)
   1.767 +	{
   1.768 +	if (aFontTypefaceName.Length() <= KMaxTypefaceNameLength)
   1.769 +		{
   1.770 +		TIpcArgs args(&aFontTypefaceName);
   1.771 +		User::LeaveIfError(iFbs->SendCommand(EFbsSetSystemDefaultTypefaceName, args));		
   1.772 +		}
   1.773 +	else
   1.774 +		User::Leave(KErrTooBig);	// Typeface name is too large
   1.775 +	}
   1.776 +
   1.777 +/**
   1.778 +Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
   1.779 +@capability ECapabilityWriteDeviceData
   1.780 +@publishedPartner
   1.781 +@released
   1.782 +@param aLinkedTypefaceSpec  The typeface specification to be added.  Ownership is not transferred.
   1.783 +@param aId A unique identifier
   1.784 +@return A global error code
   1.785 +@see CLinkedTypefaceSpecification
   1.786 +@deprecated
   1.787 +*/
   1.788 +EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& /*aLinkedTypefaceSpec*/, TInt& /*aId*/)
   1.789 +	{
   1.790 +	return KErrNotSupported;
   1.791 +	}
   1.792 +
   1.793 +/**
   1.794 +	Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
   1.795 +	@capability ECapabilityWriteDeviceData
   1.796 +	@publishedPartner
   1.797 +	@released
   1.798 +	@param aLinkedTypefaceSpec.  The typeface specification to be added.  Ownership is not transferred.
   1.799 +	@return a global error code
   1.800 +	@see CLinkedTypefaceSpecification
   1.801 +	*/
   1.802 +EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
   1.803 +	{
   1.804 +	__ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection));
   1.805 +	
   1.806 +	// send the name
   1.807 +	TPckgBuf <TLinkedTypefaceSpecificationArgs> pckgbuf;
   1.808 +	TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf();
   1.809 +	
   1.810 +	typefaceArgs = aLinkedTypefaceSpec;
   1.811 +
   1.812 +	TIpcArgs args(&pckgbuf,sizeof(TPckgBuf <TLinkedTypefaceSpecificationArgs>));
   1.813 +	
   1.814 +	return iFbs->SendCommand(EFbsMessRegisterLinkedTypeface,args);
   1.815 +	}
   1.816 +/**
   1.817 +Function to retrieve a linked typeface specification from the installed rasterizer.
   1.818 +If there is not a rasterizer present supporting font linking then KErrNotSupported will be returned.
   1.819 +The rasterizer is name specified within the passed specification and fills in the elements and
   1.820 +groups if the typeface exists.
   1.821 +
   1.822 +	@param CLinkedTypefaceSpecificaion& The typeface Specification with the name set to be the typeface to be retrieved.
   1.823 +	
   1.824 +	@leave KErrNoMemory if there is insufficient memory available
   1.825 +	@leave KErrServerTerminated if the server no longer present 
   1.826 +	@leave KErrServerBusy if there are no message slots available  
   1.827 + */
   1.828 +EXPORT_C void CFbsTypefaceStore::GetLinkedTypefaceL(CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
   1.829 +	{
   1.830 +	TBuf<KMaxTypefaceNameLength> linkedName = aLinkedTypefaceSpec.Name();
   1.831 +	
   1.832 +	TLinkedTypefaceSpecificationArgs returnSpec;
   1.833 +	TPckgBuf<TLinkedTypefaceSpecificationArgs> specPkg;
   1.834 +	
   1.835 +	TIpcArgs args;
   1.836 +	args.Set(0,&linkedName);
   1.837 +	args.Set(2,&specPkg);
   1.838 +
   1.839 +	User::LeaveIfError(iFbs->SendCommand(EFbsMessFetchLinkedTypeface, args));
   1.840 +	
   1.841 +	aLinkedTypefaceSpec.Clear();
   1.842 +	returnSpec = specPkg();
   1.843 +	
   1.844 +	TInt i;
   1.845 +	for (i = 0 ; i < returnSpec.iGroupSize ; i++)
   1.846 +		{
   1.847 +		CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(returnSpec.iGroups[i].iGroupId);
   1.848 +		grp->SetBaselineShift(returnSpec.iGroups[i].iBaselineShift);
   1.849 +		grp->SetScalingOption(returnSpec.iGroups[i].iScalingOption);
   1.850 +		grp->SetBoldnessPercentage(returnSpec.iGroups[i].iBoldnessPercentage);
   1.851 +		grp->SetItalicAngle(returnSpec.iGroups[i].iItalicAngle);
   1.852 +		aLinkedTypefaceSpec.AddLinkedTypefaceGroupL(*grp);
   1.853 +		CleanupStack::Pop(grp);
   1.854 +		}
   1.855 +	for (i = 0 ; i < returnSpec.iSize ; i++)
   1.856 +		{
   1.857 +		CLinkedTypefaceElementSpec* ele = CLinkedTypefaceElementSpec::NewLC(returnSpec.iTypefaces[i].iName, returnSpec.iTypefaces[i].iGroupId);
   1.858 +		ele->SetCanonical(returnSpec.iTypefaces[i].iIsCanonical);
   1.859 +		aLinkedTypefaceSpec.AddTypefaceAtBackL(*ele);
   1.860 +		CleanupStack::Pop(ele);
   1.861 +		}
   1.862 +	}
   1.863 +
   1.864 +/**
   1.865 +Function to update an existing linked typeface with a new specification. If successful a temporary file is generated and this will replace the
   1.866 +linked font after a reboot. Calls to FetchLinkedTypefaceSpecificationL will return the currently loaded linked font spec and not the
   1.867 +updated specification. 
   1.868 +
   1.869 +@param aLinkedTypefaceSpec A new linked font specification to replace an existing file
   1.870 +
   1.871 +@panic EFbsPanicNoConnection There is no connection to FontBitmap Server
   1.872 +
   1.873 +@return TInt One of the system wide error codes
   1.874 +*/
   1.875 +EXPORT_C TInt CFbsTypefaceStore::UpdateLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec)
   1.876 +	{
   1.877 +	__ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection));
   1.878 +
   1.879 +	TPckgBuf <TLinkedTypefaceSpecificationArgs> pckgbuf;
   1.880 +	TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf();
   1.881 +	
   1.882 +	typefaceArgs = aLinkedTypefaceSpec;
   1.883 +
   1.884 +	TIpcArgs args(&pckgbuf,sizeof(TPckgBuf <TLinkedTypefaceSpecificationArgs>));
   1.885 +	
   1.886 +	return iFbs->SendCommand(EFbsMessUpdateLinkedTypeface,args);
   1.887 +	}
   1.888 +