os/graphics/fbs/fontandbitmapserver/sfbs/FBSFONT.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-2010 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 <fntstore.h>
    17 #include <fbs.h>
    18 #include <openfont.h>
    19 #include <graphics/shapeimpl.h>
    20 #include "UTILS.H"
    21 #include <graphics/shaperparams.h>
    22 #include "FbsMessage.H"
    23 #include <graphics/gdi/gdiconsts.h>
    24 #include <graphics/gdi/gdistructs.h>
    25 
    26 GLREF_C void Panic(TFbsPanic aPanic);
    27 
    28 /** Helper function for converting a pointer to an offset from the passed
    29 heap base. Use OffsetToPointer() to convert the returned offset back to a
    30 useable pointer.
    31 @param aAny A pointer to be converted to an offset.
    32 @param aHeapBase A pointer to the heap base of the current process.
    33 @return An offset representing the passed pointer that can be converted
    34 back to a pointer using the function OffsetToPointer(). 
    35 @see OffsetToPointer()
    36  */
    37 LOCAL_C TInt PointerToOffset(const TAny* aAny, TUint8* aHeapBase)
    38 	{
    39 	if (aAny && aHeapBase)
    40 		{
    41 		return reinterpret_cast<TInt>(aAny) - reinterpret_cast<TInt>(aHeapBase);
    42 		}
    43 	return 0;
    44 	}
    45 
    46 /** Helper function for converting an offset (that was calculated using
    47 PointerToOffset()) back to a pointer relative to the passed heap base.
    48 @param aOffset The offset to be converted to a pointer.
    49 @param aHeapBase A pointer to the heap base of the current process.
    50 @return A pointer relative to the passed heap base.
    51 @see PointerToOffset()
    52  */
    53 LOCAL_C TAny* OffsetToPointer(TInt aOffset, TUint8* aHeapBase)
    54 	{
    55 	if (aOffset && aHeapBase)
    56 		{
    57 		return reinterpret_cast<TAny*>(aOffset + reinterpret_cast<TInt>(aHeapBase));
    58 		}
    59 	return NULL;
    60 	}
    61 
    62 EXPORT_C CFbsFont::CFbsFont():
    63 	CFont(),
    64 	iFbs(RFbsSession::GetSession()),
    65 	iAddressPointer(NULL),
    66 	iHandle(0),
    67 	iServerHandle(0)
    68 	{
    69 	}
    70 	
    71 EXPORT_C CFbsFont::CFbsFont(const CFbsFont& aFont):
    72 	CFont(),
    73 	iFbs(aFont.iFbs),
    74 	iAddressPointer(NULL),
    75 	iHandle(0),
    76 	iServerHandle(0)
    77 	{
    78 	}
    79 	
    80 EXPORT_C CFbsFont::~CFbsFont()
    81 	{
    82 	Reset();
    83 	}
    84 	
    85 EXPORT_C void CFbsFont::Reset()
    86 	{
    87 	if (iHandle)
    88 	    {
    89 		iFbs->SendCommand(EFbsMessClose,iHandle);
    90 	    }
    91 	iHandle = 0;
    92 	}
    93 	
    94 EXPORT_C CBitmapFont* CFbsFont::Address() const
    95 	{
    96 	__ASSERT_DEBUG(iHandle != NULL,Panic(EFbsFontAddressViolation));
    97 	__ASSERT_DEBUG(iAddressPointer != NULL,Panic(EFbsFontAddressViolation));
    98 	return iAddressPointer;
    99 	}
   100 
   101 /** Duplicates a font.
   102 This function does not create a copy of the font. It just assigns another 
   103 handle to the bitmap in the font and bitmap server, and sets this object's 
   104 handle to that.
   105 
   106 @param aFontHandle The handle to an existing CFbsFont.
   107 @return KErrNone if successful; KErrCouldNotConnect if no connection to the 
   108 font and bitmap server could be made; KErrUnknown if no font could be found 
   109 with the specified handle number.
   110 @publishedAll
   111 @released
   112 */
   113 EXPORT_C TInt CFbsFont::Duplicate(TInt aFontHandle)
   114 	{
   115 	if (!iFbs)
   116 		return KErrCouldNotConnect;
   117 	if (!aFontHandle)
   118 		return KErrUnknown;
   119 	// close any existing handle
   120 	Reset();	
   121 	// ask server to create the duplicate handle
   122 	TPckgBuf<TFontInfo> tfpckg;
   123 	TIpcArgs args(aFontHandle,&tfpckg);
   124 	TInt ret = iFbs->SendCommand(EFbsMessFontDuplicate,args);
   125 	if (ret != KErrNone || !tfpckg().iHandle)
   126 		return ret;
   127 	// created
   128 	iHandle = tfpckg().iHandle;
   129 	iServerHandle = tfpckg().iServerHandle;
   130 	iAddressPointer = (CBitmapFont*)(iFbs->HeapBase()+tfpckg().iAddressOffset);
   131 	return KErrNone;
   132 	}
   133 
   134 /** Gets the Font and Bitmap server handle of the font.
   135 @return The handle of the font. 
   136 @publishedAll
   137 @released
   138 */
   139 EXPORT_C TInt CFbsFont::Handle() const
   140 	{
   141 	if (!iHandle)
   142 		{
   143 		return 0;
   144 		}
   145 	return iServerHandle;
   146 	}
   147 
   148 /** Gets how much of the specified descriptor can be displayed in this font without 
   149 exceeding the specified width.
   150 
   151 Note:
   152 This function does not display any of the descriptor itself.  It is used 
   153 before display, to test whether the whole descriptor can be displayed.
   154 @param aText The descriptor. 
   155 @param aWidthInPixels The available width for character display 
   156 @return The number of characters (starting from the beginning of the descriptor) 
   157 which will be able to be displayed without exceeding the specified width. 
   158 @see CFont::TextCount() 
   159 @publishedAll 
   160 @released
   161 */
   162 EXPORT_C TInt CFbsFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels) const
   163 	{
   164 	TInt dummy;
   165 	return DoTextCount(aText, aWidthInPixels, dummy);
   166 	}
   167 
   168 /** Gets how much of the specified descriptor can be displayed in this font without 
   169 exceeding the specified width.
   170 It also returns the excess width defined as the specified available width 
   171 minus the width of the portion of the descriptor which can be displayed without 
   172 exceeding the available width.
   173 @param aText The descriptor. 
   174 @param aWidthInPixels The available width for character display. 
   175 @param aExcessWidthInPixels The excess width after displaying the portion of 
   176 the descriptor, in pixels. 
   177 @return The number of characters (starting from the beginning of the descriptor) 
   178 which will be able to be displayed without exceeding the specified width. 
   179 @see CFont::TextCount()
   180 @see TextCount() 
   181 @publishedAll 
   182 @released
   183 */
   184 EXPORT_C TInt CFbsFont::DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidth) const
   185 	{
   186 	TMeasureTextInput input;
   187 	input.iMaxAdvance = aWidthInPixels;
   188 	TMeasureTextOutput output;
   189 	aExcessWidth = aWidthInPixels - MeasureText(aText,&input,&output);
   190 	return output.iChars;
   191 	}
   192 
   193 /** Gets the width of the specified character in this font, in pixels.
   194 
   195 Note: For OpenType fonts this function returns the horizontal advance of
   196 the character, which may be different from the actual width.
   197 
   198 @param aChar The character whose width should be determined. 
   199 @return The width of the specified character in this font, in pixels. 
   200 @see CFont::CharWidthInPixels() 
   201 @publishedAll 
   202 @released
   203 */
   204 EXPORT_C TInt CFbsFont::DoCharWidthInPixels(TChar aChar) const
   205 	{
   206 	TOpenFontCharMetrics metrics;
   207 	const TUint8* bitmap;
   208 	TSize size;
   209 	if (GetCharacterData(aChar,metrics,bitmap,size) != ENoCharacterData)
   210 		{
   211 		return metrics.HorizAdvance();
   212 		}
   213 	return 0;
   214 	}
   215 
   216 /** Gets the width of the specified descriptor when displayed in this font, in 
   217 pixels.
   218 @param aText The descriptor whose width should be determined. 
   219 @return The width of the specified descriptor when displayed in this font, 
   220 in pixels 
   221 @see CFont::TextWidthInPixels() 
   222 @publishedAll 
   223 @released
   224 */
   225 EXPORT_C TInt CFbsFont::DoTextWidthInPixels(const TDesC& aText) const
   226 	{
   227 	TMeasureTextInput* dummy = NULL;
   228 	return DoTextWidthInPixels(aText,dummy);
   229 	}
   230 
   231 /** Gets the width of the specified descriptor when displayed in this font, in 
   232 pixels.
   233 @param aText The descriptor whose width should be determined. 
   234 @param aParam Parameter block that controls how much of aText is measured
   235 @return The width of the specified descriptor when displayed in this font, 
   236 in pixels 
   237 */
   238 TInt CFbsFont::DoTextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam) const
   239 	{
   240 	TMeasureTextOutput output;
   241 	TInt advance_width = MeasureText(aText,aParam,&output);
   242 	return Max(advance_width,output.iBounds.Width());
   243 	}
   244 
   245 /** Gets the width of the specified descriptor when displayed in this font, in 
   246 pixels. Override of the base class to resolve name clash with other
   247 TextWidthInPixels variant.
   248 @param aText The descriptor whose width should be determined. 
   249 @return The width of the specified descriptor when displayed in this font, 
   250 in pixels 
   251 @see CFont::TextWidthInPixels() 
   252 @publishedAll 
   253 @released
   254 */
   255 EXPORT_C TInt CFbsFont::TextWidthInPixels(const TDesC& aText) const
   256 	{
   257 	return DoTextWidthInPixels(aText);
   258 	}
   259 
   260 /** Gets the width of the specified descriptor when displayed in this font, in 
   261 pixels. Override of the base class to resolve name clash with other
   262 TextWidthInPixels variant.
   263 @param aText The descriptor whose width should be determined. 
   264 @param aParam Parameter block that controls how much of aText is measured
   265 @return The width of the specified descriptor when displayed in this font, 
   266 in pixels 
   267 @see CFont::TextWidthInPixels() 
   268 @publishedAll 
   269 @released
   270 */
   271 EXPORT_C TInt CFbsFont::TextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam) const
   272 	{
   273 	return DoTextWidthInPixels(aText,aParam);
   274 	}
   275 
   276 /** Gets the text width, move and adjusts of the specified descriptor when displayed 
   277 in this font.
   278 @param aText The descriptor whose width should be determined. 
   279 @param aCharWidth The width of the specified descriptor when displayed in this 
   280 font, in pixels (including information on the width, move and adjusts of the 
   281 descriptor). 
   282 @publishedAll 
   283 @released
   284 */
   285 EXPORT_C void CFbsFont::TextWidthInPixels(const TDesC& aText,SCharWidth& aCharWidth) const
   286 	{
   287 	TMeasureTextInput* dummy = NULL;
   288 	TextWidthInPixels(aText,dummy,aCharWidth);
   289 	}
   290 
   291 /** Gets the text width, move and adjusts of the specified descriptor when displayed 
   292 in this font.
   293 @param aText The descriptor whose width should be determined. 
   294 @param aParam Parameter block that controls how much of aText is measured
   295 @param aCharWidth The width of the specified descriptor when displayed in this 
   296 font, in pixels (including information on the width, move and adjusts of the 
   297 descriptor). 
   298 @publishedAll 
   299 @released
   300 */
   301 EXPORT_C void CFbsFont::TextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam, SCharWidth& aCharWidth) const
   302 	{
   303 	TMeasureTextOutput output;
   304 	aCharWidth.iMove = MeasureText(aText,aParam,&output);
   305 	aCharWidth.iLeftAdjust = output.iBounds.iTl.iX;
   306 	aCharWidth.iRightAdjust = aCharWidth.iMove - output.iBounds.iBr.iX;
   307 	aCharWidth.iWidth = output.iBounds.Width();
   308 	}
   309 
   310 /** Gets the raw width of the text in the descriptor, in pixels. 
   311  DEPRECATED: Same as MeasureText(const TDesC&).
   312 This is the width of the text without adjusting for side bearings, algorithmic 
   313 style etc.
   314 @deprecated
   315 @param aText Any text descriptor (TPtrC, TPtr, _LIT, TBuf etc.). 
   316 @return The width (in pixels) of the text in the descriptor. */
   317 EXPORT_C TInt CFbsFont::RawTextWidthInPixels(const TDesC& aText) const
   318 	{
   319 	return MeasureText(aText);
   320 	}
   321 
   322 /** Gets the baseline offset, in pixels.
   323 The offset is how far a font is raised or lowered from its normal baseline.
   324 @return Offset from normal baseline, in pixels. 
   325 @see CFont::BaselineOffsetInPixels() 
   326 @publishedAll 
   327 @released
   328 */
   329 EXPORT_C TInt CFbsFont::DoBaselineOffsetInPixels() const
   330 	{
   331 	if (!iHandle)
   332 		return 0;
   333 	return Address()->iAlgStyle.iBaselineOffsetInPixels;
   334 	}
   335 
   336 /** Gets the width of the widest character in this font, in pixels.
   337 @return The width of the maximum width character, in pixels. 
   338 @see CFont::MaxCharWidthInPixels() 
   339 @publishedAll 
   340 @released
   341 */
   342 EXPORT_C TInt CFbsFont::DoMaxCharWidthInPixels() const
   343 	{
   344 	if (!iHandle)
   345 		return 0;
   346 	TInt width = Address()->CBitmapFont::DoMaxCharWidthInPixels();
   347 	if (Address()->iAlgStyle.IsBold())
   348 		width += Address()->iAlgStyle.WidthFactor();
   349 	return width;
   350 	}
   351 
   352 /** Gets the width of the widest normal character in this font, in pixels.
   353 Normal characters include all character in a character set except non-alphabetic 
   354 characters (e.g. the copyright symbol, or a block graphics symbol, for example).
   355 @return The width of the maximum width normal character, in pixels. 
   356 @see CFont::MaxNormalCharWidthInPixels() 
   357 @publishedAll 
   358 @released
   359 */
   360 EXPORT_C TInt CFbsFont::DoMaxNormalCharWidthInPixels() const
   361 	{
   362 	if (!iHandle)
   363 		return 0;
   364 	TInt width = Address()->CBitmapFont::DoMaxNormalCharWidthInPixels();
   365 	if (Address()->iAlgStyle.IsBold())
   366 		width += Address()->iAlgStyle.WidthFactor();
   367 	return width;
   368 	}
   369 
   370 /** Gets the font height in pixels.
   371 @return The font height in pixels.
   372 @see CFont::HeightInPixels() 
   373 @publishedAll 
   374 @released
   375 */
   376 EXPORT_C TInt CFbsFont::DoHeightInPixels() const
   377 	{
   378 	if (!iHandle)
   379 		return 0;
   380 	return Address()->CBitmapFont::DoHeightInPixels();
   381 	}
   382 
   383 /** Gets the font ascent in pixels.
   384 @return The font ascent in pixels.
   385 @see CFont::AscentInPixels() 
   386 @publishedAll 
   387 @released
   388 */
   389 EXPORT_C TInt CFbsFont::DoAscentInPixels() const
   390 	{
   391 	if (!iHandle)
   392 		return 0;
   393 	return Address()->CBitmapFont::DoAscentInPixels();
   394 	}
   395 
   396 /** Gets the font specification of this font in twips.
   397 @return The font specification of this font (in twips). 
   398 @see CFont::FontSpecInTwips() 
   399 @publishedAll 
   400 @released
   401 */
   402 EXPORT_C TFontSpec CFbsFont::DoFontSpecInTwips() const
   403 	{
   404 	TFontSpec fs;
   405 	if (!iHandle)
   406 		return fs;
   407 	fs = Address()->CBitmapFont::DoFontSpecInTwips();
   408 	TPckgBuf<TInt> tfpckg;
   409 	TIpcArgs args(iHandle,&tfpckg);
   410 	TInt ret = iFbs->SendCommand(EFbsMessGetTwipsHeight,args);
   411 	fs.iHeight = tfpckg();
   412 	return fs;
   413 	}
   414 
   415 /** Gets the character metrics and a pointer to the compressed glyph bitmap for 
   416 the specified character. 
   417 This function is deprecated, because TCharacterMetrics cannot store metrics 
   418 larger than 127 or less than 127  use GetCharacterData() instead.
   419 @param aCode The code for the character to be checked. 
   420 @param aBytes On return, contains a pointer to the compressed glyph bitmap. 
   421 @return The character metrics for the font. 
   422 @publishedAll 
   423 @released
   424 @deprecated
   425 */
   426 EXPORT_C TCharacterMetrics CFbsFont::CharacterMetrics(TInt aCode,const TUint8*& aBytes) const
   427 	{
   428 	TCharacterMetrics metrics;
   429 	// Save time by not converting from TCharacterMetrics to TOpenFontCharMetrics and back if this is a real bitmap font.
   430 	if (iHandle)
   431 		{	
   432  		CBitmapFont* bitmap_font = Address();
   433 
   434  		if (!bitmap_font->IsOpenFont())
   435 			metrics = bitmap_font->CharacterMetrics(aCode,aBytes);
   436 		else
   437 			{
   438 			TOpenFontCharMetrics new_metrics;
   439 			aBytes = NULL;
   440 			TSize size;
   441 			if (GetCharacterData(aCode,new_metrics,aBytes,size) != ENoCharacterData)
   442 				new_metrics.GetTCharacterMetrics(metrics);
   443 			}
   444 		}
   445 	return metrics;
   446 	}
   447 
   448 /** Gets the character metrics and the glyph bitmap. 
   449 @param aCode The character code in Unicode. 
   450 @param aMetrics On return, contains the character metrics. 
   451 @param aBitmap On return, contains a pointer to the compressed glyph bitmap. 
   452 @param aBitmapSize The size of the returned glyph bitmap in pixels. This is 
   453 not necessarily the same as the size implied by the returned metrics, which 
   454 may incorporate algorithmic multiplication. 
   455 @publishedAll 
   456 @released
   457 */
   458 EXPORT_C CFont::TCharacterDataAvailability CFbsFont::DoGetCharacterData(TUint aCode,TOpenFontCharMetrics& aMetrics,
   459 		const TUint8*& aBitmap,TSize& aBitmapSize) const
   460 	{
   461 	aBitmap = NULL;
   462 	if (!iHandle)
   463 		return CFont::ENoCharacterData;
   464 
   465 	CBitmapFont* bitmap_font = Address();
   466 
   467 	if (!bitmap_font->GetCharacterData(iFbs->ServerSessionHandle(),aCode,aMetrics,aBitmap))
   468 		{
   469 		TPckgBuf<TRasterizeParams> paramsBuf;
   470 		TIpcArgs args(iHandle, aCode, &paramsBuf);
   471 		
   472 		if(iFbs->SendCommand(EFbsMessRasterize, args))
   473 			{				
   474 			// Translate the offsets sent to the server back to pointers relative to
   475 			// the heap base of the current process
   476 			const TOpenFontCharMetrics* metrics = (const TOpenFontCharMetrics*)OffsetToPointer(paramsBuf().iMetricsOffset, iFbs->HeapBase());
   477 			if (metrics)
   478 				{
   479 				aMetrics = *metrics;
   480 				}
   481 			aBitmap = static_cast<TUint8*>(OffsetToPointer(paramsBuf().iBitmapPointerOffset, iFbs->HeapBase()));			
   482 			}
   483 		else
   484 			{
   485 			return CFont::ENoCharacterData;
   486 			}
   487 		}
   488 
   489 	aBitmapSize.SetSize(aMetrics.Width(),aMetrics.Height());
   490 
   491 	if (!bitmap_font->IsOpenFont())
   492 		{
   493 		TAlgStyle null_style;
   494 		if (!(bitmap_font->iAlgStyle == null_style))
   495 			{
   496 			const int width_factor = bitmap_font->iAlgStyle.WidthFactor();
   497 			const int height_factor = bitmap_font->iAlgStyle.HeightFactor();
   498 			const int bold_addition =	bitmap_font->iAlgStyle.IsBold() ? width_factor : 0;
   499 			const int italic_addition = bitmap_font->iAlgStyle.IsItalic() ? width_factor : 0;
   500 
   501 			aMetrics.SetWidth(aMetrics.Width() * width_factor + bold_addition + italic_addition);
   502 			aMetrics.SetHeight(aMetrics.Height() * height_factor);
   503 			aMetrics.SetHorizBearingX(aMetrics.HorizBearingX() * width_factor);
   504 			aMetrics.SetHorizBearingY(aMetrics.HorizBearingY() * height_factor);
   505 			aMetrics.SetVertBearingX(aMetrics.VertBearingX() * width_factor);
   506 			aMetrics.SetVertBearingY(aMetrics.VertBearingY() * height_factor);
   507 			if (bitmap_font->iAlgStyle.IsMono())
   508 				aMetrics.SetHorizAdvance(bitmap_font->CBitmapFont::DoMaxNormalCharWidthInPixels() + bold_addition);
   509 			else
   510 				aMetrics.SetHorizAdvance(aMetrics.HorizAdvance() * width_factor + bold_addition);
   511 			aMetrics.SetVertAdvance(aMetrics.VertAdvance() * height_factor);
   512 			}
   513 		}
   514 	return CFont::EAllCharacterData;
   515 	}
   516 
   517 /** Gets the open font metrics. If the metrics cannot be obtained the function 
   518 returns EFalse.
   519 @param aMetrics On return, contains the font metrics 
   520 @return EFalse if the metrics cannot be obtained 
   521 @publishedAll 
   522 @released
   523 */
   524 EXPORT_C TBool CFbsFont::GetFontMetrics(TOpenFontMetrics& aMetrics) const
   525 	{
   526 	if (iHandle)
   527 		{
   528 		CBitmapFont* bitmap_font = Address();
   529 		bitmap_font->GetFontMetrics(aMetrics);
   530 		return TRUE;
   531 		}
   532 	else
   533 		return FALSE;
   534 	}
   535 
   536 /** Gets the typeface attributes of Open Font System fonts.
   537 Notes: 
   538 Typeface attributes are different from the font metrics; they are not metrics, 
   539 which are different for every different size, but size-independent attributes 
   540 of the typeface, like name and style. 
   541 This function can be used if IsOpenFont() returns true i.e. the font is 
   542 an Open Font.
   543 @param aAttrib On return, contains the typeface attributes. 
   544 @return EFalse if the attributes cannot be obtained, or if the font is not an 
   545 Open Font (IsOpenFont() returns EFalse). 
   546 @publishedAll 
   547 @released
   548 */
   549 EXPORT_C TBool CFbsFont::GetFaceAttrib(TOpenFontFaceAttrib& aAttrib) const
   550 	{
   551 	if (!iHandle)
   552 		{
   553 		return EFalse;
   554 		}
   555 	TPckgBuf<TOpenFontFaceAttrib> package;
   556 	TIpcArgs args(iHandle,&package);
   557 	if (iFbs->SendCommand(EFbsMessFaceAttrib,args))
   558 		{
   559 		aAttrib = package();
   560 		return ETrue;
   561 		}
   562 	return EFalse;
   563 	}
   564 
   565 /** Tests whether the font is an Open Font system font.
   566 Note: 
   567 If this function returns ETrue, the function GetFaceAttrib() will work.
   568 @return ETrue if font is an Open Font system font (e.g. TrueType). EFalse if 
   569 the font is a bitmap font loaded from a GDR file. 
   570 @publishedAll 
   571 @released
   572 */
   573 EXPORT_C TBool CFbsFont::IsOpenFont() const
   574 	{
   575 	if (iHandle)
   576 		{
   577 		CBitmapFont* bitmap_font = Address();
   578 		return bitmap_font->IsOpenFont();
   579 		}
   580 	else
   581 		return FALSE;
   582 	}
   583 
   584 /** Tests whether the font contains a particular character.
   585 @param aCode Character code to be tested. This code is in the code page 1252 
   586 encoding in v5, otherwise it is in Unicode 
   587 @return ETrue if the font contains aCode. 
   588 @publishedAll 
   589 @released
   590 */
   591 EXPORT_C TBool CFbsFont::HasCharacter(TInt aCode) const
   592 	{
   593 	if (iHandle)
   594 		{
   595 		return iFbs->SendCommand(EFbsMessHasCharacter,iHandle,aCode);
   596 		}
   597 	return EFalse;
   598 	}
   599 
   600 
   601 /** help DoExtendedFunction to perform KFontGetShaping function
   602 @param aParam Input & output parameter block, 
   603 if successful aParam->iShapeHeaderOutput points to the shape data.
   604 @return KErrNone if successful, otherwise a system wide error code.
   605 */
   606 TInt CFbsFont::DoFontGetShaping(TFontShapeFunctionParameters* aParam) const
   607 	{
   608 	if (!iHandle)
   609 		{
   610 		return KErrGeneral;
   611 		}
   612 	TPckgBuf<TShapeMessageParameters> sp;
   613 	sp().iStart = aParam->iStart;
   614 	sp().iEnd = aParam->iEnd;
   615 	sp().iScript = aParam->iScript;
   616 	sp().iLanguage = aParam->iLanguage;
   617 
   618 	TInt offset = iFbs->SendCommand( EFbsMessShapeText,TIpcArgs(iHandle, aParam->iText, &sp));
   619 
   620 	// Convert the returned offset to pointer relative to the heap base of the current process
   621 	aParam->iShapeHeaderOutput = reinterpret_cast<const TShapeHeader*>(OffsetToPointer(offset, iFbs->HeapBase()));
   622 	return aParam->iShapeHeaderOutput? KErrNone : KErrGeneral;
   623 	}
   624 
   625 
   626 /** help DoExtendedFunction to perform KFontDeleteShaping function
   627 @param aParam Input parameter block
   628 @return KErrNone if successful, KErrGeneral if the font does not have a valid handle.
   629 */
   630 TInt CFbsFont::DoFontDeleteShaping(TFontShapeDeleteFunctionParameters* aParam) const
   631 	{
   632 	if (!iHandle)
   633 		{
   634 		return KErrGeneral;
   635 		}
   636 	// Convert the address of the shape header to an offset from the heap base
   637 	// of this process before the offset is sent to the server
   638 	iFbs->SendCommand(EFbsMessShapeDelete,iHandle,PointerToOffset(aParam->iShapeHeader, iFbs->HeapBase()));
   639 	return KErrNone;
   640 	}
   641 
   642 
   643 TInt CFbsFont::DoGetFontTable(TGetFontTableParam* aParam) const
   644     {
   645     TInt ret = KErrGeneral;
   646 
   647     TPckgBuf<TOffsetLen> retBuf;
   648     ret = iFbs->SendCommand(EFbsMessGetFontTable, 
   649             TIpcArgs(iHandle, aParam->iTag, &retBuf));
   650     
   651     if (KErrNone == ret)
   652         {
   653         aParam->iLength = retBuf().iLen;
   654         aParam->iContent = OffsetToPointer(retBuf().iOffset, iFbs->HeapBase());
   655         }
   656     return ret;
   657     }
   658 
   659 
   660 TInt CFbsFont::DoGetGlyphOutline(TGetGlyphOutlineParam* aParam) const
   661     {
   662     TInt ret = KErrGeneral;
   663     
   664     TPckgBuf<TFBSGlyphOutlineParam> paramsBuf;
   665     TInt count = aParam->iCount;
   666     paramsBuf().iCount = aParam->iCount;
   667     paramsBuf().iHinted = aParam->iHinted;
   668     paramsBuf().iHandle = iHandle;
   669 
   670     TOffsetLen* offsetLen = (TOffsetLen *)User::Alloc(count * sizeof(TOffsetLen));
   671     if (NULL == offsetLen)
   672         {
   673         return KErrNoMemory;
   674         }
   675     TPtr8 retBuf((TUint8 *)offsetLen, count * sizeof(TOffsetLen),
   676             count * sizeof(TOffsetLen));
   677     TPtr8 codes((TUint8 *)(aParam->iCodes), count * sizeof(TUint), 
   678             count * sizeof(TUint));
   679     
   680     ret = iFbs->SendCommand( EFbsMessGetGlyphOutline, 
   681             TIpcArgs(&paramsBuf, &codes, &retBuf));
   682     
   683     if (KErrNone == ret)
   684         {
   685         // server writes the offsets back to client, convert them
   686         // to local pointers.
   687         for (TInt i = 0; i < aParam->iCount; ++i)
   688             {
   689             aParam->iOutlines[i] = OffsetToPointer(offsetLen[i].iOffset, 
   690                     iFbs->HeapBase());
   691             aParam->iLengths[i] = offsetLen[i].iLen;
   692             }
   693         }
   694     User::Free(offsetLen);
   695     return ret;
   696     }
   697 
   698 TInt CFbsFont::DoReleaseGlyphOutline(TReleaseGlyphOutlineParam* aParam) const 
   699     {
   700     TInt ret = KErrGeneral;
   701     
   702     TPckgBuf<TFBSGlyphOutlineParam> params;
   703     TInt count = aParam->iCount;
   704     params().iCount = count;
   705     params().iHinted = aParam->iHinted;
   706     params().iHandle = iHandle;
   707 
   708     TPtr8 codes((unsigned char *)aParam->iCodes, count * sizeof(TUint), count * sizeof(TUint));
   709     
   710     ret = iFbs->SendCommand(EFbsMessReleaseGlyphOutline, 
   711             TIpcArgs(&params, &codes));
   712         
   713     return ret;
   714     }   
   715 
   716 TInt CFbsFont::DoReleaseFontTable(TUint32* aParam) const 
   717     {
   718     TInt ret = KErrGeneral;
   719     
   720     ret = iFbs->SendCommand(EFbsMessReleaseFontTable, 
   721             TIpcArgs(iHandle, *aParam));
   722         
   723     return ret;
   724     }   
   725 /** API extension system that enables the caller to access a particular API
   726 extension function. As an overload of this function in a derived class
   727 it calls its immediate parent implementation for any extension function Uid
   728 that it does not recognize and handle.
   729 @param aInterfaceId UID of the required extension function
   730 @param aParam Pointer to an arbitrary parameter block that can be used to
   731 provide and/or return information to/from the particular extension function,
   732 defaults to NULL.
   733 @return Integer return value from extension function, a system wide error code.
   734 @panic FBSCLI 31, in debug builds only, if iExtra is NULL when it must not be.
   735 @panic FBSCLI 38, in debug builds only, if a reserved error code is returned 
   736 	from an extended function.
   737 @internalTechnology
   738 @released
   739 */
   740 EXPORT_C TInt CFbsFont::DoExtendedFunction(TUid aFunctionId, TAny* aParam) const
   741 	{
   742 	if (iHandle)
   743 		{
   744 		if (aFunctionId == KFontGetShaping)
   745 			{
   746 			return DoFontGetShaping(reinterpret_cast<TFontShapeFunctionParameters*>(aParam));
   747 			}
   748 		else if (aFunctionId == KFontDeleteShaping)
   749 			{
   750 			return DoFontDeleteShaping(reinterpret_cast<TFontShapeDeleteFunctionParameters*>(aParam));
   751 			}
   752 		else if ( (aFunctionId == KFontCapitalAscent)
   753 			|| (aFunctionId == KFontMaxAscent)
   754 			|| (aFunctionId == KFontStandardDescent)
   755 			|| (aFunctionId == KFontMaxDescent)
   756 			|| (aFunctionId == KFontLineGap) )
   757 			{
   758 			// Call the version on the CBitmapFont instance
   759 			return Address()->CBitmapFont::DoExtendedFunction(aFunctionId, aParam);
   760 			}
   761 		else if (aFunctionId == KTextInContextWidthInPixelsUid)
   762 			{
   763 			TTextWidthInternal* contextParam = (TTextWidthInternal*)aParam;
   764 			return DoTextWidthInPixels(contextParam->iText,&contextParam->iParam);
   765 			}
   766 		else if (aFunctionId == KFontGetFontTable) 
   767 		    {
   768             return DoGetFontTable(reinterpret_cast<TGetFontTableParam *>(aParam));
   769 		    }
   770 		else if (aFunctionId == KFontGetGlyphOutline)
   771 		    {
   772 		    return DoGetGlyphOutline(reinterpret_cast<TGetGlyphOutlineParam *>(aParam));
   773 		    }
   774 		else if (aFunctionId == KFontReleaseGlyphOutline)
   775 		    {
   776 		    return DoReleaseGlyphOutline(reinterpret_cast<TReleaseGlyphOutlineParam *>(aParam));
   777 		    }
   778 		else if (aFunctionId == KFontReleaseFontTable)
   779             {
   780             return DoReleaseFontTable(reinterpret_cast<TUint32 *>(aParam));
   781             }
   782 		}
   783 	return CFont::DoExtendedFunction(aFunctionId, aParam);
   784 	}
   785