- Usage of xft-fonts is prefered, except a font-description starts with '-'

- Removed "antialias"-option completly, to enable/disable "antialias"
  use either  <fontname>:antialias=<bool> in the style or use
  Xft.antialias: <bool> in your .Xdefaults
- Added new styleresources: 
    *.font.effect: <halo|shadow>
    *.font.shadow.x : <int>       - shadow x offset
    *.font.shadow.y : <int>       - shadow y offset
    *.font.shadow.color : <color> - color of shadow
    *.font.halo.color : <color>   - color of halo
- Removed 'shadow' and 'halo' options from fontdefinitions:
    !! Style authors have to update their styles !!
- Simplified XmbFontImp to not try all possible fonts to match locale
- Style authors may specify multiple fonts:
    <font1>|<font2>|<font3>
  if loading of font1 fails, fluxbox probes <font2>, etc. The last font is
  "fixed". Hints for style authors:
    - if xft tries to load a font it will _ALWAYS_ return a valid font,
      it doesnt have to look like the one you want to have, read more
      about it: http://fontconfig.org/fontconfig-user.html
    - export XFT_DEBUG=1  before running fluxbox helps to see
      which fonts are picked.
  eg:
      *.font: Verdana,Arial-12:antialias=true|-artwiz-snap-*-
      if fluxbox is compiled with xft this will NEVER try to
      load "-artwiz-snap-*-" since xft gives for sure a font,
      most likely Verdana or Arial but noone knows. So, if
      fluxbox has no xft support the first fontpattern fails
      and fluxbox tries the next one, which might be successful.
      if everything fails, it will use "fixed"
- Added caching of fonts, fonts are only loaded once.
- Fixed #1090902 (slow utf8 start)
This commit is contained in:
mathias 2005-06-03 07:25:48 +00:00
parent 9c27e2e799
commit ef76b45ab1
18 changed files with 237 additions and 278 deletions

View file

@ -1,5 +1,43 @@
(Format: Year/Month/Day) (Format: Year/Month/Day)
Changes for 0.9.14: Changes for 0.9.14:
*05/06/03:
* Massive change of font handling (Mathias)
- Usage of xft-fonts is prefered, except a font-description starts with '-'
- Removed "antialias"-option completly, to enable/disable "antialias"
use either <fontname>:antialias=<bool> in the style or use
Xft.antialias: <bool> in your .Xdefaults
- Added new styleresources:
*.font.effect: <halo|shadow>
*.font.shadow.x : <int> - shadow x offset
*.font.shadow.y : <int> - shadow y offset
*.font.shadow.color : <color> - color of shadow
*.font.halo.color : <color> - color of halo
- Removed 'shadow' and 'halo' options from fontdefinitions:
!! Style authors have to update their styles !!
- Simplified XmbFontImp to not try all possible fonts to match locale
- Style authors may specify multiple fonts:
<font1>|<font2>|<font3>
if loading of font1 fails, fluxbox probes <font2>, etc. The last font is
"fixed". Hints for style authors:
- if xft tries to load a font it will _ALWAYS_ return a valid font,
it doesnt have to look like the one you want to have, read more
about it: http://fontconfig.org/fontconfig-user.html
- export XFT_DEBUG=1 before running fluxbox helps to see
which fonts are picked.
eg:
*.font: Verdana,Arial-12:antialias=true|-artwiz-snap-*-
if fluxbox is compiled with xft this will NEVER try to
load "-artwiz-snap-*-" since xft gives for sure a font,
most likely Verdana or Arial but noone knows. So, if
fluxbox has no xft support the first fontpattern fails
and fluxbox tries the next one, which might be successful.
if everything fails, it will use "fixed"
- Added caching of fonts, fonts are only loaded once.
- Fixed #1090902
ToolFactory.cc TextTheme.hh/cc IconbarTheme.cc Screen.hh/cc
FbTk/Font.hh/cc FbTk/XftFontImp.cc FbTk/XmbFontImp.cc
FbTk/MenuTheme.cc FbTk/Texture.cc FbTk/ThemeItems.cc
fbrun/main.cc fbrun/FbRun.cc
*05/06/02: *05/06/02:
* Fixed _BLACKBOX_NOTIFY_WINDOW_ADD issue (thanx Vadim) * Fixed _BLACKBOX_NOTIFY_WINDOW_ADD issue (thanx Vadim)
_BLACKBOX_NOTIFY_WINDOW_ADD was emited before _NET_CLIENT_LIST _BLACKBOX_NOTIFY_WINDOW_ADD was emited before _NET_CLIENT_LIST

View file

