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