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.173 by root, Fri Jan 7 21:17:08 2011 UTC vs.
Revision 1.198 by root, Wed Jun 16 22:51:55 2021 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtfont.C 2 * File: rxvtfont.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * Copyright (c) 2003-2008 Marc Lehmann <pcg@goof.com> 4 * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de>
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 3 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22#include "../config.h" 22#include "../config.h"
23#include "rxvt.h" 23#include "rxvt.h"
24#include "rxvtutil.h" 24#include "rxvtutil.h"
25#include "rxvtfont.h" 25#include "rxvtfont.h"
26 26
27#include <cstdlib> 27#include <stdlib.h>
28 28
29#include <inttypes.h> 29#include <inttypes.h>
30 30
31#if XFT 31#if XFT
32# include <fontconfig/fontconfig.h> 32# include <fontconfig/fontconfig.h>
132 { CS_KSC5601_1987_0, "xft:Baekmuk Gulim:antialias=false" }, 132 { CS_KSC5601_1987_0, "xft:Baekmuk Gulim:antialias=false" },
133 { CS_KSC5601_1987_0, "xft::lang=ko:antialias=false" }, 133 { CS_KSC5601_1987_0, "xft::lang=ko:antialias=false" },
134# endif 134# endif
135#endif 135#endif
136 136
137 { CS_UNICODE, "-*-lucidatypewriter-*-*-*-*-*-*-*-*-m-*-iso10646-1" },
138 //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs. 137 //{ CS_UNICODE, "-*-unifont-*-*-*-*-*-*-*-*-c-*-iso10646-1" }, // this gem of a font has actual dotted circles within the combining character glyphs.
139#if XFT 138#if XFT
140 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" }, 139 { CS_UNICODE, "xft:Bitstream Vera Sans Mono:antialias=false:autohint=true" },
141 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" }, 140 { CS_UNICODE, "xft:Courier New:antialias=false:autohint=true" },
142 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" }, 141 { CS_UNICODE, "xft:Andale Mono:antialias=false:autohint=false" },
240 else if (color >= 0) 239 else if (color >= 0)
241 { 240 {
242#if XFT 241#if XFT
243 Picture dst; 242 Picture dst;
244 243
245# ifdef HAVE_BG_PIXMAP 244# ifdef HAVE_IMG
246 if (term->bgPixmap.pixmap 245 if (term->bg_img
247 && !term->pix_colors[color].is_opaque () 246 && !term->pix_colors[color].is_opaque ()
248 && ((dst = XftDrawPicture (d)))) 247 && ((dst = XftDrawPicture (d))))
249 { 248 {
250 XClearArea (disp, d, x, y, w, h, false); 249 XClearArea (disp, d, x, y, w, h, false);
251 250
475 case '\t': 474 case '\t':
476 case ZERO_WIDTH_CHAR: 475 case ZERO_WIDTH_CHAR:
477 case NOCHAR: 476 case NOCHAR:
478 break; 477 break;
479 478
479 /*
480 * If the base font does not support variation selectors, treat them as ZWC.
481 * a point could be made to do this for all wcwidth == 0 characters, but I
482 * decided against that until more data is available.
483 */
484 case 0xfe00: case 0xfe01: case 0xfe02: case 0xfe03: case 0xfe04: case 0xfe05: case 0xfe06: case 0xfe07:
485 case 0xfe08: case 0xfe09: case 0xfe0a: case 0xfe0b: case 0xfe0c: case 0xfe0d: case 0xfe0e: case 0xfe0f:
486 break;
487
480 default: 488 default:
481 XDrawRectangle (disp, d, gc, x + 2, y + 2, 489 XDrawRectangle (disp, d, gc, x + 2, y + 2,
482 fwidth - 4, term->fheight - 4); 490 fwidth - 4, term->fheight - 4);
483 } 491 }
484 492
524 532
525 void draw (rxvt_drawable &d, int x, int y, 533 void draw (rxvt_drawable &d, int x, int y,
526 const text_t *text, int len, 534 const text_t *text, int len,
527 int fg, int bg) 535 int fg, int bg)
528 { 536 {
529 while (len--) 537 while (len)
530 { 538 {
531 int fid = fs->find_font_idx (*text); 539 int fid = fs->find_font_idx (*text);
540 int w = 1;
541 while (w < len && text[w] == NOCHAR)
542 w++;
532 (*fs)[fid]->draw (d, x, y, text, 1, fg, bg); 543 (*fs)[fid]->draw (d, x, y, text, w, fg, bg);
533 ++text; 544 text += w;
545 len -= w;
534 x += term->fwidth; 546 x += term->fwidth * w;
535 } 547 }
536 } 548 }
537}; 549};
538 550
539///////////////////////////////////////////////////////////////////////////// 551/////////////////////////////////////////////////////////////////////////////
813 XFreeFontNames (list); 825 XFreeFontNames (list);
814 826
815 // this loop only iterates when the guessed font-size is too small 827 // this loop only iterates when the guessed font-size is too small
816 for (;;) 828 for (;;)
817 { 829 {
818 font_weight *best = fonts + count - 1; 830 font_weight *best = fonts;
819 831
820 for (font_weight *w = best; w-- > fonts; ) 832 for (font_weight *w = fonts + 1; w < fonts + count; w++)
821 if (w->diff <= best->diff) 833 if (w->diff < best->diff)
822 best = w; 834 best = w;
823 835
824 if (!best->name 836 if (!best->name
825 || !(f = XLoadQueryFont (disp, best->name))) 837 || !(f = XLoadQueryFont (disp, best->name)))
826 break; 838 break;
921 } 933 }
922#endif 934#endif
923 935
924 width = 1; 936 width = 1;
925 937
926 for (uint16_t *t = extent_test_chars + ARRAY_LENGTH(extent_test_chars); t-- > extent_test_chars; ) 938 for (uint16_t *t = extent_test_chars; t < extent_test_chars + ecb_array_length (extent_test_chars); t++)
927 { 939 {
928 if (FROM_UNICODE (cs, *t) == NOCHAR) 940 if (FROM_UNICODE (cs, *t) == NOCHAR)
929 continue; 941 continue;
930 942
931 // ignore characters we wouldn't use anyways 943 // ignore characters we wouldn't use anyways
932 bool careful; 944 bool careful;
933 if (!has_char (*t, &prop, careful)) 945 if (!has_char (*t, &prop, careful))
934 continue; 946 continue;
935 947
936 XChar2b ch = { *t >> 8, *t }; 948 // the casts are needed in C++11 (see 8.5.1)
949 XChar2b ch = { (unsigned char)(*t >> 8), (unsigned char)*t };
937 950
938 XCharStruct g; 951 XCharStruct g;
939 int dir_ret, asc_ret, des_ret; 952 int dir_ret, asc_ret, des_ret;
940 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g); 953 XTextExtents16 (f, &ch, 1, &dir_ret, &asc_ret, &des_ret, &g);
941 954
967} 980}
968 981
969bool 982bool
970rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const 983rxvt_font_x11::has_char (unicode_t unicode, const rxvt_fontprop *prop, bool &careful) const
971{ 984{
985 careful = false;
986
972 uint32_t ch = FROM_UNICODE (cs, unicode); 987 uint32_t ch = FROM_UNICODE (cs, unicode);
973 988
974 if (ch == NOCHAR) 989 if (ch == NOCHAR)
975 return false; 990 return false;
976 991
1039 dTermDisplay; 1054 dTermDisplay;
1040 dTermGC; 1055 dTermGC;
1041 1056
1042 bool slow = this->slow 1057 bool slow = this->slow
1043 || width != term->fwidth 1058 || width != term->fwidth
1044 || height != term->fheight; 1059 || height != term->fheight
1060 || ascent != f->ascent;
1045 1061
1046 int base = ascent; // sorry, incorrect: term->fbase; 1062 int base = ascent; // sorry, incorrect: term->fbase;
1047 1063
1048 XGCValues v; 1064 XGCValues v;
1049 v.foreground = term->pix_colors[fg]; 1065 v.foreground = term->pix_colors[fg];
1218 int ftheight = 0; 1234 int ftheight = 0;
1219 bool success = true; 1235 bool success = true;
1220 1236
1221 for (;;) 1237 for (;;)
1222 { 1238 {
1239 p = FcPatternDuplicate (match);
1223 f = XftFontOpenPattern (disp, FcPatternDuplicate (match)); 1240 f = XftFontOpenPattern (disp, p);
1224 1241
1225 if (!f) 1242 if (!f)
1226 { 1243 {
1244 FcPatternDestroy (p);
1227 success = false; 1245 success = false;
1228 break; 1246 break;
1229 } 1247 }
1230 1248
1231 FT_Face face = XftLockFace (f); 1249 FT_Face face = XftLockFace (f);
1239 1257
1240 XftUnlockFace (f); 1258 XftUnlockFace (f);
1241 1259
1242 int glheight = height; 1260 int glheight = height;
1243 1261
1244 for (uint16_t *t = extent_test_chars + ARRAY_LENGTH(extent_test_chars); t-- > extent_test_chars; ) 1262 for (uint16_t *t = extent_test_chars; t < extent_test_chars + ecb_array_length (extent_test_chars); t++)
1245 { 1263 {
1246 FcChar16 ch = *t; 1264 FcChar16 ch = *t;
1247 1265
1248 if (cs != CS_UNICODE 1266 if (cs != CS_UNICODE
1249 && ch > 0x100 1267 && ch > 0x100
1401 { 1419 {
1402 if (ep != enc) 1420 if (ep != enc)
1403 { 1421 {
1404 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h); 1422 rxvt_drawable &d2 = d.screen->scratch_drawable (w, h);
1405 1423
1406#ifdef HAVE_BG_PIXMAP 1424#ifdef HAVE_IMG
1407 Picture dst = 0; // the only assignment is done conditionally in the following if condition 1425 Picture dst = 0; // the only assignment is done conditionally in the following if condition
1408 1426
1409 if (term->bgPixmap.pixmap 1427 if (term->bg_img
1410 && (bg == Color_transparent || bg == Color_bg 1428 && (bg == Color_transparent || bg == Color_bg
1411 || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2)))))) 1429 || (bg >= 0 && !term->pix_colors[bg].is_opaque () && ((dst = XftDrawPicture (d2))))))
1412 { 1430 {
1413 int src_x = x, src_y = y; 1431 int src_x = x, src_y = y;
1414 1432
1415 if (term->bgPixmap.flags & bgPixmap_t::isTransparent) 1433 if (term->bg_flags & rxvt_term::BG_IS_TRANSPARENT)
1416 { 1434 {
1417 src_x += term->window_vt_x; 1435 src_x += term->window_vt_x;
1418 src_y += term->window_vt_y; 1436 src_y += term->window_vt_y;
1419 } 1437 }
1420 1438
1421 if (term->bgPixmap.pmap_width >= src_x + w 1439 if (term->bg_img->w >= src_x + w
1422 && term->bgPixmap.pmap_height >= src_y + h) 1440 && term->bg_img->h >= src_y + h)
1423 { 1441 {
1424 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, 1442 XCopyArea (disp, term->bg_img->pm, d2, gc,
1425 src_x, src_y, w, h, 0, 0); 1443 src_x, src_y, w, h, 0, 0);
1426 } 1444 }
1427 else 1445 else
1428 { 1446 {
1429 XGCValues gcv; 1447 XGCValues gcv;
1430 1448
1431 gcv.fill_style = FillTiled; 1449 gcv.fill_style = FillTiled;
1432 gcv.tile = term->bgPixmap.pixmap; 1450 gcv.tile = term->bg_img->pm;
1433 gcv.ts_x_origin = -src_x; 1451 gcv.ts_x_origin = -src_x;
1434 gcv.ts_y_origin = -src_y; 1452 gcv.ts_y_origin = -src_y;
1435 1453
1436 XChangeGC (disp, gc, 1454 XChangeGC (disp, gc,
1437 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle, 1455 GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
1597 cs = codeset_from_name (spec + sizeof ("codeset=") - 1); 1615 cs = codeset_from_name (spec + sizeof ("codeset=") - 1);
1598 else 1616 else
1599 rxvt_warn ("unknown parameter '%s' in font specification, skipping.\n", spec); 1617 rxvt_warn ("unknown parameter '%s' in font specification, skipping.\n", spec);
1600 1618
1601 desc++; 1619 desc++;
1602 while (*desc <= ' ') desc++; 1620 while (*desc <= ' ' && *desc) desc++;
1603 } 1621 }
1604 1622
1605 end = strchr (desc, ','); 1623 end = strchr (desc, ',');
1606 if (!end) 1624 if (!end)
1607 end = desc + strlen (desc); 1625 end = desc + strlen (desc);
1725 // way to configure this and xft is easier to hack in, 1743 // way to configure this and xft is easier to hack in,
1726 // while x11 has more framework in place already. 1744 // while x11 has more framework in place already.
1727 // TODO: this is a real resource hog, xft takes ages(?) 1745 // TODO: this is a real resource hog, xft takes ages(?)
1728#if XFT && USE_SLOW_LOOKUP 1746#if XFT && USE_SLOW_LOOKUP
1729 // grab the first xft font that seems suitable 1747 // grab the first xft font that seems suitable
1748 // TOOD: should go first for cellchar (spacing 110) then mono, then else
1730 FcPattern *p = FcPatternCreate (); 1749 FcPattern *p = FcPatternCreate ();
1731 1750
1732 FcCharSet *s = FcCharSetCreate (); 1751 FcCharSet *s = FcCharSetCreate ();
1733 FcCharSetAddChar (s, unicode); 1752 FcCharSetAddChar (s, unicode);
1734 FcPatternAddCharSet (p, FC_CHARSET, s); 1753 FcPatternAddCharSet (p, FC_CHARSET, s);
1778 while (hi >= fmap.size ()) 1797 while (hi >= fmap.size ())
1779 fmap.push_back (0); 1798 fmap.push_back (0);
1780 1799
1781 if (!fmap[hi]) 1800 if (!fmap[hi])
1782 { 1801 {
1783 fmap[hi] = (pagemap *)new pagemap; 1802 fmap[hi] = new pagemap;
1784 memset (fmap[hi], 0xff, sizeof (pagemap)); 1803 memset (fmap[hi], 0xff, sizeof (pagemap));
1785 } 1804 }
1786 1805
1787 (*fmap[hi])[unicode & 0xff] = i; 1806 (*fmap[hi])[unicode & 0xff] = i;
1788 } 1807 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines