Пример #1
0
    def test_path(self):
        self.assertEqual(Path().to_s(), "")
        self.assertEqual(Path([
            Command.parse("M150 0"), 
            Command.parse("L75 200"),
            Command.parse("L225 200"),
            Command.parse("Z")
            ]).to_s(), "M150 0 L75 200 225 200 Z")

        # Parse
        self.assertEqual(Path.parse("M150 0 L75 200 L225 200 C100,100 250,100 250,200 Z").to_s(), "M150 0 L75 200 225 200 C100,100 250,100 250,200 Z")
        self.assertEqual(Path.parse("M150  0 L75  200 L225 200 C100,100 250,100 250,200 Z ").to_s(), "M150 0 L75 200 225 200 C100,100 250,100 250,200 Z")
        self.assertEqual(Path.parse("M150 0 L75 200 225 200 C100,100 250,100 250,200 Z").to_s(), "M150 0 L75 200 225 200 C100,100 250,100 250,200 Z")
        self.assertEqual(Path.parse("M150 0 L75,200 225,200 C-100 100 -250,100 250,200 Z").to_s(), "M150 0 L75 200 225 200 C-100,100 -250,100 250,200 Z")
Пример #2
0
 def test_translate_path(self):
     self.assertEqual(Path.parse("M150 0 L75.1 200 L224.9 200 Z").translate(10, 20).to_s(), "M160 20 L85.1 220 234.9 220 Z")	
     self.assertEqual(Path.parse("M150 0 l75.1 200 224.9 200 Z").translate(10, 20).to_s(), "M160 20 l75.1 200 224.9 200 Z")
Пример #3
0
 def test_round_path(self):
     self.assertEqual(Path.parse("M150 0 L75.1 200 L224.9 200 Z").round().to_s(), "M150 0 L75 200 225 200 Z")
Пример #4
0
#!/usr/bin/python3
from svgpath import Path
import sys

for line in sys.stdin.read().split('\n'):
    if line == "": continue
    print(Path.parse(line).round().to_s())


Пример #5
0
#!/usr/bin/python3
from svgpath import Path
import sys

if len(sys.argv) < 3:
    print("usage: echo path | svgpath-translate.py x y")
    sys.exit(1)

x = sys.argv[1]
y = sys.argv[2]

for line in sys.stdin.read().split('\n'):
    if line == "": continue
    print(Path.parse(line).translate(x, y).to_s())