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.122 by ayin, Wed Oct 31 09:55:24 2007 UTC vs.
Revision 1.125 by ayin, Sun Nov 25 11:23:18 2007 UTC

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;
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines