Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-monospace fonts #16

Open
Seirdy opened this issue Jan 9, 2020 · 10 comments
Open

Support non-monospace fonts #16

Seirdy opened this issue Jan 9, 2020 · 10 comments

Comments

@Seirdy
Copy link

Seirdy commented Jan 9, 2020

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
Copy link
Owner

ii8 commented Jan 12, 2020

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

@Seirdy
Copy link
Author

Seirdy commented Jan 19, 2020

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
Copy link
Owner

ii8 commented Jan 20, 2020

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
Copy link
Author

Seirdy commented Jan 26, 2020

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

@ii8
Copy link
Owner

ii8 commented Jan 27, 2020

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
Copy link
Author

Seirdy commented Jan 27, 2020

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
Copy link
Owner

ii8 commented Jan 28, 2020

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.

@ii8 ii8 changed the title Support double-width characters Support non-monospace fonts Jun 11, 2020
@matu3ba
Copy link

matu3ba commented Dec 16, 2021

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
Copy link
Owner

ii8 commented Dec 16, 2021

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
Copy link

matu3ba commented Dec 16, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants