diff options
author | fluxgen <fluxgen> | 2003-09-11 20:00:09 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-09-11 20:00:09 (GMT) |
commit | 4b035f1d070582717620355895c9ce9967cbe8e4 (patch) | |
tree | 14685a3dd8974c7de15726692459b2817905cdbc | |
parent | 3b9f04d4405abe242f4d198342d50f497d3475b3 (diff) | |
download | fluxbox_lack-4b035f1d070582717620355895c9ce9967cbe8e4.zip fluxbox_lack-4b035f1d070582717620355895c9ce9967cbe8e4.tar.bz2 |
cleaning
-rw-r--r-- | src/FbTk/XFontImp.cc | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/FbTk/XFontImp.cc b/src/FbTk/XFontImp.cc index 66adee3..e253aa6 100644 --- a/src/FbTk/XFontImp.cc +++ b/src/FbTk/XFontImp.cc | |||
@@ -19,10 +19,12 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: XFontImp.cc,v 1.5 2002/12/09 22:12:56 fluxgen Exp $ | 22 | // $Id: XFontImp.cc,v 1.6 2003/09/11 20:00:09 fluxgen Exp $ |
23 | 23 | ||
24 | #include "XFontImp.hh" | 24 | #include "XFontImp.hh" |
25 | #include "App.hh" | 25 | #include "App.hh" |
26 | #include "GContext.hh" | ||
27 | #include "FbPixmap.hh" | ||
26 | 28 | ||
27 | #include <X11/Xutil.h> | 29 | #include <X11/Xutil.h> |
28 | 30 | ||
@@ -125,14 +127,11 @@ void XFontImp::rotate(float angle) { | |||
125 | 127 | ||
126 | m_angle = angle; | 128 | m_angle = angle; |
127 | 129 | ||
128 | char val; | ||
129 | XImage *I1, *I2; | ||
130 | // X system default vars | 130 | // X system default vars |
131 | Display *dpy = App::instance()->display(); | 131 | Display *dpy = App::instance()->display(); |
132 | Window rootwin = DefaultRootWindow(dpy); | 132 | Window rootwin = DefaultRootWindow(dpy); |
133 | int screen = DefaultScreen(dpy); | 133 | int screen = DefaultScreen(dpy); |
134 | 134 | ||
135 | GC font_gc; | ||
136 | char text[3]; | 135 | char text[3]; |
137 | int ichar, i, j, index, boxlen = 60; | 136 | int ichar, i, j, index, boxlen = 60; |
138 | int vert_w, vert_h, vert_len, bit_w, bit_h, bit_len; | 137 | int vert_w, vert_h, vert_len, bit_w, bit_h, bit_len; |
@@ -147,14 +146,12 @@ void XFontImp::rotate(float angle) { | |||
147 | return; | 146 | return; |
148 | 147 | ||
149 | // create the depth 1 canvas bitmap | 148 | // create the depth 1 canvas bitmap |
150 | Pixmap canvas = XCreatePixmap(dpy, rootwin, boxlen, boxlen, 1); | 149 | FbTk::FbPixmap canvas(rootwin, boxlen, boxlen, 1); |
151 | 150 | ||
152 | // create graphic context for our canvas | 151 | // create graphic context for our canvas |
153 | font_gc = XCreateGC(dpy, canvas, 0, 0); | 152 | FbTk::GContext font_gc(canvas); |
154 | 153 | font_gc.setBackground(None); | |
155 | XSetBackground(dpy, font_gc, None); | 154 | font_gc.setFont(m_fontstruct->fid); |
156 | |||
157 | XSetFont(dpy, font_gc, m_fontstruct->fid); | ||
158 | 155 | ||
159 | // allocate space for rotated font | 156 | // allocate space for rotated font |
160 | m_rotfont = new(nothrow) XRotFontStruct; | 157 | m_rotfont = new(nothrow) XRotFontStruct; |
@@ -207,21 +204,24 @@ void XFontImp::rotate(float angle) { | |||
207 | // width in bytes | 204 | // width in bytes |
208 | vert_len = (vert_w-1)/8+1; | 205 | vert_len = (vert_w-1)/8+1; |
209 | 206 | ||
210 | XSetForeground(dpy, font_gc, None); | 207 | font_gc.setForeground(None); |
211 | XFillRectangle(dpy, canvas, font_gc, 0, 0, boxlen, boxlen); | 208 | canvas.fillRectangle(font_gc.gc(), |
212 | 209 | 0, 0, | |
210 | boxlen, boxlen); | ||
213 | // draw the character centre top right on canvas | 211 | // draw the character centre top right on canvas |
214 | sprintf(text, "%c", ichar); | 212 | sprintf(text, "%c", ichar); |
215 | XSetForeground(dpy, font_gc, 1); | 213 | font_gc.setForeground(1); |
216 | XDrawImageString(dpy, canvas, font_gc, boxlen/2 - lbearing, | 214 | XDrawImageString(dpy, canvas.drawable(), font_gc.gc(), |
215 | boxlen/2 - lbearing, | ||
217 | boxlen/2 - descent, text, 1); | 216 | boxlen/2 - descent, text, 1); |
218 | 217 | ||
219 | // reserve memory for first XImage | 218 | // reserve memory for first XImage |
220 | vertdata = (unsigned char *) malloc((unsigned)(vert_len*vert_h)); | 219 | vertdata = new unsigned char[vert_len * vert_h]; |
221 | 220 | ||
222 | /* create the XImage ... */ | 221 | XImage *I1 = XCreateImage(dpy, DefaultVisual(dpy, screen), |
223 | I1 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, | 222 | 1, XYBitmap, |
224 | 0, (char *)vertdata, vert_w, vert_h, 8, 0); | 223 | 0, (char *)vertdata, |
224 | vert_w, vert_h, 8, 0); | ||
225 | 225 | ||
226 | if (I1 == None) { | 226 | if (I1 == None) { |
227 | cerr<<"RotFont: Cant create ximage."<<endl; | 227 | cerr<<"RotFont: Cant create ximage."<<endl; |
@@ -232,12 +232,14 @@ void XFontImp::rotate(float angle) { | |||
232 | 232 | ||
233 | I1->byte_order = I1->bitmap_bit_order = MSBFirst; | 233 | I1->byte_order = I1->bitmap_bit_order = MSBFirst; |
234 | 234 | ||
235 | /* extract character from canvas ... */ | 235 | // extract character from canvas |
236 | XGetSubImage(dpy, canvas, boxlen/2, boxlen/2 - vert_h, | 236 | XGetSubImage(dpy, canvas.drawable(), |
237 | boxlen/2, boxlen/2 - vert_h, | ||
237 | vert_w, vert_h, 1, XYPixmap, I1, 0, 0); | 238 | vert_w, vert_h, 1, XYPixmap, I1, 0, 0); |
239 | |||
238 | I1->format = XYBitmap; | 240 | I1->format = XYBitmap; |
239 | 241 | ||
240 | /* width, height of rotated character ... */ | 242 | // width, height of rotated character |
241 | if (dir == 2) { | 243 | if (dir == 2) { |
242 | bit_w = vert_w; | 244 | bit_w = vert_w; |
243 | bit_h = vert_h; | 245 | bit_h = vert_h; |
@@ -246,17 +248,17 @@ void XFontImp::rotate(float angle) { | |||
246 | bit_h = vert_w; | 248 | bit_h = vert_w; |
247 | } | 249 | } |
248 | 250 | ||
249 | /* width in bytes ... */ | 251 | // width in bytes |
250 | bit_len = (bit_w-1)/8 + 1; | 252 | bit_len = (bit_w-1)/8 + 1; |
251 | 253 | ||
252 | m_rotfont->per_char[ichar-32].glyph.bit_w = bit_w; | 254 | m_rotfont->per_char[ichar-32].glyph.bit_w = bit_w; |
253 | m_rotfont->per_char[ichar-32].glyph.bit_h = bit_h; | 255 | m_rotfont->per_char[ichar-32].glyph.bit_h = bit_h; |
254 | 256 | ||
255 | /* reserve memory for the rotated image ... */ | 257 | // reserve memory for the rotated image |
256 | bitdata = (unsigned char *)calloc((unsigned)(bit_h * bit_len), 1); | 258 | bitdata = (unsigned char *)calloc((unsigned)(bit_h * bit_len), 1); |
257 | 259 | ||
258 | /* create the image ... */ | 260 | // create the image |
259 | I2 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0, | 261 | XImage *I2 = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYBitmap, 0, |
260 | (char *)bitdata, bit_w, bit_h, 8, 0); | 262 | (char *)bitdata, bit_w, bit_h, 8, 0); |
261 | 263 | ||
262 | if (I2 == None) { | 264 | if (I2 == None) { |
@@ -268,16 +270,16 @@ void XFontImp::rotate(float angle) { | |||
268 | 270 | ||
269 | I2->byte_order = I2->bitmap_bit_order = MSBFirst; | 271 | I2->byte_order = I2->bitmap_bit_order = MSBFirst; |
270 | 272 | ||
271 | /* map vertical data to rotated character ... */ | 273 | // map vertical data to rotated character |
272 | for (j = 0; j < bit_h; j++) { | 274 | for (j = 0; j < bit_h; j++) { |
273 | for (i = 0; i < bit_w; i++) { | 275 | for (i = 0; i < bit_w; i++) { |
274 | /* map bits ... */ | 276 | char val = 0; |
275 | if (dir == 1) { | 277 | if (dir == 1) { |
276 | val = vertdata[i*vert_len + (vert_w-j-1)/8] & | 278 | val = vertdata[i*vert_len + (vert_w-j-1)/8] & |
277 | (128>>((vert_w-j-1)%8)); | 279 | (128>>((vert_w-j-1)%8)); |
278 | } else if (dir == 2) { | 280 | } else if (dir == 2) { |
279 | val = vertdata[(vert_h-j-1)*vert_len + | 281 | val = vertdata[(vert_h-j-1)*vert_len + |
280 | (vert_w-i-1)/8] & (128>>((vert_w-i-1)%8)); | 282 | (vert_w-i-1)/8] & (128>>((vert_w-i-1)%8)); |
281 | } else { | 283 | } else { |
282 | val = vertdata[(vert_h-i-1)*vert_len + j/8] & | 284 | val = vertdata[(vert_h-i-1)*vert_len + j/8] & |
283 | (128>>(j%8)); | 285 | (128>>(j%8)); |
@@ -295,17 +297,13 @@ void XFontImp::rotate(float angle) { | |||
295 | 297 | ||
296 | // put the image into the bitmap | 298 | // put the image into the bitmap |
297 | XPutImage(dpy, m_rotfont->per_char[ichar-32].glyph.bm, | 299 | XPutImage(dpy, m_rotfont->per_char[ichar-32].glyph.bm, |
298 | font_gc, I2, 0, 0, 0, 0, bit_w, bit_h); | 300 | font_gc.gc(), I2, 0, 0, 0, 0, bit_w, bit_h); |
299 | 301 | ||
300 | // free the image and data | 302 | // free the image and data |
301 | XDestroyImage(I1); | 303 | XDestroyImage(I1); |
302 | XDestroyImage(I2); | 304 | XDestroyImage(I2); |
303 | } | 305 | } |
304 | 306 | ||
305 | /* free pixmap and GC ... */ | ||
306 | XFreePixmap(dpy, canvas); | ||
307 | XFreeGC(dpy, font_gc); | ||
308 | |||
309 | } | 307 | } |
310 | 308 | ||
311 | void XFontImp::freeRotFont() { | 309 | void XFontImp::freeRotFont() { |