all repos — openbox @ c6f228f3ff9ab7087669366a23d2ae61d8e5b9b9

openbox fork - make it a bit more like ryudo

xft2 works. and works good.
Dana Jansens danakj@orodu.net
commit

c6f228f3ff9ab7087669366a23d2ae61d8e5b9b9

parent

f77502100a32a6f875f33ef2ab01802f1cbc7c69

M otk/focuslabel.ccotk/focuslabel.cc

@@ -5,18 +5,25 @@ # include "../config.h"

#endif #include "focuslabel.hh" +#include "display.hh" +#include "screeninfo.hh" namespace otk { OtkFocusLabel::OtkFocusLabel(OtkWidget *parent) : OtkFocusWidget(parent), _text("") { + const ScreenInfo *info = OBDisplay::screenInfo(getScreen()); + _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(), + info->getColormap()); + setTexture(getStyle()->getLabelFocus()); setUnfocusTexture(getStyle()->getLabelUnfocus()); } OtkFocusLabel::~OtkFocusLabel() { + XftDrawDestroy(_xftdraw); } void OtkFocusLabel::update(void)

@@ -58,7 +65,7 @@ }

OtkFocusWidget::update(); - ft.drawString(getWindow(), x, bevel, *text_color, t); + ft.drawString(_xftdraw, x, bevel, *text_color, t); } else OtkFocusWidget::update(); }
M otk/focuslabel.hhotk/focuslabel.hh

@@ -2,6 +2,7 @@ #ifndef __label_hh

#define __label_hh #include "focuswidget.hh" +#include "font.hh" namespace otk {

@@ -18,7 +19,9 @@

void update(void); private: - + //! Object used by Xft to render to the drawable + XftDraw *_xftdraw; + //! Text displayed in the label std::string _text; };
M otk/font.ccotk/font.cc

@@ -23,58 +23,70 @@ #include "display.hh"

#include "color.hh" #include "screeninfo.hh" +extern "C" { +#ifdef HAVE_STDIO_H +# include <stdio.h> +#endif // HAVE_STDIO_H + +#include "gettext.h" +#define _(str) gettext(str) +} + namespace otk { -string BFont::_fallback_font = "fixed"; +string BFont::_fallback_font = "fixed"; +bool BFont::_xft_init = false; -BFont::BFont(int screen_num, const string &family, int size, - bool bold, bool italic, bool shadow, unsigned char offset, - unsigned char tint, bool antialias) : - _screen_num(screen_num), - _family(family), - _simplename(False), - _size(size), - _bold(bold), - _italic(italic), - _antialias(antialias), - _shadow(shadow), - _offset(offset), - _tint(tint), - _xftfont(0) { - _valid = False; +BFont::BFont(int screen_num, const string &fontstring, + bool shadow, unsigned char offset, unsigned char tint) + : _screen_num(screen_num), + _fontstring(fontstring), + _shadow(shadow), + _offset(offset), + _tint(tint), + _xftfont(0) +{ + assert(screen_num >= 0); + assert(tint <= CHAR_MAX); + + if (!_xft_init) { + if (!XftInit(0)) { + printf(_("Couldn't initialize Xft version %d.\n\n"), XftVersion); + ::exit(3); + } + printf(_("Using Xft %d.\n"), XftVersion); + _xft_init = true; + } + + if ((_xftfont = XftFontOpenName(OBDisplay::display, _screen_num, + _fontstring.c_str()))) + return; - _xftfont = XftFontOpen(OBDisplay::display, _screen_num, - XFT_FAMILY, XftTypeString, _family.c_str(), - XFT_SIZE, XftTypeInteger, _size, - XFT_WEIGHT, XftTypeInteger, (_bold ? - XFT_WEIGHT_BOLD : - XFT_WEIGHT_MEDIUM), - XFT_SLANT, XftTypeInteger, (_italic ? - XFT_SLANT_ITALIC : - XFT_SLANT_ROMAN), - XFT_ANTIALIAS, XftTypeBool, _antialias, - 0); - if (! _xftfont) - return; // failure + printf(_("Unable to load font: %s"), _fontstring.c_str()); + printf(_("Trying fallback font: %s\n"), _fallback_font.c_str()); - _valid = True; + if ((_xftfont = XftFontOpenName(OBDisplay::display, _screen_num, + _fallback_font.c_str()))) + return; + + printf(_("Unable to load font: %s"), _fallback_font.c_str()); + printf(_("Aborting!.\n")); + + ::exit(3); // can't continue without a font } -BFont::~BFont(void) { +BFont::~BFont(void) +{ if (_xftfont) XftFontClose(OBDisplay::display, _xftfont); } -void BFont::drawString(Drawable d, int x, int y, const BColor &color, - const string &string) const { - assert(_valid); - - const ScreenInfo *info = OBDisplay::screenInfo(_screen_num); - XftDraw *draw = XftDrawCreate(OBDisplay::display, d, - info->getVisual(), info->getColormap()); - assert(draw); +void BFont::drawString(XftDraw *d, int x, int y, const BColor &color, + const string &string, bool utf8) const +{ + assert(d); if (_shadow) { XftColor c;

