ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtfont.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtfont.C (file contents):
Revision 1.125 by ayin, Sun Nov 25 11:23:18 2007 UTC vs.
Revision 1.150 by root, Sun Mar 29 13:36:03 2009 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2008 Marc Lehmann <pcg@goof.com>
5 * - original version. 5 * - original version.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *---------------------------------------------------------------------*/ 20 *---------------------------------------------------------------------*/
21 21
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "rxvtlib.h"
25#include "rxvtutil.h" 24#include "rxvtutil.h"
26#include "rxvtfont.h" 25#include "rxvtfont.h"
27 26
28#include <cstdlib> 27#include <cstdlib>
29 28
217: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) 216: name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset)
218{ 217{
219} 218}
220 219
221void 220void
222rxvt_font::set_name (char *name) 221rxvt_font::set_name (char *name_)
223{ 222{
224 if (this->name == name) 223 if (name == name_)
225 return; 224 return;
226 225
227 if (this->name) free (this->name); // let the compiler optimize 226 if (name) free (name); // let the compiler optimize
228 this->name = name; 227 name = name_;
229} 228}
230 229
231void 230void
232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const 231rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
233{ 232{
237 if (color == Color_bg || color == Color_transparent) 236 if (color == Color_bg || color == Color_transparent)
238 XClearArea (disp, d, x, y, w, h, false); 237 XClearArea (disp, d, x, y, w, h, false);
239 else if (color >= 0) 238 else if (color >= 0)
240 { 239 {
241#if XFT 240#if XFT
242 bool done = false; 241 Picture dst;
242
243#ifdef HAVE_BG_PIXMAP 243# ifdef HAVE_BG_PIXMAP
244 if (term->bgPixmap.pixmap && color >= 0 && term->pix_colors[color].c.color.alpha < 0x0ff00) 244 if (term->bgPixmap.pixmap
245 { 245 && !term->pix_colors[color].is_opaque ()
246 Picture dst = XftDrawPicture (d); 246 && ((dst = XftDrawPicture (d))))
247 if (dst != 0)
248 { 247 {
249 XClearArea (disp, d, x, y, w, h, false); 248 XClearArea (disp, d, x, y, w, h, false);
249
250 Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c); 250 Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c);
251 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h); 251 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h);
252 done = true;
253 } 252 }
254 } 253 else
255#endif 254# endif
256 if (!done)
257 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); 255 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
256
258#else 257#else
259 XSetForeground (disp, gc, term->pix_colors[color]); 258 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (disp, d, gc, x, y, w, h); 259 XFillRectangle (disp, d, gc, x, y, w, h);
261#endif 260#endif
262 } 261 }
632 631
633 if (slashes >= 13 && (!old || *field == old)) 632 if (slashes >= 13 && (!old || *field == old))
634 { 633 {
635 size_t len = field - name; 634 size_t len = field - name;
636 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1); 635 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1);
637 strncpy (*ptr, name, len); 636 memcpy (*ptr, name, len);
638 strcpy (*ptr + len, replace); 637 strcpy (*ptr + len, replace);
639 strcat (*ptr, end); 638 strcat (*ptr, end);
640 639
641 return true; 640 return true;
642 } 641 }
1134 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1133 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1135 1134
1136#if 0 // clipping unfortunately destroys our precious double-width-characters 1135#if 0 // clipping unfortunately destroys our precious double-width-characters
1137 // clip width, we can't do better, or can we? 1136 // clip width, we can't do better, or can we?
1138 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) 1137 if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch)
1139 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); 1138 FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width);
1140#endif 1139#endif
1141 1140
1142 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) 1141 if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch)
1143 FcPatternAddBool (p, FC_MINSPACE, 1); 1142 FcPatternAddBool (p, FC_MINSPACE, 1);
1144 1143
1297 dTermGC; 1296 dTermGC;
1298 1297
1299 int w = term->fwidth * len; 1298 int w = term->fwidth * len;
1300 int h = term->fheight; 1299 int h = term->fheight;
1301 1300
1302 /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. 1301 bool buffered = bg >= Color_transparent
1303 * Maybe make buffering into a resource flag? Compile time option doesn't seems like a 1302 && term->option (Opt_buffered);
1304 * good idea from the perspective of packaging for wide variety of user configs. 1303
1305 */
1306 bool buffered = true
1307#ifdef FORCE_UNBUFFERED_XFT
1308 && bg >= 0
1309#endif
1310 ;
1311 // cut trailing spaces 1304 // cut trailing spaces
1312 while (len && text [len - 1] == ' ') 1305 while (len && text [len - 1] == ' ')
1313 len--; 1306 len--;
1314 1307
1315 int x_ = buffered ? 0 : x; 1308 int x_ = buffered ? 0 : x;
1341 x_ += cwidth; 1334 x_ += cwidth;
1342 } 1335 }
1343 1336
1344 if (buffered) 1337 if (buffered)
1345 { 1338 {
1346 bool back_rendered = false;
1347 if (ep != enc) 1339 if (ep != enc)
1348 { 1340 {
1349 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1341 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1350 1342
1351#ifdef HAVE_BG_PIXMAP 1343#ifdef HAVE_BG_PIXMAP
1344 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1345
1352 if (term->bgPixmap.pixmap) 1346 if (term->bgPixmap.pixmap
1347 && (bg == Color_transparent || bg == Color_bg
1348 || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2))))))
1353 { 1349 {
1354 Picture dst = 0; 1350 int src_x = x, src_y = y;
1355 1351
1356 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) 1352 if (term->bgPixmap.is_parentOrigin ())
1357 dst = XftDrawPicture (d2);
1358
1359 if (bg < 0 || dst != 0)
1360 { 1353 {
1361 int src_x = x, src_y = y ;
1362
1363 if (term->bgPixmap.is_parentOrigin ())
1364 {
1365 src_x += term->window_vt_x; 1354 src_x += term->window_vt_x;
1366 src_y += term->window_vt_y; 1355 src_y += term->window_vt_y;
1367 } 1356 }
1368 1357
1369 if (term->bgPixmap.pmap_width >= src_x+w 1358 if (term->bgPixmap.pmap_width >= src_x + w
1370 && term->bgPixmap.pmap_height >= src_y+h) 1359 && term->bgPixmap.pmap_height >= src_y + h)
1371 { 1360 {
1372 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, 1361 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc,
1373 src_x, src_y, w, h, 0, 0); 1362 src_x, src_y, w, h, 0, 0);
1374 } 1363 }
1375 else 1364 else
1376 { 1365 {
1377 XGCValues gcv; 1366 XGCValues gcv;
1378 1367
1379 gcv.fill_style = FillTiled; 1368 gcv.fill_style = FillTiled;
1380 gcv.tile = term->bgPixmap.pixmap; 1369 gcv.tile = term->bgPixmap.pixmap;
1381 gcv.ts_x_origin = -src_x; 1370 gcv.ts_x_origin = -src_x;
1382 gcv.ts_y_origin = -src_y; 1371 gcv.ts_y_origin = -src_y;
1383 1372
1384 XChangeGC (disp, gc, 1373 XChangeGC (disp, gc,
1385 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, 1374 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1386 &gcv); 1375 &gcv);
1387 1376
1388 XFillRectangle (disp, d2, gc, 0, 0, w, h); 1377 XFillRectangle (disp, d2, gc, 0, 0, w, h);
1389 1378
1390 gcv.fill_style = FillSolid; 1379 gcv.fill_style = FillSolid;
1391 XChangeGC (disp, gc, GCFillStyle, &gcv); 1380 XChangeGC (disp, gc, GCFillStyle, &gcv);
1392 } 1381 }
1393 1382
1394 if (bg >= 0) 1383 if (dst)
1395 { 1384 {
1396 Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); 1385 Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c);
1386
1387 // dst can only be set when bg >= 0
1397 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); 1388 XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h);
1398 }
1399
1400 back_rendered = true;
1401 } 1389 }
1402 } 1390 }
1391 else
1403#endif 1392#endif
1404
1405 if (bg >= 0 && !back_rendered)
1406 XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); 1393 XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h);
1407 1394
1408 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); 1395 XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc);
1409 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); 1396 XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y);
1410 } 1397 }
1411 else 1398 else
1533 if (!end) 1520 if (!end)
1534 end = desc + strlen (desc); 1521 end = desc + strlen (desc);
1535 1522
1536 if (end - desc < 511) 1523 if (end - desc < 511)
1537 { 1524 {
1538 strncpy (buf, desc, end - desc); 1525 memcpy (buf, desc, end - desc);
1539 buf[end - desc] = 0; 1526 buf[end - desc] = 0;
1540 1527
1541 fonts.push_back (new_font (buf, cs)); 1528 fonts.push_back (new_font (buf, cs));
1542 } 1529 }
1543 else 1530 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines