Mercurial > hg > xemacs-beta
annotate lisp/font-mgr.el @ 5818:15b0715c204d
Avoid passing patterns to with charset property to FcNameUnparse.
Prevents crash reported by Raymond Toy.
| author | Stephen J. Turnbull <stephen@xemacs.org> |
|---|---|
| date | Sat, 18 Oct 2014 21:20:42 +0900 |
| parents | 91b3aa59f49b |
| children |
| rev | line source |
|---|---|
| 3354 | 1 ;;; font-mgr.el --- Lisp emulation of fontconfig for X fonts. |
| 2 | |
| 3 ;; Copyright (C) 2006 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Author: Stephen J. Turnbull <stephen@xemacs.org> | |
| 6 ;; Created: 12 Apr 2006 by Stephen J. Turnbull | |
| 7 | |
| 8 ;; This file is part of XEmacs. | |
| 9 | |
|
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3360
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
| 3354 | 11 ;; under the terms of the GNU General Public License as published by the |
|
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3360
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3360
diff
changeset
|
13 ;; option) any later version. |
| 3354 | 14 |
| 15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 18 ;; for more details. | |
| 19 | |
| 20 ;; You should have received a copy of the GNU General Public License | |
|
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3360
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 3354 | 22 |
| 23 ;; Synched up with: Not in GNU Emacs. | |
| 24 | |
| 25 ;; Commentary | |
| 26 ;; This module provides the Lisp interface to fonts in X11, including Xft, | |
| 27 ;; but (at least at first) not GTK+ or Qt. It is a substitute for the | |
| 28 ;; C library fontconfig, whose interface is provided in ../src/font-mgr.c. | |
| 29 | |
| 30 ;; static FcChar8 *fc_standard_properties[] = { | |
| 31 ;; "antialias", "aspect", "autohint", "charset", "dpi", "family", "file", | |
| 32 ;; "foundry", "ftface", "globaladvance", "hinting", "index", "lang", | |
| 33 ;; "minspace", "outline", "pixelsize", "rasterizer", "rgba", "scalable", | |
| 34 ;; "scale", "size", "slant", "spacing", "style", "verticallayout", "weight", | |
| 35 ;; /* obsolete after Xft v. 1 */ | |
| 36 ;; "charwidth", "charheight", "core", "encoding", "render" | |
| 37 | |
| 38 ;; #### should we wrap the world in `(unless (featurep 'font-mgr) ... )'? | |
| 39 | |
| 40 (provide 'font-mgr) | |
| 41 | |
| 42 (defvar xft-xlfd-font-regexp | |
| 43 (concat | |
| 44 ;; XLFD specifies ISO 8859-1 encoding, but we can't handle non-ASCII | |
| 45 ;; in Mule when this function is called. So use HPC. | |
| 46 ;; (xe_xlfd_prefix "\\(\\+[\040-\176\240-\377]*\\)?-") | |
| 47 ;; (xe_xlfd_opt_text "\\([\040-\044\046-\176\240-\377]*\\)") | |
| 48 ;; (xe_xlfd_text "\\([\040-\044\046-\176\240-\377]+\\)") | |
| 49 "\\`" | |
| 50 "\\(\\+[\040-\176]*\\)?-" ; prefix | |
| 51 "\\([^-]+\\)" ; foundry | |
| 52 "-" | |
| 53 "\\([^-]+\\)" ; family | |
| 54 "-" | |
| 55 "\\([^-]+\\)" ; weight | |
| 56 "-" | |
| 57 "\\([0-9ior?*][iot]?\\)" ; slant | |
| 58 "-" | |
| 59 "\\([^-]+\\)" ; swidth | |
| 60 "-" | |
| 61 "\\([^-]*\\)" ; adstyle | |
| 62 "-" | |
| 63 "\\([0-9?*]+\\|\\[[ 0-9+~.e?*]+\\]\\)" ; pixelsize | |
| 64 "-" | |
| 65 "\\([0-9?*]+\\|\\[[ 0-9+~.e?*]+\\]\\)" ; pointsize | |
| 66 "-" | |
| 67 "\\([0-9?*]+\\)" ; resx | |
| 68 "-" | |
| 69 "\\([0-9?*]+\\)" ; resy | |
| 70 "-" | |
| 71 "\\([cmp?*]\\)" ; spacing | |
| 72 "-" | |
| 73 "~?" ; avgwidth | |
| 74 "\\([0-9?*]+\\)" | |
| 75 "-" | |
| 76 "\\([^-]+\\)" ; registry | |
| 77 "-" | |
| 78 "\\([^-]+\\)" ; encoding | |
| 79 "\\'") | |
| 80 "The regular expression used to match XLFD font names.") | |
| 81 | |
| 82 (defun fc-pattern-p (object) | |
| 83 "Returns t if OBJECT is of type fc-pattern, nil otherwise." | |
| 84 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 85 | |
| 86 (defun fc-pattern-create () | |
| 87 "Return a new, empty fc-pattern object." | |
| 88 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 89 | |
| 90 (defun fc-name-parse (fontname) | |
| 91 "Parse an Fc font name and return its representation as a fc pattern object." | |
| 92 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 93 | |
| 94 (defun fc-name-unparse (pattern) | |
| 95 "Unparse an fc pattern object to a string." | |
| 96 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 97 | |
| 98 (defun fc-pattern-duplicate (pattern) | |
| 99 "Make a copy of the fc pattern object PATTERN and return it." | |
| 100 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 101 | |
| 102 (defun fc-pattern-add (pattern property value) | |
| 103 "Add attributes to the pattern object PATTERN. PROPERTY is a string naming | |
| 104 the attribute to add, VALUE the value for this attribute. | |
| 105 | |
| 106 VALUE may be a string, integer, float, or symbol, in which case the value | |
| 107 will be added as an FcChar8[], int, double, or FcBool respectively." | |
| 108 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 109 | |
| 110 (defun fc-pattern-del (pattern property) | |
| 111 "Remove attribute PROPERTY from fc pattern object PATTERN." | |
| 112 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 113 | |
| 114 ;; Generic interface to FcPatternGet() | |
| 115 ;; Don't support the losing symbol-for-property interface. | |
| 116 | |
| 117 (defun fc-pattern-get (pattern property &optional id type) | |
| 118 "From PATTERN, extract PROPERTY for the ID'th member, of type TYPE. | |
| 119 | |
| 120 PATTERN is an Xft \(fontconfig) pattern object. | |
| 121 PROPERTY is a string naming an fontconfig font property. | |
| 122 Optional ID is a nonnegative integer indexing the list of values for PROPERTY | |
| 123 stored in PATTERN, defaulting to 0 (the first value). | |
| 124 Optional TYPE is a symbol, one of 'string, 'boolean, 'integer, 'float, | |
| 125 'double, 'matrix, 'charset, or 'void, corresponding to the FcValue types. | |
| 126 \('float is an alias for 'double). | |
| 127 | |
| 128 The Lisp types returned will conform to TYPE: | |
| 129 string string | |
| 130 boolean `t' or `nil' | |
| 131 integer integer | |
| 132 double \(float) float | |
| 133 matrix not implemented | |
| 134 charset not implemented | |
| 135 void not implemented | |
| 136 | |
| 137 Symbols with names of the form \"fc-result-DESCRIPTION\" are returned when | |
| 138 the desired value is not available. These are | |
| 139 | |
| 140 fc-result-type-mismatch the value found has an unexpected type | |
| 141 fc-result-no-match there is no such attribute | |
| 142 fc-result-no-id there is no value for the requested ID | |
| 143 | |
| 144 The types of the following standard properties are predefined by fontconfig. | |
| 145 The symbol 'fc-result-type-mismatch will be returned if the object exists but | |
| 146 TYPE does not match the predefined type. It is best not to specify a type | |
| 147 for predefined properties, as a mistake here ensures error returns on the | |
| 148 correct type. | |
| 149 | |
| 150 Each standard property has a convenience accessor defined in fontconfig.el, | |
| 151 named in the form \"fc-pattern-get-PROPERTY\". The convenience functions are | |
| 152 preferred to `fc-pattern-get' since a typo in the string naming a property | |
| 153 will result in a silent null return, while a typo in a function name will | |
| 154 usually result in a compiler or runtime \"not fboundp\" error. You may use | |
| 155 `defsubst' to define convenience functions for non-standard properties. | |
| 156 | |
| 157 family String Font family name | |
| 158 style String Font style. Overrides weight and slant | |
| 159 slant Int Italic, oblique or roman | |
| 160 weight Int Light, medium, demibold, bold or black | |
| 161 size Double Point size | |
| 162 aspect Double Stretches glyphs horizontally before hinting | |
| 163 pixelsize Double Pixel size | |
| 164 spacing Int Proportional, monospace or charcell | |
| 165 foundry String Font foundry name | |
| 166 antialias Bool Whether glyphs can be antialiased | |
| 167 hinting Bool Whether the rasterizer should use hinting | |
| 168 verticallayout Bool Use vertical layout | |
| 169 autohint Bool Use autohinter instead of normal hinter | |
| 170 globaladvance Bool Use font global advance data | |
| 171 file String The filename holding the font | |
| 172 index Int The index of the font within the file | |
| 173 ftface FT_Face Use the specified FreeType face object | |
| 174 rasterizer String Which rasterizer is in use | |
| 175 outline Bool Whether the glyphs are outlines | |
| 176 scalable Bool Whether glyphs can be scaled | |
| 177 scale Double Scale factor for point->pixel conversions | |
| 178 dpi Double Target dots per inch | |
| 179 rgba Int unknown, rgb, bgr, vrgb, vbgr, none - subpixel geometry | |
| 180 minspace Bool Eliminate leading from line spacing | |
| 181 charset CharSet Unicode chars encoded by the font | |
| 182 lang String List of RFC-3066-style languages this font supports | |
| 183 | |
| 184 The FT_Face, Matrix, CharSet types are unimplemented, so the corresponding | |
| 185 properties are not accessible from Lisp at this time. If the value of a | |
| 186 property returned has type FT_Face, FcCharSet, or FcMatrix, | |
| 187 `fc-result-type-mismatch' is returned. | |
| 188 | |
| 189 The following properties which were standard in Xft v.1 are obsolete in | |
| 190 Xft v.2: encoding, charwidth, charheight, core, and render." | |
| 191 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 192 | |
| 193 (defun fc-font-match (device pattern) | |
| 194 "Return the font on DEVICE that most closely matches PATTERN. | |
| 195 | |
| 196 DEVICE is an X11 device. | |
| 197 PATTERN is a fontconfig pattern object. | |
| 198 Returns a fontconfig pattern object representing the closest match to the | |
| 199 given pattern, or an error code. Possible error codes are | |
| 200 `fc-result-no-match' and `fc-result-no-id'." | |
| 201 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 202 | |
| 203 ;; #### fix this name to correspond to Ben's new nomenclature | |
| 204 (defun fc-list-fonts-pattern-objects (device pattern properties) | |
| 205 "Return a list of fonts on DEVICE that match PATTERN for PROPERTIES. | |
| 206 Each font is represented by a fontconfig pattern object. | |
| 207 | |
| 208 DEVICE is an X11 device. | |
| 209 PATTERN is a fontconfig pattern to be matched. | |
| 210 PROPERTIES is a list of property names (strings) that should match. | |
| 211 | |
| 212 #### DEVICE is unused, ignored, and may be removed if it's not needed to | |
| 213 match other font-listing APIs." | |
| 214 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 215 | |
| 216 ;; #### maybe this can/should be folded into fc-list-fonts-pattern-objects? | |
| 217 (defun fc-font-sort (device pattern &optional trim nosub) | |
| 218 "Return a list of all fonts sorted by proximity to PATTERN. | |
| 219 Each font is represented by a fontconfig pattern object. | |
| 220 | |
| 221 DEVICE is an X11 device. | |
| 222 PATTERN is a fontconfig pattern to be matched. | |
| 223 Optional argument TRIM, if non-nil, means to trim trailing fonts that do not | |
| 224 contribute new characters to the union repertoire. | |
| 225 | |
| 226 #### Optional argument NOSUB, if non-nil, suppresses some of the usual | |
| 227 property substitutions. DON'T USE THIS in production code, it is intended | |
| 228 for exploring behavior of fontconfig and will be removed when this code is | |
| 229 stable. | |
| 230 | |
| 231 #### DEVICE is unused, ignored, and may be removed if it's not needed to | |
| 232 match other font-listing APIs." | |
| 233 (error 'unimplemented "font-mgr library is experimental and incomplete")) | |
| 234 | |
| 235 (defun xlfd-font-name-p (fontname) | |
| 236 "Check whether the string FONTNAME is a XLFD font name." | |
| 237 (save-match-data | |
| 238 (string-match xft-xlfd-font-regexp fontname))) | |
| 239 | |
| 240 ;; FcPatternPrint: there is no point in having wrappers fc-pattern-print, | |
| 241 ;; Ffc_pattern_print since this function prints to stdout. | |
| 242 | |
| 243 ;;; end font-mgr.el |
