# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

How to compute and render strings

Author:
Stephane Coutelas

Summary

A character is displayed using a CTextureFont. To avoid creating a new CTextureFont for each character we use a CFontManager which provides the textures and manages CTextureFont instances in memory. A font manager is able to compute an entire string, to do that it fills a CComputedString. A CComputedString contains a list of primitive blocks(CPrimitiveBlock) and materials(CMaterial). It can then render the string through a driver(IDriver).

CTextureFont

A CTextureFont object is a texture representing a unicode character. It inherits ITexture, and therefore CBitmap. The texture bitmap is built by calling generate() which fills in the same time useful fields, as :

  • GlyphIndex : number of the character in the this font
  • Top : Distance between origin and top of the texture
  • Left : Distance between origin and left of the texture
  • AdvX : Advance to the next caracter
Rq : all these values are given by the font generator. About bitmap dimensions : if width or height are not powers of 2 there are set to the next power of 2. The true dimensions are still availables in the CTextureFont level.

CFontManager

The font manager manages CTextureFont pointers through a list of CSmartPtr. When the user requires the texture font representing a character, it generates and stores this pointer in the list. If this character has already been generated, and lies in the list, it increments its reference count and return the pointer.

Rq : a character is defined by

  • a font name
  • a unicode char
  • a font size
The maximum memory used by the list of generated font textures in the font manager can be, and SHOULD be, set by the user after manager creation. Indeed the default value is 0. When the maximum memory is reached, the manager delete the useless characters until memory ammount is acceptable.

CFontGenerator

The font generator is the interface between Nel and FreeType. One generator is used for one font. Then, providing a unicode char and a size, the generator can return a generated bitmap containing the char bitmap.

CDisplayDescriptor

A CDisplayDescriptor is a structure used to store screen parameters :

  • screen width
  • screen height
  • font ratio

CComputedString

Rendering parameters

The coordinates are screen-relatives :

  • 0,0 is the bottom-left corner
  • 1,1 is the top-right corner
The scale parameters have the default value 1. The rotation angle is set to 0 by default.

A string as a "hot spot" which indicates its relative display origin. By default this value is LeftBottom. The others are :

  • LeftMiddle
  • LeftTop
  • MiddleBottom
  • MiddleMiddle
  • MiddleTop
  • RightBottom
  • RightMiddle
  • RightTop
font.jpg

Example

Here is an example generating and rendering a string :

// Font manager
CFontManager fontManager;
fontManager.setMaxMemory(2000000);
        
// Font generator
CFontGenerator fontGenerator("c:/winnt/fonts/arialuni.ttf");

// Screen parameters
CDisplayDescriptor displayDesc;
displayDesc.ResX = 800;
displayDesc.ResY = 600;
        
// Compute string
CComputedString cptedString;
fontManager.computeString ("Nevrax",&fontGenerator,CRGBA(255,255,255),100,displayDesc,cptedString);

//...here the driver is initialized...

// render string
cptedString.render2D (driver, 0.5, 0.7);