Strange horizontal Offset when drawing centered multiline strings

Godot Version

4.3

Question

I’m trying to draw centered multiline text width draw_multiline_string and get weird horizontal offsets (see screenshot below).

This is the relevant code:

var brk_flags = TextServer.BREAK_MANDATORY + TextServer.BREAK_WORD_BOUND + TextServer.BREAK_TRIM_EDGE_SPACES
var size = font.get_multiline_string_size(text, HORIZONTAL_ALIGNMENT_CENTER, center_radius*1.9, fontsize, -1, brk_flags)
var pos = center_offset - Vector2(size.x/2.0, size.y/2.0-font.get_ascent())
draw_multiline_string(font, pos, text, HORIZONTAL_ALIGNMENT_CENTER, center_radius*1.9, fontsize, -1, color, brk_flags)
draw_rect(Rect2(Vector2(pos.x, pos.y - font.get_ascent()), size), Color.RED, false, 1)

This produces the following output:

wrong_multiline_centered_positions

The problem is with the horizontal offset; the text should be bounded by the red box, which has the size that get_multiline_text_size returns, and is drawn at the same x position as the text (the slight vertical offset is not relevant here).

The positioning code works fine when I change the alignment in the draw command to HORIZONTAL_ALIGNMENT_LEFT (but I want the text centered in the box)

right_multiline_leftaligned_positions

Ist this a bug in draw_multiline_string, or am I doing something stupid? I’ve tried fiddling around with the break flags without success.