all repos — fluxbox @ ad7fd2d8675141925bdef7c29d3392d6ac6b0db0

custom fork of the fluxbox windowmanager

fix loading of rotated fonts on style change
simonb simonb
commit

ad7fd2d8675141925bdef7c29d3392d6ac6b0db0

parent

3a79de034f87df155f540af2186c5d87dc187b3b

M ChangeLogChangeLog

@@ -1,6 +1,8 @@

(Format: Year/Month/Day) Changes for 1.0rc3: *07/01/05: + * Fix loading of rotated fonts on style change (Simon) + FbTk/... FontImp.hh XftFontImp.hh/cc XmbFontImp.hh/cc XFontImp.hh/cc * Change default Xft font to "monospace" (was "fixed") (Simon) - The "fixed" font loads a bitmap Xfont - Note that bitmap fonts do not rotate properly, and especially the
M src/FbTk/FontImp.hhsrc/FbTk/FontImp.hh

@@ -44,7 +44,7 @@ class FontImp {

public: virtual ~FontImp() { } virtual bool load(const std::string &name) = 0; - virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const = 0; + virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) = 0; virtual unsigned int textWidth(const FbString &text, unsigned int size) const = 0; virtual bool validOrientation(FbTk::Orientation orient) { return orient == ROT0; } virtual int ascent() const = 0;
M src/FbTk/XFontImp.ccsrc/FbTk/XFontImp.cc

@@ -45,8 +45,10 @@

namespace FbTk { XFontImp::XFontImp(const char *fontname):m_fontstruct(0) { - for (int i = ROT0; i <= ROT270; ++i) + for (int i = ROT0; i <= ROT270; ++i) { m_rotfonts[i] = 0; + m_rotfonts_loaded[i] = false; + } if (fontname != 0) load(fontname);

@@ -78,19 +80,23 @@ XFreeFont(App::instance()->display(), m_fontstruct);

m_fontstruct = font; //set new font - for (int i = ROT0; i <= ROT270; ++i) - if (m_rotfonts[i] != 0) + for (int i = ROT0; i <= ROT270; ++i) { + m_rotfonts_loaded[i] = false; + if (m_rotfonts[i] != 0) { freeRotFont(m_rotfonts[i]); + m_rotfonts[i] = 0; + } + } return true; } -void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { +void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) { if (m_fontstruct == 0) return; // use roated font functions? - if (orient != ROT0 && m_rotfonts[orient] != 0) { + if (orient != ROT0 && validOrientation(orient)) { drawRotText(w.drawable(), screen, gc, text, len, x, y, orient); return; }

@@ -389,7 +395,12 @@ bool XFontImp::validOrientation(FbTk::Orientation orient) {

if (orient == ROT0 || m_rotfonts[orient]) return true; + if (m_rotfonts_loaded[orient]) + return false; // load must have failed + + m_rotfonts_loaded[orient] = true; rotate(orient); + return m_rotfonts[orient] != 0; }
M src/FbTk/XFontImp.hhsrc/FbTk/XFontImp.hh

@@ -40,7 +40,7 @@ unsigned int textWidth(const FbString &text, unsigned int size) const;

unsigned int height() const; int ascent() const; int descent() const { return m_fontstruct ? m_fontstruct->descent : 0; } - void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; + void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient); bool validOrientation(FbTk::Orientation orient);

@@ -79,6 +79,7 @@ void freeRotFont(XRotFontStruct * rotfont);

void drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; XRotFontStruct *m_rotfonts[4]; ///< rotated font structure (only 3 used) + bool m_rotfonts_loaded[4]; // whether we've tried yet XFontStruct *m_fontstruct; ///< X font structure };
M src/FbTk/XftFontImp.ccsrc/FbTk/XftFontImp.cc

@@ -36,8 +36,10 @@

XftFontImp::XftFontImp(const char *name, bool utf8): m_utf8mode(utf8), m_name("") { - for (int r = ROT0; r <= ROT270; r++) + for (int r = ROT0; r <= ROT270; r++) { m_xftfonts[r] = 0; + m_xftfonts_loaded[r] = false; + } if (name != 0) load(name);

@@ -62,21 +64,24 @@ return false;

} // destroy all old fonts and set new - for (int r = ROT0; r <= ROT270; r++) + for (int r = ROT0; r <= ROT270; r++) { + m_xftfonts_loaded[r] = false; if (m_xftfonts[r] != 0) { XftFontClose(App::instance()->display(), m_xftfonts[r]); m_xftfonts[r] = 0; } + } m_xftfonts[ROT0] = newxftfont; + m_xftfonts_loaded[ROT0] = true; m_name = name; return true; } -void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { +void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) { - if (m_xftfonts[orient] == 0) + if (!validOrientation(orient)) return; // we adjust y slightly so that the baseline is in the right spot

@@ -212,8 +217,13 @@ bool XftFontImp::validOrientation(FbTk::Orientation orient) {

if (orient == ROT0 || m_xftfonts[orient]) return true; + if (m_xftfonts_loaded[orient]) + return false; // m_xftfonts is zero here + if (m_xftfonts[ROT0] == 0) return false; + + m_xftfonts_loaded[orient] = true; // otherwise, try to load that orientation // radians is actually anti-clockwise, so we reverse it
M src/FbTk/XftFontImp.hhsrc/FbTk/XftFontImp.hh

@@ -36,7 +36,7 @@ public:

XftFontImp(const char *fontname, bool utf8); ~XftFontImp(); bool load(const std::string &name); - void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient) const; + void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient); unsigned int textWidth(const FbString &text, unsigned int len) const; unsigned int height() const; int ascent() const { return m_xftfonts[0] ? m_xftfonts[0]->ascent : 0; }

@@ -47,6 +47,7 @@ bool validOrientation(FbTk::Orientation orient);

private: XftFont *m_xftfonts[4]; // 4 possible orientations + bool m_xftfonts_loaded[4]; // whether we've tried loading the orientation // rotated xft fonts don't give proper extents info, so we keep the "real" // one around for it bool m_utf8mode;
M src/FbTk/XmbFontImp.ccsrc/FbTk/XmbFontImp.cc

@@ -190,7 +190,7 @@ return true;

} void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const FbString &text, - size_t len, int x, int y, FbTk::Orientation orient) const { + size_t len, int x, int y, FbTk::Orientation orient) { if (m_fontset == 0) return;
M src/FbTk/XmbFontImp.hhsrc/FbTk/XmbFontImp.hh

@@ -36,7 +36,7 @@ public:

XmbFontImp(const char *fontname, bool utf8); ~XmbFontImp(); bool load(const std::string &name); - virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; + virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient); unsigned int textWidth(const FbString &text, unsigned int len) const; unsigned int height() const; int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; }