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.121 by ayin, Sun Oct 28 11:25:04 2007 UTC vs.
Revision 1.125 by ayin, Sun Nov 25 11:23:18 2007 UTC

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" },
231void 231void
232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const 232rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const
233{ 233{
234 dTermDisplay; 234 dTermDisplay;
235 dTermGC; 235 dTermGC;
236 236
237 if (color == Color_bg || color == Color_transparent) 237 if (color == Color_bg || color == Color_transparent)
238 XClearArea (disp, d, x, y, w, h, false); 238 XClearArea (disp, d, x, y, w, h, false);
239 else if (color >= 0) 239 else if (color >= 0)
240 { 240 {
241#if XFT 241#if XFT
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; 252 done = true;
253 } 253 }
254 } 254 }
255#endif 255#endif
256 if (!done) 256 if (!done)
257 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h); 257 XftDrawRect (d, &term->pix_colors[color].c, x, y, w, h);
258#else 258#else
259 XSetForeground (disp, gc, term->pix_colors[color]); 259 XSetForeground (disp, gc, term->pix_colors[color]);
260 XFillRectangle (disp, d, gc, x, y, w, h); 260 XFillRectangle (disp, d, gc, x, y, w, h);
262 } 262 }
263} 263}
264 264
265///////////////////////////////////////////////////////////////////////////// 265/////////////////////////////////////////////////////////////////////////////
266 266
267#include "table/linedraw.h"
268
269struct rxvt_font_default : rxvt_font { 267struct rxvt_font_default : rxvt_font {
270 struct rxvt_fontset *fs; 268 struct rxvt_fontset *fs;
271 269
272 rxvt_font_default (rxvt_fontset *fs) 270 rxvt_font_default (rxvt_fontset *fs)
273 : rxvt_font () 271 : rxvt_font ()
308 return false; 306 return false;
309 307
310 if (unicode <= 0x009f) 308 if (unicode <= 0x009f)
311 return true; 309 return true;
312 310
311#ifdef BUILTIN_GLYPHS
313 if (unicode >= 0x2500 && unicode <= 0x259f && 312 if (unicode >= 0x2500 && unicode <= 0x259f &&
314 !term->option (Opt_skipBuiltinGlyphs)) 313 !term->option (Opt_skipBuiltinGlyphs))
315 return true; 314 return true;
315#endif
316 316
317 if (IS_COMPOSE (unicode)) 317 if (IS_COMPOSE (unicode))
318 return true; 318 return true;
319 319
320 switch (unicode) 320 switch (unicode)
356 ; 356 ;
357 357
358 int width = text - tp; 358 int width = text - tp;
359 int fwidth = term->fwidth * width; 359 int fwidth = term->fwidth * width;
360 360
361#ifdef BUILTIN_GLYPHS
361 if (0x2500 <= t && t <= 0x259f) 362 if (0x2500 <= t && t <= 0x259f)
362 { 363 {
364# include "table/linedraw.h"
363 uint16_t offs = linedraw_offs[t - 0x2500]; 365 uint16_t offs = linedraw_offs[t - 0x2500];
364 uint32_t *a = linedraw_command + (offs >> 4); 366 uint32_t *a = linedraw_command + (offs >> 4);
365 uint32_t *b = a + (offs & 15); 367 uint32_t *b = a + (offs & 15);
366 368
367 int W = fwidth; 369 int W = fwidth;
405 407
406 case 1: // rectangle, possibly stippled 408 case 1: // rectangle, possibly stippled
407 if (a) 409 if (a)
408 { 410 {
409 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 }; 411 static char bm[] = { 0,0 , 3,1 , 1,2 , 1,0 };
410 412
411 gcv.fill_style = FillStippled; 413 gcv.fill_style = FillStippled;
412 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2); 414 gcv.stipple = XCreateBitmapFromData (disp, d, bm + a * 2, 2, 2);
413 gcv.ts_x_origin = x; 415 gcv.ts_x_origin = x;
414 gcv.ts_y_origin = y; 416 gcv.ts_y_origin = y;
415 417
434 (a - 1) * 90*64, (b - 1) * 90*64); 436 (a - 1) * 90*64, (b - 1) * 90*64);
435 break; 437 break;
436 } 438 }
437 } 439 }
438 } 440 }
441#else
442 if (0)
443 ;
444#endif
439#if ENABLE_COMBINING 445#if ENABLE_COMBINING
440 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t])) 446 else if (IS_COMPOSE (t) && (cc = rxvt_composite[t]))
441 { 447 {
442 min_it (width, 2); // we only support wcwidth up to 2 448 min_it (width, 2); // we only support wcwidth up to 2
443 449
604 return false; 610 return false;
605} 611}
606 612
607// fix the size of scalable fonts 613// fix the size of scalable fonts
608static bool 614static bool
609replace_field (char *buf, const char *name, int index, const char old, const char *replace) 615replace_field (char **ptr, const char *name, int index, const char old, const char *replace)
610{ 616{
611 int slashes = 0; 617 int slashes = 0;
612 const char *field, *end; 618 const char *field, *end;
613 619
614 for (const char *c = name; *c; c++) 620 for (const char *c = name; *c; c++)
624 break; 630 break;
625 } 631 }
626 632
627 if (slashes >= 13 && (!old || *field == old)) 633 if (slashes >= 13 && (!old || *field == old))
628 { 634 {
629 // TODO: check for overflow in font-name 635 size_t len = field - name;
636 *ptr = (char *)malloc (len + strlen (replace) + strlen (end) + 1);
630 strncpy (buf, name, field - name); 637 strncpy (*ptr, name, len);
631 buf += field - name;
632 strcpy (buf, replace); 638 strcpy (*ptr + len, replace);
633 strcat (buf, end); 639 strcat (*ptr, end);
634 640
635 return true; 641 return true;
636 } 642 }
637 else 643 else
638 { 644 {
639 strcpy (buf, name); 645 *ptr = strdup (name);
640 646
641 return false; 647 return false;
642 } 648 }
643} 649}
644 650
652 char field_str[64]; // enough for 128 bits 658 char field_str[64]; // enough for 128 bits
653 659
654 // first morph the font if required 660 // first morph the font if required
655 if (force_prop) 661 if (force_prop)
656 { 662 {
657 char fname[1024]; 663 char *fname;
658 664
659 if (name[0] != '-') 665 if (name[0] != '-')
660 { 666 {
661 f = XLoadQueryFont (disp, name); 667 f = XLoadQueryFont (disp, name);
662 668
674 f = 0; 680 f = 0;
675 } 681 }
676 682
677 if (prop.weight != rxvt_fontprop::unset) 683 if (prop.weight != rxvt_fontprop::unset)
678 { 684 {
679 replace_field (fname, name, 2, 0, 685 replace_field (&fname, name, 2, 0,
680 prop.weight < rxvt_fontprop::bold 686 prop.weight < rxvt_fontprop::bold
681 ? "medium" : "bold"); 687 ? "medium" : "bold");
682 set_name (strdup (fname)); 688 set_name (fname);
683 } 689 }
684 690
685 if (prop.slant != rxvt_fontprop::unset) 691 if (prop.slant != rxvt_fontprop::unset)
686 { 692 {
687 replace_field (fname, name, 3, 0, 693 replace_field (&fname, name, 3, 0,
688 prop.slant < rxvt_fontprop::italic 694 prop.slant < rxvt_fontprop::italic
689 ? "r" : "i"); // TODO: handle "o"blique, too 695 ? "r" : "i"); // TODO: handle "o"blique, too
690 set_name (strdup (fname)); 696 set_name (fname);
691 } 697 }
692 } 698 }
693 699
694 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset 700 sprintf (field_str, "%d", prop.height == rxvt_fontprop::unset
695 ? 0 : prop.height); 701 ? 0 : prop.height);
720 font_weight *fonts = new font_weight[count]; 726 font_weight *fonts = new font_weight[count];
721 727
722 for (int i = 0; i < count; i++) 728 for (int i = 0; i < count; i++)
723 { 729 {
724 rxvt_fontprop p; 730 rxvt_fontprop p;
725 char fname[1024]; 731 char *fname;
726 732
727 int diff = 0; 733 int diff = 0;
728 734
729 if (replace_field (fname, list[i], 6, '0', field_str)) 735 if (replace_field (&fname, list[i], 6, '0', field_str))
730 diff += 10; // slightly penalize scalable fonts 736 diff += 10; // slightly penalize scalable fonts
737 else
738 {
739 free (fname);
731 else if (replace_field (fname, list[i], 11, '0', "0")) 740 if (replace_field (&fname, list[i], 11, '0', "0"))
732 diff += 300; // more heavily penalize what looks like scaled bitmap fonts 741 diff += 300; // more heavily penalize what looks like scaled bitmap fonts
742 }
733 743
734 if (!set_properties (p, fname)) 744 if (!set_properties (p, fname))
735 continue; 745 continue;
736 746
737 if (prop.height != rxvt_fontprop::unset 747 if (prop.height != rxvt_fontprop::unset
741 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128; 751 if (prop.height != rxvt_fontprop::unset) diff += (prop.height - p.height) * 128;
742 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight); 752 if (prop.weight != rxvt_fontprop::unset) diff += abs (prop.weight - p.weight);
743 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant); 753 if (prop.slant != rxvt_fontprop::unset) diff += abs (prop.slant - p.slant);
744 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width); 754 //if (prop.width != rxvt_fontprop::unset) diff += abs (prop.width - p.width);
745 755
746 fonts[i].name = strdup (fname); 756 fonts[i].name = fname;
747 fonts[i].diff = diff; 757 fonts[i].diff = diff;
748 } 758 }
749 759
750 XFreeFontNames (list); 760 XFreeFontNames (list);
751 761
828 int N = f->max_char_or_byte2 - f->min_char_or_byte2; 838 int N = f->max_char_or_byte2 - f->min_char_or_byte2;
829 839
830 if (encm) 840 if (encm)
831 N += (f->max_byte1 - f->min_byte1) 841 N += (f->max_byte1 - f->min_byte1)
832 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1); 842 * (f->max_char_or_byte2 - f->min_char_or_byte2 + 1);
833 843
834 while (N) 844 while (N)
835 { 845 {
836 if (f->per_char[N].width > width) 846 if (f->per_char[N].width > width)
837 width = f->per_char[N].width; 847 width = f->per_char[N].width;
838 848
990 else 1000 else
991 { 1001 {
992 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1002 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
993 1003
994 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1004 XChangeGC (disp, gc, GCForeground | GCFont, &v);
995 1005
996 if (slow) 1006 if (slow)
997 { 1007 {
998 do 1008 do
999 { 1009 {
1000 if (xc->byte1 || xc->byte2) 1010 if (xc->byte1 || xc->byte2)
1022 else 1032 else
1023 { 1033 {
1024 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg); 1034 clear_rect (d, x, y, term->fwidth * len, term->fheight, bg);
1025 1035
1026 XChangeGC (disp, gc, GCForeground | GCFont, &v); 1036 XChangeGC (disp, gc, GCForeground | GCFont, &v);
1027 1037
1028 if (slow) 1038 if (slow)
1029 { 1039 {
1030 do 1040 do
1031 { 1041 {
1032 if (*xc) 1042 if (*xc)
1288 1298
1289 int w = term->fwidth * len; 1299 int w = term->fwidth * len;
1290 int h = term->fheight; 1300 int h = term->fheight;
1291 1301
1292 /* TODO: this logic needs some more thinking, since we no longer do pseudo-transparency. 1302 /* 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 1303 * 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. 1304 * good idea from the perspective of packaging for wide variety of user configs.
1295 */ 1305 */
1296 bool buffered = true 1306 bool buffered = true
1297#ifdef FORCE_UNBUFFERED_XFT 1307#ifdef FORCE_UNBUFFERED_XFT
1298 && bg >= 0 1308 && bg >= 0
1310 int cwidth = term->fwidth; 1320 int cwidth = term->fwidth;
1311 FcChar32 fc = *text++; len--; 1321 FcChar32 fc = *text++; len--;
1312 1322
1313 while (len && *text == NOCHAR) 1323 while (len && *text == NOCHAR)
1314 text++, len--, cwidth += term->fwidth; 1324 text++, len--, cwidth += term->fwidth;
1315 1325
1316 if (fc != ' ') // skip spaces 1326 if (fc != ' ') // skip spaces
1317 { 1327 {
1318 FT_UInt glyph = XftCharIndex (disp, f, fc); 1328 FT_UInt glyph = XftCharIndex (disp, f, fc);
1319 XftGlyphExtents (disp, f, &glyph, 1, &extents); 1329 XftGlyphExtents (disp, f, &glyph, 1, &extents);
1320 1330
1343 { 1353 {
1344 Picture dst = 0; 1354 Picture dst = 0;
1345 1355
1346 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00) 1356 if (bg >= 0 && term->pix_colors[bg].c.color.alpha < 0x0ff00)
1347 dst = XftDrawPicture (d2); 1357 dst = XftDrawPicture (d2);
1348 1358
1349 if (bg < 0 || dst != 0) 1359 if (bg < 0 || dst != 0)
1350 { 1360 {
1351 int src_x = x, src_y = y ; 1361 int src_x = x, src_y = y ;
1352 1362
1353 if (term->bgPixmap.is_parentOrigin ()) 1363 if (term->bgPixmap.is_parentOrigin ())
1354 { 1364 {
1355 src_x += term->window_vt_x; 1365 src_x += term->window_vt_x;
1356 src_y += term->window_vt_y; 1366 src_y += term->window_vt_y;
1357 } 1367 }
1358 1368
1359 if (term->bgPixmap.pmap_width >= src_x+w 1369 if (term->bgPixmap.pmap_width >= src_x+w
1360 && term->bgPixmap.pmap_height >= src_y+h) 1370 && term->bgPixmap.pmap_height >= src_y+h)
1361 { 1371 {
1362 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc, 1372 XCopyArea (disp, term->bgPixmap.pixmap, d2, gc,
1363 src_x, src_y, w, h, 0, 0); 1373 src_x, src_y, w, h, 0, 0);
1445 1455
1446rxvt_font * 1456rxvt_font *
1447rxvt_fontset::new_font (const char *name, codeset cs) 1457rxvt_fontset::new_font (const char *name, codeset cs)
1448{ 1458{
1449 rxvt_font *f; 1459 rxvt_font *f;
1450 1460
1451 if (!name || !*name) 1461 if (!name || !*name)
1452 { 1462 {
1453 name = ""; 1463 name = "";
1454 f = new rxvt_font_default (this); 1464 f = new rxvt_font_default (this);
1455 } 1465 }
1674 if (find_font (font) < 0) 1684 if (find_font (font) < 0)
1675 { 1685 {
1676 char fontname[4096]; 1686 char fontname[4096];
1677 sprintf (fontname, "xft:%-.4090s", font); 1687 sprintf (fontname, "xft:%-.4090s", font);
1678 1688
1679 fonts.push_back (new_font (fontname, CS_UNICODE)); 1689 fonts.push_back (new_font (fontname, CS_UNICODE));
1680 } 1690 }
1681 1691
1682 free (font); 1692 free (font);
1683 } 1693 }
1684#endif 1694#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines