[WIP/RFC] Handle multiple spaces after PUA glyphs#1036
[WIP/RFC] Handle multiple spaces after PUA glyphs#1036kovidgoyal merged 8 commits intokovidgoyal:masterfrom
Conversation
kitty/fonts.c
Outdated
| render_run(fg, line->cpu_cells + i, line->gpu_cells + i, j + 1, cell_font_idx, true); | ||
| run_font_idx = NO_FONT; | ||
| first_cell_in_run = i + 1 + j; | ||
| prev_width = gpu_cell->attrs & WIDTH_MASK; |
There was a problem hiding this comment.
Re prev_width: I think this should be 1 always (regardless of this patch) to not continue above in any case.
This appears to happen in |
|
Fitting into the cell is not going to change -- it is needed for proper rendering of glyphs from fallback fonts, which can have different metrics than the main font. |
|
As for handling multiple spaces, IIRC kitty supports a max ligature length of 9 so you should ensure that the fake ligature you create is no longer than that, or bad things will happen down the road (see MAX_NUM_EXTRA_GLYPHS) |
|
MAX_NUM_EXTRA_GLYPHS is check here: https://github.com/kovidgoyal/kitty/pull/1036/files#diff-bf6698a6663f1ce908538b90d1fbe1e7R1014 |
I've looked into a bit more and the bitmap created from fontconfig is only 25 pixels wide already ( |
|
No, I prefer scaling to cropping. But I am fine with having an option to control that behavior. However, it would only work with freetype since AFAIK there is no way to do that with coretext. |
Great. Do you have some pointers for me where this needs to happen? |
|
Basically you'd need to change the code that fits the glyph(s) into the canvas to crop instead of scaling based on the value of the option |
|
That would be |
|
sorry dont remember off the top of my head would have to read the code, and I dont have the time for that right now |
|
Ok, will look into this a bit more. As for this PR: it should be independent from what we discussed above, but I've just noticed that it is broken (added space before): This appears to be happen because it gets centered in the group of 8 cells (via https://github.com/blueyed/kitty/blob/efc0b830cf5a4430adfa48be9a874086f974a427/kitty/freetype.c#L510-L516). |
|
yes glyphs are currently centered in the canvas. this works well for most glyphs such as emoji and flags and east asian characters. If you want left alignment for pua glyphs, you will need to change the freetype rendering api to pss in a bool controlling alignment. rememberthat these functions are also used in coretext so make the changes there as well. Finally, the more cells there are in a ligature, the worse lookup performance is. so I would prefer restricting the max number of spaces to 2 or 3 ince I doubt nerd fonts need more than that. |
Not sure why this became necessary though?!
Fixes:
Linking kitty/fast_data_types ...
kitty/freetype.c: In function ‘render_glyphs_in_cells’:
kitty/freetype.c:514:82: warning: ‘bm.right_edge’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (num_cells > 1 && right_edge < canvas_width && (delta = (canvas_width - right_edge) / 2) && delta > 1) {
^
kitty/freetype.c:490:21: note: ‘bm.right_edge’ was declared here
ProcessedBitmap bm;
^
|
I've added some commit to use the actual number of cells (currently only for freetype, based on the bitmap). Does this make sense? |
|
The metrics for U+e0c2 are this btw: (cell height is 20, cell width 10) |
|
If |
|
I'll review this when I have a little more time. |
|
I'll review this sometime in the next few days. Apologies for the long delay, my personal life has been crazy and I am trying to catch up now. |
|
Wow, thanks for merging - I would have expected some review/comments on it first, and would have squashed at least the fixup then, but ok.. :) |
|
I made some minor changes, but otherwise it looked good, and I am not fussy about commit history :) I find merging things quickly that require only minor cleanups is better for my long term productivity. |
|
Cool, thanks again! |


This handles multiple spaces after a PUA glyph (instead of just one).
Before:

After:

It still does not work as in (patched) urxvt, because kitty appears to shrink it to fit its height into the cell. In urxvt it looks like follows:

Where does the shrinking / fitting to cells happen? I would rather have it take the full width of the 3 cells, and be cut at the top/bottom.