Public Member Functions

CRM32Pro_CFont Class Reference
[MODULE 8: CFont v2.73, font engine class.]

CFont. More...


Detailed Description

CFont.

Font engine class.

Examples:

Example03_GUI.cpp, Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, SpacePong.cpp, and SpacePong.h.

List of all members.

Public Member Functions

void Clean ()
 Clean and reset the content of current font.
unsigned char Create (SDL_Surface *surface)
 Create a new font(with 96 characters) from a surface.
unsigned char Create (char *filebmp)
 Create a font(with 96 characters) from an external image file(BMP/PNG).
int GetAlpha ()
 Get alpha blending information.
char GetCursorChar ()
 Get current cursor character.
int GetKerning ()
 Get the kerning value for this font.
char * GetName ()
 Get the font name.
SDL_Surface * GetSurface ()
 Get font surface.
void Info ()
 Print a lot of useful font information. Very useful for debugging purposes.
unsigned char Load (char *fileDPF, char *fontname)
 Load a font from a DPF(using a filename).
unsigned char Load (int idDPF, char *fontname)
 Load a font from a DPF(using an idDPF).
void PutString (SDL_Surface *Surface, int x, int y, char *str, SDL_Rect *clip=NULL)
 Draw a string using this font.
void PutStringWithCursor (SDL_Surface *Surface, int x, int y, char *str, int cursPos, SDL_Rect *clip=NULL, unsigned char showCurs=1)
 ! Draw a string using this font and adding the cursor char
void PutStringXCenter (SDL_Surface *Surface, int y, char *str, SDL_Rect *clip=NULL)
 Render a X-centered string.
void PutStringYCenter (SDL_Surface *Surface, int x, char *str, SDL_Rect *clip=NULL)
 Render a Y-centered string.
int Save (char *fileDPF, char *fontname)
 Save this font to a DPF(using a filename).
int Save (int idDPF, char *fontname)
 Save this font to a DPF(using an idDPF).
void SetAlpha (int shade)
 Set the alpha per-surface.
void SetCursorChar (char csor)
 Set current cursor character.
void SetKerning (int value)
 Set the kerning value for this font.
void SetName (char *name)
 Set a new name for the font.
int StringHeight ()
 Get the size(height) of this font (in pixels).
int StringWidth (char *str)
 Get the size(width) of the given string.
unsigned char Test (SDL_Surface *)
 Test if a given surface can be converted to a font.
unsigned char Test (char *filebmp)
 Test if a given BMP can be converted to a font.

Member Function Documentation

void CRM32Pro_CFont::Clean (  ) 

Clean and reset the content of current font.

Useful to reuse the tile object with another content without use 'delete' and 'new' operators.

unsigned char CRM32Pro_CFont::Create ( char *  filename  ) 

Create a font(with 96 characters) from an external image file(BMP/PNG).

To create a bitmap with your desired characters set:

1.Create a text using your favourite design software with desired aspect of your font using this string:

! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

If you use an image file without alpha per-pixel, you must assure that the background(colorkey) color is RGB(0,0,0).

2.Between each character must exist a separation of at least two pixels. Left and right margins of the whole bitmap must be at least of five pixels.

Parameters:
filename Image file name, with its full path, containing all characters of the font
Returns:
96 Ok
any other number Failed. It also indicates the successfull imported characters
unsigned char CRM32Pro_CFont::Create ( SDL_Surface *  surface  ) 

Create a new font(with 96 characters) from a surface.

It supports alpha per-pixel surfaces.
The surface must contain the characters set using the right format. See description of Create(char *) to further information.

Parameters:
surface surface with all characters of this font
Returns:
96 Ok
any other number Failed. It also indicates the successfull imported characters
int CRM32Pro_CFont::GetAlpha (  ) 

Get alpha blending information.

To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).

Returns:
-1 Failed
From 0(transparent) to 254(almost full opaque) and alpha per-surface enabled
255 Alpha per-surface disabled
256 Alpha per-pixel enabled
char CRM32Pro_CFont::GetCursorChar (  ) 

Get current cursor character.

This cursor is used by PutStringWithCursor() method.

Returns:
The cursor char.
int CRM32Pro_CFont::GetKerning (  ) 

Get the kerning value for this font.

Returns:
signed integer with the kerning value in pixels.
char * CRM32Pro_CFont::GetName (  ) 

Get the font name.

Returns:
a pointer to font name
SDL_Surface * CRM32Pro_CFont::GetSurface (  ) 

Get font surface.

Returns:
pointer to SDL_Surface of this font
unsigned char CRM32Pro_CFont::Load ( int  idDPF,
char *  namefnt 
)

Load a font from a DPF(using an idDPF).

It automatically updates fonts v1.0(all ones until CRM32Pro v4.95) to fonts v2.0(since CRM32Pro v4.96).
Note that new fonts v2.0 are not compatible with old CRM32Pro versions.

Parameters:
idDPF ID of the opened DPF
namefnt name of this font
Returns:
0 Failed
1 Ok
unsigned char CRM32Pro_CFont::Load ( char *  fileDPF,
char *  namefnt 
)

Load a font from a DPF(using a filename).

It automatically updates fonts v1.0(all ones until CRM32Pro v4.95) to fonts v2.0(since CRM32Pro v4.96).
Note that new fonts v2.0 are not compatible with old CRM32Pro versions.

