Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: gdi.h
Link against: gdi.lib

Class CFont

CFont

Support

Supported from 5.0

Description

Abstract font interface.

The CFont class provides a device-independent interface to a device-dependent font usually obtained from a call to GetNearestFont() on a graphics device. It is used as a handle in CGraphicsContext::UseFont() and to obtain device-dependent information about the font — notably the pixel width of a text string.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CFontAbstract font interface

Defined in CFont:
AscentInPixels(), BaselineOffsetInPixels(), CharWidthInPixels(), CodeSection(), DescentInPixels(), EAllCharacterData, ECharacterWidthOnly, EHorizontal, ENoCharacterData, EVertical, FontSpecInTwips(), GetCharacterData(), GetCharacterPosition(), HeightInPixels(), MaxCharWidthInPixels(), MaxNormalCharWidthInPixels(), MeasureText(), NumCodeSections(), TCharacterDataAvailability, TMeasureTextInput, TMeasureTextOutput, TPositionParam, TTextDirection, TextCount(), TextWidthInPixels(), TypeUid(), WidthZeroInPixels()

Inherited from CBase:
operator new()

See also:


Getting general font and typeface information


TypeUid()

virtual TUid TypeUid() const=0;

Description

Gets run-time identity of the actual font type. This enables safe casting to a derived type.

For example, if the derived type is a CFbsFont, the return value is KCFbsFontUid. You would need to cast to a CFbsFont to get a character bounding box. Similarly, a CBitmapFont returns KCBitmapFontUidVal.

Return value

TUid

The font-type identifier.


FontSpecInTwips()

virtual TFontSpec FontSpecInTwips() const=0;

Description

Gets the font specification of this font in twips.

Return value

TFontSpec

The font specification of this font (in twips).

[Top]


Getting font height information


HeightInPixels()

virtual TInt HeightInPixels() const=0;

Description

Gets the height of the font in pixels.

Return value

TInt

The height of the font, in pixels.


AscentInPixels()

virtual TInt AscentInPixels() const=0;

Description

Gets the ascent of the font in pixels.

Return value

TInt

The ascent of the font, in pixels.


DescentInPixels()

virtual TInt DescentInPixels() const;

Description

Gets the descent of the font in pixels.

Return value

TInt

The descent of the font, in pixels.


BaselineOffsetInPixels()

virtual TInt BaselineOffsetInPixels() const=0;

Description

Gets the baseline offset in pixels.

The baseline offset is how far a font is raised or lowered from its normal baseline.

Return value

TInt

Offset from normal baseline, in pixels.

[Top]


Getting font width information


WidthZeroInPixels()

TInt WidthZeroInPixels() const;

Description

Gets the width of the zero character of this font in pixels.

This function is provided as the "0" character is roughly the average width of the characters of any font.

Return value

TInt

The width of the "0" character, in pixels.


CharWidthInPixels()

virtual TInt CharWidthInPixels(TChar aChar) const=0;

Description

Gets the width in pixels in this font of the specified character.

Parameters

TChar aChar

The character whose width should be determined.

Return value

TInt

The width in pixels of the specified character in this font.


MaxCharWidthInPixels()

virtual TInt MaxCharWidthInPixels() const=0;

Description

Gets the width in pixels of the widest character in this font.

Return value

TInt

The width of the maximum width character, in pixels.


MaxNormalCharWidthInPixels()

virtual TInt MaxNormalCharWidthInPixels() const=0;

Description

Gets the width in pixels of the widest normal character in this font.

Normal characters include all character in a character set except non-alphabetic characters (e.g. the copyright symbol, or a block graphics symbol, for example).

Return value

TInt

The width of the maximum width normal character, in pixels.

[Top]


Getting and testing width of descriptors


TextWidthInPixels()

virtual TInt TextWidthInPixels(const TDesC& aText) const=0;

Description

Gets the width in pixels of the specified descriptor when displayed in this font.

