Logic flaw in gfx/include/gfx_drawing.hpp::text_impl (3183 ff)
fschuetz opened this issue · comments
gfx/include/gfx_drawing.hpp::text_impl (3183 ff) contains a logic flaw when rendering text. On line 3222, 3214 and 3266 the following check is done:
if(chr.y2>dest_rect.bottom()) { return gfx_result::success; }
This check I assume should stop drawing when it would render text outside the target. However, there are two problems:
- the check (verified with the code block around 3266) is only done after drawing the first character. So the first character is always drawn.
- the check uses y2, which lead to partially visible text not rendered as the top might be in the visible range, but the bottom is not (assume target of height 4 pixels but font height 8 pixels. The assumption would be the top half of the text is rendered. Can easily be fixed by replacing y2 with y1.
The behaviour can be verified by for example on a 128x160 (landscape) display drawing text in a are that is smaller than the font height. For example:
draw::text(destination, remaining_area, item_ptr->name, font, col);
with destination the lcd, remaining_area (0,122)(159,127).
Thank you. I'll fix as soon as I can. I am buried with work at the moment, but I really appreciate you running this down for me.
Edit: Thinking back, I believe the idea is to stop rendering as soon as no more output would happen to the window, rather than to avoid rendering outside the draw rectangle (which clips anyway). This is how for example, Microsoft.NET handles drawing outside the lines with text. In general when I haven't had my own idea for how to do something, or even just to have a familiar model to draw from, I tended to emulate the behaviors of .NET/GDI+ for various things in GFX, at least where I was able.
Yes, I see the idea. However, the current implementation will draw one character (that might partially fit the screen, eg. the upper part of A), but not the rest of the string (eg. BCDE if the string were "ABCDE") even though their upper parts would also be visible.
fixed in 1.3.5