From b5acf3a78f51e9fb1503f82e2235d98694328a67 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 26 Nov 2002 15:57:11 +0000 Subject: moved to FbTk --- src/Color.cc | 166 ---------------------- src/Color.hh | 73 ---------- src/EventHandler.hh | 43 ------ src/Font.cc | 186 ------------------------- src/Font.hh | 84 ------------ src/FontImp.hh | 57 -------- src/NotCopyable.hh | 39 ------ src/SignalHandler.cc | 81 ----------- src/SignalHandler.hh | 71 ---------- src/Texture.cc | 96 ------------- src/Texture.hh | 97 ------------- src/XFontImp.cc | 380 --------------------------------------------------- src/XFontImp.hh | 78 ----------- src/XftFontImp.cc | 140 ------------------- src/XftFontImp.hh | 46 ------- src/XmbFontImp.cc | 239 -------------------------------- src/XmbFontImp.hh | 46 ------- 17 files changed, 1922 deletions(-) delete mode 100644 src/Color.cc delete mode 100644 src/Color.hh delete mode 100644 src/EventHandler.hh delete mode 100644 src/Font.cc delete mode 100644 src/Font.hh delete mode 100644 src/FontImp.hh delete mode 100644 src/NotCopyable.hh delete mode 100644 src/SignalHandler.cc delete mode 100644 src/SignalHandler.hh delete mode 100644 src/Texture.cc delete mode 100644 src/Texture.hh delete mode 100644 src/XFontImp.cc delete mode 100644 src/XFontImp.hh delete mode 100644 src/XftFontImp.cc delete mode 100644 src/XftFontImp.hh delete mode 100644 src/XmbFontImp.cc delete mode 100644 src/XmbFontImp.hh diff --git a/src/Color.cc b/src/Color.cc deleted file mode 100644 index e848def..0000000 --- a/src/Color.cc +++ /dev/null @@ -1,166 +0,0 @@ -// Color.cc for Fluxbox window manager -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@users.sourceforge.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: Color.cc,v 1.3 2002/09/20 13:02:39 fluxgen Exp $ - -#include "Color.hh" - -#include "BaseDisplay.hh" - -#include -using namespace std; - -namespace { -unsigned char maxValue(unsigned short colval) { - if (colval == 65535) - return 0xFF; - - return static_cast(colval/0xFF); -} - -}; - -namespace FbTk { -Color::Color(): -m_allocated(false), -m_screen(0) { - -} - -Color::Color(const Color &col_copy) { - copy(col_copy); -} - -Color::Color(unsigned char red, unsigned char green, unsigned char blue, int screen): -m_red(red), m_green(green), m_blue(blue), -m_pixel(0), m_allocated(false), -m_screen(screen) { - allocate(red, green, blue, screen); -} - -Color::Color(const char *color_string, int screen): -m_allocated(false), -m_screen(screen) { - setFromString(color_string, screen); -} - -Color::~Color() { - free(); -} - -bool Color::setFromString(const char *color_string, int screen) { - - if (color_string == 0) { - free(); - return false; - } - - Display *disp = BaseDisplay::instance()->getXDisplay(); - Colormap colm = DefaultColormap(disp, screen); - - XColor color; - - if (! XParseColor(disp, colm, color_string, &color)) - cerr<<"FbTk::Color: Parse color error: \""< -class EventHandler { -public: - virtual ~EventHandler() { } - - virtual Event_ret_T handleEvent(Event_T * const) = 0; -}; - -}; - -#endif // FBTK_EVENTHANDLER_HH diff --git a/src/Font.cc b/src/Font.cc deleted file mode 100644 index 8f683d9..0000000 --- a/src/Font.cc +++ /dev/null @@ -1,186 +0,0 @@ -// Font.cc -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//$Id: Font.cc,v 1.22 2002/11/25 14:07:21 fluxgen Exp $ - - -#include "Font.hh" -#include "FontImp.hh" - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif // HAVE_CONFIG_H - -// for antialias -#ifdef USE_XFT -#include "XftFontImp.hh" -#endif // USE_XFT - -// for multibyte support -#ifdef USE_XMB -#include "XmbFontImp.hh" -#endif //USE_XMB - -// standard font system -#include "XFontImp.hh" - -#include "StringUtil.hh" - -//use gnu extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif //_GNU_SOURCE - -#ifndef __USE_GNU -#define __USE_GNU -#endif //__USE_GNU - -#include -#include -#include -using namespace std; - -#ifdef HAVE_SETLOCALE -#include -#endif //HAVE_SETLOCALE - -namespace FbTk { - -bool Font::m_multibyte = false; -bool Font::m_utf8mode = false; - -Font::Font(const char *name, bool antialias): -m_fontimp(0), -m_antialias(false), m_rotated(false) { - - // 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 - m_multibyte = true; - - char *s; // temporary string for enviroment variable - // check for utf-8 mode - if (((s = getenv("LC_ALL")) && *s) || - ((s = getenv("LC_CTYPE")) && *s) || - ((s = getenv("LANG")) && *s)) { - if (strstr(s, "UTF-8")) - m_utf8mode = true; - } - - // create the right font implementation - // antialias is prio 1 -#ifdef USE_XFT - if (antialias) { - m_fontimp.reset(new XftFontImp(0, m_utf8mode)); - m_antialias = true; - } -#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) { - load(name); - } - -} - -Font::~Font() { - -} - -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 - cerr<<"Warning: can't load fallback font 'fixed'."<load(name); -} - -unsigned int Font::textWidth(const char * const text, unsigned int size) const { - return m_fontimp->textWidth(text, size); -} - -unsigned int Font::height() const { - return m_fontimp->height(); -} - -int Font::ascent() const { - return m_fontimp->ascent(); -} - -int Font::descent() const { - return m_fontimp->descent(); -} -void Font::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const { - if (text == 0 || len == 0) - return; - m_fontimp->drawText(w, screen, gc, text, len, x, y); -} - -void Font::rotate(float angle) { -#ifdef USE_XFT - // if we are rotated and we are changing to horiz text - // and we were antialiased before we rotated then change to XftFontImp - if (isRotated() && angle == 0 && isAntialias()) - m_fontimp.reset(new XftFontImp(m_fontstr.c_str(), m_utf8mode)); -#endif // USE_XFT - // 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 (angle != 0 && isAntialias() && !isRotated()) { - m_fontimp.reset(new XFontImp(m_fontstr.c_str())); - } - - //Note: only XFontImp implements FontImp::rotate - m_fontimp->rotate(angle); - - m_rotated = (angle == 0 ? false : true); -} - -}; diff --git a/src/Font.hh b/src/Font.hh deleted file mode 100644 index a1fb62d..0000000 --- a/src/Font.hh +++ /dev/null @@ -1,84 +0,0 @@ -// Font.cc -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//$Id: Font.hh,v 1.9 2002/11/25 14:07:21 fluxgen Exp $ - -#ifndef FBTK_FONT_HH -#define FBTK_FONT_HH - -#include -#include - -#include -#include - -namespace FbTk { - -class FontImp; - -/** - Handles the client to fontimp bridge. -*/ -class Font { -public: - Font(const char *name=0, bool antialias = false); - virtual ~Font(); - /** - Load a font - @return true on success, else false and it'll fall back on the last - loaded font - */ - bool load(const char *name); - - /// @return true if multibyte is enabled, else false - static bool multibyte() { return m_multibyte; } - /// @return true if utf-8 mode is enabled, else false - static bool utf8() { return m_utf8mode; } - void setAntialias(bool flag); - /** - @param text text to check size - @param size length of text in bytes - @return size of text in pixels - */ - unsigned int textWidth(const char * const text, unsigned int size) const; - unsigned int height() const; - int ascent() const; - int descent() const; - /** - Rotate font in any angle (currently only 90 degrees supported and just XFont implementation) - */ - void rotate(float angle); - void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const; - bool isAntialias() const { return m_antialias; } - bool isRotated() const { return m_rotated; } -private: - - std::auto_ptr m_fontimp; - std::string m_fontstr; - static bool m_multibyte; - static bool m_utf8mode; - bool m_antialias; - bool m_rotated; ///< wheter we're rotated or not -}; - -}; //end namespace FbTk - -#endif //FBTK_FONT_HH diff --git a/src/FontImp.hh b/src/FontImp.hh deleted file mode 100644 index 95f980a..0000000 --- a/src/FontImp.hh +++ /dev/null @@ -1,57 +0,0 @@ -// FontImp.cc for FbTk -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: FontImp.hh,v 1.4 2002/11/25 14:07:20 fluxgen Exp $ - -#ifndef FBTK_FONTIMP_HH -#define FBTK_FONTIMP_HH - -#include "Color.hh" - -#include - -#include - -namespace FbTk { - -/** - FontImp, second part of the bridge pattern for fonts - pure interface class. - @see Font -*/ -class FontImp { -public: - virtual ~FontImp() { } - virtual bool load(const std::string &name) = 0; - virtual void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const = 0; - virtual unsigned int textWidth(const char * const text, unsigned int size) const = 0; - virtual int ascent() const = 0; - virtual int descent() const = 0; - virtual unsigned int height() const = 0; - virtual bool loaded() const = 0; - virtual void rotate(float angle) { } // by default, no rotate support -protected: - FontImp() { } -}; - -}; // end namespace FbTk - -#endif // FBTK_FONTIMP_HH diff --git a/src/NotCopyable.hh b/src/NotCopyable.hh deleted file mode 100644 index 025d5dc..0000000 --- a/src/NotCopyable.hh +++ /dev/null @@ -1,39 +0,0 @@ -// NotCopyable.hh -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#ifndef NOTCOPYABLE_HH -#define NOTCOPYABLE_HH - -/** Makes the inherited class not copyable. - inherit this class to - disable assignment and copy -*/ -class NotCopyable -{ -protected: - NotCopyable() {} -private: - - NotCopyable(const NotCopyable &rhs); // copy constructor - NotCopyable &operator=(const NotCopyable &rhs); // assignment operator -}; - -#endif //NOTCOPYBLE_HH diff --git a/src/SignalHandler.cc b/src/SignalHandler.cc deleted file mode 100644 index c160243..0000000 --- a/src/SignalHandler.cc +++ /dev/null @@ -1,81 +0,0 @@ -// SignalHandler.cc for Fluxbox Window Manager -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: SignalHandler.cc,v 1.3 2002/10/12 13:28:03 fluxgen Exp $ - -#include "SignalHandler.hh" - -namespace FbTk { - -EventHandler *SignalHandler::s_signal_handler[NSIG]; - -SignalHandler::SignalHandler() { - // clear signal list - for (int i=0; i < NSIG; ++i) - s_signal_handler[i] = 0; -} - -SignalHandler *SignalHandler::instance() { - static SignalHandler singleton; - return &singleton; -} - -bool SignalHandler::registerHandler(int signum, EventHandler *eh, - EventHandler **oldhandler_ret) { - // must be less than NSIG - if (signum >= NSIG) - return false; - - // get old signal handler for this signum - if (oldhandler_ret != 0) - *oldhandler_ret = s_signal_handler[signum]; - - struct sigaction sa; - // set callback - sa.sa_handler = SignalHandler::handleSignal; - sigemptyset (&sa.sa_mask); - sa.sa_flags = 0; - - if (sigaction(signum, &sa, 0) == -1) - return false; - - s_signal_handler[signum] = eh; - - return true; -} - -void SignalHandler::removeHandler(int signum) { - if (signum < NSIG) - s_signal_handler[signum] = 0; // clear handler pointer -} - -void SignalHandler::handleSignal(int signum) { - if (signum >= NSIG) - return; - // make sure we got a handler for this signal - if (s_signal_handler[signum] != 0) { - SignalEvent sigev; - sigev.signum = signum; - s_signal_handler[signum]->handleEvent(&sigev); - } -} - -}; diff --git a/src/SignalHandler.hh b/src/SignalHandler.hh deleted file mode 100644 index 93d5ae4..0000000 --- a/src/SignalHandler.hh +++ /dev/null @@ -1,71 +0,0 @@ -// SignalHandler.hh for Fluxbox Window Manager -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: SignalHandler.hh,v 1.3 2002/08/17 22:15:04 fluxgen Exp $ - -#ifndef FBTK_SIGNALHANDLER_HH -#define FBTK_SIGNALHANDLER_HH - -#include "EventHandler.hh" - -#include - -namespace FbTk { - -struct SignalEvent { - int signum; -}; - -/** - Handles system signals, singleton. - Usage: inherit the class EventHandler and then register - it to SignalHandler by calling registerHandler with - a signal number -*/ -class SignalHandler { -public: - - /// get singleton object - static SignalHandler *instance(); - /** - Register an event handler - @return true on success else false - @param signum signal number - @param eh event handler - @param oldhandler_ret return handler to old sighandler - */ - bool registerHandler(int signum, EventHandler *eh, EventHandler **oldhandler_ret = 0); - /** - removes the signum handler - @param signum signal number - */ - void removeHandler(int signum); -private: - SignalHandler(); - - static void handleSignal(int signum); - - static EventHandler *s_signal_handler[NSIG]; ///< NSIG defined in signal.h -}; - -}; // end namespace FbTk - -#endif // FBTK_SIGNALHANDLER_HH diff --git a/src/Texture.cc b/src/Texture.cc deleted file mode 100644 index d88c926..0000000 --- a/src/Texture.cc +++ /dev/null @@ -1,96 +0,0 @@ -// Texture.hh for Fluxbox Window Manager -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@users.sourceforge.net) -// -// from Image.cc for Blackbox - an X11 Window manager -// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: Texture.cc,v 1.1 2002/09/14 23:22:32 fluxgen Exp $ - -#include "Texture.hh" - -#include "StringUtil.hh" - -namespace FbTk { - -void Texture::setFromString(const char * const texture_str) { - if (texture_str == 0) - return; - int t_len = strlen(texture_str) + 1; - char *ts = new char[t_len]; - strcpy(ts, texture_str); - - StringUtil::toLower(ts); - - if (strstr(ts, "parentrelative")) { - setType(Texture::PARENTRELATIVE); - } else { - setType(Texture::NONE); - - if (strstr(ts, "solid")) - addType(Texture::SOLID); - else if (strstr(ts, "gradient")) { - addType(Texture::GRADIENT); - if (strstr(ts, "crossdiagonal")) - addType(Texture::CROSSDIAGONAL); - else if (strstr(ts, "rectangle")) - addType(Texture::RECTANGLE); - else if (strstr(ts, "pyramid")) - addType(Texture::PYRAMID); - else if (strstr(ts, "pipecross")) - addType(Texture::PIPECROSS); - else if (strstr(ts, "elliptic")) - addType(Texture::ELLIPTIC); - else if (strstr(ts, "diagonal")) - addType(Texture::DIAGONAL); - else if (strstr(ts, "horizontal")) - addType(Texture::HORIZONTAL); - else if (strstr(ts, "vertical")) - addType(Texture::VERTICAL); - else - addType(Texture::DIAGONAL); - } else - addType(Texture::SOLID); - - if (strstr(ts, "raised")) - addType(Texture::RAISED); - else if (strstr(ts, "sunken")) - addType(Texture::SUNKEN); - else if (strstr(ts, "flat")) - addType(Texture::FLAT); - else - addType(Texture::RAISED); - - if (! (type() & Texture::FLAT)) - if (strstr(ts, "bevel2")) - addType(Texture::BEVEL2); - else - addType(Texture::BEVEL1); - -#ifdef INTERLACE - if (strstr(ts, "interlaced")) - addType(Texture::INTERLACED); -#endif // INTERLACE - } - - delete [] ts; -} - -}; // end namespace FbTk diff --git a/src/Texture.hh b/src/Texture.hh deleted file mode 100644 index 78356d0..0000000 --- a/src/Texture.hh +++ /dev/null @@ -1,97 +0,0 @@ -// Texture.hh for Fluxbox Window Manager -// Copyright (c) 2002 Henrik Kinnunen (fluxbox@linuxmail.org) -// -// from Image.hh for Blackbox - an X11 Window manager -// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: Texture.hh,v 1.2 2002/09/14 23:23:23 fluxgen Exp $ - -#ifndef FBTK_TEXTURE_HH -#define FBTK_TEXTURE_HH - -#include "Color.hh" - -namespace FbTk { - -/** - Holds texture type and info -*/ -class Texture { -public: - - enum Bevel { - FLAT = 0x00002, - SUNKEN = 0x00004, - RAISED = 0x00008 - }; - - enum Textures { - NONE = 0x00000, - SOLID = 0x00010, - GRADIENT = 0x00020 - }; - - enum Gradients { - HORIZONTAL = 0x00040, - VERTICAL = 0x00080, - DIAGONAL = 0x00100, - CROSSDIAGONAL = 0x00200, - RECTANGLE = 0x00400, - PYRAMID = 0x00800, - PIPECROSS = 0x01000, - ELLIPTIC = 0x02000 - }; - - enum { - BEVEL1 = 0x04000, - BEVEL2 = 0x08000, // bevel types - INVERT = 0x010000, //inverted image - PARENTRELATIVE = 0x20000, - INTERLACED = 0x40000 - }; - - Texture():m_type(0) { } - - void setType(unsigned long t) { m_type = t; } - void addType(unsigned long t) { m_type |= t; } - void setFromString(const char * const str); - - Color &color() { return m_color; } - Color &colorTo() { return m_color_to; } - Color &hiColor() { return m_hicolor; } - Color &loColor() { return m_locolor; } - - const Color &color() const { return m_color; } - const Color &colorTo() const { return m_color_to; } - const Color &hiColor() const { return m_hicolor; } - const Color &loColor() const { return m_locolor; } - - inline unsigned long type() const { return m_type; } - - -private: - FbTk::Color m_color, m_color_to, m_hicolor, m_locolor; - unsigned long m_type; -}; - -}; // end namespace FbTk - -#endif // FBTK_TEXTURE_HH diff --git a/src/XFontImp.cc b/src/XFontImp.cc deleted file mode 100644 index a263466..0000000 --- a/src/XFontImp.cc +++ /dev/null @@ -1,380 +0,0 @@ -// XFontImp.cc for FbTk fluxbox toolkit -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: XFontImp.cc,v 1.2 2002/11/25 14:07:21 fluxgen Exp $ - -#include "XFontImp.hh" -#include "BaseDisplay.hh" - -#include - -#include -using namespace std; - -XFontImp::XFontImp(const char *fontname):m_rotfont(0), m_fontstruct(0), -m_angle(0) { - if (fontname != 0) - load(fontname); -} - -XFontImp::~XFontImp() { - if (m_fontstruct != 0) - XFreeFont(BaseDisplay::getXDisplay(), m_fontstruct); - if (m_rotfont != 0) - freeRotFont(); -} - -int XFontImp::ascent() const { - if (m_fontstruct == 0) - return 0; - if (m_rotfont != 0) - return m_rotfont->max_ascent; - - return m_fontstruct->ascent; -} - -bool XFontImp::load(const std::string &fontname) { - XFontStruct *font = XLoadQueryFont(BaseDisplay::getXDisplay(), fontname.c_str()); - if (font == 0) - return false; - if (m_fontstruct != 0) // free old font struct, if any - XFreeFont(BaseDisplay::getXDisplay(), m_fontstruct); - - m_fontstruct = font; //set new font - return true; -} - -void XFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const { - if (m_fontstruct == 0) - return; - // use roated font functions? - if (m_rotfont != 0) { - drawRotText(w, screen, gc, text, len, x, y); - return; - } - - Display *disp = BaseDisplay::getXDisplay(); - XSetFont(disp, gc, m_fontstruct->fid); - XDrawString(disp, w, gc, x, y, text, len); -} - -unsigned int XFontImp::textWidth(const char * const text, unsigned int size) const { - if (text == 0) - return 0; - if (m_fontstruct == 0) - return 0; - // check rotated font? - if (m_rotfont != 0) - return rotTextWidth(text, size); - - return XTextWidth(m_fontstruct, text, size); -} - -unsigned int XFontImp::height() const { - if (m_fontstruct == 0) - return 0; - - return m_fontstruct->ascent + m_fontstruct->descent; -} - -void XFontImp::rotate(float angle) { - //we must have a font loaded before we rotate - if (m_fontstruct == 0) - return; - if (m_rotfont != 0) - freeRotFont(); - // no need for rotating, use regular font - if (angle == 0) - return; - - //get positive angle - while (angle < 0) - angle += 360; - - char val; - XImage *I1, *I2; - // X system default vars - Display *dpy = BaseDisplay::instance()->getXDisplay(); - Window rootwin = DefaultRootWindow(dpy); - int screen = DefaultScreen(dpy); - - GC font_gc; - char text[3]; - int ichar, i, j, index, boxlen = 60; - int vert_w, vert_h, vert_len, bit_w, bit_h, bit_len; - int min_char, max_char; - unsigned char *vertdata, *bitdata; - int ascent, descent, lbearing, rbearing; - - // get nearest vertical or horizontal direction - int dir = (int)((angle+45.0)/90.0)%4; - - if (dir == 0) // no rotation - return; - - // create the depth 1 canvas bitmap - Pixmap canvas = XCreatePixmap(dpy, rootwin, boxlen, boxlen, 1); - - // create graphic context for our canvas - font_gc = XCreateGC(dpy, canvas, 0, 0); - - XSetBackground(dpy, font_gc, None); - - XSetFont(dpy, font_gc, m_fontstruct->fid); - - // allocate space for rotated font - m_rotfont = new(nothrow) XRotFontStruct; - - if (m_rotfont == 0) { - cerr<<"RotFont: out of memory"<min_char_or_byte2; - max_char = m_fontstruct->max_char_or_byte2; - - // we only want printable chars - if (min_char<32) - min_char = 32; - if (max_char>126) - max_char = 126; - - /* some overall font data ... */ - m_rotfont->dir = dir; - m_rotfont->min_char = min_char; - m_rotfont->max_char = max_char; - m_rotfont->max_ascent = m_fontstruct->max_bounds.ascent; - m_rotfont->max_descent = m_fontstruct->max_bounds.descent; - m_rotfont->height = m_rotfont->max_ascent + m_rotfont->max_descent; - - // font needs rotation - // loop through each character - for (ichar = min_char; ichar <= max_char; ichar++) { - index = ichar - m_fontstruct->min_char_or_byte2; - - // per char dimensions ... - ascent = m_rotfont->per_char[ichar-32].ascent = m_fontstruct->per_char[index].ascent; - descent = m_rotfont->per_char[ichar-32].descent = m_fontstruct->per_char[index].descent; - lbearing = m_rotfont->per_char[ichar-32].lbearing = m_fontstruct->per_char[index].lbearing; - rbearing = m_rotfont->per_char[ichar-32].rbearing = m_fontstruct->per_char[index].rbearing; - m_rotfont->per_char[ichar-32].width = m_fontstruct->per_char[index].width; - - // some space chars have zero body, but a bitmap can't have - if (!ascent && !descent) - ascent = m_rotfont->per_char[ichar-32].ascent = 1; - if (!lbearing && !rbearing) - rbearing = m_rotfont->per_char[ichar-32].rbearing = 1; - - // glyph width and height when vertical - vert_w = rbearing - lbearing; - vert_h = ascent + descent; - - // width in bytes - vert_len = (vert_w-1)/8+1; - - XSetForeground(dpy, font_gc, None); - XFillRectangle(dpy, canvas, font_gc, 0, 0, boxlen, boxlen); - - // draw the character centre top right on canvas - sprintf(text, "%c", ichar); - XSetForeground(dpy, font_gc, 1); - XDrawImageString(dpy, canvas, font_gc, boxlen/2 - lbearing, - boxlen/2 - descent, text, 1); - - // reserve memory for first XImage - vertdata = (unsigned char *) malloc((unsigned)(vert_len*vert_h)); - - /* create the XImage ... */ - I1 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, - 0, (char *)vertdata, vert_w, vert_h, 8, 0); - - if (I1 == None) { - cerr<<"RotFont: Cant create ximage."<byte_order = I1->bitmap_bit_order = MSBFirst; - - /* extract character from canvas ... */ - XGetSubImage(dpy, canvas, boxlen/2, boxlen/2 - vert_h, - vert_w, vert_h, 1, XYPixmap, I1, 0, 0); - I1->format = XYBitmap; - - /* width, height of rotated character ... */ - if (dir == 2) { - bit_w = vert_w; - bit_h = vert_h; - } else { - bit_w = vert_h; - bit_h = vert_w; - } - - /* width in bytes ... */ - bit_len = (bit_w-1)/8 + 1; - - m_rotfont->per_char[ichar-32].glyph.bit_w = bit_w; - m_rotfont->per_char[ichar-32].glyph.bit_h = bit_h; - - /* reserve memory for the rotated image ... */ - bitdata = (unsigned char *)calloc((unsigned)(bit_h * bit_len), 1); - - /* create the image ... */ - I2 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0, - (char *)bitdata, bit_w, bit_h, 8, 0); - - if (I2 == None) { - cerr<<"XFontImp: Cant create ximage!"<byte_order = I2->bitmap_bit_order = MSBFirst; - - /* map vertical data to rotated character ... */ - for (j = 0; j < bit_h; j++) { - for (i = 0; i < bit_w; i++) { - /* map bits ... */ - if (dir == 1) { - val = vertdata[i*vert_len + (vert_w-j-1)/8] & - (128>>((vert_w-j-1)%8)); - } else if (dir == 2) { - val = vertdata[(vert_h-j-1)*vert_len + - (vert_w-i-1)/8] & (128>>((vert_w-i-1)%8)); - } else { - val = vertdata[(vert_h-i-1)*vert_len + j/8] & - (128>>(j%8)); - } - if (val) { - bitdata[j*bit_len + i/8] = bitdata[j*bit_len + i/8] | - (128>>(i%8)); - } - } - } - - // create this character's bitmap - m_rotfont->per_char[ichar-32].glyph.bm = - XCreatePixmap(dpy, rootwin, bit_w, bit_h, 1); - - // put the image into the bitmap - XPutImage(dpy, m_rotfont->per_char[ichar-32].glyph.bm, - font_gc, I2, 0, 0, 0, 0, bit_w, bit_h); - - // free the image and data - XDestroyImage(I1); - XDestroyImage(I2); - } - - /* free pixmap and GC ... */ - XFreePixmap(dpy, canvas); - XFreeGC(dpy, font_gc); - -} - -void XFontImp::freeRotFont() { - if (m_rotfont == 0) - return; - // loop through each character and free its pixmap - for (int ichar = m_rotfont->min_char - 32; - ichar <= m_rotfont->max_char - 32; ++ichar) { - XFreePixmap(BaseDisplay::instance()->getXDisplay(), m_rotfont->per_char[ichar].glyph.bm); - } - - delete m_rotfont; - m_rotfont = 0; -} - -void XFontImp::drawRotText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const { - - Display *dpy = BaseDisplay::instance()->getXDisplay(); - static GC my_gc = 0; - int xp, yp, dir, ichar; - - if (text == NULL || len<1) - return; - - dir = m_rotfont->dir; - if (my_gc == 0) - my_gc = XCreateGC(dpy, w, 0, 0); - - XCopyGC(dpy, gc, GCForeground|GCBackground, my_gc); - - // vertical or upside down - - XSetFillStyle(dpy, my_gc, FillStippled); - - // loop through each character in texting - for (size_t i = 0; i= 0 && ichar<95) { - // suitable offset - if (dir == 1) { - xp = x-m_rotfont->per_char[ichar].ascent; - yp = y-m_rotfont->per_char[ichar].rbearing; - } else if (dir == 2) { - xp = x-m_rotfont->per_char[ichar].rbearing; - yp = y-m_rotfont->per_char[ichar].descent+1; - } else { - xp = x-m_rotfont->per_char[ichar].descent+1; - yp = y+m_rotfont->per_char[ichar].lbearing; - } - - // draw the glyph - XSetStipple(dpy, my_gc, m_rotfont->per_char[ichar].glyph.bm); - - XSetTSOrigin(dpy, my_gc, xp, yp); - - XFillRectangle(dpy, w, my_gc, xp, yp, - m_rotfont->per_char[ichar].glyph.bit_w, - m_rotfont->per_char[ichar].glyph.bit_h); - - // advance position - if (dir == 1) - y -= m_rotfont->per_char[ichar].width; - else if (dir == 2) - x -= m_rotfont->per_char[ichar].width; - else - y += m_rotfont->per_char[ichar].width; - } - } -} - - -unsigned int XFontImp::rotTextWidth(const char * const text, unsigned int size) const { - - if (text == 0) - return 0; - - unsigned int width = 0; - for (size_t i = 0; i= 0 && ichar < 95) - width += m_rotfont->per_char[ichar].width; - } - - return width; -} diff --git a/src/XFontImp.hh b/src/XFontImp.hh deleted file mode 100644 index b293fdd..0000000 --- a/src/XFontImp.hh +++ /dev/null @@ -1,78 +0,0 @@ -// XFontImp.hh for FbTk fluxbox toolkit -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: XFontImp.hh,v 1.4 2002/11/25 14:07:21 fluxgen Exp $ - -#ifndef XFONTIMP_HH -#define XFONTIMP_HH - -#include "FontImp.hh" - -class XFontImp:public FbTk::FontImp { -public: - explicit XFontImp(const char *filename = 0); - ~XFontImp(); - bool load(const std::string &filename); - unsigned int textWidth(const char * const text, unsigned int size) const; - unsigned int height() const; - float angle() const { return m_angle; } - int ascent() const; - int descent() const { return m_fontstruct ? m_fontstruct->descent : 0; } - void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const; - bool loaded() const { return m_fontstruct != 0; } - void rotate(float angle); -private: - void freeRotFont(); - void drawRotText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const; - unsigned int rotTextWidth(const char * const text, unsigned int size) const; - struct BitmapStruct { - int bit_w; - int bit_h; - - Pixmap bm; - }; - - struct XRotCharStruct { - int ascent; - int descent; - int lbearing; - int rbearing; - int width; - - BitmapStruct glyph; - }; - - struct XRotFontStruct { - int dir; - int height; - int max_ascent; - int max_descent; - int max_char; - int min_char; - - XRotCharStruct per_char[95]; - }; - XRotFontStruct *m_rotfont; - XFontStruct *m_fontstruct; - float m_angle; -}; - -#endif // XFONTIMP_HH diff --git a/src/XftFontImp.cc b/src/XftFontImp.cc deleted file mode 100644 index 5104ce0..0000000 --- a/src/XftFontImp.cc +++ /dev/null @@ -1,140 +0,0 @@ -// XftFontImp.cc Xft font implementation for FbTk -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//$Id: XftFontImp.cc,v 1.4 2002/11/17 17:20:49 fluxgen Exp $ - -#include "XftFontImp.hh" -#include "BaseDisplay.hh" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif //HAVE_CONFIG_H - -XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0), -m_utf8mode(utf8) { - if (name != 0) - load(name); -} - -XftFontImp::~XftFontImp() { - if (m_xftfont != 0) - XftFontClose(BaseDisplay::getXDisplay(), m_xftfont); -} - -bool XftFontImp::load(const std::string &name) { - //Note: assumes screen 0 for now, changes on draw if needed - - Display *disp = BaseDisplay::getXDisplay(); - XftFont *newxftfont = XftFontOpenName(disp, 0, name.c_str()); - - if (newxftfont == 0) { // failed to open font, lets test with XLFD - newxftfont = XftFontOpenXlfd(disp, 0, name.c_str()); - if (newxftfont == 0) - return false; - } - // destroy old font and set new - if (m_xftfont != 0) - XftFontClose(disp, m_xftfont); - - m_xftfont = newxftfont; - - return true; -} - -void XftFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const { - if (m_xftfont == 0) - return; - Display *disp = BaseDisplay::getXDisplay(); - XftDraw *draw = XftDrawCreate(disp, - w, - DefaultVisual(disp, screen), - DefaultColormap(disp, screen)); - - XGCValues gc_val; - - // get foreground pixel value and convert it to XRenderColor value - // TODO: we should probably check return status - XGetGCValues(disp, gc, GCForeground, &gc_val); - - // get red, green, blue values - XColor xcol; - xcol.pixel = gc_val.foreground; - XQueryColor(disp, DefaultColormap(disp, screen), &xcol); - - // convert xcolor to XftColor - XRenderColor rendcol; - rendcol.red = xcol.red; - rendcol.green = xcol.green; - rendcol.blue = xcol.blue; - rendcol.alpha = 0xFFFF; - XftColor xftcolor; - XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), - &rendcol, &xftcolor); - - // draw string -#ifdef HAVE_XFT_UTF8_STRING - if (m_utf8mode) { - XftDrawStringUtf8(draw, - &xftcolor, - m_xftfont, - x, y, - (XftChar8 *)(text), len); - } else -#endif // HAVE_XFT_UTF8_STRING - { - XftDrawString8(draw, - &xftcolor, - m_xftfont, - x, y, - (XftChar8 *)(text), len); - } - - XftColorFree(disp, DefaultVisual(disp, screen), - DefaultColormap(disp, screen), &xftcolor); - XftDrawDestroy(draw); -} - -unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const { - if (m_xftfont == 0) - return 0; - XGlyphInfo ginfo; -#ifdef HAVE_XFT_UTF8_STRING - if (m_utf8mode) { - XftTextExtentsUtf8(BaseDisplay::getXDisplay(), - m_xftfont, - (XftChar8 *)text, len, - &ginfo); - } else -#endif //HAVE_XFT_UTF8_STRING - { - XftTextExtents8(BaseDisplay::getXDisplay(), - m_xftfont, - (XftChar8 *)text, len, - &ginfo); - } - return ginfo.xOff; -} - -unsigned int XftFontImp::height() const { - if (m_xftfont == 0) - return 0; - return m_xftfont->height; -} diff --git a/src/XftFontImp.hh b/src/XftFontImp.hh deleted file mode 100644 index 78f4080..0000000 --- a/src/XftFontImp.hh +++ /dev/null @@ -1,46 +0,0 @@ -// XftFontImp.hh Xft font implementation for FbTk -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//$Id: XftFontImp.hh,v 1.4 2002/10/19 13:58:21 fluxgen Exp $ - -#ifndef XFTFONTIMP_HH -#define XFTFONTIMP_HH - -#include "FontImp.hh" -#include - -class XftFontImp:public FbTk::FontImp { -public: - XftFontImp(const char *fontname, bool utf8); - ~XftFontImp(); - bool load(const std::string &name); - void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const; - unsigned int textWidth(const char * const text, unsigned int len) const; - unsigned int height() const; - int ascent() const { return m_xftfont ? m_xftfont->ascent : 0; } - int descent() const { return m_xftfont ? m_xftfont->descent : 0; } - bool loaded() const { return m_xftfont != 0; } -private: - XftFont *m_xftfont; - bool m_utf8mode; -}; - -#endif // XFTFONTIMP_HH diff --git a/src/XmbFontImp.cc b/src/XmbFontImp.cc deleted file mode 100644 index 2a80900..0000000 --- a/src/XmbFontImp.cc +++ /dev/null @@ -1,239 +0,0 @@ -// XmbFontImp.cc for FbTk fluxbox toolkit -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: XmbFontImp.cc,v 1.3 2002/10/24 11:40:36 fluxgen Exp $ - -#include "XmbFontImp.hh" - -#include "BaseDisplay.hh" -#include "StringUtil.hh" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif //HAVE_CONFIG_H - -#ifdef HAVE_SETLOCALE -#include -#endif // HAVE_SETLOCALE - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif // _GNU_SOURCE - -#include -#include -#include -using namespace std; - -namespace { - -const char *getFontSize(const char *pattern, int *size) { - const char *p; - const char *p2=0; - int n=0; - - for (p=pattern; 1; p++) { - if (!*p) { - if (p2!=0 && n>1 && n<72) { - *size = n; return p2+1; - } else { - *size = 16; return 0; - } - } else if (*p=='-') { - if (n>1 && n<72 && p2!=0) { - *size = n; - return p2+1; - } - p2=p; n=0; - } else if (*p>='0' && *p<='9' && p2!=0) { - n *= 10; - n += *p-'0'; - } else { - p2=0; n=0; - } - } -} - -const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) { - const char *p, *v; - char *p2; - va_list va; - - va_start(va, bufsiz); - buf[bufsiz-1] = 0; - buf[bufsiz-2] = '*'; - while((v = va_arg(va, char *)) != 0) { - p = StringUtil::strcasestr(pattern, v); - if (p) { - std::strncpy(buf, p+1, bufsiz-2); - p2 = strchr(buf, '-'); - if (p2) *p2=0; - va_end(va); - return p; - } - } - va_end(va); - std::strncpy(buf, "*", bufsiz); - return 0; -} - -XFontSet createFontSet(const char *fontname) { - Display *display = BaseDisplay::getXDisplay(); - XFontSet fs; - const int FONT_ELEMENT_SIZE=50; - char **missing, *def = "-"; - int nmissing, pixel_size = 0, buf_size = 0; - char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE]; - - fs = XCreateFontSet(display, - fontname, &missing, &nmissing, &def); - if (fs && (! nmissing)) return fs; - -#ifdef HAVE_SETLOCALE - if (! fs) { - if (nmissing) XFreeStringList(missing); - - setlocale(LC_CTYPE, "C"); - fs = XCreateFontSet(display, fontname, - &missing, &nmissing, &def); - setlocale(LC_CTYPE, ""); - } -#endif // HAVE_SETLOCALE - - if (fs) { - XFontStruct **fontstructs; - char **fontnames; - XFontsOfFontSet(fs, &fontstructs, &fontnames); - fontname = fontnames[0]; - } - - getFontElement(fontname, weight, FONT_ELEMENT_SIZE, - "-medium-", "-bold-", "-demibold-", "-regular-", 0); - getFontElement(fontname, slant, FONT_ELEMENT_SIZE, - "-r-", "-i-", "-o-", "-ri-", "-ro-", 0); - getFontSize(fontname, &pixel_size); - - if (! strcmp(weight, "*")) - std::strncpy(weight, "medium", FONT_ELEMENT_SIZE); - if (! strcmp(slant, "*")) - std::strncpy(slant, "r", FONT_ELEMENT_SIZE); - if (pixel_size < 3) - pixel_size = 3; - else if (pixel_size > 97) - pixel_size = 97; - - buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64; - char *pattern2 = new char[buf_size]; - snprintf(pattern2, buf_size - 1, - "%s," - "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*," - "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*", - fontname, weight, slant, pixel_size, pixel_size); - fontname = pattern2; - - if (nmissing) - XFreeStringList(missing); - if (fs) - XFreeFontSet(display, fs); - - fs = XCreateFontSet(display, fontname, - &missing, &nmissing, &def); - delete [] pattern2; - - return fs; -} - -}; - -XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_utf8mode(utf8) { -#ifdef DEBUG -#ifdef X_HAVE_UTF8_STRING - cerr<<"Using utf8 = "<max_ink_extent.height; -} - diff --git a/src/XmbFontImp.hh b/src/XmbFontImp.hh deleted file mode 100644 index 4fb2a2e..0000000 --- a/src/XmbFontImp.hh +++ /dev/null @@ -1,46 +0,0 @@ -// XmbFontImp.hh for FbTk fluxbox toolkit -// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id: XmbFontImp.hh,v 1.4 2002/10/19 13:58:58 fluxgen Exp $ - -#ifndef XMBFONTIMP_HH -#define XMBFONTIMP_HH - -#include "FontImp.hh" - -class XmbFontImp:public FbTk::FontImp { -public: - XmbFontImp(const char *fontname, bool utf8); - ~XmbFontImp(); - bool load(const std::string &name); - virtual void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const; - unsigned int textWidth(const char * const text, unsigned int len) const; - unsigned int height() const; - int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } - int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; } - bool loaded() const { return m_fontset != 0; } -private: - XFontSet m_fontset; - XFontSetExtents *m_setextents; - const bool m_utf8mode; -}; - -#endif // XMBFONTIMP_HH -- cgit v0.11.2