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.83 by root, Mon Jan 9 07:35:23 2006 UTC vs.
Revision 1.87 by root, Wed Jan 25 21:03:04 2006 UTC

27 27
28#include <cstdlib> 28#include <cstdlib>
29#include <wchar.h> 29#include <wchar.h>
30#include <inttypes.h> 30#include <inttypes.h>
31 31
32#define DISPLAY r->display->display
33#define TGC r->gc
34
35#define MAX_OVERLAP (4 + 1) // max. character width in 4ths of the base width 32#define MAX_OVERLAP_ROMAN (8 + 2) // max. character width in 8ths of the base width
33#define MAX_OVERLAP_ITALIC (8 + 3) // max. overlap for italic fonts
34
35#define OVERLAP_OK(w,prop) (w) > ( \
36 prop->slant >= rxvt_fontprop::italic \
37 ? (prop->width * MAX_OVERLAP_ITALIC + 7) >> 3 \
38 : (prop->width * MAX_OVERLAP_ROMAN + 7) >> 3 \
39 )
36 40
37const struct rxvt_fallback_font { 41const struct rxvt_fallback_font {
38 codeset cs; 42 codeset cs;
39 const char *name; 43 const char *name;
40} fallback_fonts[] = { 44} fallback_fonts[] = {
153 0x304c, 0x672c, // が本 157 0x304c, 0x672c, // が本
154}; 158};
155 159
156#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) 160#define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0]))
157 161
162#define dTermDisplay Display *disp = term->display->display
163#define dTermGC GC gc = term->gc
164
158///////////////////////////////////////////////////////////////////////////// 165/////////////////////////////////////////////////////////////////////////////
159 166
160#if XFT 167#if XFT
161rxvt_drawable::~rxvt_drawable () 168rxvt_drawable::~rxvt_drawable ()
162{ 169{
165} 172}
166 173
167rxvt_drawable::operator XftDraw *() 174rxvt_drawable::operator XftDraw *()
168{ 175{
169 if (!xftdrawable) 176 if (!xftdrawable)
170 xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap); 177 xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap);
171 178
172 return xftdrawable; 179 return xftdrawable;
173} 180}
174#endif 181#endif
175 182
176///////////////////////////////////////////////////////////////////////////// 183/////////////////////////////////////////////////////////////////////////////
177
178static void *enc_buf;
179static uint32_t enc_len;
180
181static inline void *
182get_enc_buf (uint32_t len)
183{
184 if (len > enc_len)
185 {
186 free (enc_buf);
187 enc_buf = malloc (len);
188 enc_len = len;
189 }
190
191 return enc_buf;
192}
193 184
194static const char * 185static const char *
195enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) 186enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero)
196{ 187{
197 uint8_t *buf = (uint8_t *)get_enc_buf (len); 188 uint8_t *buf = rxvt_temp_buf<uint8_t> (len);
189 uint8_t *res = buf;
198 190
199 while (len--) 191 while (len--)
200 { 192 {
201 uint32_t c = FROM_UNICODE (cs, *text++); 193 uint32_t c = FROM_UNICODE (cs, *text++);
202 194
207 } 199 }
208 200
209 *buf++ = c; 201 *buf++ = c;
210 } 202 }
211 203
212 return (const char *)enc_buf; 204 return (const char *)res;
213} 205}
214 206
215static const XChar2b * 207static const XChar2b *
216enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) 208enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
217{ 209{
218 XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); 210 XChar2b *buf = rxvt_temp_buf<XChar2b> (len);
211 XChar2b *res = buf;
219 212
220 while (len--) 213 while (len--)
221 { 214 {
222 uint32_t c = FROM_UNICODE (cs, *text++); 215 uint32_t c = FROM_UNICODE (cs, *text++);
223 216
230 buf->byte1 = c >> 8; 223 buf->byte1 = c >> 8;
231 buf->byte2 = c; 224 buf->byte2 = c;
232 buf++; 225 buf++;
233 } 226 }
234 227
235 return (XChar2b *)enc_buf; 228 return res;
236} 229}
237 230
238///////////////////////////////////////////////////////////////////////////// 231/////////////////////////////////////////////////////////////////////////////
239 232
240void 233void
246 if (this->name) free (this->name); // let the compiler optimize 239 if (this->name) free (this->name); // let the compiler optimize
247 this->name = name; 240 this->name = name;
248} 241}
249 242
250void 243void
251rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) 244rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
252{ 245{
246 dTermDisplay;
247 dTermGC;
248
253 if (color == Color_bg) 249 if (color == Color_bg)
254 XClearArea (d.display->display, d, x, y, w, h, FALSE); 250 XClearArea (disp, d, x, y, w, h, FALSE);
255 else if (color >= 0) 251 else if (color >= 0)
256 { 252 {
257#if XFT 253#if XFT
258 XftDrawRect (d, &r->pix_colors[color].c, x, y, w, h); 254 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
259#else 255#else
260 XSetForeground (d.display->display, TGC, r->pix_colors[color]); 256 XSetForeground (disp, gc, term->pix_colors[color]);
261 XFillRectangle (d.display->display, d, TGC, x, y, w, h); 257 XFillRectangle (disp, d, gc, x, y, w, h);
262#endif 258#endif
263 } 259 }
264} 260}
265 261
266#include "table/linedraw.h" 262#include "table/linedraw.h"
294 set_name (strdup ("built-in support font")); 290 set_name (strdup ("built-in support font"));
295 291
296 return true; 292 return true;
297 } 293 }
298 294
299 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 295 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
300 { 296 {
301 careful = false; 297 careful = false;
302 298
303 if (unicode <= 0x001f) 299 if (unicode <= 0x001f)
304 return true; 300 return true;
308 304
309 if (unicode <= 0x009f) 305 if (unicode <= 0x009f)
310 return true; 306 return true;
311 307
312 if (unicode >= 0x2500 && unicode <= 0x259f && 308 if (unicode >= 0x2500 && unicode <= 0x259f &&
313 !r->option (Opt_skipBuiltinGlyphs)) 309 !term->option (Opt_skipBuiltinGlyphs))
314 return true; 310 return true;
315 311
316 if (IS_COMPOSE (unicode)) 312 if (IS_COMPOSE (unicode))
317 return true; 313 return true;
318 314
334void 330void
335rxvt_font_default::draw (rxvt_drawable &d, int x, int y, 331rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
336 const text_t *text, int len, 332 const text_t *text, int len,
337 int fg, int bg) 333 int fg, int bg)
338{ 334{
339 Display *disp = d.display->display; 335 dTermDisplay;
336 dTermGC;
340 337
341 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 338 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
342 339
343 XSetForeground (disp, TGC, r->pix_colors[fg]); 340 XSetForeground (disp, gc, term->pix_colors[fg]);
344 341
345 while (len) 342 while (len)
346 { 343 {
347#if ENABLE_COMBINING 344#if ENABLE_COMBINING
348 compose_char *cc; 345 compose_char *cc;
352 349
353 while (++text, --len && *text == NOCHAR) 350 while (++text, --len && *text == NOCHAR)
354 ; 351 ;
355 352
356 int width = text - tp; 353 int width = text - tp;
357 int fwidth = r->fwidth * width; 354 int fwidth = term->fwidth * width;
358 355
359 if (0x2500 <= t && t <= 0x259f) 356 if (0x2500 <= t && t <= 0x259f)
360 { 357 {
361 uint16_t offs = linedraw_offs[t - 0x2500]; 358 uint16_t offs = linedraw_offs[t - 0x2500];
362 uint32_t *a = linedraw_command + (offs >> 4); 359 uint32_t *a = linedraw_command + (offs >> 4);
363 uint32_t *b = a + (offs & 15); 360 uint32_t *b = a + (offs & 15);
364 361
365 int W = fwidth; 362 int W = fwidth;
366 int H = r->fheight; 363 int H = term->fheight;
367 364
368 int x_[16]; 365 int x_[16];
369 int y_[16]; 366 int y_[16];
370 367
371 for (int i = 0; i <= 8; i++) 368 for (int i = 0; i <= 8; i++)
379 376
380 XGCValues gcv; 377 XGCValues gcv;
381 378
382 gcv.cap_style = CapButt; 379 gcv.cap_style = CapButt;
383 gcv.line_width = 0; 380 gcv.line_width = 0;
384 XChangeGC (disp, TGC, GCLineWidth | GCCapStyle, &gcv); 381 XChangeGC (disp, gc, GCLineWidth | GCCapStyle, &gcv);
385 382
386 while (a < b) 383 while (a < b)
387 { 384 {
388 uint32_t command = *a++; 385 uint32_t command = *a++;
389 386
396 int y2 = y_[(command >> 0) & 15]; 393 int y2 = y_[(command >> 0) & 15];
397 394
398 switch (op) 395 switch (op)
399 { 396 {
400 case 0: // line 397 case 0: // line
401 XDrawLine (disp, d, TGC, x1, y1, x2, y2); 398 XDrawLine (disp, d, gc, x1, y1, x2, y2);
402 break; 399 break;
403 400
404 case 1: // rectangle, possibly stippled 401 case 1: // rectangle, possibly stippled
405 if (a) 402 if (a)
406 { 403 {
409 gcv.fill_style = FillStippled; 406 gcv.fill_style = FillStippled;
410 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 407 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
411 gcv.ts_x_origin = x; 408 gcv.ts_x_origin = x;
412 gcv.ts_y_origin = y; 409 gcv.ts_y_origin = y;
413 410
414 XChangeGC (disp, TGC, 411 XChangeGC (disp, gc,
415 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin, 412 GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin,
416 &gcv); 413 &gcv);
417 } 414 }
418 415
419 XFillRectangle (disp, d, TGC, x1, y1, x2 - x1 + 1, y2 - y1 + 1); 416 XFillRectangle (disp, d, gc, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
420 417
421 if (a) 418 if (a)
422 { 419 {
423 XFreePixmap (disp, gcv.stipple); 420 XFreePixmap (disp, gcv.stipple);
424 gcv.stipple = 0; 421 gcv.stipple = 0;
425 gcv.fill_style = FillSolid; 422 gcv.fill_style = FillSolid;
426 XChangeGC (disp, TGC, GCFillStyle, &gcv); 423 XChangeGC (disp, gc, GCFillStyle, &gcv);
427 } 424 }
428 break; 425 break;
429 case 2: // arc 426 case 2: // arc
430 XDrawArc (disp, d, TGC, 427 XDrawArc (disp, d, gc,
431 x1 - W/2, y1 - H/2, W-1, H-1, 428 x1 - W/2, y1 - H/2, W-1, H-1,
432 (a - 1) * 90*64, (b - 1) * 90*64); 429 (a - 1) * 90*64, (b - 1) * 90*64);
433 break; 430 break;
434 } 431 }
435 } 432 }
466 case ZERO_WIDTH_CHAR: 463 case ZERO_WIDTH_CHAR:
467 case NOCHAR: 464 case NOCHAR:
468 break; 465 break;
469 466
470 default: 467 default:
471 XDrawRectangle (disp, d, TGC, x + 2, y + 2, 468 XDrawRectangle (disp, d, gc, x + 2, y + 2,
472 fwidth - 4, r->fheight - 4); 469 fwidth - 4, term->fheight - 4);
473 } 470 }
474 471
475 x += fwidth; 472 x += fwidth;
476 } 473 }
477} 474}
485 482
486 rxvt_fontprop properties (); 483 rxvt_fontprop properties ();
487 484
488 bool load (const rxvt_fontprop &prop); 485 bool load (const rxvt_fontprop &prop);
489 486
490 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful); 487 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const;
491 488
492 void draw (rxvt_drawable &d, int x, int y, 489 void draw (rxvt_drawable &d, int x, int y,
493 const text_t *text, int len, 490 const text_t *text, int len,
494 int fg, int bg); 491 int fg, int bg);
495 492
507char * 504char *
508rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const 505rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const
509{ 506{
510 unsigned long value; 507 unsigned long value;
511 508
512 if (XGetFontProperty (f, XInternAtom (DISPLAY, property, 0), &value)) 509 if (XGetFontProperty (f, XInternAtom (term->display->display, property, 0), &value))
513 return XGetAtomName (DISPLAY, value); 510 return XGetAtomName (term->display->display, value);
514 else 511 else
515 return rxvt_strdup (repl); 512 return rxvt_strdup (repl);
516} 513}
517 514
518rxvt_fontprop 515rxvt_fontprop
539rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) 536rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f)
540{ 537{
541 unsigned long height; 538 unsigned long height;
542 539
543#if 0 540#if 0
544 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) 541 if (!XGetFontProperty (f, XInternAtom (term->display->display, "PIXEL_SIZE", 0), &height))
545 return false; 542 return false;
546#else 543#else
547 height = f->ascent + f->descent; 544 height = f->ascent + f->descent;
548#endif 545#endif
549 546
550 unsigned long avgwidth; 547 unsigned long avgwidth;
551 if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) 548 if (!XGetFontProperty (f, XInternAtom (term->display->display, "AVERAGE_WIDTH", 0), &avgwidth))
552 avgwidth = 0; 549 avgwidth = 0;
553 550
554 char *weight = get_property (f, "WEIGHT_NAME", "medium"); 551 char *weight = get_property (f, "WEIGHT_NAME", "medium");
555 char *slant = get_property (f, "SLANT", "r"); 552 char *slant = get_property (f, "SLANT", "r");
556 553
565} 562}
566 563
567bool 564bool
568rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) 565rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name)
569{ 566{
567 dTermDisplay;
570 int slashes = 0; 568 int slashes = 0;
571 const char *comp[13]; 569 const char *comp[13];
572 570
573 for (const char *c = name; *c; c++) 571 for (const char *c = name; *c; c++)
574 if (*c == '-') 572 if (*c == '-')
582 if (slashes >= 13 580 if (slashes >= 13
583 && (*comp[ 6] >= '1' && *comp[ 6] <= '9') 581 && (*comp[ 6] >= '1' && *comp[ 6] <= '9')
584 && (*comp[11] >= '0' && *comp[11] <= '9')) 582 && (*comp[11] >= '0' && *comp[11] <= '9'))
585 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); 583 return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11]));
586 584
587 XFontStruct *f = XLoadQueryFont (DISPLAY, name); 585 XFontStruct *f = XLoadQueryFont (disp, name);
588 586
589 if (f) 587 if (f)
590 { 588 {
591 // the font should really exist now. if not, we have a problem 589 // the font should really exist now. if not, we have a problem
592 // (e.g. if the user did xset fp rehash just when we were searching fonts). 590 // (e.g. if the user did xset fp rehash just when we were searching fonts).
593 // in that case, just return garbage. 591 // in that case, just return garbage.
594 bool ret = set_properties (p, f); 592 bool ret = set_properties (p, f);
595 XFreeFont (DISPLAY, f); 593 XFreeFont (disp, f);
596 return ret; 594 return ret;
597 } 595 }
598 else 596 else
599 return false; 597 return false;
600} 598}
638} 636}
639 637
640bool 638bool
641rxvt_font_x11::load (const rxvt_fontprop &prop) 639rxvt_font_x11::load (const rxvt_fontprop &prop)
642{ 640{
643 Display *disp = DISPLAY; 641 dTermDisplay;
644 642
645 clear (); 643 clear ();
646 644
647 char field_str[64]; // enough for 128 bits 645 char field_str[64]; // enough for 128 bits
648 646
723 int diff = 0; 721 int diff = 0;
724 722
725 if (replace_field (fname, list[i], 6, '0', field_str)) 723 if (replace_field (fname, list[i], 6, '0', field_str))
726 diff += 10; // slightly penalize scalable fonts 724 diff += 10; // slightly penalize scalable fonts
727 else if (replace_field (fname, list[i], 11, '0', "0")) 725 else if (replace_field (fname, list[i], 11, '0', "0"))
728 diff += 300; // more heavily penalize what looks like scaled bitmap fotns 726 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
729 727
730 if (!set_properties (p, fname)) 728 if (!set_properties (p, fname))
731 continue; 729 continue;
732 730
733 if (prop.height != rxvt_fontprop::unset 731 if (prop.height != rxvt_fontprop::unset
857 855
858 XCharStruct g; 856 XCharStruct g;
859 int dir_ret, asc_ret, des_ret; 857 int dir_ret, asc_ret, des_ret;
860 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 858 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
861 859
862 int wcw = wcwidth (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 860 int wcw = WCWIDTH (*t); if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
863 861
864 if (width < g.width) width = g.width; 862 if (width < g.width) width = g.width;
865 } 863 }
866 864
867 if (cs == CS_UNKNOWN) 865 if (cs == CS_UNKNOWN)
886void 884void
887rxvt_font_x11::clear () 885rxvt_font_x11::clear ()
888{ 886{
889 if (f) 887 if (f)
890 { 888 {
891 XFreeFont (DISPLAY, f); 889 XFreeFont (term->display->display, f);
892 f = 0; 890 f = 0;
893 } 891 }
894} 892}
895 893
896bool 894bool
897rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 895rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
898{ 896{
899 uint32_t ch = FROM_UNICODE (cs, unicode); 897 uint32_t ch = FROM_UNICODE (cs, unicode);
900 898
901 if (ch == NOCHAR) 899 if (ch == NOCHAR)
902 return false; 900 return false;
940 938
941 if (!prop || prop->width == rxvt_fontprop::unset) 939 if (!prop || prop->width == rxvt_fontprop::unset)
942 return true; 940 return true;
943 941
944 // check character against base font bounding box 942 // check character against base font bounding box
945 int w = xcs->width; 943 int w = xcs->rbearing - xcs->lbearing;
946 int wcw = wcwidth (unicode); 944 int wcw = WCWIDTH (unicode);
947 if (wcw > 0) w = (w + wcw - 1) / wcw; 945 if (wcw > 0) w = (w + wcw - 1) / wcw;
948 946
949 careful = w > prop->width; 947 careful = w > prop->width;
950 if (careful && w > prop->width * MAX_OVERLAP >> 2) 948 if (careful && OVERLAP_OK (w, prop))
951 return false; 949 return false;
952 950
953 return true; 951 return true;
954} 952}
955 953
961 // this looks like a mess /. 959 // this looks like a mess /.
962 // and it is a mess /. 960 // and it is a mess /.
963 // yet we are trying to be perfect /. 961 // yet we are trying to be perfect /.
964 // but the result still isn't perfect /. 962 // but the result still isn't perfect /.
965 963
964 dTermDisplay;
965 dTermGC;
966
966 bool slow = this->slow 967 bool slow = this->slow
967 || width != r->fwidth 968 || width != term->fwidth
968 || height != r->fheight; 969 || height != term->fheight;
969 970
970 int base = ascent; // sorry, incorrect: r->fbase; 971 int base = ascent; // sorry, incorrect: term->fbase;
971 972
972 XGCValues v; 973 XGCValues v;
973 v.foreground = r->pix_colors[fg]; 974 v.foreground = term->pix_colors[fg];
974 v.font = f->fid; 975 v.font = f->fid;
975 976
976 if (enc2b) 977 if (enc2b)
977 { 978 {
978 const XChar2b *xc = enc_xchar2b (text, len, cs, slow); 979 const XChar2b *xc = enc_xchar2b (text, len, cs, slow);
979 980
980 if (bg == Color_bg && !slow) 981 if (bg == Color_bg && !slow)
981 { 982 {
982 v.background = r->pix_colors[bg]; 983 v.background = term->pix_colors[bg];
983 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 984 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
984 XDrawImageString16 (d.display->display, d, TGC, x, y + base, xc, len); 985 XDrawImageString16 (disp, d, gc, x, y + base, xc, len);
985 } 986 }
986 else 987 else
987 { 988 {
988 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 989 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
989 990
990 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 991 XChangeGC (disp, gc, GCForeground | GCFont, &v);
991 992
992 if (slow) 993 if (slow)
993 { 994 {
994 do 995 do
995 { 996 {
996 if (xc->byte1 || xc->byte2) 997 if (xc->byte1 || xc->byte2)
997 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, 1); 998 XDrawString16 (disp, d, gc, x, y + base, xc, 1);
998 999
999 x += r->fwidth; 1000 x += term->fwidth;
1000 xc++; len--; 1001 xc++; len--;
1001 } 1002 }
1002 while (len); 1003 while (len);
1003 } 1004 }
1004 else 1005 else
1005 XDrawString16 (d.display->display, d, TGC, x, y + base, xc, len); 1006 XDrawString16 (disp, d, gc, x, y + base, xc, len);
1006 } 1007 }
1007 } 1008 }
1008 else 1009 else
1009 { 1010 {
1010 const char *xc = enc_char (text, len, cs, slow); 1011 const char *xc = enc_char (text, len, cs, slow);
1011 1012
1012 if (bg == Color_bg && !slow) 1013 if (bg == Color_bg && !slow)
1013 { 1014 {
1014 v.background = r->pix_colors[bg]; 1015 v.background = term->pix_colors[bg];
1015 XChangeGC (d.display->display, TGC, GCForeground | GCBackground | GCFont, &v); 1016 XChangeGC (disp, gc, GCForeground | GCBackground | GCFont, &v);
1016 XDrawImageString (d.display->display, d, TGC, x, y + base, xc, len); 1017 XDrawImageString (disp, d, gc, x, y + base, xc, len);
1017 } 1018 }
1018 else 1019 else
1019 { 1020 {
1020 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1021 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1021 1022
1022 XChangeGC (d.display->display, TGC, GCForeground | GCFont, &v); 1023 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1023 1024
1024 if (slow) 1025 if (slow)
1025 { 1026 {
1026 do 1027 do
1027 { 1028 {
1028 if (*xc) 1029 if (*xc)
1029 XDrawString (d.display->display, d, TGC, x, y + base, xc, 1); 1030 XDrawString (disp, d, gc, x, y + base, xc, 1);
1030 1031
1031 x += r->fwidth; 1032 x += term->fwidth;
1032 xc++; len--; 1033 xc++; len--;
1033 } 1034 }
1034 while (len); 1035 while (len);
1035 } 1036 }
1036 else 1037 else
1037 XDrawString (d.display->display, d, TGC, x, y + base, xc, len); 1038 XDrawString (disp, d, gc, x, y + base, xc, len);
1038 } 1039 }
1039 } 1040 }
1040} 1041}
1041 1042
1042///////////////////////////////////////////////////////////////////////////// 1043/////////////////////////////////////////////////////////////////////////////
1054 1055
1055 void draw (rxvt_drawable &d, int x, int y, 1056 void draw (rxvt_drawable &d, int x, int y,
1056 const text_t *text, int len, 1057 const text_t *text, int len,
1057 int fg, int bg); 1058 int fg, int bg);
1058 1059
1059 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull); 1060 bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const;
1060 1061
1061protected: 1062protected:
1062 XftFont *f; 1063 XftFont *f;
1063}; 1064};
1064 1065
1065void 1066void
1066rxvt_font_xft::clear () 1067rxvt_font_xft::clear ()
1067{ 1068{
1068 if (f) 1069 if (f)
1069 { 1070 {
1070 XftFontClose (DISPLAY, f); 1071 XftFontClose (term->display->display, f);
1071 f = 0; 1072 f = 0;
1072 } 1073 }
1073} 1074}
1074 1075
1075rxvt_fontprop 1076rxvt_fontprop
1093} 1094}
1094 1095
1095bool 1096bool
1096rxvt_font_xft::load (const rxvt_fontprop &prop) 1097rxvt_font_xft::load (const rxvt_fontprop &prop)
1097{ 1098{
1098 Display *disp = DISPLAY; 1099 dTermDisplay;
1099 1100
1100 clear (); 1101 clear ();
1101 1102
1102 FcPattern *p = FcNameParse ((FcChar8 *) name); 1103 FcPattern *p = FcNameParse ((FcChar8 *) name);
1103 1104
1130 1131
1131 // store generated name so iso14755 view gives better results 1132 // store generated name so iso14755 view gives better results
1132 set_name ((char *)FcNameUnparse (p)); 1133 set_name ((char *)FcNameUnparse (p));
1133 1134
1134 XftResult result; 1135 XftResult result;
1135 FcPattern *match = XftFontMatch (disp, r->display->screen, p, &result); 1136 FcPattern *match = XftFontMatch (disp, term->display->screen, p, &result);
1136 1137
1137 FcPatternDestroy (p); 1138 FcPatternDestroy (p);
1138 1139
1139 if (!match) 1140 if (!match)
1140 return false; 1141 return false;
1182 XGlyphInfo g; 1183 XGlyphInfo g;
1183 XftTextExtents16 (disp, f, &ch, 1, &g); 1184 XftTextExtents16 (disp, f, &ch, 1, &g);
1184 1185
1185 g.width -= g.x; 1186 g.width -= g.x;
1186 1187
1187 int wcw = wcwidth (ch); 1188 int wcw = WCWIDTH (ch);
1188 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; 1189 if (wcw > 0) g.width = (g.width + wcw - 1) / wcw;
1189 1190
1190 if (width < g.width ) width = g.width; 1191 if (width < g.width ) width = g.width;
1191 if (height < g.height ) height = g.height; 1192 if (height < g.height ) height = g.height;
1192 if (glheight < g.height - g.y) glheight = g.height - g.y; 1193 if (glheight < g.height - g.y) glheight = g.height - g.y;
1238 1239
1239 return success; 1240 return success;
1240} 1241}
1241 1242
1242bool 1243bool
1243rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) 1244rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
1244{ 1245{
1245 careful = false; 1246 careful = false;
1246 1247
1247 if (!XftCharExists (DISPLAY, f, unicode)) 1248 if (!XftCharExists (term->display->display, f, unicode))
1248 return false; 1249 return false;
1249 1250
1250 if (!prop || prop->width == rxvt_fontprop::unset) 1251 if (!prop || prop->width == rxvt_fontprop::unset)
1251 return true; 1252 return true;
1252 1253
1253 // check character against base font bounding box 1254 // check character against base font bounding box
1254 FcChar32 ch = unicode; 1255 FcChar32 ch = unicode;
1255 XGlyphInfo g; 1256 XGlyphInfo g;
1256 XftTextExtents32 (DISPLAY, f, &ch, 1, &g); 1257 XftTextExtents32 (term->display->display, f, &ch, 1, &g);
1257 1258
1258 int w = g.width - g.x; 1259 int w = g.width - g.x;
1259 int wcw = wcwidth (unicode); 1260 int wcw = WCWIDTH (unicode);
1260 if (wcw > 0) w = (w + wcw - 1) / wcw; 1261 if (wcw > 0) w = (w + wcw - 1) / wcw;
1261 1262
1262 careful = w > prop->width; 1263 careful = w > prop->width;
1263 if (careful && w > prop->width * MAX_OVERLAP >> 2) 1264 if (careful && OVERLAP_OK (w, prop))
1264 return false; 1265 return false;
1265 1266
1266 return true; 1267 return true;
1267} 1268}
1268 1269
1269void 1270void
1270rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, 1271rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
1271 const text_t *text, int len, 1272 const text_t *text, int len,
1272 int fg, int bg) 1273 int fg, int bg)
1273{ 1274{
1275 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1276
1274 XGlyphInfo extents; 1277 XGlyphInfo extents;
1275 XftGlyphSpec *enc = (XftGlyphSpec *)get_enc_buf (len * sizeof (XftGlyphSpec)); 1278 XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec));
1276 XftGlyphSpec *ep = enc; 1279 XftGlyphSpec *ep = enc;
1277 1280
1278 clear_rect (d, x, y, r->fwidth * len, r->fheight, bg); 1281 dTermDisplay;
1282 dTermGC;
1279 1283
1280 // cut trailing spaces 1284 // cut trailing spaces
1281 while (len && text [len - 1] == ' ') 1285 while (len && text [len - 1] == ' ')
1282 len--; 1286 len--;
1283 1287
1284 while (len) 1288 while (len)
1285 { 1289 {
1286 int cwidth = r->fwidth; 1290 int cwidth = term->fwidth;
1287 FcChar32 fc = *text++; len--; 1291 FcChar32 fc = *text++; len--;
1288 1292
1289 while (len && *text == NOCHAR) 1293 while (len && *text == NOCHAR)
1290 text++, len--, cwidth += r->fwidth; 1294 text++, len--, cwidth += term->fwidth;
1291 1295
1292 if (fc != ' ') // skip spaces 1296 if (fc != ' ') // skip spaces
1293 { 1297 {
1294 FT_UInt glyph = XftCharIndex (d.display->display, f, fc); 1298 FT_UInt glyph = XftCharIndex (disp, f, fc);
1295 XftGlyphExtents (d.display->display, f, &glyph, 1, &extents); 1299 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1296 1300
1297 ep->glyph = glyph; 1301 ep->glyph = glyph;
1298 ep->x = x + (cwidth - extents.xOff >> 1); 1302 ep->x = x + (cwidth - extents.xOff >> 1);
1299 ep->y = y + ascent; 1303 ep->y = y + ascent;
1300 ep++; 1304 ep++;
1302 1306
1303 x += cwidth; 1307 x += cwidth;
1304 } 1308 }
1305 1309
1306 if (ep != enc) 1310 if (ep != enc)
1307 XftDrawGlyphSpec (d, &r->pix_colors[fg].c, f, enc, ep - enc); 1311 XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc);
1308} 1312}
1309#endif 1313#endif
1310 1314
1311///////////////////////////////////////////////////////////////////////////// 1315/////////////////////////////////////////////////////////////////////////////
1312 1316
1313rxvt_fontset::rxvt_fontset (rxvt_t r) 1317rxvt_fontset::rxvt_fontset (rxvt_term *term)
1314: fontdesc (0), r (r) 1318: fontdesc (0), term (term)
1315{ 1319{
1316 clear (); 1320 clear ();
1317} 1321}
1318 1322
1319rxvt_fontset::~rxvt_fontset () 1323rxvt_fontset::~rxvt_fontset ()
1363 f = new rxvt_font_x11; 1367 f = new rxvt_font_x11;
1364 } 1368 }
1365 else 1369 else
1366 f = new rxvt_font_x11; 1370 f = new rxvt_font_x11;
1367 1371
1368 f->set_term (r); 1372 f->set_term (term);
1369 f->set_name (strdup (name)); 1373 f->set_name (strdup (name));
1370 1374
1371 f->cs = cs; 1375 f->cs = cs;
1372 f->loaded = false; 1376 f->loaded = false;
1373 1377
1556 FcPatternAddInteger (p, FC_SLANT, prop.slant); 1560 FcPatternAddInteger (p, FC_SLANT, prop.slant);
1557 FcPatternAddBool (p, FC_MINSPACE, 1); 1561 FcPatternAddBool (p, FC_MINSPACE, 1);
1558 //FcPatternAddBool (p, FC_ANTIALIAS, 1); 1562 //FcPatternAddBool (p, FC_ANTIALIAS, 1);
1559 1563
1560 XftResult result; 1564 XftResult result;
1561 FcPattern *match = XftFontMatch (DISPLAY, r->display->screen, p, &result); 1565 FcPattern *match = XftFontMatch (term->display->display, term->display->screen, p, &result);
1562 1566
1563 FcPatternDestroy (p); 1567 FcPatternDestroy (p);
1564 1568
1565 if (match) 1569 if (match)
1566 { 1570 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines