_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

font.cpp File Reference
#include "stratagus.h"
#include "font.h"
#include "intern_video.h"
#include "video.h"
#include <vector>
#include <map>

font.cpp - The color fonts.

typedef std::map< std::string, CFont * > FontMap
 
typedef std::map< std::string, CFontColor * > FontColorMap
 Font mappings. More...
 
typedef std::map< const CFontColor *, CGraphic * > FontColorGraphicMap
 Default reverse color index. More...
 
static FontMap Fonts
 
static FontColorMap FontColors
 
static CFontColorFontColor
 Map of ident to font color. More...
 
static const CFontColorLastTextColor
 Current font color. More...
 
static CFontColorDefaultTextColor
 Last text color. More...
 
static CFontColorReverseTextColor
 Default text color. More...
 
static std::string DefaultNormalColorIndex
 Reverse text color. More...
 
static std::string DefaultReverseColorIndex
 Default normal color index. More...
 
static std::map< const CFont *, FontColorGraphicMapFontColorGraphics
 
static CFontSmallFont
 
static CFontGameFont
 Small font used in stats. More...
 
static const unsigned char codepoint_to_cp437 []
 
static const unsigned char codepoint_to_cp1252 []
 
static const unsigned char codepoint_to_cp866 []
 
static const char * codepoint_from_0xa0_to_ascii []
 
static const char * codepoint_from_0x400_to_ascii []
 
int FontCodePage = 437
 true when GameFont is provided More...
 
static std::string FormatNumber (const int number)
 Normal font used in game. More...
 
CFontGetSmallFont ()
 
bool IsGameFontReady ()
 Normal font used in game. More...
 
CFontGetGameFont ()
 Small font used in stats. More...
 
static void VideoDrawChar (const CGraphic &g, int gx, int gy, int w, int h, int x, int y, const CFontColor &fc)
 
void SetDefaultTextColors (const std::string &normal, const std::string &reverse)
 Set the default text colors for normal and reverse text. More...
 
void GetDefaultTextColors (std::string &normalp, std::string &reversep)
 Get the default text colors for normal and reverse text. More...
 
static unsigned char codepoint_to_codepage_index (int codepoint, const char **subst)
 
static int CodepageIndexFromUTF8 (const char text[], const size_t len, size_t &pos, size_t &subpos)
 
static int CodepageIndexFromUTF8 (const std::string &text, size_t &pos, size_t &subpos)
 
int convertKey (const char *key)
 
int GetHotKey (const std::string &text)
 Get the hot key from a string. More...
 
static void VideoDrawCharClip (const CGraphic &g, int gx, int gy, int w, int h, int x, int y, const CFontColor &fc)
 
static int strchrlen (const std::string &s, char c, unsigned int maxlen, const CFont *font)
 
std::string GetLineFont (unsigned int line, const std::string &s, unsigned int maxlen, const CFont *font)
 Return the 'line' line of the string 's'. More...
 
void LoadFonts ()
 Load and initialize the fonts. More...
 
void ReloadFonts ()
 
void CleanFonts ()
 Cleanup the font module. More...
 

Typedef Documentation

◆ FontColorGraphicMap

typedef std::map<const CFontColor *, CGraphic *> FontColorGraphicMap

Default reverse color index.

Font color graphics Usage: FontColorGraphics[CFont *font][CFontColor *color]

◆ FontColorMap

typedef std::map<std::string, CFontColor *> FontColorMap

Font mappings.

◆ FontMap

typedef std::map<std::string, CFont *> FontMap

Function Documentation

◆ CleanFonts()

void CleanFonts ( )

Cleanup the font module.

Clean up the font module.

◆ CodepageIndexFromUTF8() [1/2]

static int CodepageIndexFromUTF8 ( const char  text[],
const size_t  len,
size_t &  pos,
size_t &  subpos 
)
static

Get the next codepage index to render from a utf8 encoded string. This maps utf8 encoded unicode codepoints into the codepage index of the active FontCodePage. If no mapping into the codepage exists, this may offer a single- or multi-char replacement string. The subpos out-parameter is used to communicate at which position in a multi-char replacement string we are. Callers should pass in the same pos and subpos arguments while iterating over a loop. When the subpos is 0 after a call, the utf8 character was completely processed, otherwise more codepoint indices are needed to substitute the utf8 char.

