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

Add Braille support #837

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

jnaskali
Copy link

Description

Adds braille support to render pixelart (e.g. in terminal applications) requested in #482.
Thanks @Chaz6 for the implementation idea!

Requirements / Checklist

What does this Pull Request (PR) do?

Adds UBraille.ttf to glyph sources and updates font-patcher so that it copies symbols from 0x2800 to 0x28FF.

How should this be manually tested?

Check that fonts are created correctly.

Any background context you can provide?

What are the relevant tickets (if any)?

Closes #482.

Screenshots (if appropriate or helpful)

example image
Screenshot by dominikheinz from the related issue.

@Finii
Copy link
Collaborator

Finii commented May 29, 2022

Great work creating this PR 👍

Source of the glyphs mentioned in commit: ✔️

As this is not in a PUA, I think maybe it should be careful to preserve pre-existing glyphs. It is possible to have it in the attributes even it is not used by any patch set at the moment. (Compare diff comments on attributes below).
"Think maybe" => open question

font-patcher Outdated
@@ -609,6 +615,7 @@ class font_patcher:
{'Enabled': self.args.octicons, 'Name': "Octicons", 'Filename': "octicons.ttf", 'Exact': self.octiconsExactEncodingPosition, 'SymStart': 0X26A1, 'SymEnd': 0X26A1, 'SrcStart': None, 'SrcEnd': None, 'ScaleGlyph': OCTI_SCALE_LIST, 'Attributes': SYM_ATTR_DEFAULT}, # Zap
{'Enabled': self.args.octicons, 'Name': "Octicons", 'Filename': "octicons.ttf", 'Exact': self.octiconsExactEncodingPosition, 'SymStart': 0xF27C, 'SymEnd': 0xF27C, 'SrcStart': 0xF4A9, 'SrcEnd': 0xF4A9, 'ScaleGlyph': OCTI_SCALE_LIST, 'Attributes': SYM_ATTR_DEFAULT}, # Desktop
{'Enabled': self.args.codicons, 'Name': "Codicons", 'Filename': "codicons/codicon.ttf", 'Exact': True, 'SymStart': 0xEA60, 'SymEnd': 0xEBEB, 'SrcStart': None, 'SrcEnd': None, 'ScaleGlyph': None, 'Attributes': SYM_ATTR_DEFAULT},
{'Enabled': self.args.braille, 'Name': "Braille", 'Filename': "UBraille.ttf", 'Exact': False, 'SymStart': 0x2800, 'SymEnd': 0x28FF, 'SrcStart': None, 'SrcEnd': None, 'ScaleGlyph': None, 'Attributes': SYM_ATTR_DEFAULT},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need a ScaleGlyph here, to have a working mono version?
About the ScaleGlyph ... without one the patching will maximize the size of each glyph individually to fill the 'cell' completely. But with Braille you want to scale all glyphs identical to keep the relative size/position differences intact.

Further the 'Attributes': SYM_ATTR_DEFAULT seems an odd choice, as that means 'align': 'c', 'valign': 'c', 'stretch': 'pa'. That does only make sense if a ScaleGlyph is active? And maybe we want a careful here?

Also maybe correct the whitespaces, the vertical alignment (nothing I like normally, but we have it here) is broken as you see from the diff. Maybe a tab instead of spaces?

Copy link
Author

@jnaskali jnaskali May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking through the code. I amended with the vertical alignment and moved the issue number to a line of its own in the commit message.

I'm afraid I don't know enough about fonts to touch the attributes, so (everyone) feel free to improve things.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the scale effect for illustration:

image

Lets fix it...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in additional commit:

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thought I believe we do not want careful here, at least not a partial one.
If there is any glyph in the range it will not match our new glyphs in style and size.
I guess best is to not be careful here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH NOO, it is not working, the scaling is uniform but the centering is individual? Now we have a lot centered single dots!

Examining...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, ScaleGlyph can not (by design) enforce consistent shifting/centering.

This needs some thought.

@Finii
Copy link
Collaborator

Finii commented May 29, 2022

Additional note

If you edit the commit, maybe you could add to the commit message the Fixes: #837 line (on a line of its own at the bottom).
That makes it easier to go from git blame to the Issue and the MR.

@Finii
Copy link
Collaborator

Finii commented May 29, 2022

Same font packaged here: https://aur.archlinux.org/packages/ttf-ubraille

