forked from leviathanch/libsmartpen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstf.py
More file actions
executable file
·36 lines (28 loc) · 758 Bytes
/
stf.py
File metadata and controls
executable file
·36 lines (28 loc) · 758 Bytes
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
#!/usr/bin/env python3
import cairo
import sys
import parsestf
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 6000, 6000)
ctx = cairo.Context(surface)
ctx.set_source_rgb(255, 255, 255)
ctx.paint()
ctx.set_source_rgb(0,0,0)
class Parser(parsestf.STFParser):
def __init__(self, *args):
super(Parser, self).__init__(*args)
self.last_force=0
def handle_stroke_end(self, time):
ctx.stroke()
self.last_force = 0
def handle_point(self, x, y, f, time):
if f:
if self.last_force:
ctx.line_to(x, y)
else:
ctx.move_to(x, y)
self.last_force = 1
f = open(sys.argv[1], 'rb')
p = Parser(f)
p.parse()
ctx.stroke()
surface.write_to_png(sys.argv[2])