From ad7fd2d8675141925bdef7c29d3392d6ac6b0db0 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 5 Jan 2007 13:43:54 +0000 Subject: fix loading of rotated fonts on style change --- ChangeLog | 2 ++ src/FbTk/FontImp.hh | 2 +- src/FbTk/XFontImp.cc | 21 ++++++++++++++++----- src/FbTk/XFontImp.hh | 3 ++- src/FbTk/XftFontImp.cc | 18 ++++++++++++++---- src/FbTk/XftFontImp.hh | 3 ++- src/FbTk/XmbFontImp.cc | 2 +- src/FbTk/XmbFontImp.hh | 2 +- 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e200a3..014baff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/src/FbTk/FontImp.hh b/src/FbTk/FontImp.hh index 8a093f2..378c45f 100644 --- a/src/FbTk/FontImp.hh +++ b/src/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; diff --git a/src/FbTk/XFontImp.cc b/src/FbTk/XFontImp.cc index 515b1e2..0c404a1 100644 --- a/src/FbTk/XFontImp.cc +++ b/src/FbTk/XFontImp.cc @@ -45,8 +45,10 @@ using std::nothrow; 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 @@ bool XFontImp::load(const string &fontname) { 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; } diff --git a/src/FbTk/XFontImp.hh b/src/FbTk/XFontImp.hh index 02f17ee..d491a07 100644 --- a/src/FbTk/XFontImp.hh +++ b/src/FbTk/XFontImp.hh @@ -40,7 +40,7 @@ public: 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 @@ private: 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 }; diff --git a/src/FbTk/XftFontImp.cc b/src/FbTk/XftFontImp.cc index 5acf0af..b80474a 100644 --- a/src/FbTk/XftFontImp.cc +++ b/src/FbTk/XftFontImp.cc @@ -36,8 +36,10 @@ namespace FbTk { 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 @@ bool XftFontImp::load(const std::string &name) { } // 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,9 +217,14 @@ 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 double radians = -(orient) * 90 * M_PI / 180; diff --git a/src/FbTk/XftFontImp.hh b/src/FbTk/XftFontImp.hh index 14e9712..178ef3a 100644 --- a/src/FbTk/XftFontImp.hh +++ b/src/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 @@ public: 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; diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc index 9b3c302..b1fd991 100644 --- a/src/FbTk/XmbFontImp.cc +++ b/src/FbTk/XmbFontImp.cc @@ -190,7 +190,7 @@ bool XmbFontImp::load(const string &fontname) { } 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; diff --git a/src/FbTk/XmbFontImp.hh b/src/FbTk/XmbFontImp.hh index 0c8e1a1..992fa90 100644 --- a/src/FbTk/XmbFontImp.hh +++ b/src/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; } -- cgit v0.11.2