annotate lisp/fontconfig.el @ 5404:91b3aa59f49b

Convert lisp/ to GPLv3.
author Mike Sperber <sperber@deinprogramm.de>
date Fri, 15 Oct 2010 15:18:27 +0200
parents 517f6887fbc0
children b9167d522a9a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
1 ;;; fontconfig.el --- New font model, NG
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
2
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
3 ;; Copyright (c) 2003 Eric Knauel and Matthias Neubauer
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
4 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
5
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
6 ;; Authors: Eric Knauel <knauel@informatik.uni-tuebingen.de>
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
7 ;; Matthias Neubauer <neubauer@informatik.uni-freiburg.de>
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
8 ;; Stephen J. Turnbull <stephen@xemacs.org>
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
9 ;; Created: 27 Oct 2003
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
10 ;; Updated: 05 Mar 2005 by Stephen J. Turnbull
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
11 ;; Keywords: faces
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
12
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
13 ;; This file is part of XEmacs.
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
14
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
15 ;; XEmacs is free software: you can redistribute it and/or modify it
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
16 ;; under the terms of the GNU General Public License as published by the
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
17 ;; Free Software Foundation, either version 3 of the License, or (at your
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
18 ;; option) any later version.
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
19
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
20 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
21 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
22 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
23 ;; for more details.
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
24
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4607
diff changeset
26 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
27
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
28 ;;; Synched up with: Not in GNU
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
29
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
30 ;;; Commentary:
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
31
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
32 ;; This file is one of the pillars of the face refactoring effort
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
33 ;; (another will be colorconfig.el, and there may be others).
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
34
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
35 ;; The overall plan is to have a sensible modern model for values of
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
36 ;; each of the components of a face (starting with fonts and colors),
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
37 ;; implemented in a single module. Of course we must be able to
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
38 ;; convert such values to appropriate descriptors for any device type
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
39 ;; on the one hand, but on the other it seems unreasonable to force
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
40 ;; users to deal with a large number of different (and arcane, in the
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
41 ;; case of XLFD) naming formats.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
42
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
43 ;; This file implements font specification. We call a specification a
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
44 ;; *pattern* to conform to fontconfig usage. The internal
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
45 ;; representation of a pattern will have Keith Packard's fontconfig
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
46 ;; API. For one, there is a robust and free C implementation, which
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
47 ;; is available as a package for all platforms supported by X.org or
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
48 ;; XFree86. For another, it seems to be capable of representing any
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
49 ;; specification of any of the font models I know. Third, on X
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
50 ;; platforms that internal representation can be passed verbatim to
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
51 ;; libXft to get high quality TrueType fonts rendered with
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
52 ;; anti-aliasing and hinting.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
53
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
54 ;; We will support the following user interfaces:
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
55
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
56 ;; 1. fontconfig font names
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
57 ;; 2. X Logical Font Descriptions (XLFD)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
58 ;; 3. MS Windows font names
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
59 ;; 4. Mac OS X font names
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
60
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
61 ;; and possibly others (such as ad hoc abbreviations used in older X11
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
62 ;; implementations). This is called the *fontname UI* (for the
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
63 ;; platform) to distinguish it from XEmacs's internal model
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
64 ;; (fontconfig patterns) and the API for rendering engines (called the
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
65 ;; *font API* for the engine).
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
66
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
67 ;; We will support the following rendering engine APIs:
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
68
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
69 ;; 1. fontconfig patterns (the native language of Xft); to emphasize
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
70 ;; the engine-specific nature, we will call these *Xft fonts*
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
71 ;; 2. XLFD strings
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
72 ;; 3. MS Windows font names
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
73
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
74 ;; and possibly others (such as Mac OS X font names). This is called
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
75 ;; the *font API* (for the platform) to distinguish it from XEmacs's
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
76 ;; internal model (fontconfig *patterns*) and the names used by users
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
77 ;; (called the *fontname UI* for the platform).
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
78
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
79
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
80 ;; TODO (possible enhancements)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
81 ;; 1. add a more complete docstring for properties as such (would be a
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
82 ;; hash table?) to describe things like special symbolic values, and
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
83 ;; Emacs-relevant semantics
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
84 ;; 2. add a special value defining macro for constants
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
85
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
86 ;;; Code:
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
87
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
89 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
90 ;; The fontconfig pattern API
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
91 ;;
3360
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
92 ;; The basic interfaces are defined as API wrappers in C in font-mgr.c.
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
93 ;; These are prefixed with "fc-pattern-". These are
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
94 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
95 ;; fc-pattern-p
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
96 ;; fc-pattern-create
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
97 ;; fc-pattern-duplicate
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
98 ;; fc-pattern-add
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
99 ;; fc-pattern-del
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
100 ;; fc-pattern-get
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
101 ;; fc-pattern-destroy
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
102
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
103 ;; We provide a LISP-y alias, `make-fc-pattern' for the pattern
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
104 ;; constructor function `fc-pattern-create'. #### It might make sense
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
105 ;; to generalize `make-fc-pattern' by allowing a plist of properties
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
106 ;; as an optional argument. We also provide accessors
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
107 ;; `fc-pattern-get-PROPERTY' and mutators `fc-pattern-add-PROPERTY' and
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
108 ;; `fc-pattern-del-PROPERTY' for each of the standard properties used by
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
109 ;; Xft, which overlap substantially with the properties defined by X11.
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
110
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
111 (require 'font-mgr)
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
112
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
113 (defalias 'make-fc-pattern 'fc-pattern-create)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
114
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
115 (defmacro fc-define-property (property type docfrag &optional obsolete-p)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
116 "Define PROPERTY as a fontconfig font property of type TYPE using DOCFRAG.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
117
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
118 A font property is a key in a fontconfig pattern and is associated with
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
119 one or more values of a given type. This macro creates wrappers around
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
120 `fc-pattern-get', `fc-pattern-add', and `fc-pattern-del' for PROPERTY.
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
121 \(Wrappers are preferred to use of primitives with a string as the OBJECT
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
122 argument because typos in wrappers result in \"not fboundp\" errors, while
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
123 a typo in a string produces a silent null return.)
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
124
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
125 PROPERTY is a string.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
126 TYPE is a symbol indicating the type of the property value. It is used only
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
127 to modify formatting of the wrapper function docstrings.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
128 DOCFRAG is a string which briefly describes the use of the property, and is
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
129 interpolated into a format to create the doctstrings.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
130 OBSOLETE-P if non-nil marks the property as pertaining only to older versions
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
131 of fontconfig or Xft. This merely adds a deprecation to the docstrings.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
132
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
133 This macro defines an accessor named `fc-pattern-get-PROPERTY' which takes
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
134 a fontconfig pattern object and an integer as arguments, and returns the
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
135 value associated with PROPERTY and ID in the pattern object. Since it is
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
136 not possible to associate a value to PROPERTY for a particular ID, it is
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
137 not very useful to interpret the values associated with a given id for
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
138 different properties as being linked to each other in some way.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
139
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
140 A mutator `fc-pattern-add-PROPERTY' which takes a fontconfig pattern object
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
141 and a value as arguments, and adds the value to the property with the next
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
142 id. The type of the value is recognized by `fc-pattern-add', and the id
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
143 is chosen by the fontconfig implementation.
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
144
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
145 A mutator `fc-pattern-del-PROPERTY' which takes a fontconfig pattern object,
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
146 and deletes all values of that property from the pattern."
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
147
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
148 `(progn
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
149 (defsubst ,(intern (concat "fc-pattern-get-" property))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
150 (pattern id)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
151 ,(format "\
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
152 Return %s %s fc pattern PATTERN %s.%s
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
153
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
154 This function is a convenience wrapper for `fc-pattern-get'.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
155 See `fc-pattern-get' for documentation of patterns, ids, and error returns."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
156 (if (eq type 'boolean)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
157 "t"
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
158 docfrag)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
159 (if (eq type 'boolean)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
160 "if"
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
161 "associated with id ID in")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
162 (if (eq type 'boolean)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
163 docfrag
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
164 (format "as a%s %s" (if (eq type 'integer) "n" "") type))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
165 (if obsolete-p "
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
166 \(Obsolete, only available on systems using Xft version 1.)"
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
167 ""))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
168 (fc-pattern-get pattern ,property id))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
169
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
170 (defsubst ,(intern (concat "fc-pattern-add-" property))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
171 (pattern value)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
172 ,(format "\
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
173 Add VALUE to the %s property of fontconfig pattern PATTERN.%s
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
174
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
175 The type of VALUE should be %s.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
176
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
177 This function is a convenience wrapper for `fc-pattern-add'.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
178 See `fc-pattern-add' for documentation of patterns, values, and error returns."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
179 property
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
180 (if obsolete-p "
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
181 \(Obsolete, only available on systems using Xft version 1.)"
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
182 "")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
183 type)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
184 (fc-pattern-add pattern ,property value))
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
185
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
186 (defsubst ,(intern (concat "fc-pattern-del-" property))
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
187 (pattern)
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
188 ,(format "\
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
189 Delete all values of the %s property of fontconfig pattern PATTERN.%s
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
190
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
191 This function is a convenience wrapper for `fc-pattern-del'.
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
192 See `fc-pattern-del' for documentation of patterns and error returns."
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
193 property
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
194 (if obsolete-p "
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
195 \(Obsolete, only available on systems using Xft version 1.)"
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
196 "")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
197 type)
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
198 (fc-pattern-del pattern ,property))
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
199 ,property))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
200
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
201 ;; define the standard properties for Xft v.2 here
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
202 (fc-define-property "antialias" boolean "the font supports antialiasing")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
203 (fc-define-property "dpi" float "the design resolution")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
204 (fc-define-property "family" string "the font family")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
205 (fc-define-property "file" string "the file containing glyph data")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
206 (fc-define-property "foundry" string "the vendor")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
207 (fc-define-property "index" integer "the index of the glyph set")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
208 (fc-define-property "minspace" boolean "has a minimum spacing")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
209 (fc-define-property "outline" boolean "is an outline font")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
210 (fc-define-property "pixelsize" float "the size in pixels")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
211 (fc-define-property "rasterizer" string "the name of the rasterizing engine")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
212 (fc-define-property "rgba" integer "the subpixel rendering capabilities")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
213 (fc-define-property "scalable" boolean "is scalable")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
214 (fc-define-property "scale" float "the scale factor")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
215 (fc-define-property "size" float "the size in points")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
216 (fc-define-property "slant" integer "the slant")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
217 (fc-define-property "spacing" integer "the spacing model")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
218 (fc-define-property "style" string "the typographic face or style")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
219 (fc-define-property "weight" integer "the weight")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
220 (fc-define-property "xlfd" string "the XLFD (full name in X11)")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
221
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
222 ;; Xft v.1 properties (generally marked as obsolete)
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
223 ;; had different semantics from XLFD "encoding"
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
224 (fc-define-property "encoding" string "the encoding" t)
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
225 ;; also used by X11 XLFDs, so not obsolete
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
226 (fc-define-property "charwidth" integer "the average character width")
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
227 (fc-define-property "charheight" integer "the average character height" t)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
228 (fc-define-property "core" boolean "represents a core font" t)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
229 (fc-define-property "render" boolean "represents a render (Xft) font" t)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
230
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
231 ;; X11 XLFD and other standard properties
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
232 (fc-define-property "x11-swidth" string "the 'set' width")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
233 (fc-define-property "x11-adstyle" string "any additional style")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
234 (fc-define-property "x11-resx" string "the horizontal design resolution")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
235 (fc-define-property "x11-resy" string "the vertical design resolution")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
236 ;; use "charwidth" instead of "x11-avgwidth"
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
237 (fc-define-property "x11-registry" string "the encoding registry")
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
238 ;; "x11-encoding" has different semantics from Xft v.1 "encoding"
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
239 (fc-define-property "x11-encoding" string "the encoding index")
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
240
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
241
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
242 (defvar fc-find-available-font-families-fc-fonts-only t
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
243 "If `fc-find-available-font-families-fc-fonts-only' is set to `t',
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
244 `fc-find-available-font-families' will ignore core fonts.")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
245
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
246 (defconst fc-font-name-slant-roman 0)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
247 (defconst fc-font-name-slant-italic 100)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
248 (defconst fc-font-name-slant-oblique 110)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
249
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
250 (defconst fc-font-name-slant-mapping
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
251 `((,fc-font-name-slant-roman . :roman)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
252 (,fc-font-name-slant-italic . :italic)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
253 (,fc-font-name-slant-oblique . :oblique)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
254
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
255 (defconst fc-font-name-slant-mapping-string
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
256 `((,fc-font-name-slant-roman . "R")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
257 (,fc-font-name-slant-roman . "I")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
258 (,fc-font-name-slant-roman . "O")))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
259
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
260 (defconst fc-font-name-slant-mapping-string-reverse
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
261 `(("R" . ,fc-font-name-slant-roman)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
262 ("I" . ,fc-font-name-slant-italic)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
263 ("O" . ,fc-font-name-slant-oblique)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
264
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
265 (defconst fc-font-name-slant-mapping-reverse
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
266 `((:roman . ,fc-font-name-slant-roman)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
267 (:italic . ,fc-font-name-slant-italic)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
268 (:oblique . ,fc-font-name-slant-oblique)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
269
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
270 (defun fc-font-slant-translate-from-constant (number)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
271 "Translate the Xft font slant constant NUMBER to symbol."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
272 (let ((pair (assoc number fc-font-name-slant-mapping)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
273 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
274
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
275 (defun fc-font-slant-translate-from-symbol (symbol)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
276 "Translate SYMBOL (`:roman', `:italic' or `:oblique') to the
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
277 corresponding Xft font slant constant."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
278 (let ((pair (assoc symbol fc-font-name-slant-mapping-reverse)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
279 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
280
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
281 (defun fc-font-slant-translate-to-string (num-or-sym)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
282 (let* ((constant (if (symbolp num-or-sym)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
283 (cdr (assoc num-or-sym fc-font-name-slant-mapping-reverse))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
284 num-or-sym))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
285 (pair (assoc constant fc-font-name-slant-mapping-string)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
286 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
287
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
288 (defun fc-font-slant-translate-from-string (str)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
289 (let ((pair (assoc str fc-font-name-slant-mapping-string-reverse)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
290 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
291
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
292 (defconst fc-font-name-weight-light 0)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
293 (defconst fc-font-name-weight-regular 80)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
294 (defconst fc-font-name-weight-medium 100)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
295 (defconst fc-font-name-weight-demibold 180)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
296 (defconst fc-font-name-weight-bold 200)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
297 (defconst fc-font-name-weight-black 210)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
298
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
299 (defconst fc-font-name-weight-mapping
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
300 `((,fc-font-name-weight-light . :light)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
301 (,fc-font-name-weight-regular . :regular)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
302 (,fc-font-name-weight-medium . :medium)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
303 (,fc-font-name-weight-demibold . :demibold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
304 (,fc-font-name-weight-bold . :bold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
305 (,fc-font-name-weight-black . :black)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
306
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
307 (defconst fc-font-name-weight-mapping-string
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
308 `((,fc-font-name-weight-light . "Light")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
309 (,fc-font-name-weight-regular . "Regular")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
310 (,fc-font-name-weight-medium . "Medium")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
311 (,fc-font-name-weight-demibold . "Demibold")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
312 (,fc-font-name-weight-bold . "Bold")
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
313 (,fc-font-name-weight-black . "Black")))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
314
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
315 (defconst fc-font-name-weight-mapping-string-reverse
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
316 `(("Light" . ,fc-font-name-weight-light)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
317 ("Regular" . ,fc-font-name-weight-regular)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
318 ("Medium" . ,fc-font-name-weight-medium)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
319 ("Demibold" . ,fc-font-name-weight-demibold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
320 ("Bold" . ,fc-font-name-weight-bold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
321 ("Black" . ,fc-font-name-weight-black)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
322
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
323 (defconst fc-font-name-weight-mapping-reverse
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
324 `((:light . ,fc-font-name-weight-light)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
325 (:regular . ,fc-font-name-weight-regular)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
326 (:medium . ,fc-font-name-weight-medium)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
327 (:demibold . ,fc-font-name-weight-demibold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
328 (:bold . ,fc-font-name-weight-bold)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
329 (:black . ,fc-font-name-weight-black)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
330
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
331 (defun fc-font-weight-translate-from-constant (number)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
332 "Translate a Xft font weight constant NUMBER to symbol."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
333 (let ((pair (assoc number fc-font-name-weight-mapping)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
334 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
335
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
336 (defun fc-font-weight-translate-from-symbol (symbol)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
337 "Translate SYMBOL (`:light', `:regular', `:medium', `:demibold',
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
338 `:bold' or `:black') to the corresponding Xft font weight constant."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
339 (let ((pair (assoc symbol fc-font-name-weight-mapping-reverse)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
340 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
341
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
342 (defun fc-font-weight-translate-to-string (num-or-sym)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
343 (let* ((constant (if (symbolp num-or-sym)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
344 (cdr (assoc num-or-sym fc-font-name-weight-mapping-reverse))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
345 num-or-sym))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
346 (pair (assoc constant fc-font-name-weight-mapping-string)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
347 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
348
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
349 (defun fc-font-weight-translate-from-string (str)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
350 (let ((pair (assoc str fc-font-name-weight-mapping-string-reverse)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
351 (if pair (cdr pair))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
352
4362
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
353 (defun fc-pattern-get-or-compute-size (pattern id)
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
354 "Get the size from `pattern' associated with `id' or try to compute it.
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
355 Returns 'fc-result-no-match if unsucessful."
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
356 ;; Many font patterns don't have a "size" property, but do have a
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
357 ;; "dpi" and a "pixelsize" property".
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
358 (let ((maybe (fc-pattern-get-size pattern id)))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
359 (if (not (eq maybe 'fc-result-no-match))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
360 maybe
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
361 (let ((dpi (fc-pattern-get-dpi pattern id))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
362 (pixelsize (fc-pattern-get-pixelsize pattern id)))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
363 (if (and (numberp dpi)
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
364 (numberp pixelsize))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
365 (* pixelsize (/ 72 dpi))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
366 'fc-result-no-match)))))
f5693b5f7f2d Compute size for Xft fonts.
Mike Sperber <sperber@deinprogramm.de>
parents: 4021
diff changeset
367
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
368 (defun fc-copy-pattern-partial (pattern attribute-list)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
369 "Return a copy of PATTERN restricted to ATTRIBUTE-LIST.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
370
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
371 PATTERN is a fontconfig pattern object.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
372 ATTRIBUTE-LIST is a list of strings denoting font properties.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
373 A new object is allocated and returned."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
374 (let ((new (make-fc-pattern))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
375 (attrs attribute-list))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
376 ;;; We demand proper tail recursion!
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
377 (while (not (null attrs))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
378 (let ((get (intern (concat "fc-pattern-get-" (car attrs))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
379 (set (intern (concat "fc-pattern-add-" (car attrs)))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
380 (if (and (fboundp get) (fboundp set))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
381 (funcall set new (funcall get pattern 0))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
382 (warn "property '%s' not defined, ignoring" (car attrs))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
383 (setq attrs (cdr attrs)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
384 new))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
385
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
386 (defun fc-pattern-get-all-attributes (fc-pattern fc-pattern-get-function)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
387 (let ((count 0)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
388 res end val)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
389 (while (not end)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
390 (setq val (funcall fc-pattern-get-function fc-pattern count))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
391 (if (or (equal val 'fc-result-no-id)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
392 (equal val 'fc-result-no-match))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
393 (setq end t)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
394 (setq res (append res (list val))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
395 count (+ count 1))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
396 res))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
397
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
399 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
400 ;; The fontconfig fontname UI
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
401 ;;
3360
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
402 ;; The basic interfaces are defined as API wrappers in C in font-mgr.c
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
403 ;; These are prefixed with "fc-name-". These are
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
404 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
405 ;; fc-name-parse
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
406 ;; fc-name-unparse
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
407 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
408 ;; For interfacing with various font rendering systems, we need to be able
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
409 ;; to convert the fontconfig patterns to names, and vice versa. The high-
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
410 ;; level API is
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
411 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
412 ;; font-default-name-syntax
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
413 ;; variable naming the default naming syntax
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
414 ;; maybe this could be a list to try in order?
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
415 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
416 ;; font-name-to-pattern NAME &optional SYNTAX
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
417 ;; returns a fontconfig pattern, or nil if the name could not be parsed
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
418 ;; NAME is a string
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
419 ;; SYNTAX is a name syntax symbol
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
420 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
421 ;; font-pattern-to-name PATTERN &optional SYNTAX
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
422 ;; returns a string
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
423 ;; PATTERN is a fontconfig pattern
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
424 ;; SYNTAX is a name syntax symbol
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
425 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
426 ;; A "name syntax symbol" is a symbol for a font naming syntax. This may be
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
427 ;; a rendering engine syntax or a font manager syntax. Initially, 'x and
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
428 ;; 'fontconfig will be supported. Patterns may be unambiguous (one value for
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
429 ;; each specified property) or ambiguous (multiple values are allowed for
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
430 ;; some specified properties). `font-name-to-pattern' should be unambiguous,
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
431 ;; but `font-pattern-to-name' may not be an exact conversion for some
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
432 ;; syntaxes, especially for ambiguous patterns.
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
433
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
435 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
436 ;; The fontconfig font API
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
437 ;;
3360
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
438 ;; The basic interfaces are defined as API wrappers in C in font-mgr.c.
316fddbf58e2 [xemacs-hg @ 2006-04-25 14:01:52 by stephent]
stephent
parents: 3354
diff changeset
439 ;; These are prefixed with "fc-font-". These are
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
440 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
441 ;; fc-font-match
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
442 ;; fc-list-fonts-pattern-objects
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
443 ;; fc-font-sort
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
444 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
445 ;; The high-level API is
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
446 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
447 ;; font-list &optional PATTERN DEVICE ATTRIBUTE-LIST OPTION-LIST
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
448 ;; returns a list of patterns matching pattern
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
449 ;; PATTERN is an ambiguous pattern, defaulting to the empty pattern
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
450 ;; DEVICE is the display device to query (default: selected device)
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
451 ;; ATTRIBUTE-LIST is a list of font attributes to restrict the patterns
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
452 ;; in the returned list to; other attributes will not be present in
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
453 ;; the patterns, and duplicates will be removed after pruning unwanted
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
454 ;; attributes; ATTRIBUTE-LIST has no necessary relation to the active
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
455 ;; attributes in PATTERN, both subset and superset make sense; if nil,
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
456 ;; the active attributes in PATTERN is used
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
457 ;; OPTION-LIST is a list of presentation options, such as sort order
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
458 ;; and refresh-cache (if any).
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
459 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
460 ;; font-match PATTERN &optional DEVICE
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
461 ;; returns a pattern representing the platform match for PATTERN,
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
462 ;; which should unambiguously select the same font
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
463 ;; PATTERN is an ambiguous pattern
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
464 ;; DEVICE is the display device to query (default: selected device)
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
465 ;;
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
466 ;; Maybe these APIs should get an error-behavior argument?
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
467
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
468 ;; #### it might make sense to generalize `fc-try-font' by having a
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
469 ;; global variable that contains a list of font name parsers. They are
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
470 ;; tried in order, and the first one to return an fc-pattern is matched.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
471
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
472 (defun fc-try-font (font &optional device)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
473 "Return list of pattern objects matching FONT on DEVICE.
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
474
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
475 FONT may be a fontconfig pattern object or a fontconfig font name (a string).
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
476 Optional DEVICE is the device object to query, defaulting to the currently
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
477 selected device."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
478 (fc-list-fonts-pattern-objects (or device (default-x-device))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
479 (if (fc-pattern-p font)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
480 font
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
481 (fc-name-parse font))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
482 nil))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
483
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
484 ;; for example, we'd like these next two to be implementable as
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
485 ;; (font-list (fc-create-pattern) device '("family" "style")) and
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
486 ;; (font-list (let ((p (fc-create-pattern))) (fc-pattern-add "family" family))
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
487 ;; device
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
488 ;; '("weight"))
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
489
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
490 (defun fc-find-available-font-families (&optional device filter-fun)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
491 "Find all available font families."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
492 (let ((device (or device (default-x-device)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
493 (pattern (make-fc-pattern))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
494 (objectset '("family" "style")))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
495 (let* ((all-fonts
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
496 (fc-list-fonts-pattern-objects device pattern objectset)))
4607
517f6887fbc0 Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4362
diff changeset
497 (delete-duplicates
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
498 (mapcar
4021
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
499 #'(lambda (pattern)
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
500 (fc-pattern-get-family pattern 0))
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
501 (if filter-fun
4607
517f6887fbc0 Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4362
diff changeset
502 (delete-if-not filter-fun all-fonts)
517f6887fbc0 Remove duplicate functions, chiefly #'delete-duplicates reimplementations.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4362
diff changeset
503 all-fonts)) :test #'equal))))
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
504
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
505 (defun fc-find-available-weights-for-family (family &optional style device)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
506 "Find available weights for font FAMILY."
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
507 (let* ((device (or device (default-x-device)))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
508 (pattern (make-fc-pattern))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
509 (objectset '("weight")))
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
510 (fc-pattern-add-family pattern family)
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
511 (if style
3354
15fb91e3a115 [xemacs-hg @ 2006-04-23 16:11:16 by stephent]
stephent
parents: 3094
diff changeset
512 (fc-pattern-add-style pattern style))
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
513 (mapcar
4021
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
514 #'(lambda (pattern)
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
515 (let ((fc-weight-constant (fc-pattern-get-weight pattern 0)))
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
516 (if fc-weight-constant
cef5f57bb9e2 [xemacs-hg @ 2007-06-21 13:39:08 by aidan]
aidan
parents: 3360
diff changeset
517 (fc-font-weight-translate-from-constant fc-weight-constant))))
3094
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
518 (fc-list-fonts-pattern-objects device pattern objectset))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
519
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
521 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
522 ;; The XLFD fontname UI
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
523 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
524
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
525 ;; xlfd-font-name-p
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
526
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
528 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
529 ;; Utility functions
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
530 ;;
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
531
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
532 (defun fc-pattern-get-successp (result)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
533 (and (not (equal result 'fc-result-no-match))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
534 (not (equal result 'fc-result-no-id))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
535 (not (equal result 'fc-internal-error))))
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
536
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
537 (provide 'fontconfig)
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
538
ad2f4ae9895b [xemacs-hg @ 2005-11-26 11:45:47 by stephent]
stephent
parents:
diff changeset
539 ;;; fontconfig.el ends here