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