コード例 #1
0
ファイル: test_814_text2path.py プロジェクト: yanbin-ha/ezdxf
 def test_total_length_for_fit_alignment(self, ff):
     length = 3
     hatches = text2path.make_hatches_from_str(
         "XXX", font=ff, align="FIT", length=length)
     paths = []
     for hatch in hatches:
         paths.extend(path.from_hatch(hatch))
     bbox = path.bbox(paths)
     assert bbox.size.x == pytest.approx(length), "expect exact length"
     assert bbox.size.y == pytest.approx(1.0), \
         "text height should be unscaled"
コード例 #2
0
ファイル: test_814_text2path.py プロジェクト: yanbin-ha/ezdxf
 def test_make_hatches_with_holes(self, ff):
     hatches = text2path.make_hatches_from_str("AAA", font=ff)
     assert len(hatches) == 3
     assert len(hatches[0].paths) == 2, "expected external and one hole"
コード例 #3
0
ファイル: test_814_text2path.py プロジェクト: yanbin-ha/ezdxf
 def test_hatches_from_empty_string(self, ff):
     hatches = text2path.make_hatches_from_str("", font=ff)
     assert len(hatches) == 0
コード例 #4
0
ファイル: test_814_text2path.py プロジェクト: yanbin-ha/ezdxf
 def test_make_exterior_only_hatches(self, ff):
     hatches = text2path.make_hatches_from_str("XXX", font=ff)
     assert len(hatches) == 3
     assert len(hatches[0].paths) == 1
コード例 #5
0
# Requires: matplotlib

from pathlib import Path
import ezdxf
from ezdxf import path, zoom
from ezdxf.tools import fonts
from ezdxf.addons import text2path

DIR = Path('~/Desktop/Outbox').expanduser()
fonts.load()

doc = ezdxf.new()
doc.layers.new('OUTLINE')
doc.layers.new('FILLING')
msp = doc.modelspace()

attr = {'layer': 'OUTLINE', 'color': 1}
ff = fonts.FontFace(family="Noto Sans SC")
s = "Noto Sans SC 0123456789 %@ 中国文字"
align = "LEFT"
path.render_splines_and_polylines(
    msp, text2path.make_paths_from_str(s, ff, align=align), dxfattribs=attr)

attr['layer'] = 'FILLING'
attr['color'] = 2
for hatch in text2path.make_hatches_from_str(s, ff, align=align, dxfattribs=attr):
    msp.add_entity(hatch)

zoom.extents(msp)
doc.saveas(DIR / 'text2path.dxf')