Parameters

const TDesC& aText

The descriptor whose width should be determined.

Return value

TInt

The width of the specified descriptor when displayed in this font, in pixels.


TextCount()

virtual TInt TextCount(const TDesC& aText,TInt aWidthInPixels) const=0;

Description

Gets how much of the specified descriptor can be displayed in this font without exceeding the specified width.

Note:

Parameters

const TDesC& aText

The descriptor.

TInt aWidthInPixels

The available width for character display.

Return value

TInt

The number of characters which will be able to be displayed without exceeding the specified width. The count starts from the beginning of the descriptor.


TextCount()

virtual TInt TextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const=0;

Description

Gets how much of the specified descriptor can be displayed in this font without exceeding the specified width.

It also returns the excess width — defined as the specified available width minus the width of the portion of the descriptor which can be displayed without exceeding the available width.

Parameters

const TDesC& aText

The descriptor.

TInt aWidthInPixels

The available width for character display.

TInt& aExcessWidthInPixels

The excess width after displaying the portion of the descriptor, in pixels.

Return value

TInt

The number of characters which will be able to be displayed without exceeding the specified width. The count starts from the beginning of the descriptor.

[Top]


Code sections


NumCodeSections()

virtual TInt NumCodeSections() const=0;

Support

Withdrawn in 6.0

Description

Gets the number of code sections in the font.

A code section defines the bitmaps for characters in a specified range.

This function was removed in version 6.0 because it deals with implementation details of bitmap fonts — these details could not sensibly be provided for by Open Font System fonts.

Return value

TInt

The number of code sections in the font.


CodeSection()

virtual TCodeSection CodeSection(TInt anIndex) const=0;

Support

Withdrawn in 6.0

Description

Gets the code section at the specified index.

A code section defines the bitmaps for characters in a specified range.

This function was removed in version 6.0 because it deals with implementation details of bitmap fonts — these details could not sensibly be provided for by Open Font System fonts.

Parameters

TInt anIndex

The index of the code section to get.

Return value

TCodeSection

The requested code section.

[Top]


Other functions


GetCharacterData()

virtual TCharacterDataAvailability GetCharacterData(TUint aCode,
    TOpenFontCharMetrics& aMetrics, const TUint8*& aBitmap,TSize& aBitmapSize) const;

Support

Supported from 6.0

Description

Gets the character metrics for a character.

Parameters

TUint aCode

The character code.

TOpenFontCharMetrics& aMetrics

On return, contains the character bitmap.

const TUint8*& aBitmap

On return, this points to NULL.

TSize& aBitmapSize

On return, this has a size of (0,0).

Return value

TCharacterDataAvailability

ECharacterWidthOnly


GetCharacterPosition()

virtual TBool GetCharacterPosition(TPositionParam& aParam) const;

Support

Supported from 6.0

Description

Gets the character position parameter.

This function is not intended for general use. It is used for contextual glyph selection, ligature creation and diacritic placement when drawing text in complex scripts.

Parameters

TPositionParam& aParam

On return, contains the character position parameter.

Return value

TBool

ETrue if successful, otherwise EFalse.


MeasureText()

TInt MeasureText(const TDesC& aText, const TMeasureTextInput* aInput = NULL,TMeasureTextOutput* aOutput = NULL) const;

Description

Text measurement function.

This is the powerful text measurement function underlying all the other text measurement functions. It takes optional input and output parameter blocks — they may be null, and returns the the advance width (change in pen position when drawn) of the text, or advance height if the text is drawn vertically. However, vertical text is not yet supported.

Some of the functions that can be performed using this function are listed below — many of them are used by the Text Views API to do its typographic layout.

Parameters

const TDesC& aText

The text to be measured.

const TMeasureTextInput* aInput = NULL

The input block. This may be NULL.

TMeasureTextOutput* aOutput = NULL

The output block. This may be NULL.

Return value

TInt

