1 | /*----------------------------------------------------------------------* |
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-2008 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" |
|
|
25 | #include "rxvtutil.h" |
24 | #include "rxvtutil.h" |
26 | #include "rxvtfont.h" |
25 | #include "rxvtfont.h" |
27 | |
26 | |
28 | #include <cstdlib> |
27 | #include <cstdlib> |
29 | |
28 | |
… | |
… | |
80 | |
79 | |
81 | // japanese |
80 | // japanese |
82 | #if ENCODING_JP || ENCODING_JP_EXT |
81 | #if ENCODING_JP || ENCODING_JP_EXT |
83 | # if XFT |
82 | # if XFT |
84 | // prefer xft for complex scripts |
83 | // prefer xft for complex scripts |
|
|
84 | { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" }, |
85 | { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, |
85 | { CS_JIS0208_1990_0, "xft:Kochi Gothic:antialias=false" }, |
86 | { CS_JIS0208_1990_0, "xft:Sazanami Mincho:antialias=false" }, |
|
|
87 | { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, |
86 | { CS_JIS0208_1990_0, "xft:Mincho:antialias=false" }, |
88 | { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, |
87 | { CS_JIS0208_1990_0, "xft::lang=ja:antialias=false" }, |
89 | # endif |
88 | # endif |
90 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
89 | { CS_JIS0201_1976_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0201*-0" }, |
91 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
90 | { CS_JIS0208_1990_0, "-*-mincho-*-r-*--*-*-*-*-c-*-jisx0208*-0" }, |
… | |
… | |
217 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
216 | : name(0), width(rxvt_fontprop::unset), height(rxvt_fontprop::unset) |
218 | { |
217 | { |
219 | } |
218 | } |
220 | |
219 | |
221 | void |
220 | void |
222 | rxvt_font::set_name (char *name) |
221 | rxvt_font::set_name (char *name_) |
223 | { |
222 | { |
224 | if (this->name == name) |
223 | if (name == name_) |
225 | return; |
224 | return; |
226 | |
225 | |
227 | if (this->name) free (this->name); // let the compiler optimize |
226 | if (name) free (name); // let the compiler optimize |
228 | this->name = name; |
227 | name = name_; |
229 | } |
228 | } |
230 | |
229 | |
231 | void |
230 | void |
232 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
231 | rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const |
233 | { |
232 | { |
… | |
… | |
237 | if (color == Color_bg || color == Color_transparent) |
236 | if (color == Color_bg || color == Color_transparent) |
238 | XClearArea (disp, d, x, y, w, h, false); |
237 | XClearArea (disp, d, x, y, w, h, false); |
239 | else if (color >= 0) |
238 | else if (color >= 0) |
240 | { |
239 | { |
241 | #if XFT |
240 | #if XFT |
242 | bool done = false; |
241 | Picture dst; |
|
|
242 | |
243 | #ifdef HAVE_BG_PIXMAP |
243 | # ifdef HAVE_BG_PIXMAP |
244 | if (term->bgPixmap.pixmap && color >= 0 && term->pix_colors[color].c.color.alpha < 0x0ff00) |
244 | if (term->bgPixmap.pixmap |
245 | { |
245 | && !term->pix_colors[color].is_opaque () |
246 | Picture dst = XftDrawPicture (d); |
246 | && ((dst = XftDrawPicture (d)))) |
247 | if (dst != 0) |
|
|
248 | { |
247 | { |
249 | XClearArea (disp, d, x, y, w, h, false); |
248 | XClearArea (disp, d, x, y, w, h, false); |
|
|
249 | |
250 | Picture solid_color_pict = XftDrawSrcPicture (d, &term->pix_colors[color].c); |
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); |
251 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, x, y, w, h); |
252 | done = true; |
|
|
253 | } |
252 | } |
254 | } |
253 | else |
255 | #endif |
254 | # endif |
256 | if (!done) |
|
|
257 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
255 | XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); |
|
|
256 | |
258 | #else |
257 | #else |
259 | XSetForeground (disp, gc, term->pix_colors[color]); |
258 | XSetForeground (disp, gc, term->pix_colors[color]); |
260 | XFillRectangle (disp, d, gc, x, y, w, h); |
259 | XFillRectangle (disp, d, gc, x, y, w, h); |
261 | #endif |
260 | #endif |
262 | } |
261 | } |
… | |
… | |
483 | |
482 | |
484 | x += fwidth; |
483 | x += fwidth; |
485 | } |
484 | } |
486 | } |
485 | } |
487 | |
486 | |
|
|
487 | struct rxvt_font_overflow : rxvt_font { |
|
|
488 | struct rxvt_fontset *fs; |
|
|
489 | |
|
|
490 | rxvt_font_overflow (rxvt_fontset *fs) |
|
|
491 | : rxvt_font () |
|
|
492 | { |
|
|
493 | this->fs = fs; |
|
|
494 | } |
|
|
495 | |
|
|
496 | rxvt_fontprop properties () |
|
|
497 | { |
|
|
498 | rxvt_fontprop p; |
|
|
499 | |
|
|
500 | p.width = p.height = 1; |
|
|
501 | p.ascent = rxvt_fontprop::unset; |
|
|
502 | p.weight = rxvt_fontprop::medium; |
|
|
503 | p.slant = rxvt_fontprop::roman; |
|
|
504 | |
|
|
505 | return p; |
|
|
506 | } |
|
|
507 | |
|
|
508 | bool load (const rxvt_fontprop &prop, bool force_prop) |
|
|
509 | { |
|
|
510 | width = 1; height = 1; |
|
|
511 | ascent = 1; descent = 0; |
|
|
512 | |
|
|
513 | set_name (strdup ("built-in rendition overflow font")); |
|
|
514 | |
|
|
515 | return true; |
|
|
516 | } |
|
|
517 | |
|
|
518 | bool has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const |
|
|
519 | { |
|
|
520 | return false; |
|
|
521 | } |
|
|
522 | |
|
|
523 | void draw (rxvt_drawable &d, int x, int y, |
|
|
524 | const text_t *text, int len, |
|
|
525 | int fg, int bg) |
|
|
526 | { |
|
|
527 | while (len--) |
|
|
528 | { |
|
|
529 | int fid = fs->find_font_idx (*text); |
|
|
530 | (*fs)[fid]->draw (d, x, y, text, 1, fg, bg); |
|
|
531 | ++text; |
|
|
532 | x += term->fwidth; |
|
|
533 | } |
|
|
534 | } |
|
|
535 | }; |
|
|
536 | |
488 | ///////////////////////////////////////////////////////////////////////////// |
537 | ///////////////////////////////////////////////////////////////////////////// |
489 | |
538 | |
490 | struct rxvt_font_x11 : rxvt_font { |
539 | struct rxvt_font_x11 : rxvt_font { |
491 | rxvt_font_x11 () { f = 0; } |
540 | rxvt_font_x11 () { f = 0; } |
492 | |
541 | |
… | |
… | |
500 | |
549 | |
501 | void draw (rxvt_drawable &d, int x, int y, |
550 | void draw (rxvt_drawable &d, int x, int y, |
502 | const text_t *text, int len, |
551 | const text_t *text, int len, |
503 | int fg, int bg); |
552 | int fg, int bg); |
504 | |
553 | |
505 | bool slow; // wether this is a proportional font or has other funny characteristics |
554 | bool slow; // whether this is a proportional font or has other funny characteristics |
506 | XFontStruct *f; |
555 | XFontStruct *f; |
507 | bool enc2b, encm; |
556 | bool enc2b, encm; |
508 | |
557 | |
509 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
558 | char *get_property (XFontStruct *f, Atom property, const char *repl) const; |
510 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
559 | bool set_properties (rxvt_fontprop &p, int height, const char *weight, const char *slant, int avgwidth); |
… | |
… | |
632 | |
681 | |
633 | if (slashes >= 13 && (!old || *field == old)) |
682 | if (slashes >= 13 && (!old || *field == old)) |
634 | { |
683 | { |
635 | size_t len = field - name; |
684 | size_t len = field - name; |
636 | *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1); |
685 | *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1); |
637 | strncpy (*ptr, name, len); |
686 | memcpy (*ptr, name, len); |
638 | strcpy (*ptr + len, replace); |
687 | strcpy (*ptr + len, replace); |
639 | strcat (*ptr, end); |
688 | strcat (*ptr, end); |
640 | |
689 | |
641 | return true; |
690 | return true; |
642 | } |
691 | } |
… | |
… | |
793 | return false; |
842 | return false; |
794 | |
843 | |
795 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
844 | char *registry = get_property (f, term->xa [XA_CHARSET_REGISTRY], 0); |
796 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
845 | char *encoding = get_property (f, term->xa [XA_CHARSET_ENCODING], 0); |
797 | |
846 | |
|
|
847 | cs = CS_UNKNOWN; |
|
|
848 | |
798 | if (registry && encoding) |
849 | if (registry && encoding) |
799 | { |
850 | { |
800 | char charset[64]; |
851 | char charset[64]; |
801 | snprintf (charset, 64, "%s-%s", registry, encoding); |
852 | snprintf (charset, 64, "%s-%s", registry, encoding); |
802 | |
853 | |
803 | cs = codeset_from_name (charset); |
854 | cs = codeset_from_name (charset); |
|
|
855 | |
|
|
856 | if (cs == CS_UNKNOWN) |
|
|
857 | rxvt_warn ("%s: cannot deduce encoding from registry/encoding properties \"%s\", ignoring font.\n", name, charset); |
804 | } |
858 | } |
805 | else |
859 | |
|
|
860 | free (registry); |
|
|
861 | free (encoding); |
|
|
862 | |
|
|
863 | if (cs == CS_UNKNOWN) |
806 | { |
864 | { |
807 | const char *charset = get_property (f, XA_FONT, 0); |
865 | const char *charset = get_property (f, XA_FONT, 0); |
808 | |
866 | |
809 | if (!charset) |
867 | if (!charset) |
810 | charset = name; |
868 | charset = name; |
… | |
… | |
813 | while (*charset) |
871 | while (*charset) |
814 | if (*charset++ == '-' && !--count) |
872 | if (*charset++ == '-' && !--count) |
815 | break; |
873 | break; |
816 | |
874 | |
817 | cs = codeset_from_name (charset); |
875 | cs = codeset_from_name (charset); |
|
|
876 | if (cs == CS_UNKNOWN) |
|
|
877 | rxvt_warn ("%s: cannot deduce encoding from font name property \"%s\", ignoring font.\n", name, charset); |
|
|
878 | } |
|
|
879 | |
|
|
880 | if (cs == CS_UNKNOWN) |
818 | } |
881 | { |
819 | |
882 | clear (); |
820 | free (registry); |
883 | return false; |
821 | free (encoding); |
884 | } |
822 | |
885 | |
823 | if (cs == CS_UNICODE) |
886 | if (cs == CS_UNICODE) |
824 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
887 | cs = CS_UNICODE_16; // X11 can have a max. of 65536 chars per font |
825 | |
888 | |
826 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
889 | encm = f->min_byte1 != 0 || f->max_byte1 != 0; |
… | |
… | |
873 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
936 | if (wcw > 0) g.width = (g.width + wcw - 1) / wcw; |
874 | |
937 | |
875 | if (width < g.width) width = g.width; |
938 | if (width < g.width) width = g.width; |
876 | } |
939 | } |
877 | |
940 | |
878 | if (cs == CS_UNKNOWN) |
941 | #if 0 // do it per-character |
|
|
942 | if (prop && width > prop->width) |
879 | { |
943 | { |
880 | fprintf (stderr, "unable to deduce codeset, ignoring font '%s'\n", name); |
|
|
881 | |
|
|
882 | clear (); |
944 | clear (); |
883 | return false; |
945 | return false; |
884 | } |
946 | } |
885 | |
|
|
886 | #if 0 // do it per-character |
|
|
887 | if (prop && width > prop->width) |
|
|
888 | { |
|
|
889 | clear (); |
|
|
890 | return false; |
|
|
891 | } |
|
|
892 | #endif |
947 | #endif |
893 | |
948 | |
894 | return true; |
949 | return true; |
895 | } |
950 | } |
896 | |
951 | |
… | |
… | |
910 | uint32_t ch = FROM_UNICODE (cs, unicode); |
965 | uint32_t ch = FROM_UNICODE (cs, unicode); |
911 | |
966 | |
912 | if (ch == NOCHAR) |
967 | if (ch == NOCHAR) |
913 | return false; |
968 | return false; |
914 | |
969 | |
915 | /* check wether the character exists in _this_ font. horrible. */ |
970 | /* check whether the character exists in _this_ font. horrible. */ |
916 | XCharStruct *xcs; |
971 | XCharStruct *xcs; |
917 | |
972 | |
918 | if (encm) |
973 | if (encm) |
919 | { |
974 | { |
920 | unsigned char byte1 = ch >> 8; |
975 | unsigned char byte1 = ch >> 8; |
… | |
… | |
950 | return false; |
1005 | return false; |
951 | |
1006 | |
952 | if (!prop || prop->width == rxvt_fontprop::unset) |
1007 | if (!prop || prop->width == rxvt_fontprop::unset) |
953 | return true; |
1008 | return true; |
954 | |
1009 | |
955 | // check wether character overlaps previous/next character |
1010 | // check whether character overlaps previous/next character |
956 | int w = xcs->rbearing - xcs->lbearing; |
1011 | int w = xcs->rbearing - xcs->lbearing; |
957 | int wcw = max (WCWIDTH (unicode), 1); |
1012 | int wcw = max (WCWIDTH (unicode), 1); |
958 | |
1013 | |
959 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
1014 | careful = xcs->lbearing < 0 || xcs->rbearing > prop->width * wcw; |
960 | |
1015 | |
… | |
… | |
1134 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1189 | FcPatternAddInteger (p, FC_SLANT, prop.slant); |
1135 | |
1190 | |
1136 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1191 | #if 0 // clipping unfortunately destroys our precious double-width-characters |
1137 | // clip width, we can't do better, or can we? |
1192 | // clip width, we can't do better, or can we? |
1138 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1193 | if (FcPatternGet (p, FC_CHAR_WIDTH, 0, &v) != FcResultMatch) |
1139 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop->width); |
1194 | FcPatternAddInteger (p, FC_CHAR_WIDTH, prop.width); |
1140 | #endif |
1195 | #endif |
1141 | |
1196 | |
1142 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
1197 | if (FcPatternGet (p, FC_MINSPACE, 0, &v) != FcResultMatch) |
1143 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1198 | FcPatternAddBool (p, FC_MINSPACE, 1); |
1144 | |
1199 | |
… | |
… | |
1288 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1343 | rxvt_font_xft::draw (rxvt_drawable &d, int x, int y, |
1289 | const text_t *text, int len, |
1344 | const text_t *text, int len, |
1290 | int fg, int bg) |
1345 | int fg, int bg) |
1291 | { |
1346 | { |
1292 | XGlyphInfo extents; |
1347 | XGlyphInfo extents; |
1293 | XftGlyphSpec *enc = (XftGlyphSpec *)rxvt_temp_buf (len * sizeof (XftGlyphSpec)); |
1348 | XftGlyphSpec *enc = rxvt_temp_buf<XftGlyphSpec> (len); |
1294 | XftGlyphSpec *ep = enc; |
1349 | XftGlyphSpec *ep = enc; |
1295 | |
1350 | |
1296 | dTermDisplay; |
1351 | dTermDisplay; |
1297 | dTermGC; |
1352 | dTermGC; |
1298 | |
1353 | |
1299 | int w = term->fwidth * len; |
1354 | int w = term->fwidth * len; |
1300 | int h = term->fheight; |
1355 | int h = term->fheight; |
1301 | |
1356 | |
1302 | /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. |
1357 | bool buffered = bg >= Color_transparent |
1303 | * Maybe make buffering into a resource flag? Compile time option doesn't seems like a |
1358 | && term->option (Opt_buffered); |
1304 | * good idea from the perspective of packaging for wide variety of user configs. |
1359 | |
1305 | */ |
|
|
1306 | bool buffered = true |
|
|
1307 | #ifdef FORCE_UNBUFFERED_XFT |
|
|
1308 | && bg >= 0 |
|
|
1309 | #endif |
|
|
1310 | ; |
|
|
1311 | // cut trailing spaces |
1360 | // cut trailing spaces |
1312 | while (len && text [len - 1] == ' ') |
1361 | while (len && text [len - 1] == ' ') |
1313 | len--; |
1362 | len--; |
1314 | |
1363 | |
1315 | int x_ = buffered ? 0 : x; |
1364 | int x_ = buffered ? 0 : x; |
… | |
… | |
1341 | x_ += cwidth; |
1390 | x_ += cwidth; |
1342 | } |
1391 | } |
1343 | |
1392 | |
1344 | if (buffered) |
1393 | if (buffered) |
1345 | { |
1394 | { |
1346 | bool back_rendered = false; |
|
|
1347 | if (ep != enc) |
1395 | if (ep != enc) |
1348 | { |
1396 | { |
1349 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1397 | rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); |
1350 | |
1398 | |
1351 | #ifdef HAVE_BG_PIXMAP |
1399 | #ifdef HAVE_BG_PIXMAP |
|
|
1400 | Picture dst = 0; // the only assignment is done conditionally in the following if condition |
|
|
1401 | |
1352 | if (term->bgPixmap.pixmap) |
1402 | if (term->bgPixmap.pixmap |
|
|
1403 | && (bg == Color_transparent || bg == Color_bg |
|
|
1404 | || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2)))))) |
1353 | { |
1405 | { |
1354 | Picture dst = 0; |
1406 | int src_x = x, src_y = y; |
1355 | |
1407 | |
1356 | if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) |
1408 | if (term->bgPixmap.is_parentOrigin ()) |
1357 | dst = XftDrawPicture (d2); |
|
|
1358 | |
|
|
1359 | if (bg < 0 || dst != 0) |
|
|
1360 | { |
1409 | { |
1361 | int src_x = x, src_y = y ; |
|
|
1362 | |
|
|
1363 | if (term->bgPixmap.is_parentOrigin ()) |
|
|
1364 | { |
|
|
1365 | src_x += term->window_vt_x; |
1410 | src_x += term->window_vt_x; |
1366 | src_y += term->window_vt_y; |
1411 | src_y += term->window_vt_y; |
1367 | } |
1412 | } |
1368 | |
1413 | |
1369 | if (term->bgPixmap.pmap_width >= src_x+w |
1414 | if (term->bgPixmap.pmap_width >= src_x + w |
1370 | && term->bgPixmap.pmap_height >= src_y+h) |
1415 | && term->bgPixmap.pmap_height >= src_y + h) |
1371 | { |
1416 | { |
1372 | XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, |
1417 | XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, |
1373 | src_x, src_y, w, h, 0, 0); |
1418 | src_x, src_y, w, h, 0, 0); |
1374 | } |
1419 | } |
1375 | else |
1420 | else |
1376 | { |
1421 | { |
1377 | XGCValues gcv; |
1422 | XGCValues gcv; |
1378 | |
1423 | |
1379 | gcv.fill_style = FillTiled; |
1424 | gcv.fill_style = FillTiled; |
1380 | gcv.tile = term->bgPixmap.pixmap; |
1425 | gcv.tile = term->bgPixmap.pixmap; |
1381 | gcv.ts_x_origin = -src_x; |
1426 | gcv.ts_x_origin = -src_x; |
1382 | gcv.ts_y_origin = -src_y; |
1427 | gcv.ts_y_origin = -src_y; |
1383 | |
1428 | |
1384 | XChangeGC (disp, gc, |
1429 | XChangeGC (disp, gc, |
1385 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
1430 | GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, |
1386 | &gcv); |
1431 | &gcv); |
1387 | |
1432 | |
1388 | XFillRectangle (disp, d2, gc, 0, 0, w, h); |
1433 | XFillRectangle (disp, d2, gc, 0, 0, w, h); |
1389 | |
1434 | |
1390 | gcv.fill_style = FillSolid; |
1435 | gcv.fill_style = FillSolid; |
1391 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
1436 | XChangeGC (disp, gc, GCFillStyle, &gcv); |
1392 | } |
1437 | } |
1393 | |
1438 | |
1394 | if (bg >= 0) |
1439 | if (dst) |
1395 | { |
1440 | { |
1396 | Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); |
1441 | Picture solid_color_pict = XftDrawSrcPicture (d2, &term->pix_colors[bg].c); |
|
|
1442 | |
|
|
1443 | // dst can only be set when bg >= 0 |
1397 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
1444 | XRenderComposite (disp, PictOpOver, solid_color_pict, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
1398 | } |
|
|
1399 | |
|
|
1400 | back_rendered = true; |
|
|
1401 | } |
1445 | } |
1402 | } |
1446 | } |
|
|
1447 | else |
1403 | #endif |
1448 | #endif |
1404 | |
|
|
1405 | if (bg >= 0 && !back_rendered) |
|
|
1406 | XftDrawRect (d2, &term->pix_colors[bg].c, 0, 0, w, h); |
1449 | XftDrawRect (d2, &term->pix_colors[bg >= 0 ? bg : Color_bg].c, 0, 0, w, h); |
1407 | |
1450 | |
1408 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1451 | XftDrawGlyphSpec (d2, &term->pix_colors[fg].c, f, enc, ep - enc); |
1409 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1452 | XCopyArea (disp, d2, d, gc, 0, 0, w, h, x, y); |
1410 | } |
1453 | } |
1411 | else |
1454 | else |
… | |
… | |
1451 | fonts.clear (); |
1494 | fonts.clear (); |
1452 | |
1495 | |
1453 | fallback = fallback_fonts; |
1496 | fallback = fallback_fonts; |
1454 | } |
1497 | } |
1455 | |
1498 | |
|
|
1499 | void |
|
|
1500 | rxvt_fontset::prepare_font (rxvt_font *font, codeset cs) |
|
|
1501 | { |
|
|
1502 | font->set_term (term); |
|
|
1503 | |
|
|
1504 | font->cs = cs; |
|
|
1505 | font->loaded = false; |
|
|
1506 | } |
|
|
1507 | |
1456 | rxvt_font * |
1508 | rxvt_font * |
1457 | rxvt_fontset::new_font (const char *name, codeset cs) |
1509 | rxvt_fontset::new_font (const char *name, codeset cs) |
1458 | { |
1510 | { |
1459 | rxvt_font *f; |
1511 | rxvt_font *f; |
1460 | |
1512 | |
… | |
… | |
1476 | f = new rxvt_font_x11; |
1528 | f = new rxvt_font_x11; |
1477 | } |
1529 | } |
1478 | else |
1530 | else |
1479 | f = new rxvt_font_x11; |
1531 | f = new rxvt_font_x11; |
1480 | |
1532 | |
1481 | f->set_term (term); |
|
|
1482 | f->set_name (strdup (name)); |
1533 | f->set_name (strdup (name)); |
1483 | |
1534 | prepare_font (f, cs); |
1484 | f->cs = cs; |
|
|
1485 | f->loaded = false; |
|
|
1486 | |
1535 | |
1487 | return f; |
1536 | return f; |
1488 | } |
1537 | } |
1489 | |
1538 | |
1490 | ///////////////////////////////////////////////////////////////////////////// |
1539 | ///////////////////////////////////////////////////////////////////////////// |
|
|
1540 | |
|
|
1541 | void |
|
|
1542 | rxvt_fontset::push_font (rxvt_font *font) |
|
|
1543 | { |
|
|
1544 | if (fonts.size () == fontCount) |
|
|
1545 | { |
|
|
1546 | rxvt_font *f = new rxvt_font_overflow (this); |
|
|
1547 | |
|
|
1548 | prepare_font (f, CS_UNICODE); |
|
|
1549 | fonts.push_back (f); |
|
|
1550 | } |
|
|
1551 | |
|
|
1552 | fonts.push_back (font); |
|
|
1553 | } |
1491 | |
1554 | |
1492 | void |
1555 | void |
1493 | rxvt_fontset::add_fonts (const char *desc) |
1556 | rxvt_fontset::add_fonts (const char *desc) |
1494 | { |
1557 | { |
1495 | if (desc) |
1558 | if (desc) |
… | |
… | |
1533 | if (!end) |
1596 | if (!end) |
1534 | end = desc + strlen (desc); |
1597 | end = desc + strlen (desc); |
1535 | |
1598 | |
1536 | if (end - desc < 511) |
1599 | if (end - desc < 511) |
1537 | { |
1600 | { |
1538 | strncpy (buf, desc, end - desc); |
1601 | memcpy (buf, desc, end - desc); |
1539 | buf[end - desc] = 0; |
1602 | buf[end - desc] = 0; |
1540 | |
1603 | |
1541 | fonts.push_back (new_font (buf, cs)); |
1604 | push_font (new_font (buf, cs)); |
1542 | } |
1605 | } |
1543 | else |
1606 | else |
1544 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1607 | rxvt_warn ("fontset element too long (>511 bytes), ignored."); |
1545 | |
1608 | |
1546 | desc = end + 1; |
1609 | desc = end + 1; |
… | |
… | |
1574 | { |
1637 | { |
1575 | clear (); |
1638 | clear (); |
1576 | |
1639 | |
1577 | fontdesc = strdup (desc); |
1640 | fontdesc = strdup (desc); |
1578 | |
1641 | |
1579 | fonts.push_back (new_font (0, CS_UNICODE)); |
1642 | push_font (new_font (0, CS_UNICODE)); |
1580 | realize_font (0); |
1643 | realize_font (0); |
1581 | |
1644 | |
1582 | add_fonts (desc); |
1645 | add_fonts (desc); |
1583 | |
1646 | |
1584 | return true; |
1647 | return true; |
… | |
… | |
1593 | |
1656 | |
1594 | return -1; |
1657 | return -1; |
1595 | } |
1658 | } |
1596 | |
1659 | |
1597 | int |
1660 | int |
1598 | rxvt_fontset::find_font (unicode_t unicode) |
1661 | rxvt_fontset::find_font_idx (unicode_t unicode) |
1599 | { |
1662 | { |
1600 | if (unicode >= 1<<20) |
1663 | if (unicode >= 1<<20) |
1601 | return 0; |
1664 | return 0; |
1602 | |
1665 | |
1603 | unicode_t hi = unicode >> 8; |
1666 | unicode_t hi = unicode >> 8; |
… | |
… | |
1629 | goto next_font; |
1692 | goto next_font; |
1630 | |
1693 | |
1631 | bool careful; |
1694 | bool careful; |
1632 | if (f->has_char (unicode, &prop, careful)) |
1695 | if (f->has_char (unicode, &prop, careful)) |
1633 | { |
1696 | { |
1634 | if (careful) |
1697 | i = (i << 1) | careful; |
1635 | i |= 128; |
|
|
1636 | |
1698 | |
1637 | goto found; |
1699 | goto found; |
1638 | } |
1700 | } |
1639 | |
1701 | |
1640 | next_font: |
1702 | next_font: |
1641 | if (i == fonts.size () - 1) |
1703 | if (i == fonts.size () - 1) |
1642 | { |
1704 | { |
1643 | if (fallback->name) |
1705 | if (fallback->name) |
1644 | { |
1706 | { |
1645 | // search through the fallback list |
1707 | // search through the fallback list |
1646 | fonts.push_back (new_font (fallback->name, fallback->cs)); |
1708 | push_font (new_font (fallback->name, fallback->cs)); |
1647 | fallback++; |
1709 | fallback++; |
1648 | } |
1710 | } |
1649 | else |
1711 | else |
1650 | { |
1712 | { |
1651 | // try to find a new font. |
1713 | // try to find a new font. |
… | |
… | |
1682 | FcPatternDestroy (match); |
1744 | FcPatternDestroy (match); |
1683 | |
1745 | |
1684 | if (find_font (font) < 0) |
1746 | if (find_font (font) < 0) |
1685 | { |
1747 | { |
1686 | char fontname[4096]; |
1748 | char fontname[4096]; |
1687 | sprintf (fontname, "xft:%-.4090s", font); |
1749 | snprintf (fontname, sizeof (fontname), "xft:%s", font); |
1688 | |
1750 | |
1689 | fonts.push_back (new_font (fontname, CS_UNICODE)); |
1751 | push_font (new_font (fontname, CS_UNICODE)); |
1690 | } |
1752 | } |
1691 | |
1753 | |
1692 | free (font); |
1754 | free (font); |
1693 | } |
1755 | } |
1694 | #endif |
1756 | #endif |
… | |
… | |
1716 | } |
1778 | } |
1717 | |
1779 | |
1718 | return i; |
1780 | return i; |
1719 | } |
1781 | } |
1720 | |
1782 | |
1721 | |
|
|
1722 | |
|
|