I think the text should be placed on the anchor point I set. And It has nothing to do with alignment.
doc = Layout::Document.new
s_p, e_p = Geom::Point2d.new(3, 5), Geom::Point2d.new(3, 3)
dim = Layout::LinearDimension.new(s_p, e_p, 1)
doc.add_entity(dim, doc.layers.first, doc.pages.first)
text = dim.text.plain_text
anchor_type = Layout::FormattedText::ANCHOR_TYPE_CENTER_CENTER
text_p = Geom::Point2d.new((s_p.x + e_p.x) / 2.0 + 1, (s_p.y + e_p.y) / 2.0)
dim.text = Layout::FormattedText.new(text, text_p, anchor_type)
cp = Geom::Point2d.new((s_p.x + e_p.x) / 2.0, (s_p.y + e_p.y) / 2.0)
path = Layout::Path.new(cp, text_p)
doc.add_entity(path, doc.layers.first, doc.pages.first)
path = File.join(ENV['Home'], 'Downloads', 'mydoc.layout')
status = doc.save(path)
There is no rule in the following situations.

When I add a FormattedText, itâs ok.
doc = Layout::Document.new
s_p, e_p = Geom::Point2d.new(3, 5), Geom::Point2d.new(3, 3)
anchor_type = Layout::FormattedText::ANCHOR_TYPE_CENTER_CENTER
text = Layout::FormattedText.new("test_text", e_p, anchor_type)
doc.add_entity(text, doc.layers.first, doc.pages.first)
path = Layout::Path.new(s_p, e_p)
doc.add_entity(path, doc.layers.first, doc.pages.first)
file = File.join(ENV['Home'], 'Downloads', 'mydoc.layout')
status = doc.save(file)
UI.openURL file
