Ejemplo n.º 1
0
 def test_project_into_yz(self, spath):
     result = fit_paths_into_box([spath], (0, 6, 6), uniform=False)
     box = bbox(result)
     assert box.size == (0, 6, 6), "x-axis should be ignored"
Ejemplo n.º 2
0
ff = fonts.FontFace(family="Arial")
sx, sy = 4, 2

# create the target box:
msp.add_lwpolyline([(0, 0), (sx, 0), (sx, sy), (0, sy)],
                   close=True,
                   dxfattribs={'color': 1})

# convert text string into path objects:
text_as_paths = text2path.make_paths_from_str("Squeeze Me", ff)

# fit text paths into a given box size by scaling, does not move the path objects:
# uniform=True, keeps the text aspect ratio
# uniform=False, scales the text to touch all 4 sides of the box
final_paths = path.fit_paths_into_box(text_as_paths,
                                      size=(sx, sy, 0),
                                      uniform=False)

# mirror text along x-axis
final_paths = path.transform_paths(final_paths, Matrix44.scale(-1, 1, 1))

# move bottom/left corner to (0, 0) if required:
bbox = path.bbox(final_paths)
dx, dy, dz = -bbox.extmin
final_paths = path.transform_paths(final_paths, Matrix44.translate(dx, dy, dz))

path.render_lwpolylines(msp,
                        final_paths,
                        distance=0.01,
                        dxfattribs={'color': 2})
Ejemplo n.º 3
0
 def test_non_uniform_stretch_paths(self, spath):
     result = fit_paths_into_box([spath], (8, 7, 6), uniform=False)
     box = bbox(result)
     assert box.size == (8, 7, 6)
Ejemplo n.º 4
0
 def test_non_uniform_shrink_paths(self, spath):
     result = fit_paths_into_box([spath], (1.5, 1.5, 1.5), uniform=False)
     box = bbox(result)
     assert box.size == (1.5, 1.5, 1.5)
Ejemplo n.º 5
0
 def test_project_into_yz(self, spath):
     result = fit_paths_into_box([spath], (0, 6, 6))
     box = bbox(result)
     assert box.size.isclose((0, 4, 6)), "x-axis should be ignored"
Ejemplo n.º 6
0
 def test_invalid_target_size(self, spath):
     with pytest.raises(ValueError):
         fit_paths_into_box([spath], (0, 0, 0))
Ejemplo n.º 7
0
 def test_uniform_shrink_paths(self, spath):
     result = fit_paths_into_box([spath], (1.5, 1.5, 1.5))
     box = bbox(result)
     assert box.size.isclose((0.5, 1, 1.5))
Ejemplo n.º 8
0
 def test_project_into_xy(self, spath):
     result = fit_paths_into_box([spath], (6, 6, 0))
     box = bbox(result)
     # Note: z-axis is also ignored by extent detection:
     # scaling factor = 3x
     assert box.size.isclose((3, 6, 0)), "z-axis should be ignored"
Ejemplo n.º 9
0
 def test_uniform_stretch_paths_limited_by_x(self, spath):
     result = fit_paths_into_box([spath], (1.2, 6, 6))
     box = bbox(result)
     # stretch factor: 1.2
     assert box.size.isclose((1.2, 2.4, 3.6))
Ejemplo n.º 10
0
 def test_uniform_stretch_paths_limited_by_y(self, spath):
     result = fit_paths_into_box([spath], (6, 3, 6))
     box = bbox(result)
     # stretch factor: 1.5
     assert box.size == (1.5, 3, 4.5)
Ejemplo n.º 11
0
 def test_uniform_stretch_paths_limited_by_z(self, spath):
     result = fit_paths_into_box([spath], (6, 6, 6))
     box = bbox(result)
     assert box.size == (2, 4, 6)
Ejemplo n.º 12
0
 def test_empty_paths(self):
     assert fit_paths_into_box([], (0, 0, 0)) == []
Ejemplo n.º 13
0
 def test_project_into_xz(self, spath):
     result = fit_paths_into_box([spath], (6, 0, 6))
     box = bbox(result)
     assert box.size == (2, 0, 6), "y-axis should be ignored"