-
Notifications
You must be signed in to change notification settings - Fork 5
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
write_left,right rounds to pixel. temperature_color robus to nil temp #3
Conversation
Hey, thanks for the PR! If that does away with the blurry text I'll be very happy. |
src/cairo_helpers.lua
Outdated
x, y = cairo_user_to_device(cr, x, y) | ||
-- https://scriptinghelpers.org/questions/4850/how-do-i-round-numbers-in-lua-answered | ||
x = x + 0.5 - (x + 0.5) % 1 | ||
y = y + 0.5 - (y + 0.5) % 1 |
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.
Are you sure about this one? Following the link you've provided I can only find the standard math.floor(x + 0.5)
approach. If this is some lua hack I don't know yet please put it in a util.round helper and add an explanation.
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.
It is not a lua thing, it's just another way to round to an integer. It adds 0.5 and then subtracts the remainder that doing so pushes the sum over an integer.
BlueTaslem's answer in that link says this method is about 20% faster than floor(x+0.5). I'm fine to change it if it's hard to maintain/read. Can also refactor the rounding routine into its own function.
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.
Honestly I'd just prefer the inline floor(x+0.5). It's simpler and this is definitely not the bottle neck.
I've taken a closer look now and unfortunately it doesn't look like this changes text sharpness. The referenced FAQ section is talking about straight lines aligned to pixels, like the ones used to draw the various boxes. If anything it'd make sense to use this in widgets like Bar and Graph, but these should already be aligned pixel perfect. Text isn't straight lines and so will get anti-aliased either way. The changes here only align the top left corner of the text's bounding box, which doesn't do much. In addition, transforming back and forth between user and device space is only relevant if there is a transformation matrix. The only transformations used in the layout system are translations by full integer values, which do not change anything about the rendering sharpness. The fact that the text test passes on the PR confirms that there is no difference in rendering. Some impromptu logging also shows that the values don't change before and after rounding. If you're getting different results on this, please let me know! As such I won't merge the changes involving coordinate rounding unless there is some benefit I've missed. If you want to remove them, though, I'd be happy to pick up the changes you did to edit: I accidently sent this before I was done writing, sorry. :/ |
It made text sharp on my machine. I'm running Arch with conky-cairo, though, and the test-text has always failed for me. Maybe there is some difference? |
Could you send me a screenshot before/after? |
Sure. Conky:
Cairo:
|
Okay that definitely looks like an improvement. Apparently the vertical translation has some effect after all, even though I cannot reproduce it. Even shifting content by 0.5 pixels does not give me the same result. |
Thanks! |
Yes I noticed that shifting horizontally by 0.5 pixels did not work for me either. I didn't investigate, tho. |
this helps cairo drawn text in the drive temperatures and gpu top list be sharp
also avoids crashing when temperature is nil, which is nice while configuring hardware