Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMFont Class Reference

Bitmap font resource. More...

#include <PLMFont.hpp>

Inheritance diagram for PLMFont:

Inheritance graph
[legend]
List of all members.

Public Types

enum  ImageType {
  TYPE_ERROR = 0, TYPE_B1 = 1, TYPE_B2 = 2, TYPE_B8 = 8,
  TYPE_B24 = 24, TYPE_B32 = 32
}
enum  { FORMAT_UNK = 0, FORMAT_DEF = 1 }

Public Methods

 PLMFont (const char *filename=0)
 PLMFont (PLMResFile &file, int format=PLMResource::FORMAT_UNK)
 PLMFont (const char *name, u32 first, u32 last, PLMImage *src=0, u8 type=TYPE_B8)
const char * Name () const
void SetMetrics (u8 space_c, u8 space_w, s16 ascent, s16 descent)
void GetMetrics (u8 &space_c, u8 &space_w, s16 &ascent, s16 &descent) const
int CSpace () const
int WSpace () const
int Ascent () const
int Descent () const
const u8 * GetImage () const
u32 ImagePitch () const
u32 ImageHeight () const
u8 ImageType () const
bool LoadV1 (PLMResFile &src, int format=PLMResource::FORMAT_UNK)
virtual bool Load (PLMResFile &src, int format=PLMResource::FORMAT_UNK)
virtual bool Save (PLMResFile &dest, int format=PLMResource::FORMAT_DEF)
virtual u32 MemoryUsed () const
u8 FirstChar () const
u8 LastChar () const
const PLMCharGetChar (u8 c) const
u32 Height () const
u32 CharWidth (u8 c) const
u32 CharHeight (u8 c) const
u32 TextHeight (const char *text, u32 nb=PLM::INDEX_ERROR) const
u32 TextWidth (const char *text, u32 nb=PLM::INDEX_ERROR) const
void TextSize (const char *text, u32 &width, u32 &height, u32 nb=PLM::INDEX_ERROR) const
void SetFirstChar (u8 first)
void SetLastChar (u8 last)
void SetChar (u8 c, PLMChar *data)
bool SetImage (PLMImage *i, u8 type=TYPE_B8)
void PrintInfo (bool detail) const
virtual bool LoadName (const char *filename, int format=FORMAT_UNK)
virtual bool SaveName (const char *filename, int format=FORMAT_DEF)

Detailed Description

Bitmap font resource.

Notes:

  • the characters' shapes are stored in one single bitmap (8 bits grayscale, black = back, white = foreground)
  • PLMFont is a resource (Load()/Save(), handled by a resource manager)
  • can be used by PLMImage
  • use ANSI character set (= ASCII for [0..127]), can handle variable range of characters (max range is [0..255])
  • space = index 32, is always defined, but handled automatically (can not be defined as other characters)
  • some definitions :
       ----------------------------- max top    ---         ---
            |                                    |           |
            +--                                  |           |
            |        +---\                       | ascent    |
            |        |   |                       |           |  font
            \        |   /                       |           | height
       ----------------------------- base line  -+-          |
                     |                           |           |
                     |                           | descent   |
       ----------------------------- max bottom ---         ---
    
The letter 't' has a h_offset of 0 (bottom is on the base line) whereas 'p' has a h_offset of 2 (starts 2 pixels below the base line). The 'ascent' value represents the greatest height upon the base line (top - base length) for the whole font and 'descent' the greatest height below it (base - bottom length).


Member Enumeration Documentation

enum PLMFont::ImageType
 

Binary format (number of bits per pixel) of the bitmap (used to save it to a file).

Enumeration values:
TYPE_ERROR  no type, error
TYPE_B1  1 bit per pixel (black & white)
TYPE_B2  2 bits per pixel (4 colors)
TYPE_B8  8 bits per pixel (256 colors)
TYPE_B24  24 bits per pixel (RGB)
TYPE_B32  32 bits per pixel (RGBA)

anonymous enum [inherited]
 

Enumeration values:
FORMAT_UNK  unknown format (usually for load)
FORMAT_DEF  default format (usually for save)


Constructor & Destructor Documentation

PLMFont::PLMFont const char *    filename = 0
 

Create a new font and try to load data from file filename.

PLMFont::PLMFont PLMResFile   file,
int    format = PLMResource::FORMAT_UNK
 

Create a new font and try to load data from file file.

PLMFont::PLMFont const char *    name,
u32    first,
u32    last,
PLMImage   src = 0,
u8    type = TYPE_B8
 

Create a new font.

Parameters:
name  name of the new font
first  first character available
last  last character available
src  image to read character representation from
type  image format (bits per pixel, use ImageType enum).


Member Function Documentation

const char * PLMFont::Name   [inline]
 

Get the font name. Do not modify.

