예제 #1
0
 def test_findAttr_parents(self):
     ac = svglib.Svg2RlgAttributeConverter()
     rect_node = etree.XML(
         '<g style="fill:#008000;stroke:#008000;"><rect style="fill:#ff0;"/></g>'
     ).getchildren()[0]
     assert ac.findAttr(rect_node, 'fill') == "#ff0"
     assert ac.findAttr(rect_node, 'stroke') == "#008000"
예제 #2
0
 def test_findAttr(self):
     """
     Whitespace in attribute values shouldn't disturb parsing.
     """
     ac = svglib.Svg2RlgAttributeConverter()
     node = etree.XML('<rect fill=" #00A1DE\n"/>')
     assert ac.findAttr(node, 'fill') == "#00A1DE"
예제 #3
0
    def test_font_family(self):
        def font_config_available():
            try:
                subprocess.call(["fc-match"])
            except OSError:
                return False
            return True

        converter = svglib.Svg2RlgAttributeConverter()
        # Check PDF standard names are untouched
        assert converter.convertFontFamily('ZapfDingbats') == 'ZapfDingbats'
        assert converter.convertFontFamily(
            'bilbo ZapfDingbats') == 'ZapfDingbats'
        assert converter.convertFontFamily(
            ' bilbo    ZapfDingbats  ') == 'ZapfDingbats'
        assert converter.convertFontFamily(
            ' bilbo,    ZapfDingbats  ') == 'ZapfDingbats'
        if font_config_available():
            # Fontconfig will always provide at least a default font and register
            # that font under the provided font name.
            assert converter.convertFontFamily('SomeFont') == 'SomeFont'
        else:
            # Unknown fonts are converted to Helvetica by default.
            assert converter.convertFontFamily('SomeFont') == 'Helvetica'
        # Check font names with spaces
        assert converter.split_attr_list(
            "'Open Sans', Arial, 'New Times Roman'") == [
                'Open Sans', 'Arial', 'New Times Roman'
            ]
예제 #4
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test1(self):
        "Test length attribute conversion."

        ac = svglib.Svg2RlgAttributeConverter()
        attr = "1e1%"
        expected = 1
        obj = ac.convertLength(attr, 10)
        self.failUnlessEqual(obj, expected)
예제 #5
0
    def test_1(self):
        "Test length attribute conversion."

        ac = svglib.Svg2RlgAttributeConverter()
        attr = "1e1%"
        expected = 1
        obj = ac.convertLength(attr, 10)
        assert obj == expected
예제 #6
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test0(self):
        "Test multi-attribute conversion."

        mapping = (("fill: black; stroke: yellow", {
            "fill": "black",
            "stroke": "yellow"
        }), )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = testit(ac.parseMultiAttributes, mapping)
        self.failUnlessEqual(len(failed), 0)
예제 #7
0
    def test_percentage_conversion(self):
        "Test percentage length attribute conversion."

        ac = svglib.Svg2RlgAttributeConverter()
        ac.set_box(svglib.Box(0, 0, 50, 150))
        # Percentages depend on current viewport and type of attribute
        length = ac.convertLength("1e1%", attr_name='width')
        assert length == 5
        length = ac.convertLength("1e1%", attr_name='height')
        assert length == 15
예제 #8
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test0(self):
        "Test length list attribute conversion."

        mapping = (
            (" 5cm 5in", [5 * cm, 5 * inch]),
            (" 5, 5", [5, 5]),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = testit(ac.convertLengthList, mapping)
        self.failUnlessEqual(len(failed), 0)
예제 #9
0
    def test_0(self):
        "Test multi-attribute conversion."

        mapping = (("fill: black; stroke: yellow", {
            "fill": "black",
            "stroke": "yellow"
        }), )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.parseMultiAttributes, mapping)
        assert len(failed) == 0
예제 #10
0
    def test_0(self):
        "Test length list attribute conversion."

        mapping = (
            (" 5cm 5in", [5 * cm, 5 * inch]),
            (" 5, 5", [5, 5]),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertLengthList, mapping)
        assert len(failed) == 0
