1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtfont.C |
2 | * File: rxvtfont.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
4 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
5 | * - original version. |
5 | * - original version. |
6 | * |
6 | * |
… | |
… | |
43 | const char *name; |
43 | const char *name; |
44 | } fallback_fonts[] = { |
44 | } fallback_fonts[] = { |
45 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
45 | { CS_ISO8859_1, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-1" }, |
46 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
46 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-15" }, |
47 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
47 | { CS_ISO8859_15, "-*-*-*-r-*--*-*-*-*-c-*-fcd8859-15" }, |
48 | |
48 | |
49 | #if ENCODING_EU |
49 | #if ENCODING_EU |
50 | // cyrillic |
50 | // cyrillic |
51 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
51 | { CS_KOI8_R, "-*-*-*-r-*--*-*-*-*-c-*-koi8-r" }, |
52 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
52 | { CS_KOI8_U, "-*-*-*-r-*--*-*-*-*-c-*-koi8-u" }, |
53 | |
53 | |
54 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
54 | { CS_ISO8859_2, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-2" }, |
55 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
55 | { CS_ISO8859_3, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-3" }, |
56 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
56 | { CS_ISO8859_4, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-4" }, |
57 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
57 | { CS_ISO8859_5, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-5" }, |
58 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
58 | { CS_ISO8859_6, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-6" }, |
… | |
… | |
65 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
65 | { CS_ISO8859_14, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-14" }, |
66 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
66 | { CS_ISO8859_16, "-*-*-*-r-*--*-*-*-*-c-*-iso8859-16" }, |
67 | |
67 | |
68 | # if XFT |
68 | # if XFT |
69 | { CS_KOI8_U, "xft::lang=ru" }, |
69 | { CS_KOI8_U, "xft::lang=ru" }, |
70 | |
70 | |
71 | { CS_ISO8859_5, "xft::lang=ru" }, |
71 | { CS_ISO8859_5, "xft::lang=ru" }, |
72 | { CS_ISO8859_6, "xft::lang=ar" }, |
72 | { CS_ISO8859_6, "xft::lang=ar" }, |
73 | { CS_ISO8859_7, "xft::lang=el" }, |
73 | { CS_ISO8859_7, "xft::lang=el" }, |
74 | { CS_ISO8859_8, "xft::lang=he" }, |
74 | { CS_ISO8859_8, "xft::lang=he" }, |
75 | { CS_ISO8859_9, "xft::lang=tr" }, |
75 | { CS_ISO8859_9, "xft::lang=tr" }, |
… | |
… | |
158 | 0x304c, 0x672c, // が本 |
158 | 0x304c, 0x672c, // が本 |
159 | }; |
159 | }; |
160 | |
160 | |
161 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
161 | #define NUM_EXTENT_TEST_CHARS (sizeof (extent_test_chars) / sizeof (extent_test_chars[0])) |
162 | |
162 | |
163 | #define dTermDisplay Display *disp = term->xdisp |
163 | #define dTermDisplay Display *disp = term->dpy |
164 | #define dTermGC GC gc = term->gc |
164 | #define dTermGC GC gc = term->gc |
165 | |
|
|
166 | ///////////////////////////////////////////////////////////////////////////// |
|
|
167 | |
|
|
168 | #if XFT |
|
|
169 | rxvt_drawable::~rxvt_drawable () |
|
|
170 | { |
|
|
171 | if (xftdrawable) |
|
|
172 | XftDrawDestroy (xftdrawable); |
|
|
173 | } |
|
|
174 | |
|
|
175 | rxvt_drawable::operator XftDraw *() |
|
|
176 | { |
|
|
177 | if (!xftdrawable) |
|
|
178 | xftdrawable = XftDrawCreate (screen->xdisp, drawable, screen->visual, screen->cmap); |
|
|
179 | |
|
|
180 | return xftdrawable; |
|
|
181 | } |
|
|
182 | #endif |
|
|
183 | |
165 | |
184 | ///////////////////////////////////////////////////////////////////////////// |
166 | ///////////////////////////////////////////////////////////////////////////// |
185 | |
167 | |
186 | static const char * |
168 | static const char * |
187 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
169 | enc_char (const text_t *text, uint32_t len, codeset cs, bool &zero) |
… | |
… | |
249 | void |
231 | void |
250 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
232 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
251 | { |
233 | { |
252 | dTermDisplay; |
234 | dTermDisplay; |
253 | dTermGC; |
235 | dTermGC; |
254 | |
236 | |
255 | if (color == Color_bg) |
237 | if (color == Color_bg || color == Color_transparent) |
256 | XClearArea (disp, d, x, y, w, h, false); |
238 | XClearArea (disp, d, x, y, w, h, false); |
257 | else if (color >= 0) |
239 | else if (color >= 0) |
258 | { |
240 | { |
259 | #if XFT |
241 | #if XFT |
|
|
242 | bool done = false; |
|
|
243 | #ifdef HAVE_BG_PIXMAP |
|
|
244 | if (term->bgPixmap.pixmap && color >= 0 && term->pix_colors[color].c.color.alpha < 0x0ff00) |
|
|
245 | { |
|
|
246 | Picture dst = XftDrawPicture (d); |
|
|
247 | if (dst != 0) |
|
|
248 | { |
|
|
249 | XClearArea (disp, d, x, y, w, h, false); |
|
|
250 | Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c); |
|
|
251 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h); |
|
|
252 | done = true; |
|
|
253 | } |
|
|
254 | } |
|
|
255 | #endif |
|
|
256 | if (!done) |
260 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
257 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
261 | #else |
258 | #else |
262 | XSetForeground (disp, gc, term->pix_colors[color]); |
259 | XSetForeground (disp, gc, term->pix_colors[color]); |
263 | XFillRectangle (disp, d, gc, x, y, w, h); |
260 | XFillRectangle (disp, d, gc, x, y, w, h); |
264 | #endif |
261 | #endif |
265 | } |
262 | } |
… | |
… | |
288 | p.slant = rxvt_fontprop::roman; |
285 | p.slant = rxvt_fontprop::roman; |
289 | |
286 | |
290 | return p; |
287 | return p; |
291 | } |
288 | } |
292 | |
289 | |
293 | bool load (const rxvt_fontprop &prop) |
290 | bool load (const rxvt_fontprop &prop, bool force_prop) |
294 | { |
291 | { |
295 | width = 1; height = 1; |
292 | width = 1; height = 1; |
296 | ascent = 1; descent = 0; |
293 | ascent = 1; descent = 0; |
297 | |
294 | |
298 | set_name (strdup ("built-in support font")); |
295 | set_name (strdup ("built-in support font")); |
… | |
… | |
408 | |
405 | |
409 | case 1: // rectangle, possibly stippled |
406 | case 1: // rectangle, possibly stippled |
410 | if (a) |
407 | if (a) |
411 | { |
408 | { |
412 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
409 | static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; |
413 | |
410 | |
414 | gcv.fill_style = FillStippled; |
411 | gcv.fill_style = FillStippled; |
415 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
412 | gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); |
416 | gcv.ts_x_origin = x; |
413 | gcv.ts_x_origin = x; |
417 | gcv.ts_y_origin = y; |
414 | gcv.ts_y_origin = y; |
418 | |
415 | |
… | |
… | |
459 | *chrs = cc->c2; |
456 | *chrs = cc->c2; |
460 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
457 | rxvt_font *f2 = (f1->has_char (cc->c2, 0, careful) && !careful) |
461 | ? f1 |
458 | ? f1 |
462 | : (*fs)[fs->find_font (cc->c2)]; |
459 | : (*fs)[fs->find_font (cc->c2)]; |
463 | |
460 | |
464 | f2->draw (d, x, y, chrs, width, fg, -1); |
461 | f2->draw (d, x, y, chrs, width, fg, Color_none); |
465 | } |
462 | } |
466 | } |
463 | } |
467 | #endif |
464 | #endif |
468 | else |
465 | else |
469 | switch (t) |
466 | switch (t) |
… | |
… | |
489 | |
486 | |
490 | void clear (); |
487 | void clear (); |
491 | |
488 | |
492 | rxvt_fontprop properties (); |
489 | rxvt_fontprop properties (); |
493 | |
490 | |
494 | bool load (const rxvt_fontprop &prop); |
491 | bool load (const rxvt_fontprop &prop, bool force_prop); |
495 | |
492 | |
496 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
493 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
497 | |
494 | |
498 | void draw (rxvt_drawable &d, int x, int y, |
495 | void draw (rxvt_drawable &d, int x, int y, |
499 | const text_t *text, int len, |
496 | const text_t *text, int len, |
500 | int fg, int bg); |
497 | int fg, int bg); |
501 | |
498 | |
502 | bool slow; // wether this is a proportional font or has other funny characteristics |
499 | bool slow; // wether this is a proportional font or has other funny characteristics |
503 | XFontStruct *f; |
500 | XFontStruct *f; |
504 | codeset cs; |
|
|
505 | bool enc2b, encm; |
501 | bool enc2b, encm; |
506 | |
502 | |
507 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
503 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
508 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
504 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
509 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
505 | bool set_properties (rxvt_fontprop &p, XFontStruct *f); |
… | |
… | |
514 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
510 | rxvt_font_x11::get_property (XFontStruct *f, Atom property, const char *repl) const |
515 | { |
511 | { |
516 | unsigned long value; |
512 | unsigned long value; |
517 | |
513 | |
518 | if (XGetFontProperty (f, property, &value)) |
514 | if (XGetFontProperty (f, property, &value)) |
519 | return XGetAtomName (term->xdisp, value); |
515 | return XGetAtomName (term->dpy, value); |
520 | else |
516 | else |
521 | return rxvt_strdup (repl); |
517 | return repl ? strdup (repl) : 0; |
522 | } |
518 | } |
523 | |
519 | |
524 | rxvt_fontprop |
520 | rxvt_fontprop |
525 | rxvt_font_x11::properties () |
521 | rxvt_font_x11::properties () |
526 | { |
522 | { |
… | |
… | |
547 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
543 | rxvt_font_x11::set_properties (rxvt_fontprop &p, XFontStruct *f) |
548 | { |
544 | { |
549 | unsigned long height; |
545 | unsigned long height; |
550 | |
546 | |
551 | #if 0 |
547 | #if 0 |
552 | if (!XGetFontProperty (f, XInternAtom (term->xdisp, "PIXEL_SIZE", 0), &height)) |
548 | if (!XGetFontProperty (f, XInternAtom (term->dpy, "PIXEL_SIZE", 0), &height)) |
553 | return false; |
549 | return false; |
554 | #else |
550 | #else |
555 | height = f->ascent + f->descent; |
551 | height = f->ascent + f->descent; |
556 | #endif |
552 | #endif |
557 | |
553 | |
… | |
… | |
645 | return false; |
641 | return false; |
646 | } |
642 | } |
647 | } |
643 | } |
648 | |
644 | |
649 | bool |
645 | bool |
650 | rxvt_font_x11::load (const rxvt_fontprop &prop) |
646 | rxvt_font_x11::load (const rxvt_fontprop &prop, bool force_prop) |
651 | { |
647 | { |
652 | dTermDisplay; |
648 | dTermDisplay; |
653 | |
649 | |
654 | clear (); |
650 | clear (); |
655 | |
651 | |
656 | char field_str[64]; // enough for 128 bits |
652 | char field_str[64]; // enough for 128 bits |
657 | |
653 | |
658 | // first morph the font if required |
654 | // first morph the font if required |
659 | if (prop.weight != rxvt_fontprop::unset |
655 | if (force_prop) |
660 | || prop.slant != rxvt_fontprop::unset) |
|
|
661 | { |
656 | { |
662 | char fname[1024]; |
657 | char fname[1024]; |
663 | |
658 | |
664 | if (name[0] != '-') |
659 | if (name[0] != '-') |
665 | { |
660 | { |
… | |
… | |
679 | f = 0; |
674 | f = 0; |
680 | } |
675 | } |
681 | |
676 | |
682 | if (prop.weight != rxvt_fontprop::unset) |
677 | if (prop.weight != rxvt_fontprop::unset) |
683 | { |
678 | { |
684 | replace_field (fname, name, 2, 0, |
679 | replace_field (fname, name, 2, 0, |
685 | prop.weight < rxvt_fontprop::bold |
680 | prop.weight < rxvt_fontprop::bold |
686 | ? "medium" : "bold"); |
681 | ? "medium" : "bold"); |
687 | set_name (strdup (fname)); |
682 | set_name (strdup (fname)); |
688 | } |
683 | } |
689 | |
684 | |
… | |
… | |
833 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
828 | int N = f->max_char_or_byte2 - f->min_char_or_byte2; |
834 | |
829 | |
835 | if (encm) |
830 | if (encm) |
836 | N += (f->max_byte1 - f->min_byte1) |
831 | N += (f->max_byte1 - f->min_byte1) |
837 | * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); |
832 | * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); |
838 | |
833 | |
839 | while (N) |
834 | while (N) |
840 | { |
835 | { |
841 | if (f->per_char[N].width > width) |
836 | if (f->per_char[N].width > width) |
842 | width = f->per_char[N].width; |
837 | width = f->per_char[N].width; |
843 | |
838 | |
… | |
… | |
892 | void |
887 | void |
893 | rxvt_font_x11::clear () |
888 | rxvt_font_x11::clear () |
894 | { |
889 | { |
895 | if (f) |
890 | if (f) |
896 | { |
891 | { |
897 | XFreeFont (term->xdisp, f); |
892 | XFreeFont (term->dpy, f); |
898 | f = 0; |
893 | f = 0; |
899 | } |
894 | } |
900 | } |
895 | } |
901 | |
896 | |
902 | bool |
897 | bool |
… | |
… | |
995 | else |
990 | else |
996 | { |
991 | { |
997 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
992 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
998 | |
993 | |
999 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
994 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1000 | |
995 | |
1001 | if (slow) |
996 | if (slow) |
1002 | { |
997 | { |
1003 | do |
998 | do |
1004 | { |
999 | { |
1005 | if (xc->byte1 || xc->byte2) |
1000 | if (xc->byte1 || xc->byte2) |
… | |
… | |
1027 | else |
1022 | else |
1028 | { |
1023 | { |
1029 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1024 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
1030 | |
1025 | |
1031 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1026 | XChangeGC (disp, gc, GCForeground | GCFont, &v); |
1032 | |
1027 | |
1033 | if (slow) |
1028 | if (slow) |
1034 | { |
1029 | { |
1035 | do |
1030 | do |
1036 | { |
1031 | { |
1037 | if (*xc) |
1032 | if (*xc) |
… | |
… | |
1057 | |
1052 | |
1058 | void clear (); |
1053 | void clear (); |
1059 | |
1054 | |
1060 | rxvt_fontprop properties (); |
1055 | rxvt_fontprop properties (); |
1061 | |
1056 | |
1062 | bool load (const rxvt_fontprop &prop); |
1057 | bool load (const rxvt_fontprop &prop, bool force_prop); |
1063 | |
1058 | |
1064 | void draw (rxvt_drawable &d, int x, int y, |
1059 | void draw (rxvt_drawable &d, int x, int y, |
1065 | const text_t *text, int len, |
1060 | const text_t *text, int len, |
1066 | int fg, int bg); |
1061 | int fg, int bg); |
1067 | |
1062 | |
1068 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &carefull) const; |
1063 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const; |
1069 | |
1064 | |
1070 | protected: |
1065 | protected: |
1071 | XftFont *f; |
1066 | XftFont *f; |
1072 | }; |
1067 | }; |
1073 | |
1068 | |
1074 | void |
1069 | void |
1075 | rxvt_font_xft::clear () |
1070 | rxvt_font_xft::clear () |
1076 | { |
1071 | { |
1077 | if (f) |
1072 | if (f) |
1078 | { |
1073 | { |
1079 | XftFontClose (term->xdisp, f); |
1074 | XftFontClose (term->dpy, f); |
1080 | f = 0; |
1075 | f = 0; |
1081 | } |
1076 | } |
1082 | } |
1077 | } |
1083 | |
1078 | |
1084 | rxvt_fontprop |
1079 | rxvt_fontprop |
… | |
… | |
1100 | |
1095 | |
1101 | return p; |
1096 | return p; |
1102 | } |
1097 | } |
1103 | |
1098 | |
1104 | bool |
1099 | bool |
1105 | rxvt_font_xft::load (const rxvt_fontprop &prop) |
1100 | rxvt_font_xft::load (const rxvt_fontprop &prop, bool force_prop) |
1106 | { |
1101 | { |
1107 | dTermDisplay; |
1102 | dTermDisplay; |
1108 | |
1103 | |
1109 | clear (); |
1104 | clear (); |
1110 | |
1105 | |
… | |
… | |
1119 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1114 | && (FcPatternGet (p, FC_PIXEL_SIZE, 0, &v) != FcResultMatch |
1120 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1115 | && FcPatternGet (p, FC_SIZE, 0, &v) != FcResultMatch)) |
1121 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1116 | FcPatternAddInteger (p, FC_PIXEL_SIZE, prop.height); |
1122 | |
1117 | |
1123 | if (prop.weight != rxvt_fontprop::unset |
1118 | if (prop.weight != rxvt_fontprop::unset |
1124 | && FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch) |
1119 | && (force_prop || FcPatternGet (p, FC_WEIGHT, 0, &v) != FcResultMatch)) |
1125 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1120 | FcPatternAddInteger (p, FC_WEIGHT, prop.weight); |
1126 | |
1121 | |
1127 | if (prop.slant != rxvt_fontprop::unset |
1122 | if (prop.slant != rxvt_fontprop::unset |
1128 | && FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch) |
1123 | && (force_prop || FcPatternGet (p, FC_SLANT, 0, &v) != FcResultMatch)) |
1129 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1124 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1130 | |
1125 | |
1131 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1126 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1132 | // clip width, we can't do better, or can we? |
1127 | // clip width, we can't do better, or can we? |
1133 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1128 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
… | |
… | |
1251 | bool |
1246 | bool |
1252 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1247 | rxvt_font_xft::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
1253 | { |
1248 | { |
1254 | careful = false; |
1249 | careful = false; |
1255 | |
1250 | |
1256 | if (!XftCharExists (term->xdisp, f, unicode)) |
1251 | if (!XftCharExists (term->dpy, f, unicode)) |
1257 | return false; |
1252 | return false; |
1258 | |
1253 | |
1259 | if (!prop || prop->width == rxvt_fontprop::unset) |
1254 | if (!prop || prop->width == rxvt_fontprop::unset) |
1260 | return true; |
1255 | return true; |
1261 | |
1256 | |
1262 | // check character against base font bounding box |
1257 | // check character against base font bounding box |
1263 | FcChar32 ch = unicode; |
1258 | FcChar32 ch = unicode; |
1264 | XGlyphInfo g; |
1259 | XGlyphInfo g; |
1265 | XftTextExtents32 (term->xdisp, f, &ch, 1, &g); |
1260 | XftTextExtents32 (term->dpy, f, &ch, 1, &g); |
1266 | |
1261 | |
1267 | int w = g.width - g.x; |
1262 | int w = g.width - g.x; |
1268 | int wcw = max (WCWIDTH (unicode), 1); |
1263 | int wcw = max (WCWIDTH (unicode), 1); |
1269 | |
1264 | |
1270 | careful = g.x > 0 || w > prop->width * wcw; |
1265 | careful = g.x > 0 || w > prop->width * wcw; |
… | |
… | |
1282 | void |
1277 | void |
1283 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1278 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1284 | const text_t *text, int len, |
1279 | const text_t *text, int len, |
1285 | int fg, int bg) |
1280 | int fg, int bg) |
1286 | { |
1281 | { |
1287 | clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); |
|
|
1288 | |
|
|
1289 | XGlyphInfo extents; |
1282 | XGlyphInfo extents; |
1290 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1283 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1291 | XftGlyphSpec *ep = enc; |
1284 | XftGlyphSpec *ep = enc; |
1292 | |
1285 | |
1293 | dTermDisplay; |
1286 | dTermDisplay; |
1294 | dTermGC; |
1287 | dTermGC; |
1295 | |
1288 | |
|
|
1289 | int w = term->fwidth * len; |
|
|
1290 | int h = term->fheight; |
|
|
1291 | |
|
|
1292 | /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. |
|
|
1293 | * Maybe make buffering into a resource flag? Compile time option doesn't seems like a |
|
|
1294 | * good idea from the perspective of packaging for wide variety of user configs. |
|
|
1295 | */ |
|
|
1296 | bool buffered = true |
|
|
1297 | #ifdef FORCE_UNBUFFERED_XFT |
|
|
1298 | && bg >= 0 |
|
|
1299 | #endif |
|
|
1300 | ; |
1296 | // cut trailing spaces |
1301 | // cut trailing spaces |
1297 | while (len && text [len - 1] == ' ') |
1302 | while (len && text [len - 1] == ' ') |
1298 | len--; |
1303 | len--; |
1299 | |
1304 | |
|
|
1305 | int x_ = buffered ? 0 : x; |
|
|
1306 | int y_ = buffered ? 0 : y; |
|
|
1307 | |
1300 | while (len) |
1308 | while (len) |
1301 | { |
1309 | { |
1302 | int cwidth = term->fwidth; |
1310 | int cwidth = term->fwidth; |
1303 | FcChar32 fc = *text++; len--; |
1311 | FcChar32 fc = *text++; len--; |
1304 | |
1312 | |
1305 | while (len && *text == NOCHAR) |
1313 | while (len && *text == NOCHAR) |
1306 | text++, len--, cwidth += term->fwidth; |
1314 | text++, len--, cwidth += term->fwidth; |
1307 | |
1315 | |
1308 | if (fc != ' ') // skip spaces |
1316 | if (fc != ' ') // skip spaces |
1309 | { |
1317 | { |
1310 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1318 | FT_UInt glyph = XftCharIndex (disp, f, fc); |
1311 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1319 | XftGlyphExtents (disp, f, &glyph, 1, &extents); |
1312 | |
1320 | |
1313 | ep->glyph = glyph; |
1321 | ep->glyph = glyph; |
1314 | ep->x = x + (cwidth - extents.xOff >> 1); |
1322 | ep->x = x_ + (cwidth - extents.xOff >> 1); |
1315 | ep->y = y + ascent; |
1323 | ep->y = y_ + ascent; |
1316 | |
1324 | |
1317 | if (extents.xOff == 0) |
1325 | if (extents.xOff == 0) |
1318 | ep->x = x + cwidth; |
1326 | ep->x = x_ + cwidth; |
1319 | |
1327 | |
1320 | ep++; |
1328 | ep++; |
1321 | } |
1329 | } |
1322 | |
1330 | |
1323 | x += cwidth; |
1331 | x_ += cwidth; |
|
|
1332 | } |
|
|
1333 | |
|
|
1334 | if (buffered) |
1324 | } |
1335 | { |
1325 | |
1336 | bool back_rendered = false; |
1326 | if (ep != enc) |
1337 | if (ep != enc) |
|
|
1338 | { |
|
|
1339 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
|
|
1340 | |
|
|
1341 | #ifdef HAVE_BG_PIXMAP |
|
|
1342 | if (term->bgPixmap.pixmap) |
|
|
1343 | { |
|
|
1344 | Picture dst = 0; |
|
|
1345 | |
|
|
1346 | if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) |
|
|
1347 | dst = XftDrawPicture (d2); |
|
|
1348 | |
|
|
1349 | if (bg < 0 || dst != 0) |
|
|
1350 | { |
|
|
1351 | int src_x = x, src_y = y ; |
|
|
1352 | |
|
|
1353 | if (term->bgPixmap.is_parentOrigin ()) |
|
|
1354 | { |
|
|
1355 | src_x += term->window_vt_x; |
|
|
1356 | src_y += term->window_vt_y; |
|
|
1357 | } |
|
|
1358 | |
|
|
1359 | if (term->bgPixmap.pmap_width >= src_x+w |
|
|
1360 | && term->bgPixmap.pmap_height >= src_y+h) |
|
|
1361 | { |
|
|
1362 | XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, |
|
|
1363 | src_x, src_y, w, h, 0, 0); |
|
|
1364 | } |
|
|
1365 | else |
|
|
1366 | { |
|
|
1367 | XGCValues gcv; |
|
|
1368 | |
|
|
1369 | gcv.fill_style = FillTiled; |
|
|
1370 | gcv.tile = term->bgPixmap.pixmap; |
|
|
1371 | gcv.ts_x_origin = -src_x; |
|
|
1372 | gcv.ts_y_origin = -src_y; |
|
|
1373 | |
|
|
1374 | XChangeGC (disp, gc, |
|
|
1375 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
|
|
1376 | &gcv); |
|
|
1377 | |
|
|
1378 | XFillRectangle (disp, d2, gc, 0, 0, w, h); |
|
|
1379 | |
|
|
1380 | gcv.fill_style = FillSolid; |
|
|
1381 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
|
|
1382 | } |
|
|
1383 | |
|
|
1384 | if (bg >= 0) |
|
|
1385 | { |
|
|
1386 | Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); |
|
|
1387 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
1388 | } |
|
|
1389 | |
|
|
1390 | back_rendered = true; |
|
|
1391 | } |
|
|
1392 | } |
|
|
1393 | #endif |
|
|
1394 | |
|
|
1395 | if (bg >= 0 && !back_rendered) |
|
|
1396 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
|
|
1397 | |
|
|
1398 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1399 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
|
|
1400 | } |
|
|
1401 | else |
|
|
1402 | clear_rect (d, x, y, w, h, bg); |
|
|
1403 | } |
|
|
1404 | else |
|
|
1405 | { |
|
|
1406 | clear_rect (d, x, y, w, h, bg); |
1327 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
1407 | XftDrawGlyphSpec (d, &term->pix_colors[fg].c, f, enc, ep - enc); |
|
|
1408 | } |
1328 | } |
1409 | } |
|
|
1410 | |
1329 | #endif |
1411 | #endif |
1330 | |
1412 | |
1331 | ///////////////////////////////////////////////////////////////////////////// |
1413 | ///////////////////////////////////////////////////////////////////////////// |
1332 | |
1414 | |
1333 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
1415 | rxvt_fontset::rxvt_fontset (rxvt_term *term) |
… | |
… | |
1344 | void |
1426 | void |
1345 | rxvt_fontset::clear () |
1427 | rxvt_fontset::clear () |
1346 | { |
1428 | { |
1347 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1429 | prop.width = prop.height = prop.ascent = prop.weight = prop.slant |
1348 | = rxvt_fontprop::unset; |
1430 | = rxvt_fontprop::unset; |
|
|
1431 | force_prop = false; |
1349 | |
1432 | |
1350 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1433 | for (rxvt_font **i = fonts.begin (); i != fonts.end (); i++) |
1351 | FONT_UNREF (*i); |
1434 | FONT_UNREF (*i); |
1352 | |
1435 | |
1353 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
1436 | for (pagemap **p = fmap.begin (); p != fmap.end (); p++) |
… | |
… | |
1362 | |
1445 | |
1363 | rxvt_font * |
1446 | rxvt_font * |
1364 | rxvt_fontset::new_font (const char *name, codeset cs) |
1447 | rxvt_fontset::new_font (const char *name, codeset cs) |
1365 | { |
1448 | { |
1366 | rxvt_font *f; |
1449 | rxvt_font *f; |
1367 | |
1450 | |
1368 | if (!name || !*name) |
1451 | if (!name || !*name) |
1369 | { |
1452 | { |
1370 | name = ""; |
1453 | name = ""; |
1371 | f = new rxvt_font_default (this); |
1454 | f = new rxvt_font_default (this); |
1372 | } |
1455 | } |
… | |
… | |
1465 | if (fonts[i]->loaded) |
1548 | if (fonts[i]->loaded) |
1466 | return true; |
1549 | return true; |
1467 | |
1550 | |
1468 | fonts[i]->loaded = true; |
1551 | fonts[i]->loaded = true; |
1469 | |
1552 | |
1470 | if (!fonts[i]->load (prop)) |
1553 | if (!fonts[i]->load (prop, force_prop)) |
1471 | { |
1554 | { |
1472 | fonts[i]->cs = CS_UNKNOWN; |
1555 | fonts[i]->cs = CS_UNKNOWN; |
1473 | return false; |
1556 | return false; |
1474 | } |
1557 | } |
1475 | |
1558 | |
… | |
… | |
1576 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1659 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1577 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1660 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1578 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1661 | //FcPatternAddBool (p, FC_ANTIALIAS, 1); |
1579 | |
1662 | |
1580 | XftResult result; |
1663 | XftResult result; |
1581 | FcPattern *match = XftFontMatch (term->xdisp, term->display->screen, p, &result); |
1664 | FcPattern *match = XftFontMatch (term->dpy, term->display->screen, p, &result); |
1582 | |
1665 | |
1583 | FcPatternDestroy (p); |
1666 | FcPatternDestroy (p); |
1584 | |
1667 | |
1585 | if (match) |
1668 | if (match) |
1586 | { |
1669 | { |
… | |
… | |
1591 | if (find_font (font) < 0) |
1674 | if (find_font (font) < 0) |
1592 | { |
1675 | { |
1593 | char fontname[4096]; |
1676 | char fontname[4096]; |
1594 | sprintf (fontname, "xft:%-.4090s", font); |
1677 | sprintf (fontname, "xft:%-.4090s", font); |
1595 | |
1678 | |
1596 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1679 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1597 | } |
1680 | } |
1598 | |
1681 | |
1599 | free (font); |
1682 | free (font); |
1600 | } |
1683 | } |
1601 | #endif |
1684 | #endif |