Text¶
The single line TEXT entity (DXF Reference). 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.
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 vlaue, 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_pos()
andget_align()
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_pos()
andget_align()
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
¶ Get/set text generation flag BACKWARDS, for mirrored text along the x-axis.
-
property
is_upside_down
¶ 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:
Vertical
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
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
dxf.height
attribute.“MIDDLE”: also a special adjustment, centered text like “MIDDLE_CENTER”, but vertical centred at the total height of the text.
- Parameters
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,
None
for 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
None
.
-
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
dxf.align_point
manually.- Parameters
align – test alignment, see also
set_pos()
-
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.
-