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

otk::Font Class Reference

#include <font.hh>

Collaboration diagram for otk::Font:

Collaboration graph
[legend]
List of all members.

Public Methods

 Font (int screen_num, const std::string &fontstring, bool shadow, unsigned char offset, unsigned char tint)
virtual ~Font ()
const std::string & fontstring () const
int height () const
int maxCharWidth () const
int measureString (const ustring &string) const

Static Public Methods

std::string fallbackFont (void)
void setFallbackFont (const std::string &f)

Private Methods

bool createXftFont (void)

Private Attributes

int _screen_num
std::string _fontstring
bool _shadow
unsigned char _offset
unsigned char _tint
XftFont * _xftfont

Static Private Attributes

std::string _fallback_font = "fixed"
bool _xft_init = false

Friends

class RenderControl

Constructor & Destructor Documentation

otk::Font::Font int    screen_num,
const std::string &    fontstring,
bool    shadow,
unsigned char    offset,
unsigned char    tint
 

Definition at line 36 of file font.cc.

References _, _fallback_font, _fontstring, _xft_init, and _xftfont.

00038   : _screen_num(screen_num),
00039     _fontstring(fontstring),
00040     _shadow(shadow),
00041     _offset(offset),
00042     _tint(tint),
00043     _xftfont(0)
00044 {
00045   assert(screen_num >= 0);
00046   assert(tint <= CHAR_MAX);
00047   
00048   if (!_xft_init) {
00049     if (!XftInit(0)) {
00050       printf(_("Couldn't initialize Xft.\n\n"));
00051       ::exit(3);
00052     }
00053     int version = XftGetVersion();
00054     printf(_("Using Xft %d.%d.%d (Built against %d.%d.%d).\n"),
00055            version / 10000 % 100, version / 100 % 100, version % 100,
00056            XFT_MAJOR, XFT_MINOR, XFT_REVISION);
00057     _xft_init = true;
00058   }
00059 
00060   if ((_xftfont = XftFontOpenName(**display, _screen_num,
00061                                   _fontstring.c_str())))
00062     return;
00063 
00064   printf(_("Unable to load font: %s\n"), _fontstring.c_str());
00065   printf(_("Trying fallback font: %s\n"), _fallback_font.c_str());
00066 
00067   if ((_xftfont = XftFontOpenName(**display, _screen_num,
00068                                   _fallback_font.c_str())))
00069     return;
00070 
00071   printf(_("Unable to load font: %s\n"), _fallback_font.c_str());
00072   printf(_("Aborting!.\n"));
00073 
00074   ::exit(3); // can't continue without a font
00075 }

otk::Font::~Font   [virtual]
 

Definition at line 78 of file font.cc.

00079 {
00080   if (_xftfont)
00081     XftFontClose(**display, _xftfont);
00082 }


Member Function Documentation

bool otk::Font::createXftFont void    [private]
 

std::string otk::Font::fallbackFont void    [inline, static]
 

Definition at line 32 of file font.hh.

00032 { return _fallback_font; }

const std::string& otk::Font::fontstring   const [inline]
 

Definition at line 58 of file font.hh.

00058 { return _fontstring; }

int otk::Font::height   const
 

Definition at line 100 of file font.cc.

References _offset, _shadow, and _xftfont.

Referenced by otk::Label::fitString(), otk::FocusLabel::fitString(), otk::Label::update(), and otk::FocusLabel::update().

00101 {
00102   return (signed) _xftfont->height + (_shadow ? _offset : 0);
00103 }

int otk::Font::maxCharWidth   const
 

Definition at line 106 of file font.cc.

References _xftfont.

00107 {
00108   return (signed) _xftfont->max_advance_width;
00109 }

int otk::Font::measureString const ustring   string const
 

Definition at line 85 of file font.cc.

References _offset, _shadow, otk::ustring::bytes(), otk::ustring::c_str(), and otk::ustring::utf8().

Referenced by otk::Label::fitString(), otk::FocusLabel::fitString(), ob::LabelWidget::renderForeground(), otk::Label::renderForeground(), otk::FocusLabel::renderForeground(), otk::Label::update(), and otk::FocusLabel::update().

00086 {
00087   XGlyphInfo info;
00088 
00089   if (string.utf8())
00090     XftTextExtentsUtf8(**display, _xftfont,
00091                        (FcChar8*)string.c_str(), string.bytes(), &info);
00092   else
00093     XftTextExtents8(**display, _xftfont,
00094                     (FcChar8*)string.c_str(), string.bytes(), &info);
00095 
00096   return (signed) info.xOff + (_shadow ? _offset : 0);
00097 }

void otk::Font::setFallbackFont const std::string &    f [inline, static]
 

Definition at line 33 of file font.hh.

00034     { _fallback_font = f; }


Friends And Related Function Documentation

friend class RenderControl [friend]
 

Definition at line 67 of file font.hh.


Member Data Documentation

std::string otk::Font::_fallback_font = "fixed" [static, private]
 

Definition at line 33 of file font.cc.

Referenced by Font().

std::string otk::Font::_fontstring [private]
 

Definition at line 42 of file font.hh.

Referenced by Font().

unsigned char otk::Font::_offset [private]
 

Definition at line 45 of file font.hh.

Referenced by otk::RenderControl::drawString(), height(), and measureString().

int otk::Font::_screen_num [private]
 

Definition at line 40 of file font.hh.

bool otk::Font::_shadow [private]
 

Definition at line 44 of file font.hh.

Referenced by otk::RenderControl::drawString(), height(), and measureString().

unsigned char otk::Font::_tint [private]
 

Definition at line 46 of file font.hh.

Referenced by otk::RenderControl::drawString().

bool otk::Font::_xft_init = false [static, private]
 

Definition at line 34 of file font.cc.

Referenced by Font().

XftFont* otk::Font::_xftfont [private]
 

Definition at line 48 of file font.hh.

Referenced by otk::RenderControl::drawString(), Font(), height(), and maxCharWidth().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:26 2003 for Openbox by doxygen1.3-rc2