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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines