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