Open yannis300307 opened 1 year ago
Help page https://www.numworks.com/manual/python/ indicates: "draw_string(text,x,y,[color1],[color2]) Displays text from the pixel x,y. The arguments color1 (text color) and color2 (background color) are optional. " So text begins to the x position but it indicates nothing about how "\n" is dealt with so going to the beginning of the line after \n isn't wrong.
Anyway, if we want to change the behaviour, the code dealing with this part is in kandinsky/src/context_text.cpp (KDContext::drawString method) 80 if (codePoint == UCodePointLineFeed) { 81 assert(position.y() < KDCOORDINATE_MAX - glyphSize.height()); 82 position = KDPoint(0, position.y() + glyphSize.height()); 83 if (origin().y() + position.y() >= Ion::Display::Height) { 84 break; 85 } 86 codePoint = decoder.nextCodePoint(); 87 }
if we change line 82 with: position = KDPoint(p.x(), position.y() + glyphSize.height());
it seems to work.
Remark: if we use position = KDPoint(position.x(), position.y() + glyphSize.height()); it doesn't work, the next line is shifted to the right.
Describe the bug
When rendering a newline character with
draw_string()
, the x coordinate will be resest.Screenshots
Here is the result of
draw_string("hello!\na line",100,10)
:To Reproduce
Steps to reproduce the behavior:
from kandinsky import *
draw_string("hello!\na line",100,10)
for exemple.Expected behavior
The new line should be aligned with the first line of the text.
Environment