The advance width if the text is drawn horizontally or the advance height if the text is drawn vertically.

[Top]


Enumerations


Enum TTextDirection

TTextDirection

Description

Text direction flags.

This enum is used in TMeasureTextInput and determines whether the text is drawn horizontally or vertically. Note: text is drawn vertically in some styles of Japanese, etc.

See also:

EHorizontal

Text is drawn horizontally.

EVertical

Text is drawn vertically.


Enum TCharacterDataAvailability

TCharacterDataAvailability

Description

Data availability flags.

Some fonts like printer fonts may only have width information and can return ECharacterWidthOnly to show this: the text drawing routines in CFont synthesize the rest of the data if necessary.

See also:

ENoCharacterData

No font information available.

ECharacterWidthOnly

Width information only is available.

EAllCharacterData

All character data is available.

[Top]


Scoped classes


Class TPositionParam

TPositionParam

Description

Complicated parameter block used for contextual glyph selection, ligature creation and diacritic placement when drawing text in complex scripts

This class declares a constructor, another scoped class, and several other enums. However this class is not unlikely to be useful to third party developers, and so these have not been fully documented.

See also:


Class TMeasureTextInput

TMeasureTextInput

Description

Input parameter block.

This is optionally used by CFont::MeasureText(), which is the powerful text measurement function underlying all the other text measurement functions.

Defined in CFont::TMeasureTextInput:
TMeasureTextInput, iCharJustExcess, iCharJustNum, iDirection, iEndInputChar, iMaxAdvance, iMaxBounds, iStartInputChar, iWordJustExcess, iWordJustNum

See also:

Construction and destruction

TMeasureTextInput


TMeasureTextInput

Description

Default constructor.

Initialises all values to zero, except iEndInputChar and iMaxAdvance which are set to the maximum value, and iDirection which is set to EHorizontal.

Member data

iStartInputChar


    TInt iStartInputChar;

Description

Starting index specifying first input character in iText.

Together with iEndInputChar, this allows some context before and after the measured text to be supplied so that shaping can work properly.

iEndInputChar


TInt iEndInputChar;

Description

Index specifying the final input character.

Together with iStartInputChar, this allows some context before and after the measured text to be supplied so that shaping can work properly.

iDirection


TTextDirection iDirection;

Description

The direction in which to draw the text.

iMaxAdvance


TInt iMaxAdvance;

Description

The maximum advance.

iMaxBounds


TInt iMaxBounds;

Description

The maximum width (or height if drawing vertically) of bounds.

iCharJustNum


TInt iCharJustNum;

Description

The number of glyph groups to be letterspaced.

iCharJustExcess


TInt iCharJustExcess;

Description

The amount of space to be used for letterspacing.

iWordJustNum


TInt iWordJustNum;

Description

The number of spaces to be used for wordspacing.

iWordJustExcess


TInt iWordJustExcess;

Description

The amount of space to be used for wordspacing.


Class TMeasureTextOutput

class TMeasureTextOutput

Description

Output parameter block.

This is optionally used by CFont::MeasureText(), which is the powerful text measurement function underlying all the other text measurement functions.

Defined in CFont::TMeasureTextOutput:
iBounds, iChars, iGlyphs, iGroups, iMaxGlyphSize, iSpaces

See also:

Member data

iChars


TInt iChars;

Description

The number of input characters that would be drawn.

This may be less than the length of the text if a maximum advance or bounding box size is specified.

iGlyphs


TInt iGlyphs;

Description

The number of glyphs that would be drawn.

iGroups


TInt iGroups;

Description

The number of groups that would be drawn.

A group is a base glyph plus one or more combining characters.

iSpaces


TInt iSpaces;

Description

The number of word spaces (U+0020) that would be drawn.

iBounds


TRect iBounds;

Description

The bounding box of all the glyphs that would be drawn.

iMaxGlyphSize


TSize iMaxGlyphSize;

Description

The maximum width and height of any glyph.