[Top][All Lists]

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

Re: Increase default `line-spacing' to 0.05, 0.10 or 0.15 [proposal]

From: Daniele Nicolodi
Subject: Re: Increase default `line-spacing' to 0.05, 0.10 or 0.15 [proposal]
Date: Thu, 6 May 2021 22:24:36 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0

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


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))

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.


reply via email to

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