comparison src/glyphs.c @ 5073:78a3c171a427

Fixes for bitmap mask files handling src/ChangeLog addition: 2010-02-24 Didier Verna <didier@xemacs.org> * glyphs.c: Clarify comment about potential_pixmap_file_instantiator. * glyphs.c (xbm_mask_file_munging): Clarify comment, remove unreachable condition and provide a cuple of assertions. * glyphs.c (xbm_normalize): Clarify comments, error on mask file not found. * glyphs.c (xface_normalize): Ditto, and handle inline data properly.
author Didier Verna <didier@lrde.epita.fr>
date Wed, 24 Feb 2010 11:08:30 +0100
parents ae48681c47fa
children 2a462149bd6a
comparison
equal deleted inserted replaced
5072:cc74f60c150e 5073:78a3c171a427
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois 2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois
3 Copyright (C) 1995 Tinker Systems 3 Copyright (C) 1995 Tinker Systems
4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004, 2005 Ben Wing 4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004, 2005 Ben Wing
5 Copyright (C) 1995 Sun Microsystems 5 Copyright (C) 1995 Sun Microsystems
6 Copyright (C) 1998, 1999, 2000 Andy Piper 6 Copyright (C) 1998, 1999, 2000 Andy Piper
7 Copyright (C) 2007 Didier Verna 7 Copyright (C) 2007, 2010 Didier Verna
8 8
9 This file is part of XEmacs. 9 This file is part of XEmacs.
10 10
11 XEmacs is free software; you can redistribute it and/or modify it 11 XEmacs is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the 12 under the terms of the GNU General Public License as published by the
2519 2519
2520 /************************************************************************/ 2520 /************************************************************************/
2521 /* pixmap file functions */ 2521 /* pixmap file functions */
2522 /************************************************************************/ 2522 /************************************************************************/
2523 2523
2524 /* If INSTANTIATOR refers to inline data, return Qt. 2524 /* - If INSTANTIATOR refers to inline data, or there is no file keyword, we
2525 If INSTANTIATOR refers to data in a file, return the full filename 2525 have nothing to do, so return Qt.
2526 if it exists, Qnil if there's no console method for locating the file, or 2526 - If INSTANTIATOR refers to data in a file, return the full filename
2527 (filename) if there was an error locating the file. 2527 if it exists; otherwise, return '(filename), meaning "file not found".
2528 - If there is no locate_pixmap_file method for this console, return Qnil.
2528 2529
2529 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the 2530 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
2530 keywords used to look up the file and inline data, 2531 keywords used to look up the file and inline data,
2531 respectively, in the instantiator. Normally these would 2532 respectively, in the instantiator. These would be Q_file and Q_data,
2532 be Q_file and Q_data, but might be different for mask data. */ 2533 Q_mask_file or Q_mask_data. */
2533 2534
2534 Lisp_Object 2535 Lisp_Object
2535 potential_pixmap_file_instantiator (Lisp_Object instantiator, 2536 potential_pixmap_file_instantiator (Lisp_Object instantiator,
2536 Lisp_Object file_keyword, 2537 Lisp_Object file_keyword,
2537 Lisp_Object data_keyword, 2538 Lisp_Object data_keyword,
2734 } 2735 }
2735 2736
2736 return Qnil; /* not reached */ 2737 return Qnil; /* not reached */
2737 } 2738 }
2738 2739
2740 /* This function attempts to find implicit mask files by appending "Mask" or
2741 "msk" to the original bitmap file name. This is more or less standard: a
2742 number of bitmaps in /usr/include/X11/bitmaps use it. */
2739 Lisp_Object 2743 Lisp_Object
2740 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file, 2744 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
2741 Lisp_Object mask_file, Lisp_Object console_type) 2745 Lisp_Object mask_file, Lisp_Object console_type)
2742 { 2746 {
2743 /* This is unclean but it's fairly standard -- a number of the 2747 /* Let's try to find an implicit mask file if we have neither an explicit
2744 bitmaps in /usr/include/X11/bitmaps use it -- so we support 2748 mask file name, nor inline mask data. Note that no errors are reported in
2745 it. */ 2749 case of failure because the mask file we're looking for might not
2746 if (EQ (mask_file, Qt) 2750 exist. */
2747 /* don't override explicitly specified mask data. */ 2751 if (EQ (mask_file, Qt) && NILP (assq_no_quit (Q_mask_data, alist)))
2748 && NILP (assq_no_quit (Q_mask_data, alist)) 2752 {
2749 && !EQ (file, Qt)) 2753 assert (!EQ (file, Qt) && !EQ (file, Qnil));
2750 {
2751 mask_file = MAYBE_LISP_CONTYPE_METH 2754 mask_file = MAYBE_LISP_CONTYPE_METH
2752 (decode_console_type(console_type, ERROR_ME), 2755 (decode_console_type(console_type, ERROR_ME),
2753 locate_pixmap_file, (concat2 (file, build_ascstring ("Mask")))); 2756 locate_pixmap_file, (concat2 (file, build_ascstring ("Mask"))));
2754 if (NILP (mask_file)) 2757 if (NILP (mask_file))
2755 mask_file = MAYBE_LISP_CONTYPE_METH 2758 mask_file = MAYBE_LISP_CONTYPE_METH
2756 (decode_console_type(console_type, ERROR_ME), 2759 (decode_console_type(console_type, ERROR_ME),
2757 locate_pixmap_file, (concat2 (file, build_ascstring ("msk")))); 2760 locate_pixmap_file, (concat2 (file, build_ascstring ("msk"))));
2758 } 2761 }
2759 2762
2763 /* We got a mask file, either explicitely or from the search above. */
2760 if (!NILP (mask_file)) 2764 if (!NILP (mask_file))
2761 { 2765 {
2762 Lisp_Object mask_data = 2766 Lisp_Object mask_data;
2763 bitmap_to_lisp_data (mask_file, 0, 0, 0); 2767
2768 assert (!EQ (mask_file, Qt));
2769
2770 mask_data = bitmap_to_lisp_data (mask_file, 0, 0, 0);
2764 alist = remassq_no_quit (Q_mask_file, alist); 2771 alist = remassq_no_quit (Q_mask_file, alist);
2765 /* there can't be a :mask-data at this point. */ 2772 /* there can't be a :mask-data at this point. */
2766 alist = Fcons (Fcons (Q_mask_file, mask_file), 2773 alist = Fcons (Fcons (Q_mask_file, mask_file),
2767 Fcons (Fcons (Q_mask_data, mask_data), alist)); 2774 Fcons (Fcons (Q_mask_data, mask_data), alist));
2768 } 2775 }
2774 2781
2775 static Lisp_Object 2782 static Lisp_Object
2776 xbm_normalize (Lisp_Object inst, Lisp_Object console_type, 2783 xbm_normalize (Lisp_Object inst, Lisp_Object console_type,
2777 Lisp_Object UNUSED (dest_mask)) 2784 Lisp_Object UNUSED (dest_mask))
2778 { 2785 {
2779 Lisp_Object file = Qnil, mask_file = Qnil; 2786 Lisp_Object file = Qnil, mask_file = Qnil, alist = Qnil;
2780 struct gcpro gcpro1, gcpro2, gcpro3; 2787 struct gcpro gcpro1, gcpro2, gcpro3;
2781 Lisp_Object alist = Qnil;
2782 2788
2783 GCPRO3 (file, mask_file, alist); 2789 GCPRO3 (file, mask_file, alist);
2784 2790
2785 /* Now, convert any file data into inline data for both the regular 2791 /* Now, convert any file data into inline data for both the regular
2786 data and the mask data. At the end of this, `data' will contain 2792 data and the mask data. At the end of this, `data' will contain
2794 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, 2800 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
2795 console_type); 2801 console_type);
2796 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file, 2802 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
2797 Q_mask_data, console_type); 2803 Q_mask_data, console_type);
2798 2804
2799 if (NILP (file)) /* normalization impossible for the console type */ 2805 /* No locate_pixmap_file method for this console type, so we can't get a
2806 file (neither a mask file BTW). */
2807 if (NILP (file))
2800 RETURN_UNGCPRO (Qnil); 2808 RETURN_UNGCPRO (Qnil);
2801 2809
2802 if (CONSP (file)) /* failure locating filename */ 2810 if (CONSP (file)) /* failure locating filename */
2803 signal_double_image_error ("Opening bitmap file", 2811 signal_double_image_error ("Opening bitmap file",
2804 "no such file or directory", 2812 "no such file or directory",
2805 Fcar (file)); 2813 Fcar (file));
2814
2815 if (CONSP (mask_file)) /* failure locating filename */
2816 signal_double_image_error ("Opening bitmap mask file",
2817 "no such file or directory",
2818 Fcar (mask_file));
2806 2819
2807 if (EQ (file, Qt) && EQ (mask_file, Qt)) /* no conversion necessary */ 2820 if (EQ (file, Qt) && EQ (mask_file, Qt)) /* no conversion necessary */
2808 RETURN_UNGCPRO (inst); 2821 RETURN_UNGCPRO (inst);
2809 2822
2810 alist = tagged_vector_to_alist (inst); 2823 alist = tagged_vector_to_alist (inst);
2861 2874
2862 static Lisp_Object 2875 static Lisp_Object
2863 xface_normalize (Lisp_Object inst, Lisp_Object console_type, 2876 xface_normalize (Lisp_Object inst, Lisp_Object console_type,
2864 Lisp_Object UNUSED (dest_mask)) 2877 Lisp_Object UNUSED (dest_mask))
2865 { 2878 {
2866 /* This function can call lisp */ 2879 Lisp_Object file = Qnil, mask_file = Qnil, alist = Qnil;
2867 Lisp_Object file = Qnil, mask_file = Qnil;
2868 struct gcpro gcpro1, gcpro2, gcpro3; 2880 struct gcpro gcpro1, gcpro2, gcpro3;
2869 Lisp_Object alist = Qnil;
2870 2881
2871 GCPRO3 (file, mask_file, alist); 2882 GCPRO3 (file, mask_file, alist);
2872 2883
2873 /* Now, convert any file data into inline data for both the regular 2884 /* Now, convert any file data into inline data for both the regular
2874 data and the mask data. At the end of this, `data' will contain 2885 data and the mask data. At the end of this, `data' will contain
2882 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data, 2893 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
2883 console_type); 2894 console_type);
2884 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file, 2895 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
2885 Q_mask_data, console_type); 2896 Q_mask_data, console_type);
2886 2897
2887 if (NILP (file)) /* normalization impossible for the console type */ 2898 /* No locate_pixmap_file method for this console type, so we can't get a
2899 file (neither a mask file BTW). */
2900 if (NILP (file))
2888 RETURN_UNGCPRO (Qnil); 2901 RETURN_UNGCPRO (Qnil);
2889 2902
2890 if (CONSP (file)) /* failure locating filename */ 2903 if (CONSP (file)) /* failure locating filename */
2891 signal_double_image_error ("Opening bitmap file", 2904 signal_double_image_error ("Opening face file",
2892 "no such file or directory", 2905 "no such file or directory",
2893 Fcar (file)); 2906 Fcar (file));
2894 2907
2908 if (CONSP (mask_file)) /* failure locating filename */
2909 signal_double_image_error ("Opening face mask file",
2910 "no such file or directory",
2911 Fcar (mask_file));
2912
2895 if (EQ (file, Qt) && EQ (mask_file, Qt)) /* no conversion necessary */ 2913 if (EQ (file, Qt) && EQ (mask_file, Qt)) /* no conversion necessary */
2896 RETURN_UNGCPRO (inst); 2914 RETURN_UNGCPRO (inst);
2897 2915
2898 alist = tagged_vector_to_alist (inst); 2916 alist = tagged_vector_to_alist (inst);
2899 2917
2900 { 2918 if (!EQ (file, Qt))
2901 /* #### FIXME: what if EQ (file, Qt) && !EQ (mask, Qt) ? Is that possible? 2919 {
2902 If so, we have a problem... -- dvl */ 2920 Lisp_Object data = make_string_from_file (file);
2903 Lisp_Object data = make_string_from_file (file); 2921 alist = remassq_no_quit (Q_file, alist);
2904 alist = remassq_no_quit (Q_file, alist); 2922 /* there can't be a :data at this point. */
2905 /* there can't be a :data at this point. */ 2923 alist = Fcons (Fcons (Q_file, file),
2906 alist = Fcons (Fcons (Q_file, file), 2924 Fcons (Fcons (Q_data, data), alist));
2907 Fcons (Fcons (Q_data, data), alist)); 2925 }
2908 }
2909 2926
2910 alist = xbm_mask_file_munging (alist, file, mask_file, console_type); 2927 alist = xbm_mask_file_munging (alist, file, mask_file, console_type);
2911 2928
2912 { 2929 {
2913 Lisp_Object result = alist_to_tagged_vector (Qxface, alist); 2930 Lisp_Object result = alist_to_tagged_vector (Qxface, alist);