Mercurial > hg > xemacs-beta
comparison lisp/fontconfig.el @ 3354:15fb91e3a115
[xemacs-hg @ 2006-04-23 16:11:16 by stephent]
Xft/fontconfig refactoring, Part I. <87hd4ks29d.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Sun, 23 Apr 2006 16:11:34 +0000 |
parents | ad2f4ae9895b |
children | 316fddbf58e2 |
comparison
equal
deleted
inserted
replaced
3353:521d94807505 | 3354:15fb91e3a115 |
---|---|
103 | 103 |
104 ;; We provide a LISP-y alias, `make-fc-pattern' for the pattern | 104 ;; We provide a LISP-y alias, `make-fc-pattern' for the pattern |
105 ;; constructor function `fc-pattern-create'. #### It might make sense | 105 ;; constructor function `fc-pattern-create'. #### It might make sense |
106 ;; to generalize `make-fc-pattern' by allowing a plist of properties | 106 ;; to generalize `make-fc-pattern' by allowing a plist of properties |
107 ;; as an optional argument. We also provide accessors | 107 ;; as an optional argument. We also provide accessors |
108 ;; `fc-pattern-get-PROPERTY' and mutators `fc-pattern-add-PROPERTY' | 108 ;; `fc-pattern-get-PROPERTY' and mutators `fc-pattern-add-PROPERTY' and |
109 ;; for each of the standard properties used by Xft, which overlap | 109 ;; `fc-pattern-del-PROPERTY' for each of the standard properties used by |
110 ;; substantially with the properties defined by X11. #### We probably | 110 ;; Xft, which overlap substantially with the properties defined by X11. |
111 ;; should provide `fc-pattern-delete-PROPERTY', too. | 111 |
112 (require 'font-mgr) | |
112 | 113 |
113 (defalias 'make-fc-pattern 'fc-pattern-create) | 114 (defalias 'make-fc-pattern 'fc-pattern-create) |
114 | 115 |
115 (defmacro fc-define-property (property type docfrag &optional obsolete-p) | 116 (defmacro fc-define-property (property type docfrag &optional obsolete-p) |
116 "Define PROPERTY as a fontconfig font property of type TYPE using DOCFRAG. | 117 "Define PROPERTY as a fontconfig font property of type TYPE using DOCFRAG. |
117 | 118 |
118 A font property is a key in a fontconfig pattern and is associated with | 119 A font property is a key in a fontconfig pattern and is associated with |
119 one or more values of a given type. This macro creates wrappers around | 120 one or more values of a given type. This macro creates wrappers around |
120 `fc-pattern-get' and `fc-pattern-add' for PROPERTY. Wrappers are | 121 `fc-pattern-get', `fc-pattern-add', and `fc-pattern-del' for PROPERTY. |
121 preferred to use of primitives with a string as the OBJECT argument because | 122 \(Wrappers are preferred to use of primitives with a string as the OBJECT |
122 typos in wrappers result in \"not fboundp\" errors, while a typo in a string | 123 argument because typos in wrappers result in \"not fboundp\" errors, while |
123 produces a silent null return. | 124 a typo in a string produces a silent null return.) |
124 | 125 |
125 PROPERTY is a string. | 126 PROPERTY is a string. |
126 TYPE is a symbol indicating the type of the property value. It is used only | 127 TYPE is a symbol indicating the type of the property value. It is used only |
127 to modify formatting of the wrapper function docstrings. | 128 to modify formatting of the wrapper function docstrings. |
128 DOCFRAG is a string which briefly describes the use of the property, and is | 129 DOCFRAG is a string which briefly describes the use of the property, and is |
138 different properties as being linked to each other in some way. | 139 different properties as being linked to each other in some way. |
139 | 140 |
140 A mutator `fc-pattern-add-PROPERTY' which takes a fontconfig pattern object | 141 A mutator `fc-pattern-add-PROPERTY' which takes a fontconfig pattern object |
141 and a value as arguments, and adds the value to the property with the next | 142 and a value as arguments, and adds the value to the property with the next |
142 id. The type of the value is recognized by `fc-pattern-add', and the id | 143 id. The type of the value is recognized by `fc-pattern-add', and the id |
143 is chosen by the fontconfig implementation." | 144 is chosen by the fontconfig implementation. |
145 | |
146 A mutator `fc-pattern-del-PROPERTY' which takes a fontconfig pattern object, | |
147 and deletes all values of that property from the pattern." | |
144 | 148 |
145 `(progn | 149 `(progn |
146 (defsubst ,(intern (concat "fc-pattern-get-" property)) | 150 (defsubst ,(intern (concat "fc-pattern-get-" property)) |
147 (pattern id) | 151 (pattern id) |
148 ,(format "\ | 152 ,(format "\ |
177 (if obsolete-p " | 181 (if obsolete-p " |
178 \(Obsolete, only available on systems using Xft version 1.)" | 182 \(Obsolete, only available on systems using Xft version 1.)" |
179 "") | 183 "") |
180 type) | 184 type) |
181 (fc-pattern-add pattern ,property value)) | 185 (fc-pattern-add pattern ,property value)) |
186 | |
187 (defsubst ,(intern (concat "fc-pattern-del-" property)) | |
188 (pattern) | |
189 ,(format "\ | |
190 Delete all values of the %s property of fontconfig pattern PATTERN.%s | |
191 | |
192 This function is a convenience wrapper for `fc-pattern-del'. | |
193 See `fc-pattern-del' for documentation of patterns and error returns." | |
194 property | |
195 (if obsolete-p " | |
196 \(Obsolete, only available on systems using Xft version 1.)" | |
197 "") | |
198 type) | |
199 (fc-pattern-del pattern ,property)) | |
182 ,property)) | 200 ,property)) |
183 | 201 |
184 ;; define the standard properties for Xft v.2 here | 202 ;; define the standard properties for Xft v.2 here |
185 (fc-define-property "antialias" boolean "the font supports antialiasing") | 203 (fc-define-property "antialias" boolean "the font supports antialiasing") |
186 (fc-define-property "dpi" float "the design resolution") | 204 (fc-define-property "dpi" float "the design resolution") |
200 (fc-define-property "spacing" integer "the spacing model") | 218 (fc-define-property "spacing" integer "the spacing model") |
201 (fc-define-property "style" string "the typographic face or style") | 219 (fc-define-property "style" string "the typographic face or style") |
202 (fc-define-property "weight" integer "the weight") | 220 (fc-define-property "weight" integer "the weight") |
203 (fc-define-property "xlfd" string "the XLFD (full name in X11)") | 221 (fc-define-property "xlfd" string "the XLFD (full name in X11)") |
204 | 222 |
205 ;; Xft v.1 properties (marked as obsolete) | 223 ;; Xft v.1 properties (generally marked as obsolete) |
224 ;; had different semantics from XLFD "encoding" | |
206 (fc-define-property "encoding" string "the encoding" t) | 225 (fc-define-property "encoding" string "the encoding" t) |
207 (fc-define-property "charwidth" integer "the average character width" t) | 226 ;; also used by X11 XLFDs, so not obsolete |
227 (fc-define-property "charwidth" integer "the average character width") | |
208 (fc-define-property "charheight" integer "the average character height" t) | 228 (fc-define-property "charheight" integer "the average character height" t) |
209 (fc-define-property "core" boolean "represents a core font" t) | 229 (fc-define-property "core" boolean "represents a core font" t) |
210 (fc-define-property "render" boolean "represents a render (Xft) font" t) | 230 (fc-define-property "render" boolean "represents a render (Xft) font" t) |
211 | 231 |
212 | 232 ;; X11 XLFD and other standard properties |
213 (defconst fc-font-name-property-family "family") | 233 (fc-define-property "x11-swidth" string "the 'set' width") |
214 (defconst fc-font-name-property-style "style") | 234 (fc-define-property "x11-adstyle" string "any additional style") |
215 (defconst fc-font-name-property-slant "slant") | 235 (fc-define-property "x11-resx" string "the horizontal design resolution") |
216 (defconst fc-font-name-property-weight "weight") | 236 (fc-define-property "x11-resy" string "the vertical design resolution") |
217 (defconst fc-font-name-property-size "size") | 237 ;; use "charwidth" instead of "x11-avgwidth" |
218 (defconst fc-font-name-property-pixelsize "pixelsize") | 238 (fc-define-property "x11-registry" string "the encoding registry") |
219 (defconst fc-font-name-property-spacing "spacing") | 239 ;; "x11-encoding" has different semantics from Xft v.1 "encoding" |
220 (defconst fc-font-name-property-foundry "foundry") | 240 (fc-define-property "x11-encoding" string "the encoding index") |
221 (defconst fc-font-name-property-antialias "antialias") | 241 |
222 (defconst fc-font-name-property-xlfd "xlfd") | |
223 (defconst fc-font-name-property-file "file") | |
224 (defconst fc-font-name-property-index "index") | |
225 (defconst fc-font-name-property-rasterizer "rasterizer") | |
226 (defconst fc-font-name-property-outline "outline") | |
227 (defconst fc-font-name-property-scalable "scalable") | |
228 (defconst fc-font-name-property-rgba "rgba") | |
229 (defconst fc-font-name-property-minspace "minspace") | |
230 (defconst fc-font-name-property-dpi "dpi") | |
231 | |
232 ;; Xft version 1 only | |
233 ;;(defconst fc-font-name-property-encoding "encoding") | |
234 ;;(defconst fc-font-name-property-charwidth "charwidth") | |
235 ;;(defconst fc-font-name-property-charheight "charheight") | |
236 ;;(defconst fc-font-name-property-core "core") | |
237 ;;(defconst fc-font-name-property-render "render") | |
238 | |
239 | |
240 (defconst fc-pattern-selector-mapping | |
241 `((,fc-font-name-property-family . fc-pattern-get-family) | |
242 (,fc-font-name-property-style . fc-pattern-get-style) | |
243 (,fc-font-name-property-slant . fc-pattern-get-slant) | |
244 (,fc-font-name-property-weight . fc-pattern-get-weight) | |
245 (,fc-font-name-property-size . fc-pattern-get-size) | |
246 (,fc-font-name-property-pixelsize . fc-pattern-get-pixelsize) | |
247 (,fc-font-name-property-spacing . fc-pattern-get-spacing) | |
248 (,fc-font-name-property-foundry . fc-pattern-get-foundry) | |
249 (,fc-font-name-property-antialias . fc-pattern-get-antialias) | |
250 (,fc-font-name-property-xlfd . fc-pattern-get-xlfd) | |
251 (,fc-font-name-property-file . fc-pattern-get-file) | |
252 (,fc-font-name-property-index . fc-pattern-get-index) | |
253 (,fc-font-name-property-rasterizer . fc-pattern-get-rasterizer) | |
254 (,fc-font-name-property-outline . fc-pattern-get-outline) | |
255 (,fc-font-name-property-scalable . fc-pattern-get-scalable) | |
256 (,fc-font-name-property-rgba . fc-pattern-get-rgba) | |
257 (,fc-font-name-property-minspace . fc-pattern-get-minspace) | |
258 (,fc-font-name-property-dpi . fc-pattern-get-dpi) | |
259 ;; Xft version 1 only | |
260 ;; (,fc-font-name-property-encoding . fc-pattern-get-encoding) | |
261 ;; (,fc-font-name-property-charwidth . fc-pattern-get-char-width) | |
262 ;; (,fc-font-name-property-charheight . fc-pattern-get-char-height) | |
263 ;; (,fc-font-name-property-core . fc-pattern-get-core) | |
264 ;; (,fc-font-name-property-render . fc-pattern-get-render) | |
265 )) | |
266 | 242 |
267 (defvar fc-find-available-font-families-fc-fonts-only t | 243 (defvar fc-find-available-font-families-fc-fonts-only t |
268 "If `fc-find-available-font-families-fc-fonts-only' is set to `t', | 244 "If `fc-find-available-font-families-fc-fonts-only' is set to `t', |
269 `fc-find-available-font-families' will ignore core fonts.") | 245 `fc-find-available-font-families' will ignore core fonts.") |
270 | 246 |
413 ;; #### which should be renamed to fontconfig.c. These are prefixed | 389 ;; #### which should be renamed to fontconfig.c. These are prefixed |
414 ;; with "fc-name-". These are | 390 ;; with "fc-name-". These are |
415 ;; | 391 ;; |
416 ;; fc-name-parse | 392 ;; fc-name-parse |
417 ;; fc-name-unparse | 393 ;; fc-name-unparse |
418 ;; xft-name-unparse | 394 ;; xft-name-unparse (nonfunctional and presumably obsolete) |
395 ;; | |
396 ;; For interfacing with various font rendering systems, we need to be able | |
397 ;; to convert the fontconfig patterns to names, and vice versa. The high- | |
398 ;; level API is | |
399 ;; | |
400 ;; font-default-name-syntax | |
401 ;; variable naming the default naming syntax | |
402 ;; maybe this could be a list to try in order? | |
403 ;; | |
404 ;; font-name-to-pattern NAME &optional SYNTAX | |
405 ;; returns a fontconfig pattern, or nil if the name could not be parsed | |
406 ;; NAME is a string | |
407 ;; SYNTAX is a name syntax symbol | |
408 ;; | |
409 ;; font-pattern-to-name PATTERN &optional SYNTAX | |
410 ;; returns a string | |
411 ;; PATTERN is a fontconfig pattern | |
412 ;; SYNTAX is a name syntax symbol | |
413 ;; | |
414 ;; A "name syntax symbol" is a symbol for a font naming syntax. This may be | |
415 ;; a rendering engine syntax or a font manager syntax. Initially, 'x and | |
416 ;; 'fontconfig will be supported. Patterns may be unambiguous (one value for | |
417 ;; each specified property) or ambiguous (multiple values are allowed for | |
418 ;; some specified properties). `font-name-to-pattern' should be unambiguous, | |
419 ;; but `font-pattern-to-name' may not be an exact conversion for some | |
420 ;; syntaxes, especially for ambiguous patterns. | |
419 | 421 |
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
421 ;; | 423 ;; |
422 ;; The fontconfig font API | 424 ;; The fontconfig font API |
423 ;; | 425 ;; |
427 ;; | 429 ;; |
428 ;; fc-font-match | 430 ;; fc-font-match |
429 ;; fc-list-fonts-pattern-objects | 431 ;; fc-list-fonts-pattern-objects |
430 ;; fc-font-sort | 432 ;; fc-font-sort |
431 ;; fc-font-real-pattern | 433 ;; fc-font-real-pattern |
434 ;; | |
435 ;; The high-level API is | |
436 ;; | |
437 ;; font-list &optional PATTERN DEVICE ATTRIBUTE-LIST OPTION-LIST | |
438 ;; returns a list of patterns matching pattern | |
439 ;; PATTERN is an ambiguous pattern, defaulting to the empty pattern | |
440 ;; DEVICE is the display device to query (default: selected device) | |
441 ;; ATTRIBUTE-LIST is a list of font attributes to restrict the patterns | |
442 ;; in the returned list to; other attributes will not be present in | |
443 ;; the patterns, and duplicates will be removed after pruning unwanted | |
444 ;; attributes; ATTRIBUTE-LIST has no necessary relation to the active | |
445 ;; attributes in PATTERN, both subset and superset make sense; if nil, | |
446 ;; the active attributes in PATTERN is used | |
447 ;; OPTION-LIST is a list of presentation options, such as sort order | |
448 ;; and refresh-cache (if any). | |
449 ;; | |
450 ;; font-match PATTERN &optional DEVICE | |
451 ;; returns a pattern representing the platform match for PATTERN, | |
452 ;; which should unambiguously select the same font | |
453 ;; PATTERN is an ambiguous pattern | |
454 ;; DEVICE is the display device to query (default: selected device) | |
455 ;; | |
456 ;; Maybe these APIs should get an error-behavior argument? | |
432 | 457 |
433 ;; #### it might make sense to generalize `fc-try-font' by having a | 458 ;; #### it might make sense to generalize `fc-try-font' by having a |
434 ;; global variable that contains a list of font name parsers. They are | 459 ;; global variable that contains a list of font name parsers. They are |
435 ;; tried in order, and the first one to return an fc-pattern is matched. | 460 ;; tried in order, and the first one to return an fc-pattern is matched. |
436 | 461 |
444 (if (fc-pattern-p font) | 469 (if (fc-pattern-p font) |
445 font | 470 font |
446 (fc-name-parse font)) | 471 (fc-name-parse font)) |
447 nil)) | 472 nil)) |
448 | 473 |
474 ;; for example, we'd like these next two to be implementable as | |
475 ;; (font-list (fc-create-pattern) device '("family" "style")) and | |
476 ;; (font-list (let ((p (fc-create-pattern))) (fc-pattern-add "family" family)) | |
477 ;; device | |
478 ;; '("weight")) | |
479 | |
449 (defun fc-find-available-font-families (&optional device filter-fun) | 480 (defun fc-find-available-font-families (&optional device filter-fun) |
450 "Find all available font families." | 481 "Find all available font families." |
451 (let ((device (or device (default-x-device))) | 482 (let ((device (or device (default-x-device))) |
452 (pattern (make-fc-pattern)) | 483 (pattern (make-fc-pattern)) |
453 (objectset '("family" "style"))) | 484 (objectset '("family" "style"))) |
454 ; Xft2: does not work anymore | |
455 ; (if (not fc-find-available-font-families-fc-fonts-only) | |
456 ; (fc-pattern-add pattern fc-font-name-property-core t)) | |
457 ; (fc-objectset-add objectset fc-font-name-property-encoding) | |
458 (let* ((all-fonts | 485 (let* ((all-fonts |
459 (fc-list-fonts-pattern-objects device pattern objectset))) | 486 (fc-list-fonts-pattern-objects device pattern objectset))) |
460 (fc-delete-duplicates | 487 (fc-delete-duplicates |
461 (mapcar | 488 (mapcar |
462 '(lambda (pattern) | 489 '(lambda (pattern) |
463 (fc-pattern-get-family pattern 0)) | 490 (fc-pattern-get-family pattern 0)) |
464 (if filter-fun | 491 (if filter-fun |
465 (fc-filter all-fonts filter-fun) | 492 (fc-filter all-fonts filter-fun) |
466 all-fonts)))))) | 493 all-fonts)))))) |
467 | 494 |
468 ; Xft2: does not work anymore | |
469 ; (defun fc-find-available-font-families-non-mule (&optional device) | |
470 ; (fc-find-available-font-families | |
471 ; device | |
472 ; '(lambda (pattern) | |
473 ; (let ((encodings (fc-pattern-get-all-attributes | |
474 ; pattern 'fc-pattern-get-encoding))) | |
475 ; ;; Be sure that the font support ISO-8859-1 | |
476 ; (member "iso8859-1" encodings))))) | |
477 | |
478 (defun fc-find-available-weights-for-family (family &optional style device) | 495 (defun fc-find-available-weights-for-family (family &optional style device) |
479 "Find available weights for font FAMILY." | 496 "Find available weights for font FAMILY." |
480 (let* ((device (or device (default-x-device))) | 497 (let* ((device (or device (default-x-device))) |
481 (pattern (make-fc-pattern)) | 498 (pattern (make-fc-pattern)) |
482 (objectset '("weight"))) | 499 (objectset '("weight"))) |
483 (fc-pattern-add pattern fc-font-name-property-family family) | 500 (fc-pattern-add-family pattern family) |
484 (if style | 501 (if style |
485 (fc-pattern-add pattern fc-font-name-property-style style)) | 502 (fc-pattern-add-style pattern style)) |
486 (mapcar | 503 (mapcar |
487 '(lambda (pattern) | 504 '(lambda (pattern) |
488 (let ((fc-weight-constant (fc-pattern-get-weight pattern 0))) | 505 (let ((fc-weight-constant (fc-pattern-get-weight pattern 0))) |
489 (if fc-weight-constant | 506 (if fc-weight-constant |
490 (fc-font-weight-translate-from-constant fc-weight-constant)))) | 507 (fc-font-weight-translate-from-constant fc-weight-constant)))) |