unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniele Nicolodi <daniele@grinta.net>
To: emacs-devel@gnu.org
Subject: Re: Increase default `line-spacing' to 0.05, 0.10 or 0.15 [proposal]
Date: Thu, 6 May 2021 22:24:36 +0200	[thread overview]
Message-ID: <239550bd-88a4-e1c8-e313-d4287458ec84@grinta.net> (raw)
In-Reply-To: <83sg2zda04.fsf@gnu.org>

On 06/05/2021 19:53, Eli Zaretskii wrote:
>> From: Daniele Nicolodi <daniele@grinta.net>
>> Date: Thu, 6 May 2021 18:57:46 +0200
>>
>> I didn't look at the code, but I don't think this is true: on my Emacs,
>> lines containing only "." or containing only "l" have exactly the same
>> height, as I would expect.
> 
> You assume that the metrics of these two glyphs are different in
> monospaced fonts?
> 
>> Also, lines containing only a new line character (thus no printable
>> characters) still have the same height as lines with content, as
>> expected.
> 
> Newline leaves no glyphs on display, so their metrics cannot be
> calculated from the font.
> 
>> Are you sure Emacs does not consider the maximum ascent and descent of
>> each _font_ contained in a line and not of each _glyph_?
> 
> Why do you think there's a difference?

Sorry for using a sloppy terminology, I don't work with these concept
often. Fonts have a logical size and a ink size. See for example

https://docs.gtk.org/Pango/method.GlyphString.extents.html

I meant to say that Emacs may be looking at the logical size of the
glyphs, which, for a monospaced font is indeed supposed to be the same
for every glyph, not at the ink size.

This small Python script prints the ink ang logical ascent and descent
for the "Fira Code 14" font for each command line argument:

import sys
import gi
gi.require_version('Pango', '1.0')
from gi.repository import Pango
gi.require_version('PangoCairo', '1.0')
from gi.repository import PangoCairo

map = PangoCairo.font_map_get_default()
ctx = map.create_context()
font = ctx.load_font(Pango.FontDescription('Fira Code 14'))

def pixels(x):
    return (x + 512) >> 10

def ascent(rect):
    return pixels(-rect.y)

def descent(rect):
    return pixels(rect.y + rect.height)

def extents(text):
    item = Pango.itemize(ctx, text, 0, len(text),
                         Pango.AttrList(), None)
    glyphs = Pango.GlyphString()
    Pango.shape(text, -1, item[0].analysis, glyphs)
    return glyphs.extents(font)

for text in sys.argv[1:]:
    ink, logical = extents(text)
    print("     text:", repr(text))
    print("      ink:", ascent(ink), descent(ink))
    print("  logical:", ascent(logical), descent(logical))
    print()

Please note that this is my first time using the Pango API for something
like this, thus there may be better ways to do it.

Cheers,
Dan



  parent reply	other threads:[~2021-05-06 20:24 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 15:57 Increase default `line-spacing' to 0.05, 0.10 or 0.15 [proposal] Stefan Kangas
2021-05-04 16:12 ` Óscar Fuentes
2021-05-04 16:59   ` Jim Porter
2021-05-05  7:08     ` Augusto Stoffel
2021-05-05  8:51       ` Daniel Mendler
2021-05-05 19:47       ` Stefan Kangas
2021-05-06  9:26         ` Augusto Stoffel
2021-05-06 10:10           ` Eli Zaretskii
2021-05-06 11:47             ` Augusto Stoffel
2021-05-06 11:57               ` Eli Zaretskii
2021-05-06 12:27                 ` Augusto Stoffel
2021-05-06 15:21                   ` Eli Zaretskii
2021-05-06 15:46                     ` Augusto Stoffel
2021-05-06 16:16                       ` Eli Zaretskii
2021-05-06 12:30                 ` Gregory Heytings
2021-05-06 15:22                   ` Eli Zaretskii
2021-05-06 16:21                     ` Gregory Heytings
2021-05-06 16:29                       ` Eli Zaretskii
2021-05-06 16:57                         ` Daniele Nicolodi
2021-05-06 17:53                           ` Eli Zaretskii
2021-05-06 17:57                             ` Eli Zaretskii
2021-05-06 20:24                             ` Daniele Nicolodi [this message]
2021-05-06 17:01                         ` Gregory Heytings
2021-05-06 17:34                           ` Eli Zaretskii
2021-05-06 18:15                             ` Gregory Heytings
2021-05-06 20:22           ` Stefan Kangas
2021-05-06 20:21     ` Stefan Kangas
2021-05-06 23:17       ` Jim Porter
2021-05-07  6:03         ` Yuri Khan
2021-05-07  4:05       ` Eli Zaretskii
2021-05-04 16:18 ` Eli Zaretskii
2021-05-04 21:29   ` Stefan Kangas
2021-05-05  2:28     ` Eli Zaretskii
2021-05-05  5:14 ` Richard Stallman
2021-05-05 19:16   ` Stefan Kangas
2021-05-06 20:21     ` Stefan Kangas
2021-05-07  4:03       ` Eli Zaretskii
2021-05-07 18:43         ` Stefan Kangas
2021-05-08  6:19           ` Eli Zaretskii
2021-05-08  7:51             ` Daniele Nicolodi
2021-05-08  8:06               ` Eli Zaretskii
2021-05-08  9:40                 ` Daniele Nicolodi
2021-05-05 12:18 ` Daniele Nicolodi
2021-05-05 19:17   ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=239550bd-88a4-e1c8-e313-d4287458ec84@grinta.net \
    --to=daniele@grinta.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).