The font contains this copyright notice
Created by Vyacheslav Dikonov with PfaEdit 1.0 (http://pfaedit.sf.net). Free to use and distribute.

Same font is mentioned here https://fontforge.org/archive/sfds/index.html as 'GNU licensed'

Note that GNU FreeFont uses a Braille set by Steve White link.

@Finii
Copy link
Collaborator

Finii commented Jun 1, 2022

For me this looks good to merge now; playing the ball to @ryanoasis

@Finii Finii added the not ready label Jun 1, 2022
@Finii
Copy link
Collaborator

Finii commented Jun 2, 2022

It's a whole lot more involved than I initially thought. Split that up into individual commits that introduce the changes step by step.

Looks good now:
image

The changes are (mostly) only active when patching in the Braille font.

Also noticed that one glyph in the source font is missing: dots-67 is empty

image

Although it should have dot 6 (2nd colum, 3rd from top) and dot 7 (1st column, lowest row) active - as the tiny fontforge preview shows. I have no clue about Braille (maybe it is not needed), but it can lead to 'broken' displays in the usecase shown in the top of the Issue (use as graphical elements).

@Finii
Copy link
Collaborator

Finii commented Sep 7, 2022

Rebase on master, force push

@Finii
Copy link
Collaborator

Finii commented Sep 7, 2022

All the readmes need an update for the new parameter 🛑

@Finii Finii added this to the v2.3.0 milestone Sep 7, 2022
@musjj
Copy link

musjj commented Sep 7, 2022

Can this potentially fix the issue of gaps between the top and bottom of braille glyphs? Some terminals custom render them to make sure the gaps are filled, but can this issue be solved from the font level?

I noticed the commit regarding padding, so I tried out the PR out of curiosity to see what differences does it make, but it seems that this patch just makes the gaps even bigger.

(Tested on JetBrainsMono)
Before (old screenshot, ignore the colors):
image
After:
image

@Finii
Copy link
Collaborator

Finii commented Sep 8, 2022

Ah, what you would like is a stretch-x-y glyph rescale (like the powerline glyphs).

That would be nice in graphic scenarios like above, but look funny in normal (i.e. displaying actual braille text) ones, because the dots will get distorted. Hmm.

I can try a bit with that image above, but ... ping me if it takes too long, I might have forgotten to do it :-}

@musjj
Copy link

musjj commented Sep 8, 2022

Cool, looking forward to it :)
Do you think the dots need to be distorted? For reference, this is how it looks like in Wezterm, with the custom glyph rendering:
image

And the PR implementing this: wez/wezterm#919

@Finii
Copy link
Collaborator

Finii commented Sep 8, 2022

Do you think the dots need to be distorted?

Well, the 'cells' of some fonts are rectangular, more high than wide, like your cursor in the image above.
But some fonts have almost square 'cells'. If the dots are to 'fill' the 'cell' completely they must be scaled differently in X and Y, thus loosing the aspect ratio, thus round things can become ... ellipses?

image
Example of more squarish cells

@Finii
Copy link
Collaborator

Finii commented Sep 8, 2022

And the PR implementing this: wez/wezterm#919

Ah, they do not patch in a scaled source, they create the glyphs on the fly from circles drawn in the 'cell'.
That would also be possible, but more complex. Normally Nerd Fonts just aggregates glyphs, not creates new ones.

@Finii
Copy link
Collaborator

Finii commented Sep 24, 2022

@musjj Could you copy & paste that image into a comment here, so that I could try it?

I tried with this image, but that looks a bit fuzzy:

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⢈⣈⣌⣌⣬⡮⡦⠲⠳⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣈⣌⣮⣮⣿⣿⣿⣿⠻⠓⠑⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣌⣬⣮⣮⣮⣎⣌⣌⣮⣿⣿⣿⣿⣿⣿⣿⣿⣝⣝⣝⣮⣮⣮⣮⣎⣌⣌⣌⣮⣮⣮⣮⣮⣮⣮⣮⣮⣾⣿⣿⡷⡷⠷⠳⠓⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠁⠀⠀⣑⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⢙⢙⢉⢈⢈⢈⢈⠈⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣈⣌⣮⣿⣿⡷⢳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢻⠳⠳⠓⠑⠑⠑⠑⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⢈⢈⣌⣿⣿⣿⣿⣿⣮⣮⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⠻⡳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣎⢈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠱⣷⣟⠳⠆⠀⣳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣞⠙⠳⡷⣷⣿⣿⣯⢌⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠰⣷⣿⣿⣿⣿⡿⠳⠑⠑⠑⠳⠳⡳⡷⡷⡷⡷⠷⠀⠀⠀⠱⡇⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣎⠈⠀⠐⠱⡷⣿⣯⢌⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠑⠳⡳⠳⠁⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⠌⠀⠀⠀⠀⠱⡳⣏⠈⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡳⣧⣮⣎⣌⣌⣌⣌⣌⣌⣌⣬⣮⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠌⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢈⢈⢘⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠱⣷⣿⣿⣿⣿⣯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣈⣮⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠗⠀⠀⠰⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠓⠁⠀⠀⠀⠀⣱⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢀⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠷⠓⠀⠀⠀⠀⠀⠀⠀⣰⣿⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠷⠳⢓⣽⣿⣿⡷⠳⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠷⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⡣⣦⣎⣌⢈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⡳⣿⣿⣯⣎⢈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⠱⣷⣿⢏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⠈⠀⠀⠀⢈⢈⢈⢹⣷⣿⣿⣯⣎⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⠈⠱⡷⣏⢈⠀⠀⠀⠀⠀⠀⠀⠑⣳⣯⣎⠈⢙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣎⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⣌⢘⠑⠁⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢎⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠰⣿⣿⣿⡿⠱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠳⠁⠀⢀⣨⣿⣿⣿⣿⣿⣿⠷⠳⠳⠳⡷⣿⣿⣿⣿⣿⠎⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠐⣷⣿⠃⠀⠐⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣍⣌⣌⣌⣌⣮⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠰⣿⣿⣿⣿⣏⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣎⡾⠃⠀⠀⠀⠀⣿⣷⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⡿⠓⠳⡳⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢍⠀⠀⣷⣿⣿⣟⣝⢈⢈⣌⠀⠀⠀⠓⣰⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣬⣿⣿⣿⠷⠑⠀⠀⠀⠀⠀⠐⠱⠳⡷⡗⠱⡳⡷⣿⣿⣿⣿⢏⠀⠀⠐⠑⠑⠑⠑⠑⠀⠀⠀⠀⠀⣼⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢈⣌⣮⡿⡷⠳⠑⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⠷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠲⠳⠑⠑⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠷⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣈⡿⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡶⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

(I created that with https://image2ascii.com/)
Maybe their algorithm expects the dots at other codepoints?

Here is the source image, with very smooth borders:

dragon

@musjj
Copy link

musjj commented Sep 28, 2022

Here you go:

  ⣴⣶⣤⡤⠦⣤⣀⣤⠆     ⣈⣭⣿⣶⣿⣦⣼⣆         
   ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦      
         ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷    ⠻⠿⢿⣿⣧⣄    
          ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄   
         ⢠⣿⣿⣿⠈    ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀  
  ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘  ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ 
 ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷   ⢊⣿⣿⡏  ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄  
⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ 
⠙⠃   ⣼⣿⡟  ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄
     ⢻⣿⣿⣄   ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆    
      ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃    

Rendered in Vim with Wezterm:
image

[why]
First the new ScaleGlyph has been introduced with commit
  e5768e9 font-patcher: Redesign ScaleGlyph parameter

and afterwards it has been enhanced to avoid rounding errors
with commit
  983226a font-patcher: Fix scaleGlyph related rounding error

The later commit uses a function that explicitely says it will destroy
the glyph at a specific location, AFTER we already patched in one glyph
(namely F000).

It does not look too bad, bad that glyph is not correctly rescaled or
translated. Only that glyph is affected because only Font Awesome uses
the new ScaleGlyph capabilities, and only the first glyph of a set is
affected.

[how]
The ScaleGlyph calculations need to be done before the final glyph is
patched in. It is shifted some lines up. Usually that glyph is not
existing in the to-be-patched font, so we create a dummy first.

Also need to correct distinction between 'unicode in symbol font' and
'unicode in to-be-patched font', as this would bite us in cases where we
move the symbol's codepoint.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When the combinded bounding box of a range of glyphs is to be determined
and the range contains an empty glyph the resulting bounding box will
always include the [0, 0] point (that is the point-ish bounding box of
the empty glyph).

[how]
If more than one codepoint is to be considered empty glyphs are ignored.
But if only one (concrete) codepoint is queried do return the empty
(i.e. [0, 0, 0, 0]) bounding box.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
If we use a ScaleGlyph range (i.e. use the same scaling on a range of
glyphs; the scaling is determined by the combined bounding box of all
that glyphs), we probably want to shift the glyphs identically as well
to preserve relative positions not only sizes of the glyphs within the
range.
But the data is stored nowhere.

[how]
Store the 'virtual' bounding box along with the scale.

[note]
With combined (virtual) bounding box we mean the bounding box that a
glyph would have where all the individual glyphs would be stamped over
each other without shifting/scaling beforehand.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
We might want to handle monospaced symbol fonts differently then
proportional symbol fonts. Proportional symbol fonts usually have
no uniform symbol scaling, while monospaced symbol fonts usually have a
well designed placement of the symbols within the cell.

[how]
Add new member to the dimensions dict.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Finii and others added 8 commits October 13, 2022 16:56
[why]
If we define glyph groups in ScaleGlyph we want them to be scaled alike,
but they are aligned individually, which makes previously matching pairs
looking odd.

[how]
If we have a combined bounding box stored in a ScaleGlyph range, that
box is used to align all symbols in the range identically.

If the symbol font is proportinal only the v alignment is synced.
If the symbol font is monospaced v and h alignemnts are synced.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Man do I hate these indented tables in code. Specifically because they
break conciseness of commits if one needs to re-indent unrelated
entries.

[how]
Do it in this separate commit that does not change functionality.

[note]
Smuggled in unrelated code shift by some lines.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
This is obviously a complete mess.
Firstly it seems the author (me) used the array elements as ranges,
which is of course not possible. And them the end has a typo.
Sigh.

[how]
Not consecutive codes must all be given one by one (unfortunately).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The weather icons have some symbols that have a different bounding box
but should nevertheless be scaled alike, because for example one is the
outer line of a thermometer and one is the matching stem.

[how]
Just add a scaleGlyph set.

Fixes: ryanoasis#915

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
All Braille glyphs shall keep their relative size and position, so that
we see a difference if a single dot is low or high for example.

[how]
Set the ScaleGlyph, so that the total bounding box of all glyphs is
scaled and shifted, but all individual glyphs with the same values (thus
keeping them consistent).

Also set 'Exact', as that is the 'spirit' used here. Exact means that
gaps in the symbol font are NOT skipped over, keeping codepoints as they
are. The Braille source font does not have gaps, but anyhow, we do not
want any 'codepoint compression' and express this now.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Usually we scale symbols so that they are maximized within one 'cell' of
the font. If we do this for the Braille glyphs the bottom dots from an
upper line will (almost) touch the top dots of the next line. This is
not useful.

[how]
We add padding around the Braille glyphs, to get about the same distance
to the cell borders as the different dots in one glyph have to the
other (~10 %, 5% on each side).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii
Copy link
Collaborator

Finii commented Oct 13, 2022

Rebase on master, actually rebase on the code added by #916 which has the same problems.
Force push.

@Finii
Copy link
Collaborator

Finii commented Oct 13, 2022

Well, I do not know if this is really useful.

The braille glyphs are designed to always have one row of dots empty, so that one can distinguish between 'letters'.
Here is how the font originally looks like:

image

Dots have the blue diameter.
The leftmost (pale) dot is never there.
Between dots we have a gap of green
And the brown gap in the beginning and end of the glyph together are also one green.

This is in direct contradiction to the image shown above, where there are no visible vertical gaps from the columns of not-existing points.

Here you see the 'empty columns of dots' (arrows), and that they are missing in Wezterm:

image

This just talks about the vertical gaps, not the horizontal (line to line) ones.

Braille rendered with a font without char-to-char gaps will be unreadable.

@Finii
Copy link
Collaborator

Finii commented Oct 13, 2022

Lets assume we do not care if Braille is readable, because ... we are Nerds and Braille is not read from a screen but from a Braille line reader.

To get the padding right...

Horizontally we have (2 * blue + 1 green) * padding% = 1 green
Vertically we have (4 * blue + 3 green) * padding% = 1 green

This is not working if horizontal and vertical padding is the same; which is how it is currently with the patcher.

And for that we would still scale the glyphs not preserving aspect ratio, thereby ending up with ellipsis.

I guess the only good solution (for a graphical display) would be to generate the glyphs while patching the font with adapted gaps. This would also be possible but a totally different approach, rather like Wezterm.

@musjj
Copy link

musjj commented Oct 18, 2022

That seems like an interesting approach. Not really sure how fonts work, but thinking about it again, is it actually possible to get rid of the horizontal space between the lines? Aren't they rendered and controlled by the terminal instead of the fonts?
Maybe this isn't possible after all without custom glyph rendering done by the terminal.

@Finii
Copy link
Collaborator

Finii commented Oct 18, 2022

is it actually possible to get rid of the horizontal space between the lines?

We get rid of it for the powerline glyphs, right? ;-)