@@ -84,10 +96,14 @@ c.color.blue = 0;

c.color.alpha = _tint | _tint << 8; // transparent shadow c.pixel = BlackPixel(OBDisplay::display, _screen_num); - XftDrawString8(draw, &c, _xftfont, x + _offset, - _xftfont->ascent + y + _offset, - (XftChar8 *) string.c_str(), - string.size()); + if (utf8) + XftDrawStringUtf8(d, &c, _xftfont, x + _offset, + _xftfont->ascent + y + _offset, + (const FcChar8*)string.c_str(), string.size()); + else + XftDrawString8(d, &c, _xftfont, x + _offset, + _xftfont->ascent + y + _offset, + (const FcChar8*)string.c_str(), string.size()); } XftColor c;

@@ -97,36 +113,40 @@ c.color.blue = color.blue() | color.blue() << 8;

c.pixel = color.pixel(); c.color.alpha = 0xff | 0xff << 8; // no transparency in BColor yet - XftDrawString8(draw, &c, _xftfont, x, _xftfont->ascent + y, - (XftChar8 *) string.c_str(), string.size()); + if (utf8) + XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y, + (const FcChar8*)string.c_str(), string.size()); + else + XftDrawString8(d, &c, _xftfont, x, _xftfont->ascent + y, + (const FcChar8*)string.c_str(), string.size()); - XftDrawDestroy(draw); return; } -unsigned int BFont::measureString(const string &string) const { - assert(_valid); - +unsigned int BFont::measureString(const string &string, bool utf8) const +{ XGlyphInfo info; - XftTextExtents8(OBDisplay::display, _xftfont, - (XftChar8 *) string.c_str(), string.size(), &info); + if (utf8) + XftTextExtentsUtf8(OBDisplay::display, _xftfont, + (const FcChar8*)string.c_str(), string.size(), &info); + else + XftTextExtents8(OBDisplay::display, _xftfont, + (const FcChar8*)string.c_str(), string.size(), &info); return info.xOff + (_shadow ? _offset : 0); } -unsigned int BFont::height(void) const { - assert(_valid); - +unsigned int BFont::height(void) const +{ return _xftfont->height + (_shadow ? _offset : 0); } -unsigned int BFont::maxCharWidth(void) const { - assert(_valid); - +unsigned int BFont::maxCharWidth(void) const +{ return _xftfont->max_advance_width; }
M otk/font.hhotk/font.hh

@@ -4,6 +4,7 @@ #define __Font_hh

