… | |
… | |
23 | #include "rxvt.h" |
23 | #include "rxvt.h" |
24 | #include "defaultfont.h" |
24 | #include "defaultfont.h" |
25 | |
25 | |
26 | #include <cstdlib> |
26 | #include <cstdlib> |
27 | |
27 | |
28 | #define DISPLAY r->Xdisplay |
28 | #define DISPLAY r->display->display |
29 | #define DRAWABLE r->TermWin.vt |
29 | #define DRAWABLE r->TermWin.vt |
30 | #define GC r->TermWin.gc |
30 | #define GC r->TermWin.gc |
31 | |
31 | |
32 | const struct rxvt_fallback_font { |
32 | const struct rxvt_fallback_font { |
33 | codeset cs; |
33 | codeset cs; |
… | |
… | |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
73 | { CS_BIG5_EXT, "xft:AR PL Mingti2L Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
74 | { CS_BIG5_EXT, "xft:AR PL KaitiM Big5" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
75 | { CS_GB2312_1980_0, "xft:AR PL KaitiM GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
76 | { CS_GB2312_1980_0, "xft:AR PL SungtiL GB" }, |
77 | # endif |
77 | # endif |
|
|
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-gb2312*-0" }, |
78 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-1" }, |
79 | { CS_CNS11643_1992_1, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-1" }, |
79 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-2" }, |
80 | { CS_CNS11643_1992_2, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-2" }, |
80 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-3" }, |
81 | { CS_CNS11643_1992_3, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-3" }, |
81 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-4" }, |
82 | { CS_CNS11643_1992_4, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-4" }, |
82 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-5" }, |
83 | { CS_CNS11643_1992_5, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-5" }, |
83 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-6" }, |
84 | { CS_CNS11643_1992_6, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-6" }, |
84 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-7" }, |
85 | { CS_CNS11643_1992_7, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-7" }, |
85 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643.1992-f" }, |
86 | { CS_CNS11643_1992_F, "-*-*-*-*-*-*-*-*-*-*-c-*-cns11643*-f" }, |
86 | #endif |
87 | #endif |
87 | |
88 | |
88 | #if XFT |
89 | #if XFT |
89 | { CS_UNICODE, "xft:Andale Mono" }, |
90 | { CS_UNICODE, "xft:Andale Mono" }, |
90 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
91 | { CS_UNICODE, "xft:Arial Unicode MS" }, |
… | |
… | |
102 | |
103 | |
103 | static void *enc_buf; |
104 | static void *enc_buf; |
104 | static uint32_t enc_len; |
105 | static uint32_t enc_len; |
105 | |
106 | |
106 | static inline void * |
107 | static inline void * |
107 | get_enc_buf (int len) |
108 | get_enc_buf (uint32_t len) |
108 | { |
109 | { |
109 | if (len > enc_len) |
110 | if (len > enc_len) |
110 | { |
111 | { |
111 | free (enc_buf); |
112 | free (enc_buf); |
112 | enc_buf = malloc (len); |
113 | enc_buf = malloc (len); |
… | |
… | |
114 | |
115 | |
115 | return enc_buf; |
116 | return enc_buf; |
116 | } |
117 | } |
117 | |
118 | |
118 | static const char * |
119 | static const char * |
119 | enc_char (const text_t *text, int len, codeset cs, bool &zero) |
120 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
120 | { |
121 | { |
121 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
122 | uint8_t *buf = (uint8_t *)get_enc_buf (len); |
122 | |
123 | |
123 | while (len--) |
124 | while (len--) |
124 | { |
125 | { |
… | |
… | |
135 | |
136 | |
136 | return (const char *)enc_buf; |
137 | return (const char *)enc_buf; |
137 | } |
138 | } |
138 | |
139 | |
139 | static const XChar2b * |
140 | static const XChar2b * |
140 | enc_xchar2b (const text_t *text, int len, codeset cs, bool &zero) |
141 | enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero) |
141 | { |
142 | { |
142 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
143 | XChar2b *buf = (XChar2b *)get_enc_buf (len * sizeof (XChar2b)); |
143 | |
144 | |
144 | while (len--) |
145 | while (len--) |
145 | { |
146 | { |
… | |
… | |
227 | struct rxvt_font_default : rxvt_font { |
228 | struct rxvt_font_default : rxvt_font { |
228 | rxvt_fontprop properties () |
229 | rxvt_fontprop properties () |
229 | { |
230 | { |
230 | rxvt_fontprop p; |
231 | rxvt_fontprop p; |
231 | |
232 | |
232 | p.height = 1; |
233 | p.width = p.height = 1; |
233 | p.weight = rxvt_fontprop::medium; |
234 | p.weight = rxvt_fontprop::medium; |
234 | p.slant = rxvt_fontprop::roman; |
235 | p.slant = rxvt_fontprop::roman; |
235 | |
236 | |
236 | return p; |
237 | return p; |
237 | } |
238 | } |
… | |
… | |
337 | rxvt_font_x11 () { f = 0; } |
338 | rxvt_font_x11 () { f = 0; } |
338 | |
339 | |
339 | void clear (); |
340 | void clear (); |
340 | |
341 | |
341 | rxvt_fontprop properties (); |
342 | rxvt_fontprop properties (); |
342 | rxvt_fontprop properties (XFontStruct *f); |
|
|
343 | |
343 | |
344 | bool load (const rxvt_fontprop &prop); |
344 | bool load (const rxvt_fontprop &prop); |
345 | |
345 | |
346 | bool has_codepoint (uint32_t unicode); |
346 | bool has_codepoint (uint32_t unicode); |
347 | |
347 | |
… | |
… | |
352 | XFontStruct *f; |
352 | XFontStruct *f; |
353 | codeset cs; |
353 | codeset cs; |
354 | bool enc2b, encm; |
354 | bool enc2b, encm; |
355 | |
355 | |
356 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
356 | const char *get_property (XFontStruct *f, const char *property, const char *repl) const; |
|
|
357 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
|
|
358 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
|
|
359 | bool set_properties (rxvt_fontprop &p, const char *name); |
357 | }; |
360 | }; |
358 | |
361 | |
359 | const char * |
362 | const char * |
360 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
363 | rxvt_font_x11::get_property (XFontStruct *f, const char *property, const char *repl) const |
361 | { |
364 | { |
… | |
… | |
368 | } |
371 | } |
369 | |
372 | |
370 | rxvt_fontprop |
373 | rxvt_fontprop |
371 | rxvt_font_x11::properties () |
374 | rxvt_font_x11::properties () |
372 | { |
375 | { |
373 | return properties (f); |
|
|
374 | } |
|
|
375 | |
|
|
376 | rxvt_fontprop |
|
|
377 | rxvt_font_x11::properties (XFontStruct *f) |
|
|
378 | { |
|
|
379 | rxvt_fontprop p; |
376 | rxvt_fontprop p; |
|
|
377 | set_properties (p, f); |
|
|
378 | return p; |
|
|
379 | } |
380 | |
380 | |
|
|
381 | bool |
|
|
382 | rxvt_font_x11::set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth) |
|
|
383 | { |
|
|
384 | p.width = avgwidth ? (avgwidth + 1) / 10 : (height + 1) / 2; |
|
|
385 | p.height = height; |
|
|
386 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
|
|
387 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
|
|
388 | |
|
|
389 | return true; |
|
|
390 | } |
|
|
391 | |
|
|
392 | bool |
|
|
393 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
|
|
394 | { |
381 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
395 | const char *weight = get_property (f, "WEIGHT_NAME", "medium"); |
382 | const char *slant = get_property (f, "SLANT", "r"); |
396 | const char *slant = get_property (f, "SLANT", "r"); |
383 | |
397 | |
384 | p.height = height; |
398 | unsigned long height; |
385 | p.weight = *weight == 'B' || *weight == 'b' ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
399 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "PIXEL_SIZE", 0), &height)) |
386 | p.slant = *slant == 'r' || *slant == 'R' ? rxvt_fontprop::roman : rxvt_fontprop::italic; |
400 | return false; |
387 | |
401 | |
388 | return p; |
402 | unsigned long avgwidth; |
|
|
403 | if (!XGetFontProperty (f, XInternAtom (DISPLAY, "AVERAGE_WIDTH", 0), &avgwidth)) |
|
|
404 | avgwidth = 0; |
|
|
405 | |
|
|
406 | return set_properties (p, height, weight, slant, avgwidth); |
|
|
407 | } |
|
|
408 | |
|
|
409 | bool |
|
|
410 | rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) |
|
|
411 | { |
|
|
412 | int slashes = 0; |
|
|
413 | const char *comp[12]; |
|
|
414 | |
|
|
415 | for (const char *c = name; *c; c++) |
|
|
416 | if (*c == '-') |
|
|
417 | { |
|
|
418 | comp[slashes++] = c + 1; |
|
|
419 | if (slashes >= 13) |
|
|
420 | break; |
|
|
421 | } |
|
|
422 | |
|
|
423 | /* can we short-circuit the costly XLoadQueryFont? */ |
|
|
424 | if (slashes >= 13 |
|
|
425 | && (*comp[ 6] >= '1' && *comp[ 6] <= '9') |
|
|
426 | && (*comp[11] >= '0' && *comp[11] <= '9')) |
|
|
427 | return set_properties (p, atoi (comp[6]), comp[2], comp[3], atoi (comp[11])); |
|
|
428 | |
|
|
429 | XFontStruct *f = XLoadQueryFont (DISPLAY, name); |
|
|
430 | |
|
|
431 | if (f) |
|
|
432 | { |
|
|
433 | // the font should really exist now. if not, we have a problem |
|
|
434 | // (e.g. if the user did xset fp rehash just when we were searching fonts). |
|
|
435 | // in that case, just return garbage. |
|
|
436 | bool ret = set_properties (p, f); |
|
|
437 | XFreeFont (DISPLAY, f); |
|
|
438 | return ret; |
|
|
439 | } |
|
|
440 | else |
|
|
441 | return false; |
|
|
442 | } |
|
|
443 | |
|
|
444 | // fix the size of scalable fonts |
|
|
445 | static void |
|
|
446 | fix_scalable (char *buf, const char *name, const rxvt_fontprop &prop) |
|
|
447 | { |
|
|
448 | int slashes = 0; |
|
|
449 | const char *size; |
|
|
450 | |
|
|
451 | for (const char *c = name; *c; c++) |
|
|
452 | if (*c == '-') |
|
|
453 | { |
|
|
454 | if (slashes == 6) |
|
|
455 | size = c + 1; |
|
|
456 | |
|
|
457 | if (++slashes >= 13) |
|
|
458 | break; |
|
|
459 | } |
|
|
460 | |
|
|
461 | if (slashes >= 13 && size[0] == '0') |
|
|
462 | { |
|
|
463 | strncpy (buf, name, size - name); |
|
|
464 | buf += size - name; |
|
|
465 | buf += sprintf (buf, "%d", prop.height); |
|
|
466 | strcpy (buf, size + 1); |
|
|
467 | } |
|
|
468 | else |
|
|
469 | strcpy (buf, name); |
389 | } |
470 | } |
390 | |
471 | |
391 | bool |
472 | bool |
392 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
473 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
393 | { |
474 | { |
394 | clear (); |
475 | clear (); |
395 | |
476 | |
396 | char **list; |
477 | char **list; |
397 | int count; |
478 | int count; |
398 | XFontStruct *info; |
|
|
399 | list = XListFontsWithInfo (DISPLAY, name, 128, &count, &info); |
479 | list = XListFonts (DISPLAY, name, 512, &count); |
|
|
480 | set_name (0); |
400 | |
481 | |
401 | if (!list) |
482 | if (!list) |
402 | return false; |
483 | return false; |
403 | |
484 | |
404 | int bestdiff = 0x7fffffff; |
485 | int bestdiff = 0x7fffffff; |
405 | XFontStruct *best = 0; |
|
|
406 | for (int i = 0; i < count; i++) |
486 | for (int i = 0; i < count; i++) |
407 | { |
487 | { |
408 | XFontStruct *f = info + i; |
488 | rxvt_fontprop p; |
|
|
489 | char fname[1024]; |
|
|
490 | fix_scalable (fname, list[i], prop); |
409 | |
491 | |
|
|
492 | if (!set_properties (p, fname)) |
|
|
493 | continue; |
|
|
494 | |
410 | if (f->ascent + f->descent <= prop.height) // weed out too large fonts |
495 | if (p.height > prop.height) // weed out too large fonts |
411 | { |
496 | continue; |
412 | rxvt_fontprop p = properties (f); |
497 | |
413 | int diff = (prop.height - f->ascent + f->descent) * 32 |
498 | int diff = (prop.height - p.height) * 32 |
414 | + abs (prop.weight - p.weight) |
499 | + abs (prop.weight - p.weight) |
415 | + abs (prop.slant - p.slant ); |
500 | + abs (prop.slant - p.slant ); |
416 | |
501 | |
417 | if (!best // compare against best found so far |
502 | if (!name // compare against best found so far |
418 | || diff < bestdiff) |
503 | || diff < bestdiff) |
419 | { |
504 | { |
420 | best = f; |
505 | set_name (strdup (fname)); |
421 | bestdiff = diff; |
506 | bestdiff = diff; |
422 | } |
507 | } |
423 | } |
|
|
424 | } |
508 | } |
425 | |
509 | |
|
|
510 | XFreeFontNames (list); |
|
|
511 | |
426 | if (!best) |
512 | if (!name) |
427 | return false; |
513 | return false; |
428 | |
|
|
429 | set_name (strdup (list[best - info])); |
|
|
430 | |
|
|
431 | XFreeFontInfo (list, info, count); |
|
|
432 | |
514 | |
433 | f = XLoadQueryFont (DISPLAY, name); |
515 | f = XLoadQueryFont (DISPLAY, name); |
434 | |
516 | |
435 | if (!f) |
517 | if (!f) |
436 | return false; |
518 | return false; |
437 | |
|
|
438 | unsigned long value; |
|
|
439 | |
519 | |
440 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
520 | const char *registry = get_property (f, "CHARSET_REGISTRY", 0); |
441 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
521 | const char *encoding = get_property (f, "CHARSET_ENCODING", 0); |
442 | |
522 | |
443 | if (registry && encoding) |
523 | if (registry && encoding) |
… | |
… | |
530 | /* check wether the character exists in _this_ font. horrible. */ |
610 | /* check wether the character exists in _this_ font. horrible. */ |
531 | XCharStruct *xcs; |
611 | XCharStruct *xcs; |
532 | |
612 | |
533 | if (encm) |
613 | if (encm) |
534 | { |
614 | { |
535 | int byte1 = ch >> 8; |
615 | unsigned char byte1 = ch >> 8; |
536 | int byte2 = ch & 255; |
616 | unsigned char byte2 = ch & 255; |
537 | |
617 | |
538 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
618 | if (byte1 < f->min_byte1 || byte1 > f->max_byte1 |
539 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
619 | || byte2 < f->min_char_or_byte2 || byte2 > f->max_char_or_byte2) |
540 | return false; |
620 | return false; |
541 | |
621 | |
… | |
… | |
658 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
738 | //#define SWATHBITS (UNIBITS / 2 + 3) // minimum size for "full" tables |
659 | #define SWATHBITS 8 |
739 | #define SWATHBITS 8 |
660 | #endif |
740 | #endif |
661 | |
741 | |
662 | struct rxvt_font_xft : rxvt_font { |
742 | struct rxvt_font_xft : rxvt_font { |
663 | #if 0 |
|
|
664 | enum { |
|
|
665 | SWATHCOUNT = 1 << (21 - UNIBITS), |
|
|
666 | SWATHSIZE = 1 << (SWATHBITS - 5) |
|
|
667 | }; |
|
|
668 | typedef uint32_t swath[SWATHSIZE]; |
|
|
669 | |
|
|
670 | swath *cvr[SWATHCOUNT]; |
|
|
671 | #endif |
|
|
672 | |
|
|
673 | #if 0 |
|
|
674 | void gen_coverage_swath (unsigned int page); |
|
|
675 | |
|
|
676 | bool has_char (uint32_t ch) |
|
|
677 | { |
|
|
678 | unsigned int page = ch >> SWATHBITS; |
|
|
679 | unsigned int idx = ch & ((1 << SWATHBITS) - 1); |
|
|
680 | |
|
|
681 | if (page >= SWATHCOUNT) |
|
|
682 | return false; |
|
|
683 | |
|
|
684 | if (!cvr[page]) gen_coverage_swath (page); |
|
|
685 | |
|
|
686 | return cvr[page][idx >> 5] & (1 << (idx & 31)); |
|
|
687 | } |
|
|
688 | #endif |
|
|
689 | rxvt_font_xft () { f = 0; d = 0; } |
743 | rxvt_font_xft () { f = 0; d = 0; } |
690 | |
744 | |
691 | void clear (); |
745 | void clear (); |
692 | |
746 | |
693 | rxvt_fontprop properties (); |
747 | rxvt_fontprop properties (); |
… | |
… | |
701 | bool has_codepoint (uint32_t unicode); |
755 | bool has_codepoint (uint32_t unicode); |
702 | |
756 | |
703 | protected: |
757 | protected: |
704 | XftFont *f; |
758 | XftFont *f; |
705 | XftDraw *d; |
759 | XftDraw *d; |
706 | |
|
|
707 | #if 0 |
|
|
708 | virtual void populate_coverage_swath (uint32_t lo, uint32_t hi) = 0; |
|
|
709 | void set_swath (uint32_t ch) |
|
|
710 | { |
|
|
711 | cvr[ch >> SWATHBITS] |= 1 << (ch & ((1 << SWATHBITS) - 1)); |
|
|
712 | } |
|
|
713 | #endif |
|
|
714 | }; |
760 | }; |
715 | |
761 | |
716 | void |
762 | void |
717 | rxvt_font_xft::clear () |
763 | rxvt_font_xft::clear () |
718 | { |
764 | { |
|
|
765 | if (d) |
|
|
766 | { |
|
|
767 | XftDrawDestroy (d); |
|
|
768 | d = 0; |
|
|
769 | } |
|
|
770 | |
719 | if (f) |
771 | if (f) |
720 | { |
772 | { |
721 | XftFontClose (DISPLAY, f); |
773 | XftFontClose (DISPLAY, f); |
722 | f = 0; |
774 | f = 0; |
723 | } |
775 | } |
724 | |
|
|
725 | if (d) |
|
|
726 | { |
|
|
727 | XftDrawDestroy (d); |
|
|
728 | d = 0; |
|
|
729 | } |
|
|
730 | |
|
|
731 | #if 0 |
|
|
732 | for (int i = 0; i < SWATHCOUNT; i++) |
|
|
733 | delete cvr[i]; |
|
|
734 | #endif |
|
|
735 | } |
776 | } |
736 | |
777 | |
737 | rxvt_fontprop |
778 | rxvt_fontprop |
738 | rxvt_font_xft::properties () |
779 | rxvt_font_xft::properties () |
739 | { |
780 | { |
740 | rxvt_fontprop p; |
781 | rxvt_fontprop p; |
741 | |
782 | |
742 | FT_Face face = XftLockFace (f); |
783 | FT_Face face = XftLockFace (f); |
743 | |
784 | |
744 | p.height = height; |
785 | p.width = width; p.height = height; |
745 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
786 | p.weight = face->style_flags & FT_STYLE_FLAG_BOLD ? rxvt_fontprop::bold : rxvt_fontprop::medium; |
746 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
787 | p.slant = face->style_flags & FT_STYLE_FLAG_ITALIC ? rxvt_fontprop::italic : rxvt_fontprop::roman; |
747 | |
788 | |
748 | XftUnlockFace (f); |
789 | XftUnlockFace (f); |
749 | |
790 | |
… | |
… | |
771 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
812 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
772 | |
813 | |
773 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
814 | if (FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
774 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
815 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
775 | |
816 | |
|
|
817 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
|
|
818 | // clip width, we can't do better, or can we? |
|
|
819 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
|
|
820 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
|
|
821 | #endif |
|
|
822 | |
776 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
823 | //FcPatternAddBool (p, FC_MINSPACE, 1); |
777 | |
824 | |
778 | XftResult result; |
825 | XftResult result; |
779 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
826 | FcPattern *match = XftFontMatch (DISPLAY, DefaultScreen (DISPLAY), p, &result); |
780 | |
827 | |
… | |
… | |
832 | XftUnlockFace (f); |
879 | XftUnlockFace (f); |
833 | |
880 | |
834 | return true; |
881 | return true; |
835 | } |
882 | } |
836 | |
883 | |
837 | #if 0 |
|
|
838 | void rxvt_font::gen_coverage_swath (unsigned int page) |
|
|
839 | { |
|
|
840 | cvr[page] = new swath; |
|
|
841 | |
|
|
842 | for (int i = 0; i < SWATHSIZE; i++) |
|
|
843 | cvr[page][i] = 0; |
|
|
844 | |
|
|
845 | populate_coverage_swath (cvr[page], page << SWATHBITS, ((page + 1) << SWATHBITS) - 1); |
|
|
846 | } |
|
|
847 | #endif |
|
|
848 | |
|
|
849 | bool |
884 | bool |
850 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
885 | rxvt_font_xft::has_codepoint (uint32_t unicode) |
851 | { |
886 | { |
852 | return XftCharExists (DISPLAY, f, unicode); |
887 | return XftCharExists (DISPLAY, f, unicode); |
853 | } |
888 | } |
… | |
… | |
855 | void |
890 | void |
856 | rxvt_font_xft::draw (int x, int y, |
891 | rxvt_font_xft::draw (int x, int y, |
857 | const text_t *text, int len, |
892 | const text_t *text, int len, |
858 | int fg, int bg) |
893 | int fg, int bg) |
859 | { |
894 | { |
860 | if (!d) |
895 | d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap); |
861 | { |
|
|
862 | dR; |
|
|
863 | d = XftDrawCreate (DISPLAY, DRAWABLE, XVISUAL, XCMAP); |
|
|
864 | } |
|
|
865 | |
896 | |
866 | if (bg >= 0 && bg != Color_bg) |
897 | if (bg >= 0 && bg != Color_bg) |
867 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
898 | XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight); |
868 | else |
899 | else |
869 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
900 | clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg); |
870 | |
901 | |
871 | if (!slow && width == r->TermWin.fwidth) |
902 | if (!slow && width == r->TermWin.fwidth && 0) |
872 | { |
903 | { |
873 | if (sizeof (text_t) == sizeof (FcChar16)) |
904 | if (sizeof (text_t) == sizeof (FcChar16)) |
874 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
905 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, len); |
875 | else |
906 | else |
876 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
907 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, len); |
… | |
… | |
879 | { |
910 | { |
880 | while (len) |
911 | while (len) |
881 | { |
912 | { |
882 | if (*text != NOCHAR && *text != ' ') |
913 | if (*text != NOCHAR && *text != ' ') |
883 | { |
914 | { |
|
|
915 | int fwidth = r->TermWin.fwidth; |
|
|
916 | if (len >= 2 && text[1] == NOCHAR) |
|
|
917 | fwidth *= 2; |
|
|
918 | |
|
|
919 | XGlyphInfo extents; |
884 | if (sizeof (text_t) == sizeof (FcChar16)) |
920 | if (sizeof (text_t) == sizeof (FcChar16)) |
885 | XftDrawString16 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
921 | { |
|
|
922 | XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents); |
|
|
923 | XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
924 | y + r->TermWin.fbase, (const FcChar16 *)text, 1); |
|
|
925 | } |
886 | else |
926 | else |
887 | XftDrawString32 (d, &r->PixColors[fg].c, f, x, y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
927 | { |
|
|
928 | XGlyphInfo extents; |
|
|
929 | XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents); |
|
|
930 | XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2, |
|
|
931 | y + r->TermWin.fbase, (const FcChar32 *)text, 1); |
|
|
932 | } |
888 | } |
933 | } |
889 | |
934 | |
890 | x += r->TermWin.fwidth; |
935 | x += r->TermWin.fwidth; |
891 | text++; |
936 | text++; |
892 | len--; |
937 | len--; |
… | |
… | |
896 | #endif |
941 | #endif |
897 | |
942 | |
898 | ///////////////////////////////////////////////////////////////////////////// |
943 | ///////////////////////////////////////////////////////////////////////////// |
899 | |
944 | |
900 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
945 | rxvt_fontset::rxvt_fontset (rxvt_t r) |
901 | #ifdef EXPLICIT_CONTEXT |
|
|
902 | : r(r) |
946 | : r (r) |
903 | #endif |
|
|
904 | { |
947 | { |
905 | clear (); |
948 | clear (); |
906 | } |
949 | } |
907 | |
950 | |
908 | rxvt_fontset::~rxvt_fontset () |
951 | rxvt_fontset::~rxvt_fontset () |
… | |
… | |
911 | } |
954 | } |
912 | |
955 | |
913 | void |
956 | void |
914 | rxvt_fontset::clear () |
957 | rxvt_fontset::clear () |
915 | { |
958 | { |
916 | for (rxvt_font **i = fonts.begin (); i != fonts.end(); i++) |
959 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
917 | FONT_UNREF (*i); |
960 | FONT_UNREF (*i); |
918 | |
961 | |
919 | fonts.clear (); |
962 | fonts.clear (); |
920 | base_id = 0; |
963 | base_id = 0; |
921 | base_prop.height = 0x7fffffff; |
964 | base_prop.height = 0x7fffffff; |
… | |
… | |
975 | |
1018 | |
976 | if (*desc == '[') |
1019 | if (*desc == '[') |
977 | { |
1020 | { |
978 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
1021 | fprintf (stderr, "extra font parameters not yet supported, skipping.\n"); |
979 | |
1022 | |
980 | const char *extra = desc++; |
1023 | //const char *extra = desc++; // not yet used |
981 | |
1024 | |
982 | desc = strchr (desc, ']'); |
1025 | desc = strchr (desc, ']'); |
983 | |
1026 | |
984 | if (!desc) |
1027 | if (!desc) |
985 | { |
1028 | { |
… | |
… | |
1038 | |
1081 | |
1039 | if (!base_id) |
1082 | if (!base_id) |
1040 | base_id = 1; |
1083 | base_id = 1; |
1041 | |
1084 | |
1042 | // we currently need a base-font, no matter what |
1085 | // we currently need a base-font, no matter what |
1043 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1086 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1044 | { |
1087 | { |
|
|
1088 | puts ("unable to load specified font (s), falling back to 'fixed'\n"); |
1045 | add_fonts ("fixed"); |
1089 | add_fonts ("fixed"); |
1046 | base_id = fonts.size () - 1; |
1090 | base_id = fonts.size () - 1; |
1047 | } |
1091 | } |
1048 | |
1092 | |
1049 | if (fonts.size () <= base_id || !realize_font (base_id)) |
1093 | if ((int)fonts.size () <= base_id || !realize_font (base_id)) |
1050 | { |
1094 | { |
1051 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1095 | fprintf (stderr, "unable to load a base font, please provide one using -fn fontname\n"); |
1052 | exit (1); |
1096 | exit (1); |
1053 | } |
1097 | } |
1054 | |
1098 | |
… | |
… | |
1056 | } |
1100 | } |
1057 | |
1101 | |
1058 | int |
1102 | int |
1059 | rxvt_fontset::find_font (uint32_t unicode) |
1103 | rxvt_fontset::find_font (uint32_t unicode) |
1060 | { |
1104 | { |
1061 | for (int i = 0; i < fonts.size (); i++) |
1105 | for (unsigned int i = 0; i < fonts.size (); i++) |
1062 | { |
1106 | { |
1063 | rxvt_font *f = fonts[i]; |
1107 | rxvt_font *f = fonts[i]; |
1064 | |
1108 | |
1065 | if (!f->loaded) |
1109 | if (!f->loaded) |
1066 | { |
1110 | { |