-
Notifications
You must be signed in to change notification settings - Fork 3
/
svg.py
74 lines (53 loc) · 1.72 KB
/
svg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def header(width, height):
return """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="""+"\""+str(width)+"mm\""+"""
height="""+"\""+str(height)+"mm\""+"""
viewBox=\"0 0 """+str(width)+' '+str(height)+"""\"
id="dhxdron"
>"""
def background(width, height, style):
return "<rect width=\""+str(width)+"\" height=\""+str(height)+"\"" + \
" style=\""+style+"\" />"
def circle(radius, style):
return " <circle r=\""+str(radius)+"\""+" style=\""+style+"\" />\n"
def footer():
return "</svg>"
def group(code, transform=None, id=None):
if id:
ident = ' id="'+id+'"'
else:
ident = ''
if transform:
trans = ' transform="'+transform+'"'
else:
trans = ''
return "<g"+ident+trans+">"+code+"</g>\n"
def path(path, style=None):
s = ''
if style:
s = ' style="'+style+'"'
return '<path d="'+path+'"'+s+'/>'
def polygon_path(coords):
return 'M'+' L'.join( str(x)+' '+str(y) for x, y in coords )+' Z'
def polygon_multipath(paths):
return '\n'.join(polygon_path(coords) for coords in paths)
def text(x, y, text, id=None, transform=None, style=None):
t = s = i = ''
if id:
i = ' id="'+id+'"'
if transform:
t = ' transform="'+transform+'"'
if style:
s = ' style="'+style+'"'
return '<text x="'+str(x)+'" y="'+str(y)+'"'+i+t+s+'>'+text+'</text>'
def use(id, transform=None, style=None):
t = s = ''
if transform:
t = ' transform="'+transform+'"'
if style:
s = ' style="'+style+'"'
return '<use xlink:href="#'+id+'" '+t+s+'/>'