Subject: RE: bug#1562: 23.0.60; modify-frame-parameters in Emacs 23 for fonts

From: "Drew Adams" <[email-masked]>
Date: Tue, 13 Jan 2009 09:12:06 -0800

> From: Jason Rumney Sent: Wednesday, December 31, 2008 6:11 PM
> > After loading, (frame-parameter nil 'font) gives
> > "-outline-Lucida Console-normal-normal-normal-mono-14-*-*-*-c-*-iso8859-1"
> >
> > Then do `C-u 5 M-x enlarge-font'. (frame-parameter nil 'font) gives
> > "-outline-Lucida Console-normal-normal-normal-mono-19-*-*-*-c-*-iso8859-1"
> > which is correct.
> >
> > Then do `C-u -5 M-x enlarge-font'. (frame-parameter nil 'font) gives
> > "-outline-Lucida
Console-normal-normal-normal-mono-14-*-*-*-c-*-fontset-auto1"
> > which is NOT correct.   
> 
> I have fixed this now, x_new_font in w32term.c had not been 
> updated in line with xterm.c.

I just obtained a build from 2009-01-04, and was able to check this.
Unfortunately, it is still not fixed. Please reopen this bug.

With this initial font parameter:

(font . "-outline-Lucida
Console-normal-normal-normal-mono-14-*-*-*-c-*-iso8859-1")

I call this:

(modify-frame-parameters frame '((font . "-outline-Lucida
Console-normal-normal-normal-mono-6-*-*-*-c-*-iso8859-1")))

And (frame-parameters) then shows this:

(font . "-outline-Lucida
Console-normal-normal-normal-mono-6-*-*-*-c-*-fontset-auto5")

Exactly the same symptom as before. The "fontset-autoN" is inappropriate, and is
not recognized by `x-list-fonts'. `modify-frame-parameters' is still not
respecting the input I give it - it sets the font so something entirely
different.

---

Below is the code I used, but you need not use all of it to duplicate the bug,
no doubt - the above info should be sufficient.

(defun enlarge-font (&optional increment frame)
    "Increase size of font in FRAME by INCREMENT.
Interactively, INCREMENT is given by the prefix argument.
Optional FRAME parameter defaults to current frame."
    (interactive "p")
    (setq frame (or frame (selected-frame)))
    (let ((fontname (cdr (assq 'font (frame-parameters frame))))
          (count enlarge-font-tries))
      (setq fontname (enlarged-font-name fontname frame increment))
      (while (and (not (x-list-fonts fontname)) (wholenump (setq count (1-
count))))
        (setq fontname (enlarged-font-name fontname frame increment)))
      (unless (x-list-fonts fontname) (error "Cannot change font size"))
      (modify-frame-parameters frame (list (cons 'font fontname)))
      ;; Update faces that want a bold or italic version of the default font.
      (frame-update-faces frame)))

(defun enlarged-font-name (fontname frame increment)
    "FONTNAME, after enlarging font size of FRAME by INCREMENT.
FONTNAME is the font of FRAME."
    (when (query-fontset fontname)
      (let ((ascii (assq 'ascii (aref (fontset-info fontname frame) 2))))
        (when ascii (setq fontname (nth 2 ascii)))))
    (let ((xlfd-fields (x-decompose-font-name fontname)))
      (unless xlfd-fields (error "Cannot decompose font name"))
      (let ((new-size (+ (string-to-number (aref xlfd-fields
xlfd-regexp-pixelsize-subnum))
                         increment)))
        (unless (> new-size 0) (error "New font size is too small: %s"
new-size))
        (aset xlfd-fields xlfd-regexp-pixelsize-subnum (number-to-string
new-size)))
      ;; Set point size & width to "*", so frame width will adjust to new font
size
      (aset xlfd-fields xlfd-regexp-pointsize-subnum "*")
      (aset xlfd-fields xlfd-regexp-avgwidth-subnum "*")
      (x-compose-font-name xlfd-fields)))

(defcustom enlarge-font-tries 100
    "Number of times to try to change font-size, when looking for a font.
The font-size portion of a font name is incremented or decremented at
most this many times, before giving up and raising an error."
    :type 'integer :group 'Frame-Commands)