Returns
0 on failure, else the codepage index to print next for the current utf8 character

◆ CodepageIndexFromUTF8() [2/2]

static int CodepageIndexFromUTF8 ( const std::string &  text,
size_t &  pos,
size_t &  subpos 
)
static

Get the next codepage index to render from a utf8 encoded string

◆ codepoint_to_codepage_index()

static unsigned char codepoint_to_codepage_index ( int  codepoint,
const char **  subst 
)
static

Convert a Unicode codepoint to a codepage index, based on the convert table to work with Stratagus char. This maps Unicode codepoints into codepages commonly used for DOS and early Windows games; currently CP437, CP1251, and CP866. More can be added. The games need to ensure that the font graphic represents the appropriate codepage.

Parameters
codepointthe char to convert
substout variable for a char pointer with a substitution string if the codepage doesn't support the char
Returns
the equivalent codepage index; 0 if a substitution string is set; or '?' if codepoint is unsupported.

◆ convertKey()

int convertKey ( const char *  key)

◆ FormatNumber()

static std::string FormatNumber ( const int  number)
static

Normal font used in game.

@brief      Format a number using commas

This is closely tied to CFont::Width(int number).

@param      number  Number to be formatted

@return     The formatted number as a string

◆ GetDefaultTextColors()

void GetDefaultTextColors ( std::string &  normalp,
std::string &  reversep 
)

Get the default text colors for normal and reverse text.

Get the default text colors.

Parameters
normalpNormal text color pointer.
reversepReverse text color pointer.

◆ GetGameFont()

CFont& GetGameFont ( )

Small font used in stats.

◆ GetHotKey()

int GetHotKey ( const std::string &  text)

Get the hot key from a string.

Get the hot key from a string

◆ GetLineFont()

std::string GetLineFont ( unsigned int  line,
const std::string &  s,
unsigned int  maxlen,
const CFont font 
)

Return the 'line' line of the string 's'.

Return the 'line' line of the string 's'.

Parameters
lineline number.
smultiline string.
maxlenmax length of the string (0 : unlimited) (in char if font == NULL else in pixels).
fontif specified use font->Width() instead of strlen.
Returns
computed value.

◆ GetSmallFont()

CFont& GetSmallFont ( )

Font selector for the font functions. FIXME: should be moved to lua

◆ IsGameFontReady()

bool IsGameFontReady ( )

Normal font used in game.

◆ LoadFonts()

void LoadFonts ( )

Load and initialize the fonts.

Load all fonts.

◆ ReloadFonts()

void ReloadFonts ( )

Reload fonts

◆ SetDefaultTextColors()

void SetDefaultTextColors ( const std::string &  normal,
const std::string &  reverse 
)

Set the default text colors for normal and reverse text.

Set the default text colors.

Parameters
normalNormal text color.
reverseReverse text color.

◆ strchrlen()

static int strchrlen ( const std::string &  s,
char  c,
unsigned int  maxlen,
const CFont font 
)
static

Return the index of first occurrence of c in [s- s + maxlen]

Parameters
soriginal string.
ccharacter to find.
maxlensize limit of the search. (0 means unlimited). (in char if font == NULL else in pixels).
fontif specified use font->Width() instead of strlen.
Returns
computed value.

◆ VideoDrawChar()

static void VideoDrawChar ( const CGraphic g,
int  gx,
int  gy,
int  w,
int  h,
int  x,
int  y,
const CFontColor fc 
)
static

Draw character with current color.

Parameters
gPointer to object
gxX offset into object
gyY offset into object
wwidth to display
hheight to display
xX screen position
yY screen position

◆ VideoDrawCharClip()

static void VideoDrawCharClip ( const CGraphic g,
int  gx,
int  gy,
int  w,
int  h,
int  x,
int  y,
const CFontColor fc 
)
static

Draw character with current color clipped into 8 bit framebuffer.

Parameters
gPointer to object
gxX offset into object
gyY offset into object
wwidth to display
hheight to display
xX screen position
yY screen position

Variable Documentation

◆ codepoint_from_0x400_to_ascii

