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