@ -27,6 +27,7 @@
#include "Font.hh" #include "Font.hh"
#include "FontImp.hh" #include "FontImp.hh"
#include "I18n.hh" #include "I18n.hh"
#include "App.hh"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -67,6 +68,7 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <list> #include <list>
#include <map>
#include <typeinfo> #include <typeinfo>
#include <langinfo.h> #include <langinfo.h>
@ -148,69 +150,15 @@ char *recode(int cd,
} }
#endif // HAVE_ICONV #endif // HAVE_ICONV
int extract_halo_options(const std::string& opts, std::string& color) { // use to map <font1>|<font2>|<font3> => <fontthatworks>
std::list< std::string > tokens; typedef std::map<std::string, std::string> StringMap;
size_t sep= opts.find_first_of(':'); typedef StringMap::iterator StringMapIt;
StringMap lookup_map;
if ( sep == std::string::npos ) // stores <fontthatworks and the fontimp
return 1; typedef std::map<std::string, FbTk::FontImp* > FontCache;
typedef FontCache::iterator FontCacheIt;
FbTk::StringUtil::stringtok(tokens, opts.substr(sep + 1, opts.length()), ";"); FontCache font_cache;
tokens.unique();
std::list< std::string >::const_iterator token;
for ( token= tokens.begin(); token != tokens.end(); token++ ) {
if ( (*token).find("color=", 0) != std::string::npos ) {
size_t s= (*token).find_first_of('=');
std::string c= (*token).substr(s + 1, (*token).length());
if ( !c.empty() )
std::swap(color, c);
}
}
return 1;
}
int extract_shadow_options(const std::string& opts,
std::string& color,
int& offx, int& offy) {
std::list< std::string > tokens;
size_t sep= opts.find_first_of(':');
if ( sep == std::string::npos )
return 1;
FbTk::StringUtil::stringtok(tokens, opts.substr(sep + 1, opts.length()), ";");
tokens.unique();
std::list< std::string >::const_iterator token;
for ( token= tokens.begin(); token != tokens.end(); token++ ) {
if ( (*token).find("color=", 0) != std::string::npos ) {
size_t s= (*token).find_first_of('=');
std::string c= (*token).substr(s + 1, (*token).length());
if ( !c.empty() )
std::swap(color, c);
}
else if ( (*token).find("offsetx=", 0) != std::string::npos ) {
size_t s= (*token).find_first_of('=');
FbTk_istringstream o((*token).substr(s + 1, (*token).length()).c_str());
if ( !o.eof() ) {
o >> offx;
}
}
else if ( (*token).find("offsety=", 0) != std::string::npos ) {
size_t s= (*token).find_first_of('=');
FbTk_istringstream o((*token).substr(s + 1, (*token).length()).c_str());
if ( !o.eof() ) {
o >> offy;
}
}
}
return 1;
};
}; // end nameless namespace }; // end nameless namespace
@ -218,8 +166,8 @@ int extract_shadow_options(const std::string& opts,
namespace FbTk { namespace FbTk {
bool Font::m_multibyte = false; bool Font::s_multibyte = false;
bool Font::m_utf8mode = false; bool Font::s_utf8mode = false;
void Font::init() { void Font::init() {
@ -229,24 +177,34 @@ void Font::init() {
void Font::shutdown() { void Font::shutdown() {
FontCacheIt fit;
for (fit = font_cache.begin(); fit != font_cache.end(); fit++) {
FontImp* font = fit->second;
if (font) {
FontCacheIt it;
for (it = fit; it != font_cache.end(); it++)
if (it->second == font)
it->second = 0;
delete font;
}
}
} }
Font::Font(const char *name, bool antialias): Font::Font(const char *name):
m_fontimp(0), m_fontimp(0),
m_antialias(false), m_rotated(false), m_rotated(false),
m_shadow(false), m_shadow_color("#000000"), m_shadow(false), m_shadow_color("black", DefaultScreen(App::instance()->display())),
m_shadow_offx(1), m_shadow_offy(1), m_shadow_offx(2), m_shadow_offy(2),
m_halo(false), m_halo_color("#ffffff"), m_halo(false), m_halo_color("white", DefaultScreen(App::instance()->display())),
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
m_iconv((iconv_t)(-1)) m_iconv((iconv_t)(-1))
#else #else
m_iconv(-1) m_iconv(-1)
#endif // HAVE_ICONV #endif // HAVE_ICONV
{ {
// MB_CUR_MAX returns the size of a char in the current locale // MB_CUR_MAX returns the size of a char in the current locale
if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte
m_multibyte = true; s_multibyte = true;
// check for utf-8 mode // check for utf-8 mode
#ifdef CODESET #ifdef CODESET
@ -256,7 +214,7 @@ Font::Font(const char *name, bool antialias):
#endif // CODESET #endif // CODESET
if (locale_codeset && strcmp("UTF-8", locale_codeset) == 0) { if (locale_codeset && strcmp("UTF-8", locale_codeset) == 0) {
m_utf8mode = true; s_utf8mode = true;
} else if (locale_codeset != 0) { } else if (locale_codeset != 0) {
// if locale isn't UTF-8 we try to // if locale isn't UTF-8 we try to
// create a iconv pointer so we can // create a iconv pointer so we can
@ -272,13 +230,13 @@ Font::Font(const char *name, bool antialias):
cerr<<"FbTk::Font: code error: from "<<locale_codeset<<" to: UTF-8"<<endl; cerr<<"FbTk::Font: code error: from "<<locale_codeset<<" to: UTF-8"<<endl;
// if we failed with iconv then we can't convert // if we failed with iconv then we can't convert
// the strings to utf-8, so we disable utf8 mode // the strings to utf-8, so we disable utf8 mode
m_utf8mode = false; s_utf8mode = false;
} else { } else {
// success, we can now enable utf8mode // success, we can now enable utf8mode
// and if antialias is on later we can recode // and if antialias is on later we can recode
// the non utf-8 string to utf-8 and use utf-8 // the non utf-8 string to utf-8 and use utf-8
// drawing functions // drawing functions
m_utf8mode = true; s_utf8mode = true;
} }
#endif // HAVE_ICONV #endif // HAVE_ICONV
} }
@ -287,23 +245,6 @@ Font::Font(const char *name, bool antialias):
cerr<<"FbTk::Font m_iconv = "<<(int)m_iconv<<endl; cerr<<"FbTk::Font m_iconv = "<<(int)m_iconv<<endl;
#endif // DEBUG #endif // DEBUG
// create the right font implementation
// antialias is prio 1
#ifdef USE_XFT
if (antialias) {
m_fontimp.reset(new XftFontImp(0, m_utf8mode));
}
#endif //USE_XFT
// if we didn't create a Xft font then create basic font
if (m_fontimp.get() == 0) {
#ifdef USE_XMB
if (m_multibyte || m_utf8mode)
m_fontimp.reset(new XmbFontImp(0, m_utf8mode));
else // basic font implementation
#endif // USE_XMB
m_fontimp.reset(new XFontImp());
}
if (name != 0) { if (name != 0) {
load(name); load(name);
} }
@ -317,82 +258,68 @@ Font::~Font() {
#endif // HAVE_ICONV #endif // HAVE_ICONV
} }
void Font::setAntialias(bool flag) {
bool loaded = m_fontimp->loaded();
#ifdef USE_XFT
if (flag && !isAntialias() && !m_rotated) {
m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode));
} else if (!flag && isAntialias())
#endif // USE_XFT
{
#ifdef USE_XMB
if (m_multibyte || m_utf8mode)
m_fontimp.reset(new XmbFontImp(m_fontstr.c_str(), m_utf8mode));
else
#endif // USE_XMB
m_fontimp.reset(new XFontImp(m_fontstr.c_str()));
}
if (m_fontimp->loaded() != loaded) { // if the new font failed to load, fall back to 'fixed'
if (!m_fontimp->load("fixed")) {// if that failes too, output warning
_FB_USES_NLS;
cerr<<_FBTKTEXT(Error, CantFallbackFont, "Warning: can't load fallback font", "Attempt to load the last-resort default font failed")<<" 'fixed'."<<endl;
}
}
m_antialias = flag;
}
bool Font::load(const std::string &name) { bool Font::load(const std::string &name) {
if (name.size() == 0) if (name.size() == 0)
return false; return false;
// default values for font options
m_shadow = false; StringMapIt lookup_entry;
m_halo = false; FontCacheIt cache_entry;
// everything after ':' is a fontoption // check if one of <font1>|<font2>|<font3> is already there
// -> extract 'halo' and 'shadow' and if ((lookup_entry = lookup_map.find(name)) != lookup_map.end() &&
// load remaining fname (cache_entry = font_cache.find(lookup_entry->second)) != font_cache.end()) {
size_t sep= name.find_first_of(':'); m_fontstr = cache_entry->first;
m_fontimp = cache_entry->second;
return true;
}
// split up the namelist
typedef std::list<std::string> StringList;
typedef StringList::iterator StringListIt;
StringList names;
FbTk::StringUtil::stringtok<StringList>(names, name, "|");
StringListIt name_it;
for (name_it = names.begin(); name_it != names.end(); name_it++) {
FbTk::StringUtil::removeTrailingWhitespace(*name_it);
FbTk::StringUtil::removeFirstWhitespace(*name_it);
if ( sep != std::string::npos ) { if ((cache_entry = font_cache.find(*name_it)) != font_cache.end()) {
m_fontstr = cache_entry->first;
std::list< std::string > tokens; m_fontimp = cache_entry->second;
std::string fname; lookup_map[name] = m_fontstr;
return true;
fname= std::string(name.c_str(), sep);
FbTk::StringUtil::stringtok(tokens, name.substr(sep + 1), ",");
tokens.unique();
bool firstone= true;
std::list< std::string >::const_iterator token;
// check tokens and extract extraoptions for halo and shadow
for( token= tokens.begin(); token != tokens.end(); token++ ) {
if ( (*token).find("halo",0) != std::string::npos ) {
m_halo= true;
extract_halo_options(*token, m_halo_color);
}
else if ( (*token).find("shadow", 0) != std::string::npos ) {
m_shadow= true;
extract_shadow_options(*token, m_shadow_color, m_shadow_offx, m_shadow_offy);
}
else {
if ( !firstone )
fname+= ", ";
else
firstone= false;
fname= fname + ":" + *token;
}
} }
m_fontstr = fname; FontImp* tmp_font(0);
} else
m_fontstr = name; #ifdef USE_XFT
if ((*name_it)[0] != '-')
tmp_font = new XftFontImp(0, s_utf8mode);
#endif // USE_XFT
if (!tmp_font) {
#ifdef USE_XMB
if (s_multibyte || s_utf8mode)
tmp_font = new XmbFontImp(0, s_utf8mode);
else // basic font implementation
#endif // USE_XMB
tmp_font = new XFontImp();
}
return m_fontimp->load(m_fontstr.c_str()); if (tmp_font && tmp_font->load((*name_it).c_str())) {
lookup_map[name] = (*name_it);
m_fontimp = tmp_font;
font_cache[(*name_it)] = tmp_font;
m_fontstr = name;
return true;
}
delete tmp_font;
}
return false;;
} }
unsigned int Font::textWidth(const char * const text, unsigned int size) const { unsigned int Font::textWidth(const char * const text, unsigned int size) const {
@ -449,14 +376,14 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
if (first_run) { if (first_run) {
if (m_shadow) { if (m_shadow) {
FbTk::GContext shadow_gc(w); FbTk::GContext shadow_gc(w);
shadow_gc.setForeground(FbTk::Color(m_shadow_color.c_str(), screen)); shadow_gc.setForeground(m_shadow_color);
first_run = false; first_run = false;
drawText(w, screen, shadow_gc.gc(), real_text, len, drawText(w, screen, shadow_gc.gc(), real_text, len,
x + m_shadow_offx, y + m_shadow_offy, rotate); x + m_shadow_offx, y + m_shadow_offy, rotate);
first_run = true; first_run = true;
} else if (m_halo) { } else if (m_halo) {
FbTk::GContext halo_gc(w); FbTk::GContext halo_gc(w);
halo_gc.setForeground(FbTk::Color(m_halo_color.c_str(), screen)); halo_gc.setForeground(m_halo_color);
first_run = false; first_run = false;
drawText(w, screen, halo_gc.gc(), real_text, len, x + 1, y + 1, rotate); drawText(w, screen, halo_gc.gc(), real_text, len, x + 1, y + 1, rotate);
drawText(w, screen, halo_gc.gc(), real_text, len, x - 1, y + 1, rotate); drawText(w, screen, halo_gc.gc(), real_text, len, x - 1, y + 1, rotate);
@ -473,7 +400,7 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
// Using dynamic_cast just temporarly until there's a better solution // Using dynamic_cast just temporarly until there's a better solution
// to put in FontImp // to put in FontImp
try { try {
XFontImp *font = dynamic_cast<XFontImp *>(m_fontimp.get()); XFontImp *font = dynamic_cast<XFontImp *>(m_fontimp);
font->setRotate(false); // disable rotation temporarly font->setRotate(false); // disable rotation temporarly
font->drawText(w, screen, gc, real_text, len, x, y); font->drawText(w, screen, gc, real_text, len, x, y);
@ -492,15 +419,16 @@ void Font::drawText(const FbDrawable &w, int screen, GC gc,
} }
void Font::rotate(float angle) { void Font::rotate(float angle) {
/* TODO: reimplement rotated text
#ifdef USE_XFT #ifdef USE_XFT
// if we are rotated and we are changing to horiz text // if we are rotated and we are changing to horiz text
// and we were antialiased before we rotated then change to XftFontImp // and we were antialiased before we rotated then change to XftFontImp
if (isRotated() && angle == 0 && isAntialias()) if (isRotated() && angle == 0 && !m_xftfontstr.empty())
m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode)); m_fontimp.reset(new XftFontImp(m_fontstr.c_str(),s_utf8mode));
#endif // USE_XFT #endif // USE_XFT
// change to a font imp that handles rotated fonts (i.e just XFontImp at the moment) // change to a font imp that handles rotated fonts (i.e just XFontImp at the moment)
// if we're going to rotate this font // if we're going to rotate this font
if (angle != 0 && isAntialias() && !isRotated()) { if (angle != 0 && !isRotated()) {
m_fontimp.reset(new XFontImp(m_fontstr.c_str())); m_fontimp.reset(new XFontImp(m_fontstr.c_str()));
if (!m_fontimp->loaded()) // if it failed to load font, try default font fixed if (!m_fontimp->loaded()) // if it failed to load font, try default font fixed
m_fontimp->load("fixed"); m_fontimp->load("fixed");
@ -511,6 +439,7 @@ void Font::rotate(float angle) {
m_rotated = (angle == 0 ? false : true); m_rotated = (angle == 0 ? false : true);
m_angle = angle; m_angle = angle;
*/
} }

View file

@ -28,7 +28,6 @@
#include <X11/Xresource.h> #include <X11/Xresource.h>
#include <string> #include <string>
#include <memory>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -38,6 +37,8 @@
#include <iconv.h> #include <iconv.h>
#endif // HAVE_ICONV #endif // HAVE_ICONV
#include "Color.hh"
namespace FbTk { namespace FbTk {
class FontImp; class FontImp;
@ -56,13 +57,13 @@ public:
static void shutdown(); static void shutdown();
/// @return true if multibyte is enabled, else false /// @return true if multibyte is enabled, else false
static bool multibyte() { return m_multibyte; } static bool multibyte() { return s_multibyte; }
/// @return true if utf-8 mode is enabled, else false /// @return true if utf-8 mode is enabled, else false
static bool utf8() { return m_utf8mode; } static bool utf8() { return s_utf8mode; }
Font(const char *name=0, bool antialias = false); Font(const char *name = "fixed");
virtual ~Font(); virtual ~Font();
/** /**
Load a font Load a font
@ -70,10 +71,15 @@ public:
loaded font loaded font
*/ */
bool load(const std::string &name); bool load(const std::string &name);
void setAntialias(bool flag); void setHalo(bool flag) { m_halo = flag; if (m_halo) setShadow(false); }
inline void setShadow(bool flag) { m_shadow = flag; if (m_shadow) setHalo(false); } void setHaloColor(const Color& color) { m_halo_color = color; }
inline void setHalo(bool flag) { m_halo = flag; if (m_halo) setShadow(false); }
void setShadow(bool flag) { m_shadow = flag; if (m_shadow) setHalo(false); }
void setShadowColor(const Color& color) { m_shadow_color = color; }
void setShadowOffX(int offx) { m_shadow_offx = offx; }
void setShadowOffY(int offy) { m_shadow_offy = offy; }
/** /**
@param text text to check size @param text text to check size
@param size length of text in bytes @param size length of text in bytes
@ -103,28 +109,28 @@ public:
void drawText(const FbDrawable &w, int screen, GC gc, void drawText(const FbDrawable &w, int screen, GC gc,
const char *text, size_t len, const char *text, size_t len,
int x, int y, bool rotate=true) const; int x, int y, bool rotate=true) const;
bool isAntialias() const { return m_antialias; }
/// @return true if the font is rotated, else false /// @return true if the font is rotated, else false
bool isRotated() const { return m_rotated; } bool isRotated() const { return m_rotated; }
/// @return rotated angle /// @return rotated angle
float angle() const { return m_angle; } float angle() const { return m_angle; }
bool shadow() const { return m_shadow; } bool hasShadow() const { return m_shadow; }
bool halo() const { return m_halo; } bool hasHalo() const { return m_halo; }
private: private:
std::auto_ptr<FontImp> m_fontimp; ///< font implementation FbTk::FontImp* m_fontimp; ///< font implementation
std::string m_fontstr; ///< font name std::string m_fontstr; ///< font name
static bool m_multibyte; ///< if the fontimp should be a multibyte font
static bool m_utf8mode; ///< should the font use utf8 font imp static bool s_multibyte; ///< if the fontimp should be a multibyte font
bool m_antialias; ///< is font antialias static bool s_utf8mode; ///< should the font use utf8 font imp
bool m_rotated; ///< wheter we're rotated or not bool m_rotated; ///< wheter we're rotated or not
float m_angle; ///< rotation angle float m_angle; ///< rotation angle
bool m_shadow; ///< shadow text bool m_shadow; ///< shadow text
std::string m_shadow_color; ///< shadow color Color m_shadow_color; ///< shadow color
int m_shadow_offx; ///< offset y for shadow int m_shadow_offx; ///< offset y for shadow
int m_shadow_offy; ///< offset x for shadow int m_shadow_offy; ///< offset x for shadow
bool m_halo; ///< halo text bool m_halo; ///< halo text
std::string m_halo_color; ///< halo color Color m_halo_color; ///< halo color
#ifdef HAVE_ICONV #ifdef HAVE_ICONV
iconv_t m_iconv; iconv_t m_iconv;
#else #else

View file

@ -171,19 +171,4 @@ void ThemeItem<MenuTheme::BulletType>::load(const std::string *name, const std::
// do nothing, we don't have anything extra to load // do nothing, we don't have anything extra to load
} }
template <>
void ThemeItem<unsigned int>::setDefaultValue() {
m_value = 0;
}
template <>
void ThemeItem<unsigned int>::setFromString(const char *str) {
sscanf(str, "%d", &m_value);
}
template <>
void ThemeItem<unsigned int>::load(const std::string *name, const std::string *altname) {
}
}; // end namespace FbTk }; // end namespace FbTk

View file

@ -57,9 +57,7 @@ void Texture::setFromString(const char * const texture_str) {
} else { } else {
setType(Texture::NONE); setType(Texture::NONE);
if (strstr(ts, "solid")) if (strstr(ts, "gradient")) {
addType(Texture::SOLID);
else if (strstr(ts, "gradient")) {
addType(Texture::GRADIENT); addType(Texture::GRADIENT);
if (strstr(ts, "crossdiagonal")) if (strstr(ts, "crossdiagonal"))
addType(Texture::CROSSDIAGONAL); addType(Texture::CROSSDIAGONAL);
@ -79,17 +77,15 @@ void Texture::setFromString(const char * const texture_str) {
addType(Texture::VERTICAL); addType(Texture::VERTICAL);
else else
addType(Texture::DIAGONAL); addType(Texture::DIAGONAL);
} else } else // default is "solid", according to ThemeItems.cc
addType(Texture::SOLID); addType(Texture::SOLID);
if (strstr(ts, "raised")) if (strstr(ts, "raised"))
addType(Texture::RAISED); addType(Texture::RAISED);
else if (strstr(ts, "sunken")) else if (strstr(ts, "sunken"))
addType(Texture::SUNKEN); addType(Texture::SUNKEN);
else if (strstr(ts, "flat")) else // default us "flat", according to ThemeItems.cc
addType(Texture::FLAT); addType(Texture::FLAT);
else
addType(Texture::RAISED);
if (! (type() & Texture::FLAT)) if (! (type() & Texture::FLAT))
if (strstr(ts, "bevel2")) if (strstr(ts, "bevel2"))

View file

@ -26,6 +26,10 @@
#ifndef THEMEITEMS_HH #ifndef THEMEITEMS_HH
#define THEMEITEMS_HH #define THEMEITEMS_HH
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
#include "Theme.hh" #include "Theme.hh"
#include "Color.hh" #include "Color.hh"
#include "Texture.hh" #include "Texture.hh"
@ -98,9 +102,40 @@ void FbTk::ThemeItem<bool>::setFromString(char const *strval) {
} }
template <> template <>
void ThemeItem<unsigned int>::setDefaultValue() {
m_value = 0;
}
template <>
void ThemeItem<unsigned int>::setFromString(const char *str) {
sscanf(str, "%d", &m_value);
}
template <>
void ThemeItem<unsigned int>::load(const std::string *name, const std::string *altname) {
}
void ThemeItem<Font>::setDefaultValue() { void ThemeItem<Font>::setDefaultValue() {
if (!m_value.load("fixed")) { if (!m_value.load("fixed")) {
cerr<<"ThemeItem<Font>: Warning! Failed to load default value 'fixed'"<<endl; cerr<<"ThemeItem<Font>: Warning! Failed to load default value 'fixed'"<<endl;
} else {
string effect(ThemeManager::instance().resourceValue(name()+".effect", altName()+".Effect"));
if (effect == "halo") {
m_value.setHalo(true);
FbTk::Color halo_color(ThemeManager::instance().resourceValue(name()+".halo.color", altName()+".Halo.Color").c_str(),
theme().screenNum());
m_value.setHaloColor(halo_color);
} else if (effect == "shadow" ) {
FbTk::Color shadow_color(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str(),
theme().screenNum());
m_value.setShadow(true);
m_value.setShadowColor(shadow_color);
m_value.setShadowOffX(atoi(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str()));
m_value.setShadowOffY(atoi(ThemeManager::instance().resourceValue(name()+".shadow.y", altName()+".Shadow.Y").c_str()));
}
} }
} }
@ -110,19 +145,30 @@ void ThemeItem<Font>::setFromString(const char *str) {
if (str == 0 || m_value.load(str) == false) { if (str == 0 || m_value.load(str) == false) {
if (ThemeManager::instance().verbose()) { if (ThemeManager::instance().verbose()) {
cerr<<"Theme: Error loading font "<< cerr<<"Theme: Error loading font "<<
((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< ((m_value.utf8()) ? "(utf8)" : "")<<
(m_value.isAntialias() ? "antialias" : "")<<
(m_value.utf8() ? " utf8" : "")<<
((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
"for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl; "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
cerr<<"Theme: Setting default value"<<endl; cerr<<"Theme: Setting default value"<<endl;
} }
setDefaultValue(); setDefaultValue();
} } else {
string effect(ThemeManager::instance().resourceValue(name()+".effect", altName()+".Effect"));
if (effect == "halo") {
m_value.setHalo(true);
FbTk::Color halo_color(ThemeManager::instance().resourceValue(name()+".halo.color", altName()+".Halo.Color").c_str(),
theme().screenNum());
m_value.setHaloColor(halo_color);
} else if (effect == "shadow" ) {
FbTk::Color shadow_color(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str(),
theme().screenNum());
m_value.setShadow(true);
m_value.setShadowColor(shadow_color);
m_value.setShadowOffX(atoi(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str()));
m_value.setShadowOffY(atoi(ThemeManager::instance().resourceValue(name()+".shadow.y", altName()+".Shadow.Y").c_str()));
}
}
} }
// do nothing // do nothing

View file

@ -33,7 +33,6 @@ namespace FbTk {
XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0), XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0),
m_utf8mode(utf8) { m_utf8mode(utf8) {
if (name != 0) if (name != 0)
load(name); load(name);
} }
@ -47,13 +46,14 @@ bool XftFontImp::load(const std::string &name) {
//Note: assumes screen 0 for now, changes on draw if needed //Note: assumes screen 0 for now, changes on draw if needed
Display *disp = App::instance()->display(); Display *disp = App::instance()->display();
XftFont *newxftfont = XftFontOpenName(disp, 0, name.c_str());
if (newxftfont == 0) { // failed to open font, lets test with XLFD XftFont *newxftfont = XftFontOpenXlfd(disp, 0, name.c_str());
newxftfont = XftFontOpenXlfd(disp, 0, name.c_str()); if (newxftfont == 0) {
newxftfont = XftFontOpenName(disp, 0, name.c_str());
if (newxftfont == 0) if (newxftfont == 0)
return false; return false;
} }
// destroy old font and set new // destroy old font and set new
if (m_xftfont != 0) if (m_xftfont != 0)
XftFontClose(disp, m_xftfont); XftFontClose(disp, m_xftfont);

View file

@ -24,9 +24,8 @@
#ifndef FBTK_XFTFONTIMP_HH #ifndef FBTK_XFTFONTIMP_HH
#define FBTK_XFTFONTIMP_HH #define FBTK_XFTFONTIMP_HH
#include "FontImp.hh"
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#include "FontImp.hh"
namespace FbTk { namespace FbTk {

View file

@ -53,11 +53,6 @@ void IconbarTheme::reconfigTheme() {
m_unfocused_text.update(); m_unfocused_text.update();
} }
void IconbarTheme::setAntialias(bool value) {
m_focused_text.setAntialias(value);
m_unfocused_text.setAntialias(value);
}
// fallback resources // fallback resources
bool IconbarTheme::fallback(FbTk::ThemeItem_base &item) { bool IconbarTheme::fallback(FbTk::ThemeItem_base &item) {
using namespace FbTk; using namespace FbTk;

View file

@ -310,14 +310,6 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
imageControl().setDither(*resource.image_dither); imageControl().setDither(*resource.image_dither);
// setup windowtheme for antialias
// before we load the theme
winFrameTheme().font().setAntialias(*resource.antialias);
menuTheme().titleFont().setAntialias(*resource.antialias);
menuTheme().frameFont().setAntialias(*resource.antialias);
winFrameTheme().reconfigSig().attach(this);// for geom window winFrameTheme().reconfigSig().attach(this);// for geom window
@ -343,7 +335,8 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
// own resources we must do this. // own resources we must do this.
fluxbox->load_rc(*this); fluxbox->load_rc(*this);
m_configmenu.reset(createMenu(_FBTEXT(Menu, Configuration, "Configuration", "Title of configuration menu"))); m_configmenu.reset(createMenu(_FBTEXT(Menu, Configuration,
"Configuration", "Title of configuration menu")));
setupConfigmenu(*m_configmenu.get()); setupConfigmenu(*m_configmenu.get());
m_configmenu->setInternalMenu(); m_configmenu->setInternalMenu();
@ -673,11 +666,6 @@ void BScreen::reconfigure() {
m_menutheme->setDelayOpen(*resource.menu_delay); m_menutheme->setDelayOpen(*resource.menu_delay);
m_menutheme->setDelayClose(*resource.menu_delay_close); m_menutheme->setDelayClose(*resource.menu_delay_close);
// setup windowtheme, toolbartheme for antialias
winFrameTheme().font().setAntialias(*resource.antialias);
m_menutheme->titleFont().setAntialias(*resource.antialias);
m_menutheme->frameFont().setAntialias(*resource.antialias);
renderGeomWindow(); renderGeomWindow();
renderPosWindow(); renderPosWindow();
@ -849,13 +837,6 @@ void BScreen::removeClient(WinClient &client) {
} }
void BScreen::setAntialias(bool value) {
if (*resource.antialias == value)
return;
resource.antialias = value;
reconfigure();
}
int BScreen::addWorkspace() { int BScreen::addWorkspace() {
bool save_name = getNameOfWorkspace(m_workspaces_list.size()) != "" ? false : true; bool save_name = getNameOfWorkspace(m_workspaces_list.size()) != "" ? false : true;
@ -1812,12 +1793,6 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
_BOOLITEM(Configmenu, ClickRaises, _BOOLITEM(Configmenu, ClickRaises,
"Click Raises", "Click Raises", "Click Raises", "Click Raises",
*resource.click_raises, saverc_cmd); *resource.click_raises, saverc_cmd);
#ifdef USE_XFT
// setup antialias cmd to reload style and save resource on toggle
_BOOLITEM(Configmenu, AntiAlias,
"AntiAlias", "Use Anti-aliased fonts",
*resource.antialias, save_and_reconfigure);
#endif // USE_XFT
#ifdef HAVE_XRENDER #ifdef HAVE_XRENDER
if (FbTk::Transparent::haveRender() || if (FbTk::Transparent::haveRender() ||

View file

@ -218,8 +218,6 @@ public:
void saveMenu(FbTk::Menu &menu) { m_rootmenu_list.push_back(&menu); } void saveMenu(FbTk::Menu &menu) { m_rootmenu_list.push_back(&menu); }
void setAntialias(bool value);
inline FbWinFrameTheme &winFrameTheme() { return *m_windowtheme.get(); } inline FbWinFrameTheme &winFrameTheme() { return *m_windowtheme.get(); }
inline const FbWinFrameTheme &winFrameTheme() const { return *m_windowtheme.get(); } inline const FbWinFrameTheme &winFrameTheme() const { return *m_windowtheme.get(); }
inline MenuTheme &menuTheme() { return *m_menutheme.get(); } inline MenuTheme &menuTheme() { return *m_menutheme.get(); }

View file

@ -34,6 +34,9 @@ TextTheme::TextTheme(FbTk::Theme &theme,
m_text_color(theme, name + ".textColor", altname + ".TextColor"), m_text_color(theme, name + ".textColor", altname + ".TextColor"),
m_justify(theme, name + ".justify", altname + ".Justify"), m_justify(theme, name + ".justify", altname + ".Justify"),
m_text_gc(RootWindow(FbTk::App::instance()->display(), theme.screenNum())) { m_text_gc(RootWindow(FbTk::App::instance()->display(), theme.screenNum())) {
*m_justify = FbTk::LEFT;
// set default values
m_text_color->setFromString("white", theme.screenNum());
update(); update();
} }
@ -45,9 +48,3 @@ TextTheme::~TextTheme() {
void TextTheme::update() { void TextTheme::update() {
m_text_gc.setForeground(*m_text_color); m_text_gc.setForeground(*m_text_color);
} }
void TextTheme::setAntialias(bool value) {
font().setAntialias(value);
FbTk::ThemeManager::instance().loadItem(m_font);
}

View file

@ -38,8 +38,6 @@ public:
void update(); void update();
void setAntialias(bool value);
FbTk::Font &font() { return *m_font; } FbTk::Font &font() { return *m_font; }
const FbTk::Font &font() const { return *m_font; } const FbTk::Font &font() const { return *m_font; }
const FbTk::Color &textColor() const { return *m_text_color; } const FbTk::Color &textColor() const { return *m_text_color; }

View file

@ -152,13 +152,9 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
} }
void ToolFactory::updateThemes() { void ToolFactory::updateThemes() {
m_clock_theme.setAntialias(screen().antialias());
m_clock_theme.reconfigTheme(); m_clock_theme.reconfigTheme();
m_iconbar_theme.setAntialias(screen().antialias());
m_iconbar_theme.reconfigTheme(); m_iconbar_theme.reconfigTheme();
m_button_theme->setAntialias(screen().antialias());
m_button_theme->reconfigTheme(); m_button_theme->reconfigTheme();
m_workspace_theme->setAntialias(screen().antialias());
m_workspace_theme->reconfigTheme(); m_workspace_theme->reconfigTheme();
} }

View file

@ -73,8 +73,8 @@ public:
m_menu_theme(DefaultScreen(display())), m_menu_theme(DefaultScreen(display())),
m_menu(m_menu_theme, m_image_ctrl) { m_menu(m_menu_theme, m_image_ctrl) {
m_menu_theme.frameFont().setAntialias(true); //m_menu_theme.frameFont().setAntialias(true);
m_menu_theme.titleFont().setAntialias(true); //m_menu_theme.titleFont().setAntialias(true);
cerr<<"Loading menu: "<<menufile<<endl; cerr<<"Loading menu: "<<menufile<<endl;
FbMenuParser parser(menufile); FbMenuParser parser(menufile);

View file

@ -1,4 +1,3 @@
// testFont.cc for fbtk test suite
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org) // Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
@ -56,12 +55,13 @@ public:
XLookupString(&ke, keychar, 1, &ks, 0); XLookupString(&ke, keychar, 1, &ks, 0);
if (ks == XK_Escape) if (ks == XK_Escape)
end(); end();
/*
else { // toggle antialias else { // toggle antialias
m_font.setAntialias(!m_font.isAntialias()); m_font.setAntialias(!m_font.isAntialias());
cerr<<boolalpha; cerr<<boolalpha;
cerr<<"antialias: "<<m_font.isAntialias()<<endl; cerr<<"antialias: "<<m_font.isAntialias()<<endl;
redraw(); redraw();
} } */
} }
void exposeEvent(XExposeEvent &event) { void exposeEvent(XExposeEvent &event) {
@ -86,7 +86,7 @@ public:
m_win.drawLine(wingc.gc(), m_win.drawLine(wingc.gc(),
x, y, x + text_w, y); x, y, x + text_w, y);
wingc.setForeground(FbTk::Color(m_foreground.c_str(), m_win.screenNumber())); wingc.setForeground(FbTk::Color(m_foreground.c_str(), m_win.screenNumber()));
cerr<<"text width: "<<m_font.textWidth(m_text.c_str(), m_text.size())<<endl; //cerr<<"text width: "<<m_font.textWidth(m_text.c_str(), m_text.size())<<endl;
m_font.drawText(m_win, m_font.drawText(m_win,
0, wingc.gc(), 0, wingc.gc(),
m_text.c_str(), m_text.size(), m_text.c_str(), m_text.size(),
@ -105,9 +105,10 @@ private:
}; };
int main(int argc, char **argv) { int main(int argc, char **argv) {
bool antialias = false; //bool antialias = false;
bool rotate = false; bool rotate = false;
string fontname("fixed"); bool xft = false;
string fontname("");
string displayname(""); string displayname("");
string background("black"); string background("black");
string foreground("white"); string foreground("white");
@ -115,8 +116,8 @@ int main(int argc, char **argv) {
for (int a=1; a<argc; ++a) { for (int a=1; a<argc; ++a) {
if (strcmp("-font", argv[a])==0 && a + 1 < argc) { if (strcmp("-font", argv[a])==0 && a + 1 < argc) {
fontname = argv[++a]; fontname = argv[++a];
} else if (strcmp("-antialias", argv[a]) == 0) { } else if (strcmp("-xft", argv[a])==0) {
antialias = true; xft = true;
} else if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) { } else if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
displayname = argv[++a]; displayname = argv[++a];
} else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) { } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) {
@ -130,7 +131,7 @@ int main(int argc, char **argv) {
} else if (strcmp("-h", argv[a]) == 0) { } else if (strcmp("-h", argv[a]) == 0) {
cerr<<"Arguments: "<<endl; cerr<<"Arguments: "<<endl;
cerr<<"-font <fontname>"<<endl; cerr<<"-font <fontname>"<<endl;
cerr<<"-antialias"<<endl; // cerr<<"-antialias"<<endl;
cerr<<"-display <display>"<<endl; cerr<<"-display <display>"<<endl;
cerr<<"-text <text>"<<endl; cerr<<"-text <text>"<<endl;
cerr<<"-rotate"<<endl; cerr<<"-rotate"<<endl;
@ -144,7 +145,7 @@ int main(int argc, char **argv) {
App app(displayname.c_str(), foreground, background); App app(displayname.c_str(), foreground, background);
app.font().setAntialias(antialias); //app.font().setAntialias(antialias);
if (!app.font().load(fontname.c_str())) if (!app.font().load(fontname.c_str()))
cerr<<"Failed to load: "<<fontname<<endl; cerr<<"Failed to load: "<<fontname<<endl;
cerr<<"Setting text: "<<text<<endl; cerr<<"Setting text: "<<text<<endl;

View file

@ -48,7 +48,7 @@ public:
/// load and reconfigure for new font /// load and reconfigure for new font
bool loadFont(const std::string &fontname); bool loadFont(const std::string &fontname);
void setForegroundColor(const FbTk::Color &color); void setForegroundColor(const FbTk::Color &color);
void setAntialias(bool val) { m_font.setAntialias(val); } void setAntialias(bool val) { /*m_font.setAntialias(val);*/ }
const FbTk::Font &font() const { return m_font; } const FbTk::Font &font() const { return m_font; }
/// execute command and exit /// execute command and exit
void run(const std::string &execstring); void run(const std::string &execstring);

View file

@ -119,7 +119,7 @@ int main(int argc, char **argv) {
FbTk::App application(display_name.c_str()); FbTk::App application(display_name.c_str());
FbRun fbrun; FbRun fbrun;
fbrun.setAntialias(antialias); //fbrun.setAntialias(antialias);
if (fontname.size() != 0) { if (fontname.size() != 0) {
if (!fbrun.loadFont(fontname.c_str())) { if (!fbrun.loadFont(fontname.c_str())) {
@ -140,8 +140,8 @@ int main(int argc, char **argv) {
fbrun.resize(fbrun.width(), height); fbrun.resize(fbrun.width(), height);
if (set_width) if (set_width)
fbrun.resize(width, fbrun.height()); fbrun.resize(width, fbrun.height());
if (antialias) //if (antialias)
fbrun.setAntialias(antialias); // fbrun.setAntialias(antialias);
// expand and load command history // expand and load command history
string expanded_filename = FbTk::StringUtil::expandFilename(history_file); string expanded_filename = FbTk::StringUtil::expandFilename(history_file);
if (!fbrun.loadHistory(expanded_filename.c_str())) if (!fbrun.loadHistory(expanded_filename.c_str()))