ii8 / havoc

minimal terminal emulator for wayland
Other
108 stars 18 forks source link

Support non-monospace fonts #16

Open Seirdy opened 4 years ago

Seirdy commented 4 years ago

Fonts like Nerd Fonts use double-width symbols to allow using icons in shell prompts and tmux statuslines. Currently, double-width characters are cut-off at half their width.

ii8 commented 4 years ago

Double width characters are supported. Could you tell me which specific characters and fonts cause this problem for you?

Seirdy commented 4 years ago

Attached is a screenshot showing the cut-off double-width characters. The font used is Hasklug Nerd Font, converted from OTF to TTF.

havoc

ii8 commented 4 years ago

Ah, it looks like those are unicode private use area characters. The house for example is probably U+F7DB. wcwidth will report these as narrow characters.

It looks like the way to fix this is by using font ligatures, then some PUA character followed by a space can be displayed using two cells.

Ligatures are not currently implemented in havoc, so that would have to be done first.

Seirdy commented 4 years ago

st (suckless terminal) and Alacritty both don't support ligatures, yet they display these symbols correctly.

ii8 commented 4 years ago

Does st actually display the symbol using an extra cell? Or does it just draw on the next cell that may have a different character.

Try this in st to see: printf "\xef\x9f\x9b\xe2\x96\x88"

When I use this symbol with a different nerd ttf font it shows correctly in a single cell in havoc. Is there some place I can download this exact ttf font, or can you tell me how you did the conversion from otf, so that I can try it myself.

Seirdy commented 4 years ago

Try this in st to see: printf "\xef\x9f\x9b\xe2\x96\x88"

All my terminal emulators (kitty, alacritty, st, havoc) render the glyph cut off, occupying a single cell. I tried with official Nerd Font ttf files and by converting the Hasklug Nerd Font using FontForge:

fontforge -lang=ff -c 'Open("Hasklug Nerd Font Complete.otf"); Generate("Hasklug.ttf")'

When I add a space, the house icon is fully visible in kitty, alacritty, and st. The house icon is cut off in havoc.

printf "\xef\x9f\x9b \xe2\x96\x88"

Alacritty and st do not support ligatures right now.

ii8 commented 4 years ago

In that case I'm afraid I don't really know what to do about this. havoc only renders each glyph within the confounds of it's cell(s). Non monospace fonts like the one you are trying to use won't work.

matu3ba commented 2 years ago

I have a related issue, since I use extensively UTF8 arrows within Venn diagrams for documentation:

─►
◄──
│
▼
▲
│

Is there a way to patch those to work with monospace inside havoc? Side question: How does st manage to keep size down etc while supporting these?

ii8 commented 2 years ago

Yes the glyphs of the font just need to not be too wide to fit in a single cell in the terminal. For example with DejaVuSansMono those characters work fine for me, they don't look nice though, maybe you can find a font where they both look nice and are monospace.

You can mix and match characters from different fonts by using something like font forge.

The problem is that libtsm lets you render one cell at a time only and you can't render into the space of different cells.

How does st manage to keep size down etc while supporting these?

It's not inherently difficult to support these, it's just a different way to render them. st probably just renders the whole glyph and then moves a character width forward, nothing special needed, it might even be supported by accident. libtsm on the other hand gives you a draw function callback and it has to render in the confines of just one cell.

It's probably possible to modify libtsm to do this but it would be a bit hacky.

matu3ba commented 2 years ago

You can mix and match characters from different fonts by using something like font forge.

Ah, thanks. Interesting, that the other font I tried did not properly show them (Inconsolata).

It's probably possible to modify libtsm to do this but it would be a bit hacky.

Better not then I guess, since libtsm was not designed for it. Folks should probably use foot terminal, if they want these fancy features.