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.
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 vlaue, 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_pos(p1: Vertex, p2: Vertex = None, align: str = None) Text ¶
Set text alignment, valid alignments are:
Alignments “ALIGNED” and “FIT” are special, they require a second alignment point, text is aligned on the virtual line between these two points and sit vertical at the base line.
“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 vertical centred at the total height of the text.
p1 – first alignment point as (x, y[, z]) tuple
p2 – second alignment point as (x, y[, z]) tuple, required for “ALIGNED” and “FIT” else ignored
align – new alignment,
Nonefor preserve existing alignment.
- get_pos() Tuple[str, ezdxf.math._vector.Vec3, Optional[ezdxf.math._vector.Vec3]] ¶
Returns a tuple (align, p1, p2), align is the alignment method, p1 is the alignment point, p2 is only relevant if align is “ALIGNED” or “FIT”, otherwise it is
- set_align(align: str = 'LEFT') Text ¶
Just for experts: Sets the text alignment without setting the alignment points, set adjustment points attr:dxf.insert and
align – test alignment, see also
- 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 “FIT” and “ALIGNED”, defined by the distance from the insertion point to the align point or 0 for all other alignments.