Tutorial for Text

TEXT - just one line

Add simple one line text with the factory function Layout.add_text().

import ezdxf

dwg = ezdxf.new('AC1009')  # TEXT is a basic entity and exists in every DXF standard

msp = dwg.modelspace()

# use set_pos() for proper TEXT alignment - the relations between halign, valign, insert and align_point are tricky.
msp.add_text("A Simple Text").set_pos((2, 3), align='MIDDLE_RIGHT')

# using text styles
dwg.styles.new('custom', dxfattribs={'font': 'times.ttf', 'width': 0.8})  # Arial, default width factor of 0.8
msp.add_text("Text Style Example: Times New Roman", dxfattribs={'style': 'custom', 'height': 0.35}).set_pos((2, 6), align='LEFT')

dwg.saveas("simple_text.dxf")

Valid text alignments for the align argument in Text.set_pos():

Vert/Horiz Left Center Right
Top TOP_LEFT TOP_CENTER TOP_RIGHT
Middle MIDDLE_LEFT MIDDLE_CENTER MIDDLE_RIGHT
Bottom BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT
Baseline LEFT CENTER RIGHT

Special alignments are, ALIGNED and FIT, they require a second alignment point, the text is justified with the vertical alignment Baseline on the virtual line between these two points.

Alignment Description
ALIGNED Text is stretched or compressed to fit exactly between p1 and p2 and the text height is also adjusted to preserve height/width ratio.
FIT Text is stretched or compressed to fit exactly between p1 and p2 but only the text width is adjusted, the text height is fixed by the height attribute.
MIDDLE also a special adjustment, but the result is the same as for MIDDLE_CENTER.

more is coming soon ...