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
|
|
5 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
|
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
|
|
11 Updated: 05 Mar 2005 by Stephen J. Turnbull
|
|
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. */
|
|
83
|
|
84 /****************************************************************
|
|
85 * FcPattern objects *
|
|
86 ****************************************************************/
|
|
87
|
|
88 static void
|
|
89 finalize_fc_pattern (void *header, int UNUSED (for_disksave))
|
|
90 {
|
|
91 struct fc_pattern *p = (struct fc_pattern *) header;
|
|
92 if (p->fcpatPtr)
|
|
93 {
|
|
94 FcPatternDestroy (p->fcpatPtr);
|
|
95 p->fcpatPtr = 0;
|
|
96 }
|
|
97 }
|
|
98
|
|
99 static const struct memory_description fcpattern_description [] = {
|
|
100 /* #### nothing here, is this right?? */
|
|
101 { XD_END }
|
|
102 };
|
|
103
|
|
104 DEFINE_LRECORD_IMPLEMENTATION("fc-pattern", fc_pattern,
|
|
105 0, 0, 0, finalize_fc_pattern, 0, 0,
|
|
106 fcpattern_description,
|
|
107 struct fc_pattern);
|
|
108
|
|
109 /*
|
|
110 * Helper Functions
|
|
111 */
|
|
112 static Lisp_Object make_xlfd_font_regexp (void);
|
|
113 static void string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os);
|
|
114
|
|
115 /*
|
|
116 extract the C representation of the Lisp string STR and convert it
|
|
117 to the encoding used by the Fontconfig API for property and font
|
|
118 names. I suppose that Qnative is the right encoding, the manual
|
|
119 doesn't say much about this topic. This functions assumes that STR
|
|
120 is a Lisp string.
|
|
121 */
|
|
122 #define extract_fcapi_string(str) \
|
3360
|
123 ((FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((str), Qfc_font_name_encoding))
|
3354
|
124
|
3360
|
125 /* #### This homebrew lashup should be replaced with FcConstants.
|
|
126
|
|
127 fontconfig assumes that objects (property names) are statically allocated,
|
3354
|
128 and you will get bizarre results if you pass Lisp string data or strings
|
|
129 allocated on the stack as objects. fontconfig _does_ copy values, so we
|
|
130 (I hope) don't have to worry about that member.
|
|
131
|
|
132 Probably these functions don't get called so often that the memory leak
|
|
133 due to strdup'ing every time we add a property would matter, but XEmacs
|
|
134 _is_ a long-running process. So we hash them.
|
|
135
|
|
136 I suspect that using symbol names or even keywords does not provide
|
|
137 assurance that the string won't move in memory. So we hash them
|
3360
|
138 ourselves; hash.c hashtables do not interpret the value pointers.
|
|
139
|
|
140 This array should be FcChar8**, but GCC 4.x bitches about signedness. */
|
|
141 static Extbyte *fc_standard_properties[] = {
|
|
142 /* treated specially, ordered first */
|
|
143 "family", "size",
|
|
144 /* remaining are alphabetized by group */
|
|
145 /* standard properties in fontconfig and Xft v.2 */
|
|
146 "antialias", "aspect", "autohint", "charset", "dpi", "file",
|
3354
|
147 "foundry", "ftface", "globaladvance", "hinting", "index", "lang",
|
|
148 "minspace", "outline", "pixelsize", "rasterizer", "rgba", "scalable",
|
3360
|
149 "scale", "slant", "spacing", "style", "verticallayout", "weight",
|
|
150 /* common in modern fonts */
|
|
151 "fontformat", "fontversion",
|
3354
|
152 /* obsolete after Xft v. 1 */
|
|
153 "charwidth", "charheight", "core", "encoding", "render"
|
|
154 };
|
|
155
|
|
156 static struct hash_table *fc_property_name_hash_table;
|
|
157
|
|
158 /* #### Maybe fc_intern should be exposed to LISP? The idea is that
|
|
159 fc-pattern-add could warn or error if the property isn't interned. */
|
|
160
|
|
161 static FcChar8 *
|
|
162 fc_intern (Lisp_Object property)
|
|
163 {
|
|
164 const void *dummy;
|
|
165 FcChar8 *prop = extract_fcapi_string (property);
|
|
166 const void *val = gethash (prop, fc_property_name_hash_table, &dummy);
|
|
167
|
|
168 /* extract_fcapi_string returns something alloca'd
|
|
169 so we can just drop the old value of prop on the floor */
|
|
170 if (val)
|
|
171 prop = (FcChar8 *) val;
|
|
172 else
|
|
173 {
|
|
174 prop = FcStrCopy (prop);
|
|
175 puthash (prop, NULL, fc_property_name_hash_table);
|
|
176 }
|
|
177 return prop;
|
|
178 }
|
|
179
|
|
180 DEFUN("fc-pattern-p", Ffc_pattern_p, 1, 1, 0, /*
|
|
181 Returns t if OBJECT is of type fc-pattern, nil otherwise.
|
|
182 */
|
|
183 (object))
|
|
184 {
|
|
185 return FCPATTERNP(object) ? Qt : Qnil;
|
|
186 }
|
|
187
|
|
188 DEFUN("fc-pattern-create", Ffc_pattern_create, 0, 0, 0, /*
|
|
189 Return a new, empty fc-pattern object.
|
|
190 */
|
|
191 ())
|
|
192 {
|
|
193 fc_pattern *fcpat =
|
|
194 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern);
|
|
195
|
|
196 fcpat->fcpatPtr = FcPatternCreate();
|
|
197 return wrap_fcpattern(fcpat);
|
|
198 }
|
|
199
|
|
200 DEFUN("fc-name-parse", Ffc_name_parse, 1, 1, 0, /*
|
|
201 Parse an Fc font name and return its representation as a fc pattern object.
|
|
202 */
|
|
203 (name))
|
|
204 {
|
|
205 struct fc_pattern *fcpat =
|
|
206 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern);
|
|
207
|
|
208 CHECK_STRING(name); /* #### MEMORY LEAK!! maybe not ... */
|
|
209
|
|
210 fcpat->fcpatPtr = FcNameParse (extract_fcapi_string (name));
|
|
211 return wrap_fcpattern(fcpat);
|
|
212 }
|
|
213
|
|
214 /* #### Ga-a-ack! Xft's similar function is actually a different API.
|
|
215 We provide both. */
|
|
216 DEFUN("fc-name-unparse", Ffc_name_unparse, 1, 1, 0, /*
|
|
217 Unparse an fc pattern object to a string.
|
|
218 */
|
|
219 (pattern))
|
|
220 {
|
|
221 CHECK_FCPATTERN(pattern);
|
|
222 {
|
|
223 FcChar8 *temp = FcNameUnparse(XFCPATTERN_PTR(pattern));
|
3360
|
224 Lisp_Object res = build_ext_string (temp, Qfc_font_name_encoding);
|
3354
|
225 free (temp);
|
|
226 return res;
|
|
227 }
|
|
228 }
|
|
229
|
|
230 DEFUN("fc-pattern-duplicate", Ffc_pattern_duplicate, 1, 1, 0, /*
|
|
231 Make a copy of the fc pattern object PATTERN and return it.
|
|
232 */
|
|
233 (pattern))
|
|
234 {
|
|
235 struct fc_pattern *copy = NULL;
|
|
236 CHECK_FCPATTERN(pattern);
|
|
237
|
|
238 copy = ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern);
|
|
239 copy->fcpatPtr = FcPatternDuplicate(XFCPATTERN_PTR(pattern));
|
|
240 return wrap_fcpattern(copy);
|
|
241 }
|
|
242
|
|
243 DEFUN("fc-pattern-add", Ffc_pattern_add, 3, 3, 0, /*
|
|
244 Add attributes to the pattern object PATTERN. PROPERTY is a string naming
|
|
245 the attribute to add, VALUE the value for this attribute.
|
|
246
|
|
247 VALUE may be a string, integer, float, or symbol, in which case the value
|
|
248 will be added as an FcChar8[], int, double, or FcBool respectively.
|
|
249 */
|
|
250 (pattern, property, value))
|
|
251 {
|
|
252 Bool res = 0;
|
|
253 Extbyte *obj;
|
|
254 FcPattern *fcpat;
|
|
255
|
|
256 CHECK_FCPATTERN(pattern);
|
|
257 CHECK_STRING(property);
|
|
258
|
|
259 obj = fc_intern (property);
|
|
260 fcpat = XFCPATTERN_PTR (pattern);
|
|
261
|
|
262 if (STRINGP(value))
|
|
263 {
|
|
264 FcChar8 *str = (FcChar8 *) extract_fcapi_string (value);
|
|
265 res = FcPatternAddString (fcpat, obj, str);
|
|
266 }
|
|
267 else if (INTP(value))
|
|
268 {
|
|
269 res = FcPatternAddInteger (fcpat, obj, XINT(value));
|
|
270 }
|
|
271 else if (FLOATP(value))
|
|
272 {
|
|
273 res = FcPatternAddDouble (fcpat, obj, (double) XFLOAT_DATA(value));
|
|
274 }
|
|
275 else if (SYMBOLP(value))
|
|
276 {
|
|
277 res = FcPatternAddBool (fcpat, obj, !NILP(value));
|
|
278 }
|
|
279 /* else ... maybe we should wta here? */
|
|
280
|
|
281 return res ? Qt : Qnil;
|
|
282 }
|
|
283
|
|
284 DEFUN("fc-pattern-del", Ffc_pattern_del, 2, 2, 0, /*
|
|
285 Remove attribute PROPERTY from fc pattern object OBJECT.
|
|
286 */
|
|
287 (pattern, property))
|
|
288 {
|
|
289 Bool res;
|
|
290
|
|
291 CHECK_FCPATTERN(pattern);
|
|
292 CHECK_STRING(property);
|
|
293
|
|
294 res = FcPatternDel(XFCPATTERN_PTR(pattern),
|
|
295 extract_fcapi_string (property));
|
|
296 return res ? Qt : Qnil;
|
|
297 }
|
|
298
|
|
299 /* Generic interface to FcPatternGet()
|
|
300 * Don't support the losing symbol-for-property interface.
|
|
301 */
|
|
302 DEFUN("fc-pattern-get", Ffc_pattern_get, 2, 4, 0, /*
|
|
303 From PATTERN, extract PROPERTY for the ID'th member, of type TYPE.
|
|
304
|
|
305 PATTERN is an Xft (fontconfig) pattern object.
|
|
306 PROPERTY is a string naming an fontconfig font property.
|
|
307 Optional ID is a nonnegative integer indexing the list of values for PROPERTY
|
|
308 stored in PATTERN, defaulting to 0 (the first value).
|
|
309 Optional TYPE is a symbol, one of 'string, 'boolean, 'integer, 'float,
|
|
310 'double, 'matrix, 'charset, or 'void, corresponding to the FcValue types.
|
|
311 ('float is an alias for 'double).
|
|
312
|
|
313 The Lisp types returned will conform to TYPE:
|
|
314 string string
|
|
315 boolean `t' or `nil'
|
|
316 integer integer
|
|
317 double (float) float
|
|
318 matrix not implemented
|
|
319 charset not implemented
|
|
320 void not implemented
|
|
321
|
|
322 Symbols with names of the form "fc-result-DESCRIPTION" are returned when
|
|
323 the desired value is not available. These are
|
|
324
|
|
325 fc-result-type-mismatch the value found has an unexpected type
|
|
326 fc-result-no-match there is no such attribute
|
|
327 fc-result-no-id there is no value for the requested ID
|
|
328
|
|
329 The types of the following standard properties are predefined by fontconfig.
|
|
330 The symbol 'fc-result-type-mismatch will be returned if the object exists but
|
|
331 TYPE does not match the predefined type. It is best not to specify a type
|
|
332 for predefined properties, as a mistake here ensures error returns on the
|
|
333 correct type.
|
|
334
|
|
335 Each standard property has a convenience accessor defined in fontconfig.el,
|
|
336 named in the form "fc-pattern-get-PROPERTY". The convenience functions are
|
|
337 preferred to `fc-pattern-get' since a typo in the string naming a property
|
|
338 will result in a silent null return, while a typo in a function name will
|
|
339 usually result in a compiler or runtime \"not fboundp\" error. You may use
|
|
340 `defsubst' to define convenience functions for non-standard properties.
|
|
341
|
|
342 family String Font family name
|
|
343 style String Font style. Overrides weight and slant
|
|
344 slant Int Italic, oblique or roman
|
|
345 weight Int Light, medium, demibold, bold or black
|
|
346 size Double Point size
|
|
347 aspect Double Stretches glyphs horizontally before hinting
|
|
348 pixelsize Double Pixel size
|
|
349 spacing Int Proportional, monospace or charcell
|
|
350 foundry String Font foundry name
|
|
351 antialias Bool Whether glyphs can be antialiased
|
|
352 hinting Bool Whether the rasterizer should use hinting
|
|
353 verticallayout Bool Use vertical layout
|
|
354 autohint Bool Use autohinter instead of normal hinter
|
|
355 globaladvance Bool Use font global advance data
|
|
356 file String The filename holding the font
|
|
357 index Int The index of the font within the file
|
|
358 ftface FT_Face Use the specified FreeType face object
|
|
359 rasterizer String Which rasterizer is in use
|
|
360 outline Bool Whether the glyphs are outlines
|
|
361 scalable Bool Whether glyphs can be scaled
|
|
362 scale Double Scale factor for point->pixel conversions
|
|
363 dpi Double Target dots per inch
|
|
364 rgba Int unknown, rgb, bgr, vrgb, vbgr, none - subpixel geometry
|
|
365 minspace Bool Eliminate leading from line spacing
|
|
366 charset CharSet Unicode chars encoded by the font
|
|
367 lang String List of RFC-3066-style languages this font supports
|
|
368
|
|
369 The FT_Face, Matrix, CharSet types are unimplemented, so the corresponding
|
|
370 properties are not accessible from Lisp at this time. If the value of a
|
|
371 property returned has type FT_Face, FcCharSet, or FcMatrix,
|
|
372 `fc-result-type-mismatch' is returned.
|
|
373
|
|
374 The following properties which were standard in Xft v.1 are obsolete in
|
|
375 Xft v.2: encoding, charwidth, charheight, core, and render. */
|
|
376 (pattern, property, id, type))
|
|
377 {
|
|
378 FcChar8 *fc_property; /* UExtbyte * */
|
|
379 FcResult fc_result;
|
|
380 FcValue fc_value;
|
|
381
|
|
382 /*
|
|
383 process arguments
|
|
384 */
|
|
385 CHECK_FCPATTERN (pattern);
|
|
386
|
|
387 #if 0
|
|
388 /* Don't support the losing symbol-for-property interface. */
|
|
389 property = SYMBOLP (property) ? symbol_name (XSYMBOL (property)) : property;
|
|
390 #endif
|
|
391 if (STRINGP (property))
|
|
392 {
|
|
393 fc_property = (FcChar8 *) extract_fcapi_string (property);
|
|
394 }
|
|
395 else
|
|
396 {
|
|
397 /* if we allow symbols, this would need to be
|
|
398 list3 (Qlambda, list1 (Qobject),
|
|
399 list3 (Qor, list2 (Qstringp, Qobject),
|
|
400 list2 (Qsymbolp, Qobject)))
|
|
401 or something like that? */
|
|
402 dead_wrong_type_argument (Qstringp, property);
|
|
403 }
|
|
404
|
|
405 if (!NILP (id)) CHECK_NATNUM (id);
|
|
406 if (!NILP (type)) CHECK_SYMBOL (type);
|
|
407
|
|
408 /* get property */
|
|
409 fc_result = FcPatternGet (XFCPATTERN_PTR (pattern),
|
|
410 fc_property,
|
|
411 NILP (id) ? 0 : XINT(id),
|
|
412 &fc_value);
|
|
413
|
|
414 switch (fc_result)
|
|
415 {
|
|
416 case FcResultMatch:
|
|
417 /* wrap it and return */
|
|
418 switch (fc_value.type)
|
|
419 {
|
|
420 case FcTypeInteger:
|
|
421 return ((!NILP (type) && !EQ (type, Qinteger))
|
|
422 ? Qfc_result_type_mismatch : make_int (fc_value.u.i));
|
|
423 case FcTypeDouble:
|
|
424 return ((!NILP (type) && !EQ (type, intern ("double"))
|
|
425 && !EQ (type, Qfloat))
|
|
426 ? Qfc_result_type_mismatch : make_float (fc_value.u.d));
|
|
427 case FcTypeString:
|
|
428 return ((!NILP (type) && !EQ (type, Qstring))
|
|
429 ? Qfc_result_type_mismatch
|
3360
|
430 : build_ext_string (fc_value.u.s, Qfc_font_name_encoding));
|
3354
|
431 case FcTypeBool:
|
|
432 return ((!NILP (type) && !EQ (type, Qboolean))
|
|
433 ? Qfc_result_type_mismatch : fc_value.u.b ? Qt : Qnil);
|
|
434 case FcTypeMatrix:
|
|
435 return Qfc_result_type_mismatch;
|
|
436 /* #### unimplemented
|
|
437 return ((!NILP (type) && !EQ (type, intern ("matrix")))
|
|
438 ? Qfc_result_type_mismatch : make_int (fc_value.u.m));
|
|
439 */
|
|
440 case FcTypeCharSet:
|
|
441 return Qfc_result_type_mismatch;
|
|
442 /* #### unimplemented
|
|
443 return ((!NILP (type) && !EQ (type, intern ("charset")))
|
|
444 ? Qfc_result_type_mismatch : make_int (fc_value.u.c));
|
|
445 */
|
|
446 }
|
|
447 case FcResultTypeMismatch:
|
|
448 return Qfc_result_type_mismatch;
|
|
449 case FcResultNoMatch:
|
|
450 return Qfc_result_no_match;
|
|
451 case FcResultNoId:
|
|
452 return Qfc_result_no_id;
|
|
453 default:
|
|
454 return Qfc_internal_error;
|
|
455 }
|
|
456 }
|
|
457
|
|
458 DEFUN("fc-font-match", Ffc_font_match, 2, 2, 0, /*
|
|
459 Return the font on DEVICE that most closely matches PATTERN.
|
|
460
|
|
461 DEVICE is an X11 device.
|
|
462 PATTERN is a fontconfig pattern object.
|
|
463 Returns a fontconfig pattern object representing the closest match to the
|
|
464 given pattern, or an error code. Possible error codes are
|
|
465 `fc-result-no-match' and `fc-result-no-id'. */
|
|
466 (device, pattern))
|
|
467 {
|
|
468 FcResult res;
|
|
469
|
|
470 struct fc_pattern *res_fcpat =
|
|
471 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern);
|
|
472 CHECK_FCPATTERN(pattern); /* #### MEMORY LEAKS!!! */
|
|
473 if (NILP(device))
|
|
474 return Qnil;
|
|
475 CHECK_X_DEVICE(device);
|
|
476 if (!DEVICE_LIVE_P(XDEVICE(device)))
|
|
477 return Qnil;
|
|
478
|
3360
|
479 {
|
|
480 FcPattern *p = XFCPATTERN_PTR(pattern);
|
|
481 FcConfig *fcc = FcConfigGetCurrent ();
|
|
482
|
|
483 FcConfigSubstitute (fcc, p, FcMatchPattern);
|
|
484 FcDefaultSubstitute (p);
|
|
485 res_fcpat->fcpatPtr = FcFontMatch (fcc, p, &res);
|
|
486 }
|
|
487
|
3354
|
488 if (res_fcpat->fcpatPtr == NULL)
|
|
489 switch (res) {
|
|
490 case FcResultNoMatch:
|
|
491 return Qfc_result_no_match;
|
|
492 case FcResultNoId:
|
|
493 return Qfc_result_no_id;
|
|
494 default:
|
|
495 return Qfc_internal_error;
|
|
496 }
|
|
497 else
|
|
498 return wrap_fcpattern(res_fcpat);
|
|
499 }
|
|
500
|
|
501 /* NOTE NOTE NOTE This function destroys the FcFontSet passed to it. */
|
|
502 static Lisp_Object
|
|
503 fontset_to_list (FcFontSet *fontset)
|
|
504 {
|
|
505 int idx;
|
|
506 Lisp_Object fontlist = Qnil;
|
|
507 fc_pattern *fcpat;
|
|
508
|
|
509 /* #### improve this error message */
|
|
510 if (!fontset)
|
|
511 Fsignal (Qinvalid_state,
|
|
512 list1 (build_string ("failed to create FcFontSet")));
|
|
513 for (idx = 0; idx < fontset->nfont; ++idx)
|
|
514 {
|
|
515 fcpat =
|
|
516 ALLOC_LCRECORD_TYPE (struct fc_pattern, &lrecord_fc_pattern);
|
|
517 fcpat->fcpatPtr = FcPatternDuplicate (fontset->fonts[idx]);
|
|
518 fontlist = Fcons (wrap_fcpattern(fcpat), fontlist);
|
|
519 }
|
|
520 FcFontSetDestroy (fontset);
|
|
521 return fontlist;
|
|
522 }
|
|
523
|
|
524 /* #### fix this name to correspond to Ben's new nomenclature */
|
|
525 DEFUN("fc-list-fonts-pattern-objects", Ffc_list_fonts_pattern_objects,
|
|
526 3, 3, 0, /*
|
|
527 Return a list of fonts on DEVICE that match PATTERN for PROPERTIES.
|
|
528 Each font is represented by a fontconfig pattern object.
|
|
529
|
|
530 DEVICE is an X11 device.
|
|
531 PATTERN is a fontconfig pattern to be matched.
|
|
532 PROPERTIES is a list of property names (strings) that should match.
|
|
533
|
|
534 #### DEVICE is unused, ignored, and may be removed if it's not needed to
|
|
535 match other font-listing APIs. */
|
|
536 (UNUSED (device), pattern, properties))
|
|
537 {
|
|
538 FcObjectSet *os;
|
|
539 FcFontSet *fontset;
|
|
540
|
|
541 CHECK_FCPATTERN (pattern);
|
|
542 CHECK_LIST (properties);
|
|
543
|
|
544 os = FcObjectSetCreate ();
|
|
545 string_list_to_fcobjectset (properties, os);
|
|
546 /* #### why don't we need to do the "usual substitutions"? */
|
|
547 fontset = FcFontList (NULL, XFCPATTERN_PTR (pattern), os);
|
|
548 FcObjectSetDestroy (os);
|
|
549
|
|
550 return fontset_to_list (fontset);
|
|
551
|
|
552 }
|
|
553
|
|
554 /* #### maybe this can/should be folded into fc-list-fonts-pattern-objects? */
|
|
555 DEFUN("fc-font-sort", Ffc_font_sort, 2, 4, 0, /*
|
|
556 Return a list of all fonts sorted by proximity to PATTERN.
|
|
557 Each font is represented by a fontconfig pattern object.
|
|
558
|
|
559 DEVICE is an X11 device.
|
|
560 PATTERN is a fontconfig pattern to be matched.
|
|
561 Optional argument TRIM, if non-nil, means to trim trailing fonts that do not
|
|
562 contribute new characters to the union repertoire.
|
|
563
|
|
564 #### Optional argument NOSUB, if non-nil, suppresses some of the usual
|
|
565 property substitutions. DON'T USE THIS in production code, it is intended
|
|
566 for exploring behavior of fontconfig and will be removed when this code is
|
|
567 stable.
|
|
568
|
|
569 #### DEVICE is unused, ignored, and may be removed if it's not needed to
|
|
570 match other font-listing APIs. */
|
|
571 (UNUSED (device), pattern, trim, nosub))
|
|
572 {
|
|
573 CHECK_FCPATTERN (pattern);
|
|
574
|
|
575 {
|
|
576 FcConfig *fcc = FcConfigGetCurrent();
|
|
577 FcFontSet *fontset;
|
|
578 FcPattern *p = XFCPATTERN_PTR (pattern);
|
|
579 FcResult fcresult;
|
|
580
|
|
581 if (NILP(nosub)) /* #### temporary debug hack */
|
|
582 FcDefaultSubstitute (p);
|
|
583 FcConfigSubstitute (fcc, p, FcMatchPattern);
|
|
584 fontset = FcFontSort (fcc, p, !NILP(trim), NULL, &fcresult);
|
|
585
|
|
586 return fontset_to_list (fontset);
|
|
587 }
|
|
588 }
|
|
589
|
|
590 DEFUN("xlfd-font-name-p", Fxlfd_font_name_p, 1, 1, 0, /*
|
|
591 Check whether the string FONTNAME is a XLFD font name. */
|
|
592 (fontname))
|
|
593 {
|
|
594 CHECK_STRING(fontname);
|
|
595 /* #### should bind `case-fold-search' here? */
|
|
596 return Fstring_match(Vxlfd_font_name_regexp, fontname, Qnil, Qnil);
|
|
597 }
|
|
598
|
|
599 /* FcPatternPrint: there is no point in having wrappers fc-pattern-print,
|
|
600 Ffc_pattern_print since this function prints to stdout. */
|
|
601
|
|
602 /* Initialization of font-mgr */
|
|
603
|
|
604 #define XE_XLFD_SEPARATOR "-"
|
|
605 /* XLFD specifies ISO 8859-1 encoding, but we can't handle non-ASCII
|
|
606 in Mule when this function is called. So use HPC. */
|
|
607 #if 0
|
|
608 #define XE_XLFD_PREFIX "\\(\\+[\040-\176\240-\377]*\\)?-"
|
|
609 #define XE_XLFD_OPT_TEXT "\\([\040-\044\046-\176\240-\377]*\\)"
|
|
610 #define XE_XLFD_TEXT "\\([\040-\044\046-\176\240-\377]+\\)"
|
|
611 #else
|
|
612 #define XE_XLFD_PREFIX "\\(\\+[\040-\176]*\\)?-"
|
|
613 #define XE_XLFD_OPT_TEXT "\\([^-]*\\)"
|
|
614 #define XE_XLFD_TEXT "\\([^-]+\\)"
|
|
615 #endif
|
|
616
|
|
617 #define XE_XLFD_SLANT "\\([0-9ior?*][iot]?\\)"
|
|
618 #define XE_XLFD_SPACING "\\([cmp?*]\\)"
|
|
619 /* Hyphen as minus conflicts with use as separator. */
|
|
620 #define XE_XLFD_OPT_NEGATE "~?"
|
|
621 #define XE_XLFD_NUMBER "\\([0-9?*]+\\)"
|
|
622 #define XE_XLFD_PSIZE "\\([0-9?*]+\\|\\[[ 0-9+~.e?*]+\\]\\)"
|
|
623
|
|
624 /* Call this only from the init code
|
|
625 #### This is really horrible, let's get rid of it, please. */
|
|
626 static Lisp_Object
|
|
627 make_xlfd_font_regexp (void)
|
|
628 {
|
|
629 struct gcpro gcpro1;
|
|
630 unsigned i;
|
|
631 Lisp_Object reg = Qnil;
|
|
632 const Extbyte *re[] = /* #### This could just be catenated by
|
|
633 cpp and passed to build_ext_string. */
|
|
634 {
|
|
635 /* Regular expression matching XLFDs as defined by XLFD v. 1.5.
|
|
636 Matches must be case-insensitive.
|
|
637 PSIZE is a pixel or point size, which may be a "matrix". The
|
|
638 syntax of a matrix is not checked, just some lexical properties.
|
|
639 AFAICT none of the TEXT fields except adstyle is optional.
|
|
640
|
|
641 NB. It should not be a problem if this matches "too much", since
|
|
642 an "old" server will simply not be able to find a matching font. */
|
|
643 "\\`",
|
|
644 XE_XLFD_PREFIX, /* prefix */
|
|
645 XE_XLFD_TEXT, /* foundry */
|
|
646 XE_XLFD_SEPARATOR,
|
|
647 XE_XLFD_TEXT, /* family */
|
|
648 XE_XLFD_SEPARATOR,
|
|
649 XE_XLFD_TEXT, /* weight */
|
|
650 XE_XLFD_SEPARATOR,
|
|
651 XE_XLFD_SLANT, /* slant */
|
|
652 XE_XLFD_SEPARATOR,
|
|
653 XE_XLFD_TEXT, /* swidth */
|
|
654 XE_XLFD_SEPARATOR,
|
|
655 XE_XLFD_OPT_TEXT, /* adstyle */
|
|
656 XE_XLFD_SEPARATOR,
|
|
657 XE_XLFD_PSIZE, /* pixelsize */
|
|
658 XE_XLFD_SEPARATOR,
|
|
659 XE_XLFD_PSIZE, /* pointsize */
|
|
660 XE_XLFD_SEPARATOR,
|
|
661 XE_XLFD_NUMBER, /* resx */
|
|
662 XE_XLFD_SEPARATOR,
|
|
663 XE_XLFD_NUMBER, /* resy */
|
|
664 XE_XLFD_SEPARATOR,
|
|
665 XE_XLFD_SPACING, /* spacing */
|
|
666 XE_XLFD_SEPARATOR,
|
|
667 XE_XLFD_OPT_NEGATE, /* avgwidth */
|
|
668 XE_XLFD_NUMBER,
|
|
669 XE_XLFD_SEPARATOR,
|
|
670 XE_XLFD_TEXT, /* registry */
|
|
671 XE_XLFD_SEPARATOR,
|
|
672 XE_XLFD_TEXT, /* encoding */
|
|
673 "\\'"
|
|
674 };
|
|
675
|
|
676 GCPRO1 (reg);
|
|
677 for (i = 0; i < sizeof(re)/sizeof(Extbyte *); i++)
|
|
678 {
|
|
679 /* #### Currently this is Host Portable Coding, not ISO 8859-1. */
|
|
680 reg = concat2(reg, build_ext_string (re[i], Qx_font_name_encoding));
|
|
681 }
|
|
682
|
|
683 RETURN_UNGCPRO (reg);
|
|
684 }
|
|
685 #undef XE_XLFD_SEPARATOR
|
|
686 #undef XE_XLFD_PREFIX
|
|
687 #undef XE_XLFD_OPT_TEXT
|
|
688 #undef XE_XLFD_TEXT
|
|
689 #undef XE_XLFD_OPT_SLANT
|
|
690 #undef XE_XLFD_OPT_SPACING
|
|
691 #undef XE_XLFD_OPT_NEGATE
|
|
692 #undef XE_XLFD_NUMBER
|
|
693 #undef XE_XLFD_PSIZE
|
|
694
|
|
695 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
696 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
697
|
|
698 static void
|
|
699 string_list_to_fcobjectset (Lisp_Object list, FcObjectSet *os)
|
|
700 {
|
|
701 EXTERNAL_LIST_LOOP_2 (elt, list)
|
|
702 {
|
|
703 FcChar8 *s;
|
|
704
|
|
705 CHECK_STRING (elt);
|
|
706 s = fc_intern (elt);
|
|
707 FcObjectSetAdd (os, s);
|
|
708 }
|
|
709 }
|
|
710
|
|
711 void
|
|
712 syms_of_font_mgr (void)
|
|
713 {
|
|
714 INIT_LRECORD_IMPLEMENTATION(fc_pattern);
|
|
715
|
|
716 DEFSYMBOL_MULTIWORD_PREDICATE(Qfc_patternp);
|
|
717
|
|
718 DEFSYMBOL(Qfc_result_type_mismatch);
|
|
719 DEFSYMBOL(Qfc_result_no_match);
|
|
720 DEFSYMBOL(Qfc_result_no_id);
|
|
721 DEFSYMBOL(Qfc_internal_error);
|
3360
|
722 DEFSYMBOL(Qfont_mgr);
|
3354
|
723
|
|
724 DEFSUBR(Ffc_pattern_p);
|
|
725 DEFSUBR(Ffc_pattern_create);
|
|
726 DEFSUBR(Ffc_name_parse);
|
|
727 DEFSUBR(Ffc_name_unparse);
|
|
728 DEFSUBR(Ffc_pattern_duplicate);
|
|
729 DEFSUBR(Ffc_pattern_add);
|
|
730 DEFSUBR(Ffc_pattern_del);
|
|
731 DEFSUBR(Ffc_pattern_get);
|
|
732 DEFSUBR(Ffc_list_fonts_pattern_objects);
|
|
733 DEFSUBR(Ffc_font_sort);
|
|
734 DEFSUBR(Ffc_font_match);
|
|
735 DEFSUBR(Fxlfd_font_name_p);
|
|
736 }
|
|
737
|
|
738 void
|
|
739 vars_of_font_mgr (void)
|
|
740 {
|
3360
|
741 /* #### The next two functions belong somewhere else. */
|
3354
|
742
|
|
743 /* #### I know, but the right fix is use the generic debug facility. */
|
|
744 DEFVAR_INT ("xft-debug-level", &debug_xft /*
|
|
745 Level of debugging messages to issue to stderr for Xft.
|
|
746 A nonnegative integer. Set to 0 to suppress all warnings.
|
|
747 Default is 1 to ensure a minimum of debugging output at initialization.
|
|
748 Higher levels give even more information.
|
|
749 */ );
|
|
750 debug_xft = 1;
|
|
751
|
|
752 DEFVAR_LISP("xft-version", &Vxft_version /*
|
|
753 The major version number of the Xft library being used.
|
|
754 */ );
|
|
755 Vxft_version = make_int(XFT_VERSION);
|
|
756
|
3360
|
757 Fprovide (intern ("font-mgr"));
|
3354
|
758 }
|
|
759
|
|
760 void
|
|
761 complex_vars_of_font_mgr (void)
|
|
762 {
|
|
763 DEFVAR_LISP("xft-xlfd-font-regexp", &Vxlfd_font_name_regexp /*
|
|
764 The regular expression used to match XLFD font names. */
|
|
765 );
|
|
766 Vxlfd_font_name_regexp = make_xlfd_font_regexp();
|
|
767 }
|
|
768
|
|
769 void
|
|
770 reinit_vars_of_font_mgr (void)
|
|
771 {
|
|
772 int i, size = (int) countof (fc_standard_properties);
|
|
773
|
|
774 FcInit ();
|
|
775
|
|
776 fc_property_name_hash_table = make_string_hash_table (size);
|
|
777 for (i = 0; i < size; ++i)
|
|
778 puthash (fc_standard_properties[i], NULL, fc_property_name_hash_table);
|
|
779 }
|
|
780
|