DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Friends
GUI::Font Class Reference

A variable- or fixed-width fixed-size Font. More...

#include <gui_tk.h>

Inheritance diagram for GUI::Font:
GUI::BitmapFont

List of all members.

Classes

struct  ltstr
 Compare two strings for 'less-than'. More...

Public Types

enum  SpecialChar {
  CR = '\r', LF = '\n', BS = '\b', Tab = '\t',
  Space = ' ', ESC = 27
}
 Characters with special appearance or meaning.

Public Member Functions

virtual int getHeight () const =0
 Retrieve total height of font in pixels.
virtual int getAscent () const =0
 Retrieve the ascent, i.e. the number of pixels above the base line.
template<typename STR >
int getWidth (const STR s, Size start=0, Size len=(Size)-1) const
 Return width of a string.
virtual int getWidth (Char c= 'M') const =0
 Retrieve width of a character.
virtual int getWidth (const String &s, Size start=0, Size len=(Size)-1) const
 Retrieve width of a string of characters.
virtual SpecialChar toSpecial (Char c) const
 Convert a character to an equivalent SpecialChar. May return values not in SpecialChar.
virtual Char fromSpecial (SpecialChar c) const
 Convert a SpecialChar to an equivalent character.

Static Public Member Functions

static const FontgetFont (const char *name)
 Return a font with the given name (case-sensitive).
static void registry_freeall ()
static void addFont (const char *name, Font *font)
 Add a font with a given name.

Protected Member Functions

 Font ()
 Default constructor.
virtual void drawChar (Drawable *d, const Char c) const =0
 Draw character to a drawable at the current position.
virtual void drawString (Drawable *d, const String &s, Size start, Size len) const
 Draw len characters to a drawable at the current position, starting at string position start.

Static Protected Attributes

static std::map< const char
*, Font *, ltstr
registry
 Font registry. Contains all known font objects indexed by name.

Friends

void Drawable::drawText (const Char c, bool interpret)
void Drawable::drawText (const String &s, bool interpret, Size start, Size len)

Detailed Description

A variable- or fixed-width fixed-size Font.

These Fonts can't be scaled once instantiated, but it is possible to subclass this abstract font class to encapsulate scalable fonts. Fonts can be anti-aliasing and multi-coloured, depending on subclass. There is no encoding enforced. The font object implicitly knows about it's encoding. Because of that, there is a utility function for string examination as well.

You can't instantiate objects of this class directly, use one of the subclasses like BitmapFont.

This class provides a font registry which allows you to register and retrieve font objects using a name of your choice. It is recommended to use a naming scheme like "FontName-variant-pixelsize-encoding" where variant is "normal", "bold", "italic" or "bolditalic". No one enforces this, however.

The GUI uses some special font names. You must add them before creating the relevant GUI item.

Definition at line 1117 of file gui_tk.h.


Member Function Documentation

static void GUI::Font::addFont ( const char *  name,
Font font 
) [inline, static]

Add a font with a given name.

Don't delete this font once added. This class will do that for you. If a font with that name already exists, it will be replaced.

Definition at line 1167 of file gui_tk.h.

References registry.

virtual void GUI::Font::drawChar ( Drawable d,
const Char  c 
) const [protected, pure virtual]

Draw character to a drawable at the current position.

d's current position is advanced to the position of the next character. The y coordinate is located at the baseline before and after the call.

Implemented in GUI::BitmapFont.

Referenced by drawString(), and GUI::Drawable::drawText().

virtual void GUI::Font::drawString ( Drawable d,
const String s,
Size  start,
Size  len 
) const [inline, protected, virtual]

Draw len characters to a drawable at the current position, starting at string position start.

This can be used to provide kerning.

Definition at line 1139 of file gui_tk.h.

References drawChar().

Referenced by GUI::Drawable::drawText().

static const Font* GUI::Font::getFont ( const char *  name) [inline, static]

Return a font with the given name (case-sensitive).

If no font was registered with that name, returns NULL.

Definition at line 1148 of file gui_tk.h.

References registry.

Referenced by GUI::Menubar::addMenu(), GUI::Input::checkOffset(), GUI::Input::findPos(), GUI::Input::keyDown(), GUI::Input::paint(), GUI::ToplevelWindow::paint(), GUI::Menu::paint(), GUI::Menubar::paint(), GUI::Frame::paint(), and GUI::Menu::selectItem().

virtual int GUI::Font::getWidth ( const String s,
Size  start = 0,
Size  len = (Size)-1 
) const [inline, virtual]

Retrieve width of a string of characters.

Can be used to provide kerning.

Definition at line 1191 of file gui_tk.h.

References getWidth().


The documentation for this class was generated from the following files: