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
base: master
Are you sure you want to change the base?
Add Braille support #837
Conversation
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 |
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}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
Additional note If you edit the commit, maybe you could add to the commit message the |
Same font packaged here: https://aur.archlinux.org/packages/ttf-ubraille The font contains this copyright notice 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. |
For me this looks good to merge now; playing the ball to @ryanoasis |
It's a whole lot more involved than I initially thought. Split that up into individual commits that introduce the changes step by step. The changes are (mostly) only active when patching in the Braille font. Also noticed that one glyph in the source font is missing: Although it should have dot 6 (2nd colum, 3rd from top) and dot 7 (1st column, lowest row) active - as the tiny |
1df21b6
to
faf7503
Compare
Rebase on master, force push |
faf7503
to
c8bd64c
Compare
All the readmes need an update for the new parameter 🛑 |
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 |
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 :-} |
Cool, looking forward to it :) And the PR implementing this: wez/wezterm#919 |
Well, the 'cells' of some fonts are rectangular, more high than wide, like your cursor in the image above. |
Ah, they do not patch in a scaled source, they create the glyphs on the fly from circles drawn in the 'cell'. |
@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/) Here is the source image, with very smooth borders: |
Here you go:
|
[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>
[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>
GPL 2 licensed TTF file from https://yudit.org/download/fonts/UBraille/UBraille.ttf Fixes ryanoasis#482
[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>
c8bd64c
to
ec695c7
Compare
Rebase on master, actually rebase on the code added by #916 which has the same problems. |
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'. Dots have the blue diameter. 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: 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. |
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 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. |
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? |
Lots of work done here has been transferred to #916. Adding a Braille font after that PR becomes a breeze. |
In particular, braille characters are useful as box-drawing characters. I ask the reader to now take comprehension of a few pertinent facts:
Which looks better to you? Dot-braille or block-braille? |
@clort81 Interesting design. |
The future of this is unclear. 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. |
If you're interested, Unicode accepted another block of octants for 2×4 pseudo-pixels. U+1CD00 to U+1CDE5 (it isn't the complete 256 semigraphic characters because some patterns already exist as quadrants or half-blocks). 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. |
@PhMajerus Thanks for the update. That certainly looks interesting. |
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)
Screenshot by dominikheinz from the related issue.