Parameters:
fileDPF name and optional path of a DPF that contains the font
namefnt name of this font
Returns:
0 Failed
1 Ok
Examples:
Example03_GUI.cpp, Example08_SpriteCollision.cpp, and Example09_LogicRenderRates.cpp.
void CRM32Pro_CFont::PutString ( SDL_Surface *  surface,
int  x,
int  y,
char *  str,
SDL_Rect *  clip = NULL 
)

Draw a string using this font.

Parameters:
surface surface to draw the render of this font
x position x of this font on surface
y position y of this font on surface
str string to be rendered
clip SDL_Rect with clip region, by default is NULL
Examples:
Example03_GUI.cpp, Example08_SpriteCollision.cpp, and Example09_LogicRenderRates.cpp.
void CRM32Pro_CFont::PutStringWithCursor ( SDL_Surface *  surface,
int  xs,
int  y,
char *  str,
int  cursPos,
SDL_Rect *  clip = NULL,
unsigned char  showCurs = 1 
)

! Draw a string using this font and adding the cursor char

Parameters:
surface surface to draw the render of this font
xs position x of this font on surface
y position y of this font on surface
str string to be rendered
cursPos Position of the cursor inside the str
clip SDL_Rect with clip region, by default is NULL
showCurs 0 to hide it or 1 to show it
void CRM32Pro_CFont::PutStringXCenter ( SDL_Surface *  surface,
int  y,
char *  str,
SDL_Rect *  clip = NULL 
)

Render a X-centered string.

Parameters:
surface surface to draw the render of this font
y position Y of this font on surface
str string to be rendered
clip SDL_Rect with clip region, by default is NULL
void CRM32Pro_CFont::PutStringYCenter ( SDL_Surface *  surface,
int  x,
char *  str,
SDL_Rect *  clip = NULL 
)

Render a Y-centered string.

Parameters:
surface surface to draw the render of this font
x position X of this font on surface
str string to be rendered
clip SDL_Rect with clip region, by default is NULL
int CRM32Pro_CFont::Save ( char *  fileDPF,
char *  fontname 
)

Save this font to a DPF(using a filename).

Parameters:
fileDPF name and optional path of a DPF to store this font
fontname name of this font
Returns:
-1 Font already exists.
0 Failed.
any other positive value, Ok and packed size of the added font
int CRM32Pro_CFont::Save ( int  idDPF,
char *  fontname 
)

Save this font to a DPF(using an idDPF).

Note if you try to save a font which was converted to the screen format to 8bits, it will convert the surface to 32bits before to proceed to save it. So, a font is never saved with a color depht of 8bits.

Parameters:
idDPF ID of the opened DPF
fontname name of this font
Returns:
-1 Font already exists.
0 Failed.
any other positive value, Ok and packed size of the added font
void CRM32Pro_CFont::SetAlpha ( int  shade  ) 

Set the alpha per-surface.

A surface with enabled alpha blending(per-pixel or per-surface) will be never created on video memory if alpha blending is not supported by the hardware. Right now, only glSDL supports it.
With per-pixel alpha, per-surface alpha is useless, so any attempt to activate it will be ignored.

Note that enabling and disabling the alpha blending on the execution time could slowdown your graphic performance.
To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).

Parameters:
shade integer from 0(transparent) to 254(almost full opaque) to enable the per-surface alpha or 255(full opaque) to disable it.
void CRM32Pro_CFont::SetCursorChar ( char  csor  ) 

Set current cursor character.

This cursor is used by PutStringWithCursor() method.

Parameters:
csor The cursor char.
void CRM32Pro_CFont::SetKerning ( int  value  ) 

Set the kerning value for this font.

When each character is rendered, the kerning value will modify its X position. By default, this value is 0.

Parameters:
value signed integer with the kerning value in pixels.
void CRM32Pro_CFont::SetName ( char *  name  ) 

Set a new name for the font.

Parameters:
name pointer to the new name. Maximum of 31 characters.
int CRM32Pro_CFont::StringHeight (  ) 

Get the size(height) of this font (in pixels).

Returns:
size(height) in pixels of this font
int CRM32Pro_CFont::StringWidth ( char *  str  ) 

Get the size(width) of the given string.

Parameters:
str desired string to be measured
Returns:
size(width) in pixels of the given string
unsigned char CRM32Pro_CFont::Test ( SDL_Surface *  surface  ) 

Test if a given surface can be converted to a font.

It supports surfaces with alpha per pixel enabled.

Parameters:
surface surface with font characters sample
Returns:
0 The given surface is a valid font.
255 It was not possible to import any character.
Any other number indicates the number of successful imported characters of a total of 96.
In this case, a "FontWithErrors.bmp" will be generated which has an upper purple line that have to separate each character.Common errors are some characters joined or splitted.
unsigned char CRM32Pro_CFont::Test ( char *  filebmp  ) 

Test if a given BMP can be converted to a font.

Parameters:
filebmp BMP file with font characters sample
Returns:
0 The given surface is a valid font.
255 It was not possible to import any character.
Any other number indicates the number of successful imported characters of a total of 96.
In this case, a "FontWithErrors.bmp" will be generated which has an upper purple line that have to separate each character.Common errors are some characters joined or splitted.

The documentation for this class was generated from the following files:
 All Classes Functions Variables