text2path

New in version 0.16.

Tools to convert text strings and text based DXF entities into outer- and inner linear paths as Path objects. These tools depend on the optional Matplotlib package. At the moment only the TEXT and the ATTRIB entity can be converted into paths and hatches.

Don’t expect a 100% match compared to CAD applications.

Text Alignments

The text alignments work the same way as for the Text entity:

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

The vertical middle alignments (MIDDLE_XXX), center the text vertically in the middle of the uppercase letter “X” (cap height).

Special alignments, where the horizontal alignment is always in the center of the text:

  • ALIGNED: text is scaled to match the given length, scales x- and y-direction by the same factor.

  • FIT: text is scaled to match the given length, but scales only in x-direction.

  • MIDDLE: insertion point is the center of the total height (cap height + descender height) without scaling, the length argument is ignored.

Font Face Definition

A font face is defined by the Matplotlib compatible FontFace object by font-family, font-style, font-stretch and font-weight.

String Functions

ezdxf.addons.text2path.make_path_from_str(s: str, font: FontFace, size: float = 1.0, align: str = 'LEFT', length: float = 0, m: Matrix44 = None)Path

Convert a single line string s into a Multi-Path object. The text size is the height of the uppercase letter “X” (cap height). The paths are aligned about the insertion point at (0, 0). BASELINE means the bottom of the letter “X”.

Parameters
  • s – text to convert

  • font – font face definition as FontFace object

  • size – text size (cap height) in drawing units

  • align – alignment as string, default is “LEFT”

  • length – target length for the “ALIGNED” and “FIT” alignments

  • m – transformation Matrix44

New in version 0.17.

ezdxf.addons.text2path.make_paths_from_str(s: str, font: FontFace, size: float = 1.0, align: str = 'LEFT', length: float = 0, m: Matrix44 = None)List[Path]

Convert a single line string s into a list of Path objects. All paths are returned as a list of Single-Path objects. The text size is the height of the uppercase letter “X” (cap height). The paths are aligned about the insertion point at (0, 0). BASELINE means the bottom of the letter “X”.

Parameters
  • s – text to convert

  • font – font face definition as FontFace object

  • size – text size (cap height) in drawing units

  • align – alignment as string, default is “LEFT”

  • length – target length for the “ALIGNED” and “FIT” alignments

  • m – transformation Matrix44

ezdxf.addons.text2path.make_hatches_from_str(s: str, font: FontFace, size: float = 1.0, align: str = "LEFT", length: float = 0, dxfattribs: Dict = None m: Matrix44 = None)List[Hatch]

Convert a single line string s into a list of virtual Hatch entities. The text size is the height of the uppercase letter “X” (cap height). The paths are aligned about the insertion point at (0, 0). The HATCH entities are aligned to this insertion point. BASELINE means the bottom of the letter “X”.

Parameters
  • s – text to convert

  • font – font face definition as FontFace object

  • size – text size (cap height) in drawing units

  • align – alignment as string, default is “LEFT”

  • length – target length for the “ALIGNED” and “FIT” alignments

  • dxfattribs – additional DXF attributes

  • m – transformation Matrix44

Entity Functions

class ezdxf.addons.text2path.Kind(value)

The Kind enum defines the DXF types to create as bit flags, e.g. 1+2 to get HATCHES as filling and SPLINES and POLYLINES as outline:

Int

Enum

Description

1

HATCHES

Hatch entities as filling

2

SPLINES

Spline and 3D Polyline entities as outline

4

LWPOLYLINES

LWPolyline entities as approximated (flattened) outline

ezdxf.addons.text2path.virtual_entities(entity, kind=Kind.HATCHES)EntityQuery

Convert the text content of DXF entities TEXT and ATTRIB into virtual SPLINE and 3D POLYLINE entities or approximated LWPOLYLINE entities as outlines, or as HATCH entities as fillings.

Returns the virtual DXF entities as an EntityQuery object.

Parameters
  • entity – TEXT or ATTRIB entity

  • kind – kind of entities to create as bit flags, see enum Kind

ezdxf.addons.text2path.explode(entity, kind=Kind.HATCHES, target=None)EntityQuery

Explode the text entity into virtual entities, see virtual_entities(). The source entity will be destroyed.

The target layout is given by the target argument, if target is None, the target layout is the source layout of the text entity.

Returns the created DXF entities as an EntityQuery object.

Parameters
  • entity – TEXT or ATTRIB entity to explode

  • kind – kind of entities to create as bit flags, see enum Kind

  • target – target layout for new created DXF entities, None for the same layout as the source entity.

ezdxf.addons.text2path.make_path_from_entity(entity)Path

Convert text content from DXF entities TEXT and ATTRIB into a Multi-Path object. The paths are located at the location of the source entity.

New in version 0.17.

ezdxf.addons.text2path.make_paths_from_entity(entity)List[Path]

Convert text content from DXF entities TEXT and ATTRIB into a list of Path objects. All paths are returned as a list of Single-Path objects. The paths are located at the location of the source entity.