Esempio n. 1
0
    def test_mm_and_formatting(self, ppmm):
        # Integer and float support
        assert css_dimension_to_mm("123mm", ppmm) == 123
        assert css_dimension_to_mm("1.23mm", ppmm) == 1.23

        # With optional plus
        assert css_dimension_to_mm("+1mm", ppmm) == 1

        # With whitespace
        assert css_dimension_to_mm(" 1 mm ", ppmm) == 1
        assert css_dimension_to_mm(" + 1 mm ", ppmm) == 1
Esempio n. 2
0
def parse_regmarks(parser, args):
    if args.regmarks is False:
        # Regmark use is disabled
        args.regmarks = None
    elif isinstance(args.regmarks, list):
        # Manual regmarks
        try:
            svg_width, svg_height = get_svg_page_size(args.svg)
            x, y, width, height = (
                css_dimension_to_mm(
                    d, width_mm=svg_width, height_mm=svg_height)
                for d in args.regmarks
            )
            args.regmarks = RegmarkSpecification(x, y, width, height)
        except ValueError as e:
            parser.error(
                "--manual-regmarks arguments must be valid CSS dimensions ({})".format(
                    str(e)))
    else:
        # Automatic regmarks
        discovered_regmarks = find_regmarks(
            svg_to_outlines(args.svg),
            required_box_size=5.0,
        )
        
        if args.regmarks is True:
            # Automatic regmarks explicitly requested
            if discovered_regmarks is None:
                parser.error("""
                    --regmarks specified but no registration marks were found in
                    the input.  Check that: 1) all regmarks are visible 2) drawn
                    opaque in black 3) drawn with opaque black strokes (including
                    the box) 4) all brackets are the same length and thickness.
                """)
            else:
                args.regmarks = discovered_regmarks
        else:
            # Default mode: use regmarks if discovered but otherwise don't
            # bother
            args.regmarks = discovered_regmarks
Esempio n. 3
0
 def test_negative(self, ppmm):
     with pytest.raises(ValueError):
         css_dimension_to_mm("-1mm", ppmm)
Esempio n. 4
0
    def test_unsupported_units(self, ppmm):
        # No font-relative sizes
        with pytest.raises(ValueError):
            css_dimension_to_mm("1em", ppmm)

        # No viewport-relative sizes w/out width/height
        with pytest.raises(ValueError):
            css_dimension_to_mm("1vw", ppmm)
        with pytest.raises(ValueError):
            css_dimension_to_mm("1vh", ppmm)
        with pytest.raises(ValueError):
            css_dimension_to_mm("1vmin", ppmm)
        with pytest.raises(ValueError):
            css_dimension_to_mm("1vmin", ppmm)

        # No percentages...
        with pytest.raises(ValueError):
            css_dimension_to_mm("1%", ppmm)
Esempio n. 5
0
    def test_pixels(self, ppmm):
        assert css_dimension_to_mm("1px", ppmm) == 1.0 / ppmm
        assert css_dimension_to_mm("1", ppmm) == 1.0 / ppmm

        assert css_dimension_to_mm("2px", ppmm) == 2.0 / ppmm
        assert css_dimension_to_mm("2", ppmm) == 2.0 / ppmm
Esempio n. 6
0
 def test_viewport_relative(self):
     assert css_dimension_to_mm("1vw", 90.0 / 25.4, 200, 400) == 2.0
     assert css_dimension_to_mm("1vh", 90.0 / 25.4, 200, 400) == 4.0
     assert css_dimension_to_mm("1vmin", 90.0 / 25.4, 200, 400) == 2.0
     assert css_dimension_to_mm("1vmax", 90.0 / 25.4, 200, 400) == 4.0
Esempio n. 7
0
 def test_point(self, ppmm):
     assert css_dimension_to_mm("72pt",
                                ppmm) == css_dimension_to_mm("1in", ppmm)
Esempio n. 8
0
 def test_pica(self, ppmm):
     assert css_dimension_to_mm("6pc",
                                ppmm) == css_dimension_to_mm("1in", ppmm)
Esempio n. 9
0
 def test_inches(self, ppmm):
     assert css_dimension_to_mm("1in", ppmm) == 25.4
     assert css_dimension_to_mm("2in", ppmm) == 50.8
Esempio n. 10
0
 def test_Q(self, ppmm):
     assert css_dimension_to_mm("1Q", ppmm) == 0.25
     assert css_dimension_to_mm("4Q", ppmm) == 1.0
Esempio n. 11
0
 def test_cm(self, ppmm):
     assert css_dimension_to_mm("1.2cm", ppmm) == 12.0
Esempio n. 12
0
 def test_malformed(self, value, ppmm):
     with pytest.raises(ValueError):
         css_dimension_to_mm(value, ppmm)