comparison src/xfaces.c @ 3065:fff06093b756

* xfns.c (Fx_list_fonts): New function. (same_size_fonts): Function moved here from xfaces.c. (face_name_id_number): Add extern declaration for this. * xfaces.c (same_size_fonts): Moved to xfns.c. Left an extern declaration behind. (face_name_id_number): Make this externally visible, and make the FRAME argument a FRAME_PTR, not a Lisp_Object. (compute_char_face): Call face_name_id_number properly. * xfaces.c (unload_color): Don't free the pixel for now. * xfaces.c (merge_faces): You can't tell if a font is a character-cell font or not by testing whether or not it has a per_char table. They all do.
author Jim Blandy <jimb@redhat.com>
date Tue, 25 May 1993 06:59:12 +0000
parents 885e08ef0577
children 96b4623fdeb3
comparison
equal deleted inserted replaced
3064:fa5466904709 3065:fff06093b756
134 int next_face_id; 134 int next_face_id;
135 135
136 /* The number of the face to use to indicate the region. */ 136 /* The number of the face to use to indicate the region. */
137 int region_face; 137 int region_face;
138 138
139 /* Return non-zero if FONT1 and FONT2 have the same size bounding box.
140 We assume that they're both character-cell fonts. */
141 extern int same_size_fonts ();
142
139 /* This is what appears in a slot in a face to signify that the face 143 /* This is what appears in a slot in a face to signify that the face
140 does not specify that display aspect. */ 144 does not specify that display aspect. */
141 #define FACE_DEFAULT (~0) 145 #define FACE_DEFAULT (~0)
142 146
143 Lisp_Object Qface, Qwindow, Qpriority; 147 Lisp_Object Qface, Qwindow, Qpriority;
144 148
145 static void build_face (); 149 static void build_face ();
146 static Lisp_Object face_name_id_number (); 150 int face_name_id_number ();
147 151
148 struct face *intern_face (); 152 struct face *intern_face ();
149 static void ensure_face_ready (); 153 static void ensure_face_ready ();
150 154
151 /* Allocating, copying, and comparing struct faces. */ 155 /* Allocating, copying, and comparing struct faces. */
404 static void 408 static void
405 unload_color (f, pixel) 409 unload_color (f, pixel)
406 struct frame *f; 410 struct frame *f;
407 Pixel pixel; 411 Pixel pixel;
408 { 412 {
413 /* Since faces get built by copying parameters from other faces, the
414 allocation counts for the colors get all screwed up. I don't see
415 any solution that will take less than 10 minutes, and it's better
416 to have a color leak than a crash, so I'm just dyking this out.
417 This isn't really a color leak, anyway - if we ask for it again,
418 we'll get the same pixel. */
419 #if 0
409 Colormap cmap; 420 Colormap cmap;
410 Display *dpy = x_current_display; 421 Display *dpy = x_current_display;
411 if (pixel == FACE_DEFAULT 422 if (pixel == FACE_DEFAULT
412 || pixel == BLACK_PIX_DEFAULT 423 || pixel == BLACK_PIX_DEFAULT
413 || pixel == WHITE_PIX_DEFAULT) 424 || pixel == WHITE_PIX_DEFAULT)
414 return; 425 return;
415 cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display)); 426 cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display));
416 BLOCK_INPUT; 427 BLOCK_INPUT;
417 XFreeColors (dpy, cmap, &pixel, 1, 0); 428 XFreeColors (dpy, cmap, &pixel, 1, 0);
418 UNBLOCK_INPUT; 429 UNBLOCK_INPUT;
430 #endif
419 } 431 }
420 432
421 /* Initializing face arrays for frames. */ 433 /* Initializing face arrays for frames. */
422 434
423 /* Set up faces 0 and 1 based on the normal text and modeline GC's. 435 /* Set up faces 0 and 1 based on the normal text and modeline GC's.
550 FRAME_FACES (f) [id] = allocate_face (); 562 FRAME_FACES (f) [id] = allocate_face ();
551 } 563 }
552 564
553 /* Computing faces appropriate for a given piece of text in a buffer. */ 565 /* Computing faces appropriate for a given piece of text in a buffer. */
554 566
555 /* Return non-zero if FONT1 and FONT2 have the same size bounding box.
556 We assume that they're both character-cell fonts. */
557 static int
558 same_size_fonts (font1, font2)
559 XFontStruct *font1, *font2;
560 {
561 XCharStruct *bounds1 = &font1->min_bounds;
562 XCharStruct *bounds2 = &font2->min_bounds;
563
564 return (bounds1->width == bounds2->width
565 && bounds1->ascent == bounds2->ascent
566 && bounds1->descent == bounds2->descent);
567 }
568
569
570 /* Modify face TO by copying from FROM all properties which have 567 /* Modify face TO by copying from FROM all properties which have
571 nondefault settings. */ 568 nondefault settings. */
572 static void 569 static void
573 merge_faces (from, to) 570 merge_faces (from, to)
574 struct face *from, *to; 571 struct face *from, *to;
575 { 572 {
576 /* Only merge the font if it's the same size as the base font. */ 573 /* Only merge the font if it's the same size as the base font. */
577 if (from->font != (XFontStruct *) FACE_DEFAULT 574 if (from->font != (XFontStruct *) FACE_DEFAULT
578 && ! from->font->per_char
579 && same_size_fonts (from->font, to->font)) 575 && same_size_fonts (from->font, to->font))
580 to->font = from->font; 576 to->font = from->font;
581 if (from->foreground != FACE_DEFAULT) 577 if (from->foreground != FACE_DEFAULT)
582 to->foreground = from->foreground; 578 to->foreground = from->foreground;
583 if (from->background != FACE_DEFAULT) 579 if (from->background != FACE_DEFAULT)
687 bcopy (FRAME_DEFAULT_FACE (f), &face, sizeof (struct face)); 683 bcopy (FRAME_DEFAULT_FACE (f), &face, sizeof (struct face));
688 face.gc = 0; 684 face.gc = 0;
689 685
690 if (!NILP (prop)) 686 if (!NILP (prop))
691 { 687 {
692 facecode = face_name_id_number (frame, prop); 688 facecode = face_name_id_number (f, prop);
693 if (facecode >= 0 && facecode < FRAME_N_FACES (f) 689 if (facecode >= 0 && facecode < FRAME_N_FACES (f)
694 && FRAME_FACES (f) [facecode] != 0) 690 && FRAME_FACES (f) [facecode] != 0)
695 merge_faces (FRAME_FACES (f) [facecode], &face); 691 merge_faces (FRAME_FACES (f) [facecode], &face);
696 } 692 }
697 693
744 if (!NILP (prop)) 740 if (!NILP (prop))
745 { 741 {
746 Lisp_Object oend; 742 Lisp_Object oend;
747 int oendpos; 743 int oendpos;
748 744
749 facecode = face_name_id_number (frame, prop); 745 facecode = face_name_id_number (f, prop);
750 if (facecode >= 0 && facecode < FRAME_N_FACES (f) 746 if (facecode >= 0 && facecode < FRAME_N_FACES (f)
751 && FRAME_FACES (f) [facecode] != 0) 747 && FRAME_FACES (f) [facecode] != 0)
752 merge_faces (FRAME_FACES (f) [facecode], &face); 748 merge_faces (FRAME_FACES (f) [facecode], &face);
753 749
754 oend = OVERLAY_END (sortvec[i].overlay); 750 oend = OVERLAY_END (sortvec[i].overlay);
947 /* Return the face id for name NAME on frame FRAME. 943 /* Return the face id for name NAME on frame FRAME.
948 (It should be the same for all frames, 944 (It should be the same for all frames,
949 but it's as easy to use the "right" frame to look it up 945 but it's as easy to use the "right" frame to look it up
950 as to use any other one.) */ 946 as to use any other one.) */
951 947
952 static Lisp_Object 948 int
953 face_name_id_number (frame, name) 949 face_name_id_number (f, name)
954 Lisp_Object frame, name; 950 FRAME_PTR f;
951 Lisp_Object name;
955 { 952 {
956 Lisp_Object tem; 953 Lisp_Object tem;
957 954
958 CHECK_FRAME (frame, 0); 955 tem = Fcdr (Fassq (name, f->face_alist));
959 tem = Fcdr (Fassq (name, XFRAME (frame)->face_alist));
960 if (NILP (tem)) 956 if (NILP (tem))
961 return 0; 957 return 0;
962 CHECK_VECTOR (tem, 0); 958 CHECK_VECTOR (tem, 0);
963 tem = XVECTOR (tem)->contents[2]; 959 tem = XVECTOR (tem)->contents[2];
964 CHECK_NUMBER (tem, 0); 960 CHECK_NUMBER (tem, 0);