all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* `set-frame-font' doesn't support font aliases
@ 2008-06-01  5:24 Eduardo Ochs
  2008-06-03  6:44 ` Kenichi Handa
  0 siblings, 1 reply; 7+ messages in thread
From: Eduardo Ochs @ 2008-06-01  5:24 UTC (permalink / raw)
  To: emacs-devel

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":
  (set-frame-font
    "-misc-fixed-medium-r-normal--7-70-75-75-c-50-iso8859-1")
  ;; "fixed" (same as "6x13" in my machine - see below):
  (set-frame-font
    "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1")

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 23.0.60.2 (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" . "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1")
    ("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" . "-misc-fixed-bold-r-semicondensed--13-120-75-75-c-60-iso8859-1")
    ("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"
				fontname)))
    fontname))

(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...


Cheers,
  Eduardo Ochs
  eduardoochs@gmail.com
  http://angg.twu.net/





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-06-04 17:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-01  5:24 `set-frame-font' doesn't support font aliases Eduardo Ochs
2008-06-03  6:44 ` Kenichi Handa
2008-06-03  7:29   ` Stefan Monnier
2008-06-03  7:44     ` Kenichi Handa
2008-06-03  8:22       ` Stefan Monnier
2008-06-04 11:49         ` Kenichi Handa
2008-06-04 17:15           ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.