extern "C" { #include <X11/Xlib.h> +#define _XFT_NO_COMPAT_ // no Xft 1 API #include <X11/Xft/Xft.h> }

@@ -23,6 +24,7 @@ * 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

@@ -37,13 +39,8 @@ */

private: 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;

@@ -52,29 +49,27 @@ XftFont *_xftfont;

bool createXftFont(void); - bool _valid; - public: // loads an Xft font - BFont(int screen_num, const std::string &family, int size, - bool bold, bool italic, bool shadow, unsigned char offset, - unsigned char tint, bool antialias = True); - virtual ~BFont(void); + BFont(int screen_num, const std::string &fontstring, bool shadow, + unsigned char offset, unsigned char tint); + virtual ~BFont(); - inline bool valid(void) const { return _valid; } + inline const std::string &fontstring() const { return _fontstring; } - 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 height() const; + unsigned int maxCharWidth() const; - unsigned int measureString(const std::string &string) const; + unsigned int measureString(const std::string &string, + bool utf8 = false) const; - void drawString(Drawable d, int x, int y, const BColor &color, - const std::string &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! :) + */ + void drawString(XftDraw *d, int x, int y, const BColor &color, + const std::string &string, bool utf8 = false) const; }; }
M otk/label.ccotk/label.cc

@@ -11,11 +11,16 @@

OtkLabel::OtkLabel(OtkWidget *parent) : OtkWidget(parent), _text("") { + const ScreenInfo *info = OBDisplay::screenInfo(getScreen()); + _xftdraw = XftDrawCreate(OBDisplay::display, getWindow(), info->getVisual(), + info->getColormap()); + setTexture(getStyle()->getLabelUnfocus()); } OtkLabel::~OtkLabel() { + XftDrawDestroy(_xftdraw); } void OtkLabel::update(void)

@@ -55,7 +60,7 @@ }

OtkWidget::update(); - ft.drawString(getWindow(), x, bevel, *getStyle()->getTextUnfocus(), t); + ft.drawString(_xftdraw, x, bevel, *getStyle()->getTextUnfocus(), t); } else OtkWidget::update(); }
M otk/label.hhotk/label.hh

@@ -2,6 +2,7 @@ #ifndef __label_hh

#define __label_hh #include "widget.hh" +#include "font.hh" namespace otk {

@@ -18,7 +19,9 @@

void update(void); private: - + //! Object used by Xft to render to the drawable + XftDraw *_xftdraw; + //! Text displayed in the label std::string _text; };
M otk/style.ccotk/style.cc

@@ -234,53 +234,28 @@

BFont *Style::readDatabaseFont(const std::string &rbasename, const Configuration &style) { - std::string fontname; + std::string fontstring, s; - std::string s; + // XXX: load all this font stuff from the style... - int i; - if (style.getValue(rbasename + "xft.font", s) && - style.getValue(rbasename + "xft.size", i)) { - std::string family = s; - bool bold = False; - bool italic = False; - bool dropShadow = False; - - if (style.getValue(rbasename + "xft.flags", s)) { - if (s.find("bold") != std::string::npos) - bold = True; - if (s.find("italic") != std::string::npos) - italic = True; - if (s.find("shadow") != std::string::npos) - dropShadow = True; - } + bool dropShadow = True; - unsigned char offset = 1; - if (style.getValue(rbasename + "xft.shadow.offset", s)) { - offset = atoi(s.c_str()); //doesn't detect errors - if (offset > CHAR_MAX) - offset = 1; - } + unsigned char offset = 1; + if (style.getValue(rbasename + "xft.shadow.offset", s)) { + offset = atoi(s.c_str()); //doesn't detect errors + if (offset > CHAR_MAX) + offset = 1; + } - unsigned char tint = 0x40; - if (style.getValue(rbasename + "xft.shadow.tint", s)) { - tint = atoi(s.c_str()); - } - - - BFont *b = new BFont(screen_number, family, i, bold, italic, - dropShadow && shadow_fonts, - offset, tint, aa_fonts); - if (b->valid()) - return b; - delete b; + unsigned char tint = 0x40; + if (style.getValue(rbasename + "xft.shadow.tint", s)) { + tint = atoi(s.c_str()); } - if (style.getValue(rbasename + "xft.font", s)) - printf("Unable to load font \"%s\". Exiting\n", s.c_str()); - else - printf("Font not defined by style. Exiting\n"); - exit(2); // can't continue without a font + fontstring = "Arial,Sans-8:bold"; + + // if this fails, it ::exit()'s + return new BFont(screen_number, fontstring, dropShadow, offset, tint); } }
M po/POTFILES.inpo/POTFILES.in

@@ -1,5 +1,6 @@

# List of source files containing translatable strings. - +otk/display.cc +otk/font.cc src/openbox.cc src/display.cc src/client.cc