-
Notifications
You must be signed in to change notification settings - Fork 769
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
i3bar: Fix font rendering for Caveat font #4357
Conversation
Thanks for your contribution! Font rendering is frustratingly difficult to get right even with libraries like pango. :-( Unfortunately, the test suite will be of not much use here, but I'm happy to hear you tried it with various fonts already. I don't really know too much about the depths of font rendering, but I'm willing to give this a shot on the next branch and we'll see if it causes issues somewhere. Let's see if @orestisfl has some thoughts on this maybe. |
Side note, I haven't dug much into it, but awesome also makes calls to |
No thoughts here either |
Thanks for your feedback. Yes, font rendering is indeed more than difficult. I would be fine with an approach of trying it out and bailing out if there are any complaints, but I found some issues with my suggested solution. I tried some more fonts, and Akaya Telivigala is worse with my patch than without. Using my patched version and this font, some status text is now elided (is this the right word? I see the ... ellipse instead of the word). As it turns out, the x offset for the ink extent can also be negative (didn't expect that for some reason). Adding the x offset of the ink extent conditionally feels weird, so I will do some more tinkering and maybe look into awesome, as suggested. |
@mychris Thanks for giving this some good testing. Let us know when you're done :-) |
Ok, this is the best result I got. It's not conditionally adding the ink offset, but taking the max value of the (ink width + ink offset) or the layout offset. I used
I start to believe that the best solution would be, to always draw the text last, so it can be drawn above the border/spacer area, if the font has such a layout that the ink extent is outside the logical extent. With the new patch, the worst case is that fonts are no longer centered. The old width was |
I never understood i3's rendering code, but... Why are you lying to cairo about the size of the drawable? Lines 84 to 90 in fff8b0c
This tells cairo that the drawable has size x + max_width . I somehow doubt that the drawable really has this size. It likely is larger.
If you told cairo the real size of the drawable, it could draw things in the right side and would not clip away parts of things. Also, this is just ugly (sorry!): So... the logical extents should be used for placing text and the ink extents are only needed if you want to do partial redraws / need to figure out how far the text reaches. Should I try taking a look at this code and figuring out where text is clipped and how to get rid of that? |
That's what I try to do. I am not familiar with the i3 code at all. The My problem is that I found fonts, for which the ink extent can be partially outside of the logical extent. For instance, you can have a text, for which the logical extent has a width of 50, and the ink extent has an offset of 3 and a width of 49, hence it is 2 pixel outside of the logical extent (that was the case for me with Caveat). So I try to figure out how to calculate the "real size". If you could elaborate (or show code) on how to do it, I would be very much interested in that, since I don't have much experience in this.
That's also what I read, but since the ink extent can be outside of the logical extent, I am not so sure about this. Maybe I also don't get what you mean by "placing text", because the text is, for sure, not always completely inside the logical extent. That's also what
That would be very much appreciated.
Yes, it is only about the Caveat font, which is clipped at the right edge. I didn't find any other issue in |
@psychon Thanks for taking a look here, I was considering tagging you, but didn't want to bother you either. I'm sure our font rendering code could do with improvements. If you have time to look at that it would definitely be much appreciated. |
i3 actually manages to have two different cairo surfaces referring to the same drawable. One comes from the code in draw_util. The second is temporarily created while rendering text via draw_text(). No idea how well cairo handles this case. This commit instead changes the code to pass the already existing cairo surface from the caller through. This might or might not fix i3/i3#4357. My thinking here is that cairo now knows the actual size of the drawable and thus does not clip the drawing to a smaller size. Signed-off-by: Uli Schlachter <psychon@znc.in>
i3 actually manages to have two different cairo surfaces referring to the same drawable. One comes from the code in draw_util. The second is temporarily created while rendering text via draw_text(). No idea how well cairo handles this case. This commit instead changes the code to pass the already existing cairo surface from the caller through. This might or might not fix i3/i3#4357. My thinking here is that cairo now knows the actual size of the drawable and thus does not clip the drawing to a smaller size. Signed-off-by: Uli Schlachter <psychon@znc.in>
Hi,
I noticed that font rendering for i3bar has some problems with certain fonts.
Using the google font Caveat for instance, the text in the bar is always cut off at the right side. For the workspace buttons as well as for the text in the status bar.
I don't know if this is a regression, or not, since I just tried out the font today and noticed it.
I think this is because the ink extent is not accounted for?
I tried to fix the issue, by adding the ink extent to the text width, when it is calculated. I first tried to adjust the rendering position of the text, but this resulted in text no longer being centered for certain other fonts. I tried the patch with different fonts I used before with i3bar and it seems to work. I am not so experienced with pango, so I am happy for any more insights.
I executed the test suite and it passes:
Do you know of some fonts which gave you trouble in the past? I can do some more experiments to see if my solution is robust enough.
Any comments are welcome.