Mercurial > hg > xemacs-beta
comparison src/font-mgr.c @ 5125:b5df3737028a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 01:58:04 -0600 |
parents | 623d57b7fbe8 3c3c1d139863 |
children | a9c41067dd88 |
comparison
equal
deleted
inserted
replaced
5124:623d57b7fbe8 | 5125:b5df3737028a |
---|---|
43 #include "console-x-impl.h" | 43 #include "console-x-impl.h" |
44 #include "objects-x.h" | 44 #include "objects-x.h" |
45 #include "objects-x-impl.h" | 45 #include "objects-x-impl.h" |
46 #include "hash.h" | 46 #include "hash.h" |
47 #include "font-mgr.h" | 47 #include "font-mgr.h" |
48 | |
49 #include "sysfile.h" | |
48 | 50 |
49 /* #### TO DO #### | 51 /* #### TO DO #### |
50 . The "x-xft-*" and "x_xft_*" nomenclature is mostly redundant, especially | 52 . The "x-xft-*" and "x_xft_*" nomenclature is mostly redundant, especially |
51 if we separate X fonts from Xft fonts, and use fontconfig more generally. | 53 if we separate X fonts from Xft fonts, and use fontconfig more generally. |
52 . We should support the most recent Xft first, old Xft libraries later. | 54 . We should support the most recent Xft first, old Xft libraries later. |
157 names. I suppose that Qnative is the right encoding, the manual | 159 names. I suppose that Qnative is the right encoding, the manual |
158 doesn't say much about this topic. This functions assumes that STR | 160 doesn't say much about this topic. This functions assumes that STR |
159 is a Lisp string. | 161 is a Lisp string. |
160 */ | 162 */ |
161 #define extract_fcapi_string(str) \ | 163 #define extract_fcapi_string(str) \ |
162 (NEW_LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) | 164 (LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) |
163 | 165 |
164 #define build_fcapi_string(str) \ | 166 #define build_fcapi_string(str) \ |
165 (build_ext_string ((Extbyte *) (str), Qfc_font_name_encoding)) | 167 (build_extstring ((Extbyte *) (str), Qfc_font_name_encoding)) |
166 | 168 |
167 /* #### This homebrew lashup should be replaced with FcConstants. | 169 /* #### This homebrew lashup should be replaced with FcConstants. |
168 | 170 |
169 fontconfig assumes that objects (property names) are statically allocated, | 171 fontconfig assumes that objects (property names) are statically allocated, |
170 and you will get bizarre results if you pass Lisp string data or strings | 172 and you will get bizarre results if you pass Lisp string data or strings |
178 I suspect that using symbol names or even keywords does not provide | 180 I suspect that using symbol names or even keywords does not provide |
179 assurance that the string won't move in memory. So we hash them | 181 assurance that the string won't move in memory. So we hash them |
180 ourselves; hash.c hashtables do not interpret the value pointers. | 182 ourselves; hash.c hashtables do not interpret the value pointers. |
181 | 183 |
182 This array should be FcChar8**, but GCC 4.x bitches about signedness. */ | 184 This array should be FcChar8**, but GCC 4.x bitches about signedness. */ |
183 static Extbyte *fc_standard_properties[] = { | 185 static const Extbyte *fc_standard_properties[] = { |
184 /* treated specially, ordered first */ | 186 /* treated specially, ordered first */ |
185 "family", "size", | 187 "family", "size", |
186 /* remaining are alphabetized by group */ | 188 /* remaining are alphabetized by group */ |
187 /* standard properties in fontconfig and Xft v.2 */ | 189 /* standard properties in fontconfig and Xft v.2 */ |
188 "antialias", "aspect", "autohint", "charset", "dpi", "file", | 190 "antialias", "aspect", "autohint", "charset", "dpi", "file", |
256 DEFUN("fc-name-unparse", Ffc_name_unparse, 1, 1, 0, /* | 258 DEFUN("fc-name-unparse", Ffc_name_unparse, 1, 1, 0, /* |
257 Unparse an fc pattern object to a string. | 259 Unparse an fc pattern object to a string. |
258 */ | 260 */ |
259 (pattern)) | 261 (pattern)) |
260 { | 262 { |
263 FcChar8 *name; | |
264 Lisp_Object result; | |
261 CHECK_FCPATTERN(pattern); | 265 CHECK_FCPATTERN(pattern); |
262 return build_fcapi_string (FcNameUnparse (XFCPATTERN_PTR (pattern))); | 266 name = FcNameUnparse (XFCPATTERN_PTR (pattern)); |
267 result = build_fcapi_string (name); | |
268 xfree (name); | |
269 return result; | |
263 } | 270 } |
264 | 271 |
265 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /* | 272 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /* |
266 Make a copy of the fc pattern object PATTERN and return it. | 273 Make a copy of the fc pattern object PATTERN and return it. |
267 */ | 274 */ |
547 Lisp_Object fontlist = Qnil; | 554 Lisp_Object fontlist = Qnil; |
548 fc_pattern *fcpat; | 555 fc_pattern *fcpat; |
549 | 556 |
550 /* #### improve this error message */ | 557 /* #### improve this error message */ |
551 if (!fontset) | 558 if (!fontset) |
552 Fsignal (Qinvalid_state, | 559 invalid_state ("failed to create FcFontSet", Qunbound); |
553 list1 (build_string ("failed to create FcFontSet"))); | |
554 for (idx = 0; idx < fontset->nfont; ++idx) | 560 for (idx = 0; idx < fontset->nfont; ++idx) |
555 { | 561 { |
556 fcpat = XFCPATTERN (ALLOC_LISP_OBJECT (fc_pattern)); | 562 fcpat = XFCPATTERN (ALLOC_LISP_OBJECT (fc_pattern)); |
557 fcpat->fcpatPtr = FcPatternDuplicate (fontset->fonts[idx]); | 563 fcpat->fcpatPtr = FcPatternDuplicate (fontset->fonts[idx]); |
558 fontlist = Fcons (wrap_fcpattern(fcpat), fontlist); | 564 fontlist = Fcons (wrap_fcpattern(fcpat), fontlist); |
771 { | 777 { |
772 CHECK_FCCONFIG (config); | 778 CHECK_FCCONFIG (config); |
773 CHECK_STRING (file); | 779 CHECK_STRING (file); |
774 if (FcConfigAppFontAddFile | 780 if (FcConfigAppFontAddFile |
775 (XFCCONFIG_PTR (config), | 781 (XFCCONFIG_PTR (config), |
776 /* #### FIXME! is this really Qnative? */ | 782 /* #### FIXME! is Qfile_name right? */ |
777 (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((file), Qnative)) == FcFalse) | 783 (FcChar8 *) LISP_STRING_TO_EXTERNAL (file, Qfile_name)) == FcFalse) |
778 return Qnil; | 784 return Qnil; |
779 else | 785 else |
780 return Qt; | 786 return Qt; |
781 } | 787 } |
782 | 788 |
790 { | 796 { |
791 CHECK_FCCONFIG (config); | 797 CHECK_FCCONFIG (config); |
792 CHECK_STRING (dir); | 798 CHECK_STRING (dir); |
793 if (FcConfigAppFontAddDir | 799 if (FcConfigAppFontAddDir |
794 (XFCCONFIG_PTR (config), | 800 (XFCCONFIG_PTR (config), |
795 /* #### FIXME! is this really Qnative? */ | 801 /* #### FIXME! is Qfile_name right? */ |
796 (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((dir), Qnative)) == FcFalse) | 802 (FcChar8 *) LISP_STRING_TO_EXTERNAL (dir, Qfile_name)) == FcFalse) |
797 return Qnil; | 803 return Qnil; |
798 else | 804 else |
799 return Qt; | 805 return Qt; |
800 } | 806 } |
801 | 807 |
828 refers to a file in the default configuration directory; the | 834 refers to a file in the default configuration directory; the |
829 built-in default directory can be overridden with the | 835 built-in default directory can be overridden with the |
830 FC_CONFIG_DIR environment variable. */ | 836 FC_CONFIG_DIR environment variable. */ |
831 (name)) | 837 (name)) |
832 { | 838 { |
833 char *fcname = ""; | 839 const Ascbyte *fcname = ""; |
834 | 840 |
835 if (!NILP (name)) | 841 if (!NILP (name)) |
836 { | 842 { |
837 CHECK_STRING (name); | 843 CHECK_STRING (name); |
838 /* #### FIXME! is this really Qnative? */ | 844 /* #### FIXME! is Qfile_name right? */ |
839 fcname = NEW_LISP_STRING_TO_EXTERNAL (name, Qnative); | 845 LISP_PATHNAME_CONVERT_OUT (name, fcname); |
840 } | 846 } |
841 return (build_fcapi_string (FcConfigFilename ((FcChar8 *) fcname))); | 847 return (build_fcapi_string (FcConfigFilename ((FcChar8 *) fcname))); |
842 } | 848 } |
843 | 849 |
844 DEFUN("fc-init-load-config", Ffc_init_load_config, 0, 0, 0, /* | 850 DEFUN("fc-init-load-config", Ffc_init_load_config, 0, 0, 0, /* |
903 { | 909 { |
904 FcMatchKind knd; | 910 FcMatchKind knd; |
905 | 911 |
906 /* There ought to be a standard idiom for this.... */ | 912 /* There ought to be a standard idiom for this.... */ |
907 if (NILP (kind) | 913 if (NILP (kind) |
908 || EQ (kind, Qfc_match_font)) { | 914 || EQ (kind, Qfc_match_font)) |
909 knd = FcMatchFont; | 915 knd = FcMatchFont; |
910 } | 916 else if (EQ (kind, Qfc_match_pattern)) |
911 else if (EQ (kind, Qfc_match_pattern)) { | |
912 knd = FcMatchPattern; | 917 knd = FcMatchPattern; |
913 } | 918 else |
914 else { | 919 wtaerror ("need `fc-match-pattern' or `fc-match-font'", kind); |
915 Fsignal (Qwrong_type_argument, | |
916 list2 (build_string ("need `fc-match-pattern' or `fc-match-font'"), | |
917 kind)); | |
918 } | |
919 | 920 |
920 /* Typecheck arguments */ | 921 /* Typecheck arguments */ |
921 CHECK_FCPATTERN (pattern); | 922 CHECK_FCPATTERN (pattern); |
922 if (!NILP (testpat)) CHECK_FCPATTERN (testpat); | 923 if (!NILP (testpat)) CHECK_FCPATTERN (testpat); |
923 if (!NILP (config)) CHECK_FCCONFIG (config); | 924 if (!NILP (config)) CHECK_FCCONFIG (config); |
993 p = XFCPATTERN_PTR(pattern); | 994 p = XFCPATTERN_PTR(pattern); |
994 fcc = NILP (config) ? FcConfigGetCurrent () : XFCCONFIG_PTR (config); | 995 fcc = NILP (config) ? FcConfigGetCurrent () : XFCCONFIG_PTR (config); |
995 | 996 |
996 FcConfigSubstitute (fcc, p, FcMatchPattern); | 997 FcConfigSubstitute (fcc, p, FcMatchPattern); |
997 FcDefaultSubstitute (p); | 998 FcDefaultSubstitute (p); |
999 res = FcResultMatch; | |
998 res_fcpat->fcpatPtr = FcFontMatch (fcc, p, &res); | 1000 res_fcpat->fcpatPtr = FcFontMatch (fcc, p, &res); |
999 | 1001 |
1000 if (res_fcpat->fcpatPtr == NULL) | 1002 if (res_fcpat->fcpatPtr == NULL) |
1001 switch (res) { | 1003 switch (res) { |
1002 case FcResultNoMatch: | 1004 case FcResultNoMatch: |
1211 { | 1213 { |
1212 struct gcpro gcpro1; | 1214 struct gcpro gcpro1; |
1213 unsigned i; | 1215 unsigned i; |
1214 Lisp_Object reg = Qnil; | 1216 Lisp_Object reg = Qnil; |
1215 const Extbyte *re[] = /* #### This could just be catenated by | 1217 const Extbyte *re[] = /* #### This could just be catenated by |
1216 cpp and passed to build_ext_string. */ | 1218 cpp and passed to build_extstring. */ |
1217 { | 1219 { |
1218 /* Regular expression matching XLFDs as defined by XLFD v. 1.5. | 1220 /* Regular expression matching XLFDs as defined by XLFD v. 1.5. |
1219 Matches must be case-insensitive. | 1221 Matches must be case-insensitive. |
1220 PSIZE is a pixel or point size, which may be a "matrix". The | 1222 PSIZE is a pixel or point size, which may be a "matrix". The |
1221 syntax of a matrix is not checked, just some lexical properties. | 1223 syntax of a matrix is not checked, just some lexical properties. |
1258 | 1260 |
1259 GCPRO1 (reg); | 1261 GCPRO1 (reg); |
1260 for (i = 0; i < sizeof(re)/sizeof(Extbyte *); i++) | 1262 for (i = 0; i < sizeof(re)/sizeof(Extbyte *); i++) |
1261 { | 1263 { |
1262 /* #### Currently this is Host Portable Coding, not ISO 8859-1. */ | 1264 /* #### Currently this is Host Portable Coding, not ISO 8859-1. */ |
1263 reg = concat2(reg, build_ext_string (re[i], Qx_font_name_encoding)); | 1265 reg = concat2(reg, build_extstring (re[i], Qx_font_name_encoding)); |
1264 } | 1266 } |
1265 | 1267 |
1266 RETURN_UNGCPRO (reg); | 1268 RETURN_UNGCPRO (reg); |
1267 } | 1269 } |
1268 #undef XE_XLFD_SEPARATOR | 1270 #undef XE_XLFD_SEPARATOR |