Text¶
The TEXT entity (DXF Reference) represents a single line of text.
The style
attribute stores the associated Textstyle
entity as
string, which defines the basic font properties. The text size is stored as cap-height
in the height
attribute in drawing units. Text alignments
are defined as enums of type ezdxf.enums.TextEntityAlignment
.
See also
See the documentation for the Textstyle
class to understand the
limitations of text representation in the DXF format.
Subclass of |
|
DXF type |
|
Factory function |
|
Inherited DXF attributes |
Warning
Do not instantiate entity classes by yourself - always use the provided factory functions!
- class ezdxf.entities.Text¶
- dxf.text¶
Text content as string.
- dxf.insert¶
First alignment point of text (2D/3D Point in OCS), relevant for the adjustments LEFT, ALIGNED and FIT.
- dxf.align_point¶
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.
- dxf.height¶
Text height in drawing units as float value, the default value is 1.
- dxf.rotation¶
Text rotation in degrees as float value, the default value is 0.
- dxf.oblique¶
Text oblique angle (slanting) in degrees as float value, the default value is 0 (straight vertical text).
- dxf.width¶
Width scale factor as float value, the default value is 1.
- dxf.halign¶
Horizontal alignment flag as int value, use the
set_placement()
andget_align_enum()
methods to handle text alignment, the default value is 0.0
Left
2
Right
3
Aligned (if vertical alignment = 0)
4
Middle (if vertical alignment = 0)
5
Fit (if vertical alignment = 0)
- dxf.valign¶
Vertical alignment flag as int value, use the
set_placement()
andget_align_enum()
methods to handle text alignment, the default value is 0.0
Baseline
1
Bottom
2
Middle
3
Top
- dxf.text_generation_flag¶
Text generation flags as int value, use the
is_backward
andis_upside_down
attributes to handle this flags.2
text is backward (mirrored in X)
4
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: UVec, p2: UVec | None = None, align: TextEntityAlignment | None = None) Text ¶
Set text alignment and location.
The alignments
ALIGNED
andFIT
are 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 thedxf.height
attribute.MIDDLE
: also a special adjustment, centered text likeMIDDLE_CENTER
, but vertically centred at the total height of the text.
- Parameters:
p1 – first alignment point as (x, y[, z])
p2 – second alignment point as (x, y[, z]), required for
ALIGNED
andFIT
else ignoredalign – new alignment as enum
TextEntityAlignment
,None
to preserve the existing alignment.
- get_placement() tuple[TextEntityAlignment, Vec3, Vec3 | None] ¶
Returns a tuple (align, p1, p2), align is the alignment enum
TextEntityAlignment
, p1 is the alignment point, p2 is only relevant if align isALIGNED
orFIT
, otherwise it isNone
.
- get_align_enum() TextEntityAlignment ¶
Returns the current text alignment as
TextEntityAlignment
, see alsoset_placement()
.
- 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
dxf.align_point
manually.- Parameters:
align –
TextEntityAlignment
- 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.FIT
andTextEntityAlignment.ALIGNED
, defined by the distance from the insertion point to the align point or 0 for all other alignments.