X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=otk%2Ffont.hh;h=8e736d8eb746c3958c3b24ddd41ead0c4ec2f92f;hb=74061b4e2d33d7e2101c4edda26cfc2a1294f32b;hp=c070bbff9a4511d2589878eca0f171c3daba0d7e;hpb=85c41a1aec90b8daefc425596ea34b6f9d0e643c;p=chaz%2Fopenbox diff --git a/otk/font.hh b/otk/font.hh index c070bbff..8e736d8e 100644 --- a/otk/font.hh +++ b/otk/font.hh @@ -1,10 +1,12 @@ -// -*- mode: C++; indent-tabs-mode: nil; -*- -#ifndef __Font_hh -#define __Font_hh +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __font_hh +#define __font_hh + +#include "userstring.hh" extern "C" { #include - +#define _XFT_NO_COMPAT_ // no Xft 1 API #include } @@ -12,18 +14,17 @@ extern "C" { #include -class BGCCache; -class BGCCacheItem; -class BColor; +namespace otk { -#include "screen.hh" +class Color; -class BFont { +class Font { /* * static members */ private: static std::string _fallback_font; + static bool _xft_init; public: // the fallback is only used for X fonts, not for Xft fonts, since it is @@ -36,16 +37,10 @@ public: * instance members */ private: - Display *_display; - BScreen *_screen; + int _screen_num; - std::string _family; - bool _simplename; // true if not spec'd as a -*-* string - int _size; - bool _bold; - bool _italic; + std::string _fontstring; - bool _antialias; bool _shadow; unsigned char _offset; unsigned char _tint; @@ -54,29 +49,37 @@ private: bool createXftFont(void); - bool _valid; - public: // loads an Xft font - BFont(Display *d, BScreen *screen, const std::string &family, int size, - bool bold, bool italic, bool shadow, unsigned char offset, - unsigned char tint, bool antialias = True); - virtual ~BFont(void); - - inline bool valid(void) const { return _valid; } - - inline std::string family(void) const { assert(_valid); return _family; } - inline int size(void) const { assert(_valid); return _size; } - inline bool bold(void) const { assert(_valid); return _bold; } - inline bool italic(void) const { assert(_valid); return _italic; } - - unsigned int height(void) const; - unsigned int maxCharWidth(void) const; - - unsigned int measureString(const std::string &string) const; - - void drawString(Drawable d, int x, int y, const BColor &color, - const std::string &string) const; + Font(int screen_num, const std::string &fontstring, bool shadow, + unsigned char offset, unsigned char tint); + virtual ~Font(); + + inline const std::string &fontstring() const { return _fontstring; } + + unsigned int height() const; + unsigned int maxCharWidth() const; + + //! Measures the length of a string + /*! + @param string The string to measure, it should be UTF8 encoded. + */ + unsigned int measureString(const userstring &string) const; + + //! Draws a string into an XftDraw object + /*! + Be Warned: If you use an XftDraw object and a color, or a font from + different screens, you WILL have unpredictable results! :) + @param d The drawable to render into. + @param x The X offset onto the drawable at which to start drawing. + @param x The Y offset onto the drawable at which to start drawing. + @param color The color to use for drawing the text. + @param string The string to draw, it should be UTF8 encoded. + */ + void drawString(XftDraw *d, int x, int y, const Color &color, + const userstring &string) const; }; -#endif // __Font_hh +} + +#endif // __font_hh