image

They always touch top and bottom of the line (at least in terminal emulator environments).

@Finii Finii marked this pull request as draft January 4, 2023 16:56
@Finii
Copy link
Collaborator

Finii commented Jan 4, 2023

Lots of work done here has been transferred to #916. Adding a Braille font after that PR becomes a breeze.
But still I guess we would need to generate the glyphs rather than add a font, for reasons mentioned above.
Maybe there is time for that in the future. For now I will exclude it from v2.3.0. Converting to draft to keep this.

@Finii Finii removed this from the v2.3.0 milestone Jan 4, 2023
@clort81
Copy link

clort81 commented Jan 22, 2023

Lets assume we do not care if Braille is readable, because ... we are Nerds and Braille is not read from a screen but from a Braille line reader.

To get the padding right...

Horizontally we have (2 * blue + 1 green) * padding% = 1 green Vertically we have (4 * blue + 3 green) * padding% = 1 green

This is not working if horizontal and vertical padding is the same; which is how it is currently with the patcher.

And for that we would still scale the glyphs not preserving aspect ratio, thereby ending up with ellipsis.

I guess the only good solution (for a graphical display) would be to generate the glyphs while patching the font with adapted gaps. This would also be possible but a totally different approach, rather like Wezterm.

In particular, braille characters are useful as box-drawing characters.

I ask the reader to now take comprehension of a few pertinent facts:

  • Fonts are made for people with functional vision. We view font glyphs on screens, with our eyes.
  • Blind people do not read braille on screens, with their eyes, which don't work, because they are blind.
  • The Braille glyphs add 256 (2^(4x2)) distinct drawing glyphs, which allow us far greater flexibility in drawing to terminal than other glyphs in the BMP range.
  • The style of braille glyphs is most useful for drawing when they are connecting blocks, as opposed to dots.

Which looks better to you? Dot-braille or block-braille?
dotbraille_vs_block_braille-menus
dotbraille_vs_block_braille-art
fancy_monitor2.txt.gz

@Finii
Copy link
Collaborator

Finii commented Jan 22, 2023

@clort81 Interesting design.
And they (the blocky ones) would not need to be generated for each font but can be patched in using xy scaling. They would be oblong and not square, just fitting the 'Braille grid' into one target font cell.

@Finii
Copy link
Collaborator

Finii commented Feb 20, 2023

@Finii Finii added this to the Parallel Universe milestone Mar 10, 2023
@Finii
Copy link
Collaborator

Finii commented Mar 10, 2023

The future of this is unclear.
The Braille glyphs have a function in unicode, and that is representing Braille.

This PR heads in the direction to re-assign the codepoints to 'some graphics glyphs', what is not exactly right in Unicode context.

So probably this will be only a self-patch option or something.

Moving this to parallel Universe to get it out of the mainstream development.

@Finii Finii closed this Mar 10, 2023
@PhMajerus
Copy link

If you're interested, Unicode accepted another block of octants for 2×4 pseudo-pixels.

image

U+1CD00 to U+1CDE5 (it isn't the complete 256 semigraphic characters because some patterns already exist as quadrants or half-blocks).
The octants are documented at https://www.unicode.org/L2/L2021/21235r-terminals-supplement.pdf
Their planned inclusion in Unicode 16.0 is shown at https://www.unicode.org/alloc/Pipeline.html

Updating apps using braille to use the new octants should be easy, it should even be possible to write a small conversion utility that can be piped to that switches existing Braille to the new Octants without touching existing utilities that use Braille.

@Finii
Copy link
Collaborator

Finii commented Jan 21, 2024

@PhMajerus Thanks for the update. That certainly looks interesting.
I need to have a closer look.

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

Successfully merging this pull request may close these issues.

Support for Braille Characters?
5 participants