Mercurial > hg > xemacs-beta
comparison src/font-mgr.c @ 3906:605c915d2b9d
[xemacs-hg @ 2007-04-14 16:10:53 by stephent]
Small fixes for font-mgr.c. <87y7kvudz3.fsf@uwakimon.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Sat, 14 Apr 2007 16:10:57 +0000 |
parents | f986ebd9c080 |
children | fd1f0c73d4df |
comparison
equal
deleted
inserted
replaced
3905:5d22662e9c81 | 3906:605c915d2b9d |
---|---|
1 /* Lisp font handling implementation for X with Xft. | 1 /* Lisp font handling implementation for X with Xft. |
2 | 2 |
3 Copyright (C) 2003 Eric Knauel and Matthias Neubauer | 3 Copyright (C) 2003 Eric Knauel and Matthias Neubauer |
4 Copyright (C) 2005 Eric Knauel | 4 Copyright (C) 2005 Eric Knauel |
5 Copyright (C) 2004, 2005 Free Software Foundation, Inc. | 5 Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
6 | 6 |
7 Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de> | 7 Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de> |
8 Matthias Neubauer <neubauer@informatik.uni-freiburg.de> | 8 Matthias Neubauer <neubauer@informatik.uni-freiburg.de> |
9 Stephen J. Turnbull <stephen@xemacs.org> | 9 Stephen J. Turnbull <stephen@xemacs.org> |
10 Created: 27 Oct 2003 | 10 Created: 27 Oct 2003 |
11 Updated: 05 Mar 2005 by Stephen J. Turnbull | 11 Updated: 14 April 2007 by Stephen J. Turnbull |
12 | 12 |
13 This file is part of XEmacs. | 13 This file is part of XEmacs. |
14 | 14 |
15 XEmacs is free software; you can redistribute it and/or modify it | 15 XEmacs is free software; you can redistribute it and/or modify it |
16 under the terms of the GNU General Public License as published by the | 16 under the terms of the GNU General Public License as published by the |
94 FcPatternDestroy (p->fcpatPtr); | 94 FcPatternDestroy (p->fcpatPtr); |
95 p->fcpatPtr = 0; | 95 p->fcpatPtr = 0; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 static void | |
100 print_fc_pattern (Lisp_Object obj, Lisp_Object printcharfun, | |
101 int UNUSED(escapeflag)) | |
102 { | |
103 struct fc_pattern *c = XFCPATTERN (obj); | |
104 if (print_readably) | |
105 printing_unreadable_object ("#<fc-pattern 0x%x>", c->header.uid); | |
106 write_fmt_string (printcharfun, "#<fc-pattern 0x%x>", c->header.uid); | |
107 } | |
108 | |
109 /* #### We really need an equal method and a hash method (required if you | |
110 have an equal method). For the equal method, we can probably use one | |
111 or both of | |
112 | |
113 -- Function: FcBool FcPatternEqual (const FcPattern *pa, const | |
114 FcPattern *pb); | |
115 Returns whether PA and PB are exactly alike. | |
116 | |
117 -- Function: FcBool FcPatternEqualSubset (const FcPattern *pa, const | |
118 FcPattern *pb, const FcObjectSet *os) | |
119 Returns whether PA and PB have exactly the same values for all of | |
120 the objects in OS. | |
121 | |
122 For the hash, we'll have to extract some subset of attributes. | |
123 | |
124 #### Crap. It's altogether unobvious what we need. x_color_instance | |
125 does have a hash method, but fonts are apparently special. I get the | |
126 feeling that for this to work properly we're going to need to switch | |
127 to fontconfig-based font specifications (although we can allow the | |
128 platform syntaxes, the underlying specification object will need to | |
129 conform to the fontconfig API, or more precisely the font-mgr API). | |
130 | |
131 I think the whole `font-truename' interface needs to be dropped. */ | |
132 | |
99 static const struct memory_description fcpattern_description [] = { | 133 static const struct memory_description fcpattern_description [] = { |
100 /* #### nothing here, is this right?? */ | 134 /* #### nothing here, is this right?? */ |
101 { XD_END } | 135 { XD_END } |
102 }; | 136 }; |
103 | 137 |
104 DEFINE_LRECORD_IMPLEMENTATION("fc-pattern", fc_pattern, | 138 DEFINE_LRECORD_IMPLEMENTATION("fc-pattern", fc_pattern, 0, |
105 0, 0, 0, finalize_fc_pattern, 0, 0, | 139 0, print_fc_pattern, finalize_fc_pattern, |
106 fcpattern_description, | 140 0, 0, fcpattern_description, |
107 struct fc_pattern); | 141 struct fc_pattern); |
108 | 142 |
109 /* | 143 /* |
110 * Helper Functions | 144 * Helper Functions |
111 */ | 145 */ |
119 doesn't say much about this topic. This functions assumes that STR | 153 doesn't say much about this topic. This functions assumes that STR |
120 is a Lisp string. | 154 is a Lisp string. |
121 */ | 155 */ |
122 #define extract_fcapi_string(str) \ | 156 #define extract_fcapi_string(str) \ |
123 (NEW_LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) | 157 (NEW_LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) |
158 | |
159 #define build_fcapi_string(str) \ | |
160 (build_ext_string ((Extbyte *) (str), Qfc_font_name_encoding)) | |
124 | 161 |
125 /* #### This homebrew lashup should be replaced with FcConstants. | 162 /* #### This homebrew lashup should be replaced with FcConstants. |
126 | 163 |
127 fontconfig assumes that objects (property names) are statically allocated, | 164 fontconfig assumes that objects (property names) are statically allocated, |
128 and you will get bizarre results if you pass Lisp string data or strings | 165 and you will get bizarre results if you pass Lisp string data or strings |
203 (name)) | 240 (name)) |
204 { | 241 { |
205 struct fc_pattern *fcpat = | 242 struct fc_pattern *fcpat = |
206 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | 243 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); |
207 | 244 |
208 CHECK_STRING(name); /* #### MEMORY LEAK!! maybe not ... */ | 245 CHECK_STRING(name); |
209 | 246 |
210 fcpat->fcpatPtr = FcNameParse ((FcChar8 *) extract_fcapi_string (name)); | 247 fcpat->fcpatPtr = FcNameParse ((FcChar8 *) extract_fcapi_string (name)); |
211 return wrap_fcpattern(fcpat); | 248 return wrap_fcpattern(fcpat); |
212 } | 249 } |
213 | 250 |
217 Unparse an fc pattern object to a string. | 254 Unparse an fc pattern object to a string. |
218 */ | 255 */ |
219 (pattern)) | 256 (pattern)) |
220 { | 257 { |
221 CHECK_FCPATTERN(pattern); | 258 CHECK_FCPATTERN(pattern); |
222 { | 259 return build_fcapi_string (FcNameUnparse (XFCPATTERN_PTR (pattern))); |
223 Extbyte *temp = (Extbyte *) FcNameUnparse(XFCPATTERN_PTR(pattern)); | |
224 Lisp_Object res = build_ext_string (temp, Qfc_font_name_encoding); | |
225 free (temp); | |
226 return res; | |
227 } | |
228 } | 260 } |
229 | 261 |
230 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /* | 262 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /* |
231 Make a copy of the fc pattern object PATTERN and return it. | 263 Make a copy of the fc pattern object PATTERN and return it. |
232 */ | 264 */ |
424 && !EQ (type, Qfloat)) | 456 && !EQ (type, Qfloat)) |
425 ? Qfc_result_type_mismatch : make_float (fc_value.u.d)); | 457 ? Qfc_result_type_mismatch : make_float (fc_value.u.d)); |
426 case FcTypeString: | 458 case FcTypeString: |
427 return ((!NILP (type) && !EQ (type, Qstring)) | 459 return ((!NILP (type) && !EQ (type, Qstring)) |
428 ? Qfc_result_type_mismatch | 460 ? Qfc_result_type_mismatch |
429 : build_ext_string ((Extbyte *) fc_value.u.s, | 461 : build_fcapi_string (fc_value.u.s)); |
430 Qfc_font_name_encoding)); | |
431 case FcTypeBool: | 462 case FcTypeBool: |
432 return ((!NILP (type) && !EQ (type, Qboolean)) | 463 return ((!NILP (type) && !EQ (type, Qboolean)) |
433 ? Qfc_result_type_mismatch : fc_value.u.b ? Qt : Qnil); | 464 ? Qfc_result_type_mismatch : fc_value.u.b ? Qt : Qnil); |
434 case FcTypeMatrix: | 465 case FcTypeMatrix: |
435 return Qfc_result_type_mismatch; | 466 return Qfc_result_type_mismatch; |
464 given pattern, or an error code. Possible error codes are | 495 given pattern, or an error code. Possible error codes are |
465 `fc-result-no-match' and `fc-result-no-id'. */ | 496 `fc-result-no-match' and `fc-result-no-id'. */ |
466 (device, pattern)) | 497 (device, pattern)) |
467 { | 498 { |
468 FcResult res; | 499 FcResult res; |
469 | 500 struct fc_pattern *res_fcpat; |
470 struct fc_pattern *res_fcpat = | 501 |
471 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | 502 CHECK_FCPATTERN(pattern); |
472 CHECK_FCPATTERN(pattern); /* #### MEMORY LEAKS!!! */ | |
473 if (NILP(device)) | 503 if (NILP(device)) |
474 return Qnil; | 504 return Qnil; |
475 CHECK_X_DEVICE(device); | 505 CHECK_X_DEVICE(device); |
476 if (!DEVICE_LIVE_P(XDEVICE(device))) | 506 if (!DEVICE_LIVE_P(XDEVICE(device))) |
477 return Qnil; | 507 return Qnil; |
478 | 508 |
509 res_fcpat = ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | |
479 { | 510 { |
480 FcPattern *p = XFCPATTERN_PTR(pattern); | 511 FcPattern *p = XFCPATTERN_PTR(pattern); |
481 FcConfig *fcc = FcConfigGetCurrent (); | 512 FcConfig *fcc = FcConfigGetCurrent (); |
482 | 513 |
483 FcConfigSubstitute (fcc, p, FcMatchPattern); | 514 FcConfigSubstitute (fcc, p, FcMatchPattern); |