const char* codepoint_from_0x400_to_ascii[]
static
Initial value:
= {
"Ie", "Io", "Dj", "Gj", "Ie", "Dz", "I", "Yi", "J", "Lj", "Nj", "Tsh", "Kj", "I", "U", "Dzh",
"A", "B", "V", "G", "D", "E", "Zh", "Z", "I", "I", "K", "L", "M", "N", "O", "P",
"R", "S", "T", "U", "F", "Kh", "Ts", "Ch", "Sh", "Shch", "'", "Y", "'", "E", "Iu", "Ia",
"a", "b", "v", "g", "d", "e", "zh", "z", "i", "i", "k", "l", "m", "n", "o", "p",
"r", "s", "t", "u", "f", "kh", "ts", "ch", "sh", "shch", "'", "y", "'", "e", "iu", "ia",
"ie", "io", "dj", "gj", "ie", "dz", "i", "yi", "j", "lj", "nj", "tsh", "kj", "i", "u", "dzh",
}

◆ codepoint_from_0xa0_to_ascii

const char* codepoint_from_0xa0_to_ascii[]
static
Initial value:
= {
" ", "!", "C/", "PS", "$?", "Y=", "|", "SS", "\"", "(c)", "a", "<<", "!", "?", "(r)", "-",
"deg", "+-", "2", "3", "'", "u", "P", "*", ",", "1", "o", ">>", " 1/4 ", " 1/2 ", " 3/4 ", "?",
"A", "A", "A", "A", "A", "A", "AE", "C", "E", "E", "E", "E", "I", "I", "I", "I",
"D", "N", "O", "O", "O", "O", "O", "x", "O", "U", "U", "U", "U", "Y", "Th", "ss",
"a", "a", "a", "a", "a", "a", "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i",
"d", "n", "o", "o", "o", "o", "o", "/", "o", "u", "u", "u", "u", "y", "th", "y",
}

◆ codepoint_to_cp1252

const unsigned char codepoint_to_cp1252[]
static
Initial value:
= {
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
}

◆ codepoint_to_cp437

const unsigned char codepoint_to_cp437[]
static
Initial value:
= {
0xff, 0xad, 0x9b, 0x9c, 0x00, 0x9d, 0x00, 0x00, 0x00, 0x00, 0xa6, 0xae, 0xaa, 0x00, 0x00, 0x00,
0xf8, 0xf1, 0xfd, 0x00, 0x00, 0xe6, 0x00, 0xfa, 0x00, 0x00, 0xa7, 0xaf, 0xac, 0xab, 0x00, 0xa8,
0x00, 0x00, 0x00, 0x00, 0x8e, 0x8f, 0x92, 0x80, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa5, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0xe1,
0x85, 0xa0, 0x83, 0x00, 0x84, 0x86, 0x91, 0x87, 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b,
0x00, 0xa4, 0x95, 0xa2, 0x93, 0x00, 0x94, 0xf6, 0x00, 0x97, 0xa3, 0x96, 0x81, 0x00, 0x00, 0x98
}

◆ codepoint_to_cp866

const unsigned char codepoint_to_cp866[]
static
Initial value:
= {
0x00, 0xf0, 0x00, 0x00, 0xf2, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x00,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0x00, 0xf1, 0x00, 0x00, 0xf3, 0x00, 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7, 0x00
}

◆ DefaultNormalColorIndex

std::string DefaultNormalColorIndex
static

Reverse text color.

◆ DefaultReverseColorIndex

std::string DefaultReverseColorIndex
static

Default normal color index.

◆ DefaultTextColor

CFontColor* DefaultTextColor
static

Last text color.

◆ FontCodePage

int FontCodePage = 437

true when GameFont is provided

◆ FontColor

CFontColor* FontColor
static

Map of ident to font color.

◆ FontColorGraphics

std::map<const CFont *, FontColorGraphicMap> FontColorGraphics
static

◆ FontColors

FontColorMap FontColors
static

◆ Fonts

FontMap Fonts
static

◆ GameFont

CFont* GameFont
static

Small font used in stats.

◆ LastTextColor

const CFontColor* LastTextColor
static

Current font color.

◆ ReverseTextColor

CFontColor* ReverseTextColor
static

Default text color.

◆ SmallFont

CFont* SmallFont
static
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.