예제 #11
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test0(self):
        "Test transform attribute conversion."

        mapping = (
            ("", []),
            ("scale(2) translate(10,20)", [("scale", 2),
                                           ("translate", (10, 20))]),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = testit(ac.convertTransform, mapping)
        self.failUnlessEqual(len(failed), 0)
예제 #12
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test0(self):
        "Test color attribute conversion."

        mapping = (
            ("red", colors.red),
            ("#ff0000", colors.red),
            ("#f00", colors.red),
            ("rgb(100%,0%,0%)", colors.red),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = testit(ac.convertColor, mapping)
        self.failUnlessEqual(len(failed), 0)
예제 #13
0
    def test_findAttr(self):
        """
        Test various attribute peculiarities.
        """
        ac = svglib.Svg2RlgAttributeConverter()
        # Whitespace in attribute values shouldn't disturb parsing.
        node = etree.XML('<rect fill=" #00A1DE\n"/>')
        assert ac.findAttr(node, 'fill') == "#00A1DE"

        # Attributes starting with '-' are not supported.
        node = etree.XML('<text style="-inkscape-font-specification:Arial"/>')
        assert ac.findAttr(node, '-inkscape-font-specification') == ""
예제 #14
0
    def test_0(self):
        "Test color attribute conversion."

        mapping = (
            ("red", colors.red),
            ("#ff0000", colors.red),
            ("#f00", colors.red),
            ("rgb(100%,0%,0%)", colors.red),
            ("rgb(255, 0, 0)", colors.red),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0
예제 #15
0
    def test_0(self):
        "Test transform attribute conversion."

        mapping = (
            ("", []),
            ("scale(2) translate(10,-20.5)", [("scale", 2.0),
                                              ("translate", (10.0, -20.5))]),
            ("scale(0.9), translate(27,40)", [("scale", 0.9),
                                              ("translate", (27.0, 40.0))]),
            # Invalid expression returns empty list
            ("scale(0.9), translate", []),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertTransform, mapping)
        assert len(failed) == 0
예제 #16
0
    def test_1(self):
        "Test color attribute conversion to CMYK"

        mapping = (
            ("red", force_cmyk(colors.red)),
            ("#ff0000", force_cmyk(colors.red)),
            ("#f00", force_cmyk(colors.red)),
            ("rgb(100%,0%,0%)", force_cmyk(colors.red)),
            ("rgb(255, 0, 0)", force_cmyk(colors.red)),
            ("rgb(0,255, 0)", force_cmyk(colors.Color(0, 1, 0))),
            ("rgb(0, 0, 255)", force_cmyk(colors.Color(0, 0, 1))),
        )
        ac = svglib.Svg2RlgAttributeConverter(color_converter=force_cmyk)
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0
예제 #17
0
    def test_0(self):
        "Test color attribute conversion."

        mapping = (
            ("red", colors.red),
            ("#ff0000", colors.red),
            ("#f00", colors.red),
            ("rgb(100%,0.5%,0.5%)", colors.Color(1, 0.005, 0.005, 1)),
            ("rgb(255, 0, 0)", colors.red),
            ("fuchsia", colors.Color(1, 0, 1, 1)),
            ("slategrey", colors.HexColor(0x708090)),
            ("transparent", colors.Color(0, 0, 0, 0)),
            ("whatever", None),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertColor, mapping)
        assert len(failed) == 0
예제 #18
0
파일: test_svglib.py 프로젝트: spoqa/svglib
    def test0(self):
        "Test length attribute conversion."

        mapping = (
            ("0", 0),
            ("316", 316),
            ("-316", -316),
            ("-3.16", -3.16),
            ("-1e-2", -0.01),
            ("1e-5", 1e-5),
            ("1e1cm", 10 * cm),
            ("1e1in", 10 * inch),
            ("1e1%", 10),
            ("-8e-2cm", (-8e-2) * cm),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = testit(ac.convertLength, mapping)
        self.failUnlessEqual(len(failed), 0)
예제 #19
0
    def test_0(self):
        "Test length attribute conversion."

        mapping = (
            ("0", 0),
            ("316", 316),
            ("-316", -316),
            ("-3.16", -3.16),
            ("-1e-2", -0.01),
            ("1e-5", 1e-5),
            ("1e1cm", 10 * cm),
            ("1e1in", 10 * inch),
            ("1e1%", 10),
            ("-8e-2cm", (-8e-2) * cm),
            ("20px", 20),
            ("20pt", 20 * 1.25),
            ("1.5em", 12 * 1.5),
        )
        ac = svglib.Svg2RlgAttributeConverter()
        failed = _testit(ac.convertLength, mapping)
        assert len(failed) == 0
        assert ac.convertLength("1.5em", em_base=16.5) == 24.75