diff options
author | simonb <simonb> | 2007-01-05 13:43:54 (GMT) |
---|---|---|
committer | simonb <simonb> | 2007-01-05 13:43:54 (GMT) |
commit | ad7fd2d8675141925bdef7c29d3392d6ac6b0db0 (patch) | |
tree | 776c13dccaecc0eeb54c514040ac00a74f347a99 /src | |
parent | 3a79de034f87df155f540af2186c5d87dc187b3b (diff) | |
download | fluxbox-ad7fd2d8675141925bdef7c29d3392d6ac6b0db0.zip fluxbox-ad7fd2d8675141925bdef7c29d3392d6ac6b0db0.tar.bz2 |
fix loading of rotated fonts on style change
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/FontImp.hh | 2 | ||||
-rw-r--r-- | src/FbTk/XFontImp.cc | 21 | ||||
-rw-r--r-- | src/FbTk/XFontImp.hh | 3 | ||||
-rw-r--r-- | src/FbTk/XftFontImp.cc | 18 | ||||
-rw-r--r-- | src/FbTk/XftFontImp.hh | 3 | ||||
-rw-r--r-- | src/FbTk/XmbFontImp.cc | 2 | ||||
-rw-r--r-- | src/FbTk/XmbFontImp.hh | 2 |
7 files changed, 37 insertions, 14 deletions
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 { | |||
44 | public: | 44 | public: |
45 | virtual ~FontImp() { } | 45 | virtual ~FontImp() { } |
46 | virtual bool load(const std::string &name) = 0; | 46 | virtual bool load(const std::string &name) = 0; |
47 | 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; | 47 | virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) = 0; |
48 | virtual unsigned int textWidth(const FbString &text, unsigned int size) const = 0; | 48 | virtual unsigned int textWidth(const FbString &text, unsigned int size) const = 0; |
49 | virtual bool validOrientation(FbTk::Orientation orient) { return orient == ROT0; } | 49 | virtual bool validOrientation(FbTk::Orientation orient) { return orient == ROT0; } |
50 | virtual int ascent() const = 0; | 50 | 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; | |||
45 | namespace FbTk { | 45 | namespace FbTk { |
46 | 46 | ||
47 | XFontImp::XFontImp(const char *fontname):m_fontstruct(0) { | 47 | XFontImp::XFontImp(const char *fontname):m_fontstruct(0) { |
48 | for (int i = ROT0; i <= ROT270; ++i) | 48 | for (int i = ROT0; i <= ROT270; ++i) { |
49 | m_rotfonts[i] = 0; | 49 | m_rotfonts[i] = 0; |
50 | m_rotfonts_loaded[i] = false; | ||
51 | } | ||
50 | 52 | ||
51 | if (fontname != 0) | 53 | if (fontname != 0) |
52 | load(fontname); | 54 | load(fontname); |
@@ -78,19 +80,23 @@ bool XFontImp::load(const string &fontname) { | |||
78 | 80 | ||
79 | m_fontstruct = font; //set new font | 81 | m_fontstruct = font; //set new font |
80 | 82 | ||
81 | for (int i = ROT0; i <= ROT270; ++i) | 83 | for (int i = ROT0; i <= ROT270; ++i) { |
82 | if (m_rotfonts[i] != 0) | 84 | m_rotfonts_loaded[i] = false; |
85 | if (m_rotfonts[i] != 0) { | ||
83 | freeRotFont(m_rotfonts[i]); | 86 | freeRotFont(m_rotfonts[i]); |
87 | m_rotfonts[i] = 0; | ||
88 | } | ||
89 | } | ||
84 | 90 | ||
85 | return true; | 91 | return true; |
86 | } | 92 | } |
87 | 93 | ||
88 | void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { | 94 | void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) { |
89 | if (m_fontstruct == 0) | 95 | if (m_fontstruct == 0) |
90 | return; | 96 | return; |
91 | 97 | ||
92 | // use roated font functions? | 98 | // use roated font functions? |
93 | if (orient != ROT0 && m_rotfonts[orient] != 0) { | 99 | if (orient != ROT0 && validOrientation(orient)) { |
94 | drawRotText(w.drawable(), screen, gc, text, len, x, y, orient); | 100 | drawRotText(w.drawable(), screen, gc, text, len, x, y, orient); |
95 | return; | 101 | return; |
96 | } | 102 | } |
@@ -389,7 +395,12 @@ bool XFontImp::validOrientation(FbTk::Orientation orient) { | |||
389 | if (orient == ROT0 || m_rotfonts[orient]) | 395 | if (orient == ROT0 || m_rotfonts[orient]) |
390 | return true; | 396 | return true; |
391 | 397 | ||
398 | if (m_rotfonts_loaded[orient]) | ||
399 | return false; // load must have failed | ||
400 | |||
401 | m_rotfonts_loaded[orient] = true; | ||
392 | rotate(orient); | 402 | rotate(orient); |
403 | |||
393 | return m_rotfonts[orient] != 0; | 404 | return m_rotfonts[orient] != 0; |
394 | } | 405 | } |
395 | 406 | ||
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: | |||
40 | unsigned int height() const; | 40 | unsigned int height() const; |
41 | int ascent() const; | 41 | int ascent() const; |
42 | int descent() const { return m_fontstruct ? m_fontstruct->descent : 0; } | 42 | int descent() const { return m_fontstruct ? m_fontstruct->descent : 0; } |
43 | void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; | 43 | void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient); |
44 | 44 | ||
45 | bool validOrientation(FbTk::Orientation orient); | 45 | bool validOrientation(FbTk::Orientation orient); |
46 | 46 | ||
@@ -79,6 +79,7 @@ private: | |||
79 | void drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; | 79 | void drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; |
80 | 80 | ||
81 | XRotFontStruct *m_rotfonts[4]; ///< rotated font structure (only 3 used) | 81 | XRotFontStruct *m_rotfonts[4]; ///< rotated font structure (only 3 used) |
82 | bool m_rotfonts_loaded[4]; // whether we've tried yet | ||
82 | XFontStruct *m_fontstruct; ///< X font structure | 83 | XFontStruct *m_fontstruct; ///< X font structure |
83 | 84 | ||
84 | }; | 85 | }; |
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 { | |||
36 | XftFontImp::XftFontImp(const char *name, bool utf8): | 36 | XftFontImp::XftFontImp(const char *name, bool utf8): |
37 | m_utf8mode(utf8), m_name("") { | 37 | m_utf8mode(utf8), m_name("") { |
38 | 38 | ||
39 | for (int r = ROT0; r <= ROT270; r++) | 39 | for (int r = ROT0; r <= ROT270; r++) { |
40 | m_xftfonts[r] = 0; | 40 | m_xftfonts[r] = 0; |
41 | m_xftfonts_loaded[r] = false; | ||
42 | } | ||
41 | 43 | ||
42 | if (name != 0) | 44 | if (name != 0) |
43 | load(name); | 45 | load(name); |
@@ -62,21 +64,24 @@ bool XftFontImp::load(const std::string &name) { | |||
62 | } | 64 | } |
63 | 65 | ||
64 | // destroy all old fonts and set new | 66 | // destroy all old fonts and set new |
65 | for (int r = ROT0; r <= ROT270; r++) | 67 | for (int r = ROT0; r <= ROT270; r++) { |
68 | m_xftfonts_loaded[r] = false; | ||
66 | if (m_xftfonts[r] != 0) { | 69 | if (m_xftfonts[r] != 0) { |
67 | XftFontClose(App::instance()->display(), m_xftfonts[r]); | 70 | XftFontClose(App::instance()->display(), m_xftfonts[r]); |
68 | m_xftfonts[r] = 0; | 71 | m_xftfonts[r] = 0; |
69 | } | 72 | } |
73 | } | ||
70 | 74 | ||
71 | m_xftfonts[ROT0] = newxftfont; | 75 | m_xftfonts[ROT0] = newxftfont; |
76 | m_xftfonts_loaded[ROT0] = true; | ||
72 | m_name = name; | 77 | m_name = name; |
73 | 78 | ||
74 | return true; | 79 | return true; |
75 | } | 80 | } |
76 | 81 | ||
77 | void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { | 82 | void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) { |
78 | 83 | ||
79 | if (m_xftfonts[orient] == 0) | 84 | if (!validOrientation(orient)) |
80 | return; | 85 | return; |
81 | 86 | ||
82 | // we adjust y slightly so that the baseline is in the right spot | 87 | // we adjust y slightly so that the baseline is in the right spot |
@@ -212,9 +217,14 @@ bool XftFontImp::validOrientation(FbTk::Orientation orient) { | |||
212 | if (orient == ROT0 || m_xftfonts[orient]) | 217 | if (orient == ROT0 || m_xftfonts[orient]) |
213 | return true; | 218 | return true; |
214 | 219 | ||
220 | if (m_xftfonts_loaded[orient]) | ||
221 | return false; // m_xftfonts is zero here | ||
222 | |||
215 | if (m_xftfonts[ROT0] == 0) | 223 | if (m_xftfonts[ROT0] == 0) |
216 | return false; | 224 | return false; |
217 | 225 | ||
226 | m_xftfonts_loaded[orient] = true; | ||
227 | |||
218 | // otherwise, try to load that orientation | 228 | // otherwise, try to load that orientation |
219 | // radians is actually anti-clockwise, so we reverse it | 229 | // radians is actually anti-clockwise, so we reverse it |
220 | double radians = -(orient) * 90 * M_PI / 180; | 230 | 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: | |||
36 | XftFontImp(const char *fontname, bool utf8); | 36 | XftFontImp(const char *fontname, bool utf8); |
37 | ~XftFontImp(); | 37 | ~XftFontImp(); |
38 | bool load(const std::string &name); | 38 | bool load(const std::string &name); |
39 | void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient) const; | 39 | void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient); |
40 | unsigned int textWidth(const FbString &text, unsigned int len) const; | 40 | unsigned int textWidth(const FbString &text, unsigned int len) const; |
41 | unsigned int height() const; | 41 | unsigned int height() const; |
42 | int ascent() const { return m_xftfonts[0] ? m_xftfonts[0]->ascent : 0; } | 42 | int ascent() const { return m_xftfonts[0] ? m_xftfonts[0]->ascent : 0; } |
@@ -47,6 +47,7 @@ public: | |||
47 | 47 | ||
48 | private: | 48 | private: |
49 | XftFont *m_xftfonts[4]; // 4 possible orientations | 49 | XftFont *m_xftfonts[4]; // 4 possible orientations |
50 | bool m_xftfonts_loaded[4]; // whether we've tried loading the orientation | ||
50 | // rotated xft fonts don't give proper extents info, so we keep the "real" | 51 | // rotated xft fonts don't give proper extents info, so we keep the "real" |
51 | // one around for it | 52 | // one around for it |
52 | bool m_utf8mode; | 53 | 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) { | |||
190 | } | 190 | } |
191 | 191 | ||
192 | void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const FbString &text, | 192 | void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const FbString &text, |
193 | size_t len, int x, int y, FbTk::Orientation orient) const { | 193 | size_t len, int x, int y, FbTk::Orientation orient) { |
194 | 194 | ||
195 | if (m_fontset == 0) | 195 | if (m_fontset == 0) |
196 | return; | 196 | 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: | |||
36 | XmbFontImp(const char *fontname, bool utf8); | 36 | XmbFontImp(const char *fontname, bool utf8); |
37 | ~XmbFontImp(); | 37 | ~XmbFontImp(); |
38 | bool load(const std::string &name); | 38 | bool load(const std::string &name); |
39 | virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; | 39 | virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient); |
40 | unsigned int textWidth(const FbString &text, unsigned int len) const; | 40 | unsigned int textWidth(const FbString &text, unsigned int len) const; |
41 | unsigned int height() const; | 41 | unsigned int height() const; |
42 | int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } | 42 | int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; } |