-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlitehtml-wx-png.py
executable file
·70 lines (58 loc) · 1.88 KB
/
litehtml-wx-png.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
#!/usr/bin/env vpython3
import sys
import wx
import logme
from litehtmlpy import litehtmlwx, litehtmlpy
class document_container(litehtmlwx.document_container):
def pt_to_px(self, pt):
return pt
class Main:
def __init__(self):
self.wxapp = wx.App(False)
def save(self, i, htmlstart, htmlend, htmldata):
html = htmlstart+htmldata+htmlend
dc = wx.MemoryDC()
cntr = document_container()
cntr.SetDC(dc)
doc = litehtmlpy.fromString(cntr, html, None, None)
doc.render(cntr.size[0], litehtmlpy.render_all)
cntr.size[1] = doc.height()
bmp = wx.Bitmap(cntr.size[0], cntr.size[1], 32)
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(wx.WHITE))
dc.Clear()
clip = litehtmlpy.position(0, 0, doc.width(), doc.height())
doc.draw(0, 0, 0, clip)
bmp.SaveFile('demo-{i:04d}.png'.format(i=i), wx.BITMAP_TYPE_PNG)
cntr.SetDC(None)
del doc
del cntr
def main(self):
if len(sys.argv) > 1:
fname = sys.argv[1]
else:
fname = 'demo.html'
html = open(fname, 'rt').read()
split='<body>'
start = html.find(split) + len(split)
end = html.find('</body>')
htmlstart = html[0:start]
htmlend = html[end:]
html = html[start:end]
htmlpages = []
split = '<div class="lamstrone"/>'
start = 0
while True:
stop = html.find(split, start)
if stop == -1:
htmlpages.append((start, len(html)))
break
htmlpages.append((start, stop))
start = stop+len(split)
for i in range(len(htmlpages)):
print(i, htmlpages[i][0], htmlpages[i][1])
self.save(i, htmlstart, htmlend, html[htmlpages[i][0]:htmlpages[i][1]])
def main():
cls = Main()
cls.main()
main()