The single line TEXT entity (DXF Reference). The
attribute stores the associated
Textstyle entity as string,
which defines the basic font properties. The text size is stored as cap height
height attribute in drawing units. Text alignments
are defined as enums of type
See the documentation for the
Textstyle class to understand the
limitations of text representation in the DXF format.
Inherited DXF attributes
Do not instantiate entity classes by yourself - always use the provided factory functions!
- class ezdxf.entities.Text¶
Text content as string.
First alignment point of text (2D/3D Point in OCS), relevant for the adjustments LEFT, ALIGNED and FIT.
The main alignment point of text (2D/3D Point in OCS), if the alignment is anything else than LEFT, or the second alignment point for the ALIGNED and FIT alignments.
Text height in drawing units as float value, the default value is 1.
Text rotation in degrees as float value, the default value is 0.
Text oblique angle (slanting) in degrees as float value, the default value is 0 (straight vertical text).
Width scale factor as float value, the default value is 1.
Aligned (if vertical alignment = 0)
Middle (if vertical alignment = 0)
Fit (if vertical alignment = 0)
Text generation flags as int value, use the
is_upside_downattributes to handle this flags.
text is backward (mirrored in X)
text is upside down (mirrored in Y)
- property is_backward: bool¶
Get/set text generation flag BACKWARDS, for mirrored text along the x-axis.
- property is_upside_down: bool¶
Get/set text generation flag UPSIDE_DOWN, for mirrored text along the y-axis.
- set_placement(p1: Union[Sequence[float], Vec2, Vec3], p2: Optional[Union[Sequence[float], Vec2, Vec3]] = None, align: Optional[TextEntityAlignment] = None) Text ¶
Set text alignment and location.
FITare special, they require a second alignment point, the text is aligned on the virtual line between these two points and sits vertically at the baseline.
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
MIDDLE: also a special adjustment, centered text like
MIDDLE_CENTER, but vertically centred at the total height of the text.
p1 – first alignment point as (x, y[, z])
p2 – second alignment point as (x, y[, z]), required for
align – new alignment as enum
Noneto preserve the existing alignment.
- get_placement() Tuple[TextEntityAlignment, Vec3, Optional[Vec3]] ¶
Returns a tuple (align, p1, p2), align is the alignment enum
TextEntityAlignment, p1 is the alignment point, p2 is only relevant if align is
FIT, otherwise it is
- get_align_enum() TextEntityAlignment ¶
- set_align_enum(align=TextEntityAlignment.LEFT) Text ¶
Just for experts: Sets the text alignment without setting the alignment points, set adjustment points attr:dxf.insert and
- translate(dx: float, dy: float, dz: float) Text ¶
Optimized TEXT/ATTRIB/ATTDEF translation about dx in x-axis, dy in y-axis and dz in z-axis, returns self.
- plain_text() str ¶
Returns text content without formatting codes.
- fit_length() float ¶
Returns the text length for alignments
TextEntityAlignment.ALIGNED, defined by the distance from the insertion point to the align point or 0 for all other alignments.