Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

wftk::Font Class Reference

FreeType based surface font. More...

#include <font.h>

List of all members.

Public Types

typedef Resource< FontResource
 refcounted resource


Public Member Functions

 Font (const std::string &fontfilename, unsigned ptsize=12, const Color &color=textColor(), unsigned face_index=0) throw (BadFont)
 Constructor.

 Font (const unsigned char *buffer, unsigned buf_size, unsigned ptsize=12, const Color &color=textColor(), unsigned face_index=0) throw (BadFont)
 load a font from memory

 Font (const Font &f)
 Copy a Font (inexpensive, fonts are refcounted).

 Font ()
 Create an invalid Font.

Fontoperator= (const Font &f)
 Copy another Font into this one.

const GlyphgetChar (unsigned char c) const
 return surface representation of a char.

SurfacegetString (const std::string &txt) const
 return bitmap representation of a string.

SurfacegetString (const std::string &, Point &) const
 Get the string blitted to a surface, and the offset from the starting pen position to the upper left hand corner.

int blitString (const std::string &txt, Surface &target, const Point &pos) const
 Draw a string on the surface, with the pen starting at pos.

int blitString (const std::string &txt, Surface &target, const Point &pos, const Region &mask, bool copy=false) const
 Draw a string on the surface, with the pen starting at pos, with a masking region taken relative to the target.

Rect getExtents (const std::string &) const
 Get the area covered by a string, with (0, 0) being the starting pen position.

int getHeight () const
 the font height in pixels

const Metricsmetrics () const
 get the font's metrics

bool valid () const
 Return true if the font is valid.

Color color () const
 Return the foreground color of the font.

void setColor (const Color &)
 Set the color of the font.


Static Public Member Functions

const FonttextFont ()
 The font specified by the resource "text_font".

const ColortextColor ()
 Get the default text color, specified by the resource "text_color".


Static Public Attributes

ResourceRegistry< Font, ResLoad,
ResInval > 
registry
 Load font from truetype file and associate with a named resource.


Detailed Description

FreeType based surface font.

This class uses the benefit of truetype fonts (antialiasing, *many* free fonts) as well as the speed gain of surface fonts. When creating an object of Font the surfaces for the characters are all rendered in best quality. When the font-object is asked to create a surface from a string it just blits these character surfaces, which is quite fast.


Constructor & Destructor Documentation

wftk::Font::Font const std::string &  fontfilename,
unsigned  ptsize = 12,
const Color color = textColor(),
unsigned  face_index = 0
throw (BadFont)
 

Constructor.

fontfilename has to be the name of a truetype font file. The alpha channel of the color is ignored.


Member Function Documentation

const Glyph& wftk::Font::getChar unsigned char  c  )  const [inline]
 

return surface representation of a char.

if no font is loaded, the surface returned is empty.

Surface* wftk::Font::getString const std::string &  txt  )  const [inline]
 

return bitmap representation of a string.

if no font is loaded, the bitmap returned is empty.


Member Data Documentation

wftk::ResourceRegistry< wftk::Font, wftk::Font::ResLoad, wftk::Font::ResInval > wftk::Font::registry [static]
 

Load font from truetype file and associate with a named resource.

Use the load() function to load a font from a file on disk and register it with wftk's Resources engine. The font specification is a string, formatted thus:
< fontname, size, foreground, background >

Parameters:
fontname font name to be registered
size size of font in points
foreground foreground color of font, 0xAARRBBGG or 0xRRBBGG
Font::registry.load("button_font", "wf_opal.ttf, 16, 0xF0F0F0");
Note that the wftk will attempt to use the "text_font" and "button_font" resources by default for widgets / labels that don't have a font specified.

Use the find() function to retrieve a font. If the named font has not been registered, find() will return the default text font.

MultiLineEdit* title = new MultiLineEdit(bg, 50, 10, 400, 70, Font::registry.find("button_font"));


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

Generated Wed Jul 28 17:28:43 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.