aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/XftFontImp.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2006-03-26 04:02:30 (GMT)
committersimonb <simonb>2006-03-26 04:02:30 (GMT)
commitaf74a2284551c8511b66d77112c7bf32831c1522 (patch)
tree35a8830352f5facc1fc9c58b82c0c6dce8fc921e /src/FbTk/XftFontImp.cc
parent872f6a0e1e4230f702ad69fa2d7e10a2fa78b7a3 (diff)
downloadfluxbox-af74a2284551c8511b66d77112c7bf32831c1522.zip
fluxbox-af74a2284551c8511b66d77112c7bf32831c1522.tar.bz2
rotated fonts, buttons, containers. Used for tabs for now
Diffstat (limited to 'src/FbTk/XftFontImp.cc')
-rw-r--r--src/FbTk/XftFontImp.cc102
1 files changed, 84 insertions, 18 deletions
diff --git a/src/FbTk/XftFontImp.cc b/src/FbTk/XftFontImp.cc
index 1b248fa..a724463 100644
--- a/src/FbTk/XftFontImp.cc
+++ b/src/FbTk/XftFontImp.cc
@@ -25,21 +25,28 @@
25#include "App.hh" 25#include "App.hh"
26#include "FbDrawable.hh" 26#include "FbDrawable.hh"
27 27
28#include <math.h>
29
28#ifdef HAVE_CONFIG_H 30#ifdef HAVE_CONFIG_H
29#include "config.h" 31#include "config.h"
30#endif //HAVE_CONFIG_H 32#endif //HAVE_CONFIG_H
31 33
32namespace FbTk { 34namespace FbTk {
33 35
34XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0), 36XftFontImp::XftFontImp(const char *name, bool utf8):
35 m_utf8mode(utf8) { 37 m_utf8mode(utf8), m_name("") {
38
39 for (int r = ROT0; r <= ROT270; r++)
40 m_xftfonts[r] = 0;
41
36 if (name != 0) 42 if (name != 0)
37 load(name); 43 load(name);
38} 44}
39 45
40XftFontImp::~XftFontImp() { 46XftFontImp::~XftFontImp() {
41 if (m_xftfont != 0) 47 for (int r = ROT0; r <= ROT270; r++)
42 XftFontClose(App::instance()->display(), m_xftfont); 48 if (m_xftfonts[r] != 0)
49 XftFontClose(App::instance()->display(), m_xftfonts[r]);
43} 50}
44 51
45bool XftFontImp::load(const std::string &name) { 52bool XftFontImp::load(const std::string &name) {
@@ -54,18 +61,39 @@ bool XftFontImp::load(const std::string &name) {
54 return false; 61 return false;
55 } 62 }
56 63
57 // destroy old font and set new 64 // destroy all old fonts and set new
58 if (m_xftfont != 0) 65 for (int r = ROT0; r <= ROT270; r++)
59 XftFontClose(disp, m_xftfont); 66 if (m_xftfonts[r] != 0)
67 XftFontClose(App::instance()->display(), m_xftfonts[r]);
60 68
61 m_xftfont = newxftfont; 69 m_xftfonts[ROT0] = newxftfont;
70 m_name = name;
62 71
63 return true; 72 return true;
64} 73}
65 74
66void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text, size_t len, int x, int y) const { 75void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text, size_t len, int x, int y, FbTk::Orientation orient) const {
67 if (m_xftfont == 0) 76 if (m_xftfonts[orient] == 0)
68 return; 77 return;
78
79 // we adjust y slightly so that the baseline is in the right spot
80 // (it is offset one by rotation >=180 degrees)
81 switch (orient) {
82 case ROT0:
83 break;
84 case ROT90:
85 break;
86 case ROT180:
87 x+=1;
88 y+=1;
89 break;
90 case ROT270:
91 y+=1;
92 break;
93 }
94
95 XftFont *font = m_xftfonts[orient];
96
69 XftDraw *draw = XftDrawCreate(w.display(), 97 XftDraw *draw = XftDrawCreate(w.display(),
70 w.drawable(), 98 w.drawable(),
71 DefaultVisual(w.display(), screen), 99 DefaultVisual(w.display(), screen),
@@ -101,13 +129,13 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *te
101 // if the size is zero we use the XftDrawString8 function instead. 129 // if the size is zero we use the XftDrawString8 function instead.
102 XGlyphInfo ginfo; 130 XGlyphInfo ginfo;
103 XftTextExtentsUtf8(w.display(), 131 XftTextExtentsUtf8(w.display(),
104 m_xftfont, 132 m_xftfonts[ROT0],
105 (XftChar8 *)text, len, 133 (XftChar8 *)text, len,
106 &ginfo); 134 &ginfo);
107 if (ginfo.xOff != 0) { 135 if (ginfo.xOff != 0) {
108 XftDrawStringUtf8(draw, 136 XftDrawStringUtf8(draw,
109 &xftcolor, 137 &xftcolor,
110 m_xftfont, 138 font,
111 x, y, 139 x, y,
112 (XftChar8 *)(text), len); 140 (XftChar8 *)(text), len);
113 XftColorFree(w.display(), 141 XftColorFree(w.display(),
@@ -121,7 +149,7 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *te
121 149
122 XftDrawString8(draw, 150 XftDrawString8(draw,
123 &xftcolor, 151 &xftcolor,
124 m_xftfont, 152 font,
125 x, y, 153 x, y,
126 (XftChar8 *)(text), len); 154 (XftChar8 *)(text), len);
127 155
@@ -133,16 +161,19 @@ void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *te
133} 161}
134 162
135unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const { 163unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const {
136 if (m_xftfont == 0) 164 if (m_xftfonts[ROT0] == 0)
137 return 0; 165 return 0;
138 166
139 XGlyphInfo ginfo; 167 XGlyphInfo ginfo;
140 Display* disp = App::instance()->display(); 168 Display* disp = App::instance()->display();
141 169
170 XftFont *font = m_xftfonts[ROT0];
171
172
142#ifdef HAVE_XFT_UTF8_STRING 173#ifdef HAVE_XFT_UTF8_STRING
143 if (m_utf8mode) { 174 if (m_utf8mode) {
144 XftTextExtentsUtf8(disp, 175 XftTextExtentsUtf8(disp,
145 m_xftfont, 176 font,
146 (XftChar8 *)text, len, 177 (XftChar8 *)text, len,
147 &ginfo); 178 &ginfo);
148 if (ginfo.xOff != 0) 179 if (ginfo.xOff != 0)
@@ -153,7 +184,7 @@ unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) co
153#endif //HAVE_XFT_UTF8_STRING 184#endif //HAVE_XFT_UTF8_STRING
154 185
155 XftTextExtents8(disp, 186 XftTextExtents8(disp,
156 m_xftfont, 187 font,
157 (XftChar8 *)text, len, 188 (XftChar8 *)text, len,
158 &ginfo); 189 &ginfo);
159 190
@@ -161,12 +192,47 @@ unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) co
161} 192}
162 193
163unsigned int XftFontImp::height() const { 194unsigned int XftFontImp::height() const {
164 if (m_xftfont == 0) 195 if (m_xftfonts[ROT0] == 0)
165 return 0; 196 return 0;
166 return m_xftfont->height; 197 else
198 return m_xftfonts[ROT0]->height;
167 //m_xftfont->ascent + m_xftfont->descent; 199 //m_xftfont->ascent + m_xftfont->descent;
168 // curiously, fonts seem to have a smaller height, but the "height" 200 // curiously, fonts seem to have a smaller height, but the "height"
169 // is specified within the actual font, so it must be right, right? 201 // is specified within the actual font, so it must be right, right?
170} 202}
171 203
204bool XftFontImp::validOrientation(FbTk::Orientation orient) {
205 if (orient == ROT0 || m_xftfonts[orient])
206 return true;
207
208 if (m_xftfonts[ROT0] == 0)
209 return false;
210
211 // otherwise, try to load that orientation
212 // radians is actually anti-clockwise, so we reverse it
213 double radians = -(orient) * 90 * M_PI / 180;
214
215 XftMatrix matrix;
216 XftMatrixInit(&matrix);
217 XftMatrixRotate(&matrix, cos(radians), sin(radians));
218
219 Display *disp = App::instance()->display();
220
221 XftPattern * pattern = XftNameParse(m_name.c_str());
222 XftPatternAddMatrix(pattern, XFT_MATRIX, &matrix);
223 XftResult result;
224 XftPattern * foundpat = XftFontMatch(disp, 0, pattern, &result);
225 XftPatternDestroy(pattern);
226 XftFont * new_font = XftFontOpenPattern(disp, foundpat);
227
228 if (new_font == 0)
229 return false;
230
231 m_xftfonts[orient] = new_font;
232
233 return true;
234}
235
236
237
172}; // end namespace FbTk 238}; // end namespace FbTk