This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigure.py
101 lines (91 loc) · 3.04 KB
/
figure.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from common import Model
class Figure(Model):
filename = ""
source = ""
# material-icons = https://material.io/icons/
# mdi = https://materialdesignicons.com/
# fa = http://fontawesome.io/icons/
# svg = the svgs/ folder
color = "aaa"
top = 4
bottom = 4
left = 0
right = 0
size = 0
autoscale = True
scale = 100.
width = 0
height = 0
rotate = 0
def __init__(self, line, source = ""):
data = line.split(",")
self.filename = data[0].strip()
if len(data) > 1:
for key, val in [[y.strip() for y in x.split(":")] for x in data[1:]]:
if key in ("width", "height", "size", "autoscale"):
continue
elif key in ("top", "bottom", "left", "right", "scale"):
if key == "scale" and val != "auto":
self.autoscale = False
val = float(val)
elif key in ("rotate"):
val = int(val)
if key:
setattr(self, key, val)
if not self.source:
self.source = source
if self.autoscale and self.top + self.bottom + self.left + self.right > 0:
l = 0
r = 0
t = 0
b = 0
s = 0
if self.top + self.bottom > self.left + self.right:
s = self.top + self.bottom
l += (self.top + self.bottom) / 2
r += (self.top + self.bottom) / 2
ratio_t = self.top / s
ratio_b = self.bottom / s
if self.left <= r:
r -= self.left
else:
temp = self.left - r
r = 0
s += temp
t += temp * ratio_t
b += temp * ratio_b
if self.right <= l:
l -= self.right
else:
temp = self.right - l
l = 0
s += temp
t += temp / 2
b += temp / 2
else:
s = self.left + self.right
t += (self.left + self.right) / 2
b += (self.left + self.right) / 2
ratio_l = self.left / s
ratio_r = self.right / s
if self.top <= b:
b -= self.top
else:
temp = self.top - b
b = 0
s += temp
l += temp * ratio_l
r += temp * ratio_r
if self.bottom <= t:
t -= self.bottom
else:
temp = self.bottom - t
t = 0
s += temp
l += temp * ratio_l
r += temp * ratio_r
self.top += t
self.bottom += b
self.left += l
self.right += r
self.size = s