Alhadis / Menloco

Replaces the Monaco typeface's box-drawing characters with those from Menlo.
MIT License
25 stars 2 forks source link

Can I customise ascent and descent lines of Monaco? #10

Closed AlynxZhou closed 2 years ago

AlynxZhou commented 2 years ago

Actually this is my own question, I am using Emacs and I set different fonts for Chinese (Noto Sans Mono CJK SC) and English (Monaco patched with this repo). However if I set the same font size to both fonts, I got different line height, Chinese is a little bit higher than English. Then I searched on the Internet, I found that line height is not only decide by font size, but also ascent and descent, and I found most Chinese fonts have larger ascent and descent.

In Emacs, if I have font size as 16, I got following value:

Font Height Ascent Descent
Monaco 20 16 4
Noto Sans Mono CJK SC 24 19 5
Sarasa Mono SC 21 16 5

Then I try to modify OS/2 table with FontForge, but it has different entries, I don't know which one to modify. I tried to enlarge each to the same ratio of Noto Sans Mono CJK SC, now I have the same line height for both Chinese and English, but the box-drawing chars is not stretched and gap shows again.

Is there any better way to custom them, and then stretch box-drawing chars according to new ascent and descent values in ff-extend.py?

AlynxZhou commented 2 years ago

I managed to make them same height by set sTypoAscender, usWinAscender in OS/2 table and ascender in hhea table to 2376, sTypoDescender in OS/2 table and descender in hhea table to -590, usWinDescender in OS/2 table to 590, and sTypoLineGap in OS/2 table and lineGap in hhea table to 0.

Not sure if this is correct, but it works for me. And I got gaps between box-drawing characters again...

AlynxZhou commented 2 years ago

I guess there are also other value that needs to be changed, but they don't affect my display, e.g. ascender and descender in FontForge's Element -> Font Info -> General.

Emacs can only keeps the same line height when two fonts have the same ascender and descender.

AlynxZhou commented 2 years ago

It turns out that browser will also have different line height for different fonts, I didn't notice that because I set line-height: 1.5 in CSS, I wish Emacs can have such a min line height setting for use but currently no such thing.

Let me close this since I decide to just use smaller Chinese font size.

Alhadis commented 2 years ago

@AlynxZhou Sorry for the slow response. 😞

I should point out that the box-drawing glyphs this script adds to Monaco are deliberately stretched beyond the font's recorded ascender/descender heights. This is to seal any gaps that might be visible between connecting glyphs on different lines. For example:

Figure 1: Line-gap example

Having said that, you can see that a font's ascent/descent lines aren't always an indicator of its geometry's bounding box. I hacked this crude animation together in Photoshop to illustrate how Menloco's glyphs overlap each other:

Figure 2: Glyph overlap

This might be what's confusing FontForge.

Then I try to modify OS/2 table with FontForge, but it has different entries, I don't know which one to modify.

Here's a technical reference for the OS/2 table. These fields are mainly a historical curiosity, but are nonetheless required in TrueType fonts. It's best to fill them out and keep them in-sync with other metrics. However, you probably shouldn't be editing the metrics by hand in the first place, since—as I explained above—the box-drawing glyphs are intended to stretch past the ascender/descender lines.

I hope that's cleared up some of the confusion. The subject of font-metrics is a messy one, even without considering Emacs's text-rendering engine (which likely differs to both web browsers and terminal emulators…). I mainly use Emacs as my terminal editor, so, my exposure to its GUI is minimal. 😢