Mercurial > emacs
comparison src/xfaces.c @ 26594:f24bdf26ad39
(set_lface_from_font_name): New parameter may_fail_p.
Callers changed. If specified font name is bogus, and mail_fail_p
is set, try to use a reasonable default.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 25 Nov 1999 15:00:15 +0000 |
parents | 5510d0cc07c3 |
children | e23e3120d84f |
comparison
equal
deleted
inserted
replaced
26593:880b9764ac5d | 26594:f24bdf26ad39 |
---|---|
459 int, int)); | 459 int, int)); |
460 static void merge_face_vectors P_ ((Lisp_Object *from, Lisp_Object *)); | 460 static void merge_face_vectors P_ ((Lisp_Object *from, Lisp_Object *)); |
461 static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *, | 461 static void merge_face_vector_with_property P_ ((struct frame *, Lisp_Object *, |
462 Lisp_Object)); | 462 Lisp_Object)); |
463 static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object, char *, | 463 static int set_lface_from_font_name P_ ((struct frame *, Lisp_Object, char *, |
464 int)); | 464 int, int)); |
465 static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int)); | 465 static Lisp_Object lface_from_face_name P_ ((struct frame *, Lisp_Object, int)); |
466 static struct face *make_realized_face P_ ((Lisp_Object *, int, Lisp_Object)); | 466 static struct face *make_realized_face P_ ((Lisp_Object *, int, Lisp_Object)); |
467 static void free_realized_faces P_ ((struct face_cache *)); | 467 static void free_realized_faces P_ ((struct face_cache *)); |
468 static char *best_matching_font P_ ((struct frame *, Lisp_Object *, | 468 static char *best_matching_font P_ ((struct frame *, Lisp_Object *, |
469 struct font_name *, int)); | 469 struct font_name *, int)); |
2703 | 2703 |
2704 #ifdef HAVE_X_WINDOWS | 2704 #ifdef HAVE_X_WINDOWS |
2705 | 2705 |
2706 /* Set font-related attributes of Lisp face LFACE from XLFD font name | 2706 /* Set font-related attributes of Lisp face LFACE from XLFD font name |
2707 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of | 2707 FONT_NAME. If FORCE_P is zero, set only unspecified attributes of |
2708 LFACE. Ignore fields of FONT_NAME containing wildcards. Value is | 2708 LFACE. MAY_FAIL_P non-zero means return 0 if FONT_NAME isn't a |
2709 zero if not successful because FONT_NAME was not in a valid format. | 2709 valid font name; otherwise this function tries to use a reasonable |
2710 A valid format is one that is suitable for split_font_name, see the | 2710 default font. |
2711 comment there. */ | 2711 |
2712 Ignore fields of FONT_NAME containing wildcards. Value is zero if | |
2713 not successful because FONT_NAME was not in a valid format and | |
2714 MAY_FAIL_P was non-zero. A valid format is one that is suitable | |
2715 for split_font_name, see the comment there. */ | |
2712 | 2716 |
2713 static int | 2717 static int |
2714 set_lface_from_font_name (f, lface, font_name, force_p) | 2718 set_lface_from_font_name (f, lface, font_name, force_p, may_fail_p) |
2715 struct frame *f; | 2719 struct frame *f; |
2716 Lisp_Object lface; | 2720 Lisp_Object lface; |
2717 char *font_name; | 2721 char *font_name; |
2718 int force_p; | 2722 int force_p, may_fail_p; |
2719 { | 2723 { |
2720 struct font_name font; | 2724 struct font_name font; |
2721 char *buffer; | 2725 char *buffer; |
2722 int pt; | 2726 int pt; |
2723 int free_font_name_p = 0; | 2727 int free_font_name_p = 0; |
2728 int have_font_p = 0; | |
2724 | 2729 |
2725 /* If FONT_NAME contains wildcards, use the first matching font. */ | 2730 /* If FONT_NAME contains wildcards, use the first matching font. */ |
2726 if (index (font_name, '*') || index (font_name, '?')) | 2731 if (index (font_name, '*') || index (font_name, '?')) |
2727 { | 2732 { |
2728 if (!first_font_matching (f, font_name, &font)) | 2733 if (first_font_matching (f, font_name, &font)) |
2729 return 0; | 2734 free_font_name_p = have_font_p = 1; |
2730 free_font_name_p = 1; | |
2731 } | 2735 } |
2732 else | 2736 else |
2733 { | 2737 { |
2734 font.name = STRDUPA (font_name); | 2738 font.name = STRDUPA (font_name); |
2735 if (!split_font_name (f, &font, 1)) | 2739 if (!split_font_name (f, &font, 1)) |
2740 | 2744 |
2741 BLOCK_INPUT; | 2745 BLOCK_INPUT; |
2742 font_info = fs_load_font (f, FRAME_X_FONT_TABLE (f), | 2746 font_info = fs_load_font (f, FRAME_X_FONT_TABLE (f), |
2743 CHARSET_ASCII, font_name, -1); | 2747 CHARSET_ASCII, font_name, -1); |
2744 UNBLOCK_INPUT; | 2748 UNBLOCK_INPUT; |
2745 | 2749 |
2746 if (!font_info) | 2750 if (font_info) |
2747 return 0; | 2751 { |
2748 | 2752 font.name = STRDUPA (font_info->full_name); |
2749 font.name = STRDUPA (font_info->full_name); | 2753 split_font_name (f, &font, 1); |
2750 split_font_name (f, &font, 1); | 2754 have_font_p = 1; |
2755 } | |
2751 } | 2756 } |
2757 } | |
2758 | |
2759 /* If FONT_NAME is completely bogus try to use something reasonable | |
2760 if this function must succeed. Otherwise, give up. */ | |
2761 if (!have_font_p) | |
2762 { | |
2763 if (may_fail_p) | |
2764 return 0; | |
2765 else if (first_font_matching (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1", | |
2766 &font) | |
2767 || first_font_matching (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", | |
2768 &font) | |
2769 || first_font_matching (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", | |
2770 &font) | |
2771 || first_font_matching (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1", | |
2772 &font) | |
2773 || first_font_matching (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1", | |
2774 &font) | |
2775 || first_font_matching (f, "fixed", &font)) | |
2776 free_font_name_p = 1; | |
2777 else | |
2778 abort (); | |
2779 } | |
2752 | 2780 |
2753 /* FONT_NAME should not be a fontset name, here. */ | |
2754 xassert (xstricmp (font.fields[XLFD_REGISTRY], "fontset") != 0); | |
2755 } | |
2756 | 2781 |
2757 /* Set attributes only if unspecified, otherwise face defaults for | 2782 /* Set attributes only if unspecified, otherwise face defaults for |
2758 new frames would never take effect. */ | 2783 new frames would never take effect. */ |
2759 | 2784 |
2760 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface))) | 2785 if (force_p || UNSPECIFIEDP (LFACE_FAMILY (lface))) |
3408 if (EQ (frame, Qt)) | 3433 if (EQ (frame, Qt)) |
3409 f = SELECTED_FRAME (); | 3434 f = SELECTED_FRAME (); |
3410 else | 3435 else |
3411 f = check_x_frame (frame); | 3436 f = check_x_frame (frame); |
3412 | 3437 |
3413 if (!set_lface_from_font_name (f, lface, XSTRING (value)->data, 1)) | 3438 if (!set_lface_from_font_name (f, lface, XSTRING (value)->data, 1, 1)) |
3414 signal_error ("Invalid font name", value); | 3439 signal_error ("Invalid font name", value); |
3415 | 3440 |
3416 font_related_attr_p = 1; | 3441 font_related_attr_p = 1; |
3417 #endif /* HAVE_X_WINDOWS */ | 3442 #endif /* HAVE_X_WINDOWS */ |
3418 } | 3443 } |
5524 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII, | 5549 font_info = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII, |
5525 NULL, fontset); | 5550 NULL, fontset); |
5526 UNBLOCK_INPUT; | 5551 UNBLOCK_INPUT; |
5527 | 5552 |
5528 /* Set weight etc. from the ASCII font. */ | 5553 /* Set weight etc. from the ASCII font. */ |
5529 if (!set_lface_from_font_name (f, lface, font_info->full_name, 0)) | 5554 if (!set_lface_from_font_name (f, lface, font_info->full_name, 0, 0)) |
5530 return 0; | 5555 return 0; |
5531 | 5556 |
5532 /* Remember registry and encoding of the frame font. */ | 5557 /* Remember registry and encoding of the frame font. */ |
5533 unibyte_registry = deduce_unibyte_registry (f, font_info->full_name); | 5558 unibyte_registry = deduce_unibyte_registry (f, font_info->full_name); |
5534 if (STRINGP (unibyte_registry)) | 5559 if (STRINGP (unibyte_registry)) |
5552 else | 5577 else |
5553 { | 5578 { |
5554 /* Frame parameters contain a real font. Fill default face | 5579 /* Frame parameters contain a real font. Fill default face |
5555 attributes from that font. */ | 5580 attributes from that font. */ |
5556 if (!set_lface_from_font_name (f, lface, | 5581 if (!set_lface_from_font_name (f, lface, |
5557 XSTRING (frame_font)->data, 0)) | 5582 XSTRING (frame_font)->data, 0, 0)) |
5558 return 0; | 5583 return 0; |
5559 | 5584 |
5560 /* Remember registry and encoding of the frame font. */ | 5585 /* Remember registry and encoding of the frame font. */ |
5561 unibyte_registry | 5586 unibyte_registry |
5562 = deduce_unibyte_registry (f, XSTRING (frame_font)->data); | 5587 = deduce_unibyte_registry (f, XSTRING (frame_font)->data); |