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.76 by root, Tue Jan 3 23:40:58 2006 UTC vs.
Revision 1.85 by root, Wed Jan 25 00:42:21 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2006 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"
24#include "rxvtutil.h" 25#include "rxvtutil.h"
25#include "rxvtfont.h" 26#include "rxvtfont.h"
26 27
27#include <cstdlib> 28#include <cstdlib>
28#include <wchar.h> 29#include <wchar.h>
29#include <inttypes.h> 30#include <inttypes.h>
30
31#define DISPLAY r->display->display
32#define TGC r->gc
33 31
34#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width
35 33
36const struct rxvt_fallback_font { 34const struct rxvt_fallback_font {
37 codeset cs; 35 codeset cs;
152 0x304c, 0x672c, // が本 150 0x304c, 0x672c, // が本
153}; 151};
154 152
155#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 153#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
156 154
155#define dTermDisplay Display *disp = term->display->display
156#define dTermGC GC gc = term->gc
157
157///////////////////////////////////////////////////////////////////////////// 158/////////////////////////////////////////////////////////////////////////////
158 159
159#if XFT 160#if XFT
160rxvt_drawable::~rxvt_drawable () 161rxvt_drawable::~rxvt_drawable ()
161{ 162{
172} 173}
173#endif 174#endif
174 175
175///////////////////////////////////////////////////////////////////////////// 176/////////////////////////////////////////////////////////////////////////////
176 177
177static void *enc_buf;
178static uint32_t enc_len;
179
180static inline void *
181get_enc_buf (uint32_t len)
182{
183 if (len > enc_len)
184 {
185 free (enc_buf);
186 enc_buf = malloc (len);
187 enc_len = len;
188 }
189
190 return enc_buf;
191}
192
193static const char * 178static const char *
194enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 179enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
195{ 180{
196 uint8_t *buf = (uint8_t *)get_enc_buf (len); 181 uint8_t *buf = rxvt_temp_buf<uint8_t> (len);
182 uint8_t *res = buf;
197 183
198 while (len--) 184 while (len--)
199 { 185 {
200 uint32_t c = FROM_UNICODE (cs, *text++); 186 uint32_t c = FROM_UNICODE (cs, *text++);
201 187
206 } 192 }
207 193
208 *buf++ = c; 194 *buf++ = c;
209 } 195 }
210 196
211 return (const char *)enc_buf; 197 return (const char *)res;
212} 198}
213 199
214static const XChar2b * 200static const XChar2b *
215enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) 201enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
216{ 202{
217 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 203 XChar2b *buf = rxvt_temp_buf<XChar2b> (len);
204 XChar2b *res = buf;
218 205
219 while (len--) 206 while (len--)
220 { 207 {
221 uint32_t c = FROM_UNICODE (cs, *text++); 208 uint32_t c = FROM_UNICODE (cs, *text++);
222 209
229 buf->byte1 = c >> 8; 216 buf->byte1 = c >> 8;
230 buf->byte2 = c; 217 buf->byte2 = c;
231 buf++; 218 buf++;
232 } 219 }
233 220
234 return (XChar2b *)enc_buf; 221 return res;
235} 222}
236 223
237///////////////////////////////////////////////////////////////////////////// 224/////////////////////////////////////////////////////////////////////////////
238 225
239void 226void
245 if (this->name) free (this->name); // let the compiler optimize 232 if (this->name) free (this->name); // let the compiler optimize
246 this->name = name; 233 this->name = name;
247} 234}
248 235
249void 236void
250rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) 237rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
251{ 238{
239 dTermDisplay;
240 dTermGC;
241
252 if (color == Color_bg) 242 if (color == Color_bg)
253 XClearArea (d.display->display, d, x, y, w, h, FALSE); 243 XClearArea (disp, d, x, y, w, h, FALSE);
254 else if (color >= 0) 244 else if (color >= 0)
255 { 245 {
256#if XFT 246#if XFT
257 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 247 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
258#else 248#else
259 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 249 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 250 XFillRectangle (disp, d, gc, x, y, w, h);
261#endif 251#endif
262 } 252 }
263} 253}
264 254
265#include "table/linedraw.h" 255#include "table/linedraw.h"
293 set_name (strdup ("built-in support font")); 283 set_name (strdup ("built-in support font"));
294 284
295 return true; 285 return true;
296 } 286 }
297 287
298 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 288 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
299 { 289 {
300 careful = false; 290 careful = false;
301 291
302 if (unicode <= 0x001f) 292 if (unicode <= 0x001f)
303 return true; 293 return true;
306 return false; 296 return false;
307 297
308 if (unicode <= 0x009f) 298 if (unicode <= 0x009f)
309 return true; 299 return true;
310 300
311 if (unicode >= 0x2500 && unicode <= 0x259f) 301 if (unicode >= 0x2500 && unicode <= 0x259f &&
302 !term->option (Opt_skipBuiltinGlyphs))
312 return true; 303 return true;
313 304
314 if (IS_COMPOSE (unicode)) 305 if (IS_COMPOSE (unicode))
315 return true; 306 return true;
316 307
332void 323void
333rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 324rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
334 const text_t *text, int len, 325 const text_t *text, int len,
335 int fg, int bg) 326 int fg, int bg)
336{ 327{
337 Display *disp = d.display->display; 328 dTermDisplay;
329 dTermGC;
338 330
339 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 331 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
340 332
341 XSetForeground (disp, TGC, r->pix_colors[fg]); 333 XSetForeground (disp, gc, term->pix_colors[fg]);
342 334
343 while (len) 335 while (len)
344 { 336 {
345#if ENABLE_COMBINING 337#if ENABLE_COMBINING
346 compose_char *cc; 338 compose_char *cc;
350 342
351 while (++text, --len && *text == NOCHAR) 343 while (++text, --len && *text == NOCHAR)
352 ; 344 ;
353 345
354 int width = text - tp; 346 int width = text - tp;
355 int fwidth = r->fwidth * width; 347 int fwidth = term->fwidth * width;
356 348
357 if (0x2500 <= t && t <= 0x259f) 349 if (0x2500 <= t && t <= 0x259f)
358 { 350 {
359 uint16_t offs = linedraw_offs[t - 0x2500]; 351 uint16_t offs = linedraw_offs[t - 0x2500];
360 uint32_t *a = linedraw_command + (offs >> 4); 352 uint32_t *a = linedraw_command + (offs >> 4);
361 uint32_t *b = a + (offs & 15); 353 uint32_t *b = a + (offs & 15);
362 354
363 int W = fwidth; 355 int W = fwidth;
364 int H = r->fheight; 356 int H = term->fheight;
365 357
366 int x_[16]; 358 int x_[16];
367 int y_[16]; 359 int y_[16];
368 360
369 for (int i = 0; i <= 8; i++) 361 for (int i = 0; i <= 8; i++)
377 369
378 XGCValues gcv; 370 XGCValues gcv;
379 371
380 gcv.cap_style = CapButt; 372 gcv.cap_style = CapButt;
381 gcv.line_width = 0; 373 gcv.line_width = 0;
382 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); 374 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
383 375
384 while (a < b) 376 while (a < b)
385 { 377 {
386 uint32_t command = *a++; 378 uint32_t command = *a++;
387 379
394 int y2 = y_[(command >> 0) & 15]; 386 int y2 = y_[(command >> 0) & 15];
395 387
396 switch (op) 388 switch (op)
397 { 389 {
398 case 0: // line 390 case 0: // line
399 XDrawLine (disp, d, TGC, x1, y1, x2, y2); 391 XDrawLine (disp, d, gc, x1, y1, x2, y2);
400 break; 392 break;
401 393
402 case 1: // rectangle, possibly stippled 394 case 1: // rectangle, possibly stippled
403 if (a) 395 if (a)
404 { 396 {
407 gcv.fill_style = FillStippled; 399 gcv.fill_style = FillStippled;
408 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 400 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
409 gcv.ts_x_origin = x; 401 gcv.ts_x_origin = x;
410 gcv.ts_y_origin = y; 402 gcv.ts_y_origin = y;
411 403
412 XChangeGC (disp, TGC, 404 XChangeGC (disp, gc,
413 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 405 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
414 &gcv); 406 &gcv);
415 } 407 }
416 408
417 XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 409 XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
418 410
419 if (a) 411 if (a)
420 { 412 {
421 XFreePixmap (disp, gcv.stipple); 413 XFreePixmap (disp, gcv.stipple);
422 gcv.stipple = 0; 414 gcv.stipple = 0;
423 gcv.fill_style = FillSolid; 415 gcv.fill_style = FillSolid;
424 XChangeGC (disp, TGC, GCFillStyle, &gcv); 416 XChangeGC (disp, gc, GCFillStyle, &gcv);
425 } 417 }
426 break; 418 break;
427 case 2: // arc 419 case 2: // arc
428 XDrawArc (disp, d, TGC, 420 XDrawArc (disp, d, gc,
429 x1 - W/2, y1 - H/2, W-1, H-1, 421 x1 - W/2, y1 - H/2, W-1, H-1,
430 (a - 1) * 90*64, (b - 1) * 90*64); 422 (a - 1) * 90*64, (b - 1) * 90*64);
431 break; 423 break;
432 } 424 }
433 } 425 }
464 case ZERO_WIDTH_CHAR: 456 case ZERO_WIDTH_CHAR:
465 case NOCHAR: 457 case NOCHAR:
466 break; 458 break;
467 459
468 default: 460 default:
469 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 461 XDrawRectangle (disp, d, gc, x + 2, y + 2,
470 fwidth - 4, r->fheight - 4); 462 fwidth - 4, term->fheight - 4);
471 } 463 }
472 464
473 x += fwidth; 465 x += fwidth;
474 } 466 }
475} 467}
483 475
484 rxvt_fontprop properties (); 476 rxvt_fontprop properties ();
485 477
486 bool load (const rxvt_fontprop &prop); 478 bool load (const rxvt_fontprop &prop);
487 479
488 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 480 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
489 481
490 void draw (rxvt_drawable &d, int x, int y, 482 void draw (rxvt_drawable &d, int x, int y,
491 const text_t *text, int len, 483 const text_t *text, int len,
492 int fg, int bg); 484 int fg, int bg);
493 485
505char * 497char *
506rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 498rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
507{ 499{
508 unsigned long value; 500 unsigned long value;
509 501
510 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 502 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
511 return XGetAtomName (DISPLAY, value); 503 return XGetAtomName (term->display->display, value);
512 else 504 else
513 return rxvt_strdup (repl); 505 return rxvt_strdup (repl);
514} 506}
515 507
516rxvt_fontprop 508rxvt_fontprop
537rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 529rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
538{ 530{
539 unsigned long height; 531 unsigned long height;
540 532
541#if 0 533#if 0
542 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 534 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
543 return false; 535 return false;
544#else 536#else
545 height = f->ascent + f->descent; 537 height = f->ascent + f->descent;
546#endif 538#endif
547 539
548 unsigned long avgwidth; 540 unsigned long avgwidth;
549 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 541 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
550 avgwidth = 0; 542 avgwidth = 0;
551 543
552 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 544 char *weight = get_property (f, "WEIGHT_NAME", "medium");
553 char *slant = get_property (f, "SLANT", "r"); 545 char *slant = get_property (f, "SLANT", "r");
554 546
563} 555}
564 556
565bool 557bool
566rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 558rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
567{ 559{
560 dTermDisplay;
568 int slashes = 0; 561 int slashes = 0;
569 const char *comp[13]; 562 const char *comp[13];
570 563
571 for (const char *c = name; *c; c++) 564 for (const char *c = name; *c; c++)
572 if (*c == '-') 565 if (*c == '-')
580 if (slashes >= 13 573 if (slashes >= 13
581 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 574 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
582 && (*comp[11] >= '0' && *comp[11] <= '9')) 575 && (*comp[11] >= '0' && *comp[11] <= '9'))
583 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); 576 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
584 577
585 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 578 XFontStruct *f = XLoadQueryFont (disp, name);
586 579
587 if (f) 580 if (f)
588 { 581 {
589 // the font should really exist now. if not, we have a problem 582 // the font should really exist now. if not, we have a problem
590 // (e.g. if the user did xset fp rehash just when we were searching fonts). 583 // (e.g. if the user did xset fp rehash just when we were searching fonts).
591 // in that case, just return garbage. 584 // in that case, just return garbage.
592 bool ret = set_properties (p, f); 585 bool ret = set_properties (p, f);
593 XFreeFont (DISPLAY, f); 586 XFreeFont (disp, f);
594 return ret; 587 return ret;
595 } 588 }
596 else 589 else
597 return false; 590 return false;
598} 591}
636} 629}
637 630
638bool 631bool
639rxvt_font_x11::load (const rxvt_fontprop &prop) 632rxvt_font_x11::load (const rxvt_fontprop &prop)
640{ 633{
641 Display *disp = DISPLAY; 634 dTermDisplay;
642 635
643 clear (); 636 clear ();
644 637
645 char field_str[64]; // enough for 128 bits 638 char field_str[64]; // enough for 128 bits
646 639
721 int diff = 0; 714 int diff = 0;
722 715
723 if (replace_field (fname, list[i], 6, '0', field_str)) 716 if (replace_field (fname, list[i], 6, '0', field_str))
724 diff += 10; // slightly penalize scalable fonts 717 diff += 10; // slightly penalize scalable fonts
725 else if (replace_field (fname, list[i], 11, '0', "0")) 718 else if (replace_field (fname, list[i], 11, '0', "0"))
726 diff += 300; // more heavily penalize what looks like scaled bitmap fotns 719 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
727 720
728 if (!set_properties (p, fname)) 721 if (!set_properties (p, fname))
729 continue; 722 continue;
730 723
731 if (prop.height != rxvt_fontprop::unset 724 if (prop.height != rxvt_fontprop::unset
884void 877void
885rxvt_font_x11::clear () 878rxvt_font_x11::clear ()
886{ 879{
887 if (f) 880 if (f)
888 { 881 {
889 XFreeFont (DISPLAY, f); 882 XFreeFont (term->display->display, f);
890 f = 0; 883 f = 0;
891 } 884 }
892} 885}
893 886
894bool 887bool
895rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 888rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
896{ 889{
897 uint32_t ch = FROM_UNICODE (cs, unicode); 890 uint32_t ch = FROM_UNICODE (cs, unicode);
898 891
899 if (ch == NOCHAR) 892 if (ch == NOCHAR)
900 return false; 893 return false;
959 // this looks like a mess /. 952 // this looks like a mess /.
960 // and it is a mess /. 953 // and it is a mess /.
961 // yet we are trying to be perfect /. 954 // yet we are trying to be perfect /.
962 // but the result still isn't perfect /. 955 // but the result still isn't perfect /.
963 956
957 dTermDisplay;
958 dTermGC;
959
964 bool slow = this->slow 960 bool slow = this->slow
965 || width != r->fwidth 961 || width != term->fwidth
966 || height != r->fheight; 962 || height != term->fheight;
967 963
968 int base = ascent; // sorry, incorrect: r->fbase; 964 int base = ascent; // sorry, incorrect: term->fbase;
969 965
970 XGCValues v; 966 XGCValues v;
971 v.foreground = r->pix_colors[fg]; 967 v.foreground = term->pix_colors[fg];
972 v.font = f->fid; 968 v.font = f->fid;
973 969
974 if (enc2b) 970 if (enc2b)
975 { 971 {
976 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 972 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
977 973
978 if (bg == Color_bg && !slow) 974 if (bg == Color_bg && !slow)
979 { 975 {
980 v.background = r->pix_colors[bg]; 976 v.background = term->pix_colors[bg];
981 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 977 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
982 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 978 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
983 } 979 }
984 else 980 else
985 { 981 {
986 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 982 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
987 983
988 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 984 XChangeGC (disp, gc, GCForeground | GCFont, &v);
989 985
990 if (slow) 986 if (slow)
991 { 987 {
992 do 988 do
993 { 989 {
994 if (xc->byte1 || xc->byte2) 990 if (xc->byte1 || xc->byte2)
995 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 991 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
996 992
997 x += r->fwidth; 993 x += term->fwidth;
998 xc++; len--; 994 xc++; len--;
999 } 995 }
1000 while (len); 996 while (len);
1001 } 997 }
1002 else 998 else
1003 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 999 XDrawString16 (disp, d, gc, x, y + base, xc, len);
1004 } 1000 }
1005 } 1001 }
1006 else 1002 else
1007 { 1003 {
1008 const char *xc = enc_char (text, len, cs, slow); 1004 const char *xc = enc_char (text, len, cs, slow);
1009 1005
1010 if (bg == Color_bg && !slow) 1006 if (bg == Color_bg && !slow)
1011 { 1007 {
1012 v.background = r->pix_colors[bg]; 1008 v.background = term->pix_colors[bg];
1013 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1009 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
1014 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1010 XDrawImageString (disp, d, gc, x, y + base, xc, len);
1015 } 1011 }
1016 else 1012 else
1017 { 1013 {
1018 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1014 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1019 1015
1020 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1016 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1021 1017
1022 if (slow) 1018 if (slow)
1023 { 1019 {
1024 do 1020 do
1025 { 1021 {
1026 if (*xc) 1022 if (*xc)
1027 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1023 XDrawString (disp, d, gc, x, y + base, xc, 1);
1028 1024
1029 x += r->fwidth; 1025 x += term->fwidth;
1030 xc++; len--; 1026 xc++; len--;
1031 } 1027 }
1032 while (len); 1028 while (len);
1033 } 1029 }
1034 else 1030 else
1035 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1031 XDrawString (disp, d, gc, x, y + base, xc, len);
1036 } 1032 }
1037 } 1033 }
1038} 1034}
1039 1035
1040///////////////////////////////////////////////////////////////////////////// 1036/////////////////////////////////////////////////////////////////////////////
1052 1048
1053 void draw (rxvt_drawable &d, int x, int y, 1049 void draw (rxvt_drawable &d, int x, int y,
1054 const text_t *text, int len, 1050 const text_t *text, int len,
1055 int fg, int bg); 1051 int fg, int bg);
1056 1052
1057 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1053 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1058 1054
1059protected: 1055protected:
1060 XftFont *f; 1056 XftFont *f;
1061}; 1057};
1062 1058
1063void 1059void
1064rxvt_font_xft::clear () 1060rxvt_font_xft::clear ()
1065{ 1061{
1066 if (f) 1062 if (f)
1067 { 1063 {
1068 XftFontClose (DISPLAY, f); 1064 XftFontClose (term->display->display, f);
1069 f = 0; 1065 f = 0;
1070 } 1066 }
1071} 1067}
1072 1068
1073rxvt_fontprop 1069rxvt_fontprop
1091} 1087}
1092 1088
1093bool 1089bool
1094rxvt_font_xft::load (const rxvt_fontprop &prop) 1090rxvt_font_xft::load (const rxvt_fontprop &prop)
1095{ 1091{
1096 Display *disp = DISPLAY; 1092 dTermDisplay;
1097 1093
1098 clear (); 1094 clear ();
1099 1095
1100 FcPattern *p = FcNameParse ((FcChar8 *) name); 1096 FcPattern *p = FcNameParse ((FcChar8 *) name);
1101 1097
1128 1124
1129 // store generated name so iso14755 view gives better results 1125 // store generated name so iso14755 view gives better results
1130 set_name ((char *)FcNameUnparse (p)); 1126 set_name ((char *)FcNameUnparse (p));
1131 1127
1132 XftResult result; 1128 XftResult result;
1133 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); 1129 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1134 1130
1135 FcPatternDestroy (p); 1131 FcPatternDestroy (p);
1136 1132
1137 if (!match) 1133 if (!match)
1138 return false; 1134 return false;
1236 1232
1237 return success; 1233 return success;
1238} 1234}
1239 1235
1240bool 1236bool
1241rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1237rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1242{ 1238{
1243 careful = false; 1239 careful = false;
1244 1240
1245 if (!XftCharExists (DISPLAY, f, unicode)) 1241 if (!XftCharExists (term->display->display, f, unicode))
1246 return false; 1242 return false;
1247 1243
1248 if (!prop || prop->width == rxvt_fontprop::unset) 1244 if (!prop || prop->width == rxvt_fontprop::unset)
1249 return true; 1245 return true;
1250 1246
1251 // check character against base font bounding box 1247 // check character against base font bounding box
1252 FcChar32 ch = unicode; 1248 FcChar32 ch = unicode;
1253 XGlyphInfo g; 1249 XGlyphInfo g;
1254 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1250 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1255 1251
1256 int w = g.width - g.x; 1252 int w = g.width - g.x;
1257 int wcw = wcwidth (unicode); 1253 int wcw = wcwidth (unicode);
1258 if (wcw > 0) w = (w + wcw - 1) / wcw; 1254 if (wcw > 0) w = (w + wcw - 1) / wcw;
1259 1255
1267void 1263void
1268rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1264rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1269 const text_t *text, int len, 1265 const text_t *text, int len,
1270 int fg, int bg) 1266 int fg, int bg)
1271{ 1267{
1272 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1268 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1273
1274 int base = ascent; // should be fbase, but that is incorrect
1275 1269
1276 XGlyphInfo extents; 1270 XGlyphInfo extents;
1277 FcChar32 *enc = (FcChar32 *) get_enc_buf (len * sizeof (FcChar32)); 1271 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1278 FcChar32 *ep = enc; 1272 XftGlyphSpec *ep = enc;
1279 int ewidth = 0; 1273
1274 dTermDisplay;
1275 dTermGC;
1276
1277 // cut trailing spaces
1278 while (len && text [len - 1] == ' ')
1279 len--;
1280 1280
1281 while (len) 1281 while (len)
1282 { 1282 {
1283 int cwidth = r->fwidth; 1283 int cwidth = term->fwidth;
1284 FcChar32 fc = *text++; len--; 1284 FcChar32 fc = *text++; len--;
1285 1285
1286 while (len && *text == NOCHAR) 1286 while (len && *text == NOCHAR)
1287 text++, len--, cwidth += r->fwidth; 1287 text++, len--, cwidth += term->fwidth;
1288 1288
1289 if (fc == ' ' && ep == enc) // skip leading spaces 1289 if (fc != ' ') // skip spaces
1290 {
1291 FT_UInt glyph = XftCharIndex (disp, f, fc);
1292 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1293
1294 ep->glyph = glyph;
1295 ep->x = x + (cwidth - extents.xOff >> 1);
1296 ep->y = y + ascent;
1297 ep++;
1298 }
1299
1290 x += cwidth; 1300 x += cwidth;
1291 else
1292 {
1293 FT_UInt gl = XftCharIndex (d.display->display, f, fc);
1294 XftGlyphExtents (d.display->display, f, &gl, 1, &extents);
1295
1296 if (extents.xOff != cwidth)
1297 {
1298 if (ewidth)
1299 {
1300 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1301 x, y + base, enc, ep - enc);
1302 x += ewidth;
1303
1304 ep = enc;
1305 ewidth = 0;
1306 }
1307
1308 if (extents.xOff > cwidth)
1309 extents.xOff = cwidth;
1310
1311 XftDrawGlyphs (d, &r->pix_colors[fg].c, f,
1312 x + (cwidth - extents.xOff >> 1),
1313 y + base, &gl, 1);
1314 x += cwidth;
1315 }
1316 else
1317 {
1318 *ep++ = gl;
1319 ewidth += cwidth;
1320 }
1321 }
1322 } 1301 }
1323 1302
1324 if (ep != enc) 1303 if (ep != enc)
1325 XftDrawGlyphs (d, &r->pix_colors[fg].c, f, 1304 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1326 x, y + base, enc, ep - enc);
1327} 1305}
1328#endif 1306#endif
1329 1307
1330///////////////////////////////////////////////////////////////////////////// 1308/////////////////////////////////////////////////////////////////////////////
1331 1309
1332rxvt_fontset::rxvt_fontset (rxvt_t r) 1310rxvt_fontset::rxvt_fontset (rxvt_term *term)
1333: fontdesc (0), r (r) 1311: fontdesc (0), term (term)
1334{ 1312{
1335 clear (); 1313 clear ();
1336} 1314}
1337 1315
1338rxvt_fontset::~rxvt_fontset () 1316rxvt_fontset::~rxvt_fontset ()
1382 f = new rxvt_font_x11; 1360 f = new rxvt_font_x11;
1383 } 1361 }
1384 else 1362 else
1385 f = new rxvt_font_x11; 1363 f = new rxvt_font_x11;
1386 1364
1387 f->set_term (r); 1365 f->set_term (term);
1388 f->set_name (strdup (name)); 1366 f->set_name (strdup (name));
1389 1367
1390 f->cs = cs; 1368 f->cs = cs;
1391 f->loaded = false; 1369 f->loaded = false;
1392 1370
1575 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1553 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1576 FcPatternAddBool (p, FC_MINSPACE, 1); 1554 FcPatternAddBool (p, FC_MINSPACE, 1);
1577 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1555 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1578 1556
1579 XftResult result; 1557 XftResult result;
1580 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); 1558 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1581 1559
1582 FcPatternDestroy (p); 1560 FcPatternDestroy (p);
1583 1561
1584 if (match) 1562 if (match)
1585 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines