[Top][All Lists]

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

Re: A bug in tetris

From: Kenichi Handa
Subject: Re: A bug in tetris
Date: Thu, 23 Aug 2007 21:17:25 +0900

In article <address@hidden>, Kenichi Handa <address@hidden> writes:

> I don't have a strong objection to it.  Anyway, I found that
> the current problem is in the different place.  gamegrid.el
> has this function.

> (defun gamegrid-setup-default-font ()
>   (setq gamegrid-face
>       (copy-face 'default
>                  (intern (concat "gamegrid-face-" (buffer-name)))))
>   (when (eq gamegrid-display-mode 'glyph)
>     (let ((max-height nil))
>       (loop for c from 0 to 255 do
>           (let ((glyph (aref gamegrid-display-table c)))
>             (when (and (listp glyph) (eq (car  glyph) 'image))
>               (let ((height (cdr (image-size glyph))))
>                 (if (or (null max-height)
>                         (< max-height height))
>                     (setq max-height height))))))
>       (when (and max-height (< max-height 1))
>       (set-face-attribute gamegrid-face nil :height max-height)))))

> It tries to make a face height shorter than the grid-glyph
> height.  I confirmed that when I change the last line to:

>       (set-face-attribute gamegrid-face nil :height (- max-height 0.1))))))

> the resulting face is good and doesn't produce 1-dot
> horizontal gap in the play field.   I'm now investigating
> why the original code isn't good enough.

The source of the problem is the rounding off done while
converting a point size to pixel size.  In my environment,
resolution of the screen is 96dpi, grid-glyph height is
16dots, canonical char height is 20dots, the default font
height is 12.1pt, thus the requested height of the font is
9.6pt (== 12.1 * (16 / 20)).  The corresponding pixel size
is 12.75 (== 96 * (9.6 / 72.27)).  So, it's rounded off to 13,
but what we want here is a font of 12 pixel size.

So, I've just installed the attached change.  It may be
possible to add a special face attribute to tell not to
choose a font that is larger than the requested size, but
that require many C code changes.  In addition, I think such
a case (need a font equal to or smaller than a requested
size) is rare.

Kenichi Handa

Index: gamegrid.el
RCS file: /cvsroot/emacs/emacs/lisp/play/gamegrid.el,v
retrieving revision
retrieving revision
diff -u -r1.16.4.12 -r1.16.4.13
--- gamegrid.el 27 Jul 2007 10:47:51 -0000
+++ gamegrid.el 23 Aug 2007 12:13:24 -0000
@@ -320,7 +320,14 @@
                          (< max-height height))
                      (setq max-height height))))))
       (when (and max-height (< max-height 1))
-       (set-face-attribute gamegrid-face nil :height max-height)))))
+       (let ((default-font-height (face-attribute 'default :height))
+             (resy (/ (display-pixel-height) (/ (display-mm-height) 25.4)))
+             point-size pixel-size)
+         (setq point-size (/ (* (float default-font-height) max-height) 10)
+               pixel-size (floor (* resy (/ point-size 72.27)))
+               point-size (* (/ pixel-size resy) 72.27))
+         (set-face-attribute gamegrid-face nil
+                             :height (floor (* point-size 10))))))))
 (defun gamegrid-initialize-display ()
   (setq gamegrid-display-mode (gamegrid-display-type))

reply via email to

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