[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`set-frame-font' doesn't support font aliases

From: Eduardo Ochs
Subject: `set-frame-font' doesn't support font aliases
Date: Sun, 01 Jun 2008 01:24:44 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Part 1 - Problem

The current code for `set-frame-font' doesn't support font
aliases - for example, these sexps don't work:

  (set-frame-font "5x7")    ;; error: "Font `5x7' is not defined"
  (set-frame-font "fixed")  ;; uses some unexpected font

but these ones do work:

  ;; "5x7":
  ;; "fixed" (same as "6x13" in my machine - see below):

As far as I can tell, the expansion of aliased fonts is done
using this file:

  (find-file "/usr/share/fonts/X11/misc/fonts.alias")

and pgas (Pierre Gaston) pointed to me that "xlsfonts -l" can be
used to show the real name of a font. Typical command lines are:

  xlsfonts -l  -fn 5x7
  xlsfonts -ll -fn 5x7

I am using a recent CVS Emacs on Debian 4.0 ("Etch", stable, xorg).
Running (emacs-version) here returns this:
  "GNU Emacs (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
   of 2008-05-30 on dekooning"

Part 2 - Workaround

(defun ee-aref (alist idx)
  "Like `aref', but for alists.
Example: (ee-aref '((1 . one) (2 . two) (3 . three)) 2)
                                -> two"
  (cdr (assoc idx alist)))

(defun ee-font-alias (fontname &optional use-ucs)
"Expand FONTNAME when it is an alias; when USE-UCS is non-nil, use \"iso10646\".
The list of aliases has been built by hand from data found at this file:
  (find-file \"/usr/share/fonts/X11/misc/fonts.alias\")"
  (let ((aliases '(
    ("fixed" . 
    ("variable" . "-*-helvetica-bold-r-normal-*-*-120-*-*-*-*-iso8859-1")
    ("5x7" . "-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso8859-1")
    ("5x8" . "-misc-fixed-medium-r-normal--8-80-75-75-c-50-iso8859-1")
    ("6x9" . "-misc-fixed-medium-r-normal--9-90-75-75-c-60-iso8859-1")
    ("6x10" . "-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1")
    ("6x12" . "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso8859-1")
    ("6x13" . "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1")
    ("6x13bold" . 
    ("7x13" . "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1")
    ("7x13bold" . "-misc-fixed-bold-r-normal--13-120-75-75-c-70-iso8859-1")
    ("7x13euro" . "-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-15")
    ("7x13eurobold" . "-misc-fixed-bold-r-normal--13-120-75-75-c-70-iso8859-15")
    ("7x14" . "-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1")
    ("7x14bold" . "-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso8859-1")
    ("8x13" . "-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1")
    ("8x13bold" . "-misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-1")
    ("8x16" . "-sony-fixed-medium-r-normal--16-120-100-100-c-80-iso8859-1")
    ("9x15" . "-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-1")
    ("9x15bold" . "-misc-fixed-bold-r-normal--15-140-75-75-c-90-iso8859-1")
    ("10x20" . "-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1")
    ("12x24" . "-sony-fixed-medium-r-normal--24-170-100-100-c-120-iso8859-1")
    (setq fontname (or (ee-aref aliases fontname) fontname))
    (if use-ucs (setq fontname (replace-regexp-in-string
                                "iso8859" "iso10646"

(defun ee-set-frame-font (fontname &optional use-ucs)
  "Like `set-frame-font', but uses `ee-font-alias' to expand FONTNAME."
  (set-frame-font (ee-font-alias fontname use-ucs)))

;; For tests
(defun ee-insert (&rest rest)
  "Insert characters, strings, or ranges of characters.
Example: (ee-insert '(?a ?z) 10 \"Foo!\")"
  (while rest
    (let ((o (car rest)))
      (cond ((stringp o) (insert o))
            ((numberp o) (if (char-valid-p o) (insert o)))
            ((consp o) (mapc 'ee-insert (apply 'number-sequence o)))
            (t (error "Not string/int/pair: %S" o))))
    (setq rest (cdr rest))))

;; Tests:
;; (ee-font-alias "fixed")
;; (ee-font-alias "fixed" t)
;; (ee-set-frame-font "5x7" t)
;; (ee-set-frame-font "6x10" t)
;; (ee-set-frame-font "fixed" t)
;; (ee-set-frame-font "9x15" t)
;; (ee-set-frame-font "10x20" t)
;; (ee-insert "\n" '(32 126) "\n" '(913 981) "\n" '(8592 9675) "\n")

Part 3 - Suggestion

It would be nice to have an Emacs function that would do this
expansion - like the (ee-aref aliases fontname) above - cleanly
and reliably...

  Eduardo Ochs

reply via email to

[Prev in Thread] Current Thread [Next in Thread]