Important
DXF is not a layout preserving data format like PDF. It is more similar tothe MS Word format. Many applications can open MS Word documents, but thedisplayed or printed document does not look perfect like the result ofMS Word.
The final rendering of DXF files is highly dependent on the interpretationof DXF entities by the rendering engine, and the DXF reference does notprovide any guidelines for rendering entities. The biggest visualdifferences of CAD applications are the text renderings, thereforethe only way to get the exact same result is to use the same CADapplication.
The DXF format does not and can not embed TTF fonts like the PDF format!
The Textstyle entity defines a text style (DXF Reference), and canbe used by the entities: Text, Attrib, Attdef
,MText, Dimension, Leader and MultiLeader.
Example to create a new text style “Arial” and to apply this text style:
doc.styles.add("Arial", font="Arial.ttf")msp = doc.modelspace()msp.add_text("my text", dxfattribs={"style": "Arial"})
The settings stored in the Textstyle entity are the defaulttext style values used by CAD applications if the text settings are notstored in the text entity itself.But not all setting are substituted by the default value.The height
or width
attribute must be stored in thetext entities itself in order to influence the appearance of the text.It is recommended that you do not rely on the default settings in theTextstyle entity, set all attributes in the text entity itself ifsupported.
Font Settings¶
Just a few settings are available exclusive by the Textstyle entity:
The most important setting is the font
attribute, this attributedefines the rendering font as raw TTF file name, e.g. “Arial.ttf” or“OpenSansCondensed-Light.ttf”, this file name is often not the namedisplayed in GUI application and you have to digg down into the fonts foldere.g. (“C:\Windows\Fonts”) to get the real file name for the TTF font.Do not include the path!
AutoCAD supports beyond the legacy SHX fonts only TTF fonts.The SHX font format is not documented and only available in some CADapplications. The ezdxf drawing add-on replaces theSHX fonts by TTF fonts, which look similar to the SHX fonts, unfortunately thelicense of these fonts is unclear, therefore they can not be packaged with ezdxf.They are installed automatically if you use an Autodesk product like TrueView,or search the internet at you own risk for these TTF fonts.
The extended font data can provide extra information for the font, it is storedin the XDATA section, not well documented and not widely supported.
Important
The DXF format does not and can not embed TTF fonts like the PDF format!
You need to make sure that the CAD application is properly configured tohave access to the system fonts. The DXF format has no setting where the CADapplication should search for fonts, and does not guarantee that the textrendering on other computers or operating systems looks the same as on yourcurrent system on which you created the DXF.
The second exclusive setting is the vertical text flag in Textstyle.flags
.The vertical text style is enabled for all entities using the text style.Vertical text works only for SHX fonts and is not supported for TTF fonts(in AutoCAD) and is works only for the single line entities Textand Attrib.Most CAD applications beside AutoCAD and BricsCAD do not support vertical textrendering and even AutoCAD and BricsCAD have problems with vertical textrendering in some circ*mstances. Using the vertical text feature is notrecommended.
Subclass of | ezdxf.entities.DXFEntity |
DXF type |
|
Factory function |
|
See also
Tutorial for Text and DXF internals for DIMSTYLE Table.
- class ezdxf.entities.Textstyle¶
- property is_backward: bool¶
Get/set text generation flag BACKWARDS, for mirrored text along thex-axis.
- property is_upside_down: bool¶
Get/set text generation flag UPSIDE_DOWN, for mirrored text alongthe y-axis.
- property is_vertical_stacked: bool¶
Get/set style flag VERTICAL_STACKED, for vertical stacked text.
- property is_shape_file: bool¶
True
if entry describes a shape.
- dxf.handle¶
DXF handle (feature for experts).
- dxf.owner¶
Handle to owner (TextstyleTable).
- dxf.name¶
Style name (str)
- dxf.flags¶
Style flags (feature for experts).
1
If set, this entry describes a shape
4
Vertical text
16
If set, table entry is externally dependent on an xref
32
If both this bit and bit 16 are set, the externally dependent xrefhas been successfully resolved
64
If set, the table entry was referenced by at least one entity in thedrawing the last time the drawing was edited. (This flag is only forthe benefit of AutoCAD)commands. It can be ignored by most programsthat read DXF files and need not be set by programs that write DXFfiles)
- dxf.height¶
Fixed height in drawing units as float value, 0 for not fixed.
- dxf.width¶
Width factor as float value, default value is 1.
- dxf.oblique¶
Oblique (slanting) angle in degrees as float value, default value is 0for no slanting.
- dxf.generation_flags¶
Text generations flags as int value.
2
text is backward (mirrored along the x-axis)
4
text is upside down (mirrored about the base line)
- dxf.last_height¶
Last height used in drawing units as float value.
- dxf.font¶
Raw font file name as string without leading path, e.g.“Arial.ttf” for TTF fonts or the SHX font name like“TXT” or “TXT.SHX”.
- dxf.bigfont¶
Big font name as string, blank if none. No documentation how to usethis feature, maybe just a legacy artifact.
- property has_extended_font_data: bool¶
Returns
True
if extended font data is present.
- get_extended_font_data() → tuple[str, bool, bool]¶
Returns extended font data as tuple (font-family, italic-flag,bold-flag).
The extended font data is optional and not reliable! Returns(“”,
False
,False
) if extended font data is not present.
- set_extended_font_data(family: str = '', *, italic=False, bold=False) → None¶
Set extended font data, the font-family name family is notvalidated by ezdxf. Overwrites existing data.
- discard_extended_font_data()¶
Discard extended font data.
- make_font(cap_height: float | None = None, width_factor: float | None = None) → fonts.AbstractFont¶
Returns a font abstraction
AbstractFont
for this text style. Returns a font for a cap height of 1, if thetext style has auto height (Textstyle.dxf.height is 0) andthe given cap_height isNone
or 0.Uses the Textstyle.dxf.width attribute if the given width_factorisNone
or 0, the default value is 1.The attributeTextstyle.dxf.big_font
is ignored.