Use `start` instead of 0 for the starting index in `text` by iTutFadU · Pull Request #1257 · processing/processing4
The text will show up at the correct height (here green) instead of counting newlines preceding it before the range (here red).
The example code:
String text = "Some\n\ntext\nwith\nnewlines"; char[] chars; float textWidth; void setup() { size(500, 500, P2D); textFont(createFont("Arial", 50)); textAlign(LEFT, TOP); chars = text.toCharArray(); textWidth = textWidth(text.substring(6, text.length())); } void draw() { background(20); fill(#FF5555); text(chars, 6, text.length(), 0, 0); fill(#55FF55); text(text.substring(6, text.length()), width / 2, 0); }