Get only outer or inner paths/outline from text2path #877
-
Hi all, I was trying to figure out how to convert only the inner or outer outline from a text to path. I use the function ezdxf.addons.text2path.make_paths_from_str(). At the moment it creates both contours exclusively, but lets say I want to delete only the inner or the outer one, how do I achieve that? Additionally, it would be desirable if possible to create not only lines from the fonts, but also arcs. I had hoped that by converting to polylines also arcs are created: import ezdxf
from ezdxf.addons import text2path
from ezdxf.tools import fonts
from ezdxf.enums import TextEntityAlignment
doc = ezdxf.new()
msp = doc.modelspace()
paths = text2path.make_paths_from_str(
"Text Example Ø123",
font=fonts.FontFace(family="Arial"),
size=4,
align=TextEntityAlignment.LEFT,
length=0
)
polylines = ezdxf.path.to_polylines2d(paths, segments=2, distance=0.01)
for pl in polylines:
msp.add_entity(pl)
pl.explode()
doc.saveas("Text Example Ø123.dxf") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is a simple but not bulletproof way to archive this. Test that the center of the path's bounding box is inside the previous path's bounding box: from ezdxf.math import BoundingBox2d
def outer_paths(paths):
prev = None
for path in paths:
if prev is None:
prev = BoundingBox2d(path.control_vertices())
yield path
continue
bbox = BoundingBox2d(path.control_vertices())
if not prev.inside(bbox.center):
yield path
prev = bbox
def inner_paths(paths):
prev = None
for path in paths:
if prev is None:
prev = BoundingBox2d(path.control_vertices())
continue
bbox = BoundingBox2d(path.control_vertices())
if prev.inside(bbox.center):
yield path
prev = bbox
polylines = ezdxf.path.to_polylines2d(outer_paths(paths), segments=2, distance=0.01)
for pl in polylines:
msp.add_entity(pl)
pl.explode()
doc.saveas("Text Example Ø123.dxf") |
Beta Was this translation helpful? Give feedback.
This is a simple but not bulletproof way to archive this. Test that the center of the path's bounding box is inside the previous path's bounding box: