Mercurial > hg > xemacs-beta
annotate src/font-mgr.c @ 4758:75975fd0b7fc
Implement more of the fontconfig API.
Improve implementation, avoiding nonsyntactic macros and compiler warnings.
Clean up some documentation.
Guard against freeing NULL pointers returned from fonconfig.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Wed, 18 Nov 2009 22:44:28 +0900 |
parents | a23ac8f90a49 |
children | ca99a807b025 e0db3c197671 |
rev | line source |
---|---|
3354 | 1 /* Lisp font handling implementation for X with Xft. |
2 | |
3 Copyright (C) 2003 Eric Knauel and Matthias Neubauer | |
4 Copyright (C) 2005 Eric Knauel | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
5 Copyright (C) 2004-2009 Free Software Foundation, Inc. |
3354 | 6 |
7 Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de> | |
8 Matthias Neubauer <neubauer@informatik.uni-freiburg.de> | |
9 Stephen J. Turnbull <stephen@xemacs.org> | |
10 Created: 27 Oct 2003 | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
11 Updated: 18 November 2009 by Stephen J. Turnbull |
3354 | 12 |
13 This file is part of XEmacs. | |
14 | |
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 | |
17 Free Software Foundation; either version 2, or (at your option) any | |
18 later version. | |
19 | |
20 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
23 for more details. | |
24 | |
25 You should have received a copy of the GNU General Public License | |
26 along with XEmacs; see the file COPYING. If not, write to | |
27 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 Boston, MA 02111-1307, USA. */ | |
29 | |
30 /* Synched up with: Not in GNU Emacs. */ | |
31 | |
32 /* This module provides the Lisp interface to fonts in X11, including Xft, | |
33 but (at least at first) not GTK+ or Qt. | |
34 | |
35 Sealevel code should be in ../lwlib/lwlib-fonts.c or | |
36 ../lwlib/lwlib-colors.c. | |
37 */ | |
38 | |
39 #include <config.h> | |
40 #include "lisp.h" | |
41 #include "device.h" | |
42 #include "device-impl.h" | |
43 #include "console-x-impl.h" | |
44 #include "objects-x.h" | |
45 #include "objects-x-impl.h" | |
46 #include "hash.h" | |
47 #include "font-mgr.h" | |
48 | |
49 /* #### TO DO #### | |
50 . 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. | |
52 . We should support the most recent Xft first, old Xft libraries later. | |
53 . We may (think about it) wish to use fontconfig generally, even if we're | |
54 not using Xft. Either way, names that are really from fontconfig should | |
55 use the Fc* namespace. | |
56 . Mule-ize this file. | |
57 . Separate X Font Struct ops from Xft Font ops; give precedence to Xft but | |
58 allow fallback to X. | |
59 . Push decisions about font choice, defaults, fallbacks to Lisp; if we | |
60 really need efficiency, can reimplement in C later. | |
61 . Implement symbols interned in this file in the Q* namespace. | |
62 . Implement FcMatrix (Lisp vector). | |
63 . Implement FcCharSets (Lisp chartable? For implementation hints, see | |
64 FcCharSetFirstPage and FcCharSetNextPage). | |
65 . Implement FcConfigs. | |
66 DONE | |
67 . Fontconfig fontnames are encoded in UTF-8. | |
68 */ | |
69 | |
3360 | 70 Lisp_Object Qfont_mgr; |
3354 | 71 Lisp_Object Qfc_patternp; |
72 /* Lisp_Object Qfc_result_match; */ /* FcResultMatch */ | |
73 Lisp_Object Qfc_result_type_mismatch; /* FcResultTypeMismatch */ | |
74 Lisp_Object Qfc_result_no_match; /* FcResultNoMatch */ | |
75 Lisp_Object Qfc_result_no_id; /* FcResultNoId */ | |
76 Lisp_Object Qfc_internal_error; | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
77 Lisp_Object Qfc_match_pattern; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
78 Lisp_Object Qfc_match_font; |
3354 | 79 Lisp_Object Vxlfd_font_name_regexp; /* #### Really needed? */ |
3935 | 80 Fixnum xft_version; |
81 Fixnum fc_version; | |
3354 | 82 Fixnum debug_xft; /* Set to 1 enables lots of obnoxious messages. |
83 Setting it to 2 or 3 enables even more. */ | |
3931 | 84 #ifdef FONTCONFIG_EXPOSE_CONFIG |
85 Lisp_Object Qfc_configp; | |
86 static Lisp_Object Vfc_config_weak_list; | |
87 #endif | |
3354 | 88 |
89 /**************************************************************** | |
90 * FcPattern objects * | |
91 ****************************************************************/ | |
92 | |
93 static void | |
94 finalize_fc_pattern (void *header, int UNUSED (for_disksave)) | |
95 { | |
96 struct fc_pattern *p = (struct fc_pattern *) header; | |
97 if (p->fcpatPtr) | |
98 { | |
99 FcPatternDestroy (p->fcpatPtr); | |
100 p->fcpatPtr = 0; | |
101 } | |
102 } | |
103 | |
3906 | 104 static void |
105 print_fc_pattern (Lisp_Object obj, Lisp_Object printcharfun, | |
106 int UNUSED(escapeflag)) | |
107 { | |
108 struct fc_pattern *c = XFCPATTERN (obj); | |
109 if (print_readably) | |
110 printing_unreadable_object ("#<fc-pattern 0x%x>", c->header.uid); | |
111 write_fmt_string (printcharfun, "#<fc-pattern 0x%x>", c->header.uid); | |
112 } | |
113 | |
114 /* #### We really need an equal method and a hash method (required if you | |
115 have an equal method). For the equal method, we can probably use one | |
116 or both of | |
117 | |
118 -- Function: FcBool FcPatternEqual (const FcPattern *pa, const | |
119 FcPattern *pb); | |
120 Returns whether PA and PB are exactly alike. | |
121 | |
122 -- Function: FcBool FcPatternEqualSubset (const FcPattern *pa, const | |
123 FcPattern *pb, const FcObjectSet *os) | |
124 Returns whether PA and PB have exactly the same values for all of | |
125 the objects in OS. | |
126 | |
127 For the hash, we'll have to extract some subset of attributes. | |
128 | |
129 #### Crap. It's altogether unobvious what we need. x_color_instance | |
130 does have a hash method, but fonts are apparently special. I get the | |
131 feeling that for this to work properly we're going to need to switch | |
132 to fontconfig-based font specifications (although we can allow the | |
133 platform syntaxes, the underlying specification object will need to | |
134 conform to the fontconfig API, or more precisely the font-mgr API). | |
135 | |
136 I think the whole `font-truename' interface needs to be dropped. */ | |
137 | |
3354 | 138 static const struct memory_description fcpattern_description [] = { |
139 /* #### nothing here, is this right?? */ | |
140 { XD_END } | |
141 }; | |
142 | |
3906 | 143 DEFINE_LRECORD_IMPLEMENTATION("fc-pattern", fc_pattern, 0, |
144 0, print_fc_pattern, finalize_fc_pattern, | |
145 0, 0, fcpattern_description, | |
3354 | 146 struct fc_pattern); |
147 | |
148 /* | |
149 * Helper Functions | |
150 */ | |
151 static Lisp_Object make_xlfd_font_regexp (void); | |
152 static void string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os); | |
153 | |
154 /* | |
155 extract the C representation of the Lisp string STR and convert it | |
156 to the encoding used by the Fontconfig API for property and font | |
157 names. I suppose that Qnative is the right encoding, the manual | |
158 doesn't say much about this topic. This functions assumes that STR | |
159 is a Lisp string. | |
160 */ | |
161 #define extract_fcapi_string(str) \ | |
3469 | 162 (NEW_LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding)) |
3354 | 163 |
3906 | 164 #define build_fcapi_string(str) \ |
165 (build_ext_string ((Extbyte *) (str), Qfc_font_name_encoding)) | |
166 | |
3360 | 167 /* #### This homebrew lashup should be replaced with FcConstants. |
168 | |
169 fontconfig assumes that objects (property names) are statically allocated, | |
3354 | 170 and you will get bizarre results if you pass Lisp string data or strings |
171 allocated on the stack as objects. fontconfig _does_ copy values, so we | |
172 (I hope) don't have to worry about that member. | |
173 | |
174 Probably these functions don't get called so often that the memory leak | |
175 due to strdup'ing every time we add a property would matter, but XEmacs | |
176 _is_ a long-running process. So we hash them. | |
177 | |
178 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 | |
3360 | 180 ourselves; hash.c hashtables do not interpret the value pointers. |
181 | |
182 This array should be FcChar8**, but GCC 4.x bitches about signedness. */ | |
183 static Extbyte *fc_standard_properties[] = { | |
184 /* treated specially, ordered first */ | |
185 "family", "size", | |
186 /* remaining are alphabetized by group */ | |
187 /* standard properties in fontconfig and Xft v.2 */ | |
188 "antialias", "aspect", "autohint", "charset", "dpi", "file", | |
3354 | 189 "foundry", "ftface", "globaladvance", "hinting", "index", "lang", |
190 "minspace", "outline", "pixelsize", "rasterizer", "rgba", "scalable", | |
3360 | 191 "scale", "slant", "spacing", "style", "verticallayout", "weight", |
192 /* common in modern fonts */ | |
193 "fontformat", "fontversion", | |
3354 | 194 /* obsolete after Xft v. 1 */ |
195 "charwidth", "charheight", "core", "encoding", "render" | |
196 }; | |
197 | |
198 static struct hash_table *fc_property_name_hash_table; | |
199 | |
200 /* #### Maybe fc_intern should be exposed to LISP? The idea is that | |
201 fc-pattern-add could warn or error if the property isn't interned. */ | |
202 | |
3469 | 203 static const Extbyte * |
3354 | 204 fc_intern (Lisp_Object property) |
205 { | |
206 const void *dummy; | |
3469 | 207 const Extbyte *prop = extract_fcapi_string (property); |
3354 | 208 const void *val = gethash (prop, fc_property_name_hash_table, &dummy); |
209 | |
210 /* extract_fcapi_string returns something alloca'd | |
211 so we can just drop the old value of prop on the floor */ | |
212 if (val) | |
3469 | 213 prop = (const Extbyte *) val; |
3354 | 214 else |
215 { | |
3469 | 216 prop = (const Extbyte *) FcStrCopy ((FcChar8 *) prop); |
3354 | 217 puthash (prop, NULL, fc_property_name_hash_table); |
218 } | |
219 return prop; | |
220 } | |
221 | |
222 DEFUN("fc-pattern-p", Ffc_pattern_p, 1, 1, 0, /* | |
223 Returns t if OBJECT is of type fc-pattern, nil otherwise. | |
224 */ | |
225 (object)) | |
226 { | |
227 return FCPATTERNP(object) ? Qt : Qnil; | |
228 } | |
229 | |
230 DEFUN("fc-pattern-create", Ffc_pattern_create, 0, 0, 0, /* | |
231 Return a new, empty fc-pattern object. | |
232 */ | |
233 ()) | |
234 { | |
235 fc_pattern *fcpat = | |
236 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | |
237 | |
238 fcpat->fcpatPtr = FcPatternCreate(); | |
239 return wrap_fcpattern(fcpat); | |
240 } | |
241 | |
242 DEFUN("fc-name-parse", Ffc_name_parse, 1, 1, 0, /* | |
243 Parse an Fc font name and return its representation as a fc pattern object. | |
244 */ | |
245 (name)) | |
246 { | |
247 struct fc_pattern *fcpat = | |
248 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | |
249 | |
3906 | 250 CHECK_STRING(name); |
3354 | 251 |
3469 | 252 fcpat->fcpatPtr = FcNameParse ((FcChar8 *) extract_fcapi_string (name)); |
3354 | 253 return wrap_fcpattern(fcpat); |
254 } | |
255 | |
256 /* #### Ga-a-ack! Xft's similar function is actually a different API. | |
257 We provide both. */ | |
258 DEFUN("fc-name-unparse", Ffc_name_unparse, 1, 1, 0, /* | |
259 Unparse an fc pattern object to a string. | |
260 */ | |
261 (pattern)) | |
262 { | |
263 CHECK_FCPATTERN(pattern); | |
3906 | 264 return build_fcapi_string (FcNameUnparse (XFCPATTERN_PTR (pattern))); |
3354 | 265 } |
266 | |
267 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /* | |
268 Make a copy of the fc pattern object PATTERN and return it. | |
269 */ | |
270 (pattern)) | |
271 { | |
272 struct fc_pattern *copy = NULL; | |
273 CHECK_FCPATTERN(pattern); | |
274 | |
275 copy = ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | |
276 copy->fcpatPtr = FcPatternDuplicate(XFCPATTERN_PTR(pattern)); | |
277 return wrap_fcpattern(copy); | |
278 } | |
279 | |
280 DEFUN("fc-pattern-add", Ffc_pattern_add, 3, 3, 0, /* | |
281 Add attributes to the pattern object PATTERN. PROPERTY is a string naming | |
282 the attribute to add, VALUE the value for this attribute. | |
283 | |
284 VALUE may be a string, integer, float, or symbol, in which case the value | |
285 will be added as an FcChar8[], int, double, or FcBool respectively. | |
286 */ | |
287 (pattern, property, value)) | |
288 { | |
289 Bool res = 0; | |
3469 | 290 const Extbyte *obj; |
3354 | 291 FcPattern *fcpat; |
292 | |
293 CHECK_FCPATTERN(pattern); | |
294 CHECK_STRING(property); | |
295 | |
296 obj = fc_intern (property); | |
297 fcpat = XFCPATTERN_PTR (pattern); | |
298 | |
299 if (STRINGP(value)) | |
300 { | |
301 FcChar8 *str = (FcChar8 *) extract_fcapi_string (value); | |
302 res = FcPatternAddString (fcpat, obj, str); | |
303 } | |
304 else if (INTP(value)) | |
305 { | |
306 res = FcPatternAddInteger (fcpat, obj, XINT(value)); | |
307 } | |
308 else if (FLOATP(value)) | |
309 { | |
310 res = FcPatternAddDouble (fcpat, obj, (double) XFLOAT_DATA(value)); | |
311 } | |
312 else if (SYMBOLP(value)) | |
313 { | |
314 res = FcPatternAddBool (fcpat, obj, !NILP(value)); | |
315 } | |
316 /* else ... maybe we should wta here? */ | |
317 | |
318 return res ? Qt : Qnil; | |
319 } | |
320 | |
321 DEFUN("fc-pattern-del", Ffc_pattern_del, 2, 2, 0, /* | |
322 Remove attribute PROPERTY from fc pattern object OBJECT. | |
323 */ | |
324 (pattern, property)) | |
325 { | |
326 Bool res; | |
327 | |
328 CHECK_FCPATTERN(pattern); | |
329 CHECK_STRING(property); | |
330 | |
3469 | 331 res = FcPatternDel(XFCPATTERN_PTR(pattern), extract_fcapi_string (property)); |
3354 | 332 return res ? Qt : Qnil; |
333 } | |
334 | |
335 /* Generic interface to FcPatternGet() | |
336 * Don't support the losing symbol-for-property interface. | |
337 */ | |
338 DEFUN("fc-pattern-get", Ffc_pattern_get, 2, 4, 0, /* | |
339 From PATTERN, extract PROPERTY for the ID'th member, of type TYPE. | |
340 | |
341 PATTERN is an Xft (fontconfig) pattern object. | |
342 PROPERTY is a string naming an fontconfig font property. | |
343 Optional ID is a nonnegative integer indexing the list of values for PROPERTY | |
344 stored in PATTERN, defaulting to 0 (the first value). | |
345 Optional TYPE is a symbol, one of 'string, 'boolean, 'integer, 'float, | |
346 'double, 'matrix, 'charset, or 'void, corresponding to the FcValue types. | |
347 ('float is an alias for 'double). | |
348 | |
349 The Lisp types returned will conform to TYPE: | |
350 string string | |
351 boolean `t' or `nil' | |
352 integer integer | |
353 double (float) float | |
354 matrix not implemented | |
355 charset not implemented | |
356 void not implemented | |
357 | |
358 Symbols with names of the form "fc-result-DESCRIPTION" are returned when | |
359 the desired value is not available. These are | |
360 | |
361 fc-result-type-mismatch the value found has an unexpected type | |
362 fc-result-no-match there is no such attribute | |
363 fc-result-no-id there is no value for the requested ID | |
364 | |
365 The types of the following standard properties are predefined by fontconfig. | |
366 The symbol 'fc-result-type-mismatch will be returned if the object exists but | |
367 TYPE does not match the predefined type. It is best not to specify a type | |
368 for predefined properties, as a mistake here ensures error returns on the | |
369 correct type. | |
370 | |
371 Each standard property has a convenience accessor defined in fontconfig.el, | |
372 named in the form "fc-pattern-get-PROPERTY". The convenience functions are | |
373 preferred to `fc-pattern-get' since a typo in the string naming a property | |
374 will result in a silent null return, while a typo in a function name will | |
375 usually result in a compiler or runtime \"not fboundp\" error. You may use | |
376 `defsubst' to define convenience functions for non-standard properties. | |
377 | |
378 family String Font family name | |
379 style String Font style. Overrides weight and slant | |
380 slant Int Italic, oblique or roman | |
381 weight Int Light, medium, demibold, bold or black | |
382 size Double Point size | |
383 aspect Double Stretches glyphs horizontally before hinting | |
384 pixelsize Double Pixel size | |
385 spacing Int Proportional, monospace or charcell | |
386 foundry String Font foundry name | |
387 antialias Bool Whether glyphs can be antialiased | |
388 hinting Bool Whether the rasterizer should use hinting | |
389 verticallayout Bool Use vertical layout | |
390 autohint Bool Use autohinter instead of normal hinter | |
391 globaladvance Bool Use font global advance data | |
392 file String The filename holding the font | |
393 index Int The index of the font within the file | |
394 ftface FT_Face Use the specified FreeType face object | |
395 rasterizer String Which rasterizer is in use | |
396 outline Bool Whether the glyphs are outlines | |
397 scalable Bool Whether glyphs can be scaled | |
398 scale Double Scale factor for point->pixel conversions | |
399 dpi Double Target dots per inch | |
400 rgba Int unknown, rgb, bgr, vrgb, vbgr, none - subpixel geometry | |
401 minspace Bool Eliminate leading from line spacing | |
402 charset CharSet Unicode chars encoded by the font | |
403 lang String List of RFC-3066-style languages this font supports | |
404 | |
405 The FT_Face, Matrix, CharSet types are unimplemented, so the corresponding | |
406 properties are not accessible from Lisp at this time. If the value of a | |
407 property returned has type FT_Face, FcCharSet, or FcMatrix, | |
408 `fc-result-type-mismatch' is returned. | |
409 | |
410 The following properties which were standard in Xft v.1 are obsolete in | |
411 Xft v.2: encoding, charwidth, charheight, core, and render. */ | |
412 (pattern, property, id, type)) | |
413 { | |
3469 | 414 Extbyte *fc_property; |
3354 | 415 FcResult fc_result; |
416 FcValue fc_value; | |
417 | |
418 /* | |
419 process arguments | |
420 */ | |
421 CHECK_FCPATTERN (pattern); | |
422 | |
423 #if 0 | |
424 /* Don't support the losing symbol-for-property interface. */ | |
425 property = SYMBOLP (property) ? symbol_name (XSYMBOL (property)) : property; | |
426 #endif | |
427 if (STRINGP (property)) | |
428 { | |
3469 | 429 fc_property = extract_fcapi_string (property); |
3354 | 430 } |
431 else | |
432 { | |
433 /* if we allow symbols, this would need to be | |
434 list3 (Qlambda, list1 (Qobject), | |
435 list3 (Qor, list2 (Qstringp, Qobject), | |
436 list2 (Qsymbolp, Qobject))) | |
437 or something like that? */ | |
438 dead_wrong_type_argument (Qstringp, property); | |
439 } | |
440 | |
441 if (!NILP (id)) CHECK_NATNUM (id); | |
442 if (!NILP (type)) CHECK_SYMBOL (type); | |
443 | |
444 /* get property */ | |
445 fc_result = FcPatternGet (XFCPATTERN_PTR (pattern), | |
446 fc_property, | |
447 NILP (id) ? 0 : XINT(id), | |
448 &fc_value); | |
449 | |
450 switch (fc_result) | |
451 { | |
452 case FcResultMatch: | |
453 /* wrap it and return */ | |
454 switch (fc_value.type) | |
455 { | |
456 case FcTypeInteger: | |
457 return ((!NILP (type) && !EQ (type, Qinteger)) | |
458 ? Qfc_result_type_mismatch : make_int (fc_value.u.i)); | |
459 case FcTypeDouble: | |
460 return ((!NILP (type) && !EQ (type, intern ("double")) | |
461 && !EQ (type, Qfloat)) | |
462 ? Qfc_result_type_mismatch : make_float (fc_value.u.d)); | |
463 case FcTypeString: | |
464 return ((!NILP (type) && !EQ (type, Qstring)) | |
465 ? Qfc_result_type_mismatch | |
3906 | 466 : build_fcapi_string (fc_value.u.s)); |
3354 | 467 case FcTypeBool: |
468 return ((!NILP (type) && !EQ (type, Qboolean)) | |
469 ? Qfc_result_type_mismatch : fc_value.u.b ? Qt : Qnil); | |
470 case FcTypeMatrix: | |
471 return Qfc_result_type_mismatch; | |
472 /* #### unimplemented | |
473 return ((!NILP (type) && !EQ (type, intern ("matrix"))) | |
474 ? Qfc_result_type_mismatch : make_int (fc_value.u.m)); | |
475 */ | |
476 case FcTypeCharSet: | |
477 return Qfc_result_type_mismatch; | |
478 /* #### unimplemented | |
479 return ((!NILP (type) && !EQ (type, intern ("charset"))) | |
480 ? Qfc_result_type_mismatch : make_int (fc_value.u.c)); | |
481 */ | |
482 } | |
483 case FcResultTypeMismatch: | |
484 return Qfc_result_type_mismatch; | |
485 case FcResultNoMatch: | |
486 return Qfc_result_no_match; | |
487 case FcResultNoId: | |
488 return Qfc_result_no_id; | |
489 default: | |
490 return Qfc_internal_error; | |
491 } | |
492 } | |
493 | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
494 /* FcConfig handling functions. */ |
3354 | 495 |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
496 /* We obviously need to be careful about garbage collecting the current |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
497 FcConfig. I infer from the documentation of FcConfigDestroy that that |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
498 is the only reference maintained by fontconfig. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
499 So we keep track of our own references on a weak list, and only cons a |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
500 new object if we don't already have a reference to it there. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
501 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
502 enum DestroyFontsetP { DestroyNo = 0, DestroyYes = 1 }; |
3354 | 503 |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
504 static Lisp_Object |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
505 fc_config_create_using (FcConfig * (*create_function) ()) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
506 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
507 FcConfig *fc = (*create_function) (); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
508 Lisp_Object configs = XWEAK_LIST_LIST (Vfc_config_weak_list); |
3354 | 509 |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
510 /* Linear search: fc_configs are not going to multiply like conses. */ |
3360 | 511 { |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
512 LIST_LOOP_2 (cfg, configs) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
513 if (fc == XFCCONFIG_PTR (cfg)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
514 return cfg; |
3360 | 515 } |
516 | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
517 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
518 fc_config *fccfg = |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
519 ALLOC_LCRECORD_TYPE (struct fc_config, &lrecord_fc_config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
520 fccfg->fccfgPtr = fc; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
521 configs = Fcons (wrap_fcconfig (fccfg), configs); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
522 XWEAK_LIST_LIST (Vfc_config_weak_list) = configs; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
523 return wrap_fcconfig (fccfg); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
524 } |
3354 | 525 } |
526 | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
527 static Lisp_Object |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
528 fc_strlist_to_lisp_using (FcStrList * (*getter) (FcConfig *), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
529 Lisp_Object config) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
530 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
531 FcChar8 *thing; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
532 Lisp_Object value = Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
533 FcStrList *thing_list; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
534 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
535 CHECK_FCCONFIG (config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
536 thing_list = (*getter) (XFCCONFIG_PTR(config)); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
537 /* Yes, we need to do this check -- sheesh, Keith! */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
538 if (!thing_list) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
539 return Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
540 while ((thing = FcStrListNext (thing_list))) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
541 value = Fcons (build_fcapi_string (thing), value); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
542 FcStrListDone (thing_list); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
543 return value; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
544 } |
3931 | 545 |
3354 | 546 static Lisp_Object |
3931 | 547 fontset_to_list (FcFontSet *fontset, enum DestroyFontsetP destroyp) |
3354 | 548 { |
549 int idx; | |
550 Lisp_Object fontlist = Qnil; | |
551 fc_pattern *fcpat; | |
552 | |
553 /* #### improve this error message */ | |
554 if (!fontset) | |
555 Fsignal (Qinvalid_state, | |
556 list1 (build_string ("failed to create FcFontSet"))); | |
557 for (idx = 0; idx < fontset->nfont; ++idx) | |
558 { | |
559 fcpat = | |
560 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); | |
561 fcpat->fcpatPtr = FcPatternDuplicate (fontset->fonts[idx]); | |
562 fontlist = Fcons (wrap_fcpattern(fcpat), fontlist); | |
563 } | |
3931 | 564 if (destroyp) |
565 FcFontSetDestroy (fontset); | |
3354 | 566 return fontlist; |
567 } | |
568 | |
3931 | 569 DEFUN("fc-config-p", Ffc_config_p, 1, 1, 0, /* |
570 Returns t if OBJECT is of type fc-config, nil otherwise. | |
571 */ | |
572 (object)) | |
573 { | |
574 return FCCONFIGP (object) ? Qt : Qnil; | |
575 } | |
576 | |
577 DEFUN("fc-config-create", Ffc_config_create, 0, 0, 0, /* | |
578 -- Function: FcConfig *FcConfigCreate (void) | |
579 Creates an empty configuration. */ | |
580 ()) | |
581 { | |
582 return fc_config_create_using (&FcConfigCreate); | |
583 } | |
584 | |
585 #if 0 | |
586 /* I'm sorry, but we just don't do this in Lisp, OK? | |
587 Don't even think about implementing this. */ | |
588 DEFUN("fc-config-destroy", Ffc_config_destroy, 1, 1, 0, /* | |
589 -- Function: void FcConfigDestroy (FcConfig *config) | |
590 Destroys a configuration and any data associated with it. Note | |
591 that calling this function with the return value from | |
592 FcConfigGetCurrent will place the library in an indeterminate | |
593 state. */ | |
594 (config)) | |
595 { | |
596 signal_error (Qunimplemented, "No user-servicable parts!", | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
597 intern ("fc-config-destroy")); |
3931 | 598 } |
599 #endif | |
600 | |
601 DEFUN("fc-config-up-to-date", Ffc_config_up_to_date, 1, 1, 0, /* | |
602 -- Function: FcBool FcConfigUptoDate (FcConfig *config) | |
603 Checks all of the files related to 'config' and returns whether the | |
604 in-memory version is in sync with the disk version. */ | |
605 (config)) | |
606 { | |
607 CHECK_FCCONFIG (config); | |
608 return FcConfigUptoDate (XFCCONFIG_PTR (config)) == FcFalse ? Qnil : Qt; | |
609 } | |
610 | |
611 DEFUN("fc-config-build-fonts", Ffc_config_build_fonts, 1, 1, 0, /* | |
612 -- Function: FcBool FcConfigBuildFonts (FcConfig *config) | |
613 Builds the set of available fonts for the given configuration. | |
614 Note that any changes to the configuration after this call have | |
615 indeterminate effects. Returns FcFalse if this operation runs out | |
616 of memory. | |
617 XEmacs: signal out-of-memory, or return nil on success. */ | |
618 (config)) | |
619 { | |
620 CHECK_FCCONFIG (config); | |
621 if (FcConfigBuildFonts (XFCCONFIG_PTR (config)) == FcFalse) | |
622 out_of_memory ("FcConfigBuildFonts failed", config); | |
623 return Qnil; | |
624 } | |
625 | |
626 DEFUN("fc-config-get-config-dirs", Ffc_config_get_config_dirs, 1, 1, 0, /* | |
627 -- Function: FcStrList *FcConfigGetConfigDirs (FcConfig *config) | |
628 Returns the list of font directories specified in the | |
629 configuration files for 'config'. Does not include any | |
630 subdirectories. */ | |
631 (config)) | |
632 { | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
633 return fc_strlist_to_lisp_using (&FcConfigGetConfigDirs, config); |
3931 | 634 } |
635 | |
636 DEFUN("fc-config-get-font-dirs", Ffc_config_get_font_dirs, 1, 1, 0, /* | |
637 -- Function: FcStrList *FcConfigGetFontDirs (FcConfig *config) | |
638 Returns the list of font directories in 'config'. This includes the | |
639 configured font directories along with any directories below those | |
640 in the filesystem. */ | |
641 (config)) | |
642 { | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
643 return fc_strlist_to_lisp_using (&FcConfigGetFontDirs, config); |
3931 | 644 } |
645 | |
646 DEFUN("fc-config-get-config-files", Ffc_config_get_config_files, 1, 1, 0, /* | |
647 -- Function: FcStrList *FcConfigGetConfigFiles (FcConfig *config) | |
648 Returns the list of known configuration files used to generate | |
649 'config'. Note that this will not include any configuration done | |
650 with FcConfigParse. */ | |
651 (config)) | |
652 { | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
653 return fc_strlist_to_lisp_using (&FcConfigGetConfigFiles, config); |
3931 | 654 } |
655 | |
656 DEFUN("fc-config-get-cache", Ffc_config_get_cache, 1, 1, 0, /* | |
657 -- Function: char *FcConfigGetCache (FcConfig *config) | |
658 Returns the name of the file used to store per-user font | |
659 information. */ | |
660 (config)) | |
661 { | |
662 CHECK_FCCONFIG (config); | |
663 /* Surely FcConfigGetCache just casts an FcChar8* to char*. */ | |
664 return build_fcapi_string ((FcChar8 *) FcConfigGetCache (XFCCONFIG_PTR (config))); | |
665 } | |
666 | |
667 DEFUN("fc-config-get-fonts", Ffc_config_get_fonts, 2, 2, 0, /* | |
668 -- Function: FcFontSet *FcConfigGetFonts (FcConfig *config, FcSetName set) | |
669 Returns one of the two sets of fonts from the configuration as | |
670 specified by 'set'. | |
671 `FcSetName' | |
672 Specifies one of the two sets of fonts available in a | |
673 configuration; FcSetSystem for those fonts specified in the | |
674 configuration and FcSetApplication which holds fonts provided by | |
675 the application. */ | |
676 (config, set)) | |
677 { | |
678 FcSetName name = FcSetSystem; | |
679 FcFontSet *fs = NULL; | |
680 | |
681 CHECK_FCCONFIG (config); | |
682 CHECK_SYMBOL (set); | |
683 | |
684 if (EQ (set, intern ("fc-set-system"))) | |
685 name = FcSetSystem; | |
686 else if (EQ (set, intern ("fc-set-application"))) | |
687 name = FcSetApplication; | |
688 else | |
689 wtaerror ("must be in (fc-set-system fc-set-application)", set); | |
690 | |
691 fs = FcConfigGetFonts (XFCCONFIG_PTR (config), name); | |
692 return fs ? fontset_to_list (fs, DestroyNo) : Qnil; | |
693 } | |
694 | |
695 DEFUN("fc-config-set-current", Ffc_config_set_current, 1, 1, 0, /* | |
696 -- Function: FcBool FcConfigSetCurrent (FcConfig *config) | |
697 Sets the current default configuration to 'config'. Implicitly | |
698 calls FcConfigBuildFonts if necessary, returning FcFalse if that | |
699 call fails. | |
700 XEmacs: signals out-of-memory if FcConfigBuildFonts fails, or args-out-of-range | |
701 if the resulting FcConfig has no fonts (which would crash XEmacs if installed). | |
702 */ | |
703 (config)) | |
704 { | |
705 CHECK_FCCONFIG (config); | |
706 /* *sigh* "Success" DOES NOT mean you have any fonts available. It is | |
707 easy to crash fontconfig, and XEmacs with it. Without the following | |
708 check, this will do it: | |
709 (progn | |
710 (fc-config-set-current (fc-config-create)) | |
711 (set-face-font 'default "serif-12")) | |
712 */ | |
713 | |
714 if (FcConfigBuildFonts (XFCCONFIG_PTR (config)) == FcFalse) | |
715 out_of_memory ("FcConfigBuildFonts failed", config); | |
716 /* #### We'd like to avoid this consing, and FcConfigGetFonts sometimes | |
717 returns NULL, but it doesn't always. This will do for now .... */ | |
718 if (NILP (Ffc_config_get_fonts (config, intern ("fc-set-system"))) | |
719 && NILP (Ffc_config_get_fonts (config, intern ("fc-set-application")))) | |
720 signal_error (intern ("args-out-of-range"), "no fonts found", config); | |
721 /* Should never happen, but I don't trust Keith anymore .... */ | |
722 if (FcConfigSetCurrent (XFCCONFIG_PTR (config)) == FcFalse) | |
723 out_of_memory ("FcConfigBuildFonts failed in set", config); | |
724 return Qnil; | |
725 } | |
726 | |
727 DEFUN("fc-config-get-blanks", Ffc_config_get_blanks, 1, 1, 0, /* | |
728 -- Function: FcBlanks *FcConfigGetBlanks (FcConfig *config) | |
729 Returns the FcBlanks object associated with the given | |
730 configuration, if no blanks were present in the configuration, | |
731 this function will return 0. | |
732 XEmacs: should convert to a chartable. | |
733 #### Unimplemented. */ | |
734 (config)) | |
735 { | |
736 CHECK_FCCONFIG (config); | |
737 signal_error (Qunimplemented, "no method to convert FcBlanks object", | |
738 intern ("fc-config-get-blanks")); | |
739 } | |
740 | |
741 DEFUN("fc-config-get-rescan-interval", Ffc_config_get_rescan_interval, 1, 1, 0, /* | |
4328
dfd878799ef0
Autoconfiscate the recent fontconfig spelling change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3935
diff
changeset
|
742 -- Function: int FcConfigGetRescanInterval (FcConfig *config) |
3931 | 743 Returns the interval between automatic checks of the configuration |
744 (in seconds) specified in 'config'. The configuration is checked | |
745 during a call to FcFontList when this interval has passed since | |
746 the last check. */ | |
747 (config)) | |
748 { | |
749 CHECK_FCCONFIG (config); | |
4328
dfd878799ef0
Autoconfiscate the recent fontconfig spelling change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3935
diff
changeset
|
750 return make_int (FcConfigGetRescanInterval (XFCCONFIG_PTR (config))); |
3931 | 751 } |
752 | |
753 DEFUN("fc-config-set-rescan-interval", Ffc_config_set_rescan_interval, 2, 2, 0, /* | |
4328
dfd878799ef0
Autoconfiscate the recent fontconfig spelling change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3935
diff
changeset
|
754 -- Function: FcBool FcConfigSetRescanInterval (FcConfig *config, int |
3931 | 755 rescanInterval) |
756 Sets the rescan interval; returns FcFalse if an error occurred. | |
757 XEmacs: signal such error, or return nil on success. */ | |
758 (config, rescan_interval)) | |
759 { | |
760 CHECK_FCCONFIG (config); | |
761 CHECK_INT (rescan_interval); | |
4328
dfd878799ef0
Autoconfiscate the recent fontconfig spelling change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3935
diff
changeset
|
762 if (FcConfigSetRescanInterval (XFCCONFIG_PTR (config), |
3931 | 763 XINT (rescan_interval)) == FcFalse) |
764 signal_error (Qio_error, "FcConfigSetRescanInverval barfed", | |
765 intern ("fc-config-set-rescan-interval")); | |
766 return Qnil; | |
767 } | |
768 | |
769 /* #### This might usefully be made interactive. */ | |
770 DEFUN("fc-config-app-font-add-file", Ffc_config_app_font_add_file, 2, 2, 0, /* | |
771 -- Function: FcBool FcConfigAppFontAddFile (FcConfig *config, const | |
772 char *file) | |
773 Adds an application-specific font to the configuration. */ | |
774 (config, file)) | |
775 { | |
776 CHECK_FCCONFIG (config); | |
777 CHECK_STRING (file); | |
778 if (FcConfigAppFontAddFile | |
779 (XFCCONFIG_PTR (config), | |
780 /* #### FIXME! is this really Qnative? */ | |
781 (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((file), Qnative)) == FcFalse) | |
782 return Qnil; | |
783 else | |
784 return Qt; | |
785 } | |
786 | |
787 /* #### This might usefully be made interactive. */ | |
788 DEFUN("fc-config-app-font-add-dir", Ffc_config_app_font_add_dir, 2, 2, 0, /* | |
789 -- Function: FcBool FcConfigAppFontAddDir (FcConfig *config, const | |
790 char *dir) | |
791 Scans the specified directory for fonts, adding each one found to | |
792 the application-specific set of fonts. */ | |
793 (config, dir)) | |
794 { | |
795 CHECK_FCCONFIG (config); | |
796 CHECK_STRING (dir); | |
797 if (FcConfigAppFontAddDir | |
798 (XFCCONFIG_PTR (config), | |
799 /* #### FIXME! is this really Qnative? */ | |
800 (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((dir), Qnative)) == FcFalse) | |
801 return Qnil; | |
802 else | |
803 return Qt; | |
804 } | |
805 | |
806 /* #### This might usefully be made interactive. */ | |
807 DEFUN("fc-config-app-font-clear", Ffc_config_app_font_clear, 1, 1, 0, /* | |
808 -- Function: void FcConfigAppFontClear (FcConfig *config) | |
809 Clears the set of application-specific fonts. */ | |
810 (config)) | |
811 { | |
812 CHECK_FCCONFIG (config); | |
813 FcConfigAppFontClear (XFCCONFIG_PTR (config)); | |
814 return Qnil; | |
815 } | |
816 | |
817 /* These functions provide some control over how the default | |
818 configuration of the library is initialized. (This configuration is | |
819 normally implicitly initialized.) */ | |
820 | |
821 DEFUN("fc-config-filename", Ffc_config_filename, 1, 1, 0, /* | |
822 -- Function: char *FcConfigFilename (const char *name) | |
823 Given the specified external entity name, return the associated | |
824 filename. This provides applications a way to convert various | |
825 configuration file references into filename form. | |
826 | |
827 A null or empty 'name' indicates that the default configuration | |
828 file should be used; which file this references can be overridden | |
829 with the FC_CONFIG_FILE environment variable. Next, if the name | |
830 starts with '~', it refers to a file in the current users home | |
831 directory. Otherwise if the name doesn't start with '/', it | |
832 refers to a file in the default configuration directory; the | |
833 built-in default directory can be overridden with the | |
834 FC_CONFIG_DIR environment variable. */ | |
835 (name)) | |
836 { | |
837 char *fcname = ""; | |
838 | |
839 if (!NILP (name)) | |
840 { | |
841 CHECK_STRING (name); | |
842 /* #### FIXME! is this really Qnative? */ | |
843 fcname = NEW_LISP_STRING_TO_EXTERNAL (name, Qnative); | |
844 } | |
845 return (build_fcapi_string (FcConfigFilename ((FcChar8 *) fcname))); | |
846 } | |
847 | |
848 DEFUN("fc-init-load-config", Ffc_init_load_config, 0, 0, 0, /* | |
849 -- Function: FcConfig *FcInitLoadConfig (void) | |
850 Loads the default configuration file and returns the resulting | |
851 configuration. Does not load any font information. */ | |
852 ()) | |
853 { | |
854 return fc_config_create_using (&FcInitLoadConfig); | |
855 } | |
856 | |
857 DEFUN("fc-init-load-config-and-fonts", Ffc_init_load_config_and_fonts, 0, 0, 0, /* | |
858 -- Function: FcConfig *FcInitLoadConfigAndFonts (void) | |
859 Loads the default configuration file and builds information about | |
860 the available fonts. Returns the resulting configuration. */ | |
861 ()) | |
862 { | |
863 return fc_config_create_using (&FcInitLoadConfigAndFonts); | |
864 } | |
865 | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
866 DEFUN("fc-config-get-current", Ffc_config_get_current, 0, 0, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
867 -- Function: FcConfig *FcConfigGetCurrent (void) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
868 Returns the current default configuration. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
869 ()) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
870 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
871 return fc_config_create_using (&FcConfigGetCurrent); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
872 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
873 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
874 /* Pattern manipulation functions. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
875 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
876 DEFUN("fc-default-substitute", Ffc_default_substitute, 1, 1, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
877 Adds defaults for certain attributes if not specified in PATTERN. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
878 FcPattern PATTERN is modified in-place, and nil is returned. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
879 * Patterns without a specified style or weight are set to Medium |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
880 * Patterns without a specified style or slant are set to Roman |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
881 * Patterns without a specified pixel size are given one computed from any |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
882 specified point size (default 12), dpi (default 75) and scale (default 1). */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
883 (pattern)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
884 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
885 CHECK_FCPATTERN (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
886 FcDefaultSubstitute (XFCPATTERN_PTR (pattern)); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
887 return Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
888 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
889 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
890 /* -- Function: FcBool FcConfigSubstituteWithPat (FcConfig *config, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
891 FcPattern *p, FcPattern *p_pat FcMatchKind kind) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
892 OMITTED: use optional arguments in `fc-config-substitute'. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
893 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
894 DEFUN("fc-config-substitute", Ffc_config_substitute, 1, 4, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
895 Modifies PATTERN according to KIND and TESTPAT using operations from CONFIG. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
896 PATTERN is modified in-place. Returns an undocumented Boolean value. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
897 If optional KIND is `fc-match-pattern', then those tagged as pattern operations |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
898 are applied, else if KIND is `fc-match-font', those tagged as font operations |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
899 are applied and TESTPAT is used for <test> elements with target=pattern. KIND |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
900 defaults to `fc-match-font'. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
901 If optional TESTPAT is nil, it is ignored. Otherwise it must be an FcPattern. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
902 Optional CONFIG must be an FcConfig, defaulting to the current one. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
903 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
904 Note that this function actually corresponds to FcConfigSubstituteWithPat, and |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
905 the argument order is changed to take advantage of Lisp optional arguments. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
906 (pattern, kind, testpat, config)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
907 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
908 FcMatchKind knd; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
909 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
910 /* There ought to be a standard idiom for this.... */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
911 if (NILP (kind) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
912 || EQ (kind, Qfc_match_font)) { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
913 knd = FcMatchFont; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
914 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
915 else if (EQ (kind, Qfc_match_pattern)) { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
916 knd = FcMatchPattern; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
917 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
918 else { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
919 Fsignal (Qwrong_type_argument, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
920 list2 (build_string ("need `fc-match-pattern' or `fc-match-font'"), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
921 kind)); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
922 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
923 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
924 /* Typecheck arguments */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
925 CHECK_FCPATTERN (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
926 if (!NILP (testpat)) CHECK_FCPATTERN (testpat); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
927 if (!NILP (config)) CHECK_FCCONFIG (config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
928 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
929 return (FcConfigSubstituteWithPat |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
930 (NILP (config) ? FcConfigGetCurrent () : XFCCONFIG_PTR (config), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
931 XFCPATTERN_PTR (pattern), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
932 NILP (testpat) ? NULL : XFCPATTERN_PTR (testpat), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
933 knd) == FcTrue) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
934 ? Qt : Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
935 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
936 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
937 /* Pattern matching functions. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
938 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
939 /* The following functions return fonts that match a certain pattern. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
940 `FcFontRenderPrepare' and `FcFontMatch' always return a single best |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
941 match. `FcFontList' returns the list of fonts that match a given |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
942 pattern on a certain set of properties. `FcFontSort' returns the |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
943 entire list of fonts, sorted in order of match quality, possibly |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
944 filtering out fonts that do not provide additional characters beyond |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
945 those provided by preferred fonts. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
946 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
947 DEFUN("fc-font-render-prepare", Ffc_font_render_prepare, 2, 3, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
948 Return a new pattern blending PATTERN and FONT. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
949 Optional CONFIG is an FcConfig, defaulting to the current one. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
950 The returned pattern consists of elements of FONT not appearing in PATTERN, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
951 elements of PATTERN not appearing in FONT, and the best matching value from |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
952 PATTERN for elements appearing in both. The result is passed to |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
953 FcConfigSubstitute with 'kind' FcMatchFont and then returned. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
954 (pattern, font, config)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
955 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
956 if (NILP (config)) { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
957 config = Ffc_config_get_current (); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
958 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
959 CHECK_FCPATTERN (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
960 CHECK_FCPATTERN (font); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
961 CHECK_FCCONFIG (config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
962 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
963 /* I don't think this can fail? */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
964 return wrap_fcpattern (FcFontRenderPrepare (XFCCONFIG_PTR(config), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
965 XFCPATTERN_PTR(font), |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
966 XFCPATTERN_PTR(pattern))); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
967 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
968 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
969 DEFUN("fc-font-match", Ffc_font_match, 2, 3, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
970 Return the font on DEVICE that most closely matches PATTERN. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
971 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
972 DEVICE is an X11 device. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
973 PATTERN is a fontconfig pattern object. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
974 Optional CONFIG is an FcConfig, defaulting to the current one. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
975 Returns a fontconfig pattern object representing the closest match to the |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
976 given pattern, or an error code. Possible error codes are |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
977 `fc-result-no-match' and `fc-result-no-id'. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
978 PATTERN is massaged with FcConfigSubstitute and FcDefaultSubstitute before |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
979 being processed by FcFontMatch. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
980 (device, pattern, config)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
981 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
982 FcResult res; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
983 struct fc_pattern *res_fcpat; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
984 FcPattern *p; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
985 FcConfig *fcc; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
986 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
987 CHECK_FCPATTERN(pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
988 if (NILP(device)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
989 return Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
990 CHECK_X_DEVICE(device); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
991 if (!DEVICE_LIVE_P(XDEVICE(device))) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
992 return Qnil; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
993 if (!NILP (config)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
994 CHECK_FCCONFIG (config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
995 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
996 res_fcpat = ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
997 p = XFCPATTERN_PTR(pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
998 fcc = NILP (config) ? FcConfigGetCurrent () : XFCCONFIG_PTR (config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
999 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1000 FcConfigSubstitute (fcc, p, FcMatchPattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1001 FcDefaultSubstitute (p); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1002 res_fcpat->fcpatPtr = FcFontMatch (fcc, p, &res); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1003 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1004 if (res_fcpat->fcpatPtr == NULL) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1005 switch (res) { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1006 case FcResultNoMatch: |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1007 return Qfc_result_no_match; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1008 case FcResultNoId: |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1009 return Qfc_result_no_id; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1010 default: |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1011 return Qfc_internal_error; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1012 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1013 else |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1014 return wrap_fcpattern(res_fcpat); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1015 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1016 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1017 /* #### fix this name to correspond to Ben's new nomenclature */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1018 DEFUN("fc-list-fonts-pattern-objects", Ffc_list_fonts_pattern_objects, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1019 3, 3, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1020 Return a list of fonts on DEVICE that match PATTERN for PROPERTIES. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1021 Each font is represented by a fontconfig pattern object. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1022 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1023 DEVICE is an X11 device. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1024 PATTERN is a fontconfig pattern to be matched. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1025 PROPERTIES is a list of property names (strings) that should match. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1026 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1027 #### DEVICE is unused, ignored, and may be removed if it's not needed to |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1028 match other font-listing APIs. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1029 (UNUSED (device), pattern, properties)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1030 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1031 FcObjectSet *os; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1032 FcFontSet *fontset; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1033 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1034 CHECK_FCPATTERN (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1035 CHECK_LIST (properties); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1036 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1037 os = FcObjectSetCreate (); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1038 string_list_to_fcobjectset (properties, os); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1039 /* #### why don't we need to do the "usual substitutions"? */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1040 fontset = FcFontList (NULL, XFCPATTERN_PTR (pattern), os); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1041 FcObjectSetDestroy (os); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1042 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1043 return fontset_to_list (fontset, DestroyYes); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1044 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1045 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1046 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1047 /* #### maybe this can/should be folded into fc-list-fonts-pattern-objects? */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1048 DEFUN("fc-font-sort", Ffc_font_sort, 2, 4, 0, /* |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1049 Return a list of all fonts sorted by proximity to PATTERN. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1050 Each font is represented by a fontconfig pattern object. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1051 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1052 DEVICE is an X11 device. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1053 PATTERN is a fontconfig pattern to be matched. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1054 Optional argument TRIM, if non-nil, means to trim trailing fonts that do not |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1055 contribute new characters to the union repertoire. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1056 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1057 #### Optional argument NOSUB, if non-nil, suppresses some of the usual |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1058 property substitutions. DON'T USE THIS in production code, it is intended |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1059 for exploring behavior of fontconfig and will be removed when this code is |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1060 stable. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1061 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1062 #### DEVICE is unused, ignored, and may be removed if it's not needed to |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1063 match other font-listing APIs. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1064 (UNUSED (device), pattern, trim, nosub)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1065 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1066 CHECK_FCPATTERN (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1067 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1068 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1069 FcConfig *fcc = FcConfigGetCurrent(); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1070 FcFontSet *fontset; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1071 FcPattern *p = XFCPATTERN_PTR (pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1072 FcResult fcresult; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1073 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1074 if (NILP(nosub)) /* #### temporary debug hack */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1075 FcDefaultSubstitute (p); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1076 FcConfigSubstitute (fcc, p, FcMatchPattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1077 fontset = FcFontSort (fcc, p, !NILP(trim), NULL, &fcresult); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1078 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1079 return fontset_to_list (fontset, DestroyYes); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1080 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1081 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1082 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1083 #ifdef FONTCONFIG_EXPOSE_CONFIG |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1084 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1085 /* Configuration routines --- for debugging |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1086 Don't depend on these routines being available in the future! |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1087 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1088 3.2.10 Initialization |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1089 --------------------- |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1090 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1091 An FcConfig object holds the internal representation of a configuration. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1092 There is a default configuration which applications may use by passing |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1093 0 to any function using the data within an FcConfig. |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1094 */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1095 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1096 static void |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1097 finalize_fc_config (void *header, int UNUSED (for_disksave)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1098 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1099 struct fc_config *p = (struct fc_config *) header; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1100 if (p->fccfgPtr && p->fccfgPtr != FcConfigGetCurrent()) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1101 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1102 /* If we get here, all of *our* references are garbage (see comment on |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1103 fc_config_create_using() for why), and the only reference that |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1104 fontconfig keeps is the current FcConfig. */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1105 FcConfigDestroy (p->fccfgPtr); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1106 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1107 p->fccfgPtr = 0; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1108 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1109 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1110 static void |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1111 print_fc_config (Lisp_Object obj, Lisp_Object printcharfun, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1112 int UNUSED(escapeflag)) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1113 { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1114 struct fc_config *c = XFCCONFIG (obj); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1115 if (print_readably) |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1116 printing_unreadable_object ("#<fc-config 0x%x>", c->header.uid); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1117 write_fmt_string (printcharfun, "#<fc-config 0x%x>", c->header.uid); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1118 } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1119 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1120 static const struct memory_description fcconfig_description [] = { |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1121 /* #### nothing here, is this right?? */ |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1122 { XD_END } |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1123 }; |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1124 |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1125 DEFINE_LRECORD_IMPLEMENTATION("fc-config", fc_config, 0, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1126 0, print_fc_config, finalize_fc_config, 0, 0, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1127 fcconfig_description, |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1128 struct fc_config); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1129 |
3931 | 1130 DEFUN("fc-init", Ffc_init, 0, 0, 0, /* |
1131 -- Function: FcBool FcInit (void) | |
1132 Loads the default configuration file and the fonts referenced | |
1133 therein and sets the default configuration to that result. | |
1134 Returns whether this process succeeded or not. If the default | |
1135 configuration has already been loaded, this routine does nothing | |
1136 and returns FcTrue. */ | |
1137 ()) | |
1138 { | |
1139 return (FcInit () == FcTrue) ? Qt : Qnil; | |
1140 } | |
1141 | |
1142 DEFUN("fc-get-version", Ffc_get_version, 0, 0, 0, /* | |
1143 -- Function: int FcGetVersion (void) | |
1144 Returns the version number of the library. | |
3935 | 1145 XEmacs: No, this should NOT return a pretty string. |
3931 | 1146 (let ((i (fc-get-version))) |
1147 (format "%d.%d.%d" (/ i 10000) (mod (/ i 100) 100) (mod i 100))) | |
3935 | 1148 gives the usual x.y.z format. This is the version of the .so. It can be |
1149 checked against `fc-version', which is the version of fontconfig.h. | |
1150 It's probably not a disaster if `(> (fc-get-version) fc-version)'. */ | |
3931 | 1151 ()) |
1152 { | |
1153 return make_int (FcGetVersion ()); | |
1154 } | |
1155 | |
1156 DEFUN("fc-init-reinitialize", Ffc_init_reinitialize, 0, 0, 0, /* | |
1157 -- Function: FcBool FcInitReinitialize (void) | |
1158 Forces the default configuration file to be reloaded and resets | |
1159 the default configuration. */ | |
1160 ()) | |
1161 { | |
1162 return (FcInitReinitialize () == FcTrue) ? Qt : Qnil; | |
1163 } | |
1164 | |
1165 DEFUN("fc-init-bring-up-to-date", Ffc_init_bring_up_to_date, 0, 0, 0, /* | |
1166 -- Function: FcBool FcInitBringUptoDate (void) | |
1167 Checks the rescan interval in the default configuration, checking | |
1168 the configuration if the interval has passed and reloading the | |
1169 configuration when any changes are detected. */ | |
1170 ()) | |
1171 { | |
1172 return (FcInitBringUptoDate () == FcTrue) ? Qt : Qnil; | |
1173 } | |
1174 | |
1175 #endif /* FONTCONFIG_EXPOSE_CONFIG */ | |
1176 | |
3354 | 1177 DEFUN("xlfd-font-name-p", Fxlfd_font_name_p, 1, 1, 0, /* |
1178 Check whether the string FONTNAME is a XLFD font name. */ | |
1179 (fontname)) | |
1180 { | |
1181 CHECK_STRING(fontname); | |
1182 /* #### should bind `case-fold-search' here? */ | |
1183 return Fstring_match(Vxlfd_font_name_regexp, fontname, Qnil, Qnil); | |
1184 } | |
1185 | |
1186 /* FcPatternPrint: there is no point in having wrappers fc-pattern-print, | |
1187 Ffc_pattern_print since this function prints to stdout. */ | |
1188 | |
1189 /* Initialization of font-mgr */ | |
1190 | |
1191 #define XE_XLFD_SEPARATOR "-" | |
1192 /* XLFD specifies ISO 8859-1 encoding, but we can't handle non-ASCII | |
1193 in Mule when this function is called. So use HPC. */ | |
1194 #if 0 | |
1195 #define XE_XLFD_PREFIX "\\(\\+[\040-\176\240-\377]*\\)?-" | |
1196 #define XE_XLFD_OPT_TEXT "\\([\040-\044\046-\176\240-\377]*\\)" | |
1197 #define XE_XLFD_TEXT "\\([\040-\044\046-\176\240-\377]+\\)" | |
1198 #else | |
1199 #define XE_XLFD_PREFIX "\\(\\+[\040-\176]*\\)?-" | |
1200 #define XE_XLFD_OPT_TEXT "\\([^-]*\\)" | |
1201 #define XE_XLFD_TEXT "\\([^-]+\\)" | |
1202 #endif | |
1203 | |
1204 #define XE_XLFD_SLANT "\\([0-9ior?*][iot]?\\)" | |
1205 #define XE_XLFD_SPACING "\\([cmp?*]\\)" | |
1206 /* Hyphen as minus conflicts with use as separator. */ | |
1207 #define XE_XLFD_OPT_NEGATE "~?" | |
1208 #define XE_XLFD_NUMBER "\\([0-9?*]+\\)" | |
1209 #define XE_XLFD_PSIZE "\\([0-9?*]+\\|\\[[ 0-9+~.e?*]+\\]\\)" | |
1210 | |
1211 /* Call this only from the init code | |
1212 #### This is really horrible, let's get rid of it, please. */ | |
1213 static Lisp_Object | |
1214 make_xlfd_font_regexp (void) | |
1215 { | |
1216 struct gcpro gcpro1; | |
1217 unsigned i; | |
1218 Lisp_Object reg = Qnil; | |
1219 const Extbyte *re[] = /* #### This could just be catenated by | |
1220 cpp and passed to build_ext_string. */ | |
1221 { | |
1222 /* Regular expression matching XLFDs as defined by XLFD v. 1.5. | |
1223 Matches must be case-insensitive. | |
1224 PSIZE is a pixel or point size, which may be a "matrix". The | |
1225 syntax of a matrix is not checked, just some lexical properties. | |
1226 AFAICT none of the TEXT fields except adstyle is optional. | |
1227 | |
1228 NB. It should not be a problem if this matches "too much", since | |
1229 an "old" server will simply not be able to find a matching font. */ | |
1230 "\\`", | |
1231 XE_XLFD_PREFIX, /* prefix */ | |
1232 XE_XLFD_TEXT, /* foundry */ | |
1233 XE_XLFD_SEPARATOR, | |
1234 XE_XLFD_TEXT, /* family */ | |
1235 XE_XLFD_SEPARATOR, | |
1236 XE_XLFD_TEXT, /* weight */ | |
1237 XE_XLFD_SEPARATOR, | |
1238 XE_XLFD_SLANT, /* slant */ | |
1239 XE_XLFD_SEPARATOR, | |
1240 XE_XLFD_TEXT, /* swidth */ | |
1241 XE_XLFD_SEPARATOR, | |
1242 XE_XLFD_OPT_TEXT, /* adstyle */ | |
1243 XE_XLFD_SEPARATOR, | |
1244 XE_XLFD_PSIZE, /* pixelsize */ | |
1245 XE_XLFD_SEPARATOR, | |
1246 XE_XLFD_PSIZE, /* pointsize */ | |
1247 XE_XLFD_SEPARATOR, | |
1248 XE_XLFD_NUMBER, /* resx */ | |
1249 XE_XLFD_SEPARATOR, | |
1250 XE_XLFD_NUMBER, /* resy */ | |
1251 XE_XLFD_SEPARATOR, | |
1252 XE_XLFD_SPACING, /* spacing */ | |
1253 XE_XLFD_SEPARATOR, | |
1254 XE_XLFD_OPT_NEGATE, /* avgwidth */ | |
1255 XE_XLFD_NUMBER, | |
1256 XE_XLFD_SEPARATOR, | |
1257 XE_XLFD_TEXT, /* registry */ | |
1258 XE_XLFD_SEPARATOR, | |
1259 XE_XLFD_TEXT, /* encoding */ | |
1260 "\\'" | |
1261 }; | |
1262 | |
1263 GCPRO1 (reg); | |
1264 for (i = 0; i < sizeof(re)/sizeof(Extbyte *); i++) | |
1265 { | |
1266 /* #### Currently this is Host Portable Coding, not ISO 8859-1. */ | |
1267 reg = concat2(reg, build_ext_string (re[i], Qx_font_name_encoding)); | |
1268 } | |
1269 | |
1270 RETURN_UNGCPRO (reg); | |
1271 } | |
1272 #undef XE_XLFD_SEPARATOR | |
1273 #undef XE_XLFD_PREFIX | |
1274 #undef XE_XLFD_OPT_TEXT | |
1275 #undef XE_XLFD_TEXT | |
1276 #undef XE_XLFD_OPT_SLANT | |
1277 #undef XE_XLFD_OPT_SPACING | |
1278 #undef XE_XLFD_OPT_NEGATE | |
1279 #undef XE_XLFD_NUMBER | |
1280 #undef XE_XLFD_PSIZE | |
1281 | |
1282 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \ | |
1283 ? ((unsigned long) (x)) : ((unsigned long) (y))) | |
1284 | |
1285 static void | |
1286 string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os) | |
1287 { | |
1288 EXTERNAL_LIST_LOOP_2 (elt, list) | |
1289 { | |
3469 | 1290 const Extbyte *s; |
3354 | 1291 |
1292 CHECK_STRING (elt); | |
1293 s = fc_intern (elt); | |
1294 FcObjectSetAdd (os, s); | |
1295 } | |
1296 } | |
1297 | |
1298 void | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1299 syms_of_font_mgr (void) { |
3354 | 1300 INIT_LRECORD_IMPLEMENTATION(fc_pattern); |
1301 | |
1302 DEFSYMBOL_MULTIWORD_PREDICATE(Qfc_patternp); | |
1303 | |
1304 DEFSYMBOL(Qfc_result_type_mismatch); | |
1305 DEFSYMBOL(Qfc_result_no_match); | |
1306 DEFSYMBOL(Qfc_result_no_id); | |
1307 DEFSYMBOL(Qfc_internal_error); | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1308 DEFSYMBOL(Qfc_match_pattern); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1309 DEFSYMBOL(Qfc_match_font); |
3360 | 1310 DEFSYMBOL(Qfont_mgr); |
3354 | 1311 |
1312 DEFSUBR(Ffc_pattern_p); | |
1313 DEFSUBR(Ffc_pattern_create); | |
1314 DEFSUBR(Ffc_name_parse); | |
1315 DEFSUBR(Ffc_name_unparse); | |
1316 DEFSUBR(Ffc_pattern_duplicate); | |
1317 DEFSUBR(Ffc_pattern_add); | |
1318 DEFSUBR(Ffc_pattern_del); | |
1319 DEFSUBR(Ffc_pattern_get); | |
1320 DEFSUBR(Ffc_list_fonts_pattern_objects); | |
1321 DEFSUBR(Ffc_font_sort); | |
1322 DEFSUBR(Ffc_font_match); | |
4758
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1323 DEFSUBR(Ffc_default_substitute); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1324 DEFSUBR(Ffc_config_substitute); |
75975fd0b7fc
Implement more of the fontconfig API.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4757
diff
changeset
|
1325 DEFSUBR(Ffc_font_render_prepare); |
3354 | 1326 DEFSUBR(Fxlfd_font_name_p); |
3931 | 1327 |
1328 #ifdef FONTCONFIG_EXPOSE_CONFIG | |
1329 INIT_LRECORD_IMPLEMENTATION(fc_config); | |
1330 | |
1331 DEFSYMBOL_MULTIWORD_PREDICATE(Qfc_configp); | |
1332 | |
1333 DEFSUBR(Ffc_config_p); | |
1334 DEFSUBR(Ffc_config_create); | |
1335 #if 0 | |
1336 DEFSUBR(Ffc_config_destroy); | |
1337 #endif | |
1338 DEFSUBR(Ffc_config_set_current); | |
1339 DEFSUBR(Ffc_config_get_current); | |
1340 DEFSUBR(Ffc_config_up_to_date); | |
1341 DEFSUBR(Ffc_config_build_fonts); | |
1342 DEFSUBR(Ffc_config_get_config_dirs); | |
1343 DEFSUBR(Ffc_config_get_font_dirs); | |
1344 DEFSUBR(Ffc_config_get_config_files); | |
1345 DEFSUBR(Ffc_config_get_cache); | |
1346 DEFSUBR(Ffc_config_get_fonts); | |
1347 DEFSUBR(Ffc_config_get_blanks); | |
1348 DEFSUBR(Ffc_config_get_rescan_interval); | |
1349 DEFSUBR(Ffc_config_set_rescan_interval); | |
1350 DEFSUBR(Ffc_config_app_font_add_file); | |
1351 DEFSUBR(Ffc_config_app_font_add_dir); | |
1352 DEFSUBR(Ffc_config_app_font_clear); | |
1353 DEFSUBR(Ffc_config_filename); | |
1354 DEFSUBR(Ffc_init_load_config); | |
1355 DEFSUBR(Ffc_init_load_config_and_fonts); | |
1356 DEFSUBR(Ffc_init); | |
1357 DEFSUBR(Ffc_get_version); | |
1358 DEFSUBR(Ffc_init_reinitialize); | |
1359 DEFSUBR(Ffc_init_bring_up_to_date); | |
1360 #endif /* FONTCONFIG_EXPOSE_CONFIG */ | |
3354 | 1361 } |
1362 | |
1363 void | |
1364 vars_of_font_mgr (void) | |
1365 { | |
3935 | 1366 /* #### The next two DEFVARs belong somewhere else. */ |
3354 | 1367 |
1368 /* #### I know, but the right fix is use the generic debug facility. */ | |
1369 DEFVAR_INT ("xft-debug-level", &debug_xft /* | |
1370 Level of debugging messages to issue to stderr for Xft. | |
1371 A nonnegative integer. Set to 0 to suppress all warnings. | |
1372 Default is 1 to ensure a minimum of debugging output at initialization. | |
1373 Higher levels give even more information. | |
1374 */ ); | |
4757
a23ac8f90a49
Improve warning and error messages from Xft.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4328
diff
changeset
|
1375 debug_xft = 0; |
3354 | 1376 |
3935 | 1377 DEFVAR_CONST_INT("xft-version", &xft_version /* |
3354 | 1378 The major version number of the Xft library being used. |
1379 */ ); | |
3935 | 1380 xft_version = XFT_VERSION; |
1381 | |
1382 DEFVAR_CONST_INT("fc-version", &fc_version /* | |
1383 The version number of fontconfig.h. It can be checked against | |
1384 `(fc-get-version)', which is the version of the .so. | |
1385 It's probably not a disaster if `(> (fc-get-version) fc-version)'. | |
1386 */ ); | |
1387 fc_version = FC_VERSION; | |
3354 | 1388 |
3360 | 1389 Fprovide (intern ("font-mgr")); |
3354 | 1390 } |
1391 | |
1392 void | |
1393 complex_vars_of_font_mgr (void) | |
1394 { | |
3931 | 1395 #ifdef FONTCONFIG_EXPOSE_CONFIG |
1396 Vfc_config_weak_list = make_weak_list (WEAK_LIST_SIMPLE); | |
1397 staticpro (&Vfc_config_weak_list); | |
1398 #endif | |
1399 | |
3354 | 1400 DEFVAR_LISP("xft-xlfd-font-regexp", &Vxlfd_font_name_regexp /* |
1401 The regular expression used to match XLFD font names. */ | |
1402 ); | |
1403 Vxlfd_font_name_regexp = make_xlfd_font_regexp(); | |
1404 } | |
1405 | |
1406 void | |
1407 reinit_vars_of_font_mgr (void) | |
1408 { | |
1409 int i, size = (int) countof (fc_standard_properties); | |
1410 | |
1411 FcInit (); | |
1412 | |
1413 fc_property_name_hash_table = make_string_hash_table (size); | |
1414 for (i = 0; i < size; ++i) | |
1415 puthash (fc_standard_properties[i], NULL, fc_property_name_hash_table); | |
1416 } | |
1417 |