void PLMFont::SetMetrics u8    space_c,
u8    space_w,
s16    ascent,
s16    descent
[inline]
 

Set global font metrics.

Parameters:
space_c  space in pixels between two letters (inside a word)
space_w  space in pixels between two words
ascent  maximum height of characters above base line
descent  maximum height of characters under base line

void PLMFont::GetMetrics u8 &    space_c,
u8 &    space_w,
s16 &    ascent,
s16 &    descent
const [inline]
 

Get global font metrics.

Parameters:
space_c  number of pixels between two letters (inside a word)
space_w  number of pixels between two words (space)
ascent  maximum height of characters above base line
descent  maximum height of characters under base line

int PLMFont::CSpace   [inline]
 

Get the number of pixels between two letters (in the same word).

int PLMFont::WSpace   [inline]
 

Get the number of pixels between two words.

int PLMFont::Ascent   [inline]
 

Get the maximum height of a character above the base line (in pixels).

int PLMFont::Descent   [inline]
 

Get the maximum height of a character below the base line (in pixels).

const u8 * PLMFont::GetImage   [inline]
 

Get font image data (image of all the characters).

Note that even if the ImageType() uses less than 8 bits per pixel, the minimum image depth is 8 bits per pixel. If type is TYPE_B2, all values will be in the range [0..3] though.

u32 PLMFont::ImagePitch   [inline]
 

Get image pitch (width of one line in bytes).

u32 PLMFont::ImageHeight   [inline]
 

Get image height (in pixels).

u8 PLMFont::ImageType   [inline]
 

Get the image format (how it is stored in the file).

bool PLMFont::LoadV1 PLMResFile   src,
int    format = PLMResource::FORMAT_UNK
 

Load a font from an old version file.

virtual bool PLMFont::Load PLMResFile   src,
int    format = PLMResource::FORMAT_UNK
[virtual]
 

Load data from the file src, using a specific format.

Implements PLMResource.

virtual bool PLMFont::Save PLMResFile   dest,
int    format = PLMResource::FORMAT_DEF
[virtual]
 

Save data to the file dest, using a specific format.

Implements PLMResource.

virtual u32 PLMFont::MemoryUsed   [virtual]
 

Get the total amount of memory used by this resource.

Implements PLMResource.

u8 PLMFont::FirstChar   [inline]
 

Get the first character (index) defined in the font.

u8 PLMFont::LastChar   [inline]
 

Get the last character (index) defined in the font.

const PLMChar * PLMFont::GetChar u8    c const [inline]
 

Get the definition of the character at index c.

Return a pointer on a struct PLMChar from the internal list, so do not modify it. Return NULL c if out of range.

u32 PLMFont::Height   [inline]
 

Get font height (max ascent + max descent).

u32 PLMFont::CharWidth u8    c const
 

Get the width of a specific character c.

u32 PLMFont::CharHeight u8    c const
 

Get the height of a specific character c.

u32 PLMFont::TextHeight const char *    text,
u32    nb = PLM::INDEX_ERROR
const [inline]
 

Compute the width of a string, in pixels (sum of widths).

Parameters:
text  the string
nb  number of characters to use in the string, PLM::INDEX_ERROR means all
Returns:
the width in pixels.

u32 PLMFont::TextWidth const char *    text,
u32    nb = PLM::INDEX_ERROR
const
 

Compute the height of a string, in pixels (max of heights).

Parameters:
text  the string
nb  number of characters to use in the string, PLM::INDEX_ERROR means all
Returns:
the height in pixels.

void PLMFont::TextSize const char *    text,
u32 &    width,
u32 &    height,
u32    nb = PLM::INDEX_ERROR
const
 

Compute both width and height needed to draw a string, in pixels.

Parameters:
text  the string to read
width  [out] where the final width is stored
height  [out] where the final height is stored
nb  the number of characters to take into account in text.

void PLMFont::SetFirstChar u8    first
 

Set the first defined character (index) of the font.

void PLMFont::SetLastChar u8    last
 

Set the last defined character (index) of the font.

void PLMFont::SetChar u8    c,
PLMChar   data
 

Set character definition for the character at index c.

It deletes current info if data is NULL.

bool PLMFont::SetImage PLMImage   i,
u8    type = TYPE_B8
 

Change the font image.

For all types smaller than 24 bits, it must be a 8 bits image. type is an ImageType enum. Return false on error.

void PLMFont::PrintInfo bool    detail const
 

Print some informations about the font, and all characters (if detail is true).

virtual bool PLMResource::LoadName const char *    filename,
int    format = FORMAT_UNK
[virtual, inherited]
 

Load data from the file filename.

Reimplemented in PLMMusic.

virtual bool PLMResource::SaveName const char *    filename,
int    format = FORMAT_DEF
[virtual, inherited]
 

Save data to the file filename.


The documentation for this class was generated from the following file:
  • PLMFont.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:44 2004.