Add ImDrawTextFlags_NoPixelSnap for subpixel accurate text rendering - #9417
Add ImDrawTextFlags_NoPixelSnap for subpixel accurate text rendering#9417petrihakkinen wants to merge 1 commit into
Conversation
|
Thanks Petri. As discussed I'll see if I can come up with a short-term workaround. |
|
After much consideration I decided for now to expose this as a ImDrawList state. draw_list->Flags |= ImDrawListFlags_TextNoPixelSnap;
// (do your rendering)
draw_list->Flags &= ~ImDrawListFlags_TextNoPixelSnap;Some reasoning:
Closing this as hopefully solved but don't hesitate to reach out if not. |
|
Thank you! This should resolve our issue. We will probably create a wrapper for AddText with the flag as argument though. Our main use case is Lua and we do live coding extensively. Exposing this as argument means that we don't have to worry about a script forgetting to reset the state. Also, on error we would need to reset any global state so that it won't leak to other places when we resume after error. |
|
Minor note: ImDrawListFlags_TextNoPixelSnap is currently tagged [Internal]. Shouldn't this be a public flag? Our Lua binding generator does not expose flags marked with [Internal], but we can add a special case... |
|
I've merged this change to our code base and can confirm it works. |
Removed the comment, indeed. While toying with the feature I first assumed it would be temporarily marked as such, but since it is advertised in the changelog it shouldn't.
Understood. In theory should should be exposed as stacks but the flags are extremely rarely used for now, and I'd rather not add another alloc to each draw-list. Note some error recovery feature exist for stack related issues: https://github.com/ocornut/imgui/wiki/Error-Handling, which indeed will not recover this specific bit. If you implement a recovery handler for Lua script you might decide to e.g. backup/restore specific state. Realistically speaking I would assume you are not wildly overwriting this flag, is your text editor in Lua or C++? |
Currently ImDrawList::AddText() internally snaps the given text position to integer pixels. This is problematic when using a font size with non-integer advance: Rendering text in multiple parts (e.g. "foo" followed by "bar") does not yield the same result as rendering the text in one go ("foobar"). With multiple parts every text fragment is floored individually, but when rendered as a single fragment, only the starting location is floored.
In order to fix this, this PR adds a new flag for disabling flooring in RenderText().
The PR is minimal to keep changes to the API as small as possible; the new flag is only supported by one overload of ImDrawList::AddText().
Related issues:
#2291
#3437
#791