* Zero height line causing arithmetic errors @ 2008-06-14 17:35 Stefan Monnier 2008-06-19 1:12 ` Kenichi Handa 0 siblings, 1 reply; 4+ messages in thread From: Stefan Monnier @ 2008-06-14 17:35 UTC (permalink / raw) To: emacs-devel My MPC.el package uses an overlay placed at the end of a line with an after-string of #("\n" 0 1 (face (:height 0.05 :inverse-video t))) in order to place a horizontal line in the display. In Emacs-22, this worked fine (except the line was a bit thicker than 0.05 times the base line height). In Emacs-CVS until recently this worked except that the line was full-height (i.e. 13 pixels in my case). Recently, it has started to cause more problems because now FRAME_SMALLEST_FONT_HEIGHT returns 0, and that value is used at 2 places in the divisor position. I guess the 0 is because 13 pixels (default font height) * 0.05 -> 0.65 pixels which are truncated to 0. I currently use the patch below, which makes it all work again (tho still with the problem that the 0.05 isn't taken into account and line line is 13 pixel think), but I suspect it's not the right place to fix it, Stefan === modified file 'src/font.c' --- src/font.c 2008-06-13 16:25:44 +0000 +++ src/font.c 2008-06-14 17:30:14 +0000 @@ -2682,6 +2682,7 @@ if (FRAME_SMALLEST_FONT_HEIGHT (f) > font->height) FRAME_SMALLEST_FONT_HEIGHT (f) = font->height, fonts_changed_p = 1; } + FRAME_SMALLEST_FONT_HEIGHT (f) = max (1, FRAME_SMALLEST_FONT_HEIGHT (f)); #endif return font_object; ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Zero height line causing arithmetic errors 2008-06-14 17:35 Zero height line causing arithmetic errors Stefan Monnier @ 2008-06-19 1:12 ` Kenichi Handa 2008-06-19 1:19 ` Dan Nicolaescu 2008-06-19 14:13 ` Stefan Monnier 0 siblings, 2 replies; 4+ messages in thread From: Kenichi Handa @ 2008-06-19 1:12 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel In article <jwvtzfwc4kq.fsf-monnier+emacs@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> writes: > My MPC.el package uses an overlay placed at the end of a line with an > after-string of #("\n" 0 1 (face (:height 0.05 :inverse-video t))) > in order to place a horizontal line in the display. > In Emacs-22, this worked fine (except the line was a bit thicker than > 0.05 times the base line height). In Emacs-CVS until recently this > worked except that the line was full-height (i.e. 13 pixels in my case). > Recently, it has started to cause more problems because now > FRAME_SMALLEST_FONT_HEIGHT returns 0, and that value is used at 2 places > in the divisor position. > I guess the 0 is because 13 pixels (default font height) * 0.05 -> 0.65 > pixels which are truncated to 0. > I currently use the patch below, which makes it all work again (tho > still with the problem that the 0.05 isn't taken into account and line > line is 13 pixel think), but I suspect it's not the right place to fix > it, For the problem of FRAME_SMALLEST_FONT_HEIGHT being set to 0, I installed the similar change. And, for the problem of too tall line-height, I found the culprit is XftTextExtents8. When the pixelsize of a font is less than 5 or so, for some font, it returns strange values in `extents' argument. For instance, with the attached test problem, I get this result: % ./xfttest 'bitstream vera sans mono' pixelsize=9, ascent=8, descent=2 pixelsize=8, ascent=7, descent=2 pixelsize=7, ascent=6, descent=2 pixelsize=6, ascent=5, descent=2 pixelsize=5, ascent=4, descent=2 pixelsize=4, ascent=4, descent=1 pixelsize=3, ascent=3, descent=1 pixelsize=2, ascent=2, descent=1 pixelsize=1, ascent=1, descent=1 pixelsize=0, ascent=1, descent=1 % ./xfttest 'dejavu sans mono' pixelsize=9, ascent=8, descent=2 pixelsize=8, ascent=7, descent=2 pixelsize=7, ascent=6, descent=2 pixelsize=6, ascent=5, descent=1 pixelsize=5, ascent=5, descent=1 pixelsize=4, ascent=5, descent=2 <-- increasing! pixelsize=3, ascent=4, descent=4 pixelsize=2, ascent=5, descent=5 pixelsize=1, ascent=5, descent=5 pixelsize=0, ascent=5, descent=5 I don't know which component of these has a bug: o the font "dejavu sans mono", o freetype o xft Anyway, I installed a quick dirty workaround; not believe the result of XftTextExtents8 if the pixelsize is less than 5. With that change, if your default font is scalable, the following code works as expected. (let ((buf (get-buffer-create "test")) overlay) (set-buffer buf) (erase-buffer) (insert "first line\n") (setq overlay (make-overlay (1- (point)) (point))) (overlay-put overlay 'after-string (propertize "\n" 'face '(:height 0.01 :inverse-video t))) (switch-to-buffer buf)) But, note that the line height is still 2, not 1. That's because the display engine calculate the line height by ascent+descent, and both ascent and descent doesn't become 0 in the structure XftFont even though `height' member is 1. It may be another Xft (or freetype) problem. --- Kenichi Handa handa@ni.aist.go.jp PS. You can compile xfttest.c by this command: % gcc -g -o xfttest `xft-config --cflags` `xft-config --libs` xfttest.c ----- xfttest.c ---- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <X11/Xlib.h> #include <X11/Xft/Xft.h> char *str = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; void show_height (Display *display, XftFont *font) { XGlyphInfo extents; XftTextExtents8 (display, font, str, 94, &extents); printf (" ascent=%d, descent=%d\n", extents.y, extents.height - extents.y); } int main (int argc, char **argv) { int size; char name[256], *p; Display *display; if (argc < 2) { fprintf (stderr, "Usage: xfttest FAMILYNAME\n"); exit (1); } display = XOpenDisplay (NULL); if (! display) { fprintf (stderr, "Can't open the display\n"); exit (1); } strcpy (name, argv[1]); p = name + strlen (name); for (size = 9; size >= 0; size--) { XftFont *font; sprintf (p, ":pixelsize=%d", size); font = XftFontOpenName (display, 0, name); printf ("pixelsize=%d,", size); show_height (display, font); XftFontClose (display, font); } exit (0); } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Zero height line causing arithmetic errors 2008-06-19 1:12 ` Kenichi Handa @ 2008-06-19 1:19 ` Dan Nicolaescu 2008-06-19 14:13 ` Stefan Monnier 1 sibling, 0 replies; 4+ messages in thread From: Dan Nicolaescu @ 2008-06-19 1:19 UTC (permalink / raw) To: Kenichi Handa; +Cc: Stefan Monnier, emacs-devel Kenichi Handa <handa@m17n.org> writes: > In article <jwvtzfwc4kq.fsf-monnier+emacs@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> writes: > > > My MPC.el package uses an overlay placed at the end of a line with an > > after-string of #("\n" 0 1 (face (:height 0.05 :inverse-video t))) > > in order to place a horizontal line in the display. > > > In Emacs-22, this worked fine (except the line was a bit thicker than > > 0.05 times the base line height). In Emacs-CVS until recently this > > worked except that the line was full-height (i.e. 13 pixels in my case). > > Recently, it has started to cause more problems because now > > FRAME_SMALLEST_FONT_HEIGHT returns 0, and that value is used at 2 places > > in the divisor position. > > > I guess the 0 is because 13 pixels (default font height) * 0.05 -> 0.65 > > pixels which are truncated to 0. > > > I currently use the patch below, which makes it all work again (tho > > still with the problem that the 0.05 isn't taken into account and line > > line is 13 pixel think), but I suspect it's not the right place to fix > > it, > > For the problem of FRAME_SMALLEST_FONT_HEIGHT being set to > 0, I installed the similar change. > > And, for the problem of too tall line-height, I found the > culprit is XftTextExtents8. When the pixelsize of a font is > less than 5 or so, for some font, it returns strange values > in `extents' argument. For instance, with the attached > test problem, I get this result: > > % ./xfttest 'bitstream vera sans mono' > pixelsize=9, ascent=8, descent=2 > pixelsize=8, ascent=7, descent=2 > pixelsize=7, ascent=6, descent=2 > pixelsize=6, ascent=5, descent=2 > pixelsize=5, ascent=4, descent=2 > pixelsize=4, ascent=4, descent=1 > pixelsize=3, ascent=3, descent=1 > pixelsize=2, ascent=2, descent=1 > pixelsize=1, ascent=1, descent=1 > pixelsize=0, ascent=1, descent=1 > % ./xfttest 'dejavu sans mono' > pixelsize=9, ascent=8, descent=2 > pixelsize=8, ascent=7, descent=2 > pixelsize=7, ascent=6, descent=2 > pixelsize=6, ascent=5, descent=1 > pixelsize=5, ascent=5, descent=1 > pixelsize=4, ascent=5, descent=2 <-- increasing! > pixelsize=3, ascent=4, descent=4 > pixelsize=2, ascent=5, descent=5 > pixelsize=1, ascent=5, descent=5 > pixelsize=0, ascent=5, descent=5 This works fine for me on Fedora 9: ./xfttest 'dejavu sans mono' pixelsize=9, ascent=8, descent=2 pixelsize=8, ascent=8, descent=2 pixelsize=7, ascent=6, descent=2 pixelsize=6, ascent=5, descent=2 pixelsize=5, ascent=4, descent=2 pixelsize=4, ascent=4, descent=1 pixelsize=3, ascent=3, descent=1 pixelsize=2, ascent=2, descent=1 pixelsize=1, ascent=1, descent=1 pixelsize=0, ascent=1, descent=1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Zero height line causing arithmetic errors 2008-06-19 1:12 ` Kenichi Handa 2008-06-19 1:19 ` Dan Nicolaescu @ 2008-06-19 14:13 ` Stefan Monnier 1 sibling, 0 replies; 4+ messages in thread From: Stefan Monnier @ 2008-06-19 14:13 UTC (permalink / raw) To: Kenichi Handa; +Cc: emacs-devel > For the problem of FRAME_SMALLEST_FONT_HEIGHT being set to > 0, I installed the similar change. Thanks. > And, for the problem of too tall line-height, I found the > culprit is XftTextExtents8. When the pixelsize of a font is I think the problem I've been seeing is a different one. While trying to solve some other problem I discovered that my problem was linked to issues where Xresource font settings seem impose themselves too strongly, so the font-backend used was most likely X rather than xft (in my case) and the problem disappeared if I removed those font settings and let the font be specified some other way. I.e. I'm glad you found your bug, but mine is still around, and is probably elsewhere altogether. > But, note that the line height is still 2, not 1. That's > because the display engine calculate the line height by > ascent+descent, and both ascent and descent doesn't become 0 > in the structure XftFont even though `height' member is 1. > It may be another Xft (or freetype) problem. Yes, I saw that. I found it curious, but was actually happy about it: I prefer my line to be 2 pixels thick (Emacs-22 makes it even thicker, BTW). Stefan ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-06-19 14:13 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-06-14 17:35 Zero height line causing arithmetic errors Stefan Monnier 2008-06-19 1:12 ` Kenichi Handa 2008-06-19 1:19 ` Dan Nicolaescu 2008-06-19 14:13 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).