Esempio n. 1
0
    def test_identity(self):
        assert Cc.from_pt(1, 1).pt == (1, 1)
        assert Cc.from_in(1, 1).inches == (1, 1)
        assert Cc.from_cm(1, 1).cm == (1, 1)
        assert Cc.from_mm(1, 1).mm == (1, 1)
        assert Cc.from_px(1, 1).px == (1, 1)

        assert Cc.from_pt(2, 2).pt == (2, 2)
        assert Cc.from_in(2, 2).inches == (2, 2)
        assert Cc.from_cm(2, 2).cm == (2, 2)
        assert Cc.from_mm(2, 2).mm == (2, 2)
        assert Cc.from_px(2, 2).px == (2, 2)
Esempio n. 2
0
    def test_output_translate_rotate_scale(self):
        path = Path(__file__).parent.joinpath('output/svg_trs.svg')
        path.unlink(missing_ok=True)
        canvas_builder = CanvasBuilder()
        canvas_builder.set_path(path)
        canvas_builder.set_size(
            Cu.from_cm(4),
            Cu.from_cm(4)
        )

        canvas = canvas_builder.build()

        background = Background()
        background.color = (0.8, 1, 0.8, 1)
        background.draw(canvas)

        svg = Svg(Path(__file__).parent.joinpath('test_svg_grid.svg'))
        svg_size = svg.read_svg_size()
        # Should set the origin of the image to the center.
        svg.svg_origin = Cc(svg_size[0] / 2, svg_size[1] / 2)
        # Should position the image in the center of the screen.
        svg.position = Cc.from_cm(2, 2)
        # Should rotate the image clock-wise.
        svg.rotation = math.pi / 8
        # Resizes the image to almost the size of the canvas, but not exactly.
        svg.width = Cu.from_cm(3)
        svg.height = Cu.from_cm(3)
        svg.draw(canvas)

        canvas.close()

        assert path.exists()
Esempio n. 3
0
    def test_scale(self):
        path = Path(__file__).parent.joinpath('output/svg_scale.svg')
        path.unlink(missing_ok=True)
        canvas_builder = CanvasBuilder()
        canvas_builder.set_path(path)
        canvas_builder.set_size(
            Cu.from_cm(9),
            Cu.from_cm(6)
        )

        canvas = canvas_builder.build()

        background = Background()
        background.color = (1, 0.8, 0.8, 1)
        background.draw(canvas)

        # No scaling
        svg = Svg(Path(__file__).parent.joinpath('test_svg.svg'))
        svg.position = Cc.from_cm(1, 1)
        svg.draw(canvas)

        # Scale 2x by height
        svg = Svg(Path(__file__).parent.joinpath('test_svg.svg'))
        svg.position = Cc.from_cm(5, 1)
        svg.width = Cu.from_cm(3)
        svg.draw(canvas)

        # Scale 2x by height
        svg = Svg(Path(__file__).parent.joinpath('test_svg.svg'))
        svg.position = Cc.from_cm(1, 4)
        svg.height = Cu.from_cm(1)
        svg.draw(canvas)

        # Scale without ratio preservation
        svg = Svg(Path(__file__).parent.joinpath('test_svg.svg'))
        svg.position = Cc.from_cm(5, 4)
        svg.width = Cu.from_cm(3)
        svg.height = Cu.from_cm(1)
        svg.draw(canvas)

        canvas.close()

        assert path.exists()
Esempio n. 4
0
 def test_comparisons(self):
     assert Cc.from_in(1, 1).pt[0] > Cc.from_cm(1, 1).pt[0]
     assert Cc.from_cm(1, 1).pt[0] > Cc.from_mm(1, 1).pt[0]
     assert Cc.from_mm(1, 1).pt[0] > Cc.from_pt(1, 1).pt[0]