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