* `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
* Re: `set-frame-font' doesn't support font aliases
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
0 siblings, 1 reply; 7+ messages in thread
From: Kenichi Handa @ 2008-06-03 6:44 UTC (permalink / raw)
To: Eduardo Ochs; +Cc: emacs-devel
In article <87fxrxpw0z.fsf@dekooning.omnisys.int.com.br>, Eduardo Ochs <eduardoochs@gmail.com> writes:
> 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
I've just installed a fix to check also an alias name in X
font-backend. But, as Emacs accepts a fontconfig-style font
name too, for instance, "fixed" is parsed as a font of
family "fixed" which may match with many fonts.
Is keeping backward compatibility of (set-frame-font
"fixed") important enough to drop the support of
fontconfig-style name?
---
Kenichi Handa
handa@ni.aist.go.jp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: `set-frame-font' doesn't support font aliases
2008-06-03 6:44 ` Kenichi Handa
@ 2008-06-03 7:29 ` Stefan Monnier
2008-06-03 7:44 ` Kenichi Handa
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2008-06-03 7:29 UTC (permalink / raw)
To: Kenichi Handa; +Cc: Eduardo Ochs, emacs-devel
>> 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
> I've just installed a fix to check also an alias name in X
> font-backend. But, as Emacs accepts a fontconfig-style font
> name too, for instance, "fixed" is parsed as a font of
> family "fixed" which may match with many fonts.
> Is keeping backward compatibility of (set-frame-font
> "fixed") important enough to drop the support of
> fontconfig-style name?
Can you recover the Emacs-22 behavior by restricting the backends to
just `x'? If so, I think it's OK.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: `set-frame-font' doesn't support font aliases
2008-06-03 7:29 ` Stefan Monnier
@ 2008-06-03 7:44 ` Kenichi Handa
2008-06-03 8:22 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Kenichi Handa @ 2008-06-03 7:44 UTC (permalink / raw)
To: Stefan Monnier; +Cc: eduardoochs, emacs-devel
In article <jwvy75nrn8b.fsf-monnier+emacs@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> 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
> > I've just installed a fix to check also an alias name in X
> > font-backend. But, as Emacs accepts a fontconfig-style font
> > name too, for instance, "fixed" is parsed as a font of
> > family "fixed" which may match with many fonts.
> > Is keeping backward compatibility of (set-frame-font
> > "fixed") important enough to drop the support of
> > fontconfig-style name?
> Can you recover the Emacs-22 behavior by restricting the backends to
> just `x'?
No, because the font-name parser is independent of font
backends; i.e. even if you use only x font-backend, you can
specify a font name as, for instance,
"fixed-12:foundry=misc".
It is possible to implement a new method
`resolve_alias_name' for a font-backend, and add a new
function font-resolve-alias-name.
Then one can do:
(set-frame-font (font-resolve-alias-name "fixed")).
Another idea is to do:
(set-frame-font (font-spec :alias "fixed)).
or
(set-frame-font ":alias=fixed")
---
Kenichi Handa
handa@ni.aist.go.jp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: `set-frame-font' doesn't support font aliases
2008-06-03 7:44 ` Kenichi Handa
@ 2008-06-03 8:22 ` Stefan Monnier
2008-06-04 11:49 ` Kenichi Handa
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2008-06-03 8:22 UTC (permalink / raw)
To: Kenichi Handa; +Cc: eduardoochs, emacs-devel
>> Can you recover the Emacs-22 behavior by restricting the backends to
>> just `x'?
> No, because the font-name parser is independent of font
> backends; i.e. even if you use only x font-backend, you can
> specify a font name as, for instance,
> "fixed-12:foundry=misc".
Then we need to detect the ambiguity, and provide a way for the user to
resolve the ambiguity.
> Another idea is to do:
> (set-frame-font (font-spec :alias "fixed)).
> or
> (set-frame-font ":alias=fixed")
That seems clean from the user's POV. Tho maybe aliases should take
precedence, rather than the reverse.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: `set-frame-font' doesn't support font aliases
2008-06-03 8:22 ` Stefan Monnier
@ 2008-06-04 11:49 ` Kenichi Handa
2008-06-04 17:15 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Kenichi Handa @ 2008-06-04 11:49 UTC (permalink / raw)
To: Stefan Monnier; +Cc: eduardoochs, emacs-devel
In article <jwvr6bfq6a2.fsf-monnier+emacs@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Can you recover the Emacs-22 behavior by restricting the backends to
>>> just `x'?
> > No, because the font-name parser is independent of font
> > backends; i.e. even if you use only x font-backend, you can
> > specify a font name as, for instance,
> > "fixed-12:foundry=misc".
> Then we need to detect the ambiguity, and provide a way for the user to
> resolve the ambiguity.
> > Another idea is to do:
> > (set-frame-font (font-spec :alias "fixed)).
> > or
> > (set-frame-font ":alias=fixed")
> That seems clean from the user's POV. Tho maybe aliases should take
> precedence, rather than the reverse.
Something like this for "Bitstream Vera Sans"?
":family=Bitstream Vera Sans"
I don't like it because the new format is incompatible with
fontconfig's way. So, the original question arises:
> Is keeping backward compatibility of (set-frame-font
> "fixed") important enough to drop the support of
> fontconfig-style name?
Or, isn't it good enough to ask users to use this form
instead:
(set-frame-font ":alias=fixed")
---
Kenichi Handa
handa@ni.aist.go.jp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: `set-frame-font' doesn't support font aliases
2008-06-04 11:49 ` Kenichi Handa
@ 2008-06-04 17:15 ` Stefan Monnier
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2008-06-04 17:15 UTC (permalink / raw)
To: Kenichi Handa; +Cc: eduardoochs, emacs-devel
>> That seems clean from the user's POV. Tho maybe aliases should take
>> precedence, rather than the reverse.
> Something like this for "Bitstream Vera Sans"?
> ":family=Bitstream Vera Sans"
> I don't like it because the new format is incompatible with
> fontconfig's way. So, the original question arises:
>> Is keeping backward compatibility of (set-frame-font
>> "fixed") important enough to drop the support of
>> fontconfig-style name?
> Or, isn't it good enough to ask users to use this form
> instead:
> (set-frame-font ":alias=fixed")
Maybe you're right and it's sufficient.
Stefan
^ 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.