news download themes documentation links










FbTk::Font Class Reference

#include <Font.hh>

List of all members.

Public Member Functions

 Font (const char *name=0, bool antialias=false)
bool load (const std::string &name)
void setAntialias (bool flag)
void setShadow (bool flag)
unsigned int textWidth (const char *const text, unsigned int size) const
unsigned int height () const
int ascent () const
int descent () const
void rotate (float angle)
void drawText (Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y, bool rotate=true) const
bool isAntialias () const
bool isRotated () const
 true if the font is rotated, else false

float angle () const
 rotated angle

bool shadow () const

Static Public Member Functions

bool multibyte ()
 true if multibyte is enabled, else false

bool utf8 ()
 true if utf-8 mode is enabled, else false


Detailed Description

Handles the client to fontimp bridge.

Definition at line 40 of file Font.hh.


Member Function Documentation

void FbTk::Font::drawText Drawable  w,
int  screen,
GC  gc,
const char *  text,
size_t  len,
int  x,
int  y,
bool  rotate = true
const
 

Draws text to drawable

Parameters:
w the drawable
screen screen number
gc Graphic Context
text the text buffer
len size of text buffer
x position
y position
rotate if the text should be drawn rotated (if it's rotated before)

Definition at line 200 of file Font.cc.

References FbTk::XFontImp::drawText(), FbTk::GContext::gc(), isRotated(), FbTk::GContext::setForeground(), and FbTk::XFontImp::setRotate().

00202                                        {
00203     if (text == 0 || len == 0)
00204         return;
00205 
00206     // so we don't end up in a loop with m_shadow
00207     static bool first_run = true; 
00208 
00209     // draw shadow first
00210     if (first_run && m_shadow) {
00211         FbTk::GContext shadow_gc(w);
00212         shadow_gc.setForeground(FbTk::Color("black", screen));
00213         first_run = false; // so we don't end up in a loop
00214         drawText(w, screen, shadow_gc.gc(), text, len, x + 1, y + 1);
00215         first_run = true;
00216     }
00217 
00218     if (!rotate && isRotated()) {
00219         // if this was called with request to not rotated the text
00220         // we just forward it to the implementation that handles rotation
00221         // currently just XFontImp
00222         // Using dynamic_cast just temporarly until there's a better solution 
00223         // to put in FontImp
00224         try {
00225             XFontImp *font = dynamic_cast<XFontImp *>(m_fontimp.get());
00226             font->setRotate(false); // disable rotation temporarly
00227 
00228             font->drawText(w, screen, gc, text, len, x, y);
00229             font->setRotate(true); // enable rotation
00230         } catch (std::bad_cast &bc) {
00231             // draw normal...
00232             m_fontimp->drawText(w, screen, gc, text, len, x, y);
00233         }
00234 
00235     } else
00236         m_fontimp->drawText(w, screen, gc, text, len, x, y);        
00237 
00238 
00239 }   

bool FbTk::Font::load const std::string &  name  ) 
 

Load a font

Returns:
true on success, else false and it'll fall back on the last loaded font

Definition at line 140 of file Font.cc.

00140                                      {
00141     if (name.size() == 0)
00142         return false;
00143     // copy name so we can manipulate it
00144     std::string new_name = name;
00145 
00146     m_shadow = false;
00147 
00148     // find font option "shadow"    
00149     size_t start_pos = new_name.find_first_of(':');
00150     if (start_pos != std::string::npos) {        
00151         size_t shadow_pos = new_name.find("shadow", start_pos);
00152         if (shadow_pos != std::string::npos) {
00153             m_shadow = true;
00154             // erase "shadow" since it's not a valid option for the font
00155             new_name.erase(shadow_pos, 6);
00156             
00157             // is the option row empty?
00158             if (new_name.find_first_not_of("\t ,", start_pos + 1) == std::string::npos)
00159                 new_name.erase(start_pos); // erase the ':' and the rest of the line
00160             else {
00161                 // there might be some options left so we need to remove the ","
00162                 // before/after "shadow" option
00163                 size_t pos = new_name.find_last_not_of("\t ", shadow_pos);
00164                 if (pos != std::string::npos) {
00165                     if (new_name[pos] == ',')
00166                         new_name.erase(pos, 1);
00167                 
00168                 }
00169 
00170                 // ok, we removed the "," and "shadow" now we need to determine
00171                 // if we need to remove the ":" , so we search for anything except
00172                 // \t and space and if we dont find anything the ":" is removed
00173                 if (new_name.find_first_not_of("\t ", start_pos + 1) == std::string::npos)
00174                     new_name.erase(start_pos, 1);               
00175 
00176             }
00177 
00178         }
00179     }
00180 
00181     m_fontstr = name;
00182     return m_fontimp->load(new_name.c_str());
00183 }

void FbTk::Font::rotate float  angle  ) 
 

Rotate font in any angle (currently only 90 degrees supported and just XFont implementation)

Definition at line 241 of file Font.cc.

References isRotated().

00241                              {
00242 #ifdef USE_XFT
00243     // if we are rotated and we are changing to horiz text 
00244     // and we were antialiased before we rotated then change to XftFontImp
00245     if (isRotated() && angle == 0 && isAntialias())
00246         m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode));
00247 #endif // USE_XFT
00248     // change to a font imp that handles rotated fonts (i.e just XFontImp at the moment)
00249     // if we're going to rotate this font
00250     if (angle != 0 && isAntialias() && !isRotated()) {
00251         m_fontimp.reset(new XFontImp(m_fontstr.c_str()));
00252         if (!m_fontimp->loaded()) // if it failed to load font, try default font fixed
00253             m_fontimp->load("fixed");
00254     }
00255 
00256     //Note: only XFontImp implements FontImp::rotate
00257     m_fontimp->rotate(angle);
00258 
00259     m_rotated = (angle == 0 ? false : true);
00260     m_angle = angle;
00261 }

unsigned int FbTk::Font::textWidth const char *const   text,
unsigned int  size
const
 

Parameters:
text text to check size
size length of text in bytes
Returns:
size of text in pixels

Definition at line 185 of file Font.cc.

Referenced by FbTk::doAlignment(), and FbTk::Menu::drawItem().

00185                                                                              {
00186     return m_fontimp->textWidth(text, size);
00187 }


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

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA