annotate src/font-mgr.c @ 3906:605c915d2b9d

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