Doing my best here
This commit is contained in:
parent
4c7ce6383d
commit
9116ad8ac2
1 changed files with 53 additions and 12 deletions
|
@ -65,7 +65,7 @@ class Path():
|
|||
return (c >= ord('0') and c <= ord('9'))
|
||||
|
||||
@staticmethod
|
||||
def parse(text: str) -> Path:
|
||||
def parse(text: str):
|
||||
commands = list()
|
||||
command = PathCommand()
|
||||
state = State.NONE
|
||||
|
@ -152,6 +152,14 @@ class Path():
|
|||
|
||||
return cr.line_to(x, y + y2)
|
||||
|
||||
def quad_to_cube(self, cr: cairo.Context, x1: float, y1: float, x2: float, y2: float):
|
||||
x0, y0 = cr.get_current_point()
|
||||
|
||||
return (2 / 3 * x1 + 1 / 3 * x0,
|
||||
2 / 3 * y1 + 1 / 3 * y0,
|
||||
2 / 3 * x1 + 1 / 3 * x2,
|
||||
2 / 3 * y1 + 1 / 3 * y2)
|
||||
|
||||
def draw(self, cr: cairo.Context):
|
||||
last = None
|
||||
|
||||
|
@ -161,21 +169,21 @@ class Path():
|
|||
if command == 'M':
|
||||
for i in range(0, len(args), 2):
|
||||
if i == 0:
|
||||
cr.move_to(args[i], args[i+1])
|
||||
cr.move_to(*args[i:i+2])
|
||||
else:
|
||||
cr.line_to(args[i], args[i+1])
|
||||
cr.line_to(*args[i:i+2])
|
||||
elif command == 'm':
|
||||
for i in range(0, len(args), 2):
|
||||
if i == 0:
|
||||
cr.rel_move_to(args[i], args[i+1])
|
||||
cr.rel_move_to(*args[i:i+2])
|
||||
else:
|
||||
cr.rel_line_to(args[i], args[i+1])
|
||||
cr.rel_line_to(*args[i:i+2])
|
||||
elif command == 'L':
|
||||
for i in range(0, len(args), 2):
|
||||
cr.line_to(args[i], args[i+1])
|
||||
cr.line_to(*args[i:i+2])
|
||||
elif command == 'l':
|
||||
for i in range(0, len(args), 2):
|
||||
cr.rel_line_to(args[i], args[i+1])
|
||||
cr.rel_line_to(*args[i:i+2])
|
||||
elif command == 'H':
|
||||
for arg in args:
|
||||
self.horiz_to(cr, arg)
|
||||
|
@ -189,12 +197,45 @@ class Path():
|
|||
for arg in args:
|
||||
self.rel_vert_to(cr, arg)
|
||||
elif command == 'C':
|
||||
for arg in args:
|
||||
cr.curve_to(*arg)
|
||||
for i in range(0, len(args), 6):
|
||||
cr.curve_to(*args[i:i+6])
|
||||
elif command == 'c':
|
||||
for arg in args:
|
||||
cr.rel_curve_to(*arg)
|
||||
for i in range(0, len(args), 6):
|
||||
cr.rel_curve_to(*args[i:i+6])
|
||||
elif command == 'S' or command == 's':
|
||||
for i in range(0, len(args), 4):
|
||||
x2, y2, x, y = args[i:i+4]
|
||||
|
||||
if last[0] == 'C' or last[0] == 'c':
|
||||
x1, y1 = last[1][2:4]
|
||||
elif last[0] == 'S' or last[0] == 's':
|
||||
raise NotImplementedError
|
||||
else:
|
||||
x1, y1 = cr.get_current_point()
|
||||
|
||||
if command == 'S':
|
||||
cr.curve_to(x1, y1, x2, y2, x, y)
|
||||
elif command == 's':
|
||||
cr.curve_to(x1, y1, x2, y2, x, y)
|
||||
elif command == 'Q' or command == 'q':
|
||||
for i in range(0, len(args), 4):
|
||||
x1, y1, x2, y2 = args[i:i+4]
|
||||
cube = self.quad_to_cube(cr, x1, y1, x2, y2)
|
||||
|
||||
if command == 'Q':
|
||||
cr.curve_to(*cube)
|
||||
elif command == 'q':
|
||||
cr.rel_curve_to(*cube)
|
||||
elif command == 'T' or command == 't':
|
||||
for i in range(0, len(args), 2):
|
||||
x, y = args[i:i+2]
|
||||
|
||||
if last[0] == 'Q' or last[0] == 'q':
|
||||
x1, y1 = last[1][0:2]
|
||||
elif last[0] == 'T' or last[0] == 't':
|
||||
raise NotImplementedError
|
||||
|
||||
elif command == 'Z' or command == 'z':
|
||||
cr.close_path()
|
||||
|
||||
last = command
|
||||
last = item
|
||||
|
|
Loading…
Add table
Reference in a new issue